aboutsummaryrefslogtreecommitdiff
path: root/asm/main.c
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2023-11-03 21:12:15 +0000
committerAryadev Chavali <aryadev@aryadevchavali.com>2023-11-03 21:15:30 +0000
commitb8f6232bb266bc895267f8dde700aa67a91207d6 (patch)
tree126d98013c4713d9f6d8e526f28bce671c183d7c /asm/main.c
parent92f4f9011d431f9c197aff56a3dbb8a3963b4197 (diff)
downloadovm-b8f6232bb266bc895267f8dde700aa67a91207d6.tar.gz
ovm-b8f6232bb266bc895267f8dde700aa67a91207d6.tar.bz2
ovm-b8f6232bb266bc895267f8dde700aa67a91207d6.zip
Refactor assembler to use prog_t structure
Set the program structure correctly with a header using the parsed global instruction.
Diffstat (limited to 'asm/main.c')
-rw-r--r--asm/main.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/asm/main.c b/asm/main.c
index 6965c8c..842d8e9 100644
--- a/asm/main.c
+++ b/asm/main.c
@@ -88,9 +88,8 @@ int main(int argc, char *argv[])
#if VERBOSE >= 2
printf("\t[%sPARSER%s]: Beginning parse...\n", TERM_YELLOW, TERM_RESET);
#endif
- size_t number = 0;
- inst_t *instructions = NULL;
- perr_t parse_error = parse_stream(&tokens, &instructions, &number);
+ prog_t *program = NULL;
+ perr_t parse_error = parse_stream(&tokens, &program);
if (parse_error)
{
size_t column = 0;
@@ -108,21 +107,21 @@ int main(int argc, char *argv[])
}
#if VERBOSE >= 1
printf("\t[%sPARSER%s]: %lu tokens -> %lu instructions\n", TERM_GREEN,
- TERM_RESET, tokens.available, number);
+ TERM_RESET, tokens.available, program->count);
#endif
#if VERBOSE >= 2
printf("\t[%sPARSER%s]: Instructions parsed:\n", TERM_GREEN, TERM_RESET);
- for (size_t i = 0; i < number; ++i)
+ for (size_t i = 0; i < program->count; ++i)
{
printf("\t[%lu]: ", i);
- inst_print(instructions[i], stdout);
+ inst_print(program->instructions[i], stdout);
printf("\n");
}
#endif
fp = fopen(out_file, "wb");
- insts_write_bytecode_file(instructions, number, fp);
+ prog_write_file(program, fp);
fclose(fp);
#if VERBOSE >= 1
printf("[%sASSEMBLER%s]: Wrote bytecode to `%s`\n", TERM_GREEN, TERM_RESET,
@@ -137,7 +136,7 @@ end:
free(TOKEN_STREAM_AT(tokens.data, i).str);
free(tokens.data);
}
- if (instructions)
- free(instructions);
+ if (program)
+ free(program);
return ret;
}