Skip to content

Commit

Permalink
Consolidate some TableGen diagnostic helper functions.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Jim Grosbach committed Jun 21, 2011
1 parent 109c22c commit 0b6a44a
Show file tree
Hide file tree
Showing 17 changed files with 99 additions and 40 deletions.
1 change: 1 addition & 0 deletions utils/TableGen/AsmMatcherEmitter.cpp
Expand Up @@ -98,6 +98,7 @@

#include "AsmMatcherEmitter.h"
#include "CodeGenTarget.h"
#include "Error.h"
#include "Record.h"
#include "StringMatcher.h"
#include "llvm/ADT/OwningPtr.h"
Expand Down
1 change: 1 addition & 0 deletions utils/TableGen/AsmWriterEmitter.cpp
Expand Up @@ -14,6 +14,7 @@

#include "AsmWriterEmitter.h"
#include "AsmWriterInst.h"
#include "Error.h"
#include "CodeGenTarget.h"
#include "Record.h"
#include "StringToOffsetTable.h"
Expand Down
1 change: 1 addition & 0 deletions utils/TableGen/CodeGenDAGPatterns.cpp
Expand Up @@ -13,6 +13,7 @@
//===----------------------------------------------------------------------===//

#include "CodeGenDAGPatterns.h"
#include "Error.h"
#include "Record.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/STLExtras.h"
Expand Down
1 change: 1 addition & 0 deletions utils/TableGen/CodeGenInstruction.cpp
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions utils/TableGen/CodeGenRegisters.cpp
Expand Up @@ -14,6 +14,7 @@

#include "CodeGenRegisters.h"
#include "CodeGenTarget.h"
#include "Error.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h"

Expand Down
1 change: 1 addition & 0 deletions utils/TableGen/DisassemblerEmitter.cpp
Expand Up @@ -9,6 +9,7 @@

#include "DisassemblerEmitter.h"
#include "CodeGenTarget.h"
#include "Error.h"
#include "Record.h"
#include "X86DisassemblerTables.h"
#include "X86RecognizableInstr.h"
Expand Down
39 changes: 39 additions & 0 deletions utils/TableGen/Error.cpp
@@ -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 changes: 43 additions & 0 deletions utils/TableGen/Error.h
@@ -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
1 change: 1 addition & 0 deletions utils/TableGen/FastISelEmitter.cpp
Expand Up @@ -18,6 +18,7 @@
//===----------------------------------------------------------------------===//

#include "FastISelEmitter.h"
#include "Error.h"
#include "Record.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/VectorExtras.h"
Expand Down
1 change: 1 addition & 0 deletions utils/TableGen/NeonEmitter.cpp
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions utils/TableGen/Record.cpp
Expand Up @@ -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"
Expand Down
14 changes: 0 additions & 14 deletions utils/TableGen/Record.h
Expand Up @@ -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
1 change: 1 addition & 0 deletions utils/TableGen/SetTheory.cpp
Expand Up @@ -13,6 +13,7 @@
//===----------------------------------------------------------------------===//

#include "SetTheory.h"
#include "Error.h"
#include "Record.h"
#include "llvm/Support/Format.h"

Expand Down
12 changes: 1 addition & 11 deletions utils/TableGen/TGLexer.cpp
Expand Up @@ -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"
Expand All @@ -35,24 +36,13 @@ 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) {
PrintError(Loc, 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) {
Expand Down
3 changes: 0 additions & 3 deletions utils/TableGen/TGLexer.h
Expand Up @@ -101,9 +101,6 @@ class TGLexer {
}

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.
Expand Down
3 changes: 2 additions & 1 deletion utils/TableGen/TGParser.h
Expand Up @@ -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>
Expand Down Expand Up @@ -60,7 +61,7 @@ class TGParser {
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 {
Expand Down
15 changes: 4 additions & 11 deletions utils/TableGen/TableGen.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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";
}
Expand Down

0 comments on commit 0b6a44a

Please sign in to comment.