LCOV - code coverage report
Current view: top level - lib/TableGen - Error.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 23 34 67.6 %
Date: 2018-10-20 13:21:21 Functions: 6 10 60.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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"
      19             : #include "llvm/Support/raw_ostream.h"
      20             : #include <cstdlib>
      21             : 
      22             : namespace llvm {
      23             : 
      24             : SourceMgr SrcMgr;
      25             : unsigned ErrorsPrinted = 0;
      26             : 
      27          20 : static void PrintMessage(ArrayRef<SMLoc> Loc, SourceMgr::DiagKind Kind,
      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          20 :   if (Kind == SourceMgr::DK_Error)
      32          19 :     ++ErrorsPrinted;
      33             : 
      34          20 :   SMLoc NullLoc;
      35          20 :   if (Loc.empty())
      36             :     Loc = NullLoc;
      37          20 :   SrcMgr.PrintMessage(Loc.front(), Kind, Msg);
      38          22 :   for (unsigned i = 1; i < Loc.size(); ++i)
      39           2 :     SrcMgr.PrintMessage(Loc[i], SourceMgr::DK_Note,
      40             :                         "instantiated from multiclass");
      41          20 : }
      42             : 
      43           1 : void PrintNote(ArrayRef<SMLoc> NoteLoc, const Twine &Msg) {
      44           1 :   PrintMessage(NoteLoc, SourceMgr::DK_Note, Msg);
      45           1 : }
      46             : 
      47           0 : void PrintWarning(ArrayRef<SMLoc> WarningLoc, const Twine &Msg) {
      48           0 :   PrintMessage(WarningLoc, SourceMgr::DK_Warning, Msg);
      49           0 : }
      50             : 
      51           0 : void PrintWarning(const char *Loc, const Twine &Msg) {
      52           0 :   SrcMgr.PrintMessage(SMLoc::getFromPointer(Loc), SourceMgr::DK_Warning, Msg);
      53           0 : }
      54             : 
      55           2 : void PrintWarning(const Twine &Msg) { WithColor::warning() << Msg << "\n"; }
      56             : 
      57          19 : void PrintError(ArrayRef<SMLoc> ErrorLoc, const Twine &Msg) {
      58          19 :   PrintMessage(ErrorLoc, SourceMgr::DK_Error, Msg);
      59          19 : }
      60             : 
      61           1 : void PrintError(const char *Loc, const Twine &Msg) {
      62           1 :   SrcMgr.PrintMessage(SMLoc::getFromPointer(Loc), SourceMgr::DK_Error, Msg);
      63           1 : }
      64             : 
      65           0 : void PrintError(const Twine &Msg) { WithColor::error() << Msg << "\n"; }
      66             : 
      67           0 : void PrintFatalError(const Twine &Msg) {
      68           0 :   PrintError(Msg);
      69             :   // The following call runs the file cleanup handlers.
      70           0 :   sys::RunInterruptHandlers();
      71           0 :   std::exit(1);
      72             : }
      73             : 
      74           4 : void PrintFatalError(ArrayRef<SMLoc> ErrorLoc, const Twine &Msg) {
      75           4 :   PrintError(ErrorLoc, Msg);
      76             :   // The following call runs the file cleanup handlers.
      77           4 :   sys::RunInterruptHandlers();
      78           4 :   std::exit(1);
      79             : }
      80             : 
      81             : } // end namespace llvm

Generated by: LCOV version 1.13