Provide BB layout info externally in terms of code offsets.

This is sometimes useful when performing analyses on the generated
machine code: for example, some kinds of code verifiers will want to do
a control-flow analysis, and it is much easier to do this if one does
not have to recover the CFG from the machine code (doing so requires
heavyweight analysis when indirect branches are involved). If one trusts
the control-flow lowering and only needs to verify other properties of
the code, this can be very useful.
This commit is contained in:
Chris Fallin
2021-04-28 17:52:42 -07:00
committed by Chris Fallin
parent 76c6b83f6a
commit 11a2ef01e7
8 changed files with 81 additions and 7 deletions

View File

@@ -258,6 +258,24 @@ impl Context {
}
}
/// If available, return information about the code layout in the
/// final machine code: the offsets (in bytes) of each basic-block
/// start, and all basic-block edges.
pub fn get_code_bb_layout(&self) -> Option<(Vec<usize>, Vec<(usize, usize)>)> {
if let Some(result) = self.mach_compile_result.as_ref() {
Some((
result.bb_starts.iter().map(|&off| off as usize).collect(),
result
.bb_edges
.iter()
.map(|&(from, to)| (from as usize, to as usize))
.collect(),
))
} else {
None
}
}
/// Creates unwind information for the function.
///
/// Returns `None` if the function has no unwind information.