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
+33 -17
View File
@@ -2,30 +2,46 @@
#define OPCODES_H
#include <string.h>
#include "token.h"
#include "symbols_table.h"
#define OPCODECOUNT 13
#define REGISTERCOUNT 8
//const unsigned char COPYADDRESSMASK = 0x80;
typedef enum {
R1, R2, R3, R4, R5, R6, R7, R8
} Registers;
typedef enum {
COPY, ADD, SUB, JZ, INT, YLD, RET,
CMP, NOP, JMP, CALL, IN, OUT,
} Mnemonic;
typedef enum {
None,
Constant,
Address
} OpcodeParameter;
typedef struct {
char* lexeme;
TokenType op;
TokenClass parameter_one;
TokenClass parameter_two;
Mnemonic Mnemonic;
OpcodeParameter ParameterOneType;
OpcodeParameter ParameterTwoType;
union {
int Constant;
Symbol* Symbol;
} ParameterOne;
union {
int Constant;
Symbol* Symbol;
} ParameterTwo;
} Instruction;
typedef struct {
char* lexeme;
TokenType type;
} Register;
extern Instruction instructions[OPCODECOUNT];
extern Register registers[REGISTERCOUNT];
int IsOpcode(const char*, TokenType*);
int IsRegister(const char*, TokenType*);
const Instruction* GetOpcodeDetails(TokenType);
unsigned char GetInstructionMask(TokenType type);
int IsOpcode(const char*, Mnemonic*);
int IsRegister(const char*, Registers*);
//const Instruction* GetOpcodeDetails(Mnemonic);
unsigned char GetInstructionMask(Mnemonic type);
#endif