LCOV - code coverage report
Current view: top level - lib/TableGen - Error.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 20 40 50.0 %
Date: 2018-02-19 03:08:00 Functions: 6 12 50.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/raw_ostream.h"
      19             : #include <cstdlib>
      20             : 
      21             : namespace llvm {
      22             : 
      23         288 : SourceMgr SrcMgr;
      24             : unsigned ErrorsPrinted = 0;
      25             : 
      26          13 : static void PrintMessage(ArrayRef<SMLoc> Loc, SourceMgr::DiagKind Kind,
      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          13 :   if (Kind == SourceMgr::DK_Error)
      31          13 :     ++ErrorsPrinted;
      32             : 
      33          13 :   SMLoc NullLoc;
      34          13 :   if (Loc.empty())
      35             :     Loc = NullLoc;
      36          13 :   SrcMgr.PrintMessage(Loc.front(), Kind, Msg);
      37          13 :   for (unsigned i = 1; i < Loc.size(); ++i)
      38           0 :     SrcMgr.PrintMessage(Loc[i], SourceMgr::DK_Note,
      39             :                         "instantiated from multiclass");
      40          13 : }
      41             : 
      42           0 : void PrintNote(ArrayRef<SMLoc> NoteLoc, const Twine &Msg) {
      43           0 :   PrintMessage(NoteLoc, SourceMgr::DK_Note, Msg);
      44           0 : }
      45             : 
      46           0 : void PrintWarning(ArrayRef<SMLoc> WarningLoc, const Twine &Msg) {
      47           0 :   PrintMessage(WarningLoc, SourceMgr::DK_Warning, Msg);
      48           0 : }
      49             : 
      50           0 : void PrintWarning(const char *Loc, const Twine &Msg) {
      51           0 :   SrcMgr.PrintMessage(SMLoc::getFromPointer(Loc), SourceMgr::DK_Warning, Msg);
      52           0 : }
      53             : 
      54           0 : void PrintWarning(const Twine &Msg) {
      55           0 :   errs() << "warning:" << Msg << "\n";
      56           0 : }
      57             : 
      58          13 : void PrintError(ArrayRef<SMLoc> ErrorLoc, const Twine &Msg) {
      59          13 :   PrintMessage(ErrorLoc, SourceMgr::DK_Error, Msg);
      60          13 : }
      61             : 
      62           1 : void PrintError(const char *Loc, const Twine &Msg) {
      63           1 :   SrcMgr.PrintMessage(SMLoc::getFromPointer(Loc), SourceMgr::DK_Error, Msg);
      64           1 : }
      65             : 
      66           0 : void PrintError(const Twine &Msg) {
      67           0 :   errs() << "error:" << Msg << "\n";
      68           0 : }
      69             : 
      70           0 : void PrintFatalError(const Twine &Msg) {
      71           0 :   PrintError(Msg);
      72             :   // The following call runs the file cleanup handlers.
      73           0 :   sys::RunInterruptHandlers();
      74           0 :   std::exit(1);
      75             : }
      76             : 
      77           1 : void PrintFatalError(ArrayRef<SMLoc> ErrorLoc, const Twine &Msg) {
      78           1 :   PrintError(ErrorLoc, Msg);
      79             :   // The following call runs the file cleanup handlers.
      80           1 :   sys::RunInterruptHandlers();
      81           1 :   std::exit(1);
      82             : }
      83             : 
      84         864 : } // end namespace llvm

Generated by: LCOV version 1.13