Rename "runtime" to "environment".
This commit is contained in:
@@ -11,7 +11,8 @@
|
|||||||
//! Another data structure, the translation state, records information concerning unreachable code
|
//! 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.
|
//! 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 loads and stores need the memory base address;
|
||||||
//! - the `get_global` et `set_global` instructions depends on how the globals are implemented;
|
//! - 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 translation_utils::{TableIndex, SignatureIndex, FunctionIndex, MemoryIndex};
|
||||||
use state::{TranslationState, ControlStackFrame};
|
use state::{TranslationState, ControlStackFrame};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use runtime::{FuncEnvironment, GlobalValue};
|
use environ::{FuncEnvironment, GlobalValue};
|
||||||
use std::u32;
|
use std::u32;
|
||||||
|
|
||||||
/// Translates wasm operators into Cretonne IL instructions. Returns `true` if it inserted
|
/// Translates wasm operators into Cretonne IL instructions. Returns `true` if it inserted
|
||||||
@@ -61,7 +62,7 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
|
|||||||
builder.def_var(Local(local_index), val);
|
builder.def_var(Local(local_index), val);
|
||||||
}
|
}
|
||||||
/********************************** Globals ****************************************
|
/********************************** 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 } => {
|
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) {
|
||||||
@@ -349,7 +350,7 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
|
|||||||
}
|
}
|
||||||
/************************************ Calls ****************************************
|
/************************************ Calls ****************************************
|
||||||
* The call instructions pop off their arguments from the stack and append their
|
* 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.
|
* argument referring to an index in the external functions table of the module.
|
||||||
************************************************************************************/
|
************************************************************************************/
|
||||||
Operator::Call { function_index } => {
|
Operator::Call { function_index } => {
|
||||||
@@ -380,7 +381,7 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
|
|||||||
state.pushn(builder.func.dfg.inst_results(call));
|
state.pushn(builder.func.dfg.inst_results(call));
|
||||||
}
|
}
|
||||||
/******************************* Memory management ***********************************
|
/******************************* 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.
|
* special functions.
|
||||||
************************************************************************************/
|
************************************************************************************/
|
||||||
Operator::GrowMemory { reserved } => {
|
Operator::GrowMemory { reserved } => {
|
||||||
@@ -407,7 +408,7 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
|
|||||||
}
|
}
|
||||||
/******************************* Load instructions ***********************************
|
/******************************* Load instructions ***********************************
|
||||||
* Wasm specifies an integer alignment flag but we drop it in Cretonne.
|
* 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
|
* TODO: differentiate between 32 bit and 64 bit architecture, to put the uextend or not
|
||||||
************************************************************************************/
|
************************************************************************************/
|
||||||
Operator::I32Load8U { memarg: MemoryImmediate { flags: _, offset } } => {
|
Operator::I32Load8U { memarg: MemoryImmediate { flags: _, offset } } => {
|
||||||
@@ -454,7 +455,7 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
|
|||||||
}
|
}
|
||||||
/****************************** Store instructions ***********************************
|
/****************************** Store instructions ***********************************
|
||||||
* Wasm specifies an integer alignment flag but we drop it in Cretonne.
|
* 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
|
* TODO: differentiate between 32 bit and 64 bit architecture, to put the uextend or not
|
||||||
************************************************************************************/
|
************************************************************************************/
|
||||||
Operator::I32Store { memarg: MemoryImmediate { flags: _, offset } } |
|
Operator::I32Store { memarg: MemoryImmediate { flags: _, offset } } |
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use runtime::{FuncEnvironment, GlobalValue, ModuleEnvironment};
|
use environ::{FuncEnvironment, GlobalValue, ModuleEnvironment};
|
||||||
use translation_utils::{Global, Memory, Table, GlobalIndex, TableIndex, SignatureIndex,
|
use translation_utils::{Global, Memory, Table, GlobalIndex, TableIndex, SignatureIndex,
|
||||||
FunctionIndex, MemoryIndex};
|
FunctionIndex, MemoryIndex};
|
||||||
use func_translator::FuncTranslator;
|
use func_translator::FuncTranslator;
|
||||||
@@ -65,7 +65,7 @@ pub struct DummyModuleInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl 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 {
|
pub fn with_flags(flags: settings::Flags) -> Self {
|
||||||
Self {
|
Self {
|
||||||
flags,
|
flags,
|
||||||
@@ -81,9 +81,9 @@ impl DummyModuleInfo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This runtime implementation is a "naïve" one, doing essentially nothing and emitting
|
/// This `ModuleEnvironment` implementation is a "naïve" one, doing essentially nothing and
|
||||||
/// placeholders when forced to. Don't try to execute code translated with this runtime, it is
|
/// emitting placeholders when forced to. Don't try to execute code translated for this
|
||||||
/// essentially here for translation debug purposes.
|
/// environment, essentially here for translation debug purposes.
|
||||||
pub struct DummyEnvironment {
|
pub struct DummyEnvironment {
|
||||||
/// Module information.
|
/// Module information.
|
||||||
pub info: DummyModuleInfo,
|
pub info: DummyModuleInfo,
|
||||||
@@ -93,12 +93,12 @@ pub struct DummyEnvironment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl DummyEnvironment {
|
impl DummyEnvironment {
|
||||||
/// Allocates the runtime data structures with default flags.
|
/// Allocates the data structures with default flags.
|
||||||
pub fn default() -> Self {
|
pub fn default() -> Self {
|
||||||
Self::with_flags(settings::Flags::new(&settings::builder()))
|
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 {
|
pub fn with_flags(flags: settings::Flags) -> Self {
|
||||||
Self {
|
Self {
|
||||||
info: DummyModuleInfo::with_flags(flags),
|
info: DummyModuleInfo::with_flags(flags),
|
||||||
5
lib/wasm/src/environ/mod.rs
Normal file
5
lib/wasm/src/environ/mod.rs
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
mod spec;
|
||||||
|
mod dummy;
|
||||||
|
|
||||||
|
pub use environ::spec::{ModuleEnvironment, FuncEnvironment, GlobalValue};
|
||||||
|
pub use environ::dummy::DummyEnvironment;
|
||||||
@@ -9,7 +9,7 @@ use cretonne::entity::EntityRef;
|
|||||||
use cretonne::ir::{self, InstBuilder};
|
use cretonne::ir::{self, InstBuilder};
|
||||||
use cretonne::result::{CtonResult, CtonError};
|
use cretonne::result::{CtonResult, CtonError};
|
||||||
use cton_frontend::{ILBuilder, FunctionBuilder};
|
use cton_frontend::{ILBuilder, FunctionBuilder};
|
||||||
use runtime::FuncEnvironment;
|
use environ::FuncEnvironment;
|
||||||
use state::TranslationState;
|
use state::TranslationState;
|
||||||
use translation_utils::Local;
|
use translation_utils::Local;
|
||||||
use wasmparser::{self, BinaryReader};
|
use wasmparser::{self, BinaryReader};
|
||||||
@@ -233,7 +233,7 @@ fn cur_srcloc(reader: &BinaryReader) -> ir::SourceLoc {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use cretonne::{ir, Context};
|
use cretonne::{ir, Context};
|
||||||
use cretonne::ir::types::I32;
|
use cretonne::ir::types::I32;
|
||||||
use runtime::{DummyEnvironment, FuncEnvironment};
|
use environ::{DummyEnvironment, FuncEnvironment};
|
||||||
use super::FuncTranslator;
|
use super::FuncTranslator;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
//! Performs the translation from a wasm module in binary format to the in-memory representation
|
//! 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
|
//! 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.
|
//! trait to deal with tables, globals and linear memory.
|
||||||
//!
|
//!
|
||||||
//! The crate provides a `DummyEnvironment` struct that will allow to translate the code of the
|
//! 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 code_translator;
|
||||||
mod func_translator;
|
mod func_translator;
|
||||||
mod module_translator;
|
mod module_translator;
|
||||||
mod runtime;
|
mod environ;
|
||||||
mod sections_translator;
|
mod sections_translator;
|
||||||
mod state;
|
mod state;
|
||||||
mod translation_utils;
|
mod translation_utils;
|
||||||
|
|
||||||
pub use func_translator::FuncTranslator;
|
pub use func_translator::FuncTranslator;
|
||||||
pub use module_translator::translate_module;
|
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,
|
pub use translation_utils::{FunctionIndex, GlobalIndex, TableIndex, MemoryIndex, SignatureIndex,
|
||||||
Global, GlobalInit, Table, Memory};
|
Global, GlobalInit, Table, Memory};
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use sections_translator::{SectionParsingError, parse_function_signatures, parse_
|
|||||||
parse_function_section, parse_export_section, parse_start_section,
|
parse_function_section, parse_export_section, parse_start_section,
|
||||||
parse_memory_section, parse_global_section, parse_table_section,
|
parse_memory_section, parse_global_section, parse_table_section,
|
||||||
parse_elements_section, parse_data_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
|
/// Translate a sequence of bytes forming a valid Wasm binary into a list of valid Cretonne IL
|
||||||
/// [`Function`](../cretonne/ir/function/struct.Function.html).
|
/// [`Function`](../cretonne/ir/function/struct.Function.html).
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
mod spec;
|
|
||||||
mod dummy;
|
|
||||||
|
|
||||||
pub use runtime::spec::{ModuleEnvironment, FuncEnvironment, GlobalValue};
|
|
||||||
pub use runtime::dummy::DummyEnvironment;
|
|
||||||
@@ -15,7 +15,7 @@ use wasmparser::{Parser, ParserState, FuncType, ImportSectionEntryType, External
|
|||||||
MemoryType, Operator};
|
MemoryType, Operator};
|
||||||
use wasmparser;
|
use wasmparser;
|
||||||
use std::str::from_utf8;
|
use std::str::from_utf8;
|
||||||
use runtime::ModuleEnvironment;
|
use environ::ModuleEnvironment;
|
||||||
|
|
||||||
pub enum SectionParsingError {
|
pub enum SectionParsingError {
|
||||||
WrongSectionContent(String),
|
WrongSectionContent(String),
|
||||||
|
|||||||
@@ -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::ir::{self, Ebb, Inst, Value};
|
use cretonne::ir::{self, Ebb, Inst, Value};
|
||||||
use runtime::{FuncEnvironment, GlobalValue};
|
use environ::{FuncEnvironment, GlobalValue};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use translation_utils::{GlobalIndex, MemoryIndex, SignatureIndex, FunctionIndex};
|
use translation_utils::{GlobalIndex, MemoryIndex, SignatureIndex, FunctionIndex};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user