diff --git a/lib/Dialect/FIRRTL/FIRRTLUtils.cpp b/lib/Dialect/FIRRTL/FIRRTLUtils.cpp index e6777776a8d1..02985be25432 100644 --- a/lib/Dialect/FIRRTL/FIRRTLUtils.cpp +++ b/lib/Dialect/FIRRTL/FIRRTLUtils.cpp @@ -593,6 +593,16 @@ circt::firrtl::getFieldName(const FieldRef &fieldRef, bool nameSafe) { // Recurse in to the element type. type = element.type; localID = localID - bundleType.getFieldID(index); + } else if (auto bundleType = type_dyn_cast(type)) { + auto index = bundleType.getIndexForFieldID(localID); + // Add the current field string, and recurse into a subfield. + auto &element = bundleType.getElements()[index]; + if (!name.empty()) + name += nameSafe ? "_" : "."; + name += element.name.getValue(); + // Recurse in to the element type. + type = element.type; + localID = localID - bundleType.getFieldID(index); } else if (auto vecType = type_dyn_cast(type)) { auto index = vecType.getIndexForFieldID(localID); name += nameSafe ? "_" : "["; @@ -602,6 +612,15 @@ circt::firrtl::getFieldName(const FieldRef &fieldRef, bool nameSafe) { // Recurse in to the element type. type = vecType.getElementType(); localID = localID - vecType.getFieldID(index); + } else if (auto vecType = type_dyn_cast(type)) { + auto index = vecType.getIndexForFieldID(localID); + name += nameSafe ? "_" : "["; + name += std::to_string(index); + if (!nameSafe) + name += "]"; + // Recurse in to the element type. + type = vecType.getElementType(); + localID = localID - vecType.getFieldID(index); } else if (auto enumType = type_dyn_cast(type)) { auto index = enumType.getIndexForFieldID(localID); auto &element = enumType.getElements()[index];