-
Notifications
You must be signed in to change notification settings - Fork 22
/
main.cpp
79 lines (58 loc) · 2.44 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
74
75
76
77
78
79
#include "reference_language_rules.h"
#include "utilities.h"
#include "../include/compiler.h"
#include "../include/node_program.h"
#include "../include/ir_compilation_unit.h"
#include "../include/compilation_error.h"
#include "../include/memory_tracker.h"
#include <iostream>
#include <ostream>
#include <string>
#include <chrono>
int main() {
std::string filename;
std::cout << "Enter .mr file: ";
std::cin >> filename;
while (true) {
auto startCompile = std::chrono::high_resolution_clock::now();
{
std::cout << "--- Compiling --------------" << std::endl;
piranha::NodeProgram nodeProgram;
piranha_demo::ReferenceLanguageRules languageRules;
languageRules.initialize();
piranha::Compiler compiler(&languageRules);
piranha::IrCompilationUnit *unit = compiler.compile(filename);
piranha_demo::printErrorTrace(compiler.getErrorList());
if (unit == nullptr) {
std::cout << "Could not find file: " << filename << std::endl;
}
else if (compiler.getErrorList()->getErrorCount() == 0) {
unit->build(&nodeProgram);
std::cout << "--- Running ----------------" << std::endl;
auto endCompile = std::chrono::high_resolution_clock::now();
nodeProgram.initialize();
//nodeProgram.optimize();
nodeProgram.execute();
auto endExecute = std::chrono::high_resolution_clock::now();
nodeProgram.writeAssembly("../workspace/asm/" + unit->getPath().getStem() + ".pasm");
std::cout << std::endl;
std::cout << "----------------------------" << std::endl;
std::cout << " Compile time: " <<
(endCompile - startCompile).count() * 1.0e-6 << " ms" << std::endl;
std::cout << " Execution time: " <<
(endExecute - endCompile).count() * 1.0e-6 << " ms" << std::endl;
nodeProgram.free();
}
compiler.free();
}
std::cout << "Memory leaks: " << piranha::MemoryTracker::get()->countLeaks() << std::endl;
piranha::MemoryTracker::get()->reset();
std::cout << std::endl;
std::cout << "Run again (y/n)? ";
char cmd;
std::cin >> cmd;
if (cmd != 'y') break;
std::cout << std::endl;
}
return 0;
}