2026-01-21 11:17:19 +11:00
|
|
|
#include "compiler.h"
|
|
|
|
|
#include "types.h"
|
2026-01-21 13:25:13 +11:00
|
|
|
|
2026-04-10 17:43:51 +10:00
|
|
|
#include <tram.h>
|
2026-01-21 13:25:13 +11:00
|
|
|
|
2026-04-10 17:43:51 +10:00
|
|
|
void compileGroundProgram(GroundProgram* program, char* name) {
|
|
|
|
|
Tram_Program tramProgram = Tram_Program_Create();
|
2026-01-21 13:25:13 +11:00
|
|
|
|
2026-04-10 17:43:51 +10:00
|
|
|
Tram_ParameterList parameters = Tram_ParameterList_Create(1, (Tram_Parameter[]){Tram_Parameter_Variable("main")});
|
|
|
|
|
Tram_Program_AddInstruction(&tramProgram, Tram_Instruction_Create(Tram_InstructionType_CreateLabel, parameters));
|
2026-01-21 13:25:13 +11:00
|
|
|
|
|
|
|
|
for (size_t i = 0; i < program->size; i++) {
|
2026-04-10 17:43:51 +10:00
|
|
|
compileGroundInstruction(&program->instructions[i], &tramProgram);
|
2026-01-21 13:25:13 +11:00
|
|
|
}
|
2026-01-21 11:17:19 +11:00
|
|
|
|
2026-04-10 17:43:51 +10:00
|
|
|
Tram_Compiler* compiler = Tram_Compiler_Create(tramProgram);
|
|
|
|
|
Tram_Compiler_SetLogLevel(compiler, Tram_LogLevel_Debug);
|
|
|
|
|
Tram_Compiler_SetTarget(compiler, Tram_Target_x86_64_Linux_libc);
|
|
|
|
|
Tram_Compiler_Compile(compiler);
|
2026-01-21 13:25:13 +11:00
|
|
|
|
2026-04-10 17:43:51 +10:00
|
|
|
if (Tram_Compiler_HasCompiled(compiler)) {
|
|
|
|
|
Tram_Compiler_AssembleAndLink(compiler, name, (Tram_LinkerArgs){.size = 0, .data = NULL});
|
|
|
|
|
} else {
|
|
|
|
|
printf("Compilation failed\n");
|
|
|
|
|
exit(EXIT_FAILURE);
|
2026-01-21 11:17:19 +11:00
|
|
|
}
|
|
|
|
|
|
2026-04-10 17:43:51 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void compileGroundInstruction(GroundInstruction* instruction, Tram_Program* program) {
|
2026-01-21 11:17:19 +11:00
|
|
|
|
|
|
|
|
}
|