本文整理汇总了C++中SMDiagnostic::getMessage方法的典型用法代码示例。如果您正苦于以下问题:C++ SMDiagnostic::getMessage方法的具体用法?C++ SMDiagnostic::getMessage怎么用?C++ SMDiagnostic::getMessage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SMDiagnostic
的用法示例。
在下文中一共展示了SMDiagnostic::getMessage方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: JIT
IR JIT(IR code)
{
SMDiagnostic errors;
string parser_errors;
ParseAssemblyString(code.assembly.c_str(),master.Program,errors,Context);
if(master.debug)
{
cerr << "Code:\n" << code.assembly << endl;
}
llvm::Function* entryfn = master.Engine->FindFunctionNamed("entry");
if(entryfn == NULL)
nerror("ERROR: Couldn't find program entry point.");
if(!errors.getMessage().empty())
{
entryfn->eraseFromParent();
nerror("IR Parsed with errors: ",errors.getMessage(),"\nCode: \n",code.assembly);
}
if(verifyModule(*master.Program,ReturnStatusAction,&parser_errors))
{
entryfn->eraseFromParent();
nerror("IR Parser Error: ",parser_errors);
}
master.Passes.run(*master.Program);
if(master.debug)
{
cerr << "\nIR:" << endl;
master.Program->dump();
}
return code;
}
示例2: diagFromLLVMAssemblyDiag
SMDiagnostic MIRParserImpl::diagFromLLVMAssemblyDiag(const SMDiagnostic &Error,
SMRange SourceRange) {
assert(SourceRange.isValid());
// Translate the location of the error from the location in the llvm IR string
// to the corresponding location in the MIR file.
auto LineAndColumn = SM.getLineAndColumn(SourceRange.Start);
unsigned Line = LineAndColumn.first + Error.getLineNo() - 1;
unsigned Column = Error.getColumnNo();
StringRef LineStr = Error.getLineContents();
SMLoc Loc = Error.getLoc();
// Get the full line and adjust the column number by taking the indentation of
// LLVM IR into account.
for (line_iterator L(*SM.getMemoryBuffer(SM.getMainFileID()), false), E;
L != E; ++L) {
if (L.line_number() == Line) {
LineStr = *L;
Loc = SMLoc::getFromPointer(LineStr.data());
auto Indent = LineStr.find(Error.getLineContents());
if (Indent != StringRef::npos)
Column += Indent;
break;
}
}
return SMDiagnostic(SM, Loc, Filename, Line, Column, Error.getKind(),
Error.getMessage(), LineStr, Error.getRanges(),
Error.getFixIts());
}
示例3: dir
CodeGenContext::CodeGenContext():
mainFunction(0),
builder(getGlobalContext())
{
module = new Module("main", getGlobalContext());
linker=new llvm::Linker("phc", module);
char * externLibDir=getenv(PHC_ROOT_ENV);
if(externLibDir==0){
std::cout<<"Need Enviroment Variable "<<PHC_ROOT_ENV<<"\n";
return;
}
std::cout << "Parse print function\n";
SMDiagnostic Err;
std::string dir(externLibDir, strlen(externLibDir));
std::string filename("/extern/print.s");
filename = dir + filename;
libs = llvm::ParseIRFile(filename.c_str(), Err, getGlobalContext());
std::cout << "Status: " << Err.getMessage() << "\n";
if (libs == 0) {
std::cout << "Error: cannot parse module " << filename << "\n";
return;
}
std::cout << "Link print function\n";
std::string errorMsg;
linker->LinkModules(module, libs, llvm::Linker::DestroySource, &errorMsg);
std::cout << "Status: " << errorMsg << "\n";
}
示例4: jit_ir
Code* jit_ir(Code* code, const char* ir) {
SMDiagnostic errors;
string parser_errors;
ParseAssemblyString(ir,code->program,errors,Context);
Function* entryfn = code->program->getFunction(StringRef("entry"));
if(entryfn == NULL) {
return hylas_error_code("ERROR: Couldn't find program entry point.");
}
if(!errors.getMessage().empty()) {
entryfn->eraseFromParent();
return hylas_error_code(errors.getMessage().data());
}
if(verifyModule(*code->program,ReturnStatusAction,&parser_errors)) {
entryfn->eraseFromParent();
return hylas_error_code(parser_errors.data());
}
code->passes.run(*code->program);
return code;
}
示例5: wrap
extern "C" LLVMModuleRef LLVMRustParseAssemblyFile(const char *Filename) {
SMDiagnostic d;
Module *m = ParseAssemblyFile(Filename, d, getGlobalContext());
if (m) {
return wrap(m);
} else {
LLVMRustError = d.getMessage().str().c_str();
return NULL;
}
}
示例6: linkLibrary
void LLVMGenerator::linkLibrary(const std::string& path)
{
SMDiagnostic diag;
Module* mod = ParseIRFile(path, diag, getGlobalContext());
if(!mod)
throw std::runtime_error("could not load library '" + path + "': " + diag.getMessage());
linkLibrary(*mod);
}
示例7: VerboseStrm
static std::unique_ptr<Module> getModule(
StringRef ProgramName, LLVMContext &Context,
StreamingMemoryObject *StreamingObject) {
std::unique_ptr<Module> M;
SMDiagnostic Err;
std::string VerboseBuffer;
raw_string_ostream VerboseStrm(VerboseBuffer);
if (LazyBitcode) {
std::string StrError;
switch (InputFileFormat) {
case PNaClFormat: {
std::unique_ptr<StreamingMemoryObject> Cache(
new ThreadedStreamingCache(StreamingObject));
M.reset(getNaClStreamedBitcodeModule(
InputFilename, Cache.release(), Context, &VerboseStrm, &StrError));
break;
}
case LLVMFormat: {
std::unique_ptr<StreamingMemoryObject> Cache(
new ThreadedStreamingCache(StreamingObject));
ErrorOr<std::unique_ptr<Module>> MOrErr =
getStreamedBitcodeModule(
InputFilename, Cache.release(), Context);
M = std::move(*MOrErr);
break;
}
case AutodetectFileFormat:
report_fatal_error("Command can't autodetect file format!");
}
if (!StrError.empty())
Err = SMDiagnostic(InputFilename, SourceMgr::DK_Error, StrError);
} else {
#if defined(PNACL_BROWSER_TRANSLATOR)
llvm_unreachable("native client SRPC only supports streaming");
#else
// Parses binary bitcode as well as textual assembly
// (so pulls in more code into pnacl-llc).
M = NaClParseIRFile(InputFilename, InputFileFormat, Err, &VerboseStrm,
Context);
#endif
}
if (!M) {
#if defined(PNACL_BROWSER_TRANSLATOR)
report_fatal_error(VerboseStrm.str() + Err.getMessage());
#else
// Err.print is prettier, so use it for the non-sandboxed translator.
Err.print(ProgramName.data(), errs());
errs() << VerboseStrm.str();
return nullptr;
#endif
}
return std::move(M);
}
示例8: diagFromMIStringDiag
SMDiagnostic MIRParserImpl::diagFromMIStringDiag(const SMDiagnostic &Error,
SMRange SourceRange) {
assert(SourceRange.isValid() && "Invalid source range");
SMLoc Loc = SourceRange.Start;
bool HasQuote = Loc.getPointer() < SourceRange.End.getPointer() &&
*Loc.getPointer() == '\'';
// Translate the location of the error from the location in the MI string to
// the corresponding location in the MIR file.
Loc = Loc.getFromPointer(Loc.getPointer() + Error.getColumnNo() +
(HasQuote ? 1 : 0));
// TODO: Translate any source ranges as well.
return SM.GetMessage(Loc, Error.getKind(), Error.getMessage(), None,
Error.getFixIts());
}
示例9: load
bool ArchiveImporter::load(StringRef qualifiedName, Module *& module) {
if (!valid_) {
return false;
}
if (archive_ == NULL) {
SMDiagnostic smErr;
archive_ = ParseIRFile(path_.str(), smErr, getGlobalContext());
if (archive_ == NULL) {
bool exists = false;
if (fs::exists(path_.str(), exists) == errc::success && exists) {
diag.error() << "Cannot load library " << path_;
diag.info() << smErr.getMessage();
}
valid_ = false;
return false;
}
archiveSource_ = new ArchiveFile(path_);
}
Twine mdName("tart.xdef.");
NamedMDNode * md = archive_->getNamedMetadata(mdName.concat(qualifiedName));
if (md != NULL) {
// Convert the qualified name of the module to a relative path.
SmallString<128> relpath(path_);
relpath.reserve(path_.size() + qualifiedName.size() + 1);
relpath.push_back('#');
for (size_t i = 0; i < qualifiedName.size(); ++i) {
if (qualifiedName[i] == '.') {
relpath.push_back('/');
} else {
relpath.push_back(qualifiedName[i]);
}
}
// Create the module and read the header.
module = new Module(qualifiedName, &Builtins::module);
module->setModuleSource(new ArchiveEntry(relpath, archiveSource_));
return MDReader(module, module).read(md);
}
return false;
}
示例10: LinkExternalBitcode
Module* LinkExternalBitcode(Module* module, std::string bc)
{
LLVMContext &Context = getGlobalContext();
SMDiagnostic smdiagnostic;
std::string InputFile = GetRootPath() + "/" + bc;
Module* LoadBitcode = ParseIRFile(InputFile, smdiagnostic, Context);
if (!LoadBitcode) {
std::cerr << InputFile << " : " << smdiagnostic.getMessage() <<'\n';
}
std::string err;
bool result = Linker::LinkModules(module, LoadBitcode,
Linker::DestroySource, &err);
if (result) {
std::cerr << "Module Linking Error : "<< err << '\n';
}
return module;
};
示例11: LoadLLRuntime
void LoadLLRuntime()
{
#ifdef HSPWIN
HRSRC hrc;
HGLOBAL hgb;
LPVOID p;
LLVMContext& context = getGlobalContext();
hrc = FindResource(NULL, MAKEINTRESOURCEA(256), "TEXT");
hgb = LoadResource(NULL, hrc);
p = LockResource(hgb);
SMDiagnostic err;
rtModule.reset(ParseAssemblyString((char*)p, nullptr, err, context));
FreeResource(hrc);
if (!rtModule)
Alert(err.getMessage().data());
#else
#error
#endif
}
示例12: SetupModuleFromIR
//////////////////////////////////////////////////////////////////////////
/// @brief Create new LLVM module from IR.
bool JitManager::SetupModuleFromIR(const uint8_t *pIR)
{
std::unique_ptr<MemoryBuffer> pMem = MemoryBuffer::getMemBuffer(StringRef((const char*)pIR), "");
SMDiagnostic Err;
std::unique_ptr<Module> newModule = parseIR(pMem.get()->getMemBufferRef(), Err, mContext);
SWR_REL_ASSERT(
!(newModule == nullptr),
"Parse failed!\n"
"%s", Err.getMessage().data());
if (newModule == nullptr)
{
return false;
}
#if HAVE_LLVM == 0x307
// llvm-3.7 has mismatched setDataLyout/getDataLayout APIs
newModule->setDataLayout(*mpExec->getDataLayout());
#else
newModule->setDataLayout(mpExec->getDataLayout());
#endif
mpCurrentModule = newModule.get();
#if defined(_WIN32)
// Needed for MCJIT on windows
Triple hostTriple(sys::getProcessTriple());
hostTriple.setObjectFormat(Triple::ELF);
newModule->setTargetTriple(hostTriple.getTriple());
#endif // _WIN32
mpExec->addModule(std::move(newModule));
mIsModuleFinalized = false;
return true;
}
示例13: asmcode
static llvm::Module* jitCompile(const std::string& String)
{
// Create some module to put our function into it.
using namespace llvm;
legacy::PassManager* PM = extemp::EXTLLVM::PM;
legacy::PassManager* PM_NO = extemp::EXTLLVM::PM_NO;
char modname[256];
sprintf(modname, "xtmmodule_%lld", ++llvm_emitcounter);
std::string asmcode(String);
SMDiagnostic pa;
static std::string sInlineString; // This is a hack for now, but it *WORKS*
static std::string sInlineBitcode;
static std::unordered_set<std::string> sInlineSyms;
if (sInlineString.empty()) {
{
std::ifstream inStream(UNIV::SHARE_DIR + "/runtime/bitcode.ll");
std::stringstream inString;
inString << inStream.rdbuf();
sInlineString = inString.str();
}
std::copy(std::sregex_token_iterator(sInlineString.begin(), sInlineString.end(), sGlobalSymRegex, 1),
std::sregex_token_iterator(), std::inserter(sInlineSyms, sInlineSyms.begin()));
{
std::ifstream inStream(UNIV::SHARE_DIR + "/runtime/inline.ll");
std::stringstream inString;
inString << inStream.rdbuf();
std::string tString = inString.str();
std::copy(std::sregex_token_iterator(tString.begin(), tString.end(), sGlobalSymRegex, 1),
std::sregex_token_iterator(), std::inserter(sInlineSyms, sInlineSyms.begin()));
}
}
if (sInlineBitcode.empty()) {
// need to avoid parsing the types twice
static bool first(true);
if (!first) {
auto newModule(parseAssemblyString(sInlineString, pa, getGlobalContext()));
if (newModule) {
std::string bitcode;
llvm::raw_string_ostream bitstream(sInlineBitcode);
llvm::WriteBitcodeToFile(newModule.get(), bitstream);
std::ifstream inStream(UNIV::SHARE_DIR + "/runtime/inline.ll");
std::stringstream inString;
inString << inStream.rdbuf();
sInlineString = inString.str();
} else {
std::cout << pa.getMessage().str() << std::endl;
abort();
}
} else {
first = false;
}
}
std::unique_ptr<llvm::Module> newModule;
std::vector<std::string> symbols;
std::copy(std::sregex_token_iterator(asmcode.begin(), asmcode.end(), sGlobalSymRegex, 1),
std::sregex_token_iterator(), std::inserter(symbols, symbols.begin()));
std::sort(symbols.begin(), symbols.end());
auto end(std::unique(symbols.begin(), symbols.end()));
std::unordered_set<std::string> ignoreSyms;
std::copy(std::sregex_token_iterator(asmcode.begin(), asmcode.end(), sDefineSymRegex, 1),
std::sregex_token_iterator(), std::inserter(ignoreSyms, ignoreSyms.begin()));
std::string declarations;
llvm::raw_string_ostream dstream(declarations);
for (auto iter = symbols.begin(); iter != end; ++iter) {
const char* sym(iter->c_str());
if (sInlineSyms.find(sym) != sInlineSyms.end() || ignoreSyms.find(sym) != ignoreSyms.end()) {
continue;
}
auto gv = extemp::EXTLLVM::getGlobalValue(sym);
if (!gv) {
continue;
}
auto func(llvm::dyn_cast<llvm::Function>(gv));
if (func) {
dstream << "declare " << SanitizeType(func->getReturnType()) << " @" << sym << " (";
bool first(true);
for (const auto& arg : func->getArgumentList()) {
if (!first) {
dstream << ", ";
} else {
first = false;
}
dstream << SanitizeType(arg.getType());
}
if (func->isVarArg()) {
dstream << ", ...";
}
dstream << ")\n";
} else {
auto str(SanitizeType(gv->getType()));
dstream << '@' << sym << " = external global " << str.substr(0, str.length() - 1) << '\n';
}
}
// std::cout << "**** DECL ****\n" << dstream.str() << "**** ENDDECL ****\n" << std::endl;
if (!sInlineBitcode.empty()) {
auto modOrErr(parseBitcodeFile(llvm::MemoryBufferRef(sInlineBitcode, "<string>"), getGlobalContext()));
if (likely(modOrErr)) {
//.........这里部分代码省略.........
示例14: valueIsOnlyCalled
static bool valueIsOnlyCalled(const Value *v) {
#if LLVM_VERSION_CODE < LLVM_VERSION(3, 5)
for (auto it = v->use_begin(), ie = v->use_end(); it != ie; ++it) {
auto user = *it;
#else
for (auto user : v->users()) {
#endif
if (const auto *instr = dyn_cast<Instruction>(user)) {
// Make sure the instruction is a call or invoke.
CallSite cs(const_cast<Instruction *>(instr));
if (!cs) return false;
// Make sure that the value is only the target of this call and
// not an argument.
if (cs.hasArgument(v))
return false;
} else if (const auto *ce = dyn_cast<ConstantExpr>(user)) {
if (ce->getOpcode() == Instruction::BitCast)
if (valueIsOnlyCalled(ce))
continue;
return false;
} else if (const auto *ga = dyn_cast<GlobalAlias>(user)) {
if (v == ga->getAliasee() && !valueIsOnlyCalled(ga))
return false;
} else if (isa<BlockAddress>(user)) {
// only valid as operand to indirectbr or comparison against null
continue;
} else {
return false;
}
}
return true;
}
bool klee::functionEscapes(const Function *f) {
return !valueIsOnlyCalled(f);
}
bool klee::loadFile(const std::string &fileName, LLVMContext &context,
std::vector<std::unique_ptr<llvm::Module>> &modules,
std::string &errorMsg) {
KLEE_DEBUG_WITH_TYPE("klee_loader", dbgs()
<< "Load file " << fileName << "\n");
#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 5)
ErrorOr<std::unique_ptr<MemoryBuffer>> bufferErr =
MemoryBuffer::getFileOrSTDIN(fileName);
std::error_code ec = bufferErr.getError();
#else
OwningPtr<MemoryBuffer> Buffer;
error_code ec = MemoryBuffer::getFileOrSTDIN(fileName, Buffer);
#endif
if (ec) {
klee_error("Loading file %s failed: %s", fileName.c_str(),
ec.message().c_str());
}
#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6)
MemoryBufferRef Buffer = bufferErr.get()->getMemBufferRef();
#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 5)
MemoryBuffer *Buffer = bufferErr->get();
#endif
#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6)
sys::fs::file_magic magic = sys::fs::identify_magic(Buffer.getBuffer());
#else
sys::fs::file_magic magic = sys::fs::identify_magic(Buffer->getBuffer());
#endif
if (magic == sys::fs::file_magic::bitcode) {
SMDiagnostic Err;
#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6)
std::unique_ptr<llvm::Module> module(parseIR(Buffer, Err, context));
#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 5)
std::unique_ptr<llvm::Module> module(ParseIR(Buffer, Err, context));
#else
std::unique_ptr<llvm::Module> module(ParseIR(Buffer.take(), Err, context));
#endif
if (!module) {
klee_error("Loading file %s failed: %s", fileName.c_str(),
Err.getMessage().str().c_str());
}
modules.push_back(std::move(module));
return true;
}
if (magic == sys::fs::file_magic::archive) {
#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6)
ErrorOr<std::unique_ptr<object::Binary>> archOwner =
object::createBinary(Buffer, &context);
ec = archOwner.getError();
llvm::object::Binary *arch = archOwner.get().get();
#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 5)
ErrorOr<object::Binary *> archOwner =
object::createBinary(std::move(bufferErr.get()), &context);
ec = archOwner.getError();
llvm::object::Binary *arch = archOwner.get();
#else
OwningPtr<object::Binary> archOwner;
//.........这里部分代码省略.........