Add RISC-V call instruction encodings.

Calls are jal with a fixed %x1 link register.
This commit is contained in:
Jakob Stoklund Olesen
2017-04-06 15:36:03 -07:00
parent b4ac520332
commit 4ee519e620
4 changed files with 26 additions and 8 deletions

View File

@@ -8,13 +8,12 @@ use predicates::is_signed_int;
include!(concat!(env!("OUT_DIR"), "/binemit-riscv.rs"));
/// RISC-V relocation kinds.
#[allow(dead_code)]
pub enum RelocKind {
/// A conditional (SB-type) branch to an EBB.
Branch,
/// A jal call to a function.
Call,
}
pub static RELOC_NAMES: [&'static str; 1] = ["Branch"];
pub static RELOC_NAMES: [&'static str; 1] = ["Call"];
impl Into<Reloc> for RelocKind {
fn into(self) -> Reloc {
@@ -318,3 +317,13 @@ fn recipe_uj<CS: CodeSink + ?Sized>(func: &Function, inst: Inst, sink: &mut CS)
panic!("Expected Jump format: {:?}", func.dfg[inst]);
}
}
fn recipe_ujcall<CS: CodeSink + ?Sized>(func: &Function, inst: Inst, sink: &mut CS) {
if let InstructionData::Call { func_ref, .. } = func.dfg[inst] {
sink.reloc_func(RelocKind::Call.into(), func_ref);
// rd=%x1 is the standard link register.
put_uj(func.encodings[inst].bits(), 0, 1, sink);
} else {
panic!("Expected Call format: {:?}", func.dfg[inst]);
}
}