use crate::parser::dialect::puc_lua::{DecodedInstructionFields, define_puc_lua_opcodes};
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub enum Lua53OperandKind {
A,
AB,
AC,
ABC,
ABx,
AsBx,
Ax,
}
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub enum Lua53ExtraWordPolicy {
None,
ExtraArg,
ExtraArgIfCZero,
}
define_puc_lua_opcodes!(
opcode: Lua53Opcode,
operand_kind: Lua53OperandKind,
extra_word_policy: Lua53ExtraWordPolicy,
[
(Move, "MOVE", AB),
(LoadK, "LOADK", ABx),
(LoadKx, "LOADKX", A, ExtraArg),
(LoadBool, "LOADBOOL", ABC),
(LoadNil, "LOADNIL", AB),
(GetUpVal, "GETUPVAL", AB),
(GetTabUp, "GETTABUP", ABC),
(GetTable, "GETTABLE", ABC),
(SetTabUp, "SETTABUP", ABC),
(SetUpVal, "SETUPVAL", AB),
(SetTable, "SETTABLE", ABC),
(NewTable, "NEWTABLE", ABC),
(Self_, "SELF", ABC),
(Add, "ADD", ABC),
(Sub, "SUB", ABC),
(Mul, "MUL", ABC),
(Mod, "MOD", ABC),
(Pow, "POW", ABC),
(Div, "DIV", ABC),
(Idiv, "IDIV", ABC),
(Band, "BAND", ABC),
(Bor, "BOR", ABC),
(Bxor, "BXOR", ABC),
(Shl, "SHL", ABC),
(Shr, "SHR", ABC),
(Unm, "UNM", AB),
(BNot, "BNOT", AB),
(Not, "NOT", AB),
(Len, "LEN", AB),
(Concat, "CONCAT", ABC),
(Jmp, "JMP", AsBx),
(Eq, "EQ", ABC),
(Lt, "LT", ABC),
(Le, "LE", ABC),
(Test, "TEST", AC),
(TestSet, "TESTSET", ABC),
(Call, "CALL", ABC),
(TailCall, "TAILCALL", ABC),
(Return, "RETURN", AB),
(ForLoop, "FORLOOP", AsBx),
(ForPrep, "FORPREP", AsBx),
(TForCall, "TFORCALL", ABC),
(TForLoop, "TFORLOOP", AsBx),
(SetList, "SETLIST", ABC, ExtraArgIfCZero),
(Closure, "CLOSURE", ABx),
(VarArg, "VARARG", AB),
(ExtraArg, "EXTRAARG", Ax),
]
);
#[derive(Debug, Clone, PartialEq)]
pub enum Lua53Operands {
A { a: u8 },
AB { a: u8, b: u16 },
AC { a: u8, c: u16 },
ABC { a: u8, b: u16, c: u16 },
ABx { a: u8, bx: u32 },
AsBx { a: u8, sbx: i32 },
Ax { ax: u32 },
}
impl Lua53Opcode {
pub(crate) fn decode_operands(self, fields: DecodedInstructionFields) -> Lua53Operands {
match self.operand_kind() {
Lua53OperandKind::A => Lua53Operands::A { a: fields.a },
Lua53OperandKind::AB => Lua53Operands::AB {
a: fields.a,
b: fields.b,
},
Lua53OperandKind::AC => Lua53Operands::AC {
a: fields.a,
c: fields.c,
},
Lua53OperandKind::ABC => Lua53Operands::ABC {
a: fields.a,
b: fields.b,
c: fields.c,
},
Lua53OperandKind::ABx => Lua53Operands::ABx {
a: fields.a,
bx: fields.bx,
},
Lua53OperandKind::AsBx => Lua53Operands::AsBx {
a: fields.a,
sbx: fields.sbx,
},
Lua53OperandKind::Ax => Lua53Operands::Ax { ax: fields.ax },
}
}
}
#[derive(Debug, Clone, Default, PartialEq)]
pub struct Lua53HeaderExtra;
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub struct Lua53ProtoExtra {
pub raw_is_vararg: u8,
}
#[derive(Debug, Clone, Default, PartialEq)]
pub struct Lua53ConstPoolExtra;
#[derive(Debug, Clone, Default, PartialEq)]
pub struct Lua53UpvalueExtra;
#[derive(Debug, Clone, Default, PartialEq)]
pub struct Lua53DebugExtra;
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub struct Lua53InstrExtra {
pub pc: u32,
pub word_len: u8,
pub extra_arg: Option<u32>,
}