当前位置: 首页>>代码示例>>C++>>正文


C++ ExecutionEngine::getFunctionAddress方法代码示例

本文整理汇总了C++中ExecutionEngine::getFunctionAddress方法的典型用法代码示例。如果您正苦于以下问题:C++ ExecutionEngine::getFunctionAddress方法的具体用法?C++ ExecutionEngine::getFunctionAddress怎么用?C++ ExecutionEngine::getFunctionAddress使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ExecutionEngine的用法示例。


在下文中一共展示了ExecutionEngine::getFunctionAddress方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main() {
    LLVMInitializeNativeTarget();
    LLVMInitializeNativeAsmPrinter();
    LLVMInitializeNativeAsmParser();

    LLVMContext &Context = getGlobalContext();
    IRBuilder<> Builder(Context);
    std::unique_ptr<Module> Owner = make_unique<Module>("simple_module", Context);
    Module *M = Owner.get();

    Function *F = Function::Create(TypeBuilder<int32_t(void), false>::get(Context),
                                   GlobalValue::ExternalLinkage, "scramble", M);
    BasicBlock *BB = BasicBlock::Create(Context, "entry", F);
    Builder.SetInsertPoint(BB);
    Builder.CreateRet(ConstantInt::get(Context, APInt(32, 24)));

    F = Function::Create(TypeBuilder<int32_t(void), false>::get(Context),
                         GlobalValue::ExternalLinkage, "ooo1", M);
    BB = BasicBlock::Create(Context, "entry", F);
    Builder.SetInsertPoint(BB);
    Builder.CreateRet(ConstantInt::get(Context, APInt(32, 42)));

    M->dump();
    ExecutionEngine *EE = EngineBuilder(std::move(Owner)).create();
    assert(EE != NULL && "error creating MCJIT with EngineBuilder");
    union {
        uint64_t raw;
        int (*usable)();
    } functionPointer;
    functionPointer.raw = EE->getFunctionAddress("ooo1");
    std::cout << functionPointer.usable() << std::endl;

    return 0;
}
开发者ID:artagnon,项目名称:sandbox,代码行数:34,代码来源:llbugplus.cpp

示例2: LoadPlugin

	void LoadPlugin(const std::string& path, const std::string& name, MetaScriptRunner* msr) {

		SMDiagnostic error;
		std::unique_ptr<Module> Owner = parseIRFile(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";

		uint64_t func_addr = EE->getFunctionAddress(func_name.c_str());
		if (func_addr == 0) {
			printf("错误, 找不到函数: %s\n", func_name.c_str());
			return;
		}
		func_type func = (func_type) func_addr;
		func(msr->getCodeGenContext());
	}
开发者ID:elite-lang,项目名称:Elite,代码行数:22,代码来源:PackageJIT.cpp

示例3: main

int main() {
    ygt_print("Hello!\n");
    InitializeNativeTarget();
    InitializeNativeTargetAsmPrinter();
    InitializeNativeTargetAsmParser();
    InitializeNativeTargetDisassembler();

    ygt_print("Creating LLVM context and module...\n");
    LLVMContext ctx;
    auto m = make_unique<Module>("the_module", ctx);

    ygt_print("Creating StackMapHelper...\n");
    StackMapHelper smhelper;

    ygt_print("Declaring yg_stack_swap as an LLVM-level function...\n");
    declare_ss(ctx, *m);

    ygt_print("Constructing bar, the ss leaf...\n");
    Function *bar;
    smid_t bar_smid;
    tie(bar, bar_smid) = make_ss_leaf("barss", &main_stack, &coro_stack, smhelper, ctx, *m);

    verifyFunction(*bar);

    ygt_print("Constructing foo, the caller...\n");
    Function *foo;
    smid_t foo_smid;
    tie(foo, foo_smid) = make_caller("foo", bar, smhelper, ctx, *m);

    verifyFunction(*foo);

    m->dump();

    Function *ss_func = m->getFunction("yg_stack_swap");

    ygt_print("Creating execution engine...\n");
    ExecutionEngine *ee = EngineBuilder(move(m)).setEngineKind(EngineKind::JIT).create();
    ygt_print("Execution engine created.\n");

    StackMapSectionRecorder smsr;
    ygt_print("Registering JIT event listener...\n");
    ee->RegisterJITEventListener(&smsr);

    EHFrameSectionRegisterer reg;
    ygt_print("Registering EHFrame registerer...\n");
    ee->RegisterJITEventListener(&reg);

    ygt_print("Adding global mapping yg_stack_swap...\n");
    ee->addGlobalMapping(ss_func, reinterpret_cast<void*>(yg_stack_swap));

    ygt_print("JIT compiling...\n");
    ee->finalizeObject();

    ygt_print("Adding stack map sections...\n");
    smhelper.add_stackmap_sections(smsr, *ee);

    ygt_print("Registering EH frames...\n");
    reg.registerEHFrameSections();

    uintptr_t yg_stack_swap_addr = ee->getFunctionAddress("yg_stack_swap");
    ygt_print("yg_stack_swap_addr=%" PRIxPTR ", yg_stack_swap=%p\n", yg_stack_swap_addr, yg_stack_swap);
    assert(yg_stack_swap_addr == reinterpret_cast<uintptr_t>(yg_stack_swap));

    ygt_print("Getting foo...\n");
    void (*the_real_foo)(int32_t, int64_t, float, double) = (void(*)(int32_t, int64_t, float, double))
            ee->getFunctionAddress("foo");
    ygt_print("the_real_foo == %p\n", the_real_foo);

    ygt_print("Prepare corotine for introspection...\n");
    coro_stack = YGStack::alloc(8*1024*1024);
    coro_stack.init(reinterpret_cast<uintptr_t>(coro));

    MyCtx my_ctx = { foo_smid, bar_smid, &smhelper };

    ygt_print("Swap-stack to prepare the coroutine...\n");
    yg_stack_swap(&main_stack, &coro_stack, reinterpret_cast<uintptr_t>(&my_ctx));

    ygt_print("Back from coro.\n");

    ygt_print("Calling the_real_foo...\n");

    the_real_foo(100, 200, 300.0f, 400.0);

    ygt_print("Returned from foo.\n");

    return 0;
}
开发者ID:microvm,项目名称:libyugong,代码行数:87,代码来源:test-llvm_stackmap.cpp


注:本文中的ExecutionEngine::getFunctionAddress方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。