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

can't determine constant for FUNCREF for function returning an enum #970

Closed
veripoolbot opened this issue Sep 30, 2015 · 7 comments
Closed
Assignees
Labels
resolution: fixed Closed; fixed

Comments

@veripoolbot
Copy link
Contributor


Author Name: Todd Strader (@toddstrader)
Original Redmine Issue: 970 from https://www.veripool.org
Original Date: 2015-09-29
Original Assignee: Todd Strader (@toddstrader)


I thought this would be more of the same from #�, but I don't think it is.

You can find the test (t_static_elab_enum) here:
https://github.com/toddstrader/verilator-enum-func

When returning an enum from a constant function, I get:

%Error: t/t_static_elab_enum.v:22: Expecting expression to be constant, but can't determine constant for FUNCREF 'gimme_five'
%Error: t/t_static_elab_enum.v:19: ... Location of non-constant ENUMITEMREF 'HIGH_FIVE': Unknown node type, perhaps missing visitor in SimulateVisitor

And sure enough, there is no ENUMITEMREF. However, I believe the deeper problem is that at the point which we're running the simulator, enum items don't appear to have values yet.

$ grep -A 4 TYPEDEF obj_dir/t_static_elab_enum/Vt_static_elab_enum_007_link.tree 
     1:2: TYPEDEF 0x19965e0 <e13> {e8} @dt=0@  five_t
     1:2:1: ENUMDTYPE 0x1996400 <e55> {e8} @dt=0@
     1:2:1:1: BASICDTYPE 0x1996100 <e10> {e8} @dt=this@(sw32)  int kwd=int range=[31:0]
     1:2:1:2: ENUMITEM 0x1996220 <e6> {e9} @dt=0@  HIGH_FIVE
     1:2:1:2: ENUMITEM 0x1996340 <e8> {e10} @dt=0@  LOW_FIVE

I believe this problem would be pretty trivial if the enum items had values at this stage. I haven't dug into this yet, but does anyone know if there is a reason enum items don't have values at 009_paramlink (it seems to happen at 011_width)? Also, does anyone know how is there is a major issue with moving this step earlier?

I'm still looking. I'll see what I can do.

@veripoolbot
Copy link
Contributor Author


Original Redmine Comment
Author Name: Todd Strader (@toddstrader)
Original Date: 2015-09-30T00:30:40Z


I tried the simple thing:

$ git diff src/Verilator.cpp
diff --git a/src/Verilator.cpp b/src/Verilator.cpp
index 6a820c2..dcd2b94 100644
--- a/src/Verilator.cpp
+++ b/src/Verilator.cpp
@@ -170,6 +170,13 @@ void process () {
 
      if (v3Global.opt.stats()) V3Stats::statsStageAll(v3Global.rootp(), "Link");
 
+// TAS -- moved this ---\
+    // Calculate and check widths, edit tree to TRUNC/EXTRACT any width mismatches
+    V3Width::width(v3Global.rootp());
+
+    V3Error::abortIfErrors();
+// TAS -- moved this ---/
+
      // Remove parameters by cloning modules to de-parameterized versions
      //   This requires some width calculations and constant propagation
      V3Param::param(v3Global.rootp());
@@ -180,10 +187,10 @@ void process () {
      V3Dead::deadifyModules(v3Global.rootp());
      v3Global.checkTree();
 
-    // Calculate and check widths, edit tree to TRUNC/EXTRACT any width mismatches
-    V3Width::width(v3Global.rootp());
-
-    V3Error::abortIfErrors();
+//    // Calculate and check widths, edit tree to TRUNC/EXTRACT any width mismatches
+//    V3Width::width(v3Global.rootp());
+//
+//    V3Error::abortIfErrors();
 
      // Commit to the widths we've chosen; Make widthMin==width
      V3Width::widthCommit(v3Global.rootp());

And while I got enum item values to work with in the paramlink step, I also got:

TESTS Passed 587  Unsup 18  Skipped 24  Failed 82  Time 3:56

Perhaps I can extract the enum value assignment from the width step and run that before paramlink? That's what I'll try next.

@veripoolbot
Copy link
Contributor Author


Original Redmine Comment
Author Name: Wilson Snyder (@wsnyder)
Original Date: 2015-09-30T00:46:22Z


Constification causes calls to width as each individual item requires it. I suspect V3Const's AstEnumItemRef call is missing something, probably the enum item hasn't been made into a constant. Probably code line V3Const's AstFuncRef "if (m_param)" is needed in AstEnumItemRef. That is, when we see an EnumItemRef and there's no value yet, and we're parameter constifying, we need to iterate on the EnumItem to constify it.

@veripoolbot
Copy link
Contributor Author


Original Redmine Comment
Author Name: Todd Strader (@toddstrader)
Original Date: 2015-09-30T22:16:19Z


Thanks for the pointers. It seems that once again, things are simpler than I assumed.

However, I am a bit confused by what I'm currently seeing. I added an EnumItemRef visitor to V3Simulate with some debug just to see what's going on (pushed to GitHub). When I run the test while debugging V3Simulate, I get:

- V3Simulate.h:349:      simulate enumitemref nodep ENUMITEMREF 0x10b7740 <e156#> {e16} @dt=0x10bf7f0@(sw32)  LOW_FIVE -> ENUMITEM 0x10bf730 <e142#> {e10} @dt=0x10bf7f0@(sw32)  LOW_FIVE
- V3Simulate.h:351:      simulate enumitemref itemp ENUMITEM 0x10bf730 <e142#> {e10} @dt=0x10bf7f0@(sw32)  LOW_FIVE
- V3Simulate.h:353:      simulate enumitemref valuep CONST 0x10bbd00 <e144#> {e10} @dt=0x10bf530@(G/w32)  32'hdeadbef0

This seems strange to me because LOW_FIVE already seems to have the right enum item value (0xdeadbeef + 1), but I can't find this node in any of the tree dumps. Vt_static_elab_enum_007_link.tree shows :

     1:2:1:2: ENUMITEM 0x10bf610 <e10> {e9} @dt=0@  HIGH_FIVE
     1:2:1:2:2: CONST 0x10bf3f0 <e9> {e9} @dt=0x10bf530@(G/w32)  32'hdeadbeef
     1:2:1:2: ENUMITEM 0x10bf730 <e12> {e10} @dt=0@  LOW_FIVE
     1:2: FUNC 0x10bfc50 <e34> {e13} @dt=0@  gimme_five

In fact, no one has heard of this guy:

tstrader@sark:~/git/verilator_static_elab_2/test_regress$ grep 0x10bbd00 obj_dir/t_static_elab_enum/*tree
tstrader@sark:~/git/verilator_static_elab_2/test_regress$ grep deadbef0 obj_dir/t_static_elab_enum/*tree
tstrader@sark:~/git/verilator_static_elab_2/test_regress$ 

Where did LOW_FIVE's CONST node come from? And is it a problem that it doesn't show up in any of the tree dumps? Does it get created during paramlink? If so, why does paramlink say that there are no changes? Is this because the build fails?

Sorry for all the questions, just trying to get my head around what is happening here.

@veripoolbot
Copy link
Contributor Author


Original Redmine Comment
Author Name: Wilson Snyder (@wsnyder)
Original Date: 2015-09-30T23:57:17Z


Since the constant isn't part of the tree it was probably created by V3Simulate. It passes constants across itself to represent variable values related to the nodes it's simulating.

@veripoolbot
Copy link
Contributor Author


Original Redmine Comment
Author Name: Todd Strader (@toddstrader)
Original Date: 2015-10-01T22:17:10Z


GitHub repo should be ready to go now. I combined the struct and enum parameter tests since I've seen a a few tests that roll up a few things like that. Please let me know if this isn't desirable and I'll break them apart.

@veripoolbot
Copy link
Contributor Author


Original Redmine Comment
Author Name: Wilson Snyder (@wsnyder)
Original Date: 2015-10-02T01:16:01Z


Oh, that makes sense, simpler than I thought too.

Fixed in git towards 3.877.

@veripoolbot
Copy link
Contributor Author


Original Redmine Comment
Author Name: Wilson Snyder (@wsnyder)
Original Date: 2015-11-01T13:23:03Z


In 3.878.

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

2 participants