Don't re-parse wasm for debuginfo (#2085)
* Don't re-parse wasm for debuginfo This commit updates debuginfo parsing to happen during the main translation of the original wasm module. This avoid re-parsing the wasm module twice (at least the section-level headers). Additionally this ties debuginfo directly to a `ModuleTranslation` which makes it easier to process debuginfo for nested modules in the upcoming module linking proposal. The changes here are summarized by taking the `read_debuginfo` function and merging it with the main module translation that happens which is driven by cranelift. Some new hooks were added to the module environment trait to support this, but most of it was integrating with existing hooks. * Fix tests in debug crate
This commit is contained in:
@@ -66,6 +66,20 @@ impl TryFrom<wasmparser::Type> for WasmType {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<WasmType> for wasmparser::Type {
|
||||
fn from(ty: WasmType) -> wasmparser::Type {
|
||||
match ty {
|
||||
WasmType::I32 => wasmparser::Type::I32,
|
||||
WasmType::I64 => wasmparser::Type::I64,
|
||||
WasmType::F32 => wasmparser::Type::F32,
|
||||
WasmType::F64 => wasmparser::Type::F64,
|
||||
WasmType::V128 => wasmparser::Type::V128,
|
||||
WasmType::FuncRef => wasmparser::Type::FuncRef,
|
||||
WasmType::ExternRef => wasmparser::Type::ExternRef,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// WebAssembly function type -- equivalent of `wasmparser`'s FuncType.
|
||||
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
|
||||
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
|
||||
@@ -743,10 +757,13 @@ pub trait ModuleEnvironment<'data>: TargetEnvironment {
|
||||
/// Declare a passive data segment.
|
||||
fn declare_passive_data(&mut self, data_index: DataIndex, data: &'data [u8]) -> WasmResult<()>;
|
||||
|
||||
/// Indicates how many functions the code section reports and the byte
|
||||
/// offset of where the code sections starts.
|
||||
fn reserve_function_bodies(&mut self, bodies: u32, code_section_offset: u64) {
|
||||
drop((bodies, code_section_offset));
|
||||
}
|
||||
|
||||
/// Provides the contents of a function body.
|
||||
///
|
||||
/// Note there's no `reserve_function_bodies` function because the number of
|
||||
/// functions is already provided by `reserve_func_types`.
|
||||
fn define_function_body(
|
||||
&mut self,
|
||||
module_translation_state: &ModuleTranslationState,
|
||||
@@ -773,16 +790,19 @@ pub trait ModuleEnvironment<'data>: TargetEnvironment {
|
||||
///
|
||||
/// By default this does nothing, but implementations can use this to read
|
||||
/// the module name subsection of the custom name section if desired.
|
||||
fn declare_module_name(&mut self, _name: &'data str) -> WasmResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
fn declare_module_name(&mut self, _name: &'data str) {}
|
||||
|
||||
/// Declares the name of a function to the environment.
|
||||
///
|
||||
/// By default this does nothing, but implementations can use this to read
|
||||
/// the function name subsection of the custom name section if desired.
|
||||
fn declare_func_name(&mut self, _func_index: FuncIndex, _name: &'data str) -> WasmResult<()> {
|
||||
Ok(())
|
||||
fn declare_func_name(&mut self, _func_index: FuncIndex, _name: &'data str) {}
|
||||
|
||||
/// Declares the name of a function's local to the environment.
|
||||
///
|
||||
/// By default this does nothing, but implementations can use this to read
|
||||
/// the local name subsection of the custom name section if desired.
|
||||
fn declare_local_name(&mut self, _func_index: FuncIndex, _local_index: u32, _name: &'data str) {
|
||||
}
|
||||
|
||||
/// Indicates that a custom section has been found in the wasm file
|
||||
|
||||
Reference in New Issue
Block a user