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
This commit is contained in:
Jim Grosbach 2011-06-21 22:55:50 +00:00
parent 109c22c062
commit 0b6a44afb9
17 changed files with 99 additions and 40 deletions

View File

@ -98,6 +98,7 @@
#include "AsmMatcherEmitter.h"
#include "CodeGenTarget.h"
#include "Error.h"
#include "Record.h"
#include "StringMatcher.h"
#include "llvm/ADT/OwningPtr.h"

View File

@ -14,6 +14,7 @@
#include "AsmWriterEmitter.h"
#include "AsmWriterInst.h"
#include "Error.h"
#include "CodeGenTarget.h"
#include "Record.h"
#include "StringToOffsetTable.h"

View File

@ -13,6 +13,7 @@
//===----------------------------------------------------------------------===//
#include "CodeGenDAGPatterns.h"
#include "Error.h"
#include "Record.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/STLExtras.h"

View File

@ -13,6 +13,7 @@
#include "CodeGenInstruction.h"
#include "CodeGenTarget.h"
#include "Error.h"
#include "Record.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringMap.h"

View File

@ -14,6 +14,7 @@
#include "CodeGenRegisters.h"
#include "CodeGenTarget.h"
#include "Error.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h"

View File

@ -9,6 +9,7 @@
#include "DisassemblerEmitter.h"
#include "CodeGenTarget.h"
#include "Error.h"
#include "Record.h"
#include "X86DisassemblerTables.h"
#include "X86RecognizableInstr.h"

39
utils/TableGen/Error.cpp Normal file
View File

@ -0,0 +1,39 @@
//===- Error.cpp - tblgen error handling helper routines --------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file contains error handling helper routines to pretty-print diagnostic
// messages from tblgen.
//
//===----------------------------------------------------------------------===//
#include "Error.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Support/raw_ostream.h"
namespace llvm {
SourceMgr SrcMgr;
void PrintError(SMLoc ErrorLoc, const Twine &Msg) {
SrcMgr.PrintMessage(ErrorLoc, Msg, "error");
}
void PrintError(const char *Loc, const Twine &Msg) {
SrcMgr.PrintMessage(SMLoc::getFromPointer(Loc), Msg, "error");
}
void PrintError(const Twine &Msg) {
errs() << "error:" << Msg << "\n";
}
void PrintError(const TGError &Error) {
PrintError(Error.getLoc(), Error.getMessage());
}
} // end namespace llvm

43
utils/TableGen/Error.h Normal file
View File

@ -0,0 +1,43 @@
//===- Error.h - tblgen error handling helper routines ----------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file contains error handling helper routines to pretty-print diagnostic
// messages from tblgen.
//
//===----------------------------------------------------------------------===//
#ifndef ERROR_H
#define ERROR_H
#include "llvm/Support/SourceMgr.h"
namespace llvm {
class TGError {
SMLoc Loc;
std::string Message;
public:
TGError(SMLoc loc, const std::string &message) : Loc(loc), Message(message) {}
SMLoc getLoc() const { return Loc; }
const std::string &getMessage() const { return Message; }
};
void PrintError(SMLoc ErrorLoc, const Twine &Msg);
void PrintError(const char *Loc, const Twine &Msg);
void PrintError(const Twine &Msg);
void PrintError(const TGError &Error);
extern SourceMgr SrcMgr;
} // end namespace "llvm"
#endif

View File

@ -18,6 +18,7 @@
//===----------------------------------------------------------------------===//
#include "FastISelEmitter.h"
#include "Error.h"
#include "Record.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/VectorExtras.h"

View File

@ -24,6 +24,7 @@
//===----------------------------------------------------------------------===//
#include "NeonEmitter.h"
#include "Error.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h"

View File

@ -12,6 +12,7 @@
//===----------------------------------------------------------------------===//
#include "Record.h"
#include "Error.h"
#include "llvm/Support/DataTypes.h"
#include "llvm/Support/Format.h"
#include "llvm/ADT/StringExtras.h"

View File

@ -1486,22 +1486,8 @@ struct LessRecordFieldName {
}
};
class TGError {
SMLoc Loc;
std::string Message;
public:
TGError(SMLoc loc, const std::string &message) : Loc(loc), Message(message) {}
SMLoc getLoc() const { return Loc; }
const std::string &getMessage() const { return Message; }
};
raw_ostream &operator<<(raw_ostream &OS, const RecordKeeper &RK);
void PrintError(SMLoc ErrorLoc, const Twine &Msg);
} // End llvm namespace
#endif

View File

@ -13,6 +13,7 @@
//===----------------------------------------------------------------------===//
#include "SetTheory.h"
#include "Error.h"
#include "Record.h"
#include "llvm/Support/Format.h"

View File

@ -12,6 +12,7 @@
//===----------------------------------------------------------------------===//
#include "TGLexer.h"
#include "Error.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Config/config.h"
@ -35,7 +36,6 @@ SMLoc TGLexer::getLoc() const {
return SMLoc::getFromPointer(TokStart);
}
/// ReturnError - Set the error to the specified string at the specified
/// location. This is defined to always return tgtok::Error.
tgtok::TokKind TGLexer::ReturnError(const char *Loc, const Twine &Msg) {
@ -43,16 +43,6 @@ tgtok::TokKind TGLexer::ReturnError(const char *Loc, const Twine &Msg) {
return tgtok::Error;
}
void TGLexer::PrintError(const char *Loc, const Twine &Msg) const {
SrcMgr.PrintMessage(SMLoc::getFromPointer(Loc), Msg, "error");
}
void TGLexer::PrintError(SMLoc Loc, const Twine &Msg) const {
SrcMgr.PrintMessage(Loc, Msg, "error");
}
int TGLexer::getNextChar() {
char CurChar = *CurPtr++;
switch (CurChar) {

View File

@ -101,9 +101,6 @@ public:
}
SMLoc getLoc() const;
void PrintError(const char *Loc, const Twine &Msg) const;
void PrintError(SMLoc Loc, const Twine &Msg) const;
private:
/// LexToken - Read the next token and return its code.

View File

@ -15,6 +15,7 @@
#define TGPARSER_H
#include "TGLexer.h"
#include "Error.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Support/SourceMgr.h"
#include <map>
@ -60,7 +61,7 @@ public:
bool ParseFile();
bool Error(SMLoc L, const Twine &Msg) const {
Lex.PrintError(L, Msg);
PrintError(L, Msg);
return true;
}
bool TokError(const Twine &Msg) const {

View File

@ -26,6 +26,7 @@
#include "DAGISelEmitter.h"
#include "DisassemblerEmitter.h"
#include "EDEmitter.h"
#include "Error.h"
#include "FastISelEmitter.h"
#include "InstrEnumEmitter.h"
#include "InstrInfoEmitter.h"
@ -194,12 +195,6 @@ namespace {
}
static SourceMgr SrcMgr;
void llvm::PrintError(SMLoc ErrorLoc, const Twine &Msg) {
SrcMgr.PrintMessage(ErrorLoc, Msg, "error");
}
int main(int argc, char **argv) {
RecordKeeper Records;
@ -403,13 +398,11 @@ int main(int argc, char **argv) {
return 0;
} catch (const TGError &Error) {
errs() << argv[0] << ": error:\n";
PrintError(Error.getLoc(), Error.getMessage());
PrintError(Error);
} catch (const std::string &Error) {
errs() << argv[0] << ": " << Error << "\n";
PrintError(Error);
} catch (const char *Error) {
errs() << argv[0] << ": " << Error << "\n";
PrintError(Error);
} catch (...) {
errs() << argv[0] << ": Unknown unexpected exception occurred.\n";
}