From 3b17ffcaa6458c7382f06a9d5bd785906328e584 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Wed, 9 Nov 2022 15:54:01 +0100 Subject: [PATCH] add addi print test --- src/decode.rs | 3 +++ src/print.rs | 21 ++++++++++++++------- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/decode.rs b/src/decode.rs index 80ac041..7aa2d87 100644 --- a/src/decode.rs +++ b/src/decode.rs @@ -1,3 +1,5 @@ +#[allow(non_snake_case)] // supprimer le warning snake case (quand les noms de variables ont des majuscules) +#[derive(Debug)] pub struct Instruction { pub value : u64, @@ -26,6 +28,7 @@ pub struct Instruction { pub imm21_1_signed : i32, } +#[allow(non_snake_case)] pub fn decode(val : u64) -> Instruction { let value = val; diff --git a/src/print.rs b/src/print.rs index d4651ba..2435951 100644 --- a/src/print.rs +++ b/src/print.rs @@ -260,16 +260,16 @@ pub fn print(ins: Instruction, pc: i32) -> String { //TODO pc should be u64 #[cfg(test)] -mod Test { +mod test { use crate::{print, decode}; #[test] - fn test1() { - let sub = decode::decode(0b01000001000010001000111000110011); - let add = decode::decode(0b00000001000010001000111000110011); - let xor = decode::decode(0b00000001000010001100111000110011); - let slr = decode::decode(0b00000001000010001101111000110011); - let sra = decode::decode(0b01000001000010001101111000110011); + fn test_op() { + let sub = decode::decode(0b0100000_10000_10001_000_11100_0110011); + let add = decode::decode(0b0000000_10000_10001_000_11100_0110011); + let xor = decode::decode(0b0000000_10000_10001_100_11100_0110011); + let slr = decode::decode(0b0000000_10000_10001_101_11100_0110011); + let sra = decode::decode(0b0100000_10000_10001_101_11100_0110011); assert_eq!("sub r28, r17, r16", print::print(sub, 0)); assert_eq!("xor r28, r17, r16", print::print(xor, 0)); @@ -278,4 +278,11 @@ mod Test { assert_eq!("add r28, r17, r16", print::print(add, 0)); } + + #[test] + fn test_opi() { + let addi = decode::decode(0b0000000000_10001_000_11100_0010011); + assert_eq!("addi x28, x17, 0", print::print(addi, 0)); + } + } \ No newline at end of file