-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompiler.c
More file actions
68 lines (57 loc) · 2 KB
/
compiler.c
File metadata and controls
68 lines (57 loc) · 2 KB
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
#include "prelexer.h"
#include "postlexer.h"
#include <stdlib.h>
#if !(defined __COMPILER_MINIMAL_REQ__) && (defined __SIZEOF_INT128__)
#define __COMPILER_MINIMAL_REQ__ 1
#else
#define __COMPILER_MINIMAL_REQ__ 0
#endif
extern void parse(FILE *in, FILE *out);
int main(int argc, char *argv[]) {
if (!__COMPILER_MINIMAL_REQ__) {
fprintf(stderr, "[COMPILER]: Minimal Requirements for Compiler aren't satisfied!\n");
fprintf(stderr, "There is no int128_t on this machine. Make sure you use 64-bit GCC!\n");
exit(EXIT_FAILURE);
}
if (argc == 3) {
FILE *in = fopen(argv[1], "r");
if (in == NULL) {
fprintf(stderr, "Couldn't open file: %s!\n", argv[1]);
exit(EXIT_FAILURE);
}
char const * const temp_out = "prelexer_temp_out";
FILE *prelex_out = fopen(temp_out, "w+");
if (prelex_out == NULL) {
fprintf(stderr, "Couldn't create temporary files for compiler: %s!\n", temp_out);
exit(EXIT_FAILURE);
}
char const * const asm_out = "asm_out";
FILE *parse_out = fopen(asm_out, "w+");
if (parse_out == NULL) {
fprintf(stderr, "Couldn't create temporary files for compiler: %s!\n", asm_out);
exit(EXIT_FAILURE);
}
FILE *compiler_out = fopen(argv[2], "w+");
if (compiler_out == NULL) {
fprintf(stderr, "Couldn't create OUTPUT FILE of compiler: %s!\n", argv[2]);
exit(EXIT_FAILURE);
}
// prelexer
prelex(in, prelex_out);
fclose(in);
// parser
rewind(prelex_out);
parse(prelex_out, parse_out);
fclose(prelex_out);
remove(temp_out); // comment for debug
// postlexer
rewind(parse_out);
postlex(parse_out, compiler_out);
fclose(parse_out);
remove(asm_out);
fclose(compiler_out);
} else {
fprintf(stderr, "WRONG AMOUNT OF INPUT ARGUMENTS!\n");
exit(EXIT_FAILURE);
}
}