aboutsummaryrefslogtreecommitdiffstats
path: root/utils
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-03-13 16:25:21 +0000
committerChris Lattner <sabre@nondot.org>2009-03-13 16:25:21 +0000
commita14b1ded69dc76f4e41ef60eeab89dc8575af44b (patch)
tree442f96347125ff44bddb8a3c32707364662ad559 /utils
parent7b9ffe4a6db2e59c18510aac4ba30902653e13eb (diff)
downloadexternal_llvm-a14b1ded69dc76f4e41ef60eeab89dc8575af44b.zip
external_llvm-a14b1ded69dc76f4e41ef60eeab89dc8575af44b.tar.gz
external_llvm-a14b1ded69dc76f4e41ef60eeab89dc8575af44b.tar.bz2
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@66898 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils')
-rw-r--r--utils/TableGen/CodeGenDAGPatterns.cpp2
-rw-r--r--utils/TableGen/Record.h11
-rw-r--r--utils/TableGen/TableGen.cpp33
3 files changed, 26 insertions, 20 deletions
diff --git a/utils/TableGen/CodeGenDAGPatterns.cpp b/utils/TableGen/CodeGenDAGPatterns.cpp
index 6e7dd1e..6af0515 100644
--- a/utils/TableGen/CodeGenDAGPatterns.cpp
+++ b/utils/TableGen/CodeGenDAGPatterns.cpp
@@ -1113,7 +1113,7 @@ TreePattern::TreePattern(Record *TheRec, TreePatternNode *Pat, bool isInput,
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) {
diff --git a/utils/TableGen/Record.h b/utils/TableGen/Record.h
index 5eb07eb..00b7730 100644
--- a/utils/TableGen/Record.h
+++ b/utils/TableGen/Record.h
@@ -1195,6 +1195,17 @@ struct LessRecordFieldName {
}
};
+
+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);
diff --git a/utils/TableGen/TableGen.cpp b/utils/TableGen/TableGen.cpp
index 1beddf0..36ad999 100644
--- a/utils/TableGen/TableGen.cpp
+++ b/utils/TableGen/TableGen.cpp
@@ -114,7 +114,7 @@ RecordKeeper llvm::Records;
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 @@ int main(int argc, char **argv) {
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;
}