-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
55 lines (49 loc) · 1.27 KB
/
Copy pathmain.cpp
File metadata and controls
55 lines (49 loc) · 1.27 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
#include <iostream>
#include <stdexcept>
#include "ast.h"
#include "Codegen.h"
#include "parser.hpp"
#include "ccalc.h"
using namespace std;
extern int yyparse();
extern ast::Program* ast_root;
std::string red(const std::string& str) {
string red_b = "\033[1;31m";
string red_e = "\033[0m";
return red_b + str + red_e;
}
std::string green(const std::string& str) {
string red_b = "\033[1;32m";
string red_e = "\033[0m";
return red_b + str + red_e;
}
int main(int argc, char** argv) {
init_buffer();
yyparse();
extern int parseError;
if (parseError) return 0;
cout << green("syntax check success!") << endl;
cout << ast_root << endl;
ast_root->print_node("", true, true);
// InitializeNativeTarget();
// LLVMInitializeNativeTarget() ;
//
InitializeAllTargetInfos();
InitializeAllTargets();
InitializeAllTargetMCs();
LLVMInitializeNativeAsmPrinter();
LLVMInitializeNativeAsmParser();
Codegen context;
//createCoreFunctions(context);
try {
context.generateCode(*ast_root);
context.runCode();
} catch (const std::domain_error &de) {
cout << red(de.what()) << endl;
} catch (const std::logic_error &le) {
cout << red(le.what()) << endl;
} catch (...) {
cout << "other uncaught error" << endl;
}
return 0;
}