[llvm-commits] [llvm] r66898 - in /llvm/trunk/utils/TableGen: CodeGenDAGPatterns.cpp Record.h TableGen.cpp
Chris Lattner
sabre at nondot.org
Fri Mar 13 09:25:21 PDT 2009
Author: lattner
Date: Fri Mar 13 11:25:21 2009
New Revision: 66898
URL: http://llvm.org/viewvc/llvm-project?rev=66898&view=rev
Log:
add a new TGError class and use it to propagate location info with
errors when thrown. This gets us nice errors like this from tblgen:
CMOVL32rr: (set GR32:i32:$dst, (X86cmov GR32:$src1, GR32:$src2))
/Users/sabre/llvm/Debug/bin/tblgen: error:
Included from X86.td:116:
Parsing X86InstrInfo.td:922: In CMOVL32rr: X86cmov node requires exactly 4 operands!
def CMOVL32rr : I<0x4C, MRMSrcReg, // if <s, GR32 = GR32
^
instead of just:
CMOVL32rr: (set GR32:i32:$dst, (X86cmov GR32:$src1, GR32:$src2))
/Users/sabre/llvm/Debug/bin/tblgen: In CMOVL32rr: X86cmov node requires exactly 4 operands!
This is all I plan to do with this, but it should be easy enough to improve if anyone
cares (e.g. keeping more loc info in "dag" expr records in tblgen.
Modified:
llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp
llvm/trunk/utils/TableGen/Record.h
llvm/trunk/utils/TableGen/TableGen.cpp
Modified: llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp?rev=66898&r1=66897&r2=66898&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp (original)
+++ llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp Fri Mar 13 11:25:21 2009
@@ -1113,7 +1113,7 @@
void TreePattern::error(const std::string &Msg) const {
dump();
- throw "In " + TheRecord->getName() + ": " + Msg;
+ throw TGError(TheRecord->getLoc(), "In " + TheRecord->getName() + ": " + Msg);
}
TreePatternNode *TreePattern::ParseTreePattern(DagInit *Dag) {
Modified: llvm/trunk/utils/TableGen/Record.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/Record.h?rev=66898&r1=66897&r2=66898&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/Record.h (original)
+++ llvm/trunk/utils/TableGen/Record.h Fri Mar 13 11:25:21 2009
@@ -1195,6 +1195,17 @@
}
};
+
+class TGError {
+ TGLoc Loc;
+ std::string Message;
+public:
+ TGError(TGLoc loc, const std::string &message) : Loc(loc), Message(message) {}
+
+ TGLoc getLoc() const { return Loc; }
+ const std::string &getMessage() const { return Message; }
+};
+
std::ostream &operator<<(std::ostream &OS, const RecordKeeper &RK);
Modified: llvm/trunk/utils/TableGen/TableGen.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/TableGen.cpp?rev=66898&r1=66897&r2=66898&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/TableGen.cpp (original)
+++ llvm/trunk/utils/TableGen/TableGen.cpp Fri Mar 13 11:25:21 2009
@@ -114,7 +114,7 @@
static TGSourceMgr SrcMgr;
-void PrintError(TGLoc ErrorLoc, const std::string &Msg) {
+void llvm::PrintError(TGLoc ErrorLoc, const std::string &Msg) {
SrcMgr.PrintError(ErrorLoc, Msg);
}
@@ -229,31 +229,26 @@
assert(1 && "Invalid Action");
return 1;
}
+
+ if (Out != cout.stream())
+ delete Out; // Close the file
+ return 0;
+
+ } catch (const TGError &Error) {
+ cerr << argv[0] << ": error:\n";
+ PrintError(Error.getLoc(), Error.getMessage());
+
} catch (const std::string &Error) {
cerr << argv[0] << ": " << Error << "\n";
- if (Out != cout.stream()) {
- delete Out; // Close the file
- std::remove(OutputFilename.c_str()); // Remove the file, it's broken
- }
- return 1;
} catch (const char *Error) {
cerr << argv[0] << ": " << Error << "\n";
- if (Out != cout.stream()) {
- delete Out; // Close the file
- std::remove(OutputFilename.c_str()); // Remove the file, it's broken
- }
- return 1;
} catch (...) {
cerr << argv[0] << ": Unknown unexpected exception occurred.\n";
- if (Out != cout.stream()) {
- delete Out; // Close the file
- std::remove(OutputFilename.c_str()); // Remove the file, it's broken
- }
- return 2;
}
-
+
if (Out != cout.stream()) {
- delete Out; // Close the file
+ delete Out; // Close the file
+ std::remove(OutputFilename.c_str()); // Remove the file, it's broken
}
- return 0;
+ return 1;
}
More information about the llvm-commits
mailing list