Reorganize the global value kinds. (#490)
* Reorganize the global value kinds. This: - renames "deref" global values to "load" and gives it a offset that works like the "load" instructions' does - adds an explicit "iadd_imm" global value kind, which replaces the builtin iadd in "vmctx" and "deref" global values. - also renames "globalsym" to "symbol"
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
//! wasm translation.
|
||||
|
||||
use cranelift_codegen::cursor::FuncCursor;
|
||||
use cranelift_codegen::ir::immediates::Imm64;
|
||||
use cranelift_codegen::ir::immediates::{Imm64, Offset32};
|
||||
use cranelift_codegen::ir::types::*;
|
||||
use cranelift_codegen::ir::{self, InstBuilder};
|
||||
use cranelift_codegen::settings;
|
||||
@@ -162,21 +162,26 @@ impl<'dummy_environment> FuncEnvironment for DummyFuncEnvironment<'dummy_environ
|
||||
|
||||
fn make_global(&mut self, func: &mut ir::Function, index: GlobalIndex) -> GlobalVariable {
|
||||
// Just create a dummy `vmctx` global.
|
||||
let offset = ((index * 8) as i32 + 8).into();
|
||||
let gv = func.create_global_value(ir::GlobalValueData::VMContext { offset });
|
||||
let offset = ((index * 8) as i64 + 8).into();
|
||||
let vmctx = func.create_global_value(ir::GlobalValueData::VMContext {});
|
||||
let iadd = func.create_global_value(ir::GlobalValueData::IAddImm {
|
||||
base: vmctx,
|
||||
offset,
|
||||
global_type: self.pointer_type(),
|
||||
});
|
||||
GlobalVariable::Memory {
|
||||
gv,
|
||||
gv: iadd,
|
||||
ty: self.mod_info.globals[index].entity.ty,
|
||||
}
|
||||
}
|
||||
|
||||
fn make_heap(&mut self, func: &mut ir::Function, _index: MemoryIndex) -> ir::Heap {
|
||||
// Create a static heap whose base address is stored at `vmctx+0`.
|
||||
let addr = func.create_global_value(ir::GlobalValueData::VMContext { offset: 0.into() });
|
||||
let gv = func.create_global_value(ir::GlobalValueData::Deref {
|
||||
let addr = func.create_global_value(ir::GlobalValueData::VMContext);
|
||||
let gv = func.create_global_value(ir::GlobalValueData::Load {
|
||||
base: addr,
|
||||
offset: 0.into(),
|
||||
memory_type: self.pointer_type(),
|
||||
offset: Offset32::new(0),
|
||||
global_type: self.pointer_type(),
|
||||
});
|
||||
|
||||
func.create_heap(ir::HeapData {
|
||||
@@ -192,19 +197,16 @@ impl<'dummy_environment> FuncEnvironment for DummyFuncEnvironment<'dummy_environ
|
||||
|
||||
fn make_table(&mut self, func: &mut ir::Function, _index: TableIndex) -> ir::Table {
|
||||
// Create a table whose base address is stored at `vmctx+0`.
|
||||
let base_gv_addr =
|
||||
func.create_global_value(ir::GlobalValueData::VMContext { offset: 0.into() });
|
||||
let base_gv = func.create_global_value(ir::GlobalValueData::Deref {
|
||||
base: base_gv_addr,
|
||||
offset: 0.into(),
|
||||
memory_type: self.pointer_type(),
|
||||
let vmctx = func.create_global_value(ir::GlobalValueData::VMContext);
|
||||
let base_gv = func.create_global_value(ir::GlobalValueData::Load {
|
||||
base: vmctx,
|
||||
offset: Offset32::new(0),
|
||||
global_type: self.pointer_type(),
|
||||
});
|
||||
let bound_gv_addr =
|
||||
func.create_global_value(ir::GlobalValueData::VMContext { offset: 0.into() });
|
||||
let bound_gv = func.create_global_value(ir::GlobalValueData::Deref {
|
||||
base: bound_gv_addr,
|
||||
offset: 0.into(),
|
||||
memory_type: self.pointer_type(),
|
||||
let bound_gv = func.create_global_value(ir::GlobalValueData::Load {
|
||||
base: vmctx,
|
||||
offset: Offset32::new(0),
|
||||
global_type: self.pointer_type(),
|
||||
});
|
||||
|
||||
func.create_table(ir::TableData {
|
||||
|
||||
Reference in New Issue
Block a user