mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 14:24:45 +00:00
Wasm: adjust function indices for preloading
This commit is contained in:
parent
9f0e0d5099
commit
9f8f31b2b6
2 changed files with 10 additions and 5 deletions
|
@ -539,14 +539,16 @@ impl<'a> WasmBackend<'a> {
|
|||
CallConv::C,
|
||||
);
|
||||
|
||||
for (func_index, (ir_sym, linker_sym_index)) in
|
||||
for (roc_proc_index, (ir_sym, linker_sym_index)) in
|
||||
self.proc_symbols.iter().enumerate()
|
||||
{
|
||||
let wasm_fn_index =
|
||||
self.module.code.preloaded_count + roc_proc_index as u32;
|
||||
if ir_sym == func_sym {
|
||||
let num_wasm_args = param_types.len();
|
||||
let has_return_val = ret_type.is_some();
|
||||
self.code_builder.call(
|
||||
func_index as u32,
|
||||
wasm_fn_index,
|
||||
*linker_sym_index,
|
||||
num_wasm_args,
|
||||
has_return_val,
|
||||
|
|
|
@ -58,7 +58,7 @@ pub fn build_module_help<'a>(
|
|||
let mut proc_symbols = Vec::with_capacity_in(procedures.len() * 2, env.arena);
|
||||
let mut linker_symbols = Vec::with_capacity_in(procedures.len() * 2, env.arena);
|
||||
let mut exports = Vec::with_capacity_in(4, env.arena);
|
||||
let mut main_fn_index = None;
|
||||
let mut maybe_main_fn_index = None;
|
||||
|
||||
// Collect the symbols & names for the procedures,
|
||||
// and filter out procs we're going to inline
|
||||
|
@ -92,12 +92,15 @@ pub fn build_module_help<'a>(
|
|||
fn_index += 1;
|
||||
}
|
||||
|
||||
let initial_module = WasmModule::preload(env.arena, preload_bytes);
|
||||
let main_function_index = maybe_main_fn_index.unwrap() + initial_module.code.preloaded_count;
|
||||
|
||||
let mut backend = WasmBackend::new(
|
||||
env,
|
||||
interns,
|
||||
layout_ids,
|
||||
proc_symbols,
|
||||
WasmModule::preload(env.arena, preload_bytes),
|
||||
initial_module,
|
||||
CodeGenHelp::new(env.arena, IntWidth::I32, env.module_id),
|
||||
);
|
||||
|
||||
|
@ -134,7 +137,7 @@ pub fn build_module_help<'a>(
|
|||
|
||||
let module = backend.into_module();
|
||||
|
||||
Ok((module, main_fn_index.unwrap()))
|
||||
Ok((module, main_function_index))
|
||||
}
|
||||
|
||||
pub struct CopyMemoryConfig {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue