wasm: Add Roc procedure names to Names section for debug

This commit is contained in:
Brian Carroll 2022-03-18 14:46:53 +00:00
parent dca9404772
commit 21ee531e8c
3 changed files with 47 additions and 10 deletions

View file

@ -1,4 +1,5 @@
use bumpalo::{self, collections::Vec};
use std::fmt::Write;
use code_builder::Align;
use roc_builtins::bitcode::IntWidth;
@ -175,6 +176,8 @@ impl<'a> WasmBackend<'a> {
println!("\ngenerating procedure {:?}\n", proc.name);
}
self.append_proc_debug_name(proc.name);
self.start_proc(proc);
self.stmt(&proc.body);
@ -235,6 +238,16 @@ impl<'a> WasmBackend<'a> {
);
}
fn append_proc_debug_name(&mut self, name: Symbol) {
let proc_index = self.proc_lookup.iter().position(|(n, _, _)| *n == name).unwrap();
let wasm_fn_index = self.fn_index_offset + proc_index as u32;
let mut debug_name = bumpalo::collections::String::with_capacity_in(64, self.env.arena);
write!(debug_name, "{:?}", name).unwrap();
let name_bytes = debug_name.into_bytes().into_bump_slice();
self.module.names.append_function(wasm_fn_index, name_bytes);
}
/**********************************************************
STATEMENTS