|
| 1 | +#[cfg(test)] |
| 2 | +mod tests { |
| 3 | + use binary_room::instruction::*; |
| 4 | + use binary_room::translate::*; |
| 5 | + use binary_room::utils; |
| 6 | + use binary_room::utils::translate_to_file; |
| 7 | + use binary_room::utils::START; |
| 8 | + |
| 9 | + #[test] |
| 10 | + fn test_binary_translate() { |
| 11 | + let riscv_asm: Vec<RiscVInstruction> = vec![ |
| 12 | + RiscVInstruction::Verbatim { text: START.to_string() }, |
| 13 | + RiscVInstruction::Addi { |
| 14 | + dest: RiscVRegister::SP, |
| 15 | + src: RiscVRegister::SP, |
| 16 | + imm: -32, |
| 17 | + }, |
| 18 | + RiscVInstruction::S { |
| 19 | + width: RiscVWidth::Double, |
| 20 | + src: RiscVRegister::RA, |
| 21 | + dest: RiscVVal::Offset { |
| 22 | + register: RiscVRegister::SP, |
| 23 | + offset: 24, |
| 24 | + }, |
| 25 | + }, |
| 26 | + RiscVInstruction::S { |
| 27 | + width: RiscVWidth::Double, |
| 28 | + src: RiscVRegister::S0FP, |
| 29 | + dest: RiscVVal::Offset { |
| 30 | + register: RiscVRegister::SP, |
| 31 | + offset: 16, |
| 32 | + }, |
| 33 | + }, |
| 34 | + RiscVInstruction::Addi { |
| 35 | + dest: RiscVRegister::S0FP, |
| 36 | + src: RiscVRegister::SP, |
| 37 | + imm: 32, |
| 38 | + }, |
| 39 | + RiscVInstruction::Li { |
| 40 | + dest: RiscVRegister::A5, |
| 41 | + imm: 3, |
| 42 | + }, |
| 43 | + RiscVInstruction::S { |
| 44 | + width: RiscVWidth::Word, |
| 45 | + src: RiscVRegister::A5, |
| 46 | + dest: RiscVVal::Offset { |
| 47 | + register: RiscVRegister::S0FP, |
| 48 | + offset: -20, |
| 49 | + }, |
| 50 | + }, |
| 51 | + RiscVInstruction::Li { |
| 52 | + dest: RiscVRegister::A5, |
| 53 | + imm: 4, |
| 54 | + }, |
| 55 | + RiscVInstruction::S { |
| 56 | + width: RiscVWidth::Word, |
| 57 | + src: RiscVRegister::A5, |
| 58 | + dest: RiscVVal::Offset { |
| 59 | + register: RiscVRegister::S0FP, |
| 60 | + offset: -24, |
| 61 | + }, |
| 62 | + }, |
| 63 | + RiscVInstruction::L { |
| 64 | + width: RiscVWidth::Word, |
| 65 | + dest: RiscVRegister::A5, |
| 66 | + src: RiscVVal::Offset { |
| 67 | + register: RiscVRegister::S0FP, |
| 68 | + offset: -20, |
| 69 | + }, |
| 70 | + }, |
| 71 | + RiscVInstruction::Mv { |
| 72 | + dest: RiscVRegister::A4, |
| 73 | + src: RiscVRegister::A5, |
| 74 | + }, |
| 75 | + RiscVInstruction::L { |
| 76 | + width: RiscVWidth::Word, |
| 77 | + dest: RiscVRegister::A5, |
| 78 | + src: RiscVVal::Offset { |
| 79 | + register: RiscVRegister::S0FP, |
| 80 | + offset: -24, |
| 81 | + }, |
| 82 | + }, |
| 83 | + RiscVInstruction::Add { |
| 84 | + width: RiscVWidth::Word, |
| 85 | + dest: RiscVRegister::A5, |
| 86 | + arg1: RiscVRegister::A4, |
| 87 | + arg2: RiscVRegister::A5, |
| 88 | + }, |
| 89 | + RiscVInstruction::SextW { |
| 90 | + dest: RiscVRegister::A5, |
| 91 | + src: RiscVRegister::A5, |
| 92 | + }, |
| 93 | + RiscVInstruction::Mv { |
| 94 | + dest: RiscVRegister::A0, |
| 95 | + src: RiscVRegister::A5, |
| 96 | + }, |
| 97 | + RiscVInstruction::L { |
| 98 | + width: RiscVWidth::Double, |
| 99 | + dest: RiscVRegister::RA, |
| 100 | + src: RiscVVal::Offset { |
| 101 | + register: RiscVRegister::SP, |
| 102 | + offset: 24, |
| 103 | + }, |
| 104 | + }, |
| 105 | + RiscVInstruction::L { |
| 106 | + width: RiscVWidth::Double, |
| 107 | + dest: RiscVRegister::S0FP, |
| 108 | + src: RiscVVal::Offset { |
| 109 | + register: RiscVRegister::SP, |
| 110 | + offset: 16, |
| 111 | + }, |
| 112 | + }, |
| 113 | + RiscVInstruction::Addi { |
| 114 | + dest: RiscVRegister::SP, |
| 115 | + src: RiscVRegister::SP, |
| 116 | + imm: 32, |
| 117 | + }, |
| 118 | + RiscVInstruction::Jr { |
| 119 | + target: RiscVRegister::RA, |
| 120 | + }, |
| 121 | + ]; |
| 122 | + |
| 123 | + translate_to_file(riscv_asm, "./tests/add/add.arm.s".to_string()); |
| 124 | + } |
| 125 | +} |
0 commit comments