From 6d6bf1cbaf0e709d1f321c0a476c3d120ea536ea Mon Sep 17 00:00:00 2001 From: Garritt McCune Date: Mon, 10 Oct 2022 18:36:38 +0000 Subject: [PATCH] Wrote the first step for the binary output. Doesn't handle instruction pointer symbols yet since those emit addresses that still need to be computed. --- src/main.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/main.c b/src/main.c index 1fb2939..13b8a1e 100644 --- a/src/main.c +++ b/src/main.c @@ -8,6 +8,10 @@ #include "../includes/futil.h" #include "../includes/scanner.h" +unsigned char Memory[2000]; + +void Setup(IRState*); + int main(int argc, char* args[]) { if (argc == 1) { printf("Usage: assm \n"); @@ -159,6 +163,8 @@ int main(int argc, char* args[]) { printf("\n"); } } + + Setup(image); //free(image); //Disassemble(image); //for(int i = 0; i < image->Opcodes->size; i++) { @@ -172,4 +178,43 @@ int main(int argc, char* args[]) { //fclose(program); free(source_code); +} + +void Setup(IRState* state) { + int start = 4; + int end = start; + + for(int i = 0; i < state->SymbolsTable->Size; i++) { + Symbol* symbol = state->SymbolsTable->Symbols[i]; + + switch(symbol->Type) { + case StringSymbol: + memccpy(&Memory[end], symbol->Value.String->String, 0, strlen(symbol->Value.String->String)); + + end += strlen(symbol->Value.String->String); + + if (symbol->Value.String->Terminated) { + Memory[end] = symbol->Value.String->TerminatingByte; + end++; + } + + //end++; + break; + case NumericSymbol: + Memory[end] = symbol->Value.Number >> 8 & 0xFF; + Memory[end + 1] = symbol->Value.Number & 0xFF; + end += 2; + break; + case InstructionPointerSymbol: + break; + default: + break; + } + } + + for(int i = 0; i < end; i++) { + if (i != 0 && i % 8 == 0) printf("\n"); + printf("%02x ", Memory[i]); + } + printf("\n"); } \ No newline at end of file