Better cmdline args, start work on compiler

This commit is contained in:
2026-01-21 11:17:19 +11:00
parent c6762a7966
commit d3c03b4987
5 changed files with 131 additions and 1 deletions

29
src/compiler.c Normal file
View File

@@ -0,0 +1,29 @@
#include "compiler.h"
#include "types.h"
#include "include/estr.h"
char* compileGroundProgram(GroundProgram* program) {
Estr start = CREATE_ESTR("global _start\nsection .text\n_start:\n");
Estr data = CREATE_ESTR("section .rodata\n");
for (size_t i = 0; i < program->size; i++) {
switch (program->instructions[i].type) {
case END: {
APPEND_ESTR(start, " mov rax, 60\n");
APPEND_ESTR(start, " mov rdi, 0\n");
APPEND_ESTR(start, " syscall\n");
break;
}
default: {
printf("no\n");
exit(1);
}
}
}
Estr complete = CREATE_ESTR("");
APPEND_ESTR(complete, start.str);
APPEND_ESTR(complete, data.str)
return complete.str;
}