From 1f24ae37264be378bdbcb8efc62b734ae541a628 Mon Sep 17 00:00:00 2001 From: Kamil Rakoczy Date: Mon, 14 Feb 2022 16:11:55 +0100 Subject: [PATCH] Update yosys Signed-off-by: Kamil Rakoczy --- yosys | 2 +- ...d-support-for-accessing-whole-struct.patch | 94 --------------- yosys-patches/0004-Update-tests.patch | 107 ------------------ 3 files changed, 1 insertion(+), 202 deletions(-) delete mode 100644 yosys-patches/0003-Add-support-for-accessing-whole-struct.patch delete mode 100644 yosys-patches/0004-Update-tests.patch diff --git a/yosys b/yosys index 59738c09b..15a4e900b 160000 --- a/yosys +++ b/yosys @@ -1 +1 @@ -Subproject commit 59738c09beb3ba43a693b77eb4545122a99df7d2 +Subproject commit 15a4e900b2e8f61464c7d24751b1d0182a894a1b diff --git a/yosys-patches/0003-Add-support-for-accessing-whole-struct.patch b/yosys-patches/0003-Add-support-for-accessing-whole-struct.patch deleted file mode 100644 index 873a0b01f..000000000 --- a/yosys-patches/0003-Add-support-for-accessing-whole-struct.patch +++ /dev/null @@ -1,94 +0,0 @@ -From 9e9d71d10c37dd9c80c3a9e8d3544567dcc2f0cc Mon Sep 17 00:00:00 2001 -From: Kamil Rakoczy -Date: Mon, 22 Nov 2021 15:02:27 +0100 -Subject: [PATCH 3/4] Add support for accessing whole struct - -Signed-off-by: Kamil Rakoczy ---- - frontends/ast/genrtlil.cc | 2 +- - frontends/ast/simplify.cc | 24 ++++++++++++++++++------ - 2 files changed, 19 insertions(+), 7 deletions(-) - -diff --git a/frontends/ast/genrtlil.cc b/frontends/ast/genrtlil.cc -index 4c25287ad..020b4e5e8 100644 ---- a/frontends/ast/genrtlil.cc -+++ b/frontends/ast/genrtlil.cc -@@ -877,7 +877,7 @@ void AstNode::detectSignWidthWorker(int &width_hint, bool &sign_hint, bool *foun - this_width = id_ast->children[0]->range_left - id_ast->children[0]->range_right + 1; - if (children.size() > 1) - range = children[1]; -- } else if (id_ast->type == AST_STRUCT_ITEM) { -+ } else if (id_ast->type == AST_STRUCT_ITEM || id_ast->type == AST_STRUCT) { - AstNode *tmp_range = make_struct_member_range(this, id_ast); - this_width = tmp_range->range_left - tmp_range->range_right + 1; - delete tmp_range; -diff --git a/frontends/ast/simplify.cc b/frontends/ast/simplify.cc -index 653c64e65..1105c0687 100644 ---- a/frontends/ast/simplify.cc -+++ b/frontends/ast/simplify.cc -@@ -307,6 +307,10 @@ static int size_packed_struct(AstNode *snode, int base_offset) - if (node->type == AST_STRUCT || node->type == AST_UNION) { - // embedded struct or union - width = size_packed_struct(node, base_offset + offset); -+ // set range of struct -+ node->range_right = base_offset + offset; -+ node->range_left = base_offset + offset + width - 1; -+ node->range_valid = true; - } - else { - log_assert(node->type == AST_STRUCT_ITEM); -@@ -493,14 +497,12 @@ static void add_members_to_scope(AstNode *snode, std::string name) - // in case later referenced in assignments - log_assert(snode->type==AST_STRUCT || snode->type==AST_UNION); - for (auto *node : snode->children) { -+ auto member_name = name + "." + node->str; -+ current_scope[member_name] = node; - if (node->type != AST_STRUCT_ITEM) { - // embedded struct or union - add_members_to_scope(node, name + "." + node->str); - } -- else { -- auto member_name = name + "." + node->str; -- current_scope[member_name] = node; -- } - } - } - -@@ -509,7 +511,7 @@ static int get_max_offset(AstNode *node) - // get the width from the MS member in the struct - // as members are laid out from left to right in the packed wire - log_assert(node->type==AST_STRUCT || node->type==AST_UNION); -- while (node->type != AST_STRUCT_ITEM) { -+ while (node->range_left < 0) { - node = node->children[0]; - } - return node->range_left; -@@ -1341,6 +1343,16 @@ bool AstNode::simplify(bool const_fold, bool at_zero, bool in_lvalue, int stage, - - case AST_PARAMETER: - case AST_LOCALPARAM: -+ // if parameter is implicite type which is the typename of a struct or union, -+ // save information about struct in wiretype attribute -+ if (children[0]->type == AST_IDENTIFIER && current_scope.count(children[0]->str) > 0) { -+ auto item_node = current_scope[children[0]->str]; -+ if (item_node->type == AST_STRUCT || item_node->type == AST_UNION) { -+ attributes[ID::wiretype] = item_node->clone(); -+ size_packed_struct(attributes[ID::wiretype], 0); -+ add_members_to_scope(attributes[ID::wiretype], str); -+ } -+ } - while (!children[0]->basic_prep && children[0]->simplify(false, false, false, stage, -1, false, true) == true) - did_something = true; - children[0]->detectSignWidth(width_hint, sign_hint); -@@ -2018,7 +2030,7 @@ bool AstNode::simplify(bool const_fold, bool at_zero, bool in_lvalue, int stage, - if (name_has_dot(str, sname)) { - if (current_scope.count(str) > 0) { - auto item_node = current_scope[str]; -- if (item_node->type == AST_STRUCT_ITEM) { -+ if (item_node->type == AST_STRUCT_ITEM || item_node->type == AST_STRUCT) { - // structure member, rewrite this node to reference the packed struct wire - auto range = make_struct_member_range(this, item_node); - newNode = new AstNode(AST_IDENTIFIER, range); --- -2.33.1 - diff --git a/yosys-patches/0004-Update-tests.patch b/yosys-patches/0004-Update-tests.patch deleted file mode 100644 index e7b3e9237..000000000 --- a/yosys-patches/0004-Update-tests.patch +++ /dev/null @@ -1,107 +0,0 @@ -From ea1a6d9e32b34febf1edd7437ddfd0d39d3c6323 Mon Sep 17 00:00:00 2001 -From: Kamil Rakoczy -Date: Mon, 22 Nov 2021 15:02:36 +0100 -Subject: [PATCH 4/4] Update tests - -Signed-off-by: Kamil Rakoczy ---- - tests/various/param_struct.ys | 3 +-- - tests/various/struct_access.sv | 43 ++++++++++++++++++++++++++++++++++ - tests/various/struct_access.ys | 4 ++++ - tests/verilog/struct_access.sv | 5 ++-- - 4 files changed, 50 insertions(+), 5 deletions(-) - create mode 100644 tests/various/struct_access.sv - create mode 100644 tests/various/struct_access.ys - -diff --git a/tests/various/param_struct.ys b/tests/various/param_struct.ys -index 6d7a7c6ad..b8de67968 100644 ---- a/tests/various/param_struct.ys -+++ b/tests/various/param_struct.ys -@@ -41,8 +41,7 @@ always_comb begin - assert(j == 1'b1); - assert(k == 1'b0); - assert(l == 3'b111); --// TODO: support access to whole sub-structs and unions --// assert(m == 2'b10); -+ assert(m == 2'b10); - assert(u == 5'b11001); - end - endmodule -diff --git a/tests/various/struct_access.sv b/tests/various/struct_access.sv -new file mode 100644 -index 000000000..d41a7114f ---- /dev/null -+++ b/tests/various/struct_access.sv -@@ -0,0 +1,43 @@ -+module dut(); -+typedef struct packed { -+ logic a; -+ logic b; -+} sub_sub_struct_t; -+ -+typedef struct packed { -+ sub_sub_struct_t c; -+} sub_struct_t; -+ -+typedef struct packed { -+ sub_struct_t d; -+ sub_struct_t e; -+} struct_t; -+ -+parameter struct_t P = 4'b1100; -+ -+localparam sub_struct_t f = P.d; -+localparam sub_struct_t g = P.e; -+localparam sub_sub_struct_t h = f.c; -+localparam logic i = P.d.c.a; -+localparam logic j = P.d.c.b; -+localparam x = P.e; -+localparam y = x.c; -+localparam z = y.a; -+localparam q = P.d; -+localparam n = q.c.a; -+ -+always_comb begin -+ assert(P == 4'b1100); -+ assert(f == 2'b11); -+ assert(g == 2'b00); -+ assert(h == 2'b11); -+ assert(i == 1'b1); -+ assert(j == 1'b1); -+ assert(x == 2'b00); -+ assert(y == 2'b00); -+ assert(x.c == 2'b00); -+ assert(y.b == 1'b0); -+ assert(n == 1'b1); -+ assert(z == 1'b0); -+end -+endmodule -diff --git a/tests/various/struct_access.ys b/tests/various/struct_access.ys -new file mode 100644 -index 000000000..1dfebd258 ---- /dev/null -+++ b/tests/various/struct_access.ys -@@ -0,0 +1,4 @@ -+read_verilog -sv struct_access.sv -+hierarchy; proc; opt -+sat -verify -seq 1 -prove-asserts -show-all -+ -diff --git a/tests/verilog/struct_access.sv b/tests/verilog/struct_access.sv -index f13b8dd51..bc91e3f01 100644 ---- a/tests/verilog/struct_access.sv -+++ b/tests/verilog/struct_access.sv -@@ -77,9 +77,8 @@ module top; - `CHECK(s.y.a, 1, 0) - `CHECK(s.y.b, 1, 1) - -- // TODO(zachjs): support access to whole sub-structs and unions -- // `CHECK(s.x, 2, 0) -- // `CHECK(s.y, 2, 1) -+ `CHECK(s.x, 2, 0) -+ `CHECK(s.y, 2, 1) - - assert (fail === 0); - end --- -2.33.1 -