cranelift-wasm: Remove ModuleTranslationState (#5365)
* cranelift-wasm: Remove `ModuleTranslationState` We were putting data into it, but never reading data out of it. Can be removed. * cranelift-wasm: move `funct_state.rs` sub module to `state.rs` Since it is the only submodule of `state` it can just be the whole `state` module.
This commit is contained in:
@@ -61,8 +61,7 @@ pub use crate::environ::{
|
||||
};
|
||||
pub use crate::func_translator::FuncTranslator;
|
||||
pub use crate::module_translator::translate_module;
|
||||
pub use crate::state::func_state::FuncTranslationState;
|
||||
pub use crate::state::module_state::ModuleTranslationState;
|
||||
pub use crate::state::FuncTranslationState;
|
||||
pub use crate::translation_utils::*;
|
||||
pub use cranelift_frontend::FunctionBuilder;
|
||||
pub use wasmtime_types::*;
|
||||
|
||||
@@ -6,7 +6,6 @@ use crate::sections_translator::{
|
||||
parse_global_section, parse_import_section, parse_memory_section, parse_name_section,
|
||||
parse_start_section, parse_table_section, parse_tag_section, parse_type_section,
|
||||
};
|
||||
use crate::state::ModuleTranslationState;
|
||||
use crate::WasmResult;
|
||||
use cranelift_codegen::timing;
|
||||
use std::prelude::v1::*;
|
||||
@@ -17,9 +16,8 @@ use wasmparser::{NameSectionReader, Parser, Payload, Validator};
|
||||
pub fn translate_module<'data>(
|
||||
data: &'data [u8],
|
||||
environ: &mut dyn ModuleEnvironment<'data>,
|
||||
) -> WasmResult<ModuleTranslationState> {
|
||||
) -> WasmResult<()> {
|
||||
let _tt = timing::wasm_translate_module();
|
||||
let mut module_translation_state = ModuleTranslationState::new();
|
||||
let mut validator = Validator::new_with_features(environ.wasm_features());
|
||||
|
||||
for payload in Parser::new(0).parse_all(data) {
|
||||
@@ -37,7 +35,7 @@ pub fn translate_module<'data>(
|
||||
|
||||
Payload::TypeSection(types) => {
|
||||
validator.type_section(&types)?;
|
||||
parse_type_section(types, &mut module_translation_state, environ)?;
|
||||
parse_type_section(types, environ)?;
|
||||
}
|
||||
|
||||
Payload::ImportSection(imports) => {
|
||||
@@ -127,5 +125,5 @@ pub fn translate_module<'data>(
|
||||
}
|
||||
}
|
||||
|
||||
Ok(module_translation_state)
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
//! is handled, according to the semantics of WebAssembly, to only specific expressions that are
|
||||
//! interpreted on the fly.
|
||||
use crate::environ::ModuleEnvironment;
|
||||
use crate::state::ModuleTranslationState;
|
||||
use crate::wasm_unsupported;
|
||||
use crate::{
|
||||
DataIndex, ElemIndex, FuncIndex, Global, GlobalIndex, GlobalInit, Memory, MemoryIndex, Table,
|
||||
@@ -64,21 +63,15 @@ fn global(ty: GlobalType, initializer: GlobalInit) -> WasmResult<Global> {
|
||||
/// Parses the Type section of the wasm module.
|
||||
pub fn parse_type_section<'a>(
|
||||
types: TypeSectionReader<'a>,
|
||||
module_translation_state: &mut ModuleTranslationState,
|
||||
environ: &mut dyn ModuleEnvironment<'a>,
|
||||
) -> WasmResult<()> {
|
||||
let count = types.get_count();
|
||||
module_translation_state.wasm_types.reserve(count as usize);
|
||||
environ.reserve_types(count)?;
|
||||
|
||||
for entry in types {
|
||||
match entry? {
|
||||
Type::Func(wasm_func_ty) => {
|
||||
environ.declare_type_func(wasm_func_ty.clone().try_into()?)?;
|
||||
module_translation_state.wasm_types.push((
|
||||
wasm_func_ty.params().to_vec().into(),
|
||||
wasm_func_ty.results().to_vec().into(),
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
//! WebAssembly module and function translation state.
|
||||
//!
|
||||
//! The `ModuleTranslationState` struct defined in this module is used to keep track of data about
|
||||
//! the whole WebAssembly module, such as the decoded type signatures.
|
||||
//!
|
||||
//! The `FuncTranslationState` struct defined in this module is used to keep track of the WebAssembly
|
||||
//! value and control stacks during the translation of a single function.
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
//! WebAssembly module and function translation state.
|
||||
//!
|
||||
//! The `ModuleTranslationState` struct defined in this module is used to keep track of data about
|
||||
//! the whole WebAssembly module, such as the decoded type signatures.
|
||||
//!
|
||||
//! The `FuncTranslationState` struct defined in this module is used to keep track of the WebAssembly
|
||||
//! value and control stacks during the translation of a single function.
|
||||
|
||||
pub(crate) mod func_state;
|
||||
pub(crate) mod module_state;
|
||||
|
||||
// Re-export for convenience.
|
||||
pub(crate) use func_state::*;
|
||||
pub(crate) use module_state::*;
|
||||
@@ -1,31 +0,0 @@
|
||||
use crate::SignatureIndex;
|
||||
use cranelift_entity::PrimaryMap;
|
||||
use std::boxed::Box;
|
||||
|
||||
/// Map of signatures to a function's parameter and return types.
|
||||
pub(crate) type WasmTypes =
|
||||
PrimaryMap<SignatureIndex, (Box<[wasmparser::ValType]>, Box<[wasmparser::ValType]>)>;
|
||||
|
||||
/// Contains information decoded from the Wasm module that must be referenced
|
||||
/// during each Wasm function's translation.
|
||||
///
|
||||
/// This is only for data that is maintained by `cranelift-wasm` itself, as
|
||||
/// opposed to being maintained by the embedder. Data that is maintained by the
|
||||
/// embedder is represented with `ModuleEnvironment`.
|
||||
#[derive(Debug)]
|
||||
pub struct ModuleTranslationState {
|
||||
/// A map containing a Wasm module's original, raw signatures.
|
||||
///
|
||||
/// This is used for translating multi-value Wasm blocks inside functions,
|
||||
/// which are encoded to refer to their type signature via index.
|
||||
pub(crate) wasm_types: WasmTypes,
|
||||
}
|
||||
|
||||
impl ModuleTranslationState {
|
||||
/// Creates a new empty ModuleTranslationState.
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
wasm_types: PrimaryMap::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user