Add ability to relocate constants using RelocSink

This commit is contained in:
Andrew Brown
2019-07-23 10:47:03 -07:00
committed by Dan Gohman
parent c20b13d5a9
commit 7b2d055f78
8 changed files with 79 additions and 5 deletions

View File

@@ -90,6 +90,10 @@ impl binemit::CodeSink for TextSink {
write!(self.text, ") ").unwrap();
}
fn reloc_constant(&mut self, reloc: binemit::Reloc, constant: ir::ConstantOffset) {
write!(self.text, "{}({}) ", reloc, constant).unwrap();
}
fn reloc_jt(&mut self, reloc: binemit::Reloc, jt: ir::JumpTable) {
write!(self.text, "{}({}) ", reloc, jt).unwrap();
}
@@ -313,7 +317,13 @@ impl SubTest for TestBinEmit {
}
sink.begin_rodata();
// TODO: Read-only (constant pool) data.
// output constants
for (_, constant_data) in func.dfg.constants.iter() {
for byte in constant_data.iter() {
sink.put1(*byte)
}
}
sink.end_codegen();

View File

@@ -106,6 +106,7 @@ impl binemit::CodeSink for SizeSink {
_addend: binemit::Addend,
) {
}
fn reloc_constant(&mut self, _: binemit::Reloc, _: ir::ConstantOffset) {}
fn reloc_jt(&mut self, _reloc: binemit::Reloc, _jt: ir::JumpTable) {}
fn trap(&mut self, _code: ir::TrapCode, _srcloc: ir::SourceLoc) {}
fn begin_jumptables(&mut self) {}