本文整理汇总了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;
}