This repository has been archived on 2025-02-21. You can view files and clone it, but cannot push or open issues or pull requests.
corten/src/instruction.rs
Anthony Foxclaw 86f060e0f5 Implemented HLT instruction
- 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.
2020-02-09 15:16:38 -05:00

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