57 lines
1.1 KiB
C
57 lines
1.1 KiB
C
#pragma once
|
|
#include "VM/VM.h"
|
|
|
|
///@param program_pos position in vm->program next afrer opcode
|
|
///@returns number of bytes read
|
|
typedef i32 (*InstructionImplFunc_t)(VM* vm);
|
|
|
|
typedef enum __attribute__((__packed__)) Opcode {
|
|
Opcode_NOP,
|
|
Opcode_EXIT,
|
|
Opcode_SYS,
|
|
|
|
Opcode_MOVC,
|
|
Opcode_MOVR,
|
|
|
|
Opcode_ADD,
|
|
Opcode_SUB,
|
|
Opcode_MUL,
|
|
Opcode_DIV,
|
|
Opcode_MOD,
|
|
|
|
Opcode_EQ,
|
|
Opcode_NE,
|
|
Opcode_LT,
|
|
Opcode_LE,
|
|
Opcode_GT,
|
|
Opcode_GE,
|
|
Opcode_NOT,
|
|
Opcode_INV,
|
|
Opcode_OR,
|
|
Opcode_XOR,
|
|
Opcode_AND,
|
|
|
|
Opcode_JMP,
|
|
Opcode_JNZ,
|
|
Opcode_JZ,
|
|
} Opcode;
|
|
|
|
typedef struct Instruction {
|
|
str name;
|
|
InstructionImplFunc_t implementation;
|
|
Opcode opcode;
|
|
} Instruction;
|
|
|
|
#define Instruction_construct(NAME) {\
|
|
.name = STR(#NAME), \
|
|
.implementation = NAME##_impl, \
|
|
.opcode = Opcode_##NAME\
|
|
}
|
|
|
|
/// @brief get instruction info from table
|
|
/// @param opcode any byte
|
|
/// @return ptr to struct or NULL
|
|
const Instruction* NULLABLE(Instruction_getByOpcode)(Opcode opcode);
|
|
const Instruction* NULLABLE(Instruction_getByName)(str name);
|
|
void Instruction_destroySearchStructs();
|