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:
@@ -4,8 +4,10 @@
|
||||
//! binary machine code.
|
||||
|
||||
mod relaxation;
|
||||
mod memorysink;
|
||||
|
||||
pub use self::relaxation::relax_branches;
|
||||
pub use self::memorysink::{MemoryCodeSink, RelocSink};
|
||||
|
||||
use ir::{Ebb, FuncRef, JumpTable, Function, Inst};
|
||||
|
||||
@@ -55,3 +57,20 @@ pub fn bad_encoding(func: &Function, inst: Inst) -> ! {
|
||||
func.encodings[inst],
|
||||
func.dfg.display_inst(inst, None));
|
||||
}
|
||||
|
||||
/// Emit a function to `sink`, given an instruction emitter function.
|
||||
///
|
||||
/// This function is called from the `TargetIsa::emit_function()` implementations with the
|
||||
/// appropriate instruction emitter.
|
||||
pub fn emit_function<CS, EI>(func: &Function, emit_inst: EI, sink: &mut CS)
|
||||
where CS: CodeSink,
|
||||
EI: Fn(&Function, Inst, &mut CS)
|
||||
{
|
||||
for ebb in func.layout.ebbs() {
|
||||
assert_eq!(func.offsets[ebb], sink.offset());
|
||||
for inst in func.layout.ebb_insts(ebb) {
|
||||
emit_inst(func, inst, sink);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user