Add parsing for attributes and attibutes on operations. Add IR representation
for attributes on operations. Split Operation out from OperationInst so it
can be shared with OperationStmt one day.
PiperOrigin-RevId: 203325366
diff --git a/lib/IR/AsmPrinter.cpp b/lib/IR/AsmPrinter.cpp
index b24eb2f..1cefc0a 100644
--- a/lib/IR/AsmPrinter.cpp
+++ b/lib/IR/AsmPrinter.cpp
@@ -22,6 +22,7 @@
#include "mlir/IR/AffineExpr.h"
#include "mlir/IR/AffineMap.h"
+#include "mlir/IR/Attributes.h"
#include "mlir/IR/CFGFunction.h"
#include "mlir/IR/MLFunction.h"
#include "mlir/IR/Module.h"
@@ -32,6 +33,14 @@
using namespace mlir;
+void Identifier::print(raw_ostream &os) const {
+ os << str();
+}
+
+void Identifier::dump() const {
+ print(llvm::errs());
+}
+
//===----------------------------------------------------------------------===//
// Function printing
//===----------------------------------------------------------------------===//
@@ -140,7 +149,18 @@
void CFGFunctionState::print(const OperationInst *inst) {
// TODO: escape name if necessary.
- os << " \"" << inst->getName().str() << "\"()\n";
+ os << " \"" << inst->getName().str() << "\"()";
+
+ auto attrs = inst->getAttrs();
+ if (!attrs.empty()) {
+ os << '{';
+ interleave(attrs, [&](NamedAttribute attr) {
+ os << attr.first << ": " << *attr.second;
+ }, [&]() { os << ", "; });
+ os << '}';
+ }
+
+ os << '\n';
}
void CFGFunctionState::print(const BranchInst *inst) {