-
Notifications
You must be signed in to change notification settings - Fork 5
/
sqlgen.cpp
60 lines (52 loc) · 1.39 KB
/
sqlgen.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/WithColor.h"
#include "llvm/TableGen/Error.h"
#include "llvm/TableGen/Main.h"
#include "llvm/TableGen/Record.h"
#include "Error.h"
using namespace llvm;
namespace {
enum ActionType {
PrintRecords,
PrintDetailedRecords,
EmitSQL
};
} // end anonymous namespace
static cl::opt<ActionType>
Action(cl::desc("Actions to perform"),
cl::values(
clEnumValN(PrintRecords, "print-records", ""),
clEnumValN(PrintDetailedRecords, "print-detailed-records", ""),
clEnumValN(EmitSQL, "emit-sql", "")
),
cl::init(EmitSQL));
Error emitSQL(raw_ostream &OS, RecordKeeper &Records);
bool SQLGenMain(raw_ostream &OS, RecordKeeper &Records) {
switch (Action) {
case PrintRecords:
OS << Records;
break;
case EmitSQL:
if (auto E = emitSQL(OS, Records)) {
handleAllErrors(std::move(E),
[](const SMLocError &E) {
llvm::PrintError(E.Loc.getPointer(), E.getMessage());
},
[](const ErrorInfoBase &E) {
E.log(WithColor::error());
errs() << "\n";
});
return true;
}
break;
default:
return true;
}
return false;
}
int main(int argc, char **argv) {
cl::ParseCommandLineOptions(argc, argv);
return llvm::TableGenMain(argv[0], &SQLGenMain);
}