Add a Context::emit_to_memory function.

This function will emit the binary machine code into contiguous raw
memory while sending relocations to a RelocSink.

Add a MemoryCodeSink for generating machine code directly into memory
efficiently. Allow the TargetIsa to provide emit_function
implementations that are specialized to the MemoryCodeSink type to avoid
needless small virtual callbacks to put1() et etc.
This commit is contained in:
Jakob Stoklund Olesen
2017-07-17 18:13:05 -07:00
parent 9dc92eb8b3
commit 2f7057b96f
9 changed files with 168 additions and 13 deletions

View File

@@ -51,12 +51,9 @@ impl SubTest for TestCompile {
// Finally verify that the returned code size matches the emitted bytes.
let mut sink = SizeSink { offset: 0 };
for ebb in comp_ctx.func.layout.ebbs() {
assert_eq!(sink.offset, comp_ctx.func.offsets[ebb]);
for inst in comp_ctx.func.layout.ebb_insts(ebb) {
isa.emit_inst(&comp_ctx.func, inst, &mut sink);
}
}
binemit::emit_function(&comp_ctx.func,
|func, inst, sink| isa.emit_inst(func, inst, sink),
&mut sink);
if sink.offset != code_size {
return Err(format!("Expected code size {}, got {}", code_size, sink.offset));