本文整理汇总了C++中LLVMContext::getDiagnosticContext方法的典型用法代码示例。如果您正苦于以下问题:C++ LLVMContext::getDiagnosticContext方法的具体用法?C++ LLVMContext::getDiagnosticContext怎么用?C++ LLVMContext::getDiagnosticContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LLVMContext
的用法示例。
在下文中一共展示了LLVMContext::getDiagnosticContext方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: compileModule
//.........这里部分代码省略.........
OS = BOS.get();
}
if (!RunPassNames->empty()) {
if (!StartAfter.empty() || !StopAfter.empty() || !StartBefore.empty() ||
!StopBefore.empty()) {
errs() << argv[0] << ": start-after and/or stop-after passes are "
"redundant when run-pass is specified.\n";
return 1;
}
if (!MIR) {
errs() << argv[0] << ": run-pass needs a .mir input.\n";
return 1;
}
LLVMTargetMachine &LLVMTM = static_cast<LLVMTargetMachine&>(*Target);
TargetPassConfig &TPC = *LLVMTM.createPassConfig(PM);
PM.add(&TPC);
MachineModuleInfo *MMI = new MachineModuleInfo(&LLVMTM);
MMI->setMachineFunctionInitializer(MIR.get());
PM.add(MMI);
TPC.printAndVerify("");
for (const std::string &RunPassName : *RunPassNames) {
if (addPass(PM, argv[0], RunPassName, TPC))
return 1;
}
PM.add(createPrintMIRPass(*OS));
} else {
const char *argv0 = argv[0];
AnalysisID StartBeforeID = getPassID(argv0, "start-before", StartBefore);
AnalysisID StartAfterID = getPassID(argv0, "start-after", StartAfter);
AnalysisID StopAfterID = getPassID(argv0, "stop-after", StopAfter);
AnalysisID StopBeforeID = getPassID(argv0, "stop-before", StopBefore);
if (StartBeforeID && StartAfterID) {
errs() << argv[0] << ": -start-before and -start-after specified!\n";
return 1;
}
if (StopBeforeID && StopAfterID) {
errs() << argv[0] << ": -stop-before and -stop-after specified!\n";
return 1;
}
// Ask the target to add backend passes as necessary.
if (Target->addPassesToEmitFile(PM, *OS, FileType, NoVerify,
StartBeforeID, StartAfterID, StopBeforeID,
StopAfterID, MIR.get())) {
errs() << argv[0] << ": target does not support generation of this"
<< " file type!\n";
return 1;
}
}
// Before executing passes, print the final values of the LLVM options.
cl::PrintOptionValues();
// If requested, run the pass manager over the same module again,
// to catch any bugs due to persistent state in the passes. Note that
// opt has the same functionality, so it may be worth abstracting this out
// in the future.
SmallVector<char, 0> CompileTwiceBuffer;
if (CompileTwice) {
std::unique_ptr<Module> M2(llvm::CloneModule(M.get()));
PM.run(*M2);
CompileTwiceBuffer = Buffer;
Buffer.clear();
}
PM.run(*M);
auto HasError = *static_cast<bool *>(Context.getDiagnosticContext());
if (HasError)
return 1;
// Compare the two outputs and make sure they're the same
if (CompileTwice) {
if (Buffer.size() != CompileTwiceBuffer.size() ||
(memcmp(Buffer.data(), CompileTwiceBuffer.data(), Buffer.size()) !=
0)) {
errs()
<< "Running the pass manager twice changed the output.\n"
"Writing the result of the second run to the specified output\n"
"To generate the one-run comparison binary, just run without\n"
"the compile-twice option\n";
Out->os() << Buffer;
Out->keep();
return 1;
}
}
if (BOS) {
Out->os() << Buffer;
}
}
// Declare success.
Out->keep();
return 0;
}