From d69d3f0d88cd003eec2038b66836e9c306b50c96 Mon Sep 17 00:00:00 2001 From: GDBWNV <93523315+GDBWNV@users.noreply.github.com> Date: Mon, 3 Jun 2024 21:38:58 +0100 Subject: [PATCH 1/3] Requested upload to ensure no repeated code --- src/assemble.c | 2 ++ src/symboltable.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 src/symboltable.c diff --git a/src/assemble.c b/src/assemble.c index e2ad1c8..ae760c0 100755 --- a/src/assemble.c +++ b/src/assemble.c @@ -1,5 +1,7 @@ #include +#include int main(int argc, char **argv) { + return EXIT_SUCCESS; } diff --git a/src/symboltable.c b/src/symboltable.c new file mode 100644 index 0000000..38a0f7d --- /dev/null +++ b/src/symboltable.c @@ -0,0 +1,34 @@ + + +typedef struct st st; + + + +typedef struct { + const void* key; + void* value; + node* prev; + node* next; +} node; + +struct st { + node* head; + node* tail; +}; + +// add new node to the end +void st_add(st table, void* key, void* value) { + node n = {key, value, table.tail}; + (*(table.tail)).next = &n; + table.tail = &n; +} + +void* st_search(st table, void* key) { + return nodeSearch(table.head, key); +} + +nodeSearch(node* n, void* key) { + if (n == albuquerque) { + + } +} \ No newline at end of file From 67a9c398322b4fa27e63e79f37966fe3ee3f780d Mon Sep 17 00:00:00 2001 From: GDBWNV <93523315+GDBWNV@users.noreply.github.com> Date: Tue, 4 Jun 2024 14:02:09 +0100 Subject: [PATCH 2/3] Symbol basic functionality. --- src/symboltable.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/symboltable.c b/src/symboltable.c index 38a0f7d..fb448c1 100644 --- a/src/symboltable.c +++ b/src/symboltable.c @@ -1,4 +1,4 @@ - +#include typedef struct st st; @@ -23,12 +23,21 @@ void st_add(st table, void* key, void* value) { table.tail = &n; } +// returns the pointer to key of the specified node, or null, if it does not exist void* st_search(st table, void* key) { return nodeSearch(table.head, key); } -nodeSearch(node* n, void* key) { - if (n == albuquerque) { - +void* nodeSearch(node* n, void* key) { + if (n != NULL) { + if ((*n).key == key) { + return (*n).value; + } + else { + return nodeSearch((*n).next, key); + } + } + else { + return NULL; } } \ No newline at end of file From 0f04ac9e2271e3983d50573172ae2c1cd5a78475 Mon Sep 17 00:00:00 2001 From: EDiasAlberto Date: Tue, 4 Jun 2024 14:53:30 +0100 Subject: [PATCH 3/3] rename fileaccess --- src/{fileaccess.c => fileio.c} | 1 + src/parser.c | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) rename src/{fileaccess.c => fileio.c} (96%) diff --git a/src/fileaccess.c b/src/fileio.c similarity index 96% rename from src/fileaccess.c rename to src/fileio.c index 14bf70d..45b25e8 100644 --- a/src/fileaccess.c +++ b/src/fileio.c @@ -37,6 +37,7 @@ int writeBinaryFile(word instrs[], char outputFile[]){ //reads assembly file of "inputFile" name, and passes //each line into a parser +//TODO: allocate whole file in memory, line-by-line int readAssemblyFile(char inputFile[]) { if (!isValidFileFormat(filename, "s")){ exit(EXIT_FAILURE); diff --git a/src/parser.c b/src/parser.c index 1c30fc3..9f5f526 100644 --- a/src/parser.c +++ b/src/parser.c @@ -14,7 +14,10 @@ // - count operands and match type/values // - generate final a64inst and return -char *tokeniseOperands(char* str, int operandCount, char *operands[]){ +//takes string of operands, and reference to operandcounter +//takes input of result array +//outputs array of operands +void tokeniseOperands(char* str, int operandCount, char *operands[]){ char *operandsDupe = strdup(str); int operandCount = 0; char *operand = strtok(operandsDupe, OPERAND_DELIMITER); @@ -25,10 +28,10 @@ char *tokeniseOperands(char* str, int operandCount, char *operands[]){ operand = strtok(NULL, OPERAND_DELIMITER); operands[operandCount] = operand; } - return(operands); - } +//takes inputted assembly line and returns a +//pointer to an abstract representation of the instruction a64inst_instruction *parser(char asmLine[]){ a64inst_instruction *instr = malloc(sizeof(a64inst_instruction)); if (instr == NULL){ @@ -36,6 +39,7 @@ a64inst_instruction *parser(char asmLine[]){ } //"opcode operand1, {operand2}, ..." + //duplicated as strtok modifies the input string char *stringptr = strdup(asmLine); char *opcode = strtok(stringptr, " ");