Add a func.inst_offsets() iterator.

This Function method can be used after the final code layout has been
computed. It returns all the instructions in an EBB along with their
encoded size and offset from the beginning of the function.

This is useful for extracting additional metadata about trapping
instructions and other things that may be needed by a VM.
This commit is contained in:
Jakob Stoklund Olesen
2018-02-01 17:10:21 -08:00
parent 429027e2f2
commit e3714ddd10
2 changed files with 48 additions and 3 deletions

View File

@@ -211,7 +211,8 @@ impl SubTest for TestBinEmit {
"Inconsistent {} header offset",
ebb
);
for inst in func.layout.ebb_insts(ebb) {
for (offset, inst, enc_bytes) in func.inst_offsets(ebb, &encinfo) {
assert_eq!(sink.offset, offset);
sink.text.clear();
let enc = func.encodings[inst];
@@ -234,7 +235,7 @@ impl SubTest for TestBinEmit {
// Verify the encoding recipe sizes against the ISAs emit_inst implementation.
assert_eq!(
emitted,
encinfo.bytes(enc),
enc_bytes,
"Inconsistent size for [{}] {}",
encinfo.display(enc),
func.dfg.display_inst(inst, isa)