llvm.org GIT mirror llvm / a14b1de
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 Chris Lattner 10 years ago
3 changed file(s) with 29 addition(s) and 23 deletion(s). Raw diff Collapse all Expand all
11121112
11131113 void TreePattern::error(const std::string &Msg) const {
11141114 dump();
1115 throw "In " + TheRecord->getName() + ": " + Msg;
1115 throw TGError(TheRecord->getLoc(), "In " + TheRecord->getName() + ": " + Msg);
11161116 }
11171117
11181118 TreePatternNode *TreePattern::ParseTreePattern(DagInit *Dag) {
11941194 }
11951195 };
11961196
1197
1198 class TGError {
1199 TGLoc Loc;
1200 std::string Message;
1201 public:
1202 TGError(TGLoc loc, const std::string &message) : Loc(loc), Message(message) {}
1203
1204 TGLoc getLoc() const { return Loc; }
1205 const std::string &getMessage() const { return Message; }
1206 };
1207
11971208
11981209 std::ostream &operator<<(std::ostream &OS, const RecordKeeper &RK);
11991210
113113
114114 static TGSourceMgr SrcMgr;
115115
116 void PrintError(TGLoc ErrorLoc, const std::string &Msg) {
116 void llvm::PrintError(TGLoc ErrorLoc, const std::string &Msg) {
117117 SrcMgr.PrintError(ErrorLoc, Msg);
118118 }
119119
228228 assert(1 && "Invalid Action");
229229 return 1;
230230 }
231
232 if (Out != cout.stream())
233 delete Out; // Close the file
234 return 0;
235
236 } catch (const TGError &Error) {
237 cerr << argv[0] << ": error:\n";
238 PrintError(Error.getLoc(), Error.getMessage());
239
231240 } catch (const std::string &Error) {
232241 cerr << argv[0] << ": " << Error << "\n";
233 if (Out != cout.stream()) {
234 delete Out; // Close the file
235 std::remove(OutputFilename.c_str()); // Remove the file, it's broken
236 }
237 return 1;
238242 } catch (const char *Error) {
239243 cerr << argv[0] << ": " << Error << "\n";
240 if (Out != cout.stream()) {
241 delete Out; // Close the file
242 std::remove(OutputFilename.c_str()); // Remove the file, it's broken
243 }
244 return 1;
245244 } catch (...) {
246245 cerr << argv[0] << ": Unknown unexpected exception occurred.\n";
247 if (Out != cout.stream()) {
248 delete Out; // Close the file
249 std::remove(OutputFilename.c_str()); // Remove the file, it's broken
250 }
251 return 2;
252 }
253
246 }
247
254248 if (Out != cout.stream()) {
255 delete Out; // Close the file
256 }
257 return 0;
258 }
249 delete Out; // Close the file
250 std::remove(OutputFilename.c_str()); // Remove the file, it's broken
251 }
252 return 1;
253 }