cranelift: Implement pinned reg in interpreter (#4375)

This commit is contained in:
Afonso Bordado
2022-08-10 22:33:45 +01:00
committed by GitHub
parent 11f0b003eb
commit 268ddf2f6c
4 changed files with 42 additions and 3 deletions

View File

@@ -0,0 +1,13 @@
test interpret
set enable_pinned_reg
target x86_64
function %read_write(i64) -> i64 {
block0(v0: i64):
set_pinned_reg v0
v1 = get_pinned_reg.i64
return v1
}
; run: %read_write(0) == 0
; run: %read_write(-1) == -1
; run: %read_write(0xDEADBEEF_C0FFEEEE) == 0xDEADBEEF_C0FFEEEE

View File

@@ -201,6 +201,7 @@ pub struct InterpreterState<'a> {
pub heaps: Vec<HeapBacking>, pub heaps: Vec<HeapBacking>,
pub iflags: HashSet<IntCC>, pub iflags: HashSet<IntCC>,
pub fflags: HashSet<FloatCC>, pub fflags: HashSet<FloatCC>,
pub pinned_reg: DataValue,
} }
impl Default for InterpreterState<'_> { impl Default for InterpreterState<'_> {
@@ -213,6 +214,7 @@ impl Default for InterpreterState<'_> {
heaps: Vec::new(), heaps: Vec::new(),
iflags: HashSet::new(), iflags: HashSet::new(),
fflags: HashSet::new(), fflags: HashSet::new(),
pinned_reg: DataValue::U64(0),
} }
} }
} }
@@ -592,10 +594,18 @@ impl<'a> State<'a, DataValue> for InterpreterState<'a> {
} }
} }
_ => unimplemented!(), _ => unimplemented!(),
} };
Ok(()) Ok(())
} }
fn get_pinned_reg(&self) -> DataValue {
self.pinned_reg.clone()
}
fn set_pinned_reg(&mut self, v: DataValue) {
self.pinned_reg = v;
}
} }
#[cfg(test)] #[cfg(test)]

View File

@@ -86,6 +86,11 @@ pub trait State<'a, V> {
/// Checks if an address is valid and within a known region of memory /// Checks if an address is valid and within a known region of memory
fn validate_address(&self, address: &Address) -> Result<(), MemoryError>; fn validate_address(&self, address: &Address) -> Result<(), MemoryError>;
/// Retrieves the current pinned reg value
fn get_pinned_reg(&self) -> V;
/// Sets a value for the pinned reg
fn set_pinned_reg(&mut self, v: V);
} }
#[derive(Error, Debug)] #[derive(Error, Debug)]
@@ -187,4 +192,12 @@ where
fn validate_address(&self, _addr: &Address) -> Result<(), MemoryError> { fn validate_address(&self, _addr: &Address) -> Result<(), MemoryError> {
unimplemented!() unimplemented!()
} }
fn get_pinned_reg(&self) -> V {
unimplemented!()
}
fn set_pinned_reg(&mut self, _v: V) {
unimplemented!()
}
} }

View File

@@ -407,8 +407,11 @@ where
unreachable!() unreachable!()
} }
} }
Opcode::GetPinnedReg => unimplemented!("GetPinnedReg"), Opcode::GetPinnedReg => assign(state.get_pinned_reg()),
Opcode::SetPinnedReg => unimplemented!("SetPinnedReg"), Opcode::SetPinnedReg => {
state.set_pinned_reg(arg(0)?);
ControlFlow::Continue
}
Opcode::TableAddr => { Opcode::TableAddr => {
if let InstructionData::TableAddr { table, offset, .. } = inst { if let InstructionData::TableAddr { table, offset, .. } = inst {
let table = &state.get_current_function().tables[table]; let table = &state.get_current_function().tables[table];