sv: allow globals in one file to depend on globals in another
authorZachary Snow <zach@zachjs.com>
Thu, 11 Mar 2021 18:05:04 +0000 (13:05 -0500)
committerZachary Snow <zach@zachjs.com>
Fri, 12 Mar 2021 16:22:41 +0000 (11:22 -0500)
This defers the simplification of globals so that globals in one file
may depend on globals in other files. Adds a simplify() call downstream
because globals are appended at the end.

frontends/ast/ast.cc
frontends/ast/simplify.cc
tests/verilog/parameters_across_files.ys [new file with mode: 0644]

index 06e2e23a8393c775e89b0537e39d8741fb6d6159..7aa391c93ac2c1ee094da9ded72d860df680f2b1 100644 (file)
@@ -1288,7 +1288,6 @@ void AST::process(RTLIL::Design *design, AstNode *ast, bool dump_ast1, bool dump
                        // must be global definition
                        if ((*it)->type == AST_PARAMETER)
                                (*it)->type = AST_LOCALPARAM; // cannot be overridden
-                       (*it)->simplify(false, false, false, 1, -1, false, false); //process enum/other declarations
                        design->verilog_globals.push_back((*it)->clone());
                        current_scope.clear();
                }
index e0ac58f205da822d1aa842e46e48561b90ce057a..d68b13b2a9aee5bd499dbc0abd5c3a3894dd173b 100644 (file)
@@ -192,6 +192,7 @@ void AstNode::annotateTypedEnums(AstNode *template_node)
                log_assert(current_scope.count(enum_type) == 1);
                AstNode *enum_node = current_scope.at(enum_type);
                log_assert(enum_node->type == AST_ENUM);
+               while (enum_node->simplify(true, false, false, 1, -1, false, true)) { }
                //get width from 1st enum item:
                log_assert(enum_node->children.size() >= 1);
                AstNode *enum_item0 = enum_node->children[0];
diff --git a/tests/verilog/parameters_across_files.ys b/tests/verilog/parameters_across_files.ys
new file mode 100644 (file)
index 0000000..c53e401
--- /dev/null
@@ -0,0 +1,20 @@
+read_verilog -sv <<EOF
+parameter Q = 1;
+EOF
+read_verilog -sv <<EOF
+parameter P = Q;
+module top(
+    output integer out
+);
+    assign out = P;
+    always @*
+        assert (out == 1);
+endmodule
+EOF
+
+hierarchy
+proc
+flatten
+opt -full
+select -module top
+sat -verify -seq 1 -tempinduct -prove-asserts -show-all