Allow building clif-backend without wasm-debug

This commit is contained in:
Mark McCaskey
2020-02-25 17:08:09 -08:00
parent d7fca539c1
commit 6f5ebb564c
2 changed files with 51 additions and 38 deletions

View File

@ -113,6 +113,12 @@ impl FuncResolverBuilder {
let generate_debug_info = info.generate_debug_info; let generate_debug_info = info.generate_debug_info;
let fb = function_bodies.iter().collect::<Vec<(_, _)>>(); let fb = function_bodies.iter().collect::<Vec<(_, _)>>();
#[cfg(feature = "generate-debug-information")]
use wasm_debug::types::CompiledFunctionData;
#[cfg(not(feature = "generate-debug-information"))]
type CompiledFunctionData = ();
/// Data about the the compiled machine code. /// Data about the the compiled machine code.
type CompileMetadata = ( type CompileMetadata = (
LocalFuncIndex, LocalFuncIndex,
@ -128,7 +134,7 @@ impl FuncResolverBuilder {
.par_iter() .par_iter()
.map_init( .map_init(
|| Context::new(), || Context::new(),
|ctx, (lfi, (func, loc))| { |ctx, (lfi, (func, _loc))| {
let mut code_buf = Vec::new(); let mut code_buf = Vec::new();
ctx.func = func.to_owned(); ctx.func = func.to_owned();
let mut reloc_sink = RelocSink::new(); let mut reloc_sink = RelocSink::new();
@ -149,6 +155,7 @@ impl FuncResolverBuilder {
_ => CompileError::InternalError { msg: e.to_string() }, _ => CompileError::InternalError { msg: e.to_string() },
})?; })?;
#[cfg(feature = "generate-debug-information")]
let debug_entry = if generate_debug_info { let debug_entry = if generate_debug_info {
let func = &ctx.func; let func = &ctx.func;
let encinfo = isa.encoding_info(); let encinfo = isa.encoding_info();
@ -180,8 +187,8 @@ impl FuncResolverBuilder {
let entry = CompiledFunctionData { let entry = CompiledFunctionData {
instructions, instructions,
start_srcloc: wasm_debug::types::SourceLoc::new(loc.start()), start_srcloc: wasm_debug::types::SourceLoc::new(_loc.start()),
end_srcloc: wasm_debug::types::SourceLoc::new(loc.end()), end_srcloc: wasm_debug::types::SourceLoc::new(_loc.end()),
// this not being 0 breaks inst-level debugging // this not being 0 breaks inst-level debugging
body_offset: 0, body_offset: 0,
body_len: code_buf.len(), body_len: code_buf.len(),
@ -191,13 +198,15 @@ impl FuncResolverBuilder {
None None
}; };
#[cfg(not(feature = "generate-debug-information"))]
let debug_entry = None;
ctx.clear(); ctx.clear();
Ok((code_buf, (*lfi, debug_entry, reloc_sink, local_trap_sink))) Ok((code_buf, (*lfi, debug_entry, reloc_sink, local_trap_sink)))
}, },
) )
.collect(); .collect();
use wasm_debug::types::CompiledFunctionData;
let mut debug_metadata = if generate_debug_info { let mut debug_metadata = if generate_debug_info {
Some(wasmer_runtime_core::codegen::DebugMetadata { Some(wasmer_runtime_core::codegen::DebugMetadata {
func_info: Map::new(), func_info: Map::new(),
@ -216,12 +225,14 @@ impl FuncResolverBuilder {
// We separate into two iterators, one iterable and one into iterable // We separate into two iterators, one iterable and one into iterable
let (code_bufs, sinks): (Vec<Vec<u8>>, Vec<CompileMetadata>) = let (code_bufs, sinks): (Vec<Vec<u8>>, Vec<CompileMetadata>) =
compiled_functions.into_iter().unzip(); compiled_functions.into_iter().unzip();
for (code_buf, (_, debug_info, reloc_sink, mut local_trap_sink)) in for (code_buf, (_, _debug_info, reloc_sink, mut local_trap_sink)) in
code_bufs.iter().zip(sinks.into_iter()) code_bufs.iter().zip(sinks.into_iter())
{ {
let rounded_size = round_up(code_buf.len(), mem::size_of::<usize>()); let rounded_size = round_up(code_buf.len(), mem::size_of::<usize>());
#[cfg(feature = "generate-debug-information")]
{
if let Some(ref mut dbg_metadata) = debug_metadata { if let Some(ref mut dbg_metadata) = debug_metadata {
let (entry, vlr, stackslots) = debug_info.unwrap(); let (entry, vlr, stackslots) = _debug_info.unwrap();
dbg_metadata.func_info.push(entry); dbg_metadata.func_info.push(entry);
let new_vlr = vlr let new_vlr = vlr
.into_iter() .into_iter()
@ -241,7 +252,9 @@ impl FuncResolverBuilder {
} }
cranelift_codegen::ir::ValueLoc::Stack(st) => { cranelift_codegen::ir::ValueLoc::Stack(st) => {
wasm_debug::types::ValueLoc::Stack( wasm_debug::types::ValueLoc::Stack(
wasm_debug::types::StackSlot::from_u32(st.as_u32()), wasm_debug::types::StackSlot::from_u32(
st.as_u32(),
),
) )
} }
}, },
@ -253,6 +266,7 @@ impl FuncResolverBuilder {
dbg_metadata.inst_info.push(new_vlr); dbg_metadata.inst_info.push(new_vlr);
dbg_metadata.stack_slot_offsets.push(stackslots); dbg_metadata.stack_slot_offsets.push(stackslots);
} }
}
// Clear the local trap sink and consolidate all trap info // Clear the local trap sink and consolidate all trap info
// into a single location. // into a single location.

View File

@ -277,7 +277,6 @@ pub fn read_module<
} }
} }
// read instruction locations into vector for debug purposes
{ {
let info_read = info.read().unwrap(); let info_read = info.read().unwrap();
let mut cur_pos = let mut cur_pos =