mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 22:34:45 +00:00
Wasm: Parse the Name section, export init_refcount_test, and don't DCE exports
This commit is contained in:
parent
3d00217b53
commit
c7da7ca689
6 changed files with 242 additions and 71 deletions
|
@ -20,11 +20,12 @@ use crate::storage::{StackMemoryLocation, Storage, StoredValue, StoredValueKind}
|
|||
use crate::wasm_module::linking::{DataSymbol, LinkingSegment, WasmObjectSymbol};
|
||||
use crate::wasm_module::sections::{DataMode, DataSegment};
|
||||
use crate::wasm_module::{
|
||||
code_builder, CodeBuilder, LocalId, Signature, SymInfo, ValueType, WasmModule,
|
||||
code_builder, CodeBuilder, Export, ExportType, LocalId, Signature, SymInfo, ValueType,
|
||||
WasmModule,
|
||||
};
|
||||
use crate::{
|
||||
copy_memory, round_up_to_alignment, CopyMemoryConfig, Env, DEBUG_LOG_SETTINGS, PTR_SIZE,
|
||||
PTR_TYPE,
|
||||
copy_memory, round_up_to_alignment, CopyMemoryConfig, Env, DEBUG_LOG_SETTINGS, MEMORY_NAME,
|
||||
PTR_SIZE, PTR_TYPE, STACK_POINTER_GLOBAL_ID, STACK_POINTER_NAME,
|
||||
};
|
||||
|
||||
/// The memory address where the constants data will be loaded during module instantiation.
|
||||
|
@ -41,7 +42,6 @@ pub struct WasmBackend<'a> {
|
|||
layout_ids: LayoutIds<'a>,
|
||||
next_constant_addr: u32,
|
||||
fn_index_offset: u32,
|
||||
preloaded_functions_map: MutMap<&'a [u8], u32>,
|
||||
called_preload_fns: MutSet<u32>,
|
||||
proc_symbols: Vec<'a, (Symbol, u32)>,
|
||||
helper_proc_gen: CodeGenHelp<'a>,
|
||||
|
@ -64,11 +64,21 @@ impl<'a> WasmBackend<'a> {
|
|||
interns: &'a mut Interns,
|
||||
layout_ids: LayoutIds<'a>,
|
||||
proc_symbols: Vec<'a, (Symbol, u32)>,
|
||||
module: WasmModule<'a>,
|
||||
mut module: WasmModule<'a>,
|
||||
fn_index_offset: u32,
|
||||
preloaded_functions_map: MutMap<&'a [u8], u32>,
|
||||
helper_proc_gen: CodeGenHelp<'a>,
|
||||
) -> Self {
|
||||
module.export.append(Export {
|
||||
name: MEMORY_NAME.as_bytes(),
|
||||
ty: ExportType::Mem,
|
||||
index: 0,
|
||||
});
|
||||
module.export.append(Export {
|
||||
name: STACK_POINTER_NAME.as_bytes(),
|
||||
ty: ExportType::Global,
|
||||
index: STACK_POINTER_GLOBAL_ID,
|
||||
});
|
||||
|
||||
WasmBackend {
|
||||
env,
|
||||
interns,
|
||||
|
@ -79,7 +89,6 @@ impl<'a> WasmBackend<'a> {
|
|||
layout_ids,
|
||||
next_constant_addr: CONST_SEGMENT_BASE_ADDR,
|
||||
fn_index_offset,
|
||||
preloaded_functions_map,
|
||||
called_preload_fns: MutSet::default(),
|
||||
proc_symbols,
|
||||
helper_proc_gen,
|
||||
|
@ -117,15 +126,8 @@ impl<'a> WasmBackend<'a> {
|
|||
self.module.linking.symbol_table.push(linker_symbol);
|
||||
}
|
||||
|
||||
pub fn into_module(mut self, remove_dead_preloads: bool) -> WasmModule<'a> {
|
||||
if remove_dead_preloads {
|
||||
self.module.code.remove_dead_preloads(
|
||||
self.env.arena,
|
||||
self.module.import.function_count,
|
||||
self.called_preload_fns,
|
||||
)
|
||||
}
|
||||
self.module
|
||||
pub fn finalize(self) -> (WasmModule<'a>, MutSet<u32>) {
|
||||
(self.module, self.called_preload_fns)
|
||||
}
|
||||
|
||||
/// Register the debug names of Symbols in a global lookup table
|
||||
|
@ -1474,7 +1476,7 @@ impl<'a> WasmBackend<'a> {
|
|||
) {
|
||||
let num_wasm_args = param_types.len();
|
||||
let has_return_val = ret_type.is_some();
|
||||
let fn_index = self.preloaded_functions_map[name.as_bytes()];
|
||||
let fn_index = self.module.names.functions[name.as_bytes()];
|
||||
self.called_preload_fns.insert(fn_index);
|
||||
let linker_symbol_index = u32::MAX;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue