-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
87 lines (70 loc) · 2.99 KB
/
main.cpp
File metadata and controls
87 lines (70 loc) · 2.99 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include "ive/Dialect.hpp"
#include "ive/DriverHelpers.hpp"
#include <mlir/Dialect/Func/Extensions/AllExtensions.h>
#include <mlir/Dialect/LLVMIR/Transforms/InlinerInterfaceImpl.h>
#include <mlir/IR/MLIRContext.h>
#include <mlir/Parser/Parser.h>
#include <mlir/Pass/PassManager.h>
#include <string>
using namespace ive;
namespace cl = llvm::cl;
int main(int argc, char **argv) {
cl::opt<std::string> inputFileName(cl::Positional,
cl::desc("<input ive file>"),
cl::init("-"), cl::value_desc("filename"));
cl::opt<enum InputType> inputType(
"x", cl::init(Ive), cl::desc("Decided the kind of output desired"),
cl::values(
clEnumValN(Ive, "ive", "load the input file as an Ive source.")),
cl::values(
clEnumValN(MLIR, "mlir", "load the input file as an MLIR file")));
cl::opt<enum Action> emitAction(
"emit", cl::desc("Select the kind of output desired"),
cl::values(clEnumValN(DumpAST, "ast", "output the AST dump")),
cl::values(clEnumValN(DumpMLIR, "mlir", "output the MLIR dump")),
cl::values(clEnumValN(DumpMLIRAffine, "mlir-affine",
"output the MLIR dump after affine lowering")),
cl::values(clEnumValN(DumpMLIRLLVM, "mlir-llvm",
"output the MLIR dump after llvm lowering")),
cl::values(clEnumValN(DumpLLVMIR, "llvm", "output the LLVM IR dump")),
cl::values(
clEnumValN(RunJIT, "jit",
"JIT the code and run it by invoking the main function")));
cl::opt<bool> enableOpt("opt", cl::desc("Enable optimizations"));
// Register any command line options.
mlir::registerAsmPrinterCLOptions();
mlir::registerMLIRContextCLOptions();
mlir::registerPassManagerCLOptions();
cl::ParseCommandLineOptions(argc, argv, "ive compiler\n");
if (emitAction == DumpAST) {
return dumpAST(inputFileName, inputType);
}
// If we aren't dumping the AST, then we are compiling with/to MLIR.
mlir::DialectRegistry registry;
mlir::func::registerAllExtensions(registry);
mlir::LLVM::registerInlinerInterface(registry);
mlir::MLIRContext context(registry);
// Load our Dialect in this MLIR Context.
context.getOrLoadDialect<mlir::ive::IveDialect>();
mlir::OwningOpRef<mlir::ModuleOp> module;
if (int error = loadAndProcessMLIR(context, module, inputFileName, inputType,
emitAction, enableOpt)) {
return error;
}
// If we aren't exporting to non-mlir, then we are done.
bool isOutputingMLIR = emitAction <= Action::DumpMLIRLLVM;
if (isOutputingMLIR) {
module->dump();
return 0;
}
// Check to see if we are compiling to LLVM IR.
if (emitAction == Action::DumpLLVMIR) {
return dumpLLVMIR(*module, enableOpt);
}
// Otherwise, we must be running the jit.
if (emitAction == RunJIT) {
return runJit(*module, enableOpt);
}
llvm::errs() << "No action specified (parsing only?), use -emit=<action>\n";
return -1;
}