forked from OSchip/llvm-project
Make SMDiagnostic a little more sane. Instead of passing around note/warning/error as a
string, pass it around as an enum. llvm-svn: 142107
This commit is contained in:
parent
a3a0681083
commit
03b80a4027
|
@ -40,7 +40,8 @@ namespace llvm {
|
||||||
std::string ErrMsg;
|
std::string ErrMsg;
|
||||||
Module *M = getLazyBitcodeModule(Buffer, Context, &ErrMsg);
|
Module *M = getLazyBitcodeModule(Buffer, Context, &ErrMsg);
|
||||||
if (M == 0) {
|
if (M == 0) {
|
||||||
Err = SMDiagnostic(Buffer->getBufferIdentifier(), ErrMsg);
|
Err = SMDiagnostic(Buffer->getBufferIdentifier(), SourceMgr::DK_Error,
|
||||||
|
ErrMsg);
|
||||||
// ParseBitcodeFile does not take ownership of the Buffer in the
|
// ParseBitcodeFile does not take ownership of the Buffer in the
|
||||||
// case of an error.
|
// case of an error.
|
||||||
delete Buffer;
|
delete Buffer;
|
||||||
|
@ -60,7 +61,7 @@ namespace llvm {
|
||||||
LLVMContext &Context) {
|
LLVMContext &Context) {
|
||||||
OwningPtr<MemoryBuffer> File;
|
OwningPtr<MemoryBuffer> File;
|
||||||
if (error_code ec = MemoryBuffer::getFileOrSTDIN(Filename.c_str(), File)) {
|
if (error_code ec = MemoryBuffer::getFileOrSTDIN(Filename.c_str(), File)) {
|
||||||
Err = SMDiagnostic(Filename,
|
Err = SMDiagnostic(Filename, SourceMgr::DK_Error,
|
||||||
"Could not open input file: " + ec.message());
|
"Could not open input file: " + ec.message());
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -80,7 +81,8 @@ namespace llvm {
|
||||||
std::string ErrMsg;
|
std::string ErrMsg;
|
||||||
Module *M = ParseBitcodeFile(Buffer, Context, &ErrMsg);
|
Module *M = ParseBitcodeFile(Buffer, Context, &ErrMsg);
|
||||||
if (M == 0)
|
if (M == 0)
|
||||||
Err = SMDiagnostic(Buffer->getBufferIdentifier(), ErrMsg);
|
Err = SMDiagnostic(Buffer->getBufferIdentifier(), SourceMgr::DK_Error,
|
||||||
|
ErrMsg);
|
||||||
// ParseBitcodeFile does not take ownership of the Buffer.
|
// ParseBitcodeFile does not take ownership of the Buffer.
|
||||||
delete Buffer;
|
delete Buffer;
|
||||||
return M;
|
return M;
|
||||||
|
@ -97,7 +99,7 @@ namespace llvm {
|
||||||
LLVMContext &Context) {
|
LLVMContext &Context) {
|
||||||
OwningPtr<MemoryBuffer> File;
|
OwningPtr<MemoryBuffer> File;
|
||||||
if (error_code ec = MemoryBuffer::getFileOrSTDIN(Filename.c_str(), File)) {
|
if (error_code ec = MemoryBuffer::getFileOrSTDIN(Filename.c_str(), File)) {
|
||||||
Err = SMDiagnostic(Filename,
|
Err = SMDiagnostic(Filename, SourceMgr::DK_Error,
|
||||||
"Could not open input file: " + ec.message());
|
"Could not open input file: " + ec.message());
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,10 +31,16 @@ namespace llvm {
|
||||||
/// and handles diagnostic wrangling.
|
/// and handles diagnostic wrangling.
|
||||||
class SourceMgr {
|
class SourceMgr {
|
||||||
public:
|
public:
|
||||||
|
enum DiagKind {
|
||||||
|
DK_Error,
|
||||||
|
DK_Warning,
|
||||||
|
DK_Note
|
||||||
|
};
|
||||||
|
|
||||||
/// DiagHandlerTy - Clients that want to handle their own diagnostics in a
|
/// DiagHandlerTy - Clients that want to handle their own diagnostics in a
|
||||||
/// custom way can register a function pointer+context as a diagnostic
|
/// custom way can register a function pointer+context as a diagnostic
|
||||||
/// handler. It gets called each time PrintMessage is invoked.
|
/// handler. It gets called each time PrintMessage is invoked.
|
||||||
typedef void (*DiagHandlerTy)(const SMDiagnostic&, void *Context);
|
typedef void (*DiagHandlerTy)(const SMDiagnostic &, void *Context);
|
||||||
private:
|
private:
|
||||||
struct SrcBuffer {
|
struct SrcBuffer {
|
||||||
/// Buffer - The memory buffer for the file.
|
/// Buffer - The memory buffer for the file.
|
||||||
|
@ -119,10 +125,7 @@ public:
|
||||||
/// PrintMessage - Emit a message about the specified location with the
|
/// PrintMessage - Emit a message about the specified location with the
|
||||||
/// specified string.
|
/// specified string.
|
||||||
///
|
///
|
||||||
/// @param Type - If non-null, the kind of message (e.g., "error") which is
|
void PrintMessage(SMLoc Loc, DiagKind Kind, const Twine &Msg,
|
||||||
/// prefixed to the message.
|
|
||||||
/// @param ShowLine - Should the diagnostic show the source line.
|
|
||||||
void PrintMessage(SMLoc Loc, const Twine &Msg, const char *Type,
|
|
||||||
ArrayRef<SMRange> Ranges = ArrayRef<SMRange>(),
|
ArrayRef<SMRange> Ranges = ArrayRef<SMRange>(),
|
||||||
bool ShowLine = true) const;
|
bool ShowLine = true) const;
|
||||||
|
|
||||||
|
@ -133,8 +136,7 @@ public:
|
||||||
/// @param Type - If non-null, the kind of message (e.g., "error") which is
|
/// @param Type - If non-null, the kind of message (e.g., "error") which is
|
||||||
/// prefixed to the message.
|
/// prefixed to the message.
|
||||||
/// @param ShowLine - Should the diagnostic show the source line.
|
/// @param ShowLine - Should the diagnostic show the source line.
|
||||||
SMDiagnostic GetMessage(SMLoc Loc,
|
SMDiagnostic GetMessage(SMLoc Loc, DiagKind Kind, const Twine &Msg,
|
||||||
const Twine &Msg, const char *Type,
|
|
||||||
ArrayRef<SMRange> Ranges = ArrayRef<SMRange>(),
|
ArrayRef<SMRange> Ranges = ArrayRef<SMRange>(),
|
||||||
bool ShowLine = true) const;
|
bool ShowLine = true) const;
|
||||||
|
|
||||||
|
@ -155,21 +157,24 @@ class SMDiagnostic {
|
||||||
SMLoc Loc;
|
SMLoc Loc;
|
||||||
std::string Filename;
|
std::string Filename;
|
||||||
int LineNo, ColumnNo;
|
int LineNo, ColumnNo;
|
||||||
|
SourceMgr::DiagKind Kind;
|
||||||
std::string Message, LineContents;
|
std::string Message, LineContents;
|
||||||
unsigned ShowLine : 1;
|
unsigned ShowLine : 1;
|
||||||
std::vector<std::pair<unsigned, unsigned> > Ranges;
|
std::vector<std::pair<unsigned, unsigned> > Ranges;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Null diagnostic.
|
// Null diagnostic.
|
||||||
SMDiagnostic() : SM(0), LineNo(0), ColumnNo(0), ShowLine(0) {}
|
SMDiagnostic()
|
||||||
|
: SM(0), LineNo(0), ColumnNo(0), Kind(SourceMgr::DK_Error), ShowLine(0) {}
|
||||||
// Diagnostic with no location (e.g. file not found, command line arg error).
|
// Diagnostic with no location (e.g. file not found, command line arg error).
|
||||||
SMDiagnostic(const std::string &filename, const std::string &Msg)
|
SMDiagnostic(const std::string &filename, SourceMgr::DiagKind Kind,
|
||||||
: SM(0), Filename(filename), LineNo(-1), ColumnNo(-1),
|
const std::string &Msg)
|
||||||
|
: SM(0), Filename(filename), LineNo(-1), ColumnNo(-1), Kind(Kind),
|
||||||
Message(Msg), ShowLine(false) {}
|
Message(Msg), ShowLine(false) {}
|
||||||
|
|
||||||
// Diagnostic with a location.
|
// Diagnostic with a location.
|
||||||
SMDiagnostic(const SourceMgr &sm, SMLoc L, const std::string &FN,
|
SMDiagnostic(const SourceMgr &sm, SMLoc L, const std::string &FN,
|
||||||
int Line, int Col,
|
int Line, int Col, SourceMgr::DiagKind Kind,
|
||||||
const std::string &Msg, const std::string &LineStr,
|
const std::string &Msg, const std::string &LineStr,
|
||||||
ArrayRef<std::pair<unsigned,unsigned> > Ranges, bool showline);
|
ArrayRef<std::pair<unsigned,unsigned> > Ranges, bool showline);
|
||||||
|
|
||||||
|
@ -178,6 +183,7 @@ public:
|
||||||
const std::string &getFilename() const { return Filename; }
|
const std::string &getFilename() const { return Filename; }
|
||||||
int getLineNo() const { return LineNo; }
|
int getLineNo() const { return LineNo; }
|
||||||
int getColumnNo() const { return ColumnNo; }
|
int getColumnNo() const { return ColumnNo; }
|
||||||
|
SourceMgr::DiagKind getKind() const { return Kind; }
|
||||||
const std::string &getMessage() const { return Message; }
|
const std::string &getMessage() const { return Message; }
|
||||||
const std::string &getLineContents() const { return LineContents; }
|
const std::string &getLineContents() const { return LineContents; }
|
||||||
bool getShowLine() const { return ShowLine; }
|
bool getShowLine() const { return ShowLine; }
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
bool LLLexer::Error(LocTy ErrorLoc, const Twine &Msg) const {
|
bool LLLexer::Error(LocTy ErrorLoc, const Twine &Msg) const {
|
||||||
ErrorInfo = SM.GetMessage(ErrorLoc, Msg, "error");
|
ErrorInfo = SM.GetMessage(ErrorLoc, SourceMgr::DK_Error, Msg);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ Module *llvm::ParseAssemblyFile(const std::string &Filename, SMDiagnostic &Err,
|
||||||
LLVMContext &Context) {
|
LLVMContext &Context) {
|
||||||
OwningPtr<MemoryBuffer> File;
|
OwningPtr<MemoryBuffer> File;
|
||||||
if (error_code ec = MemoryBuffer::getFileOrSTDIN(Filename.c_str(), File)) {
|
if (error_code ec = MemoryBuffer::getFileOrSTDIN(Filename.c_str(), File)) {
|
||||||
Err = SMDiagnostic(Filename,
|
Err = SMDiagnostic(Filename, SourceMgr::DK_Error,
|
||||||
"Could not open input file: " + ec.message());
|
"Could not open input file: " + ec.message());
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -171,10 +171,10 @@ private:
|
||||||
void HandleMacroExit();
|
void HandleMacroExit();
|
||||||
|
|
||||||
void PrintMacroInstantiations();
|
void PrintMacroInstantiations();
|
||||||
void PrintMessage(SMLoc Loc, const Twine &Msg, const char *Type,
|
void PrintMessage(SMLoc Loc, SourceMgr::DiagKind Kind, const Twine &Msg,
|
||||||
ArrayRef<SMRange> Ranges = ArrayRef<SMRange>(),
|
ArrayRef<SMRange> Ranges = ArrayRef<SMRange>(),
|
||||||
bool ShowLine = true) const {
|
bool ShowLine = true) const {
|
||||||
SrcMgr.PrintMessage(Loc, Msg, Type, Ranges, ShowLine);
|
SrcMgr.PrintMessage(Loc, Kind, Msg, Ranges, ShowLine);
|
||||||
}
|
}
|
||||||
static void DiagHandler(const SMDiagnostic &Diag, void *Context);
|
static void DiagHandler(const SMDiagnostic &Diag, void *Context);
|
||||||
|
|
||||||
|
@ -392,21 +392,21 @@ void AsmParser::PrintMacroInstantiations() {
|
||||||
// Print the active macro instantiation stack.
|
// Print the active macro instantiation stack.
|
||||||
for (std::vector<MacroInstantiation*>::const_reverse_iterator
|
for (std::vector<MacroInstantiation*>::const_reverse_iterator
|
||||||
it = ActiveMacros.rbegin(), ie = ActiveMacros.rend(); it != ie; ++it)
|
it = ActiveMacros.rbegin(), ie = ActiveMacros.rend(); it != ie; ++it)
|
||||||
PrintMessage((*it)->InstantiationLoc, "while in macro instantiation",
|
PrintMessage((*it)->InstantiationLoc, SourceMgr::DK_Note,
|
||||||
"note");
|
"while in macro instantiation");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AsmParser::Warning(SMLoc L, const Twine &Msg, ArrayRef<SMRange> Ranges) {
|
bool AsmParser::Warning(SMLoc L, const Twine &Msg, ArrayRef<SMRange> Ranges) {
|
||||||
if (FatalAssemblerWarnings)
|
if (FatalAssemblerWarnings)
|
||||||
return Error(L, Msg, Ranges);
|
return Error(L, Msg, Ranges);
|
||||||
PrintMessage(L, Msg, "warning", Ranges);
|
PrintMessage(L, SourceMgr::DK_Warning, Msg, Ranges);
|
||||||
PrintMacroInstantiations();
|
PrintMacroInstantiations();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AsmParser::Error(SMLoc L, const Twine &Msg, ArrayRef<SMRange> Ranges) {
|
bool AsmParser::Error(SMLoc L, const Twine &Msg, ArrayRef<SMRange> Ranges) {
|
||||||
HadError = true;
|
HadError = true;
|
||||||
PrintMessage(L, Msg, "error", Ranges);
|
PrintMessage(L, SourceMgr::DK_Error, Msg, Ranges);
|
||||||
PrintMacroInstantiations();
|
PrintMacroInstantiations();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -498,9 +498,9 @@ bool AsmParser::Run(bool NoInitialTextSection, bool NoFinalize) {
|
||||||
// FIXME: We would really like to refer back to where the symbol was
|
// FIXME: We would really like to refer back to where the symbol was
|
||||||
// first referenced for a source location. We need to add something
|
// first referenced for a source location. We need to add something
|
||||||
// to track that. Currently, we just point to the end of the file.
|
// to track that. Currently, we just point to the end of the file.
|
||||||
PrintMessage(getLexer().getLoc(), "assembler local symbol '" +
|
PrintMessage(getLexer().getLoc(), SourceMgr::DK_Error,
|
||||||
Sym->getName() + "' not defined", "error",
|
"assembler local symbol '" + Sym->getName() +
|
||||||
ArrayRef<SMRange>(), false);
|
"' not defined");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1203,7 +1203,7 @@ bool AsmParser::ParseStatement() {
|
||||||
}
|
}
|
||||||
OS << "]";
|
OS << "]";
|
||||||
|
|
||||||
PrintMessage(IDLoc, OS.str(), "note");
|
PrintMessage(IDLoc, SourceMgr::DK_Note, OS.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
// If parsing succeeded, match the instruction.
|
// If parsing succeeded, match the instruction.
|
||||||
|
@ -1305,7 +1305,8 @@ void AsmParser::DiagHandler(const SMDiagnostic &Diag, void *Context) {
|
||||||
|
|
||||||
SMDiagnostic NewDiag(*Diag.getSourceMgr(), Diag.getLoc(),
|
SMDiagnostic NewDiag(*Diag.getSourceMgr(), Diag.getLoc(),
|
||||||
Filename, LineNo, Diag.getColumnNo(),
|
Filename, LineNo, Diag.getColumnNo(),
|
||||||
Diag.getMessage(), Diag.getLineContents(),
|
Diag.getKind(), Diag.getMessage(),
|
||||||
|
Diag.getLineContents(),
|
||||||
Diag.getRanges(), Diag.getShowLine());
|
Diag.getRanges(), Diag.getShowLine());
|
||||||
|
|
||||||
NewDiag.print(0, OS);
|
NewDiag.print(0, OS);
|
||||||
|
|
|
@ -140,8 +140,8 @@ void SourceMgr::PrintIncludeStack(SMLoc IncludeLoc, raw_ostream &OS) const {
|
||||||
///
|
///
|
||||||
/// @param Type - If non-null, the kind of message (e.g., "error") which is
|
/// @param Type - If non-null, the kind of message (e.g., "error") which is
|
||||||
/// prefixed to the message.
|
/// prefixed to the message.
|
||||||
SMDiagnostic SourceMgr::GetMessage(SMLoc Loc, const Twine &Msg,
|
SMDiagnostic SourceMgr::GetMessage(SMLoc Loc, SourceMgr::DiagKind Kind,
|
||||||
const char *Type, ArrayRef<SMRange> Ranges,
|
const Twine &Msg, ArrayRef<SMRange> Ranges,
|
||||||
bool ShowLine) const {
|
bool ShowLine) const {
|
||||||
|
|
||||||
// First thing to do: find the current buffer containing the specified
|
// First thing to do: find the current buffer containing the specified
|
||||||
|
@ -164,12 +164,6 @@ SMDiagnostic SourceMgr::GetMessage(SMLoc Loc, const Twine &Msg,
|
||||||
++LineEnd;
|
++LineEnd;
|
||||||
std::string LineStr(LineStart, LineEnd);
|
std::string LineStr(LineStart, LineEnd);
|
||||||
|
|
||||||
std::string PrintedMsg;
|
|
||||||
raw_string_ostream OS(PrintedMsg);
|
|
||||||
if (Type)
|
|
||||||
OS << Type << ": ";
|
|
||||||
OS << Msg;
|
|
||||||
|
|
||||||
// Convert any ranges to column ranges that only intersect the line of the
|
// Convert any ranges to column ranges that only intersect the line of the
|
||||||
// location.
|
// location.
|
||||||
SmallVector<std::pair<unsigned, unsigned>, 4> ColRanges;
|
SmallVector<std::pair<unsigned, unsigned>, 4> ColRanges;
|
||||||
|
@ -194,16 +188,18 @@ SMDiagnostic SourceMgr::GetMessage(SMLoc Loc, const Twine &Msg,
|
||||||
|
|
||||||
return SMDiagnostic(*this, Loc,
|
return SMDiagnostic(*this, Loc,
|
||||||
CurMB->getBufferIdentifier(), FindLineNumber(Loc, CurBuf),
|
CurMB->getBufferIdentifier(), FindLineNumber(Loc, CurBuf),
|
||||||
Loc.getPointer()-LineStart, OS.str(),
|
Loc.getPointer()-LineStart, Kind, Msg.str(),
|
||||||
LineStr, ColRanges, ShowLine);
|
LineStr, ColRanges, ShowLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SourceMgr::PrintMessage(SMLoc Loc, const Twine &Msg,
|
void SourceMgr::PrintMessage(SMLoc Loc, SourceMgr::DiagKind Kind,
|
||||||
const char *Type, ArrayRef<SMRange> Ranges,
|
const Twine &Msg, ArrayRef<SMRange> Ranges,
|
||||||
bool ShowLine) const {
|
bool ShowLine) const {
|
||||||
|
SMDiagnostic Diagnostic = GetMessage(Loc, Kind, Msg, Ranges, ShowLine);
|
||||||
|
|
||||||
// Report the message with the diagnostic handler if present.
|
// Report the message with the diagnostic handler if present.
|
||||||
if (DiagHandler) {
|
if (DiagHandler) {
|
||||||
DiagHandler(GetMessage(Loc, Msg, Type, Ranges, ShowLine), DiagContext);
|
DiagHandler(Diagnostic, DiagContext);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -213,7 +209,7 @@ void SourceMgr::PrintMessage(SMLoc Loc, const Twine &Msg,
|
||||||
assert(CurBuf != -1 && "Invalid or unspecified location!");
|
assert(CurBuf != -1 && "Invalid or unspecified location!");
|
||||||
PrintIncludeStack(getBufferInfo(CurBuf).IncludeLoc, OS);
|
PrintIncludeStack(getBufferInfo(CurBuf).IncludeLoc, OS);
|
||||||
|
|
||||||
GetMessage(Loc, Msg, Type, Ranges, ShowLine).print(0, OS);
|
Diagnostic.print(0, OS);
|
||||||
}
|
}
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
@ -221,12 +217,15 @@ void SourceMgr::PrintMessage(SMLoc Loc, const Twine &Msg,
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
SMDiagnostic::SMDiagnostic(const SourceMgr &sm, SMLoc L, const std::string &FN,
|
SMDiagnostic::SMDiagnostic(const SourceMgr &sm, SMLoc L, const std::string &FN,
|
||||||
int Line, int Col, const std::string &Msg,
|
int Line, int Col, SourceMgr::DiagKind Kind,
|
||||||
|
const std::string &Msg,
|
||||||
const std::string &LineStr,
|
const std::string &LineStr,
|
||||||
ArrayRef<std::pair<unsigned,unsigned> > Ranges,
|
ArrayRef<std::pair<unsigned,unsigned> > Ranges,
|
||||||
bool showline)
|
bool showline)
|
||||||
: SM(&sm), Loc(L), Filename(FN), LineNo(Line), ColumnNo(Col), Message(Msg),
|
: SM(&sm), Loc(L), Filename(FN), LineNo(Line), ColumnNo(Col), Kind(Kind),
|
||||||
LineContents(LineStr), ShowLine(showline), Ranges(Ranges.vec()) {}
|
Message(Msg), LineContents(LineStr), ShowLine(showline),
|
||||||
|
Ranges(Ranges.vec()) {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void SMDiagnostic::print(const char *ProgName, raw_ostream &S) const {
|
void SMDiagnostic::print(const char *ProgName, raw_ostream &S) const {
|
||||||
|
@ -247,6 +246,13 @@ void SMDiagnostic::print(const char *ProgName, raw_ostream &S) const {
|
||||||
S << ": ";
|
S << ": ";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch (Kind) {
|
||||||
|
default: assert(0 && "Unknown diagnostic kind");
|
||||||
|
case SourceMgr::DK_Error: S << "error: "; break;
|
||||||
|
case SourceMgr::DK_Warning: S << "warning: "; break;
|
||||||
|
case SourceMgr::DK_Note: S << "note: "; break;
|
||||||
|
}
|
||||||
|
|
||||||
S << Message << '\n';
|
S << Message << '\n';
|
||||||
|
|
||||||
if (LineNo == -1 || ColumnNo == -1 || !ShowLine)
|
if (LineNo == -1 || ColumnNo == -1 || !ShowLine)
|
||||||
|
|
|
@ -21,11 +21,11 @@ namespace llvm {
|
||||||
SourceMgr SrcMgr;
|
SourceMgr SrcMgr;
|
||||||
|
|
||||||
void PrintError(SMLoc ErrorLoc, const Twine &Msg) {
|
void PrintError(SMLoc ErrorLoc, const Twine &Msg) {
|
||||||
SrcMgr.PrintMessage(ErrorLoc, Msg, "error");
|
SrcMgr.PrintMessage(ErrorLoc, SourceMgr::DK_Error, Msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrintError(const char *Loc, const Twine &Msg) {
|
void PrintError(const char *Loc, const Twine &Msg) {
|
||||||
SrcMgr.PrintMessage(SMLoc::getFromPointer(Loc), Msg, "error");
|
SrcMgr.PrintMessage(SMLoc::getFromPointer(Loc), SourceMgr::DK_Error, Msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrintError(const Twine &Msg) {
|
void PrintError(const Twine &Msg) {
|
||||||
|
|
|
@ -100,7 +100,7 @@ void LLVMContext::emitError(unsigned LocCookie, StringRef ErrorStr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we do have an error handler, we can report the error and keep going.
|
// If we do have an error handler, we can report the error and keep going.
|
||||||
SMDiagnostic Diag("", "error: " + ErrorStr.str());
|
SMDiagnostic Diag("", SourceMgr::DK_Error, ErrorStr.str());
|
||||||
|
|
||||||
pImpl->InlineAsmDiagHandler(Diag, pImpl->InlineAsmDiagContext, LocCookie);
|
pImpl->InlineAsmDiagHandler(Diag, pImpl->InlineAsmDiagContext, LocCookie);
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,14 +72,16 @@ static bool PrintInsts(const MCDisassembler &DisAsm,
|
||||||
switch (S) {
|
switch (S) {
|
||||||
case MCDisassembler::Fail:
|
case MCDisassembler::Fail:
|
||||||
SM.PrintMessage(SMLoc::getFromPointer(Bytes[Index].second),
|
SM.PrintMessage(SMLoc::getFromPointer(Bytes[Index].second),
|
||||||
"invalid instruction encoding", "warning");
|
SourceMgr::DK_Warning,
|
||||||
|
"invalid instruction encoding");
|
||||||
if (Size == 0)
|
if (Size == 0)
|
||||||
Size = 1; // skip illegible bytes
|
Size = 1; // skip illegible bytes
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MCDisassembler::SoftFail:
|
case MCDisassembler::SoftFail:
|
||||||
SM.PrintMessage(SMLoc::getFromPointer(Bytes[Index].second),
|
SM.PrintMessage(SMLoc::getFromPointer(Bytes[Index].second),
|
||||||
"potentially undefined instruction encoding", "warning");
|
SourceMgr::DK_Warning,
|
||||||
|
"potentially undefined instruction encoding");
|
||||||
// Fall through
|
// Fall through
|
||||||
|
|
||||||
case MCDisassembler::Success:
|
case MCDisassembler::Success:
|
||||||
|
@ -125,8 +127,8 @@ static bool ByteArrayFromString(ByteArrayTy &ByteArray,
|
||||||
unsigned ByteVal;
|
unsigned ByteVal;
|
||||||
if (Value.getAsInteger(0, ByteVal) || ByteVal > 255) {
|
if (Value.getAsInteger(0, ByteVal) || ByteVal > 255) {
|
||||||
// If we have an error, print it and skip to the end of line.
|
// If we have an error, print it and skip to the end of line.
|
||||||
SM.PrintMessage(SMLoc::getFromPointer(Value.data()),
|
SM.PrintMessage(SMLoc::getFromPointer(Value.data()), SourceMgr::DK_Error,
|
||||||
"invalid input token", "error");
|
"invalid input token");
|
||||||
Str = Str.substr(Str.find('\n'));
|
Str = Str.substr(Str.find('\n'));
|
||||||
ByteArray.clear();
|
ByteArray.clear();
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -267,7 +267,8 @@ static int AsLexInput(const char *ProgName) {
|
||||||
|
|
||||||
switch (Tok.getKind()) {
|
switch (Tok.getKind()) {
|
||||||
default:
|
default:
|
||||||
SrcMgr.PrintMessage(Lexer.getLoc(), "unknown token", "warning");
|
SrcMgr.PrintMessage(Lexer.getLoc(), SourceMgr::DK_Warning,
|
||||||
|
"unknown token");
|
||||||
Error = true;
|
Error = true;
|
||||||
break;
|
break;
|
||||||
case AsmToken::Error:
|
case AsmToken::Error:
|
||||||
|
|
|
@ -117,8 +117,9 @@ bool Pattern::ParsePattern(StringRef PatternStr, SourceMgr &SM) {
|
||||||
|
|
||||||
// Check that there is something on the line.
|
// Check that there is something on the line.
|
||||||
if (PatternStr.empty()) {
|
if (PatternStr.empty()) {
|
||||||
SM.PrintMessage(PatternLoc, "found empty check string with prefix '" +
|
SM.PrintMessage(PatternLoc, SourceMgr::DK_Error,
|
||||||
CheckPrefix+":'", "error");
|
"found empty check string with prefix '" +
|
||||||
|
CheckPrefix+":'");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,7 +145,8 @@ bool Pattern::ParsePattern(StringRef PatternStr, SourceMgr &SM) {
|
||||||
size_t End = PatternStr.find("}}");
|
size_t End = PatternStr.find("}}");
|
||||||
if (End == StringRef::npos) {
|
if (End == StringRef::npos) {
|
||||||
SM.PrintMessage(SMLoc::getFromPointer(PatternStr.data()),
|
SM.PrintMessage(SMLoc::getFromPointer(PatternStr.data()),
|
||||||
"found start of regex string with no end '}}'","error");
|
SourceMgr::DK_Error,
|
||||||
|
"found start of regex string with no end '}}'");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,7 +175,8 @@ bool Pattern::ParsePattern(StringRef PatternStr, SourceMgr &SM) {
|
||||||
size_t End = PatternStr.find("]]");
|
size_t End = PatternStr.find("]]");
|
||||||
if (End == StringRef::npos) {
|
if (End == StringRef::npos) {
|
||||||
SM.PrintMessage(SMLoc::getFromPointer(PatternStr.data()),
|
SM.PrintMessage(SMLoc::getFromPointer(PatternStr.data()),
|
||||||
"invalid named regex reference, no ]] found", "error");
|
SourceMgr::DK_Error,
|
||||||
|
"invalid named regex reference, no ]] found");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,8 +188,8 @@ bool Pattern::ParsePattern(StringRef PatternStr, SourceMgr &SM) {
|
||||||
StringRef Name = MatchStr.substr(0, NameEnd);
|
StringRef Name = MatchStr.substr(0, NameEnd);
|
||||||
|
|
||||||
if (Name.empty()) {
|
if (Name.empty()) {
|
||||||
SM.PrintMessage(SMLoc::getFromPointer(Name.data()),
|
SM.PrintMessage(SMLoc::getFromPointer(Name.data()), SourceMgr::DK_Error,
|
||||||
"invalid name in named regex: empty name", "error");
|
"invalid name in named regex: empty name");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,14 +197,14 @@ bool Pattern::ParsePattern(StringRef PatternStr, SourceMgr &SM) {
|
||||||
for (unsigned i = 0, e = Name.size(); i != e; ++i)
|
for (unsigned i = 0, e = Name.size(); i != e; ++i)
|
||||||
if (Name[i] != '_' && !isalnum(Name[i])) {
|
if (Name[i] != '_' && !isalnum(Name[i])) {
|
||||||
SM.PrintMessage(SMLoc::getFromPointer(Name.data()+i),
|
SM.PrintMessage(SMLoc::getFromPointer(Name.data()+i),
|
||||||
"invalid name in named regex", "error");
|
SourceMgr::DK_Error, "invalid name in named regex");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Name can't start with a digit.
|
// Name can't start with a digit.
|
||||||
if (isdigit(Name[0])) {
|
if (isdigit(Name[0])) {
|
||||||
SM.PrintMessage(SMLoc::getFromPointer(Name.data()),
|
SM.PrintMessage(SMLoc::getFromPointer(Name.data()), SourceMgr::DK_Error,
|
||||||
"invalid name in named regex", "error");
|
"invalid name in named regex");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -266,8 +269,8 @@ bool Pattern::AddRegExToRegEx(StringRef RegexStr, unsigned &CurParen,
|
||||||
Regex R(RegexStr);
|
Regex R(RegexStr);
|
||||||
std::string Error;
|
std::string Error;
|
||||||
if (!R.isValid(Error)) {
|
if (!R.isValid(Error)) {
|
||||||
SM.PrintMessage(SMLoc::getFromPointer(RegexStr.data()),
|
SM.PrintMessage(SMLoc::getFromPointer(RegexStr.data()), SourceMgr::DK_Error,
|
||||||
"invalid regex: " + Error, "error");
|
"invalid regex: " + Error);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -383,8 +386,8 @@ void Pattern::PrintFailureInfo(const SourceMgr &SM, StringRef Buffer,
|
||||||
OS.write_escaped(it->second) << "\"";
|
OS.write_escaped(it->second) << "\"";
|
||||||
}
|
}
|
||||||
|
|
||||||
SM.PrintMessage(SMLoc::getFromPointer(Buffer.data()), OS.str(), "note",
|
SM.PrintMessage(SMLoc::getFromPointer(Buffer.data()), SourceMgr::DK_Note,
|
||||||
ArrayRef<SMRange>(), /*ShowLine=*/false);
|
OS.str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -422,7 +425,7 @@ void Pattern::PrintFailureInfo(const SourceMgr &SM, StringRef Buffer,
|
||||||
// line.
|
// line.
|
||||||
if (Best && Best != StringRef::npos && BestQuality < 50) {
|
if (Best && Best != StringRef::npos && BestQuality < 50) {
|
||||||
SM.PrintMessage(SMLoc::getFromPointer(Buffer.data() + Best),
|
SM.PrintMessage(SMLoc::getFromPointer(Buffer.data() + Best),
|
||||||
"possible intended match here", "note");
|
SourceMgr::DK_Note, "possible intended match here");
|
||||||
|
|
||||||
// FIXME: If we wanted to be really friendly we would show why the match
|
// FIXME: If we wanted to be really friendly we would show why the match
|
||||||
// failed, as it can be hard to spot simple one character differences.
|
// failed, as it can be hard to spot simple one character differences.
|
||||||
|
@ -566,8 +569,9 @@ static bool ReadCheckFile(SourceMgr &SM,
|
||||||
// Verify that CHECK-NEXT lines have at least one CHECK line before them.
|
// Verify that CHECK-NEXT lines have at least one CHECK line before them.
|
||||||
if (IsCheckNext && CheckStrings.empty()) {
|
if (IsCheckNext && CheckStrings.empty()) {
|
||||||
SM.PrintMessage(SMLoc::getFromPointer(CheckPrefixStart),
|
SM.PrintMessage(SMLoc::getFromPointer(CheckPrefixStart),
|
||||||
|
SourceMgr::DK_Error,
|
||||||
"found '"+CheckPrefix+"-NEXT:' without previous '"+
|
"found '"+CheckPrefix+"-NEXT:' without previous '"+
|
||||||
CheckPrefix+ ": line", "error");
|
CheckPrefix+ ": line");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -607,15 +611,15 @@ static void PrintCheckFailed(const SourceMgr &SM, const CheckString &CheckStr,
|
||||||
StringRef Buffer,
|
StringRef Buffer,
|
||||||
StringMap<StringRef> &VariableTable) {
|
StringMap<StringRef> &VariableTable) {
|
||||||
// Otherwise, we have an error, emit an error message.
|
// Otherwise, we have an error, emit an error message.
|
||||||
SM.PrintMessage(CheckStr.Loc, "expected string not found in input",
|
SM.PrintMessage(CheckStr.Loc, SourceMgr::DK_Error,
|
||||||
"error");
|
"expected string not found in input");
|
||||||
|
|
||||||
// Print the "scanning from here" line. If the current position is at the
|
// Print the "scanning from here" line. If the current position is at the
|
||||||
// end of a line, advance to the start of the next line.
|
// end of a line, advance to the start of the next line.
|
||||||
Buffer = Buffer.substr(Buffer.find_first_not_of(" \t\n\r"));
|
Buffer = Buffer.substr(Buffer.find_first_not_of(" \t\n\r"));
|
||||||
|
|
||||||
SM.PrintMessage(SMLoc::getFromPointer(Buffer.data()), "scanning from here",
|
SM.PrintMessage(SMLoc::getFromPointer(Buffer.data()), SourceMgr::DK_Note,
|
||||||
"note");
|
"scanning from here");
|
||||||
|
|
||||||
// Allow the pattern to print additional information if desired.
|
// Allow the pattern to print additional information if desired.
|
||||||
CheckStr.Pat.PrintFailureInfo(SM, Buffer, VariableTable);
|
CheckStr.Pat.PrintFailureInfo(SM, Buffer, VariableTable);
|
||||||
|
@ -710,25 +714,22 @@ int main(int argc, char **argv) {
|
||||||
|
|
||||||
unsigned NumNewLines = CountNumNewlinesBetween(SkippedRegion);
|
unsigned NumNewLines = CountNumNewlinesBetween(SkippedRegion);
|
||||||
if (NumNewLines == 0) {
|
if (NumNewLines == 0) {
|
||||||
SM.PrintMessage(CheckStr.Loc,
|
SM.PrintMessage(CheckStr.Loc, SourceMgr::DK_Error,
|
||||||
CheckPrefix+"-NEXT: is on the same line as previous match",
|
CheckPrefix+"-NEXT: is on the same line as previous match");
|
||||||
"error");
|
|
||||||
SM.PrintMessage(SMLoc::getFromPointer(Buffer.data()),
|
SM.PrintMessage(SMLoc::getFromPointer(Buffer.data()),
|
||||||
"'next' match was here", "note");
|
SourceMgr::DK_Note, "'next' match was here");
|
||||||
SM.PrintMessage(SMLoc::getFromPointer(LastMatch),
|
SM.PrintMessage(SMLoc::getFromPointer(LastMatch), SourceMgr::DK_Note,
|
||||||
"previous match was here", "note");
|
"previous match was here");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NumNewLines != 1) {
|
if (NumNewLines != 1) {
|
||||||
SM.PrintMessage(CheckStr.Loc,
|
SM.PrintMessage(CheckStr.Loc, SourceMgr::DK_Error, CheckPrefix+
|
||||||
CheckPrefix+
|
"-NEXT: is not on the line after the previous match");
|
||||||
"-NEXT: is not on the line after the previous match",
|
|
||||||
"error");
|
|
||||||
SM.PrintMessage(SMLoc::getFromPointer(Buffer.data()),
|
SM.PrintMessage(SMLoc::getFromPointer(Buffer.data()),
|
||||||
"'next' match was here", "note");
|
SourceMgr::DK_Note, "'next' match was here");
|
||||||
SM.PrintMessage(SMLoc::getFromPointer(LastMatch),
|
SM.PrintMessage(SMLoc::getFromPointer(LastMatch), SourceMgr::DK_Note,
|
||||||
"previous match was here", "note");
|
"previous match was here");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -743,10 +744,10 @@ int main(int argc, char **argv) {
|
||||||
VariableTable);
|
VariableTable);
|
||||||
if (Pos == StringRef::npos) continue;
|
if (Pos == StringRef::npos) continue;
|
||||||
|
|
||||||
SM.PrintMessage(SMLoc::getFromPointer(LastMatch+Pos),
|
SM.PrintMessage(SMLoc::getFromPointer(LastMatch+Pos), SourceMgr::DK_Error,
|
||||||
CheckPrefix+"-NOT: string occurred!", "error");
|
CheckPrefix+"-NOT: string occurred!");
|
||||||
SM.PrintMessage(CheckStr.NotStrings[ChunkNo].first,
|
SM.PrintMessage(CheckStr.NotStrings[ChunkNo].first, SourceMgr::DK_Note,
|
||||||
CheckPrefix+"-NOT: pattern specified here", "note");
|
CheckPrefix+"-NOT: pattern specified here");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue