- Instructions are now detected automatically based on context - Since MIPs can't decide if it wants to be open or not, Corten will be aiming to be more of a RISC-V VM in the long term.
43 lines
979 B
Rust
43 lines
979 B
Rust
#![allow(dead_code)]
|
|
|
|
use crate::assembler::Opcode;
|
|
|
|
#[derive(Debug, PartialEq)]
|
|
pub struct Instruction {
|
|
opcode: Opcode,
|
|
}
|
|
|
|
impl Instruction {
|
|
pub fn new(opcode: Opcode) -> Self {
|
|
Instruction { opcode }
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod instruction_tests {
|
|
use crate::assembler::Opcode;
|
|
use crate::instruction::*;
|
|
use nom::types::CompleteStr;
|
|
|
|
#[test]
|
|
fn test_crate_hlt() {
|
|
let opcode = Opcode::HLT;
|
|
assert_eq!(opcode, Opcode::HLT);
|
|
}
|
|
|
|
#[test]
|
|
fn test_create_instruction() {
|
|
let inst = Instruction::new(Opcode::HLT);
|
|
assert_eq!(inst.opcode, Opcode::HLT);
|
|
}
|
|
|
|
#[test]
|
|
fn test_str_to_opcode() {
|
|
let opcode = Opcode::from(CompleteStr("load"));
|
|
assert_eq!(opcode, Opcode::LOAD);
|
|
let opcode = Opcode::from(CompleteStr("add"));
|
|
assert_eq!(opcode, Opcode::ADD);
|
|
let opcode = Opcode::from(CompleteStr("illegal"));
|
|
assert_eq!(opcode, Opcode::IGL);
|
|
}
|
|
}
|