From fd56cb6d2b841d018481d244e3ed3b2e1860727e Mon Sep 17 00:00:00 2001 From: Alain Dargelas Date: Mon, 13 Nov 2023 21:15:44 -0800 Subject: [PATCH] Package enum const pushing --- frontends/systemverilog/uhdm_ast_frontend.cc | 4 +++- .../uhdm_surelog_ast_frontend.cc | 4 +++- tests/formal/passlist.txt | 1 + .../PackageEnumConstPush/Makefile.in | 2 ++ .../simple_tests/PackageEnumConstPush/dut.sv | 23 +++++++++++++++++++ .../PackageEnumConstPush/yosys_script.tcl | 6 +++++ third_party/surelog | 2 +- 7 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 tests/simple_tests/PackageEnumConstPush/Makefile.in create mode 100644 tests/simple_tests/PackageEnumConstPush/dut.sv create mode 100644 tests/simple_tests/PackageEnumConstPush/yosys_script.tcl diff --git a/frontends/systemverilog/uhdm_ast_frontend.cc b/frontends/systemverilog/uhdm_ast_frontend.cc index 8e7b8574c..5d3e4ad3a 100644 --- a/frontends/systemverilog/uhdm_ast_frontend.cc +++ b/frontends/systemverilog/uhdm_ast_frontend.cc @@ -43,8 +43,10 @@ struct UhdmAstFrontend : public UhdmCommonFrontend { UHDM::Serializer serializer; std::vector restoredDesigns = serializer.Restore(filename); + vpiHandle designH = restoredDesigns.at(0); + UHDM::design *design = UhdmDesignFromVpiHandle(designH); UHDM::SynthSubset *synthSubset = - make_new_object_with_optional_extra_true_arg(&serializer, this->shared.nonSynthesizableObjects, false); + make_new_object_with_optional_extra_true_arg(&serializer, this->shared.nonSynthesizableObjects, design, false); synthSubset->listenDesigns(restoredDesigns); delete synthSubset; UhdmAst uhdm_ast(this->shared); diff --git a/frontends/systemverilog/uhdm_surelog_ast_frontend.cc b/frontends/systemverilog/uhdm_surelog_ast_frontend.cc index 0bdecff3b..37655574f 100644 --- a/frontends/systemverilog/uhdm_surelog_ast_frontend.cc +++ b/frontends/systemverilog/uhdm_surelog_ast_frontend.cc @@ -201,9 +201,11 @@ struct UhdmSurelogAstFrontend : public UhdmCommonFrontend { // `-defer` turns elaboration off, so check for it // Should be called 1. for normal flow 2. after finishing with `-link` if (!this->shared.defer) { + vpiHandle designH = uhdm_designs.at(0); + UHDM::design *design = UhdmDesignFromVpiHandle(designH); UHDM::Serializer serializer; UHDM::SynthSubset *synthSubset = - make_new_object_with_optional_extra_true_arg(&serializer, this->shared.nonSynthesizableObjects, false); + make_new_object_with_optional_extra_true_arg(&serializer, this->shared.nonSynthesizableObjects, design, false); synthSubset->listenDesigns(uhdm_designs); delete synthSubset; } diff --git a/tests/formal/passlist.txt b/tests/formal/passlist.txt index 4683274f1..e9151e8b3 100644 --- a/tests/formal/passlist.txt +++ b/tests/formal/passlist.txt @@ -157,6 +157,7 @@ simple:OneReplicate/dut.v simple:OneStruct/dut.sv simple:OneSysFunc/dut.v simple:PackageCast/dut.v +simple:PackageEnumConstPush/dut.sv simple:PackageLogicTypespec/dut.sv simple:PackedArray/top.sv simple:PackedArrayPort/top.sv diff --git a/tests/simple_tests/PackageEnumConstPush/Makefile.in b/tests/simple_tests/PackageEnumConstPush/Makefile.in new file mode 100644 index 000000000..a1e826ead --- /dev/null +++ b/tests/simple_tests/PackageEnumConstPush/Makefile.in @@ -0,0 +1,2 @@ +TEST_FILES := $(TEST_DIR)/dut.sv +TOP_MODULE := dut diff --git a/tests/simple_tests/PackageEnumConstPush/dut.sv b/tests/simple_tests/PackageEnumConstPush/dut.sv new file mode 100644 index 000000000..4d82cf802 --- /dev/null +++ b/tests/simple_tests/PackageEnumConstPush/dut.sv @@ -0,0 +1,23 @@ +package pkg; + + typedef enum logic { + TEST_1, + TEST_2 + } test_t; + + function test_t swap(test_t test); + unique case (test) + TEST_1: return TEST_2; // works with pkg::TEST_1 + TEST_2: return TEST_1; // works with pkg::TEST_2 + endcase + endfunction + +endpackage + +module dut ( + input logic clk, + input pkg::test_t a, + output pkg::test_t b +); + always_comb b = pkg::swap(a); +endmodule diff --git a/tests/simple_tests/PackageEnumConstPush/yosys_script.tcl b/tests/simple_tests/PackageEnumConstPush/yosys_script.tcl new file mode 100644 index 000000000..034f00069 --- /dev/null +++ b/tests/simple_tests/PackageEnumConstPush/yosys_script.tcl @@ -0,0 +1,6 @@ +source ../yosys_common.tcl + +prep -top \\dut +write_verilog +write_verilog yosys.sv +sim -rstlen 10 -vcd dump.vcd diff --git a/third_party/surelog b/third_party/surelog index af495514d..a5149e86e 160000 --- a/third_party/surelog +++ b/third_party/surelog @@ -1 +1 @@ -Subproject commit af495514d296448dd7633371134a20a5f79cd5ad +Subproject commit a5149e86ece90980c04b0712e8e5d79593be6f94