Change GlobalVar to GlobalValue

This commit is contained in:
Lachlan Sneff
2018-06-14 01:07:27 -04:00
committed by Dan Gohman
parent 49cc693d64
commit 5c320a0d30
44 changed files with 324 additions and 237 deletions

View File

@@ -74,7 +74,7 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
let val = match state.get_global(builder.func, global_index, environ) {
GlobalValue::Const(val) => val,
GlobalValue::Memory { gv, ty } => {
let addr = builder.ins().global_addr(environ.native_pointer(), gv);
let addr = builder.ins().global_value(environ.native_pointer(), gv);
let mut flags = ir::MemFlags::new();
flags.set_notrap();
flags.set_aligned();
@@ -87,7 +87,7 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
match state.get_global(builder.func, global_index, environ) {
GlobalValue::Const(_) => panic!("global #{} is a constant", global_index),
GlobalValue::Memory { gv, .. } => {
let addr = builder.ins().global_addr(environ.native_pointer(), gv);
let addr = builder.ins().global_value(environ.native_pointer(), gv);
let mut flags = ir::MemFlags::new();
flags.set_notrap();
flags.set_aligned();

View File

@@ -159,7 +159,7 @@ impl<'dummy_environment> FuncEnvironment for DummyFuncEnvironment<'dummy_environ
fn make_global(&mut self, func: &mut ir::Function, index: GlobalIndex) -> GlobalValue {
// Just create a dummy `vmctx` global.
let offset = ((index * 8) as i32 + 8).into();
let gv = func.create_global_var(ir::GlobalVarData::VMContext { offset });
let gv = func.create_global_value(ir::GlobalValueData::VMContext { offset });
GlobalValue::Memory {
gv,
ty: self.mod_info.globals[index].entity.ty,
@@ -168,10 +168,10 @@ impl<'dummy_environment> FuncEnvironment for DummyFuncEnvironment<'dummy_environ
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 gv = func.create_global_var(ir::GlobalVarData::VMContext { offset: 0.into() });
let gv = func.create_global_value(ir::GlobalValueData::VMContext { offset: 0.into() });
func.create_heap(ir::HeapData {
base: ir::HeapBase::GlobalVar(gv),
base: ir::HeapBase::GlobalValue(gv),
min_size: 0.into(),
guard_size: 0x8000_0000.into(),
style: ir::HeapStyle::Static {

View File

@@ -9,17 +9,17 @@ use translation_utils::{FunctionIndex, Global, GlobalIndex, Memory, MemoryIndex,
Table, TableIndex};
use wasmparser::BinaryReaderError;
/// The value of a WebAssembly global variable.
/// The value of a WebAssembly global valueiable.
#[derive(Clone, Copy)]
pub enum GlobalValue {
/// This is a constant global with a value known at compile time.
Const(ir::Value),
/// This is a variable in memory that should be referenced as a `GlobalVar`.
/// This is a variable in memory that should be referenced as a `GlobalValue`.
Memory {
/// Which global variable should be referenced.
gv: ir::GlobalVar,
/// The global variable's type.
/// Which global valueiable should be referenced.
gv: ir::GlobalValue,
/// The global valueiable's type.
ty: ir::Type,
},
}
@@ -88,12 +88,12 @@ pub trait FuncEnvironment {
ir::Type::int(u16::from(self.triple().pointer_width().unwrap().bits())).unwrap()
}
/// Set up the necessary preamble definitions in `func` to access the global variable
/// Set up the necessary preamble definitions in `func` to access the global valueiable
/// identified by `index`.
///
/// The index space covers both imported globals and globals defined by the module.
///
/// Return the global variable reference that should be used to access the global and the
/// Return the global valueiable reference that should be used to access the global and the
/// WebAssembly type of the global.
fn make_global(&mut self, func: &mut ir::Function, index: GlobalIndex) -> GlobalValue;

View File

@@ -4,7 +4,7 @@
//! The code of theses helper function is straightforward since it is only about reading metadata
//! about linear memories, tables, globals, etc. and storing them for later use.
//!
//! The special case of the initialize expressions for table elements offsets or global variables
//! The special case of the initialize expressions for table elements offsets or global valueiables
//! is handled, according to the semantics of WebAssembly, to only specific expressions that are
//! interpreted on the fly.
use cretonne_codegen::ir::{self, AbiParam, Signature};

View File

@@ -134,7 +134,7 @@ pub struct TranslationState {
pub control_stack: Vec<ControlStackFrame>,
pub reachable: bool,
// Map of global variables that have already been created by `FuncEnvironment::make_global`.
// Map of global valueiables that have already been created by `FuncEnvironment::make_global`.
globals: HashMap<GlobalIndex, GlobalValue>,
// Map of heaps that have been created by `FuncEnvironment::make_heap`.
@@ -272,7 +272,7 @@ impl TranslationState {
/// Methods for handling entity references.
impl TranslationState {
/// Get the `GlobalVar` reference that should be used to access the global variable `index`.
/// Get the `GlobalValue` reference that should be used to access the global valueiable `index`.
/// Create the reference if necessary.
/// Also return the WebAssembly type of the global.
pub fn get_global<FE: FuncEnvironment + ?Sized>(

View File

@@ -7,7 +7,7 @@ use wasmparser;
pub type FunctionIndex = usize;
/// Index of a table (imported or defined) inside the WebAssembly module.
pub type TableIndex = usize;
/// Index of a global variable (imported or defined) inside the WebAssembly module.
/// Index of a global valueiable (imported or defined) inside the WebAssembly module.
pub type GlobalIndex = usize;
/// Index of a linear memory (imported or defined) inside the WebAssembly module.
pub type MemoryIndex = usize;