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


C++ OwningPtr::getPointerToFunction方法代码示例

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


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

示例1: sstream


//.........这里部分代码省略.........
    Args.push_back("-fsyntax-only");
    OwningPtr<Compilation> C(TheDriver.BuildCompilation(Args));
    if (!C)
    {
      sstream << "Can't create Compilation object (TheDriver.BuildCompilation())\n";
      return NULL;
    }

    // FIXME: This is copied from ASTUnit.cpp; simplify and eliminate.

    // We expect to get back exactly one command job, if we didn't something
    // failed. Extract that job from the compilation.
    const driver::JobList &Jobs = C->getJobs();
    if (Jobs.size() != 1 || !isa<driver::Command>(*Jobs.begin())) {
      SmallString<256> Msg;
      llvm::raw_svector_ostream OS(Msg);
      sstream << "Wrong number of compiler jobs (see details below)\n";
      C->PrintJob(OS, C->getJobs(), "; ", true);
      Diags.Report(diag::err_fe_expected_compiler_job) << OS.str();
      return NULL;
    }

    const driver::Command *Cmd = cast<driver::Command>(*Jobs.begin());
    if (llvm::StringRef(Cmd->getCreator().getName()) != "clang") {
      sstream << "No clang job (see details below)\n";
      Diags.Report(diag::err_fe_expected_clang_command);
      return NULL;
    }

    // Initialize a compiler invocation object from the clang (-cc1) arguments.
    const driver::ArgStringList &CCArgs = Cmd->getArguments();
    OwningPtr<CompilerInvocation> CI(new CompilerInvocation);
    CompilerInvocation::CreateFromArgs(*CI,
                                       const_cast<const char **>(CCArgs.data()),
                                       const_cast<const char **>(CCArgs.data()) +
                                         CCArgs.size(),
                                       Diags);

    // FIXME: This is copied from cc1_main.cpp; simplify and eliminate.

    // Create a compiler instance to handle the actual work.
    CompilerInstance Clang;
    Clang.setInvocation(CI.take());

    // Create the compilers actual diagnostics engine.
    Clang.createDiagnostics();
    if (!Clang.hasDiagnostics())
    {
      sstream << "Can't create diagnostics engine\n";
      return NULL;
    }

    // Create and execute the frontend to generate an LLVM bitcode module.
    OwningPtr<CodeGenAction> Act(new EmitLLVMOnlyAction(Ctx.get()));
    if (!Clang.ExecuteAction(*Act))
    {
      sstream <<  "Can't execute frontend action (parsing source, converting to LLVM IR)\n";
      return NULL;
    }

    if (llvm::Module *Module = Act->takeModule())
    {
      // now let's create MSCJIT instance
      LLVMLinkInMCJIT();
      std::string Error;
      EE.reset(createMCJIT (Module, Error));
      if (!EE) {
        sstream <<  "Unable to make execution engine: " << Error;
        return NULL;
      }
      // compile module, apply memory permissions
      EE->finalizeObject();
      // retrieve requested function
      Function* F = Module->getFunction(function);
      if (!F) {
        sstream << "Function " << function << " couldn't be found in module\n";
        return NULL;
      }

      return EE->getPointerToFunction(F);
    }
  }


  // Execution engine already created
  if (EE)
  {
    // just find damn function
    Function* F = EE->FindFunctionNamed(function);
    if (!F) {
      sstream << "Function " << function << " couldn't be found in module\n";
      return NULL;
    }

    return EE->getPointerToFunction(F);
  }

  sstream << "Unknown error (may be no execution engine is present)\n";
  return NULL;
}
开发者ID:rampage644,项目名称:zerovm-llvm,代码行数:101,代码来源:jit.cpp


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