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