From 995a893afdae5710b2986824fbd82b07e1aa02ad Mon Sep 17 00:00:00 2001 From: Krystine Sherwin <93062060+KrystalDelusion@users.noreply.github.com> Date: Mon, 26 May 2025 12:16:58 +1200 Subject: [PATCH 1/2] Tests: Add svtypes/typedef_struct_global.ys --- tests/svtypes/typedef_struct_global.ys | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 tests/svtypes/typedef_struct_global.ys diff --git a/tests/svtypes/typedef_struct_global.ys b/tests/svtypes/typedef_struct_global.ys new file mode 100644 index 000000000..0fed440e4 --- /dev/null +++ b/tests/svtypes/typedef_struct_global.ys @@ -0,0 +1,13 @@ +read_verilog -sv << EOF +typedef struct packed { + logic y; + logic x; +} Vec_2_B; + +module top; + + Vec_2_B two_dee; + wire foo = two_dee.x; + +endmodule +EOF From 32ce23458faaaae453f6ba5a1180b1931385179e Mon Sep 17 00:00:00 2001 From: Krystine Sherwin <93062060+KrystalDelusion@users.noreply.github.com> Date: Mon, 26 May 2025 12:19:33 +1200 Subject: [PATCH 2/2] read_verilog: Mark struct as custom type Being a custom type means that it will be resolved *before* (e.g.) a wire can use it as a type. --- frontends/ast/simplify.cc | 1 + frontends/verilog/verilog_parser.y | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/frontends/ast/simplify.cc b/frontends/ast/simplify.cc index 55087c772..749767743 100644 --- a/frontends/ast/simplify.cc +++ b/frontends/ast/simplify.cc @@ -1433,6 +1433,7 @@ bool AstNode::simplify(bool const_fold, int stage, int width_hint, bool sign_hin current_ast_mod->children.push_back(wnode); } basic_prep = true; + is_custom_type = false; } break; diff --git a/frontends/verilog/verilog_parser.y b/frontends/verilog/verilog_parser.y index 9d0956c8e..68c3ec6ff 100644 --- a/frontends/verilog/verilog_parser.y +++ b/frontends/verilog/verilog_parser.y @@ -1855,7 +1855,7 @@ struct_decl: } ; -struct_type: struct_union { astbuf2 = $1; } struct_body { $$ = astbuf2; } +struct_type: struct_union { astbuf2 = $1; astbuf2->is_custom_type = true; } struct_body { $$ = astbuf2; } ; struct_union: