From 8f2bc6e028eb3bab7aafc07ef21a08f5179ffb07 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Wed, 22 Mar 2017 17:34:47 -0400 Subject: [PATCH] Patch to fix for bug1135. --- src/V3Inst.cpp | 20 ++++++++++++++------ test_regress/t/t_interface_arraymux.v | 15 +++++++++++++++ 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/V3Inst.cpp b/src/V3Inst.cpp index 737090dde..ae65ed26f 100644 --- a/src/V3Inst.cpp +++ b/src/V3Inst.cpp @@ -333,15 +333,18 @@ private: // Clone the var referenced by the pin, and clone each var referenced by the varref // Clone pin varp: for (int i = pinArrp->lsb(); i <= pinArrp->msb(); ++i) { - AstIfaceRefDType* ifaceRefp = pinArrp->subDTypep()->castIfaceRefDType(); - ifaceRefp->cellp(NULL); - string varNewName = pinVarp->name() + "__BRA__" + cvtToStr(i) + "__KET__"; VarNameMap::iterator it = m_modVarNameMap.find(varNewName); - AstVar* varNewp; - if (it != m_modVarNameMap.end()) { - varNewp = it->second; + AstVar* varNewp = NULL; + + // Only clone the var once for each module + if (!pinVarp->backp()) { + if (it != m_modVarNameMap.end()) { + varNewp = it->second; + } } else { + AstIfaceRefDType* ifaceRefp = pinArrp->subDTypep()->castIfaceRefDType(); + ifaceRefp->cellp(NULL); varNewp = pinVarp->cloneTree(false); m_modVarNameMap.insert(make_pair(varNewName, varNewp)); varNewp->name(varNewName); @@ -353,6 +356,11 @@ private: prevp->addNextHere(varNewp); } } + if (varNewp == NULL) { + nodep->v3fatalSrc("Module dearray failed\n"); + } + + // But clone the pin for each module instance // Now also clone the pin itself and update its varref AstPin* newp = nodep->cloneTree(false); newp->modVarp(varNewp); diff --git a/test_regress/t/t_interface_arraymux.v b/test_regress/t/t_interface_arraymux.v index a77232702..e9345a5cd 100644 --- a/test_regress/t/t_interface_arraymux.v +++ b/test_regress/t/t_interface_arraymux.v @@ -102,4 +102,19 @@ module t .uids ( uids ), .thing_inp( thing_inp ), .thing_out( thing_out )); + + // Previously there was a problem in V3Inst if non-default parameters was used + localparam K = 2; + the_intf #(.M(K)) thing_inp2(); + the_intf #(.M(K)) thing_out2(); + + Thinker #( + .M ( K ), + .N ( N )) + thinker2( + .clk ( clk ), + .reset ( reset ), + .uids ( uids ), + .thing_inp( thing_inp2 ), + .thing_out( thing_out2 )); endmodule