Commit a1cd6941 by Zachary Snow

apply patterns to substructures

parent de581eca
...@@ -358,6 +358,9 @@ convertAsgn structs types (lhs, expr) = ...@@ -358,6 +358,9 @@ convertAsgn structs types (lhs, expr) =
-- look up by name -- look up by name
if Map.member fieldName namedItemMap then if Map.member fieldName namedItemMap then
namedItemMap Map.! fieldName namedItemMap Map.! fieldName
-- recurse for substructures
else if isStruct fieldType then
Pattern specialItems
-- look up by field type -- look up by field type
else if Map.member fieldTypeName specialItemMap then else if Map.member fieldTypeName specialItemMap then
specialItemMap Map.! fieldTypeName specialItemMap Map.! fieldTypeName
...@@ -372,6 +375,9 @@ convertAsgn structs types (lhs, expr) = ...@@ -372,6 +375,9 @@ convertAsgn structs types (lhs, expr) =
fieldType = fieldTypeMap Map.! fieldName fieldType = fieldTypeMap Map.! fieldName
fieldTypeName = fieldTypeName =
specialTag : (show $ fst $ typeRanges fieldType) specialTag : (show $ fst $ typeRanges fieldType)
isStruct :: Type -> Bool
isStruct (Struct{}) = True
isStruct _ = False
convertExpr (Struct (Packed sg) fields (r : rs)) subExpr = convertExpr (Struct (Packed sg) fields (r : rs)) subExpr =
Repeat (rangeSize r) [subExpr'] Repeat (rangeSize r) [subExpr']
......
...@@ -35,6 +35,35 @@ module test; ...@@ -35,6 +35,35 @@ module test;
#1 a = '{w: 8, int: 3, byte: 2, default: 0}; #1 a = '{w: 8, int: 3, byte: 2, default: 0};
end end
typedef struct packed {
int x;
struct_a y;
logic z;
} struct_b;
struct_b b;
initial begin
#100;
$monitor("%2d: %b %b %b %b", $time, b, b.x, b.y, b.z);
#1 b.x = 0;
#1 b.y = 0;
#1 b.z = 0;
#1 b = '{default: 1};
#1 b = '{default: 2};
#1 b = '{default: 3};
#1 b = '{default: 0};
#1 b = '{default: -1};
#1 b = '{default: -2};
#1 b = '{int: 0, default: 1};
#1 b = '{byte: 0, default: 1};
#1 b = '{logic: 0, default: 1};
#1 b = '{logic: 1, int: 2, byte: 3};
#1 b = '{logic: 1, int: 2, byte: 3, default: -1};
#1 b = '{int: 3, byte: 2, default: 0};
end
endmodule endmodule
module top; endmodule module top; endmodule
...@@ -113,6 +113,120 @@ module test; ...@@ -113,6 +113,120 @@ module test;
a_z = 0; a_z = 0;
end end
end
reg [31:0] b_x;
wire [72:0] b_y;
reg b_z;
reg [105:0] b;
assign b_y = a;
always @* b = {b_x, b_y, b_z};
initial begin
#100;
a_w = 'bx;
a_x = 'bx;
a_y = 'bx;
a_z = 'bx;
$monitor("%2d: %b %b %b %b", $time, b, b_x, b_y, b_z);
#1 b_x = 0;
#1 begin
a_w = 0;
a_x = 0;
a_y = 0;
a_z = 0;
end
#1 b_z = 0;
#1 begin
a_w = 1;
a_x = 1;
a_y = 1;
a_z = 1;
b_x = 1;
b_z = 1;
end
#1 begin
a_w = 2;
a_x = 2;
a_y = 2;
a_z = 2;
b_x = 2;
b_z = 2;
end
#1 begin
a_w = 3;
a_x = 3;
a_y = 3;
a_z = 3;
b_x = 3;
b_z = 3;
end
#1 begin
a_w = 0;
a_x = 0;
a_y = 0;
a_z = 0;
b_x = 0;
b_z = 0;
end
#1 begin
a_w = -1;
a_x = -1;
a_y = -1;
a_z = -1;
b_x = -1;
b_z = -1;
end
#1 begin
a_w = -2;
a_x = -2;
a_y = -2;
a_z = -2;
b_x = -2;
b_z = -2;
end
#1 begin
a_w = 0;
a_x = 0;
a_y = 1;
a_z = 1;
b_x = 0;
b_z = 1;
end
#1 begin
a_w = 1;
a_x = 1;
a_y = 0;
a_z = 1;
b_x = 1;
b_z = 1;
end
#1 begin
a_w = 1;
a_x = 1;
a_y = 1;
a_z = 0;
b_x = 1;
b_z = 0;
end
#1 begin
a_w = 2;
a_x = 2;
a_y = 3;
a_z = 1;
b_x = 2;
b_z = 1;
end
#1;
#1 begin
a_w = 3;
a_x = 3;
a_y = 2;
a_z = 0;
b_x = 3;
b_z = 0;
end
end 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