-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain_codegen.cpp
More file actions
52 lines (42 loc) · 1.02 KB
/
Copy pathmain_codegen.cpp
File metadata and controls
52 lines (42 loc) · 1.02 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
#include <iostream>
#include <string>
#include "driver.hpp"
#include "llvm_printer.hpp"
#include "semantic_analyzer.hpp"
#include "llvm/IR/LLVMContext.h"
#include "llvm/Support/raw_ostream.h"
int main(int argc, char** argv)
{
if (argc != 2)
{
std::cerr << "Usage: paracl_codegen <input-file>\n";
return 1;
}
Driver drv;
int status = drv.parse(argv[1]);
if (status != 0 || drv.ast.globalScope == nullptr)
{
std::cerr << "Parsing failed\n";
return status != 0 ? status : 1;
}
try
{
SemanticAnalyzer semantic(drv.node_locations);
semantic.analyze(drv.ast);
llvm::LLVMContext context;
LLVMPrinter printer(context);
printer.generate(drv.ast);
printer.dump(llvm::outs());
}
catch (const SemanticError& e)
{
std::cerr << e.what() << '\n';
return 1;
}
catch (const std::exception& e)
{
std::cerr << "Codegen error: " << e.what() << '\n';
return 1;
}
return 0;
}