@@ -88,20 +88,18 @@ class AddReflectionMapClass : public OpRewritePattern<emitc::ClassOp> {
8888 // Collect all field names
8989 std::vector<std::pair<std::string, std::string>> fieldNames;
9090 classOp.walk ([&](mlir::emitc::FieldOp fieldOp) {
91- if (DictionaryAttr innerDictAttr = dyn_cast<mlir::DictionaryAttr>(
92- fieldOp->getAttrDictionary ().get (" attrs" ))) {
93- ArrayAttr arrayAttr = cast<mlir::ArrayAttr>(
94- innerDictAttr.getNamed (attributeName)->getValue ());
91+ if (ArrayAttr arrayAttr = cast<mlir::ArrayAttr>(
92+ fieldOp->getAttrDictionary ().get (attributeName))) {
9593 StringAttr stringAttr = cast<mlir::StringAttr>(arrayAttr[0 ]);
9694 fieldNames.emplace_back (stringAttr.getValue ().str (),
9795 fieldOp.getName ().str ());
9896
99- } else
97+ } else {
10098 fieldOp.emitError ()
10199 << " FieldOp must have a dictionary attribute named '"
102100 << attributeName << " '"
103101 << " with an array containing a string attribute" ;
104-
102+ }
105103 });
106104
107105 std::string mapString;
@@ -113,24 +111,18 @@ class AddReflectionMapClass : public OpRewritePattern<emitc::ClassOp> {
113111 }
114112 mapString += " }" ;
115113
116- emitc::FuncOp executeFunc =
117- classOp.lookupSymbol <mlir::emitc::FuncOp>(" execute" );
118- if (executeFunc)
114+ if (emitc::FuncOp executeFunc =
115+ classOp.lookupSymbol <mlir::emitc::FuncOp>(" execute" ))
119116 rewriter.setInsertionPoint (executeFunc);
120117 else {
121118 classOp.emitError () << " ClassOp must contain a function named 'execute' "
122119 " to add reflection map" ;
123120 return failure ();
124121 }
125122
126- // Create the constant map
127- rewriter.create <emitc::ConstantOp>(
128- classOp.getLoc (), mapType, emitc::OpaqueAttr::get (context, mapString));
129-
130- // TODO: Ideally, we would create a function that returns a reference to the
131- // buffer map. However, current limitations in EmitC function support make
132- // this difficult to implement at the moment.
133-
123+ rewriter.create <emitc::FieldOp>(
124+ classOp.getLoc (), rewriter.getStringAttr (" reflectionMap" ),
125+ TypeAttr::get (mapType), emitc::OpaqueAttr::get (context, mapString));
134126 return success ();
135127 }
136128
0 commit comments