X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FTableGen%2FError.cpp;h=8d9ae20dd52eda1a6dc0b0c24a1f0b870553f0b5;hb=12af22e8cc217827cf4f118b0f5e4ebbda9925ae;hp=5071ee77ac436e6c8928ab1895be0d4b76db184a;hpb=3f2d5f60b31fd057c10f77b2e607b23a8c94f6d3;p=oota-llvm.git diff --git a/lib/TableGen/Error.cpp b/lib/TableGen/Error.cpp index 5071ee77ac4..8d9ae20dd52 100644 --- a/lib/TableGen/Error.cpp +++ b/lib/TableGen/Error.cpp @@ -15,13 +15,43 @@ #include "llvm/TableGen/Error.h" #include "llvm/ADT/Twine.h" #include "llvm/Support/raw_ostream.h" +#include namespace llvm { SourceMgr SrcMgr; +unsigned ErrorsPrinted = 0; -void PrintError(SMLoc ErrorLoc, const Twine &Msg) { - SrcMgr.PrintMessage(ErrorLoc, SourceMgr::DK_Error, Msg); +static void PrintMessage(ArrayRef Loc, SourceMgr::DiagKind Kind, + const Twine &Msg) { + // Count the total number of errors printed. + // This is used to exit with an error code if there were any errors. + if (Kind == SourceMgr::DK_Error) + ++ErrorsPrinted; + + SMLoc NullLoc; + if (Loc.empty()) + Loc = NullLoc; + SrcMgr.PrintMessage(Loc.front(), Kind, Msg); + for (unsigned i = 1; i < Loc.size(); ++i) + SrcMgr.PrintMessage(Loc[i], SourceMgr::DK_Note, + "instantiated from multiclass"); +} + +void PrintWarning(ArrayRef WarningLoc, const Twine &Msg) { + PrintMessage(WarningLoc, SourceMgr::DK_Warning, Msg); +} + +void PrintWarning(const char *Loc, const Twine &Msg) { + SrcMgr.PrintMessage(SMLoc::getFromPointer(Loc), SourceMgr::DK_Warning, Msg); +} + +void PrintWarning(const Twine &Msg) { + errs() << "warning:" << Msg << "\n"; +} + +void PrintError(ArrayRef ErrorLoc, const Twine &Msg) { + PrintMessage(ErrorLoc, SourceMgr::DK_Error, Msg); } void PrintError(const char *Loc, const Twine &Msg) { @@ -32,8 +62,14 @@ void PrintError(const Twine &Msg) { errs() << "error:" << Msg << "\n"; } -void PrintError(const TGError &Error) { - PrintError(Error.getLoc(), Error.getMessage()); +void PrintFatalError(const Twine &Msg) { + PrintError(Msg); + std::exit(1); +} + +void PrintFatalError(ArrayRef ErrorLoc, const Twine &Msg) { + PrintError(ErrorLoc, Msg); + std::exit(1); } } // end namespace llvm