diff --git a/lib/wasm/src/code_translator.rs b/lib/wasm/src/code_translator.rs index dab7d3a08d..a4a22435ae 100644 --- a/lib/wasm/src/code_translator.rs +++ b/lib/wasm/src/code_translator.rs @@ -11,7 +11,8 @@ //! Another data structure, the translation state, records information concerning unreachable code //! status and about if inserting a return at the end of the function is necessary. //! -//! Some of the WebAssembly instructions need information about the runtime to be translated: +//! Some of the WebAssembly instructions need information about the environment for which they +//! are being translated: //! //! - the loads and stores need the memory base address; //! - the `get_global` et `set_global` instructions depends on how the globals are implemented; @@ -30,7 +31,7 @@ use translation_utils::{f32_translation, f64_translation, type_to_type, num_retu use translation_utils::{TableIndex, SignatureIndex, FunctionIndex, MemoryIndex}; use state::{TranslationState, ControlStackFrame}; use std::collections::HashMap; -use runtime::{FuncEnvironment, GlobalValue}; +use environ::{FuncEnvironment, GlobalValue}; use std::u32; /// Translates wasm operators into Cretonne IL instructions. Returns `true` if it inserted @@ -61,7 +62,7 @@ pub fn translate_operator( builder.def_var(Local(local_index), val); } /********************************** Globals **************************************** - * `get_global` and `set_global` are handled by the runtime. + * `get_global` and `set_global` are handled by the environment. ***********************************************************************************/ Operator::GetGlobal { global_index } => { let val = match state.get_global(builder.func, global_index, environ) { @@ -349,7 +350,7 @@ pub fn translate_operator( } /************************************ Calls **************************************** * The call instructions pop off their arguments from the stack and append their - * return values to it. `call_indirect` needs runtime support because there is an + * return values to it. `call_indirect` needs environment support because there is an * argument referring to an index in the external functions table of the module. ************************************************************************************/ Operator::Call { function_index } => { @@ -380,7 +381,7 @@ pub fn translate_operator( state.pushn(builder.func.dfg.inst_results(call)); } /******************************* Memory management *********************************** - * Memory management is handled by runtime. It is usually translated into calls to + * Memory management is handled by environment. It is usually translated into calls to * special functions. ************************************************************************************/ Operator::GrowMemory { reserved } => { @@ -407,7 +408,7 @@ pub fn translate_operator( } /******************************* Load instructions *********************************** * Wasm specifies an integer alignment flag but we drop it in Cretonne. - * The memory base address is provided by the runtime. + * The memory base address is provided by the environment. * TODO: differentiate between 32 bit and 64 bit architecture, to put the uextend or not ************************************************************************************/ Operator::I32Load8U { memarg: MemoryImmediate { flags: _, offset } } => { @@ -454,7 +455,7 @@ pub fn translate_operator( } /****************************** Store instructions *********************************** * Wasm specifies an integer alignment flag but we drop it in Cretonne. - * The memory base address is provided by the runtime. + * The memory base address is provided by the environment. * TODO: differentiate between 32 bit and 64 bit architecture, to put the uextend or not ************************************************************************************/ Operator::I32Store { memarg: MemoryImmediate { flags: _, offset } } | diff --git a/lib/wasm/src/runtime/dummy.rs b/lib/wasm/src/environ/dummy.rs similarity index 95% rename from lib/wasm/src/runtime/dummy.rs rename to lib/wasm/src/environ/dummy.rs index aab8ed6a4f..b2d4e66151 100644 --- a/lib/wasm/src/runtime/dummy.rs +++ b/lib/wasm/src/environ/dummy.rs @@ -1,4 +1,4 @@ -use runtime::{FuncEnvironment, GlobalValue, ModuleEnvironment}; +use environ::{FuncEnvironment, GlobalValue, ModuleEnvironment}; use translation_utils::{Global, Memory, Table, GlobalIndex, TableIndex, SignatureIndex, FunctionIndex, MemoryIndex}; use func_translator::FuncTranslator; @@ -65,7 +65,7 @@ pub struct DummyModuleInfo { } impl DummyModuleInfo { - /// Allocates the runtime data structures with the given flags. + /// Allocates the data structures with the given flags. pub fn with_flags(flags: settings::Flags) -> Self { Self { flags, @@ -81,9 +81,9 @@ impl DummyModuleInfo { } } -/// This runtime implementation is a "naïve" one, doing essentially nothing and emitting -/// placeholders when forced to. Don't try to execute code translated with this runtime, it is -/// essentially here for translation debug purposes. +/// This `ModuleEnvironment` implementation is a "naïve" one, doing essentially nothing and +/// emitting placeholders when forced to. Don't try to execute code translated for this +/// environment, essentially here for translation debug purposes. pub struct DummyEnvironment { /// Module information. pub info: DummyModuleInfo, @@ -93,12 +93,12 @@ pub struct DummyEnvironment { } impl DummyEnvironment { - /// Allocates the runtime data structures with default flags. + /// Allocates the data structures with default flags. pub fn default() -> Self { Self::with_flags(settings::Flags::new(&settings::builder())) } - /// Allocates the runtime data structures with the given flags. + /// Allocates the data structures with the given flags. pub fn with_flags(flags: settings::Flags) -> Self { Self { info: DummyModuleInfo::with_flags(flags), diff --git a/lib/wasm/src/environ/mod.rs b/lib/wasm/src/environ/mod.rs new file mode 100644 index 0000000000..a31308b135 --- /dev/null +++ b/lib/wasm/src/environ/mod.rs @@ -0,0 +1,5 @@ +mod spec; +mod dummy; + +pub use environ::spec::{ModuleEnvironment, FuncEnvironment, GlobalValue}; +pub use environ::dummy::DummyEnvironment; diff --git a/lib/wasm/src/runtime/spec.rs b/lib/wasm/src/environ/spec.rs similarity index 100% rename from lib/wasm/src/runtime/spec.rs rename to lib/wasm/src/environ/spec.rs diff --git a/lib/wasm/src/func_translator.rs b/lib/wasm/src/func_translator.rs index 9a4395c151..394da6ab36 100644 --- a/lib/wasm/src/func_translator.rs +++ b/lib/wasm/src/func_translator.rs @@ -9,7 +9,7 @@ use cretonne::entity::EntityRef; use cretonne::ir::{self, InstBuilder}; use cretonne::result::{CtonResult, CtonError}; use cton_frontend::{ILBuilder, FunctionBuilder}; -use runtime::FuncEnvironment; +use environ::FuncEnvironment; use state::TranslationState; use translation_utils::Local; use wasmparser::{self, BinaryReader}; @@ -233,7 +233,7 @@ fn cur_srcloc(reader: &BinaryReader) -> ir::SourceLoc { mod tests { use cretonne::{ir, Context}; use cretonne::ir::types::I32; - use runtime::{DummyEnvironment, FuncEnvironment}; + use environ::{DummyEnvironment, FuncEnvironment}; use super::FuncTranslator; #[test] diff --git a/lib/wasm/src/lib.rs b/lib/wasm/src/lib.rs index 5aaee81d25..b5b79049fe 100644 --- a/lib/wasm/src/lib.rs +++ b/lib/wasm/src/lib.rs @@ -1,6 +1,7 @@ //! Performs the translation from a wasm module in binary format to the in-memory representation //! of the Cretonne IL. More particularly, it translates the code of all the functions bodies and -//! interacts with a runtime implementing the [`ModuleEnvironment`](trait.ModuleEnvironment.html) +//! interacts with an environment implementing the +//! [`ModuleEnvironment`](trait.ModuleEnvironment.html) //! trait to deal with tables, globals and linear memory. //! //! The crate provides a `DummyEnvironment` struct that will allow to translate the code of the @@ -18,13 +19,13 @@ extern crate cretonne; mod code_translator; mod func_translator; mod module_translator; -mod runtime; +mod environ; mod sections_translator; mod state; mod translation_utils; pub use func_translator::FuncTranslator; pub use module_translator::translate_module; -pub use runtime::{FuncEnvironment, ModuleEnvironment, DummyEnvironment, GlobalValue}; +pub use environ::{FuncEnvironment, ModuleEnvironment, DummyEnvironment, GlobalValue}; pub use translation_utils::{FunctionIndex, GlobalIndex, TableIndex, MemoryIndex, SignatureIndex, Global, GlobalInit, Table, Memory}; diff --git a/lib/wasm/src/module_translator.rs b/lib/wasm/src/module_translator.rs index ef68350e80..87e38a119c 100644 --- a/lib/wasm/src/module_translator.rs +++ b/lib/wasm/src/module_translator.rs @@ -5,7 +5,7 @@ use sections_translator::{SectionParsingError, parse_function_signatures, parse_ parse_function_section, parse_export_section, parse_start_section, parse_memory_section, parse_global_section, parse_table_section, parse_elements_section, parse_data_section}; -use runtime::ModuleEnvironment; +use environ::ModuleEnvironment; /// Translate a sequence of bytes forming a valid Wasm binary into a list of valid Cretonne IL /// [`Function`](../cretonne/ir/function/struct.Function.html). diff --git a/lib/wasm/src/runtime/mod.rs b/lib/wasm/src/runtime/mod.rs deleted file mode 100644 index abee71b3f8..0000000000 --- a/lib/wasm/src/runtime/mod.rs +++ /dev/null @@ -1,5 +0,0 @@ -mod spec; -mod dummy; - -pub use runtime::spec::{ModuleEnvironment, FuncEnvironment, GlobalValue}; -pub use runtime::dummy::DummyEnvironment; diff --git a/lib/wasm/src/sections_translator.rs b/lib/wasm/src/sections_translator.rs index ecaf3578ba..21ade154ec 100644 --- a/lib/wasm/src/sections_translator.rs +++ b/lib/wasm/src/sections_translator.rs @@ -15,7 +15,7 @@ use wasmparser::{Parser, ParserState, FuncType, ImportSectionEntryType, External MemoryType, Operator}; use wasmparser; use std::str::from_utf8; -use runtime::ModuleEnvironment; +use environ::ModuleEnvironment; pub enum SectionParsingError { WrongSectionContent(String), diff --git a/lib/wasm/src/state.rs b/lib/wasm/src/state.rs index d862e8d9a0..1c9ce6d8cd 100644 --- a/lib/wasm/src/state.rs +++ b/lib/wasm/src/state.rs @@ -4,7 +4,7 @@ //! value and control stacks during the translation of a single function. use cretonne::ir::{self, Ebb, Inst, Value}; -use runtime::{FuncEnvironment, GlobalValue}; +use environ::{FuncEnvironment, GlobalValue}; use std::collections::HashMap; use translation_utils::{GlobalIndex, MemoryIndex, SignatureIndex, FunctionIndex};