]> git.proxmox.com Git - rustc.git/blame - src/llvm/lib/TableGen/Error.cpp
Imported Upstream version 1.0.0+dfsg1
[rustc.git] / src / llvm / lib / TableGen / Error.cpp
CommitLineData
223e47cc
LB
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"
970d7e83 18#include <cstdlib>
223e47cc
LB
19
20namespace llvm {
21
22SourceMgr SrcMgr;
1a4d82fc 23unsigned ErrorsPrinted = 0;
223e47cc
LB
24
25static void PrintMessage(ArrayRef<SMLoc> Loc, SourceMgr::DiagKind Kind,
26 const Twine &Msg) {
1a4d82fc
JJ
27 // Count the total number of errors printed.
28 // This is used to exit with an error code if there were any errors.
29 if (Kind == SourceMgr::DK_Error)
30 ++ErrorsPrinted;
31
223e47cc
LB
32 SMLoc NullLoc;
33 if (Loc.empty())
34 Loc = NullLoc;
35 SrcMgr.PrintMessage(Loc.front(), Kind, Msg);
36 for (unsigned i = 1; i < Loc.size(); ++i)
37 SrcMgr.PrintMessage(Loc[i], SourceMgr::DK_Note,
38 "instantiated from multiclass");
39}
40
41void PrintWarning(ArrayRef<SMLoc> WarningLoc, const Twine &Msg) {
42 PrintMessage(WarningLoc, SourceMgr::DK_Warning, Msg);
43}
44
45void PrintWarning(const char *Loc, const Twine &Msg) {
46 SrcMgr.PrintMessage(SMLoc::getFromPointer(Loc), SourceMgr::DK_Warning, Msg);
47}
48
49void PrintWarning(const Twine &Msg) {
50 errs() << "warning:" << Msg << "\n";
51}
52
223e47cc
LB
53void PrintError(ArrayRef<SMLoc> ErrorLoc, const Twine &Msg) {
54 PrintMessage(ErrorLoc, SourceMgr::DK_Error, Msg);
55}
56
57void PrintError(const char *Loc, const Twine &Msg) {
58 SrcMgr.PrintMessage(SMLoc::getFromPointer(Loc), SourceMgr::DK_Error, Msg);
59}
60
61void PrintError(const Twine &Msg) {
62 errs() << "error:" << Msg << "\n";
63}
64
1a4d82fc
JJ
65void PrintFatalError(const Twine &Msg) {
66 PrintError(Msg);
970d7e83
LB
67 std::exit(1);
68}
69
1a4d82fc 70void PrintFatalError(ArrayRef<SMLoc> ErrorLoc, const Twine &Msg) {
970d7e83
LB
71 PrintError(ErrorLoc, Msg);
72 std::exit(1);
223e47cc
LB
73}
74
75} // end namespace llvm