-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
61 lines (54 loc) · 1.58 KB
/
Copy pathmain.cpp
File metadata and controls
61 lines (54 loc) · 1.58 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
#include <iostream>
#include "Lexer.h"
#include "Parser.h"
#include "Driver.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/raw_ostream.h"
#include <fstream>
#include <string>
int main(int argc, char **argv) {
if(argc > 1) {
std::string filename(argv[1]);
std::ifstream file;
file.open(filename);
std::string line;
std::string src = "";
while(std::getline(file, line)) {
src += line;
src += "\n";
}
// std::cout << src << std::endl;
llvm::errs() << "Printing source code: \n" << src << "\n";
// Lexing
llvm::StringRef source_code(src);
Lexer lexer(source_code);
// Parsing
Parser parser(lexer.return_token_list());
std::list<std::shared_ptr<DeclNode>> declarations = parser.parse();
if(argc > 2 && strcmp(argv[2], "--lexer") == 0) {
// Printing tokens
lexer.printTokenList();
}
if(argc > 2 && strcmp(argv[2], "--ast") == 0) {
// Pretty printer
NodePrinter np;
for(auto & i : declarations) {
np.printDeclaration(i);
}
std::cout << std::endl;
}
else if(argc == 2) {
std::cout << "Code-generation" << std::endl;
programCodegen(declarations);
/***
// LLVM IR printing
for(auto &i : declarations) {
GenerateCode(i);
}***/
}
}
else {
std::cerr << "Source code not given" << std::endl;
}
return 0;
}