Add conditional branch encodings for RISC-V.

Not all br_icmp opcodes are present in the ISA. The missing ones can be
reached by commuting operands.

Don't attempt to encode EBB offsets yet. For now just emit an EBB
relocation for the branch instruction.
This commit is contained in:
Jakob Stoklund Olesen
2017-04-03 15:07:08 -07:00
parent 1b6a6f4e48
commit 479ff156c1
9 changed files with 124 additions and 12 deletions

View File

@@ -25,6 +25,7 @@ pub fn subtest(parsed: &TestCommand) -> Result<Box<SubTest>> {
// Code sink that generates text.
struct TextSink {
rnames: &'static [&'static str],
text: String,
}
@@ -45,12 +46,16 @@ impl binemit::CodeSink for TextSink {
write!(self.text, "{:016x} ", x).unwrap();
}
fn reloc_func(&mut self, _: binemit::Reloc, _: ir::FuncRef) {
unimplemented!()
fn reloc_ebb(&mut self, reloc: binemit::Reloc, ebb: ir::Ebb) {
write!(self.text, "{}({}) ", self.rnames[reloc.0 as usize], ebb).unwrap();
}
fn reloc_jt(&mut self, _: binemit::Reloc, _: ir::JumpTable) {
unimplemented!()
fn reloc_func(&mut self, reloc: binemit::Reloc, fref: ir::FuncRef) {
write!(self.text, "{}({}) ", self.rnames[reloc.0 as usize], fref).unwrap();
}
fn reloc_jt(&mut self, reloc: binemit::Reloc, jt: ir::JumpTable) {
write!(self.text, "{}({}) ", self.rnames[reloc.0 as usize], jt).unwrap();
}
}
@@ -73,7 +78,10 @@ impl SubTest for TestBinEmit {
// value locations. The current error reporting is just crashing...
let mut func = func.into_owned();
let mut sink = TextSink { text: String::new() };
let mut sink = TextSink {
rnames: isa.reloc_names(),
text: String::new(),
};
for comment in &context.details.comments {
if let Some(want) = match_directive(comment.text, "bin:") {