Say "Global Variable" when referring to the WebAssembly concept.

This helps avoid confusion between wasm global variables and cretonne
global values.
This commit is contained in:
Dan Gohman
2018-06-26 14:03:22 -07:00
parent 8f3c49bc6c
commit 7a55a107ae
8 changed files with 26 additions and 24 deletions

View File

@@ -27,7 +27,7 @@ use cretonne_codegen::ir::types::*;
use cretonne_codegen::ir::{self, InstBuilder, JumpTableData, MemFlags}; use cretonne_codegen::ir::{self, InstBuilder, JumpTableData, MemFlags};
use cretonne_codegen::packed_option::ReservedValue; use cretonne_codegen::packed_option::ReservedValue;
use cretonne_frontend::{FunctionBuilder, Variable}; use cretonne_frontend::{FunctionBuilder, Variable};
use environ::{FuncEnvironment, GlobalValue, WasmError, WasmResult}; use environ::{FuncEnvironment, GlobalVariable, WasmError, WasmResult};
use state::{ControlStackFrame, TranslationState}; use state::{ControlStackFrame, TranslationState};
use std::collections::{hash_map, HashMap}; use std::collections::{hash_map, HashMap};
use std::vec::Vec; use std::vec::Vec;
@@ -72,8 +72,8 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
***********************************************************************************/ ***********************************************************************************/
Operator::GetGlobal { global_index } => { Operator::GetGlobal { global_index } => {
let val = match state.get_global(builder.func, global_index, environ) { let val = match state.get_global(builder.func, global_index, environ) {
GlobalValue::Const(val) => val, GlobalVariable::Const(val) => val,
GlobalValue::Memory { gv, ty } => { GlobalVariable::Memory { gv, ty } => {
let addr = builder.ins().global_value(environ.native_pointer(), gv); let addr = builder.ins().global_value(environ.native_pointer(), gv);
let mut flags = ir::MemFlags::new(); let mut flags = ir::MemFlags::new();
flags.set_notrap(); flags.set_notrap();
@@ -85,8 +85,8 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
} }
Operator::SetGlobal { global_index } => { Operator::SetGlobal { global_index } => {
match state.get_global(builder.func, global_index, environ) { match state.get_global(builder.func, global_index, environ) {
GlobalValue::Const(_) => panic!("global #{} is a constant", global_index), GlobalVariable::Const(_) => panic!("global #{} is a constant", global_index),
GlobalValue::Memory { gv, .. } => { GlobalVariable::Memory { gv, .. } => {
let addr = builder.ins().global_value(environ.native_pointer(), gv); let addr = builder.ins().global_value(environ.native_pointer(), gv);
let mut flags = ir::MemFlags::new(); let mut flags = ir::MemFlags::new();
flags.set_notrap(); flags.set_notrap();

View File

@@ -4,7 +4,7 @@ use cretonne_codegen::cursor::FuncCursor;
use cretonne_codegen::ir::types::*; use cretonne_codegen::ir::types::*;
use cretonne_codegen::ir::{self, InstBuilder}; use cretonne_codegen::ir::{self, InstBuilder};
use cretonne_codegen::settings; use cretonne_codegen::settings;
use environ::{FuncEnvironment, GlobalValue, ModuleEnvironment, WasmResult}; use environ::{FuncEnvironment, GlobalVariable, ModuleEnvironment, WasmResult};
use func_translator::FuncTranslator; use func_translator::FuncTranslator;
use std::string::String; use std::string::String;
use std::vec::Vec; use std::vec::Vec;
@@ -157,11 +157,11 @@ impl<'dummy_environment> FuncEnvironment for DummyFuncEnvironment<'dummy_environ
&self.mod_info.flags &self.mod_info.flags
} }
fn make_global(&mut self, func: &mut ir::Function, index: GlobalIndex) -> GlobalValue { fn make_global(&mut self, func: &mut ir::Function, index: GlobalIndex) -> GlobalVariable {
// Just create a dummy `vmctx` global. // Just create a dummy `vmctx` global.
let offset = ((index * 8) as i32 + 8).into(); let offset = ((index * 8) as i32 + 8).into();
let gv = func.create_global_value(ir::GlobalValueData::VMContext { offset }); let gv = func.create_global_value(ir::GlobalValueData::VMContext { offset });
GlobalValue::Memory { GlobalVariable::Memory {
gv, gv,
ty: self.mod_info.globals[index].entity.ty, ty: self.mod_info.globals[index].entity.ty,
} }

View File

@@ -4,4 +4,6 @@ mod dummy;
mod spec; mod spec;
pub use environ::dummy::DummyEnvironment; pub use environ::dummy::DummyEnvironment;
pub use environ::spec::{FuncEnvironment, GlobalValue, ModuleEnvironment, WasmError, WasmResult}; pub use environ::spec::{
FuncEnvironment, GlobalVariable, ModuleEnvironment, WasmError, WasmResult,
};

View File

@@ -10,17 +10,17 @@ use translation_utils::{
}; };
use wasmparser::BinaryReaderError; use wasmparser::BinaryReaderError;
/// The value of a WebAssembly global value. /// The value of a WebAssembly global variable.
#[derive(Clone, Copy)] #[derive(Clone, Copy)]
pub enum GlobalValue { pub enum GlobalVariable {
/// This is a constant global with a value known at compile time. /// This is a constant global with a value known at compile time.
Const(ir::Value), Const(ir::Value),
/// This is a variable in memory that should be referenced as a `GlobalValue`. /// This is a variable in memory that should be referenced through a `GlobalValue`.
Memory { Memory {
/// Which global value should be referenced. /// The address of the global variable storage.
gv: ir::GlobalValue, gv: ir::GlobalValue,
/// The global value's type. /// The global variable's type.
ty: ir::Type, ty: ir::Type,
}, },
} }
@@ -89,14 +89,14 @@ pub trait FuncEnvironment {
ir::Type::int(u16::from(self.triple().pointer_width().unwrap().bits())).unwrap() ir::Type::int(u16::from(self.triple().pointer_width().unwrap().bits())).unwrap()
} }
/// Set up the necessary preamble definitions in `func` to access the global value /// Set up the necessary preamble definitions in `func` to access the global variable
/// identified by `index`. /// identified by `index`.
/// ///
/// The index space covers both imported globals and globals defined by the module. /// 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 variable reference that should be used to access the global and the
/// WebAssembly type of the global. /// WebAssembly type of the global.
fn make_global(&mut self, func: &mut ir::Function, index: GlobalIndex) -> GlobalValue; fn make_global(&mut self, func: &mut ir::Function, index: GlobalIndex) -> GlobalVariable;
/// Set up the necessary preamble definitions in `func` to access the linear memory identified /// Set up the necessary preamble definitions in `func` to access the linear memory identified
/// by `index`. /// by `index`.

View File

@@ -43,7 +43,7 @@ mod state;
mod translation_utils; mod translation_utils;
pub use environ::{ pub use environ::{
DummyEnvironment, FuncEnvironment, GlobalValue, ModuleEnvironment, WasmError, WasmResult, DummyEnvironment, FuncEnvironment, GlobalVariable, ModuleEnvironment, WasmError, WasmResult,
}; };
pub use func_translator::FuncTranslator; pub use func_translator::FuncTranslator;
pub use module_translator::translate_module; pub use module_translator::translate_module;

View File

@@ -4,7 +4,7 @@
//! The code of theses helper function is straightforward since it is only about reading metadata //! 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. //! 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 values //! The special case of the initialize expressions for table elements offsets or global variables
//! is handled, according to the semantics of WebAssembly, to only specific expressions that are //! is handled, according to the semantics of WebAssembly, to only specific expressions that are
//! interpreted on the fly. //! interpreted on the fly.
use cretonne_codegen::ir::{self, AbiParam, Signature}; use cretonne_codegen::ir::{self, AbiParam, Signature};

View File

@@ -4,7 +4,7 @@
//! value and control stacks during the translation of a single function. //! value and control stacks during the translation of a single function.
use cretonne_codegen::ir::{self, Ebb, Inst, Value}; use cretonne_codegen::ir::{self, Ebb, Inst, Value};
use environ::{FuncEnvironment, GlobalValue}; use environ::{FuncEnvironment, GlobalVariable};
use std::collections::HashMap; use std::collections::HashMap;
use std::vec::Vec; use std::vec::Vec;
use translation_utils::{FunctionIndex, GlobalIndex, MemoryIndex, SignatureIndex}; use translation_utils::{FunctionIndex, GlobalIndex, MemoryIndex, SignatureIndex};
@@ -134,8 +134,8 @@ pub struct TranslationState {
pub control_stack: Vec<ControlStackFrame>, pub control_stack: Vec<ControlStackFrame>,
pub reachable: bool, pub reachable: bool,
// Map of global values that have already been created by `FuncEnvironment::make_global`. // Map of global variables that have already been created by `FuncEnvironment::make_global`.
globals: HashMap<GlobalIndex, GlobalValue>, globals: HashMap<GlobalIndex, GlobalVariable>,
// Map of heaps that have been created by `FuncEnvironment::make_heap`. // Map of heaps that have been created by `FuncEnvironment::make_heap`.
heaps: HashMap<MemoryIndex, ir::Heap>, heaps: HashMap<MemoryIndex, ir::Heap>,
@@ -272,7 +272,7 @@ impl TranslationState {
/// Methods for handling entity references. /// Methods for handling entity references.
impl TranslationState { impl TranslationState {
/// Get the `GlobalValue` reference that should be used to access the global value `index`. /// Get the `GlobalVariable` reference that should be used to access the global variable `index`.
/// Create the reference if necessary. /// Create the reference if necessary.
/// Also return the WebAssembly type of the global. /// Also return the WebAssembly type of the global.
pub fn get_global<FE: FuncEnvironment + ?Sized>( pub fn get_global<FE: FuncEnvironment + ?Sized>(
@@ -280,7 +280,7 @@ impl TranslationState {
func: &mut ir::Function, func: &mut ir::Function,
index: u32, index: u32,
environ: &mut FE, environ: &mut FE,
) -> GlobalValue { ) -> GlobalVariable {
let index = index as GlobalIndex; let index = index as GlobalIndex;
*self.globals *self.globals
.entry(index) .entry(index)

View File

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