Fix names of foreach blocks (#4264)

This commit is contained in:
Ryszard Rozak 2023-06-06 16:24:42 +02:00 committed by GitHub
parent 058233fc87
commit c3e5db5f04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 14 deletions

View File

@ -158,9 +158,7 @@ private:
std::array<ScopeAliasMap, SAMN__MAX> m_scopeAliasMap; // Map of <lhs,rhs> aliases std::array<ScopeAliasMap, SAMN__MAX> m_scopeAliasMap; // Map of <lhs,rhs> aliases
std::vector<VSymEnt*> m_ifaceVarSyms; // List of AstIfaceRefDType's to be imported std::vector<VSymEnt*> m_ifaceVarSyms; // List of AstIfaceRefDType's to be imported
IfaceModSyms m_ifaceModSyms; // List of AstIface+Symbols to be processed IfaceModSyms m_ifaceModSyms; // List of AstIface+Symbols to be processed
bool m_forPrimary; // First link const VLinkDotStep m_step; // Operational step
bool m_forPrearray; // Compress cell__[array] refs
bool m_forScopeCreation; // Remove VarXRefs for V3Scope
public: public:
// METHODS // METHODS
@ -202,11 +200,9 @@ public:
// CONSTRUCTORS // CONSTRUCTORS
LinkDotState(AstNetlist* rootp, VLinkDotStep step) LinkDotState(AstNetlist* rootp, VLinkDotStep step)
: m_syms{rootp} { : m_syms{rootp}
, m_step(step) {
UINFO(4, __FUNCTION__ << ": " << endl); UINFO(4, __FUNCTION__ << ": " << endl);
m_forPrimary = (step == LDS_PRIMARY);
m_forPrearray = (step == LDS_PARAMED || step == LDS_PRIMARY);
m_forScopeCreation = (step == LDS_SCOPED);
s_errorThisp = this; s_errorThisp = this;
V3Error::errorExitCb(preErrorDumpHandler); // If get error, dump self V3Error::errorExitCb(preErrorDumpHandler); // If get error, dump self
} }
@ -217,9 +213,10 @@ public:
// ACCESSORS // ACCESSORS
VSymGraph* symsp() { return &m_syms; } VSymGraph* symsp() { return &m_syms; }
bool forPrimary() const { return m_forPrimary; } int stepNumber() const { return int(m_step); }
bool forPrearray() const { return m_forPrearray; } bool forPrimary() const { return m_step == LDS_PRIMARY; }
bool forScopeCreation() const { return m_forScopeCreation; } bool forPrearray() const { return m_step == LDS_PARAMED || m_step == LDS_PRIMARY; }
bool forScopeCreation() const { return m_step == LDS_SCOPED; }
// METHODS // METHODS
static string nodeTextType(AstNode* nodep) { static string nodeTextType(AstNode* nodep) {
@ -590,7 +587,7 @@ public:
baddot = ident; // So user can see where they botched it baddot = ident; // So user can see where they botched it
okSymp = lookupSymp; okSymp = lookupSymp;
string altIdent; string altIdent;
if (m_forPrearray) { if (forPrearray()) {
// GENFOR Begin is foo__BRA__##__KET__ after we've genloop unrolled, // GENFOR Begin is foo__BRA__##__KET__ after we've genloop unrolled,
// but presently should be just "foo". // but presently should be just "foo".
// Likewise cell foo__[array] before we've expanded arrays is just foo // Likewise cell foo__[array] before we've expanded arrays is just foo
@ -620,7 +617,7 @@ public:
else if (ident == "$root") { else if (ident == "$root") {
lookupSymp = rootEntp(); lookupSymp = rootEntp();
// We've added the '$root' module, now everything else is one lower // We've added the '$root' module, now everything else is one lower
if (!m_forPrearray) { if (!forPrearray()) {
lookupSymp = lookupSymp->findIdFlat(ident); lookupSymp = lookupSymp->findIdFlat(ident);
UASSERT(lookupSymp, "Cannot find $root module under netlist"); UASSERT(lookupSymp, "Cannot find $root module under netlist");
} }
@ -1017,9 +1014,12 @@ class LinkDotFindVisitor final : public VNVisitor {
for (AstNode* stmtp = nodep->stmtsp(); stmtp; stmtp = stmtp->nextp()) { for (AstNode* stmtp = nodep->stmtsp(); stmtp; stmtp = stmtp->nextp()) {
if (VN_IS(stmtp, Var) || VN_IS(stmtp, Foreach)) { if (VN_IS(stmtp, Var) || VN_IS(stmtp, Foreach)) {
std::string name; std::string name;
const std::string stepStr = m_statep->forPrimary()
? ""
: std::to_string(m_statep->stepNumber()) + "_";
do { do {
++m_modBlockNum; ++m_modBlockNum;
name = "unnamedblk" + cvtToStr(m_modBlockNum); name = "unnamedblk" + stepStr + cvtToStr(m_modBlockNum);
// Increment again if earlier pass of V3LinkDot claimed this name // Increment again if earlier pass of V3LinkDot claimed this name
} while (m_curSymp->findIdFlat(name)); } while (m_curSymp->findIdFlat(name));
nodep->name(name); nodep->name(name);

View File

@ -12,5 +12,8 @@ module t;
end end
foreach (a[i]) begin foreach (a[i]) begin
end end
begin
int x;
end
endfunction endfunction
endmodule endmodule

View File

@ -1,2 +1,2 @@
[0] %Error: t_randcase_bad.v:12: Assertion failed in top.t.unnamedblk1: All randcase items had 0 weights (IEEE 1800-2017 18.16) [0] %Error: t_randcase_bad.v:12: Assertion failed in top.t.unnamedblk2_1: All randcase items had 0 weights (IEEE 1800-2017 18.16)
*-* All Finished *-* *-* All Finished *-*