mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 14:54:47 +00:00
Adjust relocation offset to account for inserts, preamble, function offset, etc.
This commit is contained in:
parent
1def56ea04
commit
f066adbe05
5 changed files with 141 additions and 70 deletions
|
@ -44,7 +44,7 @@ pub fn build_module<'a>(
|
|||
env: &'a Env,
|
||||
procedures: MutMap<(Symbol, ProcLayout<'a>), Proc<'a>>,
|
||||
) -> Result<std::vec::Vec<u8>, String> {
|
||||
let (builder, code_section_bytes, _) = build_module_help(env, procedures)?;
|
||||
let (builder, code_section_bytes) = build_module_help(env, procedures)?;
|
||||
let mut module = builder.build();
|
||||
replace_code_section(&mut module, code_section_bytes);
|
||||
|
||||
|
@ -56,13 +56,11 @@ pub fn build_module<'a>(
|
|||
pub fn build_module_help<'a>(
|
||||
env: &'a Env,
|
||||
procedures: MutMap<(Symbol, ProcLayout<'a>), Proc<'a>>,
|
||||
) -> Result<(builder::ModuleBuilder, std::vec::Vec<u8>, u32), String> {
|
||||
) -> Result<(builder::ModuleBuilder, std::vec::Vec<u8>), String> {
|
||||
let proc_symbols = Vec::from_iter_in(procedures.keys().map(|(sym, _)| *sym), env.arena);
|
||||
let mut backend = WasmBackend::new(env, proc_symbols);
|
||||
let mut layout_ids = LayoutIds::default();
|
||||
|
||||
let mut main_function_index = None;
|
||||
|
||||
for ((sym, layout), proc) in procedures.into_iter() {
|
||||
let function_index = backend.build_proc(proc, sym)?;
|
||||
if env.exposed_to_host.contains(&sym) {
|
||||
|
@ -76,12 +74,9 @@ pub fn build_module_help<'a>(
|
|||
.build();
|
||||
|
||||
backend.module_builder.push_export(export);
|
||||
main_function_index = Some(function_index);
|
||||
}
|
||||
}
|
||||
|
||||
main_function_index.ok_or(format!("No functions exposed to host"))?;
|
||||
|
||||
// Update code section length
|
||||
let inner_length = (backend.code_section_bytes.len() - 5) as u32;
|
||||
overwrite_padded_u32(&mut backend.code_section_bytes[0..5], inner_length);
|
||||
|
@ -106,11 +101,7 @@ pub fn build_module_help<'a>(
|
|||
.build();
|
||||
backend.module_builder.push_global(stack_pointer_global);
|
||||
|
||||
Ok((
|
||||
backend.module_builder,
|
||||
backend.code_section_bytes,
|
||||
main_function_index.unwrap(),
|
||||
))
|
||||
Ok((backend.module_builder, backend.code_section_bytes))
|
||||
}
|
||||
|
||||
/// Replace parity-wasm's code section with our own handmade one
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue