Some refactoring to update everything to use the new structures and some new considerations for how Symbols and Instructions shoudl be represented.

This commit is contained in:
2022-09-15 22:14:38 -05:00
parent 2ae60a607c
commit 0b58e0124f
5 changed files with 119 additions and 64 deletions
+8 -6
View File
@@ -4,8 +4,6 @@
#include <string.h>
#include "symbols_table.h"
#define OPCODECOUNT 13
typedef enum {
R1, R2, R3, R4, R5, R6, R7, R8
} Registers;
@@ -16,9 +14,10 @@ typedef enum {
} Mnemonic;
typedef enum {
None,
Constant,
Address
NoParameter,
ConstantParameter,
AddressParameter,
RegisterParameter
} OpcodeParameter;
typedef struct {
@@ -37,10 +36,13 @@ typedef struct {
} ParameterTwo;
} Instruction;
extern Instruction instructions[OPCODECOUNT];
//extern Instruction instructions[OPCODECOUNT];
Instruction* CreateInstruction(Mnemonic mnemonic);
void FreeInstruction(Instruction* instruction);
int IsOpcode(const char*, Mnemonic*);
int IsRegister(const char*, Registers*);
void GetMnemonicText(Mnemonic mnemonic, char buffer[12]);
//const Instruction* GetOpcodeDetails(Mnemonic);
unsigned char GetInstructionMask(Mnemonic type);
+14 -14
View File
@@ -18,24 +18,24 @@
// int resolved;
// } Symbol;
typedef struct {
Mnemonic Mnemonic;
TokenClass ParameterOneType;
TokenClass ParameterTwoType;
// typedef struct {
// Mnemonic Mnemonic;
// TokenClass ParameterOneType;
// TokenClass ParameterTwoType;
union {
uint16_t Constant;
Symbol* Address;
} ParameterOne;
// union {
// uint16_t Constant;
// Symbol* Address;
// } ParameterOne;
union {
uint16_t Constant;
Symbol* Address;
} ParameterTwo;
} IROpcode;
// union {
// uint16_t Constant;
// Symbol* Address;
// } ParameterTwo;
// } IROpcode;
typedef struct {
List* Opcodes;
List* Instructions;
SymbolTable* SymbolsTable;
} IRState;
+11 -1
View File
@@ -8,11 +8,21 @@
#define SYMBOLSTABLE_DEFAULT_CAPACITY 128
typedef enum {
Data,
Address
} SymbolType;
typedef struct {
void* Value;
char* Name;
int Length;
int Resolved;
union {
char* Text;
int Number;
//Instruction Instruction;
} Value;
} Symbol;
typedef struct {