From fe90c7bbf4888a1bc149afc261629f5dec4d7861 Mon Sep 17 00:00:00 2001 From: Zachary Snow Date: Sat, 4 Nov 2023 17:31:11 -0400 Subject: [PATCH] fix inline explicit struct casts --- CHANGELOG.md | 1 + src/Convert/Struct.hs | 7 +++++-- test/core/struct_pattern_cast.sv | 16 ++++++++++++++++ test/core/struct_pattern_cast.v | 7 +++++++ 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f849f4..59d50c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ * Fixed an issue that prevented parsing tasks and functions with `inout` ports * Fixed conflicting genvar names when inlining interfaces and modules that use them; all genvars are now given a design-wide unique name +* Fixed unconverted structs within explicit type casts * Fixed non-typenames (e.g., from packages or subsequent declarations) improperly shadowing the names of `struct` pattern fields * Fixed failure to resolve typenames suffixed with dimensions in contexts diff --git a/src/Convert/Struct.hs b/src/Convert/Struct.hs index c16e18e..9dd75a7 100644 --- a/src/Convert/Struct.hs +++ b/src/Convert/Struct.hs @@ -495,8 +495,11 @@ convertSubExpr scopes (Call e args) = (retType, _) = fallbackType scopes e args' = convertCall scopes e args convertSubExpr scopes (Cast (Left t) e) = - (t, Cast (Left t) e') - where (_, e') = convertSubExpr scopes e + (t', Cast (Left t') e') + where + e' = convertExpr scopes t $ snd $ convertSubExpr scopes e + t' = convertType t + convertSubExpr scopes (Pattern items) = if all (== Right Nil) $ map fst items' then (UnknownType, Concat $ map snd items') diff --git a/test/core/struct_pattern_cast.sv b/test/core/struct_pattern_cast.sv index 11ce360..5a0898b 100644 --- a/test/core/struct_pattern_cast.sv +++ b/test/core/struct_pattern_cast.sv @@ -29,4 +29,20 @@ module top; $display("$bits(a.z.x) = %0d", $bits(a.z.x)); $display("$bits(a.z.y) = %0d", $bits(a.z.y)); end + + typedef struct packed { + logic x; + } U; + initial begin + case (U'(0)) + U'(0): $display("1"); + endcase + if (U'(1)) + $display("2"); + case (U'{x: 0}) + U'{x: 0}: $display("3"); + endcase + if (U'{x: 1}) + $display("4"); + end endmodule diff --git a/test/core/struct_pattern_cast.v b/test/core/struct_pattern_cast.v index 06feb8a..625a387 100644 --- a/test/core/struct_pattern_cast.v +++ b/test/core/struct_pattern_cast.v @@ -17,4 +17,11 @@ module top; $display("$bits(a.z.x) = %0d", 32); $display("$bits(a.z.y) = %0d", 8); end + + initial begin + $display("1"); + $display("2"); + $display("3"); + $display("4"); + end endmodule