Skip to content

Commit

Permalink
compiler/compiler.c :: Implement 'fox_compile_intel()'
Browse files Browse the repository at this point in the history
  • Loading branch information
LeotendoDev committed Mar 2, 2022
1 parent 1e6b15b commit f5d69b5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
14 changes: 13 additions & 1 deletion compiler/compiler.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
#include <stdio.h>
#include <stdbool.h>
#include <assert.h>
#include <errno.h>

#include "compiler.h"

int fox_compile_intel(char* source, char* output)
{
assert(false && "TODO: --- NOT IMPLEMETED YET ---");
FILE* output_stream = fopen(output, "w");
if (output_stream == NULL) {
perror("Unnable to write to output!");
return 1;
}

fprintf(output_stream, "global _start:\n");
fprintf(output_stream, "_start:\n");
fprintf(output_stream, " mov eax, 1\n");
fprintf(output_stream, " mov ebx, 0\n");
fprintf(output_stream, " int 0x80\n");

return 0;
}

Expand Down
5 changes: 5 additions & 0 deletions examples/output.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
global _start:
_start:
mov eax, 1
mov ebx, 0
int 0x80
5 changes: 1 addition & 4 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@

int main(int argc, char** argv)
{
struct arg_options* options = handle_args(argv);

printf("SOURCE FILE: %s\n", options->source_file);
printf("OUTPUT FILE: %s\n", options->output_file);
int compile_exitcode = fox_compile_intel("examples/test.fox", "examples/output.asm");

return 0;
}
Expand Down

0 comments on commit f5d69b5

Please sign in to comment.