Skip to content

Commit d2d003f

Browse files
committed
fix(instruction) Mnemonic issues with encoding.
1 parent 8bfecd9 commit d2d003f

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

examples/all_valid.rs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
use arrseq_lightning::instruction::Instruction;
2+
3+
fn main() {
4+
let mut count = 0u32;
5+
loop {
6+
let decoded = Instruction::decode(count);
7+
dbg!(decoded);
8+
count += 1;
9+
}
10+
}

src/instruction.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use proc_bitfield::{bitfield, ConvRaw};
2+
use crate::instruction::mnemonic::Operation;
23
use crate::num::MaskedU8;
34

45
pub mod memory;
@@ -15,11 +16,11 @@ bitfield! {
1516

1617
#[derive(Debug, Clone, Copy, PartialEq, Default)]
1718
#[repr(u8)]
18-
pub enum Scale {
19+
pub enum Scale {
1920
#[default]
20-
X8,
21-
X16,
22-
X32,
21+
X8,
22+
X16,
23+
X32,
2324
X64
2425
}
2526

@@ -44,7 +45,7 @@ impl From<Scale> for u8 {
4445
#[derive(Debug, Clone, Copy, PartialEq)]
4546
#[repr(u8)]
4647
pub enum Instruction {
47-
Mnemonic(mnemonic::Format),
48+
Mnemonic(mnemonic::Operation),
4849

4950
LoadImmediate(register::LoadImmediateOperation),
5051
BuildVector(register::BuildVectorOperation),
@@ -108,14 +109,17 @@ impl Instruction {
108109
Self::BINARY_CODE => Self::Binary(binary::Operation::from(encoded)),
109110
Self::REGROUP_BINARY_CODE => Self::RegroupBinary(binary::RegroupingBinaryOperation::from(encoded)),
110111
Self::REGROUP_QUATERNARY_CODE => Self::RegroupQuaternary(binary::RegroupingQuaternaryOperation::from(encoded)),
111-
112-
_ => unimplemented!()
112+
_ => Self::Mnemonic(mnemonic::Format::from(0).operation())
113113
}
114114
}
115115

116116
pub fn encode(self) -> u32 {
117117
let (opcode, operands) = match self {
118-
Instruction::Mnemonic(op) => (Self::MNEMONIC_CODE, u32::from(op)),
118+
Instruction::Mnemonic(op) => {
119+
let mut inner = mnemonic::Format::from(0);
120+
inner.set_operation(op);
121+
(Self::MNEMONIC_CODE, u32::from(inner))
122+
},
119123
Instruction::LoadImmediate(op) => (Self::LOAD_IMMEDIATE_CODE, u32::from(op)),
120124
Instruction::BuildVector(op) => (Self::BUILD_VECTOR_CODE, u32::from(op)),
121125
Instruction::UnBuildVector(op) => (Self::UNBUILD_VECTOR_CODE, u32::from(op)),

0 commit comments

Comments
 (0)