-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
80 lines (72 loc) · 1.35 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
77
78
79
80
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include "debug.h"
#include "kel.h"
int main(
int argc,
char** argv) {
if(argc != 2) {
printf("Source file required.\n");
return EXIT_FAILURE;
}
bool exit_status = true;
Source source;
MemoryArea memArea;
Binary binary;
Lexer lexer;
Parser parser;
initialize_source(&source);
initialize_memory_area(&memArea);
initialize_binary(&binary);
initialize_lexer(&lexer);
initialize_parser(&parser);
if((exit_status = create_source(
argv[1],
&source))
== false)
goto END;
if((exit_status = source.length == 0))
goto END;
printf("%s\n", source.content + 1);
if((exit_status = create_memory_area(
source.length,
sizeof(uint8_t),
&memArea))
== false)
goto END;
if((exit_status = create_binary(
"./bin",
&binary))
== false)
goto END;
if((exit_status = create_lexer(
&source,
&memArea,
&lexer)
== false))
goto END;
#ifndef NDEBUG
debug_print_tokens(&lexer);
#endif
if((exit_status = create_parser(
&lexer,
&memArea,
&parser))
== false)
goto END;
#ifndef NDEBUG
debug_print_file_nodes(&parser);
debug_print_nodes(&parser);
#endif
binary_x64(
&binary,
&parser);
END:
destroy_parser(&parser);
destroy_lexer(&lexer);
destroy_binary(&binary);
destroy_memory_area(&memArea);
destroy_source(&source);
return exit_status ? EXIT_SUCCESS : EXIT_FAILURE;
}