#include "opcode.hpp" #include "die.hpp" struct op_t { const char* opname; OpcodeType optype; }; static const op_t opcode_tbl[] = {}; op_t get_op(Oc op) { switch (op) { case Oc::Unknown: return op_t{0, OpcodeType::Reg0}; case Oc::Add: return op_t{"add", OpcodeType::Reg3}; case Oc::Sub: return op_t{"sub", OpcodeType::Reg3}; case Oc::Mul: return op_t{"mul", OpcodeType::Reg3}; case Oc::Div: return op_t{"div", OpcodeType::Reg3}; case Oc::Mod: return op_t{"mod", OpcodeType::Reg3}; case Oc::Mov: return op_t{"mov", OpcodeType::Reg2}; case Oc::LoadConst: return op_t{"loadc", OpcodeType::Reg1I}; case Oc::LoadStack: return op_t{"lfi", OpcodeType::Reg1I}; case Oc::Jump: return op_t{"jump", OpcodeType::Reg0I}; case Oc::Equal: return op_t{"equal", OpcodeType::Reg2I}; case Oc::Less: return op_t{"less", OpcodeType::Reg2I}; case Oc::LessEqual: return op_t{"less-equal", OpcodeType::Reg2I}; case Oc::Call: return op_t{"call", OpcodeType::Reg2}; case Oc::Self: return op_t{"self", OpcodeType::Reg1}; case Oc::TailCall: return op_t{"tailcall", OpcodeType::Reg1I}; case Oc::Ret: return op_t{"ret", OpcodeType::Reg1}; case Oc::RetNil: return op_t{"retnil", OpcodeType::Reg0}; case Oc::ShiftRight: return op_t{"sri", OpcodeType::Reg2I}; case Oc::ShiftLeft: return op_t{"sli", OpcodeType::Reg2I}; case Oc::BitwiseAnd: return op_t{"band", OpcodeType::Reg3}; case Oc::BitwiseOr: return op_t{"bor", OpcodeType::Reg3}; case Oc::BitwiseXor: return op_t{"bxor", OpcodeType::Reg3}; case Oc::BitwiseNeg: return op_t{"bneg", OpcodeType::Reg2}; case Oc::MakeArray: return op_t{"make-array", OpcodeType::Reg1I}; case Oc::ArrayLoad: return op_t{"al", OpcodeType::Reg3}; case Oc::ArrayStore: return op_t{"as", OpcodeType::Reg4}; case Oc::Push: return op_t{"push", OpcodeType::Reg1}; case Oc::Pop: return op_t{"pop", OpcodeType::Reg1}; case Oc::StackReserve: return op_t{"sr", OpcodeType::Reg0I}; case Oc::AssertEqual: return op_t{"assert-equal", OpcodeType::Reg2}; case Oc::MakeDict: return op_t{"make-dict", OpcodeType::Reg1}; case Oc::SetJump: return op_t{"setjump", OpcodeType::Reg1I}; return op_t{"setglobal", OpcodeType::Reg2}; case Oc::GlobalLoad: return op_t{"global-load", OpcodeType::Reg2}; case Oc::GlobalStore: return op_t{"global-store", OpcodeType::Reg2}; case Oc::MakeClosure: return op_t{"make-closure", OpcodeType::Reg2}; case Oc::ClosureLoad: return op_t{"closure-load", OpcodeType::Reg1I}; default: die("Unknown opcode\n"); } } const char* opcode_name(Oc op) { return get_op(op).opname; } OpcodeType opcode_type(Oc op) { return get_op(op).optype; }