Jim Grosbach | 0b6a44a | 2011-06-21 22:55:50 +0000 | [diff] [blame] | 1 | //===- Error.cpp - tblgen error handling helper routines --------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file contains error handling helper routines to pretty-print diagnostic |
| 11 | // messages from tblgen. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Peter Collingbourne | 7c78888 | 2011-10-01 16:41:13 +0000 | [diff] [blame] | 15 | #include "llvm/TableGen/Error.h" |
Jim Grosbach | 0b6a44a | 2011-06-21 22:55:50 +0000 | [diff] [blame] | 16 | #include "llvm/ADT/Twine.h" |
| 17 | #include "llvm/Support/raw_ostream.h" |
| 18 | |
Joerg Sonnenberger | 0eafc7f | 2012-10-25 16:35:18 +0000 | [diff] [blame] | 19 | #include <cstdlib> |
| 20 | |
Jim Grosbach | 0b6a44a | 2011-06-21 22:55:50 +0000 | [diff] [blame] | 21 | namespace llvm { |
| 22 | |
| 23 | SourceMgr SrcMgr; |
| 24 | |
Jakob Stoklund Olesen | 376a8a7 | 2012-08-22 23:33:58 +0000 | [diff] [blame] | 25 | static void PrintMessage(ArrayRef<SMLoc> Loc, SourceMgr::DiagKind Kind, |
| 26 | const Twine &Msg) { |
| 27 | SMLoc NullLoc; |
| 28 | if (Loc.empty()) |
| 29 | Loc = NullLoc; |
| 30 | SrcMgr.PrintMessage(Loc.front(), Kind, Msg); |
| 31 | for (unsigned i = 1; i < Loc.size(); ++i) |
| 32 | SrcMgr.PrintMessage(Loc[i], SourceMgr::DK_Note, |
| 33 | "instantiated from multiclass"); |
| 34 | } |
| 35 | |
| 36 | void PrintWarning(ArrayRef<SMLoc> WarningLoc, const Twine &Msg) { |
| 37 | PrintMessage(WarningLoc, SourceMgr::DK_Warning, Msg); |
Jim Grosbach | 97c02bf | 2012-04-18 17:46:31 +0000 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | void PrintWarning(const char *Loc, const Twine &Msg) { |
| 41 | SrcMgr.PrintMessage(SMLoc::getFromPointer(Loc), SourceMgr::DK_Warning, Msg); |
| 42 | } |
| 43 | |
| 44 | void PrintWarning(const Twine &Msg) { |
Jim Grosbach | 28b810e | 2012-04-18 18:09:53 +0000 | [diff] [blame] | 45 | errs() << "warning:" << Msg << "\n"; |
Jim Grosbach | 97c02bf | 2012-04-18 17:46:31 +0000 | [diff] [blame] | 46 | } |
| 47 | |
Jakob Stoklund Olesen | 376a8a7 | 2012-08-22 23:33:58 +0000 | [diff] [blame] | 48 | void PrintError(ArrayRef<SMLoc> ErrorLoc, const Twine &Msg) { |
| 49 | PrintMessage(ErrorLoc, SourceMgr::DK_Error, Msg); |
Jim Grosbach | 0b6a44a | 2011-06-21 22:55:50 +0000 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | void PrintError(const char *Loc, const Twine &Msg) { |
Chris Lattner | 3f2d5f6 | 2011-10-16 05:43:57 +0000 | [diff] [blame] | 53 | SrcMgr.PrintMessage(SMLoc::getFromPointer(Loc), SourceMgr::DK_Error, Msg); |
Jim Grosbach | 0b6a44a | 2011-06-21 22:55:50 +0000 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | void PrintError(const Twine &Msg) { |
| 57 | errs() << "error:" << Msg << "\n"; |
| 58 | } |
| 59 | |
Joerg Sonnenberger | 0eafc7f | 2012-10-25 16:35:18 +0000 | [diff] [blame] | 60 | void PrintFatalError(const std::string &Msg) { |
| 61 | PrintError(Twine(Msg)); |
| 62 | std::exit(1); |
| 63 | } |
| 64 | |
| 65 | void PrintFatalError(ArrayRef<SMLoc> ErrorLoc, const std::string &Msg) { |
| 66 | PrintError(ErrorLoc, Msg); |
| 67 | std::exit(1); |
| 68 | } |
| 69 | |
Jim Grosbach | 0b6a44a | 2011-06-21 22:55:50 +0000 | [diff] [blame] | 70 | } // end namespace llvm |