[ExportVerilog] Fix XMR paths for inner symbols in generate.case (#9972)#10025
[ExportVerilog] Fix XMR paths for inner symbols in generate.case (#9972)#10025
Conversation
|
Fixes #9972 |
…m#9972) - Emit generate/case scope names before instance segments, matching `GenerateOp` / `GenerateCaseOp` emission (including `legalizeName` order for case labels)
7fa0946 to
d081516
Compare
uenoku
left a comment
There was a problem hiding this comment.
Thank you for working on this!
…#10025) - Follow the reviewer's suggestions
|
@uenoku Thanks for the review! I’ve addressed the comments and pushed updates. Could you please take another look when you have a chance? Thanks!! |
fix nit: please avoid unnecessary allocation of strings Co-authored-by: Hideto Ueno <uenoku.tokotoko@gmail.com>
|
The CI seems to be failing, but 'Conversion/ExportVerilog/sv-dialect.mlir' tests pass on my local machine. @uenoku Would you be able to help take a look when you have a moment? Thanks in advance! |
| let arguments = (ins TypedAttrInterface:$cond, | ||
| PatternArrayAttr:$casePatterns, StrArrayAttr:$caseNames); | ||
| PatternArrayAttr:$casePatterns, StrArrayAttr:$caseNames, | ||
| OptionalAttr<StrArrayAttr>:$verilogCaseNames); |
There was a problem hiding this comment.
I know it's a bit weird but could you not make verilogCaseNames as part of ODS defined attributes because we don't want to expose verilog names here as API?
| module.walk([&](GenerateCaseOp genCase) { | ||
| llvm::StringMap<size_t> nextGenIds; | ||
| SmallVector<Attribute> legalizedNames; | ||
| for (Attribute name : genCase.getCaseNames()) { | ||
| StringRef legal = | ||
| sv::legalizeName(cast<StringAttr>(name).getValue(), nextGenIds, | ||
| options.caseInsensitiveKeywords); | ||
| legalizedNames.emplace_back(StringAttr::get(ctxt, legal)); | ||
| } | ||
| genCase.setVerilogCaseNamesAttr(ArrayAttr::get(ctxt, legalizedNames)); | ||
| }); |
There was a problem hiding this comment.
nit: Could you do this in a walk above?
| options.caseInsensitiveKeywords); | ||
| legalizedNames.emplace_back(StringAttr::get(ctxt, legal)); | ||
| } | ||
| genCase.setVerilogCaseNamesAttr(ArrayAttr::get(ctxt, legalizedNames)); |
There was a problem hiding this comment.
As I mentioned above could you use discardable attribute hw.verilogCaseNames ?
| segments.push_back(SmallString<32>(legal)); | ||
| break; | ||
| } | ||
| } else if (auto gen = dyn_cast<GenerateOp>(parentOp)) { | ||
| StringRef name = ExportVerilog::getSymOpName(gen); | ||
| segments.push_back(SmallString<32>(name)); |
There was a problem hiding this comment.
I think this causes UAF.
| segments.push_back(SmallString<32>(legal)); | |
| break; | |
| } | |
| } else if (auto gen = dyn_cast<GenerateOp>(parentOp)) { | |
| StringRef name = ExportVerilog::getSymOpName(gen); | |
| segments.push_back(SmallString<32>(name)); | |
| segments.push_back(legal); | |
| break; | |
| } | |
| } else if (auto gen = dyn_cast<GenerateOp>(parentOp)) { | |
| StringRef name = ExportVerilog::getSymOpName(gen); | |
| segments.push_back(name); |
GenerateOp/GenerateCaseOpemission (includinglegalizeNameorder for case labels)