pub mod stack {
pub const PUSH_IMM: u8 = 0x01;
pub const PUSH_IMM8: u8 = 0x02;
pub const PUSH_REG: u8 = 0x03;
pub const POP_REG: u8 = 0x04;
pub const DUP: u8 = 0x05;
pub const SWAP: u8 = 0x06;
pub const DROP: u8 = 0x07;
pub const PUSH_IMM16: u8 = 0x08;
pub const PUSH_IMM32: u8 = 0x09;
}
pub mod register {
pub const MOV_IMM: u8 = 0x10;
pub const MOV_REG: u8 = 0x11;
pub const LOAD_MEM: u8 = 0x12;
pub const STORE_MEM: u8 = 0x13;
}
pub mod arithmetic {
pub const ADD: u8 = 0x20;
pub const SUB: u8 = 0x21;
pub const MUL: u8 = 0x22;
pub const XOR: u8 = 0x23;
pub const AND: u8 = 0x24;
pub const OR: u8 = 0x25;
pub const SHL: u8 = 0x26;
pub const SHR: u8 = 0x27;
pub const NOT: u8 = 0x28;
pub const ROL: u8 = 0x29;
pub const ROR: u8 = 0x2A;
pub const INC: u8 = 0x2B;
pub const DEC: u8 = 0x2C;
pub const DIV: u8 = 0x46;
pub const MOD: u8 = 0x47;
pub const IDIV: u8 = 0x48;
pub const IMOD: u8 = 0x49;
}
pub mod control {
pub const CMP: u8 = 0x30;
pub const JMP: u8 = 0x31;
pub const JZ: u8 = 0x32;
pub const JNZ: u8 = 0x33;
pub const JGT: u8 = 0x34;
pub const JLT: u8 = 0x35;
pub const JGE: u8 = 0x36;
pub const JLE: u8 = 0x37;
pub const CALL: u8 = 0x38;
pub const RET: u8 = 0x39;
}
pub mod special {
pub const NOP: u8 = 0x40;
pub const NOP_N: u8 = 0x41;
pub const OPAQUE_TRUE: u8 = 0x42;
pub const OPAQUE_FALSE: u8 = 0x43;
pub const HASH_CHECK: u8 = 0x44;
pub const TIMING_CHECK: u8 = 0x45;
}
pub mod convert {
pub const SEXT8: u8 = 0x50;
pub const SEXT16: u8 = 0x51;
pub const SEXT32: u8 = 0x52;
pub const TRUNC8: u8 = 0x53;
pub const TRUNC16: u8 = 0x54;
pub const TRUNC32: u8 = 0x55;
}
pub mod memory {
pub const LOAD8: u8 = 0x60;
pub const LOAD16: u8 = 0x61;
pub const LOAD32: u8 = 0x62;
pub const LOAD64: u8 = 0x63;
pub const STORE8: u8 = 0x64;
pub const STORE16: u8 = 0x65;
pub const STORE32: u8 = 0x66;
pub const STORE64: u8 = 0x67;
}
pub mod vector {
pub const VEC_NEW: u8 = 0x80;
pub const VEC_LEN: u8 = 0x81;
pub const VEC_CAP: u8 = 0x82;
pub const VEC_PUSH: u8 = 0x83;
pub const VEC_POP: u8 = 0x84;
pub const VEC_GET: u8 = 0x85;
pub const VEC_SET: u8 = 0x86;
pub const VEC_REPEAT: u8 = 0x87;
pub const VEC_CLEAR: u8 = 0x88;
pub const VEC_RESERVE: u8 = 0x89;
}
pub mod string {
pub const STR_NEW: u8 = 0x90;
pub const STR_LEN: u8 = 0x91;
pub const STR_PUSH: u8 = 0x92;
pub const STR_GET: u8 = 0x93;
pub const STR_SET: u8 = 0x94;
pub const STR_CMP: u8 = 0x95;
pub const STR_EQ: u8 = 0x96;
pub const STR_HASH: u8 = 0x97;
pub const STR_CONCAT: u8 = 0x98;
}
pub mod heap {
pub const HEAP_ALLOC: u8 = 0x70;
pub const HEAP_FREE: u8 = 0x71;
pub const HEAP_LOAD8: u8 = 0x72;
pub const HEAP_LOAD16: u8 = 0x73;
pub const HEAP_LOAD32: u8 = 0x74;
pub const HEAP_LOAD64: u8 = 0x75;
pub const HEAP_STORE8: u8 = 0x76;
pub const HEAP_STORE16: u8 = 0x77;
pub const HEAP_STORE32: u8 = 0x78;
pub const HEAP_STORE64: u8 = 0x79;
pub const HEAP_SIZE: u8 = 0x7A;
}
pub mod native {
pub const NATIVE_CALL: u8 = 0xF0;
pub const NATIVE_READ: u8 = 0xF1;
pub const NATIVE_WRITE: u8 = 0xF2;
pub const INPUT_LEN: u8 = 0xF3;
}
pub mod exec {
pub const HALT: u8 = 0xFF;
pub const HALT_ERR: u8 = 0xFE;
}
pub mod flags {
pub use crate::build_config::flags::*;
}
#[cfg(feature = "vm_debug")]
pub fn opcode_name(op: u8) -> &'static str {
match op {
stack::PUSH_IMM => "PUSH_IMM",
stack::PUSH_IMM8 => "PUSH_IMM8",
stack::PUSH_IMM16 => "PUSH_IMM16",
stack::PUSH_IMM32 => "PUSH_IMM32",
stack::PUSH_REG => "PUSH_REG",
stack::POP_REG => "POP_REG",
stack::DUP => "DUP",
stack::SWAP => "SWAP",
stack::DROP => "DROP",
register::MOV_IMM => "MOV_IMM",
register::MOV_REG => "MOV_REG",
register::LOAD_MEM => "LOAD_MEM",
register::STORE_MEM => "STORE_MEM",
arithmetic::ADD => "ADD",
arithmetic::SUB => "SUB",
arithmetic::MUL => "MUL",
arithmetic::XOR => "XOR",
arithmetic::AND => "AND",
arithmetic::OR => "OR",
arithmetic::SHL => "SHL",
arithmetic::SHR => "SHR",
arithmetic::NOT => "NOT",
arithmetic::ROL => "ROL",
arithmetic::ROR => "ROR",
arithmetic::INC => "INC",
arithmetic::DEC => "DEC",
arithmetic::DIV => "DIV",
arithmetic::MOD => "MOD",
arithmetic::IDIV => "IDIV",
arithmetic::IMOD => "IMOD",
control::CMP => "CMP",
control::JMP => "JMP",
control::JZ => "JZ",
control::JNZ => "JNZ",
control::JGT => "JGT",
control::JLT => "JLT",
control::JGE => "JGE",
control::JLE => "JLE",
control::CALL => "CALL",
control::RET => "RET",
special::NOP => "NOP",
special::NOP_N => "NOP_N",
special::OPAQUE_TRUE => "OPAQUE_TRUE",
special::OPAQUE_FALSE => "OPAQUE_FALSE",
special::HASH_CHECK => "HASH_CHECK",
special::TIMING_CHECK => "TIMING_CHECK",
convert::SEXT8 => "SEXT8",
convert::SEXT16 => "SEXT16",
convert::SEXT32 => "SEXT32",
convert::TRUNC8 => "TRUNC8",
convert::TRUNC16 => "TRUNC16",
convert::TRUNC32 => "TRUNC32",
memory::LOAD8 => "LOAD8",
memory::LOAD16 => "LOAD16",
memory::LOAD32 => "LOAD32",
memory::LOAD64 => "LOAD64",
memory::STORE8 => "STORE8",
memory::STORE16 => "STORE16",
memory::STORE32 => "STORE32",
memory::STORE64 => "STORE64",
vector::VEC_NEW => "VEC_NEW",
vector::VEC_LEN => "VEC_LEN",
vector::VEC_CAP => "VEC_CAP",
vector::VEC_PUSH => "VEC_PUSH",
vector::VEC_POP => "VEC_POP",
vector::VEC_GET => "VEC_GET",
vector::VEC_SET => "VEC_SET",
vector::VEC_REPEAT => "VEC_REPEAT",
vector::VEC_CLEAR => "VEC_CLEAR",
vector::VEC_RESERVE => "VEC_RESERVE",
string::STR_NEW => "STR_NEW",
string::STR_LEN => "STR_LEN",
string::STR_PUSH => "STR_PUSH",
string::STR_GET => "STR_GET",
string::STR_SET => "STR_SET",
string::STR_CMP => "STR_CMP",
string::STR_EQ => "STR_EQ",
string::STR_HASH => "STR_HASH",
string::STR_CONCAT => "STR_CONCAT",
heap::HEAP_ALLOC => "HEAP_ALLOC",
heap::HEAP_FREE => "HEAP_FREE",
heap::HEAP_LOAD8 => "HEAP_LOAD8",
heap::HEAP_LOAD16 => "HEAP_LOAD16",
heap::HEAP_LOAD32 => "HEAP_LOAD32",
heap::HEAP_LOAD64 => "HEAP_LOAD64",
heap::HEAP_STORE8 => "HEAP_STORE8",
heap::HEAP_STORE16 => "HEAP_STORE16",
heap::HEAP_STORE32 => "HEAP_STORE32",
heap::HEAP_STORE64 => "HEAP_STORE64",
heap::HEAP_SIZE => "HEAP_SIZE",
native::NATIVE_CALL => "NATIVE_CALL",
native::NATIVE_READ => "NATIVE_READ",
native::NATIVE_WRITE => "NATIVE_WRITE",
native::INPUT_LEN => "INPUT_LEN",
exec::HALT => "HALT",
exec::HALT_ERR => "HALT_ERR",
_ => "UNKNOWN",
}
}