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

@ -470,6 +470,18 @@ impl<'a> LinkingSection<'a> {
subsections: Vec::with_capacity_in(1, arena),
}
}
pub fn symbol_table_mut(&mut self) -> &mut Vec<'a, SymInfo> {
for sub in self.subsections.iter_mut() {
match sub {
LinkingSubSection::SymbolTable(syminfos) => {
return syminfos;
}
_ => {}
}
}
panic!("Symbol table not found");
}
}
impl<'a> Serialize for LinkingSection<'a> {