Skip to main content

WasmRegAlloc

Struct WasmRegAlloc 

Source
pub struct WasmRegAlloc { /* private fields */ }
Expand description

WASM “register allocator” for stack-based virtual machine.

WASM doesn’t use physical registers like x86_64, but we still need to track virtual registers for stack operations. This is a simplified allocator that maps virtual registers to stack positions.

Implementations§

Source§

impl WasmRegAlloc

Source

pub fn new() -> Self

Source

pub fn get_stack_position(&self, vreg: &VirtualReg) -> Option<u32>

Get the stack position for a virtual register

Source

pub fn allocate_stack(&mut self, vreg: VirtualReg) -> u32

Allocate a stack position for a virtual register

Trait Implementations§

Source§

impl Default for WasmRegAlloc

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl RegisterAllocator for WasmRegAlloc

Source§

type PhysReg = u32

Architecture-specific physical register handle.
Source§

fn alloc_scratch(&mut self) -> Option<Self::PhysReg>

Acquire a short-lived scratch register. Returns None when the dedicated pool is exhausted so the caller may spill or choose an alternate path.
Source§

fn free_scratch(&mut self, _phys: Self::PhysReg)

Release a scratch register obtained through RegisterAllocator::alloc_scratch.
Source§

fn get_mapping(&self, vreg: &VirtualReg) -> Option<Self::PhysReg>

Look up the physical register currently assigned to the virtual register, when available.
Source§

fn ensure_mapping(&mut self, vreg: VirtualReg) -> Option<Self::PhysReg>

Ensure that the virtual register has a permanent mapping. Implementers can reject unsupported register classes by returning None, signalling that the caller should spill.
Source§

fn mapped_for_register(&self, reg: &Register) -> Option<Self::PhysReg>

Resolve the backing physical register for an arbitrary MIR register (virtual or physical).
Source§

fn occupy(&mut self, _phys: Self::PhysReg)

Mark a physical register as occupied, removing it from the allocator’s free pool if necessary.
Source§

fn release(&mut self, _phys: Self::PhysReg)

Release a previously occupied physical register back to the pool.
Source§

fn is_occupied(&self, _phys: Self::PhysReg) -> bool

Test whether the allocator currently treats the physical register as occupied.

Auto Trait Implementations§

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
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> RegisterAllocatorDyn for T

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.