Implement custom parser support for operations, enhance dim/addf to use it, and add a new load op.
This regresses parser error recovery in some cases (in invalid.mlir) which I'll
consider in a follow-up patch. The important thing in this patch is that the
parse methods in StandardOps.cpp are nice and simple.
PiperOrigin-RevId: 206023308
diff --git a/lib/IR/OperationSet.cpp b/lib/IR/OperationSet.cpp
index c8e1e9b..43a65aa 100644
--- a/lib/IR/OperationSet.cpp
+++ b/lib/IR/OperationSet.cpp
@@ -19,10 +19,19 @@
#include "mlir/IR/OpDefinition.h"
#include "mlir/IR/OpImplementation.h"
#include "llvm/ADT/StringMap.h"
+#include "llvm/ADT/Twine.h"
#include "llvm/Support/raw_ostream.h"
using namespace mlir;
using llvm::StringMap;
+OpAsmParser::~OpAsmParser() {}
+
+// The fallback for the printer is to reject the short form.
+OpAsmParserResult OpImpl::BaseState::parse(OpAsmParser *parser) {
+ parser->emitError(parser->getNameLoc(), "has no concise form");
+ return {};
+}
+
// The fallback for the printer is to print it the longhand form.
void OpImpl::BaseState::print(OpAsmPrinter *p) const {
p->printDefaultOp(getOperation());