X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FTableGen%2FError.cpp;h=928b1203cd8f108ca0b4b180f56bf1f2fdebc7b9;hb=2c6f997290f589b80da903e33718175666557dd7;hp=369e3c1623e39053b158e56e370232f224277030;hpb=97c02bf2409bccdb43c3822c438e3ff977d8514e;p=oota-llvm.git diff --git a/lib/TableGen/Error.cpp b/lib/TableGen/Error.cpp index 369e3c1623e..928b1203cd8 100644 --- a/lib/TableGen/Error.cpp +++ b/lib/TableGen/Error.cpp @@ -15,13 +15,31 @@ #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 PrintWarning(SMLoc WarningLoc, const Twine &Msg) { - SrcMgr.PrintMessage(WarningLoc, SourceMgr::DK_Warning, 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) { @@ -29,15 +47,11 @@ void PrintWarning(const char *Loc, const Twine &Msg) { } void PrintWarning(const Twine &Msg) { - errs() << "error:" << Msg << "\n"; + errs() << "warning:" << Msg << "\n"; } -void PrintWarning(const TGError &Warning) { - PrintWarning(Warning.getLoc(), Warning.getMessage()); -} - -void PrintError(SMLoc ErrorLoc, const Twine &Msg) { - SrcMgr.PrintMessage(ErrorLoc, SourceMgr::DK_Error, Msg); +void PrintError(ArrayRef ErrorLoc, const Twine &Msg) { + PrintMessage(ErrorLoc, SourceMgr::DK_Error, Msg); } void PrintError(const char *Loc, const Twine &Msg) { @@ -48,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 std::string &Msg) { + PrintError(Twine(Msg)); + std::exit(1); +} + +void PrintFatalError(ArrayRef ErrorLoc, const std::string &Msg) { + PrintError(ErrorLoc, Msg); + std::exit(1); } } // end namespace llvm