Clearer variant names for StackMemoryLocation

This commit is contained in:
Brian Carroll 2021-10-03 21:53:18 +01:00
parent 2756425eb9
commit cc6f83f284
2 changed files with 11 additions and 11 deletions

View file

@ -200,7 +200,7 @@ impl<'a> WasmBackend<'a> {
alignment_bytes, alignment_bytes,
} => { } => {
let location = match kind { let location = match kind {
LocalKind::Parameter => StackMemoryLocation::CallerFrame(next_local_id), LocalKind::Parameter => StackMemoryLocation::PointerArg(next_local_id),
LocalKind::Variable => { LocalKind::Variable => {
match self.stack_frame_pointer { match self.stack_frame_pointer {
@ -215,7 +215,7 @@ impl<'a> WasmBackend<'a> {
self.stack_memory = offset + size as i32; self.stack_memory = offset + size as i32;
StackMemoryLocation::OwnFrame(offset as u32) StackMemoryLocation::FrameOffset(offset as u32)
} }
}; };
@ -260,14 +260,14 @@ impl<'a> WasmBackend<'a> {
match storage { match storage {
SymbolStorage::Local { local_id, .. } SymbolStorage::Local { local_id, .. }
| SymbolStorage::StackMemory { | SymbolStorage::StackMemory {
location: StackMemoryLocation::CallerFrame(local_id), location: StackMemoryLocation::PointerArg(local_id),
.. ..
} => { } => {
self.instructions.push(GetLocal(local_id.0)); self.instructions.push(GetLocal(local_id.0));
} }
SymbolStorage::StackMemory { SymbolStorage::StackMemory {
location: StackMemoryLocation::OwnFrame(offset), location: StackMemoryLocation::FrameOffset(offset),
.. ..
} => { } => {
self.instructions.extend([ self.instructions.extend([
@ -308,7 +308,7 @@ impl<'a> WasmBackend<'a> {
// Map this symbol to the first argument (pointer into caller's stack) // Map this symbol to the first argument (pointer into caller's stack)
// Saves us from having to copy it later // Saves us from having to copy it later
let storage = SymbolStorage::StackMemory { let storage = SymbolStorage::StackMemory {
location: StackMemoryLocation::CallerFrame(LocalId(0)), location: StackMemoryLocation::PointerArg(LocalId(0)),
size, size,
alignment_bytes, alignment_bytes,
}; };
@ -345,8 +345,8 @@ impl<'a> WasmBackend<'a> {
alignment_bytes, alignment_bytes,
} => { } => {
let (from_ptr, from_offset) = match location { let (from_ptr, from_offset) = match location {
StackMemoryLocation::CallerFrame(local_id) => (*local_id, 0), StackMemoryLocation::PointerArg(local_id) => (*local_id, 0),
StackMemoryLocation::OwnFrame(offset) => { StackMemoryLocation::FrameOffset(offset) => {
(self.stack_frame_pointer.unwrap(), *offset) (self.stack_frame_pointer.unwrap(), *offset)
} }
}; };

View file

@ -3,15 +3,15 @@ use parity_wasm::elements::{Instruction, Instruction::*, ValueType};
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub enum StackMemoryLocation { pub enum StackMemoryLocation {
CallerFrame(LocalId), FrameOffset(u32),
OwnFrame(u32), PointerArg(LocalId),
} }
impl StackMemoryLocation { impl StackMemoryLocation {
pub fn local_and_offset(&self, stack_frame_pointer: Option<LocalId>) -> (LocalId, u32) { pub fn local_and_offset(&self, stack_frame_pointer: Option<LocalId>) -> (LocalId, u32) {
match self { match self {
Self::CallerFrame(local_id) => (*local_id, 0), Self::PointerArg(local_id) => (*local_id, 0),
Self::OwnFrame(offset) => (stack_frame_pointer.unwrap(), *offset), Self::FrameOffset(offset) => (stack_frame_pointer.unwrap(), *offset),
} }
} }
} }