LLVM  10.0.0svn
Error.cpp
Go to the documentation of this file.
1 //===- Error.cpp - tblgen error handling helper routines --------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file contains error handling helper routines to pretty-print diagnostic
10 // messages from tblgen.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "llvm/TableGen/Error.h"
15 #include "llvm/ADT/Twine.h"
16 #include "llvm/Support/Signals.h"
17 #include "llvm/Support/WithColor.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)
38  SrcMgr.PrintMessage(Loc[i], SourceMgr::DK_Note,
39  "instantiated from multiclass");
40 }
41 
42 void PrintNote(const Twine &Msg) { WithColor::note() << Msg << "\n"; }
43 
44 void PrintNote(ArrayRef<SMLoc> NoteLoc, const Twine &Msg) {
45  PrintMessage(NoteLoc, SourceMgr::DK_Note, Msg);
46 }
47 
48 void PrintWarning(ArrayRef<SMLoc> WarningLoc, const Twine &Msg) {
49  PrintMessage(WarningLoc, SourceMgr::DK_Warning, Msg);
50 }
51 
52 void PrintWarning(const char *Loc, const Twine &Msg) {
54 }
55 
56 void PrintWarning(const Twine &Msg) { WithColor::warning() << Msg << "\n"; }
57 
58 void PrintError(ArrayRef<SMLoc> ErrorLoc, const Twine &Msg) {
59  PrintMessage(ErrorLoc, SourceMgr::DK_Error, Msg);
60 }
61 
62 void PrintError(const char *Loc, const Twine &Msg) {
64 }
65 
66 void PrintError(const Twine &Msg) { WithColor::error() << Msg << "\n"; }
67 
68 void PrintFatalError(const Twine &Msg) {
69  PrintError(Msg);
70  // The following call runs the file cleanup handlers.
72  std::exit(1);
73 }
74 
75 void PrintFatalError(ArrayRef<SMLoc> ErrorLoc, const Twine &Msg) {
76  PrintError(ErrorLoc, Msg);
77  // The following call runs the file cleanup handlers.
79  std::exit(1);
80 }
81 
82 } // end namespace llvm
const T & front() const
front - Get the first element.
Definition: ArrayRef.h:151
This class represents lattice values for constants.
Definition: AllocatorList.h:23
static raw_ostream & error()
Convenience method for printing "error: " to stderr.
Definition: WithColor.cpp:60
SourceMgr SrcMgr
Definition: Error.cpp:23
static raw_ostream & warning()
Convenience method for printing "warning: " to stderr.
Definition: WithColor.cpp:62
unsigned ErrorsPrinted
Definition: Error.cpp:24
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:242
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:80
static raw_ostream & note()
Convenience method for printing "note: " to stderr.
Definition: WithColor.cpp:64
void PrintNote(const Twine &Msg)
Definition: Error.cpp:42
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:32
static void PrintMessage(ArrayRef< SMLoc > Loc, SourceMgr::DiagKind Kind, const Twine &Msg)
Definition: Error.cpp:26
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:148
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:48
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling...
Definition: SourceMgr.h:41
LLVM_ATTRIBUTE_NORETURN void PrintFatalError(const Twine &Msg)
Definition: Error.cpp:68
static SMLoc getFromPointer(const char *Ptr)
Definition: SMLoc.h:36
Represents a location in source code.
Definition: SMLoc.h:23
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:143
void PrintError(ArrayRef< SMLoc > ErrorLoc, const Twine &Msg)
Definition: Error.cpp:58