Enable stack coloring.
[oota-llvm.git] / lib / TableGen / Error.cpp
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
15 #include "llvm/TableGen/Error.h"
16 #include "llvm/ADT/Twine.h"
17 #include "llvm/Support/raw_ostream.h"
18
19 namespace llvm {
20
21 SourceMgr SrcMgr;
22
23 static void PrintMessage(ArrayRef<SMLoc> Loc, SourceMgr::DiagKind Kind,
24                          const Twine &Msg) {
25   SMLoc NullLoc;
26   if (Loc.empty())
27     Loc = NullLoc;
28   SrcMgr.PrintMessage(Loc.front(), Kind, Msg);
29   for (unsigned i = 1; i < Loc.size(); ++i)
30     SrcMgr.PrintMessage(Loc[i], SourceMgr::DK_Note,
31                         "instantiated from multiclass");
32 }
33
34 void PrintWarning(ArrayRef<SMLoc> WarningLoc, const Twine &Msg) {
35   PrintMessage(WarningLoc, SourceMgr::DK_Warning, Msg);
36 }
37
38 void PrintWarning(const char *Loc, const Twine &Msg) {
39   SrcMgr.PrintMessage(SMLoc::getFromPointer(Loc), SourceMgr::DK_Warning, Msg);
40 }
41
42 void PrintWarning(const Twine &Msg) {
43   errs() << "warning:" << Msg << "\n";
44 }
45
46 void PrintWarning(const TGError &Warning) {
47   PrintWarning(Warning.getLoc(), Warning.getMessage());
48 }
49
50 void PrintError(ArrayRef<SMLoc> ErrorLoc, const Twine &Msg) {
51   PrintMessage(ErrorLoc, SourceMgr::DK_Error, Msg);
52 }
53
54 void PrintError(const char *Loc, const Twine &Msg) {
55   SrcMgr.PrintMessage(SMLoc::getFromPointer(Loc), SourceMgr::DK_Error, Msg);
56 }
57
58 void PrintError(const Twine &Msg) {
59   errs() << "error:" << Msg << "\n";
60 }
61
62 void PrintError(const TGError &Error) {
63   PrintError(Error.getLoc(), Error.getMessage());
64 }
65
66 } // end namespace llvm