Updated the way Instructions keep track of symbols. Only their name is important but we need the Symbols to be able to track which Instruction they point to (if they do that is, i.e. a label symbol).
This commit is contained in:
+22
-6
@@ -1,10 +1,11 @@
|
||||
#include "../includes/parser.h"
|
||||
#include <stdio.h>
|
||||
|
||||
const List* TokensList;
|
||||
int CurrentToken = 0;
|
||||
|
||||
void PrintSymbols(void);
|
||||
void HandleOperation(void);
|
||||
Instruction* HandleOperation(void);
|
||||
void HandleAssemblerDirective(void);
|
||||
void AdvanceParser(void);
|
||||
void IgnoreParserLine(void);
|
||||
@@ -45,6 +46,13 @@ IRState* ParseTokens(List* tokens) {
|
||||
else symbol->Resolved = 1;
|
||||
|
||||
AdvanceParser(); //Consume the NewLine
|
||||
|
||||
// Instruction* ins = HandleOperation();
|
||||
|
||||
// if (!ins) continue;
|
||||
|
||||
// symbol->Value.Instruction = ins;
|
||||
// symbol->InstructionPointer = 1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@@ -78,13 +86,13 @@ Parameter* GetParameterType() {
|
||||
//case LabelClass:
|
||||
case IdentifierClass:
|
||||
param->ParameterType = AddressParameter;
|
||||
param->InterpretedAs = ConstantParameter;
|
||||
param->InterpretedAs = AddressParameter;
|
||||
|
||||
symbol = TryGetSymbol(token->Lemexe, MachineState.SymbolsTable);
|
||||
|
||||
if (!symbol) symbol = AddSymbolToTable(token->Lemexe, token->Lemexe, strlen(token->Lemexe), MachineState.SymbolsTable);
|
||||
|
||||
param->Value.Symbol = symbol;
|
||||
param->Value.Symbol = symbol->Name;
|
||||
|
||||
AdvanceParser();
|
||||
|
||||
@@ -111,13 +119,13 @@ Parameter* GetParameterType() {
|
||||
}
|
||||
else if (token->Class & AddressClass) {
|
||||
param->ParameterType = AddressParameter;
|
||||
param->ParameterType = AddressParameter;
|
||||
param->InterpretedAs = AddressParameter;
|
||||
|
||||
symbol = TryGetSymbol(token->Lemexe, MachineState.SymbolsTable);
|
||||
|
||||
if (!symbol) symbol = AddSymbolToTable(token->Lemexe, NULL, strlen(token->Lemexe), MachineState.SymbolsTable);
|
||||
|
||||
param->Value.Symbol = symbol;
|
||||
param->Value.Symbol = symbol->Name;
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "[Error] Line %d: Expected identifier, constant number or register.\n", token->LineNumber);
|
||||
@@ -154,10 +162,16 @@ Parameter* GetParameterType() {
|
||||
return param;
|
||||
}
|
||||
|
||||
void HandleOperation() {
|
||||
Instruction* HandleOperation() {
|
||||
Token* token = PeekToken();
|
||||
char mn[12];
|
||||
|
||||
if (token->Class != MnemonicClass) {
|
||||
fprintf(stderr, "[Error] Line %d: Expected instruction mnemonic\n", token->LineNumber);
|
||||
IgnoreParserLine();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Instruction* ins = CreateInstruction(token->Value.Mnemonic);
|
||||
|
||||
GetMnemonicText(ins->Mnemonic, mn);
|
||||
@@ -202,6 +216,8 @@ void HandleOperation() {
|
||||
AdvanceParser(); //Consume the line break
|
||||
|
||||
free(ins);
|
||||
|
||||
return MachineState.Instructions->content[(MachineState.Instructions->size - 1) * sizeof(Instruction)];
|
||||
}
|
||||
|
||||
void PrintSymbols(void) {
|
||||
|
||||
Reference in New Issue
Block a user