-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.cc
87 lines (65 loc) · 2.14 KB
/
Main.cc
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
81
82
83
84
85
86
87
#include "AST/AST.h"
#include "CodeGenerator/CodeGenerator.h"
#include "Parser/Parser.h"
#include "TypeChecker/TypeChecker.h"
#include <chrono>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std::chrono;
int main(int argc, char **argv)
{
if (argc < 2)
{
std::cout << "Please provide an input file" << std::endl;
std::exit(0);
}
bool quiet = false;
for (int i = 2; i < argc; i++)
{
if (argv[i] == std::string("--quiet"))
{
quiet = true;
}
}
auto t1 = high_resolution_clock::now();
std::ifstream is{argv[1], std::ifstream::binary};
Tokenizer tokenizer{is};
tokenizer.tokenize();
SymbolTable symbol_table{};
TypeChecker type_checker{&symbol_table};
Quads quads{&symbol_table};
std::ofstream os{"out.asm"};
CodeGenerator code_generator{os, &symbol_table};
Parser parser{tokenizer, &symbol_table, type_checker, quads,
code_generator};
parser.parse();
auto t2 = high_resolution_clock::now();
int status_code = std::system("nasm -f elf64 -o out.o out.asm");
if (status_code != 0)
{
std::exit(status_code);
}
auto t3 = high_resolution_clock::now();
status_code = std::system("ld -o out out.o");
if (status_code != 0)
{
std::exit(status_code);
}
auto t4 = high_resolution_clock::now();
if (!quiet)
{
duration<float> d1 = t4 - t1;
std::cout << "Compiled in: " << std::setprecision(4) << std::fixed
<< d1.count() << " seconds" << std::endl;
duration<float> d2 = t2 - t1;
std::cout << "\tGenerated assembler in: " << std::setprecision(4)
<< std::fixed << d2.count() << " seconds" << std::endl;
duration<float> d3 = t3 - t2;
std::cout << "\tAssembled assembler in: " << std::setprecision(4)
<< std::fixed << d3.count() << " seconds" << std::endl;
duration<float> d4 = t4 - t3;
std::cout << "\tLinked object file in: " << std::setprecision(4)
<< std::fixed << d4.count() << " seconds" << std::endl;
}
}