From c73688fbb03085eec48f0e47fae75debf76fe6b8 Mon Sep 17 00:00:00 2001 From: Cassie Jones Date: Fri, 10 Jan 2020 22:25:15 -0500 Subject: [PATCH] Start adding framework for encoding and decoding --- toolchain/src/cpu.rs | 3 +++ toolchain/src/inst.rs | 3 +++ toolchain/src/inst/decode.rs | 6 ++++++ toolchain/src/inst/encode.rs | 6 ++++++ 4 files changed, 18 insertions(+) create mode 100644 toolchain/src/inst/decode.rs create mode 100644 toolchain/src/inst/encode.rs diff --git a/toolchain/src/cpu.rs b/toolchain/src/cpu.rs index 42be7ad..bca67d6 100644 --- a/toolchain/src/cpu.rs +++ b/toolchain/src/cpu.rs @@ -29,6 +29,7 @@ impl IndexMut for RegFile { } pub struct Cpu { + init: bool, pc: u16, reg: RegFile, memory: Vec, @@ -37,6 +38,8 @@ pub struct Cpu { impl Cpu { pub fn new() -> Self { Cpu { + init: false, + pc: 0, reg: RegFile { values: [0; 4] }, memory: vec![0; 1 << 16], } diff --git a/toolchain/src/inst.rs b/toolchain/src/inst.rs index 2075230..8792781 100644 --- a/toolchain/src/inst.rs +++ b/toolchain/src/inst.rs @@ -1,3 +1,6 @@ +mod encode; +mod decode; + pub enum Reg { R0, R1, diff --git a/toolchain/src/inst/decode.rs b/toolchain/src/inst/decode.rs new file mode 100644 index 0000000..f85cbba --- /dev/null +++ b/toolchain/src/inst/decode.rs @@ -0,0 +1,6 @@ +use std::io::{self, Read}; +use crate::inst::Inst; + +pub trait Decode { + fn decode(code: &mut impl Read) -> io::Result>; +} diff --git a/toolchain/src/inst/encode.rs b/toolchain/src/inst/encode.rs new file mode 100644 index 0000000..6a50b07 --- /dev/null +++ b/toolchain/src/inst/encode.rs @@ -0,0 +1,6 @@ +use std::io::{self, Write}; +use crate::inst::Inst; + +pub trait Encode { + fn encode(&self, out: &mut impl Write) -> io::Result<()>; +} -- 2.47.0