From 2aff725ea253489e82cba5ee9f423ea02bb8f383 Mon Sep 17 00:00:00 2001 From: Zachary Snow Date: Sun, 14 May 2023 23:18:58 -0400 Subject: [PATCH] drop tf block edge case - The deleted chunk in TFBlock has been unreachable since 57ef23ef. The RemoveComments change would make it reachable by dropping the leading Null in a task or function body. - The optimization in TFBlock was unsound because the nested block could shadow identifiers used (but not defined) in the tail of the outer block. - The optimization is not clearly necessary, so I'm dropping it for now. - Expand tf_block test coverage. --- src/Convert/RemoveComments.hs | 4 ++- src/Convert/TFBlock.hs | 5 --- test/core/tf_block.sv | 62 +++++++++++++++++++++++++++++++++++ test/core/tf_block.v | 55 +++++++++++++++++++++++++++++++ 4 files changed, 120 insertions(+), 6 deletions(-) diff --git a/src/Convert/RemoveComments.hs b/src/Convert/RemoveComments.hs index 35ada6d..bbdc78e 100644 --- a/src/Convert/RemoveComments.hs +++ b/src/Convert/RemoveComments.hs @@ -61,4 +61,6 @@ convertDecls = filter (not . isCommentDecl) isCommentDecl _ = False convertStmts :: [Stmt] -> [Stmt] -convertStmts = map $ traverseNestedStmts convertStmt +convertStmts = + filter (/= Null) . + map (traverseNestedStmts convertStmt) diff --git a/src/Convert/TFBlock.hs b/src/Convert/TFBlock.hs index 463641e..a54fb51 100644 --- a/src/Convert/TFBlock.hs +++ b/src/Convert/TFBlock.hs @@ -47,11 +47,6 @@ flattenOuterBlocks (Block Seq "" declsA [stmt]) = then (declsA ++ declsB, stmtsB) else (declsA, [stmt]) where (declsB, stmtsB) = flattenOuterBlocks stmt -flattenOuterBlocks (Block Seq "" declsA (Block Seq name declsB stmtsA : stmtsB)) = - if canCombine declsA declsB - then flattenOuterBlocks $ - Block Seq name (declsA ++ declsB) (stmtsA ++ stmtsB) - else (declsA, Block Seq name declsB stmtsA : stmtsB) flattenOuterBlocks (Block Seq name decls stmts) | null name = (decls, stmts) | otherwise = ([], [Block Seq name decls stmts]) diff --git a/test/core/tf_block.sv b/test/core/tf_block.sv index f76e3fd..8941003 100644 --- a/test/core/tf_block.sv +++ b/test/core/tf_block.sv @@ -11,4 +11,66 @@ module top; initial t(); initial $display("f(0) = ", f(0)); initial $display("f(1) = ", f(1)); + + task t1; + localparam X = 1; + begin + localparam X = 2; + $display("t1", X); + end + endtask + task t2; + localparam X = 10; + begin + localparam X = 20; + $display("t2", X); + end + $display("t2", X); + endtask + task t3; + localparam X = 100; + begin + localparam Y = 200; + $display("t3", Y); + end + $display("t3", X); + endtask + task t4; + begin + begin + localparam Y = 99; + $display("t4", Y); + end + $display("t4", 123); + end + endtask + initial begin + t1; + t2; + t3; + t4; + end + + localparam X = 1; + task a; + localparam X = 2; + begin + begin : blk + localparam X = 3; + $display("a", X); + end + $display("a", X); + end + endtask + task b; + begin : blk + localparam X = 5; + $display("b", X); + end + $display("b", X); + endtask + initial begin + a; + b; + end endmodule diff --git a/test/core/tf_block.v b/test/core/tf_block.v index d8a3569..97bcf59 100644 --- a/test/core/tf_block.v +++ b/test/core/tf_block.v @@ -12,4 +12,59 @@ module top; initial t(); initial $display("f(0) = ", f(0)); initial $display("f(1) = ", f(1)); + + task t1; + localparam X = 2; + $display("t1", X); + endtask + task t2; + localparam X = 10; + localparam Y = 20; + begin + $display("t2", Y); + $display("t2", X); + end + endtask + task t3; + localparam X = 100; + localparam Y = 200; + begin + $display("t3", Y); + $display("t3", X); + end + endtask + task t4; + localparam Y = 99; + begin + $display("t4", Y); + $display("t4", 123); + end + endtask + initial begin + t1; + t2; + t3; + t4; + end + + localparam X = 1; + task a; + localparam X = 2; + localparam Y = 3; + begin + $display("a", Y); + $display("a", X); + end + endtask + task b; + localparam Y = 5; + begin + $display("b", Y); + $display("b", X); + end + endtask + initial begin + a; + b; + end endmodule