-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
33 lines (30 loc) · 822 Bytes
/
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
#include <fstream>
#include <json/json.h>
#include "ast.hpp"
#include "cminus.y.h"
extern std::shared_ptr<lyf::ASTNode> ROOT;
extern std::unique_ptr<llvm::Module> mod;
int main()
{
yyparse();
lyf::CreatePrintf();
lyf::CreateScanf();
// std::printf("%p", ROOT);
auto res = ROOT->codeGen();
if (res == nullptr) {
std::cerr << "Error occured during compilation." << std::endl;
}
if (llvm::verifyModule(*mod, &llvm::errs())) {
llvm::errs() << "There are errors in module!" << "\n";
return -1;
}
std::error_code EC;
std::string IRFileName = "a.ll";
llvm::raw_fd_ostream IRFile(IRFileName, EC);
// output IR file
IRFile << *mod << "\n";
std::ofstream astJson("ast.json");
astJson << ROOT->jsonGen();
astJson.close();
return 0;
}