-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.cpp
executable file
·52 lines (40 loc) · 1.23 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
#include <iostream>
#include "lexer.h"
#include "parser.hpp"
#include "shell.hpp"
#include "llvm.hpp"
#define RED "\033[31m"
#define GREEN "\033[32m"
#define YELLOW "\033[33m"
#define CYAN "\033[36m"
#define RESET "\033[0m"
extern cplus::Shell shell;
extern ast::node_ptr<ast::Program> program;
int main(int argc, char **argv) {
if (shell.parse_args(argc, argv)) {
std::cerr << RESET << RED << "Error parsing arguments\n";
return 1;
}
if(shell.debug) {
std::cout << "\n\n" << YELLOW << "[LEXER]" << RESET << " and " << GREEN << "[PARSER]" << RESET << ":" << std::endl;
}
if (shell.parse_program()) {
std::cerr << RESET << RED << "Error parsing program\n";
return 1;
}
if(shell.debug) {
std::cout << CYAN << "[AST]:" << RESET << std::endl;
}
IRGenerator gen;
program->accept(&gen);
gen.generate();
std::string cmd = "clang -x ir ir.ll -o \"" + shell.outfile + "\"";
if(!system(cmd.c_str())) {
std::cout << "\033[0m" << "Compilation successful. Run ./" << shell.outfile << " to execute\n";
}
else {
std::cerr << RESET << RED << "Error generating IR\n";
return 1;
}
return 0;
}