Struct FuncGen

Source
pub struct FuncGen<'a, M: Machine> {
Show 19 fields module: &'a ModuleInfo, config: &'a Singlepass, vmoffsets: &'a VMOffsets, memory_styles: &'a PrimaryMap<MemoryIndex, MemoryStyle>, signature: FunctionType, locals: Vec<Location<M::GPR, M::SIMD>>, local_types: Vec<ValType>, value_stack: Vec<(Location<M::GPR, M::SIMD>, CanonicalizeType)>, control_stack: Vec<ControlFrame<M>>, stack_offset: usize, save_area_offset: Option<usize>, machine: M, unreachable_depth: usize, local_func_index: LocalFunctionIndex, relocations: Vec<Relocation>, special_labels: SpecialLabelSet, calling_convention: CallingConvention, function_name: String, assembly_comments: HashMap<usize, AssemblyComment>,
}
Expand description

The singlepass per-function code generator.

Fields§

§module: &'a ModuleInfo

Static module information.

§config: &'a Singlepass

ModuleInfo compilation config.

§vmoffsets: &'a VMOffsets

Offsets of vmctx fields.

§memory_styles: &'a PrimaryMap<MemoryIndex, MemoryStyle>§signature: FunctionType

Function signature.

§locals: Vec<Location<M::GPR, M::SIMD>>

Memory locations of local variables.

§local_types: Vec<ValType>

Types of local variables, including arguments.

§value_stack: Vec<(Location<M::GPR, M::SIMD>, CanonicalizeType)>

Value stack.

§control_stack: Vec<ControlFrame<M>>

A list of frames describing the current control stack.

§stack_offset: usize

Stack offset tracking in bytes.

§save_area_offset: Option<usize>§machine: M

Low-level machine state.

§unreachable_depth: usize

Nesting level of unreachable code.

§local_func_index: LocalFunctionIndex

Index of a function defined locally inside the WebAssembly module.

§relocations: Vec<Relocation>

Relocation information.

§special_labels: SpecialLabelSet

A set of special labels for trapping.

§calling_convention: CallingConvention

Calling convention to use.

§function_name: String

Name of the function.

§assembly_comments: HashMap<usize, AssemblyComment>

Assembly comments.

Implementations§

Source§

impl<'a, M: Machine> FuncGen<'a, M>

Source

fn acquire_location( &mut self, ty: &WpType, ) -> Result<Location<M::GPR, M::SIMD>, CompileError>

Acquires location from the machine state.

If the returned location is used for stack value, release_location needs to be called on it; Otherwise, if the returned locations is used for a local, release_location does not need to be called on it.

Source

fn acquire_location_on_stack( &mut self, ) -> Result<Location<M::GPR, M::SIMD>, CompileError>

Acquire location that will live on the stack.

Source

fn release_locations( &mut self, locs: &[(Location<M::GPR, M::SIMD>, CanonicalizeType)], ) -> Result<(), CompileError>

Releases locations used for stack value.

Source

fn release_reg_locations( &mut self, locs: &[(Location<M::GPR, M::SIMD>, CanonicalizeType)], ) -> Result<(), CompileError>

Source

fn release_stack_locations( &mut self, locs: &[(Location<M::GPR, M::SIMD>, CanonicalizeType)], ) -> Result<(), CompileError>

Source

fn release_stack_locations_keep_stack_offset( &mut self, stack_depth: usize, ) -> Result<(), CompileError>

Source

fn check_location_on_stack( &self, loc: &Location<M::GPR, M::SIMD>, expected_stack_offset: usize, ) -> Result<(), CompileError>

Source

fn allocate_return_slots_and_swap( &mut self, stack_slots: usize, return_slots: usize, ) -> Result<(), CompileError>

Allocate return slots for block operands (Block, If, Loop) and swap them with the corresponding input parameters on the value stack.

This method reserves memory slots that can accommodate both integer and floating-point types, then swaps these slots with the last stack_slots values on the stack to position them correctly for the block’s return values. that are already present at the value stack.

Source

fn init_locals( &mut self, n: usize, sig: FunctionType, calling_convention: CallingConvention, ) -> Result<Vec<Location<M::GPR, M::SIMD>>, CompileError>

Source

fn finalize_locals( &mut self, calling_convention: CallingConvention, ) -> Result<(), CompileError>

Source

pub fn set_srcloc(&mut self, offset: u32)

Set the source location of the Wasm to the given offset.

Source

fn get_location_released( &mut self, loc: (Location<M::GPR, M::SIMD>, CanonicalizeType), ) -> Result<(Location<M::GPR, M::SIMD>, CanonicalizeType), CompileError>

Source

fn pop_value_released( &mut self, ) -> Result<(Location<M::GPR, M::SIMD>, CanonicalizeType), CompileError>

Source

fn i2o1_prepare( &mut self, ty: WpType, canonicalize: CanonicalizeType, ) -> Result<I2O1<M::GPR, M::SIMD>, CompileError>

Prepare data for binary operator with 2 inputs and 1 output.

Source

fn emit_call_native<I: Iterator<Item = (Location<M::GPR, M::SIMD>, CanonicalizeType)>, J: Iterator<Item = WpType>, K: Iterator<Item = WpType>, F: FnOnce(&mut Self) -> Result<(), CompileError>>( &mut self, cb: F, params: I, params_type: J, return_types: K, call_type: NativeCallType, ) -> Result<(), CompileError>

Emits a Native ABI call sequence.

The caller MUST NOT hold any temporary registers allocated by acquire_temp_gpr when calling this function.

Source

fn op_memory<F: FnOnce(&mut Self, bool, bool, i32, DynamicLabel, DynamicLabel) -> Result<(), CompileError>>( &mut self, cb: F, ) -> Result<(), CompileError>

Emits a memory operation.

Source

fn emit_head(&mut self) -> Result<(), CompileError>

Source

pub fn new( module: &'a ModuleInfo, config: &'a Singlepass, vmoffsets: &'a VMOffsets, memory_styles: &'a PrimaryMap<MemoryIndex, MemoryStyle>, _table_styles: &'a PrimaryMap<TableIndex, TableStyle>, local_func_index: LocalFunctionIndex, local_types_excluding_arguments: &[WpType], machine: M, calling_convention: CallingConvention, ) -> Result<FuncGen<'a, M>, CompileError>

Source

pub fn has_control_frames(&self) -> bool

Source

fn emit_return_values( &mut self, value_stack_depth_after: usize, return_values: usize, ) -> Result<(), CompileError>

Moves the top return_values items from the value stack into the preallocated return slots starting at value_stack_depth_after.

Used when completing Block/If/Loop constructs or returning from the function. Applies NaN canonicalization when enabled and supported.

Source

fn emit_loop_params_store( &mut self, value_stack_depth_after: usize, param_count: usize, ) -> Result<(), CompileError>

Similar to emit_return_values, except it stores the return_values items into the slots preallocated for parameters of a loop.

Source

fn return_types_for_block( &self, block_type: WpTypeOrFuncType, ) -> SmallVec<[WpType; 1]>

Source

fn param_types_for_block( &self, block_type: WpTypeOrFuncType, ) -> SmallVec<[WpType; 8]>

Source

pub fn feed_operator(&mut self, op: Operator<'_>) -> Result<(), CompileError>

Source

fn add_assembly_comment(&mut self, comment: AssemblyComment)

Source

pub fn finalize( self, data: &FunctionBodyData<'_>, arch: Architecture, ) -> Result<(CompiledFunction, Option<UnwindFrame>), CompileError>

Source

fn sort_call_movs(movs: &mut [(Location<M::GPR, M::SIMD>, M::GPR)])

Auto Trait Implementations§

§

impl<'a, M> Freeze for FuncGen<'a, M>
where M: Freeze,

§

impl<'a, M> !RefUnwindSafe for FuncGen<'a, M>

§

impl<'a, M> Send for FuncGen<'a, M>
where M: Send, <M as Machine>::GPR: Send, <M as Machine>::SIMD: Send,

§

impl<'a, M> Sync for FuncGen<'a, M>
where M: Sync, <M as Machine>::GPR: Sync, <M as Machine>::SIMD: Sync,

§

impl<'a, M> Unpin for FuncGen<'a, M>
where M: Unpin, <M as Machine>::GPR: Unpin, <M as Machine>::SIMD: Unpin,

§

impl<'a, M> !UnwindSafe for FuncGen<'a, M>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> ArchivePointee for T

§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> LayoutRaw for T

§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Returns the layout of the type.
§

impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
where T: SharedNiching<N1, N2>, N1: Niching<T>, N2: Niching<T>,

§

unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool

Returns whether the given value has been niched. Read more
§

fn resolve_niched(out: Place<NichedOption<T, N1>>)

Writes data to out indicating that a T is niched.
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> Pointee for T

§

type Metadata = ()

The metadata type for pointers and references to this type.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> Upcastable for T
where T: Any + Send + Sync + 'static,

§

fn upcast_any_ref(&self) -> &(dyn Any + 'static)

upcast ref
§

fn upcast_any_mut(&mut self) -> &mut (dyn Any + 'static)

upcast mut ref
§

fn upcast_any_box(self: Box<T>) -> Box<dyn Any>

upcast boxed dyn