forked from valida-xyz/valida
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request valida-xyz#148 from valida-xyz/ali/pretty_print
make interactive debugger to pretty print instructions
- Loading branch information
Showing
6 changed files
with
210 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,88 @@ | ||
use num_enum::TryFromPrimitive; | ||
|
||
pub const BYTES_PER_INSTR: u32 = 24; // 4 bytes per word * 6 words per instruction | ||
|
||
#[repr(u32)] | ||
#[derive(Debug, TryFromPrimitive)] | ||
pub enum Opcode { | ||
LOAD32 = 1, | ||
STORE32 = 2, | ||
JAL = 3, | ||
JALV = 4, | ||
BEQ = 5, | ||
BNE = 6, | ||
IMM32 = 7, | ||
STOP = 8, | ||
READ_ADVICE = 9, | ||
LOADFP = 10, | ||
ADD32 = 100, | ||
SUB32 = 101, | ||
MUL32 = 102, | ||
DIV32 = 103, | ||
SDIV32 = 110, | ||
LT32 = 104, | ||
SHL32 = 105, | ||
SHR32 = 106, | ||
AND32 = 107, | ||
OR32 = 108, | ||
XOR32 = 109, | ||
NE32 = 111, | ||
MULHU32 = 112, | ||
SRA32 = 113, | ||
MULHS32 = 114, | ||
LTE32 = 115, | ||
EQ32 = 116, | ||
ADD = 200, | ||
SUB = 201, | ||
MUL = 202, | ||
WRITE = 300, | ||
} | ||
|
||
macro_rules! declare_opcode { | ||
($opcode : ident) => { | ||
pub const $opcode: u32 = Opcode::$opcode as u32; | ||
}; | ||
} | ||
|
||
// TODO: should combine enum together | ||
|
||
/// CORE | ||
pub const LOAD32: u32 = 1; | ||
pub const STORE32: u32 = 2; | ||
pub const JAL: u32 = 3; | ||
pub const JALV: u32 = 4; | ||
pub const BEQ: u32 = 5; | ||
pub const BNE: u32 = 6; | ||
pub const IMM32: u32 = 7; | ||
pub const STOP: u32 = 8; | ||
pub const LOADFP: u32 = 10; | ||
declare_opcode!(LOAD32); | ||
declare_opcode!(STORE32); | ||
declare_opcode!(JAL); | ||
declare_opcode!(JALV); | ||
declare_opcode!(BEQ); | ||
declare_opcode!(BNE); | ||
declare_opcode!(IMM32); | ||
declare_opcode!(STOP); | ||
declare_opcode!(LOADFP); | ||
|
||
/// NONDETERMINISTIC | ||
pub const READ_ADVICE: u32 = 9; | ||
declare_opcode!(READ_ADVICE); | ||
|
||
/// U32 ALU | ||
pub const ADD32: u32 = 100; | ||
pub const SUB32: u32 = 101; | ||
pub const MUL32: u32 = 102; | ||
pub const DIV32: u32 = 103; | ||
pub const SDIV32: u32 = 110; // TODO: Should we redo the numbers? Need to update compiler? | ||
pub const LT32: u32 = 104; | ||
pub const SHL32: u32 = 105; | ||
pub const SHR32: u32 = 106; | ||
pub const AND32: u32 = 107; | ||
pub const OR32: u32 = 108; | ||
pub const XOR32: u32 = 109; | ||
pub const NE32: u32 = 111; | ||
pub const MULHU32: u32 = 112; | ||
pub const SRA32: u32 = 113; | ||
pub const MULHS32: u32 = 114; | ||
pub const LTE32: u32 = 115; | ||
pub const EQ32: u32 = 116; | ||
declare_opcode!(ADD32); | ||
declare_opcode!(SUB32); | ||
declare_opcode!(MUL32); | ||
declare_opcode!(DIV32); | ||
declare_opcode!(SDIV32); | ||
declare_opcode!(LT32); | ||
declare_opcode!(SHL32); | ||
declare_opcode!(SHR32); | ||
declare_opcode!(AND32); | ||
declare_opcode!(OR32); | ||
declare_opcode!(XOR32); | ||
declare_opcode!(NE32); | ||
declare_opcode!(MULHU32); | ||
declare_opcode!(SRA32); | ||
declare_opcode!(MULHS32); | ||
declare_opcode!(LTE32); | ||
declare_opcode!(EQ32); | ||
|
||
/// NATIVE FIELD | ||
pub const ADD: u32 = 200; | ||
pub const SUB: u32 = 201; | ||
pub const MUL: u32 = 202; | ||
declare_opcode!(ADD); | ||
declare_opcode!(SUB); | ||
declare_opcode!(MUL); | ||
|
||
/// OUTPUT | ||
pub const WRITE: u32 = 300; | ||
declare_opcode!(WRITE); |