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 global_value in interpreter #4396

Merged
merged 1 commit into from
Jul 6, 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
23 changes: 23 additions & 0 deletions cranelift/filetests/filetests/runtests/global_value.clif
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
test interpret
test run
target x86_64
target s390x
target aarch64

; Store a value in the heap using `heap_addr` and load it using `global_value`
function %store_load(i64 vmctx, i64, i32) -> i32 {
gv0 = vmctx
gv1 = load.i64 notrap aligned gv0+0
heap0 = static gv1, min 0x1000, bound 0x1_0000_0000, offset_guard 0, index_type i64

block0(v0: i64, v1: i64, v2: i32):
v3 = heap_addr.i64 heap0, v1, 0
store.i32 v2, v3

v4 = global_value.i64 gv1
v5 = load.i32 v4
return v5
}
; heap: static, size=0x1000, ptr=vmctx+0, bound=vmctx+8
; run: %store_load(0, 1) == 1
; run: %store_load(0, -1) == -1
8 changes: 7 additions & 1 deletion cranelift/interpreter/src/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,13 @@ where
})
})
}
Opcode::GlobalValue => unimplemented!("GlobalValue"),
Opcode::GlobalValue => {
if let InstructionData::UnaryGlobalValue { global_value, .. } = inst {
assign_or_memtrap(state.resolve_global_value(global_value))
} else {
unreachable!()
}
}
Opcode::SymbolValue => unimplemented!("SymbolValue"),
Opcode::TlsValue => unimplemented!("TlsValue"),
Opcode::HeapAddr => {
Expand Down