LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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"
18 #include <cstdlib>
19 
20 namespace llvm {
21 
23 unsigned ErrorsPrinted = 0;
24 
26  const Twine &Msg) {
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 
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)
38  "instantiated from multiclass");
39 }
40 
41 void PrintWarning(ArrayRef<SMLoc> WarningLoc, const Twine &Msg) {
42  PrintMessage(WarningLoc, SourceMgr::DK_Warning, Msg);
43 }
44 
45 void PrintWarning(const char *Loc, const Twine &Msg) {
47 }
48 
49 void PrintWarning(const Twine &Msg) {
50  errs() << "warning:" << Msg << "\n";
51 }
52 
53 void PrintError(ArrayRef<SMLoc> ErrorLoc, const Twine &Msg) {
54  PrintMessage(ErrorLoc, SourceMgr::DK_Error, Msg);
55 }
56 
57 void PrintError(const char *Loc, const Twine &Msg) {
59 }
60 
61 void PrintError(const Twine &Msg) {
62  errs() << "error:" << Msg << "\n";
63 }
64 
65 void PrintFatalError(const std::string &Msg) {
66  PrintError(Twine(Msg));
67  std::exit(1);
68 }
69 
70 void PrintFatalError(ArrayRef<SMLoc> ErrorLoc, const std::string &Msg) {
71  PrintError(ErrorLoc, Msg);
72  std::exit(1);
73 }
74 
75 } // end namespace llvm
raw_ostream & errs()
const T & front() const
front - Get the first element.
Definition: ArrayRef.h:112
SourceMgr SrcMgr
unsigned ErrorsPrinted
static void PrintMessage(ArrayRef< SMLoc > Loc, SourceMgr::DiagKind Kind, const Twine &Msg)
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:109
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:104
void PrintWarning(ArrayRef< SMLoc > WarningLoc, const Twine &Msg)
static SMLoc getFromPointer(const char *Ptr)
Definition: SMLoc.h:35
LLVM_ATTRIBUTE_NORETURN void PrintFatalError(const std::string &Msg)
void PrintMessage(raw_ostream &OS, SMLoc Loc, DiagKind Kind, const Twine &Msg, ArrayRef< SMRange > Ranges=None, ArrayRef< SMFixIt > FixIts=None, bool ShowColors=true) const
Definition: SourceMgr.cpp:214
Represents a location in source code.
Definition: SMLoc.h:23
void PrintError(ArrayRef< SMLoc > ErrorLoc, const Twine &Msg)