1 //===- Error.cpp - tblgen error handling helper routines --------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains error handling helper routines to pretty-print diagnostic
11 // messages from tblgen.
13 //===----------------------------------------------------------------------===//
15 #include "llvm/TableGen/Error.h"
16 #include "llvm/ADT/Twine.h"
17 #include "llvm/Support/Signals.h"
18 #include "llvm/Support/WithColor.h"
19 #include "llvm/Support/raw_ostream.h"
25 unsigned ErrorsPrinted
= 0;
27 static void PrintMessage(ArrayRef
<SMLoc
> Loc
, SourceMgr::DiagKind Kind
,
29 // Count the total number of errors printed.
30 // This is used to exit with an error code if there were any errors.
31 if (Kind
== SourceMgr::DK_Error
)
37 SrcMgr
.PrintMessage(Loc
.front(), Kind
, Msg
);
38 for (unsigned i
= 1; i
< Loc
.size(); ++i
)
39 SrcMgr
.PrintMessage(Loc
[i
], SourceMgr::DK_Note
,
40 "instantiated from multiclass");
43 void PrintNote(ArrayRef
<SMLoc
> NoteLoc
, const Twine
&Msg
) {
44 PrintMessage(NoteLoc
, SourceMgr::DK_Note
, Msg
);
47 void PrintWarning(ArrayRef
<SMLoc
> WarningLoc
, const Twine
&Msg
) {
48 PrintMessage(WarningLoc
, SourceMgr::DK_Warning
, Msg
);
51 void PrintWarning(const char *Loc
, const Twine
&Msg
) {
52 SrcMgr
.PrintMessage(SMLoc::getFromPointer(Loc
), SourceMgr::DK_Warning
, Msg
);
55 void PrintWarning(const Twine
&Msg
) { WithColor::warning() << Msg
<< "\n"; }
57 void PrintError(ArrayRef
<SMLoc
> ErrorLoc
, const Twine
&Msg
) {
58 PrintMessage(ErrorLoc
, SourceMgr::DK_Error
, Msg
);
61 void PrintError(const char *Loc
, const Twine
&Msg
) {
62 SrcMgr
.PrintMessage(SMLoc::getFromPointer(Loc
), SourceMgr::DK_Error
, Msg
);
65 void PrintError(const Twine
&Msg
) { WithColor::error() << Msg
<< "\n"; }
67 void PrintFatalError(const Twine
&Msg
) {
69 // The following call runs the file cleanup handlers.
70 sys::RunInterruptHandlers();
74 void PrintFatalError(ArrayRef
<SMLoc
> ErrorLoc
, const Twine
&Msg
) {
75 PrintError(ErrorLoc
, Msg
);
76 // The following call runs the file cleanup handlers.
77 sys::RunInterruptHandlers();
81 } // end namespace llvm