Bugfix in name resolution with generate blocks
authorClifford Wolf <clifford@clifford.at>
Thu, 30 Jan 2014 13:52:46 +0000 (14:52 +0100)
committerClifford Wolf <clifford@clifford.at>
Thu, 30 Jan 2014 14:01:28 +0000 (15:01 +0100)
frontends/ast/simplify.cc
tests/simple/carryadd.v [new file with mode: 0644]

index bd5da14e3d3a2fb62e3c7c5166eeec826fda753a..5a2d1ae6c4e8847c08f0bf6f79077f7a25f3f304 100644 (file)
@@ -1478,7 +1478,7 @@ void AstNode::expand_genblock(std::string index_var, std::string prefix, std::ma
 
        for (size_t i = 0; i < children.size(); i++) {
                AstNode *child = children[i];
-               if (child->type != AST_FUNCTION && child->type != AST_TASK)
+               if (child->type != AST_FUNCTION && child->type != AST_TASK && child->type != AST_PREFIX)
                        child->expand_genblock(index_var, prefix, name_map);
        }
 
diff --git a/tests/simple/carryadd.v b/tests/simple/carryadd.v
new file mode 100644 (file)
index 0000000..4f777f7
--- /dev/null
@@ -0,0 +1,24 @@
+module carryadd(a, b, y);
+
+parameter WIDTH = 8;
+
+input [WIDTH-1:0] a, b;
+output [WIDTH-1:0] y;
+
+genvar i;
+generate
+       for (i = 0; i < WIDTH; i = i+1) begin:STAGE
+               wire IN1 = a[i], IN2 = b[i];
+               wire C, Y;
+               if (i == 0)
+                       assign C = IN1 & IN2, Y = IN1 ^ IN2;
+               else
+                       assign C = (IN1 & IN2) | ((IN1 | IN2) & STAGE[i-1].C),
+                              Y = IN1 ^ IN2 ^ STAGE[i-1].C;
+               assign y[i] = Y;
+       end
+endgenerate
+
+// assert property (y == a + b);
+
+endmodule