-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
61 lines (51 loc) · 1.39 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <stdio.h>
#include <stdlib.h>
#include "compiler.h"
int main(int argc, char **argv) {
const char *input_file = "./test.c";
const char *output_file = "./test";
const char *option = "exec";
if (argc > 1) {
input_file = argv[1];
}
if (argc > 2) {
output_file = argv[2];
}
if (argc > 3) {
option = argv[3];
}
int compile_flags = COMPILE_PROCESS_EXECUTE_NASM;
if (S_EQ(option, "object")) {
compile_flags |= COMPILE_PROCESS_EXPORT_AS_OBJECT;
}
int res = compile_file(input_file, output_file, compile_flags);
if (res == COMPILER_FILE_COMPILED_OK) {
printf("Everything compiled fine!\n");
} else if (res == COMPILER_FAILED_WITH_ERRORS) {
printf("Compile failed!\n");
} else {
printf("Unknown response for compile file\n");
}
if (compile_flags & COMPILE_PROCESS_EXECUTE_NASM) {
char nasm_output_file[40];
char nasm_cmd[512];
sprintf(nasm_output_file, "%s.o", output_file);
if (compile_flags & COMPILE_PROCESS_EXPORT_AS_OBJECT) {
sprintf(nasm_cmd, "nasm -f elf32 %s -o %s", output_file, nasm_output_file);
} else {
sprintf(nasm_cmd,
"nasm -f elf32 %s -o %s && gcc -m32 %s -o %s --enable-multilib",
output_file,
nasm_output_file,
nasm_output_file,
output_file);
}
printf("%s", nasm_cmd);
int res = system(nasm_cmd);
if (res < 0) {
printf("Issue with nasm assembly and/or linking with gcc");
return res;
}
}
return 0;
}