avoid unnecessary casts on substituted hierarchical constants

This commit is contained in:
Zachary Snow 2021-07-24 17:01:17 -04:00
parent 46be0edbdf
commit 121fea5aec
4 changed files with 31 additions and 2 deletions

View File

@ -99,7 +99,7 @@ traverseStmtM stmt = do
return stmt'
traverseExprM :: Expr -> SC Expr
traverseExprM (Cast (Left (IntegerVector _ sg rs)) value) = do
traverseExprM (Cast (Left (IntegerVector kw sg rs)) value) | kw /= TBit = do
value' <- traverseExprM value
size' <- traverseExprM size
convertCastM size' value' signed

View File

@ -71,7 +71,10 @@ traverseDeclM decl = do
scopeExpr e >>= insertElem x . Right
Param Localparam (Implicit sg rs) x e ->
scopeExpr (Cast (Left t) e) >>= insertElem x . Right
where t = IntegerVector TLogic sg rs
where t = IntegerVector TBit sg rs
Param Localparam (IntegerVector _ sg rs) x e ->
scopeExpr (Cast (Left t) e) >>= insertElem x . Right
where t = IntegerVector TBit sg rs
Param Localparam t x e ->
scopeExpr (Cast (Left t) e) >>= insertElem x . Right
_ -> return ()

View File

@ -0,0 +1,19 @@
module top;
typedef struct packed {
int A;
byte B;
shortint C;
} T;
localparam T Q = '{ A: 1, B: 2, C: 3 };
if (1) begin : blk
localparam T P = Q;
logic [P.A - 1:0] a;
logic [P.B - 1:0] b;
logic [P.C - 1:0] c;
end
initial begin
$display("%b", $bits(blk.a));
$display("%b", $bits(blk.b));
$display("%b", $bits(blk.c));
end
endmodule

View File

@ -0,0 +1,7 @@
module top;
initial begin
$display("%b", 32'd1);
$display("%b", 8'd2);
$display("%b", 16'd3);
end
endmodule