fix struct typing of ternary expressions (resolves #73)

This commit is contained in:
Zachary Snow 2020-02-15 14:44:36 -05:00
parent b124a561f2
commit fe8839eaec
4 changed files with 34 additions and 0 deletions

View File

@ -261,6 +261,11 @@ convertAsgn structs types (lhs, expr) =
-- try expression conversion by looking at the *outermost* type first
convertExpr :: Type -> Expr -> Expr
convertExpr t (Mux c e1 e2) =
Mux c e1' e2'
where
e1' = convertExpr t e1
e2' = convertExpr t e2
-- TODO: This is really a conversion for using default patterns to
-- populate arrays. Maybe this should be somewhere else?
convertExpr (IntegerVector t sg (r:rs)) (Pattern [(":default", e)]) =

12
test/basic/struct_tern.sv Normal file
View File

@ -0,0 +1,12 @@
module Example(flag, out);
typedef struct packed {
logic a, b;
} T;
output T out;
input logic flag;
assign out =
flag
? '{ a: 1'b1, b: 1'b0 }
: '{ a: 1'b1, b: 1'b1 }
;
endmodule

5
test/basic/struct_tern.v Normal file
View File

@ -0,0 +1,5 @@
module Example(flag, out);
output wire [1:0] out;
input wire flag;
assign out = flag ? 2'b10 : 2'b11;
endmodule

View File

@ -0,0 +1,12 @@
module top;
reg flag;
wire [1:0] out;
Example example(flag, out);
initial begin
$monitor("%2d %b %b", $time, flag, out);
#1 flag = 0;
#1 flag = 1;
#1 flag = 0;
#1 flag = 1;
end
endmodule