Re-index all internal functions to make room for imported external functions

Linked external functions must be declared in the Import section,
and they must come first in the function index space.
In other words, internal function numbers start at the number of imports.

However we don't know in advance how many builtins the code may call,
and we don't want to add more passes over the full IR. Instead we re-index
function references at the end of code generation.
This commit is contained in:
Brian Carroll 2021-11-08 15:01:30 +00:00
parent 141480aa8d
commit d0ffaabe83
6 changed files with 197 additions and 44 deletions

View file

@ -34,7 +34,7 @@ pub fn build_module<'a>(
) -> Result<std::vec::Vec<u8>, String> {
let mut wasm_module = build_module_help(env, procedures)?;
let mut buffer = std::vec::Vec::with_capacity(4096);
wasm_module.serialize(&mut buffer);
wasm_module.serialize_mut(&mut buffer);
Ok(buffer)
}