Path: blob/main/winch/codegen/src/abi/local.rs
1692 views
use wasmtime_environ::WasmValType;12/// Base register used to address the local slot.3///4/// Slots for stack arguments are addressed from the frame pointer.5/// Slots for function-defined locals and for registers are addressed6/// from the stack pointer.7#[derive(Clone, Eq, PartialEq, Copy, Debug)]8enum Base {9FP,10SP,11}1213/// A local slot.14///15/// Represents the type, location and addressing mode of a local16/// in the stack's local and argument area.17/// LocalSlots are well known slots in the machine stack, and are generally18/// reference by the stack pointer register (SP) or the base pointer register (FP).19/// * Local slots that are referenced by the stack pointer register are the20/// function defined locals and the param locals.21/// * Local slots that represent arguments in the stack, are referenced through the22/// base pointer register.23///24/// A [crate::masm::StackSlot] is a generalized form of a [LocalSlot]: they25/// represent dynamic chunks of memory that get created throughout the function26/// compilation lifetime when spilling values (register and locals) into the27/// machine stack. A [LocalSlot] on the other hand gets created at the beginning28/// of a function compilation and gets cleaned up at the end.29#[derive(Clone, Copy, Debug)]30pub(crate) struct LocalSlot {31/// The offset of the local slot.32pub offset: u32,33/// The type contained by this local slot.34pub ty: WasmValType,35/// Base register associated to this local slot.36base: Base,37}3839impl LocalSlot {40/// Creates a local slot for a function defined local or41/// for a spilled argument register.42pub fn new(ty: WasmValType, offset: u32) -> Self {43Self {44ty,45offset,46base: Base::SP,47}48}4950/// Int32 shortcut for `new`.51pub fn i32(offset: u32) -> Self {52Self {53ty: WasmValType::I32,54offset,55base: Base::SP,56}57}5859/// Int64 shortcut for `new`.60pub fn i64(offset: u32) -> Self {61Self {62ty: WasmValType::I64,63offset,64base: Base::SP,65}66}6768/// Creates a local slot for a stack function argument.69pub fn stack_arg(ty: WasmValType, offset: u32) -> Self {70Self {71ty,72offset,73base: Base::FP,74}75}7677/// Check if the local is addressed from the stack pointer.78pub fn addressed_from_sp(&self) -> bool {79self.base == Base::SP80}81}828384