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

@@ -16,7 +16,7 @@ pub use self::relaxation::relax_branches;
pub use self::shrink::shrink_instructions;
pub use self::stackmap::Stackmap;
use crate::ir::entities::Value;
use crate::ir::{ExternalName, Function, Inst, JumpTable, SourceLoc, TrapCode};
use crate::ir::{ConstantOffset, ExternalName, Function, Inst, JumpTable, SourceLoc, TrapCode};
use crate::isa::TargetIsa;
pub use crate::regalloc::RegDiversions;
use core::fmt;
@@ -133,6 +133,9 @@ pub trait CodeSink {
/// Add a relocation referencing an external symbol plus the addend at the current offset.
fn reloc_external(&mut self, _: Reloc, _: &ExternalName, _: Addend);
/// Add a relocation referencing a jump table.
fn reloc_constant(&mut self, _: Reloc, _: ConstantOffset);
/// Add a relocation referencing a jump table.
fn reloc_jt(&mut self, _: Reloc, _: JumpTable);
@@ -192,7 +195,13 @@ where
}
sink.begin_rodata();
// TODO: No read-only data (constant pools) at this time.
// output constants
for (_, constant_data) in func.dfg.constants.iter() {
for byte in constant_data.iter() {
sink.put1(*byte)
}
}
sink.end_codegen();
}