-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.cpp
83 lines (72 loc) · 1.98 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
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
#include <chrono>
#include <llvm/ADT/STLExtras.h>
#include <llvm/ExecutionEngine/ExecutionEngine.h>
#include <llvm/ExecutionEngine/GenericValue.h>
#include <llvm/IR/Constants.h>
#include <llvm/IR/IRBuilder.h>
#include <llvm/Support/ManagedStatic.h>
#include <llvm/Support/TargetSelect.h>
#include "codegen/CodeGen.hpp"
#include "foundations/loader.hpp"
#include "foundations/exceptions.hpp"
#include "tests/tests.hpp"
#include "queries/queries.hpp"
#include "queryCompiler/queryCompiler.hpp"
#include "utils/general.hpp"
using namespace llvm;
void usage(const char * name)
{
printf("Usage:\n"
"\t%s\n"
"\t%s -q query\n"
"\t%s -b query runs\n"
"\t%s -t test\n",
name, name, name, name
);
}
void prompt()
{
std::unique_ptr<Database> currentdb = loadDatabase();
while (true) {
try {
printf(">>> ");
fflush(stdout);
std::string input = readline();
if (input == "quit\n") {
break;
}
QueryCompiler::compileAndExecute(input,*currentdb);
} catch (const std::exception & e) {
fprintf(stderr, "Exception: %s\n", e.what());
}
}
}
int main(int argc, char * argv[])
{
// necessary for the LLVM JIT compiler
InitializeNativeTarget();
llvm::InitializeNativeTargetAsmPrinter();
llvm::InitializeNativeTargetAsmParser();
if (argc == 1) {
prompt();
} else if (argc == 3) {
if (std::strcmp(argv[1], "-q") == 0) {
runNamedQuery(argv[2]);
} else if(std::strcmp(argv[1], "-t") == 0) {
runNamedTest(argv[2]);
} else {
usage(argv[0]);
}
} else if (argc == 4) {
if (std::strcmp(argv[1], "-b") == 0) {
unsigned runs = atoi(argv[3]);
benchmarkNamedQuery(argv[2], runs);
} else {
usage(argv[0]);
}
} else {
usage(argv[0]);
}
llvm_shutdown();
return 0;
}