pub mod instr;
#[allow(dead_code)]
mod instr_masks;
#[cfg(test)]
mod tests {
use std::collections::HashMap;
use std::fs::read_to_string;
use std::path::Path;
use serde::{Deserialize};
use crate::rv32i::instr::Instruction;
#[derive(Deserialize)]
struct InstructionSpec {
pub example: String
}
#[test]
fn instruction_parsing() {
let instr_reference: HashMap<String, InstructionSpec> = {
let contents_path = Path::new("src/rv32i/instr_spec.json");
let contents = read_to_string(contents_path).unwrap();
serde_json::from_str(contents.as_str()).unwrap()
};
for (name, spec) in &instr_reference {
let instr_raw = u32::from_str_radix(spec.example.as_str(), 2).unwrap();
let instr_decoded = Instruction::parse_from_word(instr_raw).unwrap();
assert_eq!(instr_decoded.get_name(), *name);
}
}
}