-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.cpp
99 lines (82 loc) · 2.13 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include <iostream>
#include "Language/Lexer.hpp"
#include "Language/Parser.hpp"
#include "Language/AST.hpp"
#include "Language/CodeGen.hpp"
#include "Tooling/Project.hpp"
#include <fstream>
std::string Parser::last_identifier;
std::string Parser::last_target;
std::string Parser::last_function_call;
bool Parser::grab_target = true;
std::unordered_map<std::string, std::string> Parser::all_variables;
std::unordered_map<std::string, std::string> Parser::all_loads;
std::unordered_map<std::string, std::string> Parser::all_prototypes;
std::unordered_map<std::string, AST::Type*> Parser::all_arrays;
bool Parser::is_exit_declared = false;
bool Parser::use_architechture_bit = false;
std::unordered_map<std::string, bool> Parser::vars_with_nothing;
std::unordered_map<std::string, bool> Parser::verified_allocs;
std::pair<std::string, std::string> Parser::current_function_in_scope;
bool Parser::dont_share_history = false;
int Parser::random_global_id = 0;
void CompileToLLVMIR()
{
std::ifstream t("main.nk");
std::string str((std::istreambuf_iterator<char>(t)),
std::istreambuf_iterator<char>());
CodeGen::Initialize();
Lexer::AddContent(str);
Lexer::Start();
Parser::MainLoop();
}
int main(int argc, char const *argv[])
{
if (argc > 1)
{
std::string cmd = argv[1];
if (cmd == "hello")
{
std::cout << "Hi! :D\n";
}
else if (cmd == "emit")
{
if(argc > 2) {
std::string cmd_two = argv[2];
if(cmd_two == "release") {
CodeGen::is_release = true;
}
}
CompileToLLVMIR();
CodeGen::Print();
TodoList::print();
}
else if (cmd == "build")
{
if(argc > 2) {
std::string cmd_two = argv[2];
if(cmd_two == "release") {
CodeGen::is_release = true;
}
}
CompileToLLVMIR();
TodoList::print();
CodeGen::Build();
}
else if (cmd == "run")
{
CompileToLLVMIR();
TodoList::print();
CodeGen::Run();
}
else if (cmd == "create")
{
if (argc > 2)
{
Project::Create(argv[2]);
}
else { std::cout << "Error: Name not provided!\n"; }
}
}
return 0;
}