Commit 10885206 by Zachary Snow

prefix bare generate blocks with conditionals in codegen

parent 404385b0
...@@ -31,26 +31,31 @@ data GenItem ...@@ -31,26 +31,31 @@ data GenItem
instance Show GenItem where instance Show GenItem where
showList i _ = unlines' $ map show i showList i _ = unlines' $ map show i
show (GenBlock x i) = show (GenBlock x i) =
printf "begin%s\n%s\nend" "if (1) " ++ showBareBlock (GenBlock x i)
(if null x then "" else " : " ++ x)
(indent $ show i)
show (GenCase e cs) = show (GenCase e cs) =
printf "case (%s)\n%s\nendcase" (show e) bodyStr printf "case (%s)\n%s\nendcase" (show e) bodyStr
where bodyStr = indent $ unlines' $ map showGenCase cs where bodyStr = indent $ unlines' $ map showGenCase cs
show (GenIf e a GenNull) = printf "if (%s) %s" (show e) (show a) show (GenIf e a GenNull) = printf "if (%s) %s" (show e) (showBareBlock a)
show (GenIf e a b ) = printf "if (%s) %s\nelse %s" (show e) (showBlockedBranch a) (show b) show (GenIf e a b ) = printf "if (%s) %s\nelse %s" (show e) (showBlockedBranch a) (showBareBlock b)
show (GenFor (x1, e1) c (x2, o2, e2) s) = show (GenFor (x1, e1) c (x2, o2, e2) s) =
printf "for (%s = %s; %s; %s %s %s) %s" printf "for (%s = %s; %s; %s %s %s) %s"
x1 (show e1) x1 (show e1)
(show c) (show c)
x2 (show o2) (show e2) x2 (show o2) (show e2)
(if s == GenNull then "begin end" else show s) (if s == GenNull then "begin end" else showBareBlock s)
show (GenNull) = ";" show (GenNull) = ";"
show (GenModuleItem item) = show item show (GenModuleItem item) = show item
showBareBlock :: GenItem -> String
showBareBlock (GenBlock x i) =
printf "begin%s\n%s\nend"
(if null x then "" else " : " ++ x)
(indent $ show i)
showBareBlock item = show item
showBlockedBranch :: GenItem -> String showBlockedBranch :: GenItem -> String
showBlockedBranch genItem = showBlockedBranch genItem =
show $ showBareBlock $
if isControl genItem if isControl genItem
then GenBlock "" [genItem] then GenBlock "" [genItem]
else genItem else genItem
...@@ -65,5 +70,5 @@ showBlockedBranch genItem = ...@@ -65,5 +70,5 @@ showBlockedBranch genItem =
type GenCase = ([Expr], GenItem) type GenCase = ([Expr], GenItem)
showGenCase :: GenCase -> String showGenCase :: GenCase -> String
showGenCase (a, b) = printf "%s: %s" exprStr (show b) showGenCase (a, b) = printf "%s: %s" exprStr (showBareBlock b)
where exprStr = if null a then "default" else commas $ map show a where exprStr = if null a then "default" else commas $ map show a
...@@ -11,7 +11,7 @@ module top; ...@@ -11,7 +11,7 @@ module top;
assign c = x ? d : e; assign c = x ? d : e;
generate generate
begin : A if (1) begin : A
wire [1:0] c [0:2]; wire [1:0] c [0:2];
wire [5:0] d; wire [5:0] d;
end end
......
module top; module top;
generate generate
begin : A if (1) begin : A
reg signed [31:0] x; reg signed [31:0] x;
end end
endgenerate endgenerate
......
...@@ -3,13 +3,13 @@ module top; ...@@ -3,13 +3,13 @@ module top;
initial $display("A t %0d", 1); initial $display("A t %0d", 1);
initial $display("A top.t %0d", 1); initial $display("A top.t %0d", 1);
generate generate
begin : X if (1) begin : X
wire [1:0] t; wire [1:0] t;
initial $display("B t %0d", 2); initial $display("B t %0d", 2);
initial $display("B top.t %0d", 1); initial $display("B top.t %0d", 1);
initial $display("B X.t %0d", 2); initial $display("B X.t %0d", 2);
initial $display("B top.X.t %0d", 2); initial $display("B top.X.t %0d", 2);
begin : Y if (1) begin : Y
wire [2:0] t; wire [2:0] t;
initial $display("C t %0d", 3); initial $display("C t %0d", 3);
initial $display("C top.t %0d", 1); initial $display("C top.t %0d", 1);
...@@ -46,7 +46,7 @@ module top; ...@@ -46,7 +46,7 @@ module top;
wire [11:0] arr; wire [11:0] arr;
generate generate
begin : M if (1) begin : M
wire [19:0] arr; wire [19:0] arr;
initial $display("M arr[0] = %b", arr[4:0]); initial $display("M arr[0] = %b", arr[4:0]);
initial $display("M M.arr[0] = %b", M.arr[4:0]); initial $display("M M.arr[0] = %b", M.arr[4:0]);
......
...@@ -33,7 +33,7 @@ module top; ...@@ -33,7 +33,7 @@ module top;
generate generate
begin : intf if (1) begin : intf
wire [N-1:0] req; wire [N-1:0] req;
end end
genvar j; genvar j;
......
...@@ -2,7 +2,7 @@ module top; ...@@ -2,7 +2,7 @@ module top;
genvar g; genvar g;
localparam SOME_VAL = 3; localparam SOME_VAL = 3;
generate generate
begin : i if (1) begin : i
wire x = 0; wire x = 0;
initial $display("Interface %d %d", x, SOME_VAL); initial $display("Interface %d %d", x, SOME_VAL);
for (g = 10; g < 15; g = g + 1) begin for (g = 10; g < 15; g = g + 1) begin
...@@ -11,7 +11,7 @@ module top; ...@@ -11,7 +11,7 @@ module top;
end end
endgenerate endgenerate
generate generate
begin : m if (1) begin : m
initial $display("Module %d", i.x); initial $display("Module %d", i.x);
for (g = 0; g < 5; g = g + 1) begin for (g = 0; g < 5; g = g + 1) begin
initial $display(g); initial $display(g);
......
module top; module top;
wire x = 1; wire x = 1;
generate generate
begin : f if (1) begin : f
wire x; wire x;
begin : a if (1) begin : a
wire x; wire x;
initial begin initial begin
$display("bar got %b", x); $display("bar got %b", x);
end end
end end
assign a.x = x; assign a.x = x;
begin : b if (1) begin : b
wire x; wire x;
initial begin initial begin
$display("bar got %b", x); $display("bar got %b", x);
......
...@@ -13,10 +13,10 @@ endmodule ...@@ -13,10 +13,10 @@ endmodule
module top; module top;
generate generate
begin : x if (1) begin : x
wire [31:0] data = 0; wire [31:0] data = 0;
end end
begin : y if (1) begin : y
wire [9:0] data = 0; wire [9:0] data = 0;
end end
endgenerate endgenerate
......
module top; module top;
generate generate
begin : x if (1) begin : x
integer x; integer x;
function z; function z;
input x; input x;
...@@ -10,7 +10,7 @@ module top; ...@@ -10,7 +10,7 @@ module top;
endgenerate endgenerate
initial x.x = 1; initial x.x = 1;
generate generate
begin : y if (1) begin : y
function z; function z;
input x; input x;
z = x; z = x;
......
module top; module top;
generate generate
begin : i if (1) begin : i
wire [3:0] x; wire [3:0] x;
reg [1:0] w; reg [1:0] w;
end end
......
...@@ -19,12 +19,12 @@ module top; ...@@ -19,12 +19,12 @@ module top;
end end
generate generate
begin : A if (1) begin : A
wire x; wire x;
begin : B if (1) begin : B
reg x; reg x;
end end
begin : C if (1) begin : C
wire x; wire x;
end end
assign x = B.x ^ C.x; assign x = B.x ^ C.x;
......
...@@ -3,7 +3,7 @@ module top; ...@@ -3,7 +3,7 @@ module top;
$display("tick() called"); $display("tick() called");
endtask endtask
generate generate
begin : foo if (1) begin : foo
task tick; task tick;
$display("foo.tick() called"); $display("foo.tick() called");
endtask endtask
......
...@@ -4,7 +4,7 @@ module top; ...@@ -4,7 +4,7 @@ module top;
wire [17:0] c; wire [17:0] c;
generate generate
begin : foo if (1) begin : foo
wire [2:0] a; wire [2:0] a;
wire [14:0] b; wire [14:0] b;
wire [17:0] c; wire [17:0] c;
......
...@@ -21,7 +21,6 @@ simulate() { ...@@ -21,7 +21,6 @@ simulate() {
iv_output=`iverilog \ iv_output=`iverilog \
-Wall \ -Wall \
-Wno-select-range \ -Wno-select-range \
-Wno-anachronisms \
-Wno-portbind \ -Wno-portbind \
-o $sim_prog \ -o $sim_prog \
-g2005 \ -g2005 \
......
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