Commit ab867465 by Zachary Snow

fix handling of explicitly typed struct patterns in other contexts

parent dde734be
...@@ -152,9 +152,7 @@ traverseStmtM' = ...@@ -152,9 +152,7 @@ traverseStmtM' =
traverseStmtAsgnsM traverseAsgnM traverseStmtAsgnsM traverseAsgnM
traverseExprM :: Expr -> Scoper Type Expr traverseExprM :: Expr -> Scoper Type Expr
traverseExprM = traverseExprM = embedScopes convertSubExpr >=> return . snd
(embedScopes convertSubExpr >=> return . snd) .
(traverseNestedExprs $ traverseExprTypes convertType)
traverseLHSM :: LHS -> Scoper Type LHS traverseLHSM :: LHS -> Scoper Type LHS
traverseLHSM = convertLHS >=> return . snd traverseLHSM = convertLHS >=> return . snd
...@@ -292,10 +290,12 @@ convertExpr (struct @ (Struct _ fields [])) (Pattern itemsOrig) = ...@@ -292,10 +290,12 @@ convertExpr (struct @ (Struct _ fields [])) (Pattern itemsOrig) =
Just value = numberToInteger n Just value = numberToInteger n
Right (Number n) = item Right (Number n) = item
convertExpr _ (Cast (Left t) expr@Pattern{}) = convertExpr _ (Cast (Left t) expr) =
Cast (Left t) $ convertExpr t expr Cast (Left t') $ convertExpr t expr
where t' = convertType t
convertExpr (Implicit _ []) expr = expr convertExpr (Implicit _ []) expr =
traverseSinglyNestedExprs (convertExpr UnknownType) expr
convertExpr (Implicit sg rs) expr = convertExpr (Implicit sg rs) expr =
convertExpr (IntegerVector TBit sg rs) expr convertExpr (IntegerVector TBit sg rs) expr
...@@ -343,7 +343,8 @@ convertExpr t (Concat exprs) = ...@@ -343,7 +343,8 @@ convertExpr t (Concat exprs) =
t' = dropInnerTypeRange t t' = dropInnerTypeRange t
exprs' = map (convertExpr t') exprs exprs' = map (convertExpr t') exprs
convertExpr _ other = other convertExpr _ expr =
traverseSinglyNestedExprs (convertExpr UnknownType) expr
fallbackType :: Scopes Type -> Expr -> (Type, Expr) fallbackType :: Scopes Type -> Expr -> (Type, Expr)
fallbackType scopes e = fallbackType scopes e =
...@@ -484,7 +485,8 @@ convertSubExpr scopes e = ...@@ -484,7 +485,8 @@ convertSubExpr scopes e =
traverseSinglyNestedExprs exprMapper e traverseSinglyNestedExprs exprMapper e
where where
exprMapper = snd . convertSubExpr scopes exprMapper = snd . convertSubExpr scopes
typeMapper = traverseNestedTypes $ traverseTypeExprs exprMapper typeMapper = convertType .
traverseNestedTypes (traverseTypeExprs exprMapper)
-- get the fields and type function of a struct or union -- get the fields and type function of a struct or union
getFields :: Type -> Maybe [Field] getFields :: Type -> Maybe [Field]
......
...@@ -8,5 +8,25 @@ module top; ...@@ -8,5 +8,25 @@ module top;
shortint y; shortint y;
S z; S z;
} T; } T;
initial $display("%b", T'{ x: 1, y: 2, z: '{ x: 3, y: 4 } }); var T a;
initial a = T'{ x: 5, y: 6, z: '{ x: 7, y: 8 } };
var T b;
T c;
assign c = T'{ x: 9, y: 10, z: '{ x: 11, y: 12 } };
initial begin
b = T'{ x: 13, y: 14, z: '{ x: 15, y: 16 } };
#1;
$display("a %b", a);
$display("b %b", b);
$display("c %b", c);
$display("x %b", T'{ x: 1, y: 2, z: '{ x: 3, y: 4 } });
$display("$bits(S) = %0d", $bits(S));
$display("$bits(T) = %0d", $bits(T));
$display("$bits(a) = %0d", $bits(a));
$display("$bits(a.x) = %0d", $bits(a.x));
$display("$bits(a.y) = %0d", $bits(a.y));
$display("$bits(a.z) = %0d", $bits(a.z));
$display("$bits(a.z.x) = %0d", $bits(a.z.x));
$display("$bits(a.z.y) = %0d", $bits(a.z.y));
end
endmodule endmodule
module top; module top;
initial $display("%b", { 8'd1, 16'd2, 32'd3, 8'd4 } ); reg [63:0] a = { 8'd5, 16'd6, 32'd7, 8'd8 };
reg [63:0] b = { 8'd13, 16'd14, 32'd15, 8'd16 };
wire [63:0] c = { 8'd9, 16'd10, 32'd11, 8'd12 };
initial begin
#1;
$display("a %b", a);
$display("b %b", b);
$display("c %b", c);
$display("x %b", { 8'd1, 16'd2, 32'd3, 8'd4 } );
$display("$bits(S) = %0d", 40);
$display("$bits(T) = %0d", 64);
$display("$bits(a) = %0d", 64);
$display("$bits(a.x) = %0d", 8);
$display("$bits(a.y) = %0d", 16);
$display("$bits(a.z) = %0d", 40);
$display("$bits(a.z.x) = %0d", 32);
$display("$bits(a.z.y) = %0d", 8);
end
endmodule endmodule
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment