Dekejit/src/main.rs
2023-05-02 14:13:49 +02:00

45 lines
1 KiB
Rust

use dekejit::assembler::parser;
use dekejit::assembler::to_binary;
use dekejit::cpu::IOBuffer;
use dekejit::cpu::CPU;
use dekejit::loader::unloader::*;
fn main() {
let code = std::fs::read_to_string("./tests/assembly/hello_world.grasm").unwrap();
let mut parser = parser::Parser::new(code);
let r = parser.parse_sections().unwrap();
println!("Parsed sections: {:?}", r);
let code = to_binary(r).unwrap();
// let mut k = make_string("Hello world!");
//
// let mut code: Vec<u16> = vec![
// 0b0111000100000011, // addi ra 3
// 0b1110000100000011, // ecall ra 3
// 0b1111000000000000, // HALT.
// ];
//
// code.append(&mut k);
//
let mut env = IOBuffer::default();
//
let mut cpu = CPU::new(&mut env);
//
for c in &code[..] {
println!("{:#018b}", c);
}
//
match cpu.run_code_raw(&code) {
Ok(_) => {
println!("Result: {}", env.output)
}
Err(e) => println!("Err: {:?}", e),
};
}