Incomplete, but I want to make sure the ideas I have here don't get wiped. Sadly this commit won't compile.

This commit is contained in:
2022-09-15 21:29:27 +00:00
parent 6d17dffcdf
commit 2ae60a607c
8 changed files with 238 additions and 210 deletions
+11 -13
View File
@@ -18,7 +18,7 @@ Instruction instructions[OPCODECOUNT] = {
{ "call", CALL, Address, None}
};
unsigned char GetInstructionMask(TokenType type) {
unsigned char GetInstructionMask(Mnemonic type) {
switch (type) {
case COPY:
return 0x20; //0b00100000; ORing 0x80 marks the first parameter as an address
@@ -93,7 +93,7 @@ Register registers[REGISTERCOUNT] = {
{ "r8", R8 }
};
const Instruction* GetOpcodeDetails(TokenType type) {
const Instruction* GetOpcodeDetails(Mnemonic type) {
for(int i = 0; i < OPCODECOUNT; i++) {
if (instructions[i].op == type) return &instructions[i];
}
@@ -101,12 +101,12 @@ const Instruction* GetOpcodeDetails(TokenType type) {
return NULL;
}
int IsOpcode(const char* text, TokenType* opcode) {
int IsOpcode(const char* text, Mnemonic* opcode) {
if (!text) return 0;
for(int i = 0; i < OPCODECOUNT; i++) {
if (strcmp(instructions[i].lexeme, text) == 0) {
if (opcode) *opcode = instructions[i].op;
if (strcmp(instructions[i], text) == 0) {
if (opcode) *opcode = instructions[i].Mnemonic;
return 1;
}
}
@@ -114,15 +114,13 @@ int IsOpcode(const char* text, TokenType* opcode) {
return 0;
}
int IsRegister(const char* text, TokenType* reg) {
int IsRegister(const char* text, Registers* reg) {
if (!text) return 0;
for(int i = 0; i < REGISTERCOUNT; i++) {
if (strcmp(registers[i].lexeme, text) == 0) {
*reg = registers[i].type;
return 1;
}
}
int length = strlen(text);
return 0;
if (length != 2) return 0;
if (text[0] != 'r') return 0;
return text[1] >= '1' && text[1] <= '8';
}