llvm.org GIT mirror llvm / 0b6a44a
Consolidate some TableGen diagnostic helper functions. TableGen had diagnostic printers sprinkled about in a few places. Pull them together into a single location in Error.cpp. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@133568 91177308-0d34-0410-b5e6-96231b3b80d8 Jim Grosbach 9 years ago
17 changed file(s) with 99 addition(s) and 40 deletion(s). Raw diff Collapse all Expand all
9797
9898 #include "AsmMatcherEmitter.h"
9999 #include "CodeGenTarget.h"
100 #include "Error.h"
100101 #include "Record.h"
101102 #include "StringMatcher.h"
102103 #include "llvm/ADT/OwningPtr.h"
1313
1414 #include "AsmWriterEmitter.h"
1515 #include "AsmWriterInst.h"
16 #include "Error.h"
1617 #include "CodeGenTarget.h"
1718 #include "Record.h"
1819 #include "StringToOffsetTable.h"
1212 //===----------------------------------------------------------------------===//
1313
1414 #include "CodeGenDAGPatterns.h"
15 #include "Error.h"
1516 #include "Record.h"
1617 #include "llvm/ADT/StringExtras.h"
1718 #include "llvm/ADT/STLExtras.h"
1212
1313 #include "CodeGenInstruction.h"
1414 #include "CodeGenTarget.h"
15 #include "Error.h"
1516 #include "Record.h"
1617 #include "llvm/ADT/StringExtras.h"
1718 #include "llvm/ADT/StringMap.h"
1313
1414 #include "CodeGenRegisters.h"
1515 #include "CodeGenTarget.h"
16 #include "Error.h"
1617 #include "llvm/ADT/SmallVector.h"
1718 #include "llvm/ADT/StringExtras.h"
1819
88
99 #include "DisassemblerEmitter.h"
1010 #include "CodeGenTarget.h"
11 #include "Error.h"
1112 #include "Record.h"
1213 #include "X86DisassemblerTables.h"
1314 #include "X86RecognizableInstr.h"
0 //===- Error.cpp - tblgen error handling helper routines --------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file contains error handling helper routines to pretty-print diagnostic
10 // messages from tblgen.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "Error.h"
15 #include "llvm/ADT/Twine.h"
16 #include "llvm/Support/raw_ostream.h"
17
18 namespace llvm {
19
20 SourceMgr SrcMgr;
21
22 void PrintError(SMLoc ErrorLoc, const Twine &Msg) {
23 SrcMgr.PrintMessage(ErrorLoc, Msg, "error");
24 }
25
26 void PrintError(const char *Loc, const Twine &Msg) {
27 SrcMgr.PrintMessage(SMLoc::getFromPointer(Loc), Msg, "error");
28 }
29
30 void PrintError(const Twine &Msg) {
31 errs() << "error:" << Msg << "\n";
32 }
33
34 void PrintError(const TGError &Error) {
35 PrintError(Error.getLoc(), Error.getMessage());
36 }
37
38 } // end namespace llvm
0 //===- Error.h - tblgen error handling helper routines ----------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file contains error handling helper routines to pretty-print diagnostic
10 // messages from tblgen.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef ERROR_H
15 #define ERROR_H
16
17 #include "llvm/Support/SourceMgr.h"
18
19 namespace llvm {
20
21 class TGError {
22 SMLoc Loc;
23 std::string Message;
24 public:
25 TGError(SMLoc loc, const std::string &message) : Loc(loc), Message(message) {}
26
27 SMLoc getLoc() const { return Loc; }
28 const std::string &getMessage() const { return Message; }
29 };
30
31 void PrintError(SMLoc ErrorLoc, const Twine &Msg);
32 void PrintError(const char *Loc, const Twine &Msg);
33 void PrintError(const Twine &Msg);
34 void PrintError(const TGError &Error);
35
36
37 extern SourceMgr SrcMgr;
38
39
40 } // end namespace "llvm"
41
42 #endif
1717 //===----------------------------------------------------------------------===//
1818
1919 #include "FastISelEmitter.h"
20 #include "Error.h"
2021 #include "Record.h"
2122 #include "llvm/ADT/SmallString.h"
2223 #include "llvm/ADT/VectorExtras.h"
2323 //===----------------------------------------------------------------------===//
2424
2525 #include "NeonEmitter.h"
26 #include "Error.h"
2627 #include "llvm/ADT/SmallString.h"
2728 #include "llvm/ADT/SmallVector.h"
2829 #include "llvm/ADT/StringExtras.h"
1111 //===----------------------------------------------------------------------===//
1212
1313 #include "Record.h"
14 #include "Error.h"
1415 #include "llvm/Support/DataTypes.h"
1516 #include "llvm/Support/Format.h"
1617 #include "llvm/ADT/StringExtras.h"
14851485 }
14861486 };
14871487
1488
1489 class TGError {
1490 SMLoc Loc;
1491 std::string Message;
1492 public:
1493 TGError(SMLoc loc, const std::string &message) : Loc(loc), Message(message) {}
1494
1495 SMLoc getLoc() const { return Loc; }
1496 const std::string &getMessage() const { return Message; }
1497 };
1498
1499
15001488 raw_ostream &operator<<(raw_ostream &OS, const RecordKeeper &RK);
15011489
1502 void PrintError(SMLoc ErrorLoc, const Twine &Msg);
1503
15041490 } // End llvm namespace
15051491
15061492 #endif
1212 //===----------------------------------------------------------------------===//
1313
1414 #include "SetTheory.h"
15 #include "Error.h"
1516 #include "Record.h"
1617 #include "llvm/Support/Format.h"
1718
1111 //===----------------------------------------------------------------------===//
1212
1313 #include "TGLexer.h"
14 #include "Error.h"
1415 #include "llvm/Support/SourceMgr.h"
1516 #include "llvm/Support/MemoryBuffer.h"
1617 #include "llvm/Config/config.h"
3435 return SMLoc::getFromPointer(TokStart);
3536 }
3637
37
3838 /// ReturnError - Set the error to the specified string at the specified
3939 /// location. This is defined to always return tgtok::Error.
4040 tgtok::TokKind TGLexer::ReturnError(const char *Loc, const Twine &Msg) {
4141 PrintError(Loc, Msg);
4242 return tgtok::Error;
4343 }
44
45
46 void TGLexer::PrintError(const char *Loc, const Twine &Msg) const {
47 SrcMgr.PrintMessage(SMLoc::getFromPointer(Loc), Msg, "error");
48 }
49
50 void TGLexer::PrintError(SMLoc Loc, const Twine &Msg) const {
51 SrcMgr.PrintMessage(Loc, Msg, "error");
52 }
53
5444
5545 int TGLexer::getNextChar() {
5646 char CurChar = *CurPtr++;
100100 }
101101
102102 SMLoc getLoc() const;
103
104 void PrintError(const char *Loc, const Twine &Msg) const;
105 void PrintError(SMLoc Loc, const Twine &Msg) const;
106103
107104 private:
108105 /// LexToken - Read the next token and return its code.
1414 #define TGPARSER_H
1515
1616 #include "TGLexer.h"
17 #include "Error.h"
1718 #include "llvm/ADT/Twine.h"
1819 #include "llvm/Support/SourceMgr.h"
1920 #include
5960 bool ParseFile();
6061
6162 bool Error(SMLoc L, const Twine &Msg) const {
62 Lex.PrintError(L, Msg);
63 PrintError(L, Msg);
6364 return true;
6465 }
6566 bool TokError(const Twine &Msg) const {
2525 #include "DAGISelEmitter.h"
2626 #include "DisassemblerEmitter.h"
2727 #include "EDEmitter.h"
28 #include "Error.h"
2829 #include "FastISelEmitter.h"
2930 #include "InstrEnumEmitter.h"
3031 #include "InstrInfoEmitter.h"
193194 }
194195
195196
196 static SourceMgr SrcMgr;
197
198 void llvm::PrintError(SMLoc ErrorLoc, const Twine &Msg) {
199 SrcMgr.PrintMessage(ErrorLoc, Msg, "error");
200 }
201
202197 int main(int argc, char **argv) {
203198 RecordKeeper Records;
204199
402397 return 0;
403398
404399 } catch (const TGError &Error) {
405 errs() << argv[0] << ": error:\n";
406 PrintError(Error.getLoc(), Error.getMessage());
407
400 PrintError(Error);
408401 } catch (const std::string &Error) {
409 errs() << argv[0] << ": " << Error << "\n";
402 PrintError(Error);
410403 } catch (const char *Error) {
411 errs() << argv[0] << ": " << Error << "\n";
404 PrintError(Error);
412405 } catch (...) {
413406 errs() << argv[0] << ": Unknown unexpected exception occurred.\n";
414407 }