-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
37 lines (28 loc) · 1.1 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
#include <iostream>
#include "llvm/ExecutionEngine/ExecutionEngine.h"
#include "llvm/IR/Constants.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/ExecutionEngine/GenericValue.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/Bitcode/BitcodeReader.h"
using namespace llvm;
int main() {
InitializeNativeTarget();
InitializeAllAsmParsers();
InitializeNativeTargetAsmPrinter();
std::string Error;
LLVMContext Context;
ErrorOr<std::unique_ptr<MemoryBuffer>> buffer = MemoryBuffer::getFile("../equal.bc");
outs() << buffer.getError().message() << "\n";
Expected<std::unique_ptr<Module>> M = getOwningLazyBitcodeModule(move(buffer.get()), Context);
outs() << *(move(M.get())) << "\n";
std::unique_ptr<ExecutionEngine> EE;
EE.reset(EngineBuilder(move(M.get())).setEngineKind(llvm::EngineKind::JIT).create());
bool (*equal)(char *, char *) = nullptr;
equal = ((bool (*)(char *, char *)) EE->getFunctionAddress(std::string("equal")));
char *a = "hello";
char *b = "hello";
bool res = equal(a, b);
outs() << "res : " << res << "\n";
return 0;
}