Commit 5f0dc6be by Zachary Snow

preserve generate else branch association in codegen

parent e4adf6a7
......@@ -38,7 +38,7 @@ instance Show GenItem where
printf "case (%s)\n%s\nendcase" (show e) bodyStr
where bodyStr = indent $ unlines' $ map showGenCase cs
show (GenIf e a GenNull) = printf "if (%s) %s" (show e) (show a)
show (GenIf e a b ) = printf "if (%s) %s\nelse %s" (show e) (show a) (show b)
show (GenIf e a b ) = printf "if (%s) %s\nelse %s" (show e) (showBlockedBranch a) (show b)
show (GenFor (x1, e1) c (x2, o2, e2) s) =
printf "for (%s = %s; %s; %s %s %s) %s"
x1 (show e1)
......@@ -48,6 +48,20 @@ instance Show GenItem where
show (GenNull) = ";"
show (GenModuleItem item) = show item
showBlockedBranch :: GenItem -> String
showBlockedBranch genItem =
show $
if isControl genItem
then GenBlock "" [genItem]
else genItem
where
isControl :: GenItem -> Bool
isControl GenIf{} = True
isControl GenFor{} = True
isControl GenCase{} = True
isControl GenModuleItem{} = True
isControl _ = False
type GenCase = ([Expr], GenItem)
showGenCase :: GenCase -> String
......
module Example;
parameter X = 1;
parameter Y = 1;
parameter Z = 1;
initial $display("X=%0d Y=%0d Z=%0d Example", X, Y, Z);
generate
if (X) begin
if (Y) begin
if (Z) begin
initial $display("X=%0d Y=%0d Z=%0d A", X, Y, Z);
end
end
else begin
initial $display("X=%0d Y=%0d Z=%0d B", X, Y, Z);
end
end
initial
if (X) begin
if (Y) begin
if (Z) begin
$display("X=%0d Y=%0d Z=%0d C", X, Y, Z);
end
end
else begin
$display("X=%0d Y=%0d Z=%0d D", X, Y, Z);
end
end
if (X) begin
initial
if (Y) begin
if (Z) begin
$display("X=%0d Y=%0d Z=%0d E", X, Y, Z);
end
end
else begin
$display("X=%0d Y=%0d Z=%0d F", X, Y, Z);
end
end
if (X) begin
if (Y) begin
initial
if (Z) begin
$display("X=%0d Y=%0d Z=%0d G", X, Y, Z);
end
end
else begin
initial $display("X=%0d Y=%0d Z=%0d H", X, Y, Z);
end
end
endgenerate
endmodule
module top;
Example #(0, 0, 0) e000();
Example #(0, 0, 1) e001();
Example #(0, 1, 0) e010();
Example #(0, 1, 1) e011();
Example #(1, 0, 0) e100();
Example #(1, 0, 1) e101();
Example #(1, 1, 0) e110();
Example #(1, 1, 1) e111();
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