From 599507c3497c0b79acc0d99afe1ef783583920f2 Mon Sep 17 00:00:00 2001 From: Cassie Jones Date: Sat, 11 Jan 2020 01:44:06 -0500 Subject: [PATCH] Add instruction datatype --- toolchain/.gitignore | 1 + toolchain/Cargo.lock | 5 +++ toolchain/Cargo.toml | 9 ++++ toolchain/src/inst.rs | 96 +++++++++++++++++++++++++++++++++++++++++++ toolchain/src/lib.rs | 1 + toolchain/src/main.rs | 3 ++ 6 files changed, 115 insertions(+) create mode 100644 toolchain/.gitignore create mode 100644 toolchain/Cargo.lock create mode 100644 toolchain/Cargo.toml create mode 100644 toolchain/src/inst.rs create mode 100644 toolchain/src/lib.rs create mode 100644 toolchain/src/main.rs diff --git a/toolchain/.gitignore b/toolchain/.gitignore new file mode 100644 index 0000000..2f7896d --- /dev/null +++ b/toolchain/.gitignore @@ -0,0 +1 @@ +target/ diff --git a/toolchain/Cargo.lock b/toolchain/Cargo.lock new file mode 100644 index 0000000..e24cc9f --- /dev/null +++ b/toolchain/Cargo.lock @@ -0,0 +1,5 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "toolchain" +version = "0.1.0" diff --git a/toolchain/Cargo.toml b/toolchain/Cargo.toml new file mode 100644 index 0000000..e910a73 --- /dev/null +++ b/toolchain/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "toolchain" +version = "0.1.0" +authors = ["Cassie Jones "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/toolchain/src/inst.rs b/toolchain/src/inst.rs new file mode 100644 index 0000000..db8c939 --- /dev/null +++ b/toolchain/src/inst.rs @@ -0,0 +1,96 @@ +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub struct Reg(u8); + +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum Op1 { + Zero, + Lsl1, + Lsr1, + Asr1, + Incr, + Decr, + Comp, + Negt, +} + +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum OpR { + Add, + Sub, + And, + Ior, + Xor, + Lsl, + Lsr, + Asr, +} + +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum Data { + D1, + D2, +} + +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum Special { + Data(Data), + Code, +} + +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub struct U3(u8); +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub struct AddImm(i8); + +impl U3 { + pub fn new(x: u8) -> Option { + match x { + 0..=7 => Some(U3(x)), + _ => None, + } + } +} + +impl AddImm { + pub fn new(x: i8) -> Option { + match x { + -64..=127 => Some(AddImm(x)), + _ => None, + } + } +} + +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum AluI { + And(u8), + Ior(u8), + Xor(u8), + Add(AddImm), + Rol(U3), + Lsl(U3), + Lsr(U3), + Asr(U3), +} + +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum Inst { + Trap, + JAbs, + CAbs, + JOff, + COff, + Swap(Reg), + GetR(Reg), + SetR(Reg), + Get(Special), + Set(Special), + Alu1(Op1), + IsLt(Reg), + AluR(OpR, Reg), + LdD(Data, Reg), + StD(Data, Reg), + AluI(AluI), + BEzI(i8), + JOfI(i8), + COfI(i8), +} diff --git a/toolchain/src/lib.rs b/toolchain/src/lib.rs new file mode 100644 index 0000000..d4cc11e --- /dev/null +++ b/toolchain/src/lib.rs @@ -0,0 +1 @@ +pub mod inst; diff --git a/toolchain/src/main.rs b/toolchain/src/main.rs new file mode 100644 index 0000000..c89b901 --- /dev/null +++ b/toolchain/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + todo!(); +} -- 2.47.0