-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmain.cpp
73 lines (59 loc) · 1.62 KB
/
main.cpp
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
#include <stdio.h>
#include <fstream>
#include <string>
#include <cstring>
#include <sstream>
#include "ast.h"
#include "common.h"
#include "parse.h"
#include "typecheck.h"
config_t config;
const char *filename;
// GENERAL TODO:
// 1) Give option to Buf for an allocator (basically, an arena
// from alloc.h.
Goal parse_and_return_goal() {
std::ifstream input_file(filename);
if (!input_file.good()) {
assert(0);
}
std::stringstream sstr;
sstr << input_file.rdbuf();
std::string file_contents_str = sstr.str();
input_file.close();
const char *file_contents = file_contents_str.c_str();
parse_init(file_contents, filename);
Goal goal = parse_goal();
return goal;
// Here `file_contents_str` memory gets deallocated because
// of destructor.
}
int main(int argc, char **argv) {
filename = argv[1];
config.log = false;
config.ansi_style = true;
config.unused = true;
config.offsets = false;
config.codegen = false;
for (int i = 1; i != argc; ++i) {
if (!strcmp(argv[i], "-v")) {
config.log = true;
}
if (!strcmp(argv[i], "-unused")) {
config.unused = false;
}
if (!strcmp(argv[i], "-no-style")) {
config.ansi_style = false;
}
if (!strcmp(argv[i], "-offsets")) {
config.offsets = true;
}
if (!strcmp(argv[i], "-codegen")) {
config.codegen = true;
}
}
Goal goal = parse_and_return_goal();
// TODO: Check for fatal parsing errors here and don't continue
// if they exist.
typecheck(&goal);
}