-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathmain.cpp
44 lines (34 loc) · 1.43 KB
/
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
34
35
36
37
38
39
40
41
42
43
44
#include "core/Program.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/CommandLine.h"
#include <iostream>
#include <string>
using namespace llvm;
int main(int argc, char** argv) {
cl::OptionCategory options("llvm2c options");
cl::opt<std::string> Output("o", cl::desc("Output filename"), cl::value_desc("filename"), cl::cat(options));
cl::opt<std::string> Input(cl::Positional, cl::Required, cl::desc("<input>"), cl::cat(options));
cl::opt<bool> Print("p", cl::desc("Print translated program"), cl::cat(options));
cl::opt<bool> Debug("debug", cl::desc("Print only information about translation"), cl::cat(options));
cl::opt<bool> Includes("add-includes", cl::desc("Uses includes instead of declarations. For experimental purposes."), cl::cat(options));
cl::opt<bool> Casts("no-function-call-casts", cl::desc("Removes casts around function calls. For experimental purposes."), cl::cat(options));
cl::HideUnrelatedOptions(options);
cl::ParseCommandLineOptions(argc, argv);
if (Output.empty() && !Print && !Debug) {
std::cout << "Output method not specified!\n";
return 1;
}
try {
Program program(Input, Includes, Casts);
if (Print) {
program.print();
}
if (!Output.empty()) {
program.saveFile(Output);
}
} catch (std::invalid_argument& e) {
std::cerr << e.what();
return 1;
}
return 0;
}