Skip to content

Commit 22b89e0

Browse files
committed
cranelift: Implement pinned reg in interpreter
1 parent a2197eb commit 22b89e0

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
test interpret
2+
test run
3+
set enable_pinned_reg
4+
target x86_64
5+
6+
function %read_write(i64) -> i64 {
7+
block0(v0: i64):
8+
set_pinned_reg v0
9+
v1 = get_pinned_reg.i64
10+
return v1
11+
}
12+
; run: %read_write(0) == 0
13+
; run: %read_write(-1) == -1
14+
; run: %read_write(0xDEADBEEF_C0FFEEEE) == 0xDEADBEEF_C0FFEEEE

cranelift/interpreter/src/interpreter.rs

+10
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ pub struct InterpreterState<'a> {
182182
pub heap: Vec<u8>,
183183
pub iflags: HashSet<IntCC>,
184184
pub fflags: HashSet<FloatCC>,
185+
pub pinned_reg: DataValue,
185186
}
186187

187188
impl Default for InterpreterState<'_> {
@@ -194,6 +195,7 @@ impl Default for InterpreterState<'_> {
194195
heap: vec![0; 1024],
195196
iflags: HashSet::new(),
196197
fflags: HashSet::new(),
198+
pinned_reg: DataValue::U64(0),
197199
}
198200
}
199201
}
@@ -351,6 +353,14 @@ impl<'a> State<'a, DataValue> for InterpreterState<'a> {
351353

352354
Ok(v.write_to_slice(dst))
353355
}
356+
357+
fn get_pinned_reg(&self) -> DataValue {
358+
self.pinned_reg.clone()
359+
}
360+
361+
fn set_pinned_reg(&mut self, v: DataValue) {
362+
self.pinned_reg = v;
363+
}
354364
}
355365

356366
#[cfg(test)]

cranelift/interpreter/src/state.rs

+13
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ pub trait State<'a, V> {
7474
/// Store a value `V` into memory at the given `address`, checking if it belongs either to the
7575
/// stack or to one of the heaps; the number of bytes stored corresponds to the specified [Type].
7676
fn checked_store(&mut self, address: Address, v: V) -> Result<(), MemoryError>;
77+
78+
/// Retrieves the current pinned reg value
79+
fn get_pinned_reg(&self) -> V;
80+
/// Sets a value for the pinned reg
81+
fn set_pinned_reg(&mut self, v: V);
7782
}
7883

7984
#[derive(Error, Debug)]
@@ -162,4 +167,12 @@ where
162167
fn checked_store(&mut self, _addr: Address, _v: V) -> Result<(), MemoryError> {
163168
unimplemented!()
164169
}
170+
171+
fn get_pinned_reg(&self) -> V {
172+
unimplemented!()
173+
}
174+
175+
fn set_pinned_reg(&mut self, _v: V) {
176+
unimplemented!()
177+
}
165178
}

cranelift/interpreter/src/step.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,11 @@ where
384384
Opcode::SymbolValue => unimplemented!("SymbolValue"),
385385
Opcode::TlsValue => unimplemented!("TlsValue"),
386386
Opcode::HeapAddr => unimplemented!("HeapAddr"),
387-
Opcode::GetPinnedReg => unimplemented!("GetPinnedReg"),
388-
Opcode::SetPinnedReg => unimplemented!("SetPinnedReg"),
387+
Opcode::GetPinnedReg => assign(state.get_pinned_reg()),
388+
Opcode::SetPinnedReg => {
389+
state.set_pinned_reg(arg(0)?);
390+
ControlFlow::Continue
391+
}
389392
Opcode::TableAddr => unimplemented!("TableAddr"),
390393
Opcode::Iconst => assign(Value::int(imm().into_int()?, ctrl_ty)?),
391394
Opcode::F32const => assign(imm()),

0 commit comments

Comments
 (0)