Reworked the tokens to include a broad class to make parameter matching a bit easier, and removed the hexadecimal distinction.
This commit is contained in:
+17
-9
@@ -2,15 +2,15 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
OpCode opcodes[OPCODECOUNT] = {
|
||||
{ "copy", COPY, Reg, Reg | Imm8 | Imm16 },
|
||||
{ "add", ADD, Reg, Reg | Imm8 | Imm16 },
|
||||
{ "sub", SUB, Reg, Reg | Imm8 | Imm16 },
|
||||
{ "jz", JZ, Imm8 | Imm16, None },
|
||||
{ "int", INT, Imm8, None },
|
||||
Instruction instructions[OPCODECOUNT] = {
|
||||
{ "copy", COPY, Reg, Reg | Immediate16 },
|
||||
{ "add", ADD, Reg, Reg | Immediate16 },
|
||||
{ "sub", SUB, Reg, Reg | Immediate16 },
|
||||
{ "jz", JZ, Immediate16, None },
|
||||
{ "int", INT, Immediate16, None },
|
||||
{ "yld", YLD, None, None },
|
||||
{ "ret", RET, None, None },
|
||||
{ "cmp", CMP, Reg | Imm8 | Imm16, Reg | Imm8 | Imm16 },
|
||||
{ "cmp", CMP, Reg | Immediate16, Reg | Immediate16 },
|
||||
{ "in", IN, None, None},
|
||||
{ "out", OUT, None, None}
|
||||
};
|
||||
@@ -26,12 +26,20 @@ Register registers[REGISTERCOUNT] = {
|
||||
{ "r8", R8 }
|
||||
};
|
||||
|
||||
const Instruction* GetOpcodeDetails(TokenType type) {
|
||||
for(int i = 0; i < OPCODECOUNT; i++) {
|
||||
if (instructions[i].op == type) return &instructions[i];
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int IsOpcode(const char* text, TokenType* opcode) {
|
||||
if (!text) return 0;
|
||||
|
||||
for(int i = 0; i < OPCODECOUNT; i++) {
|
||||
if (strcmp(opcodes[i].lexeme, text) == 0) {
|
||||
if (opcode) *opcode = opcodes[i].op;
|
||||
if (strcmp(instructions[i].lexeme, text) == 0) {
|
||||
if (opcode) *opcode = instructions[i].op;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user