LLVM  8.0.0svn
Error.cpp
Go to the documentation of this file.
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/Signals.h"
18 #include "llvm/Support/WithColor.h"
20 #include <cstdlib>
21 
22 namespace llvm {
23 
25 unsigned ErrorsPrinted = 0;
26 
28  const Twine &Msg) {
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)
32  ++ErrorsPrinted;
33 
34  SMLoc NullLoc;
35  if (Loc.empty())
36  Loc = NullLoc;
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");
41 }
42 
43 void PrintNote(ArrayRef<SMLoc> NoteLoc, const Twine &Msg) {
44  PrintMessage(NoteLoc, SourceMgr::DK_Note, Msg);
45 }
46 
47 void PrintWarning(ArrayRef<SMLoc> WarningLoc, const Twine &Msg) {
48  PrintMessage(WarningLoc, SourceMgr::DK_Warning, Msg);
49 }
50 
51 void PrintWarning(const char *Loc, const Twine &Msg) {
53 }
54 
55 void PrintWarning(const Twine &Msg) { WithColor::warning() << Msg << "\n"; }
56 
57 void PrintError(ArrayRef<SMLoc> ErrorLoc, const Twine &Msg) {
58  PrintMessage(ErrorLoc, SourceMgr::DK_Error, Msg);
59 }
60 
61 void PrintError(const char *Loc, const Twine &Msg) {
63 }
64 
65 void PrintError(const Twine &Msg) { WithColor::error() << Msg << "\n"; }
66 
67 void PrintFatalError(const Twine &Msg) {
68  PrintError(Msg);
69  // The following call runs the file cleanup handlers.
71  std::exit(1);
72 }
73 
74 void PrintFatalError(ArrayRef<SMLoc> ErrorLoc, const Twine &Msg) {
75  PrintError(ErrorLoc, Msg);
76  // The following call runs the file cleanup handlers.
78  std::exit(1);
79 }
80 
81 } // end namespace llvm
const T & front() const
front - Get the first element.
Definition: ArrayRef.h:152
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
static raw_ostream & error()
Convenience method for printing "error: " to stderr.
Definition: WithColor.cpp:63
SourceMgr SrcMgr
Definition: Error.cpp:24
static raw_ostream & warning()
Convenience method for printing "warning: " to stderr.
Definition: WithColor.cpp:65
unsigned ErrorsPrinted
Definition: Error.cpp:25
void PrintMessage(raw_ostream &OS, SMLoc Loc, DiagKind Kind, const Twine &Msg, ArrayRef< SMRange > Ranges=None, ArrayRef< SMFixIt > FixIts=None, bool ShowColors=true) const
Emit a message about the specified location with the specified string.
Definition: SourceMgr.cpp:247
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
static void PrintMessage(ArrayRef< SMLoc > Loc, SourceMgr::DiagKind Kind, const Twine &Msg)
Definition: Error.cpp:27
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:149
void RunInterruptHandlers()
This function runs all the registered interrupt handlers, including the removal of files registered b...
void PrintWarning(ArrayRef< SMLoc > WarningLoc, const Twine &Msg)
Definition: Error.cpp:47
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling...
Definition: SourceMgr.h:42
LLVM_ATTRIBUTE_NORETURN void PrintFatalError(const Twine &Msg)
Definition: Error.cpp:67
static SMLoc getFromPointer(const char *Ptr)
Definition: SMLoc.h:37
const unsigned Kind
Represents a location in source code.
Definition: SMLoc.h:24
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:144
void PrintNote(ArrayRef< SMLoc > NoteLoc, const Twine &Msg)
Definition: Error.cpp:43
void PrintError(ArrayRef< SMLoc > ErrorLoc, const Twine &Msg)
Definition: Error.cpp:57