Skip to content

Commit 2a2d819

Browse files
committed
additional codegen test coverage
- assertions, gen case, and inout - simplify block codegen - remove blank lines in tasks with no inputs
1 parent 2311d3e commit 2a2d819

File tree

11 files changed

+96
-16
lines changed

11 files changed

+96
-16
lines changed

src/Language/SystemVerilog/AST/Description.hs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ module Language.SystemVerilog.AST.Description
1313
) where
1414

1515
import Data.Maybe (fromMaybe)
16-
import Data.List (intercalate)
1716
import Text.Printf (printf)
1817

1918
import Language.SystemVerilog.AST.ShowHelp
@@ -31,7 +30,7 @@ data Description
3130
deriving Eq
3231

3332
instance Show Description where
34-
showList descriptions _ = intercalate "\n" $ map show descriptions
33+
showList l _ = unlines' $ map show l
3534
show (Part attrs True kw lifetime name _ items) =
3635
printf "%sextern %s %s%s %s;"
3736
(concatMap showPad attrs)
@@ -66,13 +65,11 @@ data PackageItem
6665
instance Show PackageItem where
6766
show (Typedef t x) = printf "typedef %s %s;" (show t) x
6867
show (Function ml t x i b) =
69-
printf "function %s%s%s;\n%s\n%s\nendfunction"
70-
(showPad ml) (showPad t) x (indent $ show i)
71-
(indent $ unlines' $ map show b)
68+
printf "function %s%s%s;\n%s\nendfunction" (showPad ml) (showPad t) x
69+
(showBlock i b)
7270
show (Task ml x i b) =
73-
printf "task %s%s;\n%s\n%s\nendtask"
74-
(showPad ml) x (indent $ show i)
75-
(indent $ unlines' $ map show b)
71+
printf "task %s%s;\n%s\nendtask"
72+
(showPad ml) x (showBlock i b)
7673
show (Import x y) = printf "import %s::%s;" x (fromMaybe "*" y)
7774
show (Export Nothing) = "export *::*";
7875
show (Export (Just (x, y))) = printf "export %s::%s;" x (fromMaybe "*" y)

src/Language/SystemVerilog/AST/GenItem.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ instance Show GenItem where
3333
show (GenBlock x i) =
3434
printf "begin%s\n%s\nend"
3535
(if null x then "" else " : " ++ x)
36-
(indent $ unlines' $ map show i)
36+
(indent $ show i)
3737
show (GenCase e cs) =
3838
printf "case (%s)\n%s\nendcase" (show e) bodyStr
3939
where bodyStr = indent $ unlines' $ map showGenCase cs

src/Language/SystemVerilog/AST/ModuleItem.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ instance Show ModuleItem where
5454
show (Assign o a b) = printf "assign %s%s = %s;" (showPad o) (show a) (show b)
5555
show (Defparam a b) = printf "defparam %s = %s;" (show a) (show b)
5656
show (Genvar x ) = printf "genvar %s;" x
57-
show (Generate b ) = printf "generate\n%s\nendgenerate" (indent $ unlines' $ map show b)
57+
show (Generate b ) = printf "generate\n%s\nendgenerate" (indent $ show b)
5858
show (Modport x l) = printf "modport %s(\n%s\n);" x (indent $ intercalate ",\n" $ map showModportDecl l)
5959
show (Initial s ) = printf "initial %s" (show s)
6060
show (Final s ) = printf "final %s" (show s)

src/Language/SystemVerilog/AST/ShowHelp.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ module Language.SystemVerilog.AST.ShowHelp
1313
, commas
1414
, indentedParenList
1515
, showEither
16+
, showBlock
1617
) where
1718

1819
import Data.List (intercalate)
@@ -52,3 +53,8 @@ indentedParenList l = "(\n" ++ (indent $ intercalate ",\n" l) ++ "\n)"
5253
showEither :: (Show a, Show b) => Either a b -> String
5354
showEither (Left v) = show v
5455
showEither (Right v) = show v
56+
57+
showBlock :: (Show a, Show b) => [a] -> [b] -> String
58+
showBlock a [] = indent $ show a
59+
showBlock [] b = indent $ show b
60+
showBlock a b = indent $ show a ++ "\n" ++ show b

src/Language/SystemVerilog/AST/Stmt.hs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ module Language.SystemVerilog.AST.Stmt
2525

2626
import Text.Printf (printf)
2727

28-
import Language.SystemVerilog.AST.ShowHelp (commas, indent, unlines', showPad)
28+
import Language.SystemVerilog.AST.ShowHelp (commas, indent, unlines', showPad, showBlock)
2929
import Language.SystemVerilog.AST.Attr (Attr)
3030
import Language.SystemVerilog.AST.Decl (Decl)
3131
import Language.SystemVerilog.AST.Expr (Expr(Inside, Nil), Args(..), showExprOrRange)
@@ -57,13 +57,13 @@ data Stmt
5757
deriving Eq
5858

5959
instance Show Stmt where
60+
showList l _ = unlines' $ map show l
6061
show (StmtAttr attr stmt) = printf "%s\n%s" (show attr) (show stmt)
6162
show (Block kw name decls stmts) =
6263
printf "%s%s\n%s\n%s" (show kw) header body (blockEndToken kw)
6364
where
6465
header = if null name then "" else " : " ++ name
65-
bodyLines = (map show decls) ++ (map show stmts)
66-
body = indent $ unlines' bodyLines
66+
body = showBlock decls stmts
6767
show (Case u kw e cs) =
6868
printf "%s%s (%s)\n%s\nendcase" (showPad u) (show kw) (show e) bodyStr
6969
where bodyStr = indent $ unlines' $ map showCase cs
@@ -104,9 +104,8 @@ instance Show Stmt where
104104
else "// " ++ c
105105

106106
showBranch :: Stmt -> String
107-
showBranch (Block Seq "" [] [CommentStmt c, stmt]) =
108-
'\n' : (indent $ unlines' $ map show stmts)
109-
where stmts = [CommentStmt c, stmt]
107+
showBranch (Block Seq "" [] (stmts @ [CommentStmt{}, _])) =
108+
'\n' : (indent $ show stmts)
110109
showBranch (block @ Block{}) = ' ' : show block
111110
showBranch stmt = '\n' : (indent $ show stmt)
112111

test/basic/assert.sv

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module Module(input clock, input clear, input data);
2+
logic x, y;
3+
assign y = data;
4+
assign x = y;
5+
assert property (
6+
@(posedge clock) disable iff(clear) x == y
7+
);
8+
task hello;
9+
$display("Hello!");
10+
assert property (x == y);
11+
endtask
12+
endmodule

test/basic/assert.v

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module Module(input clock, input clear, input data);
2+
wire x, y;
3+
assign y = data;
4+
assign x = y;
5+
task hello;
6+
$display("Hello!");
7+
endtask
8+
endmodule

test/basic/assert_tb.v

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module top;
2+
reg clock;
3+
initial begin
4+
clock = 0;
5+
repeat (100)
6+
#1 clock = ~clock;
7+
end
8+
9+
reg clear;
10+
initial clear = 0;
11+
12+
reg data;
13+
initial data = 0;
14+
15+
Module m(clock, clear, data);
16+
initial m.hello;
17+
endmodule

test/basic/empty_task.sv

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module top;
2+
task t;
3+
input x;
4+
begin : y
5+
reg z;
6+
end
7+
endtask
8+
initial t(0);
9+
endmodule

test/basic/gen_case.sv

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module Module;
2+
parameter X = 1;
3+
case (X)
4+
1: initial $display("A");
5+
2: initial $display("B");
6+
default: initial $display("C");
7+
3: ;
8+
endcase
9+
endmodule
10+
11+
module top;
12+
Module #(1) a();
13+
Module #(2) b();
14+
Module #(3) c();
15+
Module #(4) d();
16+
endmodule

0 commit comments

Comments
 (0)