-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy paththeExpressionEngine.cpp
More file actions
51 lines (48 loc) · 1.54 KB
/
theExpressionEngine.cpp
File metadata and controls
51 lines (48 loc) · 1.54 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
#include <iostream>
#include "factory.h"
#include "expression.h"
#include <llvm/IR/IRBuilder.h>
#include <llvm/IR/LLVMContext.h>
#include <llvm/IR/Module.h>
#include <llvm/IR/Verifier.h>
#include <llvm/ExecutionEngine/ExecutionEngine.h>
#include <llvm/ExecutionEngine/MCJIT.h>
#include <llvm/Support/raw_ostream.h>
#include <llvm/ExecutionEngine/GenericValue.h>
#include <llvm/Support/TargetSelect.h>
int main(int argc, char**argv)
{
using namespace llvm;
using namespace theExpressionEngine;
// Initialize the native target
InitializeNativeTarget();
InitializeNativeTargetAsmPrinter();
InitializeNativeTargetAsmParser();
if (argc < 2)
{ std::cerr << argv[0] << ": Usage : " << argv[0] << " expression" << std::endl;
return 1;
}
constexpr const auto BTHREADED = true;
const auto pFactory = factory<BTHREADED>::getFactory();
std::vector<expression<BTHREADED>::ptr> sE;
for (auto p = argv + 1; *p; ++p)
sE.push_back(pFactory->parse(*p, {{"x", pFactory->parameter(0, true)}}));
const auto sES = pFactory->createExpressionSet(sE);
const auto &rOrder = sES->getOrder();
std::vector<double> sX(1);
std::vector<int> sXI;
std::string sLine;
std::vector<double> sChildren;
std::vector<int> sChildrenI;
while (std::getline(std::cin, sLine))
{ if (sLine.empty())
continue;
sX[0] = std::stod(sLine.c_str());
sES->evaluateLLVM(sChildren, sChildrenI, sX.data(), sXI.data());
std::cout << sX[0] << "\t";
for (std::size_t i = 0, iMax = sE.size(); i < iMax; ++i)
std::cout << sChildren[rOrder[i]] << "\t";
std::cout << std::endl;
}
return 0;
}