Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cranelift: Implement pinned reg in interpreter #4375

Merged
merged 1 commit into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions cranelift/filetests/filetests/runtests/pinned-reg.clif
Original file line number Diff line number Diff line change
@@ -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
12 changes: 11 additions & 1 deletion cranelift/interpreter/src/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ pub struct InterpreterState<'a> {
pub heaps: Vec<HeapBacking>,
pub iflags: HashSet<IntCC>,
pub fflags: HashSet<FloatCC>,
pub pinned_reg: DataValue,
}

impl Default for InterpreterState<'_> {
Expand All @@ -213,6 +214,7 @@ impl Default for InterpreterState<'_> {
heaps: Vec::new(),
iflags: HashSet::new(),
fflags: HashSet::new(),
pinned_reg: DataValue::U64(0),
}
}
}
Expand Down Expand Up @@ -592,10 +594,18 @@ impl<'a> State<'a, DataValue> for InterpreterState<'a> {
}
}
_ => unimplemented!(),
}
};

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)]
Expand Down
13 changes: 13 additions & 0 deletions cranelift/interpreter/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ pub trait State<'a, V> {

/// Checks if an address is valid and within a known region of memory
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)]
Expand Down Expand Up @@ -187,4 +192,12 @@ where
fn validate_address(&self, _addr: &Address) -> Result<(), MemoryError> {
unimplemented!()
}

fn get_pinned_reg(&self) -> V {
unimplemented!()
}

fn set_pinned_reg(&mut self, _v: V) {
unimplemented!()
}
}
7 changes: 5 additions & 2 deletions cranelift/interpreter/src/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,11 @@ where
unreachable!()
}
}
Opcode::GetPinnedReg => unimplemented!("GetPinnedReg"),
Opcode::SetPinnedReg => unimplemented!("SetPinnedReg"),
Opcode::GetPinnedReg => assign(state.get_pinned_reg()),
Opcode::SetPinnedReg => {
state.set_pinned_reg(arg(0)?);
ControlFlow::Continue
}
Opcode::TableAddr => {
if let InstructionData::TableAddr { table, offset, .. } = inst {
let table = &state.get_current_function().tables[table];
Expand Down