diff --git a/mlir/test/mlir-tblgen/op-format-spec.td b/mlir/test/mlir-tblgen/op-format-spec.td --- a/mlir/test/mlir-tblgen/op-format-spec.td +++ b/mlir/test/mlir-tblgen/op-format-spec.td @@ -20,7 +20,7 @@ //===----------------------------------------------------------------------===// // attr-dict -// CHECK: error: 'attr-dict' directive not found in custom assembly format +// CHECK: error: 'attr-dict' directive not found def DirectiveAttrDictInvalidA : TestFormat_Op<"attrdict_invalid_a", [{ }]>; // CHECK: error: 'attr-dict' directive has already been seen @@ -286,7 +286,7 @@ def ZCoverageInvalidA : TestFormat_Op<"variable_invalid_a", [{ attr-dict }]>, Arguments<(ins AnyMemRef:$operand)>, Results<(outs AnyMemRef:$result)>; -// CHECK: error: operand #0, named 'operand', not found in custom assembly format +// CHECK: error: operand #0, named 'operand', not found // CHECK: note: suggest adding a '$operand' directive to the custom assembly format def ZCoverageInvalidB : TestFormat_Op<"variable_invalid_b", [{ type($result) attr-dict @@ -306,7 +306,7 @@ def ZCoverageInvalidE : TestFormat_Op<"variable_invalid_e", [{ attr-dict }]>, Results<(outs Variadic:$result)>; -// CHECK: error: successor #0, named 'successor', not found in custom assembly format +// CHECK: error: successor #0, named 'successor', not found // CHECK: note: suggest adding a '$successor' directive to the custom assembly format def ZCoverageInvalidF : TestFormat_Op<"variable_invalid_f", [{ attr-dict diff --git a/mlir/tools/mlir-tblgen/OpFormatGen.cpp b/mlir/tools/mlir-tblgen/OpFormatGen.cpp --- a/mlir/tools/mlir-tblgen/OpFormatGen.cpp +++ b/mlir/tools/mlir-tblgen/OpFormatGen.cpp @@ -1048,7 +1048,7 @@ /// This class implements a simple lexer for operation assembly format strings. class FormatLexer { public: - FormatLexer(llvm::SourceMgr &mgr); + FormatLexer(llvm::SourceMgr &mgr, Operator &op); /// Lex the next token and return it. Token lexToken(); @@ -1057,7 +1057,8 @@ Token emitError(llvm::SMLoc loc, const Twine &msg); Token emitError(const char *loc, const Twine &msg); - Token emitErrorAndNote(llvm::SMLoc loc, const Twine &msg, const Twine ¬e); + Token emitErrorAndNote(llvm::SMLoc loc, + const Twine &msg, const Twine ¬e); private: Token formToken(Token::Kind kind, const char *tokStart) { @@ -1073,24 +1074,32 @@ Token lexVariable(const char *tokStart); llvm::SourceMgr &srcMgr; + Operator &op; StringRef curBuffer; const char *curPtr; }; } // end anonymous namespace -FormatLexer::FormatLexer(llvm::SourceMgr &mgr) : srcMgr(mgr) { +FormatLexer::FormatLexer(llvm::SourceMgr &mgr, Operator &op) : + srcMgr(mgr), op(op) { curBuffer = srcMgr.getMemoryBuffer(mgr.getMainFileID())->getBuffer(); curPtr = curBuffer.begin(); } Token FormatLexer::emitError(llvm::SMLoc loc, const Twine &msg) { srcMgr.PrintMessage(loc, llvm::SourceMgr::DK_Error, msg); + llvm::SrcMgr.PrintMessage(op.getLoc()[0], + llvm::SourceMgr::DK_Note, + "in custom assembly format for this operation"); return formToken(Token::error, loc.getPointer()); } Token FormatLexer::emitErrorAndNote(llvm::SMLoc loc, - const Twine &msg, - const Twine ¬e) { + const Twine &msg, + const Twine ¬e) { srcMgr.PrintMessage(loc, llvm::SourceMgr::DK_Error, msg); + llvm::SrcMgr.PrintMessage(op.getLoc()[0], + llvm::SourceMgr::DK_Note, + "in custom assembly format for this operation"); srcMgr.PrintMessage(loc, llvm::SourceMgr::DK_Note, note); return formToken(Token::error, loc.getPointer()); } @@ -1227,7 +1236,7 @@ class FormatParser { public: FormatParser(llvm::SourceMgr &mgr, OperationFormat &format, Operator &op) - : lexer(mgr), curToken(lexer.lexToken()), fmt(format), op(op), + : lexer(mgr, op), curToken(lexer.lexToken()), fmt(format), op(op), seenOperandTypes(op.getNumOperands()), seenResultTypes(op.getNumResults()) {} @@ -1352,9 +1361,7 @@ // Check that the attribute dictionary is in the format. if (!hasAttrDict) - return emitError(loc, - "'attr-dict' directive not found in " - "custom assembly format"); + return emitError(loc, "'attr-dict' directive not found"); // Check for any type traits that we can use for inferring types. llvm::StringMap variableTyResolver; @@ -1419,8 +1426,7 @@ // Check that the operand itself is in the format. if (!hasAllOperands && !seenOperands.count(&operand)) { return emitErrorAndNote(loc, "operand #" + Twine(i) + - ", named '" + operand.name + - "', not found in custom assembly format", + ", named '" + operand.name + "', not found", "suggest adding a '$" + operand.name + "' directive to the custom assembly format"); } @@ -1463,7 +1469,7 @@ if (!seenSuccessors.count(&successor)) { return emitErrorAndNote(loc, "successor #" + Twine(i) + ", named '" + successor.name + - "', not found in custom assembly format", + "', not found", "suggest adding a '$" + successor.name + "' directive to the custom assembly format"); }