Skip to content

Commit 46e1aa1

Browse files
Samuel OrtizSamuel Ortiz
authored andcommitted
do-core1: Initial do-core crate
With a minimal content, just our opcodes. Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
1 parent 8efc82e commit 46e1aa1

5 files changed

Lines changed: 45 additions & 1 deletion

File tree

Cargo.lock

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ edition = "2018"
77
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
88

99
[dependencies]
10-
clap = { version = "3.0.5", features = ["derive"] }
10+
clap = { version = "3.0.5", features = ["derive"] }
11+
do-core = { path = "do-core" }

do-core/Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[package]
2+
name = "do-core"
3+
version = "0.1.0"
4+
authors = ["Samuel Ortiz <sameo@linux.intel.com>"]
5+
edition = "2018"
6+
7+
[dependencies]

do-core/src/instruction.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
use crate::Error;
2+
3+
#[allow(dead_code)]
4+
#[derive(Clone, Debug, PartialEq)]
5+
pub enum OpCode {
6+
LD = 0x00,
7+
ST = 0x01,
8+
ADD = 0x02,
9+
XOR = 0x03,
10+
}
11+
12+
impl OpCode {
13+
pub fn from_u8(opcode: u8) -> Result<OpCode, Error> {
14+
match opcode {
15+
0x00 => Ok(OpCode::LD),
16+
0x01 => Ok(OpCode::ST),
17+
0x02 => Ok(OpCode::ADD),
18+
0x03 => Ok(OpCode::XOR),
19+
_ => Err(Error::InvalidOpCode(opcode)),
20+
}
21+
}
22+
}

do-core/src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#[derive(Debug)]
2+
pub enum Error {
3+
InvalidOpCode(u8),
4+
Op0OutOfRange,
5+
Op1OutOfRange,
6+
AdditionOverflow(u32, u32),
7+
}
8+
9+
pub mod instruction;

0 commit comments

Comments
 (0)