-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.c
76 lines (65 loc) · 1.58 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <stdio.h>
#include <stdlib.h>
#include "compiler.h"
int main(int argc, const char** argv)
{
const char* input_file = "./test.c";
const char* output_file = "./test";
const char* option = "asm";
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_OUTPUT_ASM;
if (S_EQ(option, "exec"))
{
compile_flags |= COMPILE_PROCESS_EXECUTE_NASM;
}
else if (S_EQ(option, "object"))
{
compile_flags |= COMPILE_PROCESS_EXECUTE_NASM | COMPILE_PROCESS_EXPORT_AS_OBJECT;
}
int res = compile_file(input_file, output_file, compile_flags);
if (res == COMPILER_FILE_COMPILED_OK)
{
printf("Everything compiled ok\n");
}
else if (res == COMPILER_FAILED_WITH_ERRORS)
{
printf("Compile failed\n");
}
else
{
printf("Unknown response for compile time\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", output_file, nasm_output_file, nasm_output_file, output_file);
}
printf("%s\n", nasm_cmd);
int res = system(nasm_cmd);
if (res < 0)
{
printf("Issue assembling the assembly file with NASM and linking with gcc\n");
return res;
}
}
return 0;
}