LLVM  4.0.0
TableGen/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"
19 #include <cstdlib>
20 
21 namespace llvm {
22 
24 unsigned ErrorsPrinted = 0;
25 
27  const Twine &Msg) {
28  // Count the total number of errors printed.
29  // This is used to exit with an error code if there were any errors.
30  if (Kind == SourceMgr::DK_Error)
31  ++ErrorsPrinted;
32 
33  SMLoc NullLoc;
34  if (Loc.empty())
35  Loc = NullLoc;
36  SrcMgr.PrintMessage(Loc.front(), Kind, Msg);
37  for (unsigned i = 1; i < Loc.size(); ++i)
39  "instantiated from multiclass");
40 }
41 
42 void PrintWarning(ArrayRef<SMLoc> WarningLoc, const Twine &Msg) {
43  PrintMessage(WarningLoc, SourceMgr::DK_Warning, Msg);
44 }
45 
46 void PrintWarning(const char *Loc, const Twine &Msg) {
48 }
49 
50 void PrintWarning(const Twine &Msg) {
51  errs() << "warning:" << Msg << "\n";
52 }
53 
54 void PrintError(ArrayRef<SMLoc> ErrorLoc, const Twine &Msg) {
55  PrintMessage(ErrorLoc, SourceMgr::DK_Error, Msg);
56 }
57 
58 void PrintError(const char *Loc, const Twine &Msg) {
60 }
61 
62 void PrintError(const Twine &Msg) {
63  errs() << "error:" << Msg << "\n";
64 }
65 
66 void PrintFatalError(const Twine &Msg) {
67  PrintError(Msg);
68  // The following call runs the file cleanup handlers.
70  std::exit(1);
71 }
72 
73 void PrintFatalError(ArrayRef<SMLoc> ErrorLoc, const Twine &Msg) {
74  PrintError(ErrorLoc, Msg);
75  // The following call runs the file cleanup handlers.
77  std::exit(1);
78 }
79 
80 } // end namespace llvm
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
size_t i
const T & front() const
front - Get the first element.
Definition: ArrayRef.h:144
SourceMgr SrcMgr
unsigned ErrorsPrinted
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)
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:141
void RunInterruptHandlers()
This function runs all the registered interrupt handlers, including the removal of files registered b...
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:136
void PrintWarning(ArrayRef< SMLoc > WarningLoc, const Twine &Msg)
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling...
Definition: SourceMgr.h:35
LLVM_ATTRIBUTE_NORETURN void PrintFatalError(const Twine &Msg)
static SMLoc getFromPointer(const char *Ptr)
Definition: SMLoc.h:37
const unsigned Kind
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:216
Represents a location in source code.
Definition: SMLoc.h:24
void PrintError(ArrayRef< SMLoc > ErrorLoc, const Twine &Msg)