本文整理汇总了C++中ExecutionEngine::runFunction方法的典型用法代码示例。如果您正苦于以下问题:C++ ExecutionEngine::runFunction方法的具体用法?C++ ExecutionEngine::runFunction怎么用?C++ ExecutionEngine::runFunction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ExecutionEngine
的用法示例。
在下文中一共展示了ExecutionEngine::runFunction方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char **argv) {
int n = argc > 1 ? atol(argv[1]) : 24;
LLVMContext Context;
// Create some module to put our function into it.
Module *M = new Module("test", Context);
// We are about to create the "fib" function:
Function *FibF = CreateFibFunction(M, Context);
// Now we going to create JIT
ExecutionEngine *EE = EngineBuilder(M).create();
errs() << "verifying... ";
if (verifyModule(*M)) {
errs() << argv[0] << ": Error constructing function!\n";
return 1;
}
errs() << "OK\n";
errs() << "We just constructed this LLVM module:\n\n---------\n" << *M;
errs() << "---------\nstarting fibonacci(" << n << ") with JIT...\n";
// Call the Fibonacci function with argument n:
std::vector<GenericValue> Args(1);
Args[0].IntVal = APInt(32, n);
GenericValue GV = EE->runFunction(FibF, Args);
// import result of execution
outs() << "Result: " << GV.IntVal << "\n";
return 0;
}
示例2: runCode
GenericValue CodeGenContext::runCode() {
std::cout << "Running code ...\n";
ExecutionEngine* ee = EngineBuilder(module_).create();
vector<GenericValue> noargs;
GenericValue v = ee->runFunction(main_func_, noargs);
std::cout << "Code was run.\n";
return v;
}
示例3: runCode
/* Executes the AST by running the main function */
GenericValue CodeGenContext::runCode() {
std::cout << "Running code...\n";
ExistingModuleProvider *mp = new ExistingModuleProvider(module);
ExecutionEngine *ee = ExecutionEngine::create(mp, false);
vector<GenericValue> noargs;
GenericValue v = ee->runFunction(mainFunction, noargs);
std::cout << "Code was run.\n";
return v;
}
示例4: runCode
/* Executes the AST by running the main function */
GenericValue CodeGenContext::runCode() {
std::cout << "Running code...\n";
InitializeNativeTarget();
ExecutionEngine *ee = ExecutionEngine::create(module, false);
vector<GenericValue> noargs;
GenericValue v = ee->runFunction(mainFunction, noargs);
std::cout << "Code was run.\n";
return v;
}
示例5: execute
GenericValue execute(Function *ep, vector<GenericValue>& args)
{
if (engine)
return engine->runFunction(ep, args);
GenericValue v;
v.DoubleVal = 0;
return v;
}
示例6: main
int main(int argc, char**argv) {
// Create an LLVM Module by calling makeLLVMModule()
// Access the LLVM Module through a module owner
std::unique_ptr<Module> Owner(makeLLVMModule());
Module* Mod = Owner.get();
// Verify the LLVM Module - check syntax and semantics
verifyModule(*Mod, &errs());
// Create a 'Pass Manager' for the compiler pipeline
// Configure the Pass Manager with available / custom passes
legacy::PassManager PM;
PM.add(createPrintModulePass(outs()));
// Run the LLVM Module through the pipeline managed by the Pass Manager.
// The pipeline has a single 'print' pass which will stream out the LLVM Module as LLVM IR
PM.run(*Mod);
// Now let's check if the LLVM Module is functionally correct. To do this, we will test the module
// with concrete values, execute the module on an 'ExecutionEngine' (which can be configured as a
// JIT compiler or an interpreter), and verify if the output matches the expected result.
std::string errStr;
ExecutionEngine *Engine = EngineBuilder(std::move(Owner)).setErrorStr(&errStr).create();
if (!Engine) {
errs() << argv[0] << ": Failed to construct the Execution Engine: " << errStr << "\n";
return -1; // Add a error macro
}
// Input values 2,3,4.
// Expected value: mul_add(2,3,4) = 2 * 3 + 4 = 10
std::vector<GenericValue> Args(3);
Args[0].IntVal = APInt(32, 2);
Args[1].IntVal = APInt(32, 3);
Args[2].IntVal = APInt(32, 4);
GenericValue GV = Engine->runFunction(mul_add, Args);
outs() << "\nCalling mul_add( " << Args[0].IntVal << ", " << Args[1].IntVal << ", " << Args[2].IntVal <<" )";
outs() << "\nResult: " << GV.IntVal << "\n";
if( GV.IntVal == (Args[0].IntVal * Args[1].IntVal + Args[2].IntVal) )
{
outs() << "\n\nResult matches expectation!!";
outs() << "\nMyFirstModule is a perfect LLVM Module :)";
}
else
{
outs() << "\n\nOops! Result doesn't match expectation. Check mul_add again.";
}
delete Mod;
return 0;
}
示例7: runCode
/* Executes the AST by running the main function */
GenericValue CodeGenContext::runCode() {
std::cout << "Running begining...\n";
std::cout <<
"========================================" << std::endl;
ExecutionEngine *ee = EngineBuilder(module).create();
std::vector<GenericValue> noargs;
GenericValue v = ee->runFunction(mainFunction, noargs);
std::cout << "========================================" << std::endl;
std::cout << "Running end.\n";
return v;
}
示例8: runCode
GenericValue CodeGenContext::runCode()
{
std::cout << "Executing code...\n";
ExecutionEngine* ee = EngineBuilder(module).create();
vector<GenericValue> noargs;
GenericValue v = ee->runFunction(mainFunction, noargs);
std::cout << "Code execution complete.\n";
return v;
}
示例9: main
int main(int argc, char **argv) {
int n = argc > 1 ? atol(argv[1]) : 24;
InitializeNativeTarget();
LLVMContext Context;
// Create some module to put our function into it.
OwningPtr<Module> M(new Module("test", Context));
// We are about to create the "fib" function:
Type* ty=Type::getInt64Ty(Context);
//if (n<30) ty=Type::getInt32Ty(Context); // decide on type at runtime
Function *FibF = CreateFibFunction(M.get(), Context, ty);
// Now we going to create JIT
//auto engine=EngineKind::Interpreter;
auto engine=EngineKind::JIT;
std::string errStr;
ExecutionEngine *EE =
EngineBuilder(M.get())
.setErrorStr(&errStr)
.setEngineKind(engine)
.create();
if (!EE) {
errs() << argv[0] << ": Failed to construct ExecutionEngine: " << errStr
<< "\n";
return 1;
}
errs() << "verifying... ";
if (verifyModule(*M)) {
errs() << argv[0] << ": Error constructing function!\n";
return 1;
}
errs() << "OK\n";
errs() << "We just constructed this LLVM module:\n\n---------\n" << *M;
errs() << "---------\nstarting fibonacci(" << n << ") with "<<(engine==EngineKind::Interpreter?"interpreter":(engine==EngineKind::JIT)?"JIT":"???")<<" ...\n";
// Call the Fibonacci function with argument n:
std::vector<GenericValue> Args(1);
Args[0].IntVal = APInt(32, n);
GenericValue GV = EE->runFunction(FibF, Args);
// import result of execution
outs() << "Result: " << GV.IntVal << "\n";
return 0;
}
示例10: main
int main(int argc, char **argv) {
int n = argc > 1 ? atol(argv[1]) : 24;
InitializeNativeTarget();
InitializeNativeTargetAsmPrinter();
LLVMContext Context;
// Create some module to put our function into it.
std::unique_ptr<Module> Owner(new Module("test", Context));
Module *M = Owner.get();
// We are about to create the "fib" function:
Function *FibF = CreateFibFunction(M, Context);
// Now we going to create JIT
std::string errStr;
ExecutionEngine *EE =
EngineBuilder(std::move(Owner))
.setErrorStr(&errStr)
.create();
if (!EE) {
errs() << argv[0] << ": Failed to construct ExecutionEngine: " << errStr
<< "\n";
return 1;
}
errs() << "verifying... ";
if (verifyModule(*M)) {
errs() << argv[0] << ": Error constructing function!\n";
return 1;
}
errs() << "OK\n";
errs() << "We just constructed this LLVM module:\n\n---------\n" << *M;
errs() << "---------\nstarting fibonacci(" << n << ") with JIT...\n";
// Call the Fibonacci function with argument n:
std::vector<GenericValue> Args(1);
Args[0].IntVal = APInt(32, n);
GenericValue GV = EE->runFunction(FibF, Args);
// import result of execution
outs() << "Result: " << GV.IntVal << "\n";
return 0;
}
示例11: LoadPlugin
void LoadPlugin(const std::string& path, const std::string& name, MetaScriptRunner* msr) {
SMDiagnostic error;
std::unique_ptr<Module> Owner = getLazyIRFileModule(path, error, context);
if(Owner == nullptr) {
cout << "Load Error: " << path << endl;
Owner->dump();
return;
}
initEE(std::move(Owner));
string func_name = name + "_elite_plugin_init";
Function* func = EE->FindFunctionNamed(func_name.c_str());
std::vector<GenericValue> args;
args.push_back(GenericValue(msr->getCodeGenContext()));
GenericValue gv = EE->runFunction(func, args);
}
示例12: main
int main(int argc, char**argv) {
InitializeNativeTarget();
InitializeNativeTargetAsmPrinter();
Module* Mod = makeLLVMModule();
verifyModule(*Mod, PrintMessageAction);
PassManager PM;
PM.add(createPrintModulePass(&outs()));
PM.run(*Mod);
//ExecutionEngine *exe=::llvm::Interpreter::create(Mod);
//ExecutionEngine *exe = EngineBuilder(Mod).create();
//printf("----%p\n",exe);
EngineBuilder eb = EngineBuilder(Mod);
#if LLVM_VERSION >= 33
eb.setEngineKind(EngineKind::JIT);
eb.setJITMemoryManager(JITMemoryManager::CreateDefaultMemManager());
eb.setAllocateGVsWithCode(false);
eb.setOptLevel(CodeGenOpt::Aggressive);
eb.setCodeModel(CodeModel::JITDefault);
#endif
eb.setMArch("x86-64");
eb.setMCPU("corei7-avx");
eb.setUseMCJIT(true);
ExecutionEngine *exe = eb.create();
std::vector<GenericValue> args;
GenericValue GVArgc;
GVArgc.IntVal = APInt(32, 24);
args.push_back(GVArgc);
//printf("xxxx:%p,%p\n",func_factorial,(void*)(&exe->runFunction));
GenericValue ret=exe->runFunction(func_factorial, args);
printf("ret=%llu\n",ret.IntVal.getZExtValue());
#if LLVM_VERSION < 33
exe->freeMachineCodeForFunction(func_factorial);
#endif
delete exe;
//llvm_shutdown();
return 0;
}
示例13: EngineBuilder
llvm::GenericValue minipascal::CodeGenContext::runCode()
{
std::cout << "Running code...\n";
ExecutionEngine* execueng = EngineBuilder(mmodule).create();
std::cout << "Code was run1.\n";
vector<GenericValue> noargs;
GenericValue retval;
std::cout << "Code was run2.\n";
if (execueng == nullptr)
{
cout << "nullptr executionenigine\n";
return retval;
}
else
{
cout << "not nullptr\n";
}
execueng->runFunction(currentFunction(), noargs);
std::cout << "Code was run3.\n";
return retval;
}
示例14: main
int main(int argc, char **argv) {
InitializeNativeTarget();
InitializeNativeTargetAsmPrinter();
InitializeNativeTargetAsmParser();
// Create a module containing the `calc` function
LLVMContext context;
Module* module = new Module("test", context);
// Create the expression and compile it
Expr* expression = parseExpression(argv[1]);
Function* calcFunction = compileFunction(context, module, "calc", expression);
// Initialize the LLVM JIT engine.
ExecutionEngine* engine = createEngine(module);
// Compute the result and print it out
auto calcArgs = parseArguments(argc - 2, argv + 2);
GenericValue calcValue = engine->runFunction(calcFunction, calcArgs);
outs() << "RESULT: " << calcValue.IntVal << "\n";
return 0;
}
示例15: main
//.........这里部分代码省略.........
}
std::unique_ptr<const MCInstrAnalysis>
MIA(TheTarget->createMCInstrAnalysis(MII.get()));
std::unique_ptr<MCObjectDisassembler> OD(
new MCObjectDisassembler(*Obj, *DisAsm, *MIA));
std::unique_ptr<MCModule> MCM(OD->buildEmptyModule());
if (!MCM)
return 1;
TransOpt::Level TOLvl;
switch (TransOptLevel) {
default:
errs() << ToolName << ": invalid optimization level.\n";
return 1;
case 0: TOLvl = TransOpt::None; break;
case 1: TOLvl = TransOpt::Less; break;
case 2: TOLvl = TransOpt::Default; break;
case 3: TOLvl = TransOpt::Aggressive; break;
}
std::unique_ptr<DCRegisterSema> DRS(
TheTarget->createDCRegisterSema(TripleName, *MRI, *MII));
if (!DRS) {
errs() << "error: no dc register sema for target " << TripleName << "\n";
return 1;
}
std::unique_ptr<DCInstrSema> DIS(
TheTarget->createDCInstrSema(TripleName, *DRS, *MRI, *MII));
if (!DIS) {
errs() << "error: no dc instruction sema for target " << TripleName << "\n";
return 1;
}
std::unique_ptr<DCTranslator> DT(new DCTranslator(getGlobalContext(), TOLvl,
*DIS, *DRS, *MIP,
*MCM, OD.get(),
AnnotateIROutput));
// Now run it !
Module *Mod = DT->getModule();
std::string ErrorMsg;
EngineBuilder Builder(Mod);
Builder.setErrorStr(&ErrorMsg);
Builder.setOptLevel(CodeGenOpt::Aggressive);
Builder.setEngineKind(EngineKind::JIT);
Builder.setAllocateGVsWithCode(false);
ExecutionEngine *EE = Builder.create();
if (!EE) {
errs() << "error: Unable to create ExecutionEngine: " << ErrorMsg << "\n";
return -1;
}
const DataLayout *DL = EE->getDataLayout();
const StructLayout *SL = DL->getStructLayout(DRS->getRegSetType());
uint8_t *RegSet = new uint8_t[SL->getSizeInBytes()];
const unsigned StackSize = 8192;
uint8_t *StackPtr = new uint8_t[StackSize];
std::vector<GenericValue> Args;
GenericValue GV;
GV.PointerVal = RegSet; Args.push_back(GV);
GV.PointerVal = StackPtr; Args.push_back(GV);
GV.IntVal = APInt(32, StackSize); Args.push_back(GV);
GV.IntVal = APInt(32, argc - 2); Args.push_back(GV);
GV.PointerVal = argv + 2; Args.push_back(GV);
EE->runFunction(DT->getInitRegSetFunction(), Args);
Args.clear();
GV.PointerVal = RegSet; Args.push_back(GV);
unsigned PCSize, PCOffset;
DRS->getRegOffsetInRegSet(DL, MRI->getProgramCounter(), PCSize, PCOffset);
__dc_DT = DT.get();
__dc_EE = EE;
uint64_t CurPC = DT->getEntrypoint();
while (CurPC != ~0ULL) {
Function *Fn = DT->getFunctionAt(CurPC);
DEBUG(dbgs() << "Executing function " << Fn->getName() << "\n");
EE->runFunction(Fn, Args);
CurPC = loadRegFromSet(RegSet, PCOffset, PCSize);
}
// Dump the IR we found.
if (DumpIR)
Mod->dump();
GV = EE->runFunction(DT->getFiniRegSetFunction(), Args);
return GV.IntVal.getZExtValue();
}