From 3c7056c5e6f476e8ab507c96424f5683e362641d Mon Sep 17 00:00:00 2001 From: Garritt McCune Date: Mon, 29 Aug 2022 21:23:02 +0000 Subject: [PATCH] The main function will now write out the output of the parser. --- .gitignore | 3 ++- misc/test.asm | 4 ++-- src/main.c | 29 ++++++++++++++++++----------- src/parser.c | 20 -------------------- 4 files changed, 22 insertions(+), 34 deletions(-) diff --git a/.gitignore b/.gitignore index c8cc4d0..ff641a7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ assm obj/ -bin/ \ No newline at end of file +bin/ +*.bin \ No newline at end of file diff --git a/misc/test.asm b/misc/test.asm index 10712fb..6e50977 100644 --- a/misc/test.asm +++ b/misc/test.asm @@ -2,8 +2,8 @@ .db msg "Hello, world!", 0 .db more_stuff "AA", 0 copy r7, msg ; // -cmp r8, r3 ;1000 1111 -add r4, r1 +cmp r8, msg ;1000 1111 +add r4, 0x42 sub r1, r8 int 20 jz 45 diff --git a/src/main.c b/src/main.c index 5e44a43..32e5a7c 100644 --- a/src/main.c +++ b/src/main.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -21,22 +22,28 @@ int main(int argc, char* args[]) { List* list = GenerateTokenList(source_code); - for(int i = 0; i < list->size; i++) { - Token* t = (Token*) list->content[i]; + // for(int i = 0; i < list->size; i++) { + // Token* t = (Token*) list->content[i]; - if (t->type == LineEnd) { - if (i - 1 >= 0 && ((Token*) list->content[i - 1])->type != LineEnd) - printf("\n"); + // if (t->type == LineEnd) { + // if (i - 1 >= 0 && ((Token*) list->content[i - 1])->type != LineEnd) + // printf("\n"); - continue; - } + // continue; + // } - printf("[T: %i][C: %i] '%s' ", t->type, t->token_class, t->lexeme); - if (t->type == LABEL) printf("* "); - } + // printf("[T: %i][C: %i] '%s' ", t->type, t->token_class, t->lexeme); + // if (t->type == LABEL) printf("* "); + // } unsigned char* image = ParseTokens(list); - Disassemble(image); + //Disassemble(image); + + FILE* program = fopen("program.bin", "w+b"); + + fwrite(image, 1, image[2] + image[3], program); + + fclose(program); free(source_code); } \ No newline at end of file diff --git a/src/parser.c b/src/parser.c index 6043dce..9c113f4 100644 --- a/src/parser.c +++ b/src/parser.c @@ -32,8 +32,6 @@ int Expect(int, ...); int ExpectTokenClass(int, ...); const Symbol* GetSymbol(char*); List* SymbolsTable; -void WriteMemory(unsigned char value, int location); -void WriteMemoryORMask(unsigned char mask, int location); unsigned int HeapTop = 4; unsigned int ProgramCounter = 0; unsigned char Heap[HIGHMEMORY]; @@ -481,22 +479,4 @@ int ParserAtEnd(void) { Token* PeekToken(void) { return TokensList->content[CurrentToken]; -} - -void WriteMemory(unsigned char value, int location) { - if (location > HIGHMEMORY) { - fprintf(stderr, "[Error] Exceeded memmory size\n"); - exit(1); - } - - Memory[location] = value; -} - -void WriteMemoryORMask(unsigned char mask, int location) { - if (location > HIGHMEMORY) { - fprintf(stderr, "[Error] Exceeded memmory size\n"); - exit(1); - } - - Memory[location] |= mask; } \ No newline at end of file