Skip to content

Commit 98fe35e

Browse files
committed
translate: add minimal riscv translation map
1 parent f77e898 commit 98fe35e

2 files changed

Lines changed: 23 additions & 3 deletions

File tree

src/main.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
use std::fs;
22
use std::str::FromStr;
33
mod instruction;
4-
use instruction::Instruction;
4+
pub mod translate;
5+
use instruction::RiscVInstruction;
56

67
/// Parse a text file into our enum.
7-
fn parse_asm(asm: &str) -> Vec<Instruction> {
8+
fn parse_asm(asm: &str) -> Vec<RiscVInstruction> {
89
asm.lines()
910
.filter_map(|line| {
1011
// TODO (Samir): Not sure that this will handle assembly labels
@@ -14,7 +15,7 @@ fn parse_asm(asm: &str) -> Vec<Instruction> {
1415
if parts.is_empty() {
1516
None
1617
} else {
17-
Instruction::from_str(parts[0]).ok()
18+
RiscVInstruction::from_str(parts[0]).ok()
1819
}
1920
})
2021
.collect()

src/translate.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
use crate::instruction::{ArmInstruction, RiscVInstruction};
2+
3+
/// Run the core logic to match from RISC-V to ARM Instructions.
4+
5+
/// Translate one instruction at a time.
6+
pub fn translate(riscv_instr: RiscVInstruction) -> ArmInstruction {
7+
match riscv_instr {
8+
RiscVInstruction::Addi => add,
9+
RiscVInstruction::Sd => todo!(),
10+
RiscVInstruction::Ld => todo!(),
11+
RiscVInstruction::Sw => todo!(),
12+
RiscVInstruction::Lw => todo!(),
13+
RiscVInstruction::Mv => todo!(),
14+
RiscVInstruction::Addw => todo!(),
15+
RiscVInstruction::SextW => todo!(),
16+
RiscVInstruction::Jr => todo!(),
17+
RiscVInstruction::Li => todo!(),
18+
}
19+
}

0 commit comments

Comments
 (0)