================
@@ -216,6 +217,59 @@ void Generate(const Record *OpRecord) {
       LLVMLoweringPatternsList.push_back(std::move(PatternName));
   }
 }
+
+static std::string getCIRAttrCppClassRef(const Record *AttrRecord) {
+  const Record *DialectRec = AttrRecord->getValueAsDef("dialect");
+  llvm::StringRef Ns = DialectRec->getValueAsString("cppNamespace");
+  Ns.consume_front("::");
+  std::string Result = Ns.str();
+  Result += "::";
+  Result += AttrRecord->getValueAsString("cppClassName");
+  return Result;
+}
+
+static void emitCIRAttrToValueVisitor(const llvm::RecordKeeper &RK,
+                                      llvm::raw_ostream &OS) {
+  std::vector<const Record *> Attrs;
+  for (const Record *R : RK.getAllDerivedDefinitions("CIR_Attr")) {
+    if (!R->getValueAsBit("hasAttrToValueLowering"))
+      continue;
+    Attrs.push_back(R);
+  }
+
+  if (Attrs.empty())
+    PrintFatalError("no CIR attributes with hasAttrToValueLowering");
+
+  llvm::sort(Attrs, [](const Record *A, const Record *B) {
+    return getCIRAttrCppClassRef(A) < getCIRAttrCppClassRef(B);
+  });
+
+  OS << "#ifdef GET_CIR_ATTR_TO_VALUE_VISITOR_DECLS\n";
+  OS << "  mlir::Value visit(mlir::Attribute attr) {\n";
+  OS << "    return llvm::TypeSwitch<mlir::Attribute, mlir::Value>(attr)\n";
+  OS << "        .Case<";
+  for (size_t I = 0; I < Attrs.size(); ++I) {
----------------
erichkeane wrote:

this looks a heck of a lot like the llvm::join that takes a functor, right?  
Perhaps that would be easier to read?

https://github.com/llvm/llvm-project/pull/187607
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to