Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dotted reference error with generated array #1005

Closed
veripoolbot opened this issue Nov 22, 2015 · 6 comments
Closed

Dotted reference error with generated array #1005

veripoolbot opened this issue Nov 22, 2015 · 6 comments
Labels
resolution: fixed Closed; fixed

Comments

@veripoolbot
Copy link
Contributor


Author Name: Jeff Bush (@jbush001)
Original Redmine Issue: 1005 from https://www.veripool.org
Original Date: 2015-11-22


The following code emits an error when compiled with version 3.878. It works fine with 3.876:

module foo_module;
	genvar i;
	generate
		for (i = 0; i < 2; i = i + 1) begin : my_gen_block
			logic baz;
		end
	endgenerate
endmodule

module bar_module;
	foo_module foo();
endmodule

module top;
	bar_module bar();
	initial bar.foo.my_gen_block[0].baz = 1;
endmodule

$ verilator error.sv --cc
%Error: error.sv:16: Can't find definition of 'foo' in dotted signal: foo.my_gen_block__BRA__0__KET__.baz
%Error:      Known scopes under 'baz': bar

It does not fail if I instantiate the foo_module directly from top and reference foo.my_gen_block[0].baz from there.

@veripoolbot
Copy link
Contributor Author


Original Redmine Comment
Author Name: Johan Bjork
Original Date: 2015-11-22T20:09:55Z


Thanks, I can see how this happens, when adding support for arrayed interfaces we rewrite the reference name but end up losing the first part of the dotted reference.
I'll compose a proper patch later this week, but if this is blocking you, the following hacky diff should get you going.

diff -r 4b288e13c7dd build/verilator/src/V3Param.cpp
--- a/build/verilator/src/V3Param.cpp   Sun Nov 22 12:51:19 2015 -0500
+++ b/build/verilator/src/V3Param.cpp   Sun Nov 22 15:07:54 2015 -0500
@@ -308,9 +308,10 @@
      }
 
      virtual void visit(AstUnlinkedRef* nodep, AstNUser*) {
+       AstVarXRef* varxrefp = nodep->op1p()->castVarXRef();
         m_unlinkedTxt.clear();
+    m_unlinkedTxt = varxrefp->dotted();
         nodep->cellrefp()->iterate(*this);
-       AstVarXRef* varxrefp = nodep->op1p()->castVarXRef();
         AstNodeFTaskRef* taskref = nodep->op1p()->castNodeFTaskRef();
         if (varxrefp) {
             varxrefp->dotted(m_unlinkedTxt);
@@ -326,7 +327,9 @@
         V3Const::constifyParamsEdit(nodep->selp());
         if (AstConst* constp = nodep->selp()->castConst()) {
             string index = AstNode::encodeNumber(constp->toSInt());
-           m_unlinkedTxt += nodep->name() + "__BRA__"+index+"__KET__";
+        string replacestr = nodep->name() + "__BRA__??__KET__";
+        size_t pos = m_unlinkedTxt.find(replacestr);
+        m_unlinkedTxt.replace(pos, replacestr.length(), nodep->name() + "__BRA__"+index+"__KET__");
         } else {
             nodep->v3error("Could not expand constant selection inside dotted reference: "<<nodep->selp()->prettyName());
             return;
@@ -337,15 +340,15 @@
         if (nodep->cellp()->castCellArrayRef() || nodep->cellp()->castCellRef()) {
             nodep->cellp()->iterate(*this);
         } else if (nodep->cellp()->castParseRef()) {
-           m_unlinkedTxt += nodep->cellp()->name();
+           //m_unlinkedTxt += nodep->cellp()->name();
         } else {
             nodep->v3error("Could not elaborate dotted reference (LHS): "<<nodep->cellp()->prettyName());
         }
-       m_unlinkedTxt += ".";
+       //m_unlinkedTxt += ".";
         if (nodep->exprp()->castCellArrayRef() || nodep->exprp()->castCellRef()) {
             nodep->exprp()->iterate(*this);
         } else if (nodep->exprp()->castParseRef()) {
-           m_unlinkedTxt += nodep->exprp()->name();
+           //m_unlinkedTxt += nodep->exprp()->name();
         } else {
             nodep->v3error("Could not elaborate dotted reference (RHS): "<<nodep->exprp()->prettyName());
         }

@veripoolbot
Copy link
Contributor Author


Original Redmine Comment
Author Name: Jeff Bush (@jbush001)
Original Date: 2015-11-22T21:20:18Z


I did git bisect and this is the commit where this started happening:

commit 040b1b06d514a8201b229436b88de9522af0aa2f
Author: Wilson Snyder <wsnyder@wsnyder.org>
Date:   Thu Oct 22 20:13:49 2015 -0400

     Support genvar indexes into arrayed cells, #�.

@veripoolbot
Copy link
Contributor Author


Original Redmine Comment
Author Name: Jeff Bush (@jbush001)
Original Date: 2015-11-22T21:22:40Z


Oops, didn't see your update before I added my last comment. It looks like you know what it is. Thanks for the quick response!

@veripoolbot
Copy link
Contributor Author


Original Redmine Comment
Author Name: Johan Bjork
Original Date: 2015-12-02T01:59:58Z


Wilson,

Patch for this issue available here: https://github.com/phb/verilator-dev/tree/issue1005

@veripoolbot
Copy link
Contributor Author


Original Redmine Comment
Author Name: Wilson Snyder (@wsnyder)
Original Date: 2015-12-06T00:59:48Z


Thanks for another good patch. BTW I added the example provided, and had to make one minor test patch to get it to pass.

Fixed in git towards 3.880.

@veripoolbot
Copy link
Contributor Author


Original Redmine Comment
Author Name: Wilson Snyder (@wsnyder)
Original Date: 2015-12-19T15:33:59Z


In 3.880.

@veripoolbot veripoolbot added the resolution: fixed Closed; fixed label Dec 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
resolution: fixed Closed; fixed
Projects
None yet
Development

No branches or pull requests

1 participant