wasmer_compiler_cranelift/
address_map.rs1use cranelift_codegen::{Context, MachSrcLoc};
5use std::ops::Range;
6use wasmer_compiler::types::address_map::{FunctionAddressMap, InstructionAddressMap};
7use wasmer_types::SourceLoc;
8
9pub fn get_function_address_map(
10 context: &Context,
11 range: Range<usize>,
12 body_len: usize,
13) -> FunctionAddressMap {
14 let mut instructions = Vec::new();
15
16 let mcr = context.compiled_code().unwrap();
19 for &MachSrcLoc { start, end, loc } in mcr.buffer.get_srclocs_sorted() {
20 instructions.push(InstructionAddressMap {
21 srcloc: SourceLoc::new(loc.bits()),
22 code_offset: start as usize,
23 code_len: (end - start) as usize,
24 });
25 }
26
27 let start_srcloc = SourceLoc::new(range.start as u32);
31 let end_srcloc = SourceLoc::new(range.end as u32);
32
33 FunctionAddressMap {
34 instructions,
35 start_srcloc,
36 end_srcloc,
37 body_offset: 0,
38 body_len,
39 }
40}