-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
63 lines (51 loc) · 1.84 KB
/
main.cpp
File metadata and controls
63 lines (51 loc) · 1.84 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
#include <fstream>
#include <iostream>
#include "bc_def.hpp"
#include "expr_engine.hpp"
#include "ir_gen.hpp"
#include "lex_def.hpp"
#define DEBUG 0
//TODO: Create macros
int main(int argc, char* argv[]) {
if (argc > 2 || argc < 2) {std::cerr << "Too many or too little args provided\n"; return 1;}
if (!std::filesystem::exists(argv[1])) {std::cerr << argv[1] << " does not exist\n"; return 1;}
std::vector<std::string> lines{};
std::ifstream ifile(argv[1]);
std::string token;
while (getline(ifile, token)) lines.push_back(token);
auto lex = lexer(lines);
auto ir = ir_gen(lex);
auto b = bc_gen(ir);
#if DEBUG
std::cout << boolalpha;
/*
visit([](auto&& val){std::cout << val << std::endl;}, Expression(vector<Lex>{
Expression testing
}).solve());
*/
for (auto l : lex) {
std::cout << "====================\n";
std::cout << "LINE: " << l.line << std::endl;
std::cout << "TYPE: " << l.type << std::endl;
std::cout << "SUB-TYPE: " << l.sub_type << std::endl;
std::visit([](auto&& value){std::cout << value << std::endl;}, l.value);
std::cout << "====================\n";
}
std::cout << "=====IR=====" << std::endl;
for (auto i : ir) {
std::cout << "line: " << i.line << std::endl;
std::cout << "l-type: " << i.l_type;
std::cout << " | l-value: " << i.lvalue << std::endl;
std::cout << "r-type: " << i.r_type;
std::visit([](auto&& rval) {std::cout << " | r-value: " << rval << std::endl;}, i.rvalue);
std::cout << "====================\n";
}
std::cout << "====Bytecode====" << std::endl;
for (auto bc : b) {
std::cout << bc.code << " " << bc.sub_code << " ";
std::visit([](auto&& val) {std::cout << val << std::endl;}, bc.value);
}
#else
return executor(b);
#endif
}