-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.c
42 lines (36 loc) · 1 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include "lexerf.h"
#include "parserf.h"
#include "codegeneratorf.h"
int main(int argc, char *argv[]){
if(argc != 3){
printf("Error: correct syntax: %s <filename.unn> <output_filename>\n", argv[0]);
exit(1);
}
char *output_filename = malloc(sizeof(char) * 16);
sprintf(output_filename, "%s.asm", argv[2]);
FILE *file;
file = fopen(argv[1], "r");
if(!file){
printf("ERROR: File not found\n");
exit(1);
}
Token *tokens = lexer(file);
Node *test = parser(tokens);
generate_code(test, "generated.asm");
FILE *assembly_file = fopen("generated.asm", "r");
if(!assembly_file){
printf("ERRROR");
exit(1);
}
char *nasm = malloc(sizeof(char) * 64);
char *gcc = malloc(sizeof(char) * 64);
sprintf(nasm, "nasm -f elf64 generated.asm -o generated.o", argv[2], argv[2]);
sprintf(gcc, "gcc generated.o -o %s -lc -no-pie", argv[2], argv[2]);
system(nasm);
system(gcc);
printf("FINISHED\n");
}