Merge branch 'decode_print' of gitlab.istic.univ-rennes1.fr:simpleos/burritos into decode_print

This commit is contained in:
Rémi Rativel 2022-11-09 16:00:07 +01:00
commit f9af5c138f
2 changed files with 17 additions and 7 deletions

View File

@ -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 : u32,
@ -26,6 +28,7 @@ pub struct Instruction {
pub imm21_1_signed : i32,
}
#[allow(non_snake_case)]
pub fn decode(val : u32) -> Instruction {
let value = val;

View File

@ -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));
}
}