Modified how registers and opcodes are represented. This commit is a bit buggy but doesn't crash and burn at least. I just wanted the new structs push out before making a bigger mess of things as I try to organize this all.

This commit is contained in:
2022-02-17 21:35:57 -06:00
parent 3d4ab57f05
commit 19021ff782
6 changed files with 106 additions and 59 deletions
+20 -17
View File
@@ -9,23 +9,26 @@
#include "tokenizer.h"
typedef enum {
TK_Add,
TK_Sub,
TK_Mul,
TK_Div,
TK_Power,
TK_LParam,
TK_RParam,
TK_LBracket,
TK_RBracket,
TK_String,
TK_Number,
TK_Hex,
TK_Opcode,
TK_Register,
TK_Directive,
TK_Symbol,
TK_Comma
PLUS,
MINUS,
STAR,
SLASH,
POWER,
LPARAM,
RPARAM,
LBRACKET,
RBracket,
COMMA,
IDENTIFIER,
NUMBER,
HEX,
//Keywords
DB, ORG,
//Opcodes
COPY, ADD, SUB, JZ, INT, YLD, RET,
CMP, IN, OUT,
//Registers
R1, R2, R3, R4, R5, R6, R7, R8
} TokenType;
typedef struct {
+25 -5
View File
@@ -2,14 +2,34 @@
#define OPCODES_H
#include <string.h>
#include "lexer.h"
#define OPCODECOUNT 7
#define OPCODECOUNT 10
#define REGISTERCOUNT 8
extern char *opcodes[OPCODECOUNT];
extern char *registers[REGISTERCOUNT];
typedef enum {
None = 0,
Reg,
Imm8,
Imm16
} ParameterType;
int IsOpcode(const char*);
int IsRegister(const char*);
typedef struct {
char* lexeme;
TokenType op;
ParameterType parameter_one;
ParameterType parameter_two;
} OpCode;
typedef struct {
char* lexeme;
TokenType type;
} Register;
extern OpCode opcodes[OPCODECOUNT];
extern Register registers[REGISTERCOUNT];
int IsOpcode(const char*, TokenType*);
int IsRegister(const char*, TokenType*);
#endif