mirror of https://github.com/zachjs/sv2v.git
convert do while loops
This commit is contained in:
parent
1315bed81c
commit
4ced649a87
|
|
@ -7,6 +7,7 @@
|
|||
* Added support for enumerated type ranges (e.g., `enum { X[3:5] }`)
|
||||
* Added support for the SystemVerilog `edge` event
|
||||
* Added support for cycle delay ranges in assertion sequence expressions
|
||||
* Added conversion for `do` `while` loops
|
||||
* Added support for passing through DPI imports and exports
|
||||
* Added support for passing through functions with output ports
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ import qualified Convert.Assertion
|
|||
import qualified Convert.BlockDecl
|
||||
import qualified Convert.Cast
|
||||
import qualified Convert.DimensionQuery
|
||||
import qualified Convert.DoWhile
|
||||
import qualified Convert.DuplicateGenvar
|
||||
import qualified Convert.EmptyArgs
|
||||
import qualified Convert.Enum
|
||||
|
|
@ -105,6 +106,7 @@ initialPhases selectExclude =
|
|||
, Convert.SenseEdge.convert
|
||||
, Convert.LogOp.convert
|
||||
, Convert.EmptyArgs.convert
|
||||
, Convert.DoWhile.convert
|
||||
, Convert.Foreach.convert
|
||||
, Convert.FuncRoutine.convert
|
||||
, selectExclude Job.Assert Convert.Assertion.convert
|
||||
|
|
|
|||
|
|
@ -0,0 +1,31 @@
|
|||
{- sv2v
|
||||
- Author: Zachary Snow <zach@zachjs.com>
|
||||
-
|
||||
- Conversion for `do` `while` loops.
|
||||
-
|
||||
- These are converted into while loops with an extra condition which is
|
||||
- initially true and immediately set to false in the body. This strategy is
|
||||
- preferrable to simply duplicating the loop body as it could contain jumps.
|
||||
-}
|
||||
|
||||
module Convert.DoWhile (convert) where
|
||||
|
||||
import Convert.Traverse
|
||||
import Language.SystemVerilog.AST
|
||||
|
||||
convert :: [AST] -> [AST]
|
||||
convert =
|
||||
map $ traverseDescriptions $ traverseModuleItems $
|
||||
traverseStmts $ traverseNestedStmts convertStmt
|
||||
|
||||
convertStmt :: Stmt -> Stmt
|
||||
convertStmt (DoWhile cond body) =
|
||||
Block Seq "" [decl] [While cond' body']
|
||||
where
|
||||
ident = "sv2v_do_while"
|
||||
typ = IntegerVector TLogic Unspecified []
|
||||
decl = Variable Local typ ident [] (RawNum 1)
|
||||
cond' = BinOp LogOr (Ident ident) cond
|
||||
asgn = Asgn AsgnOpEq Nothing (LHSIdent ident) (RawNum 0)
|
||||
body' = Block Seq "" [] [asgn, body]
|
||||
convertStmt other = other
|
||||
|
|
@ -208,9 +208,6 @@ convertStmt (For inits comp incr stmt) =
|
|||
convertStmt (While comp stmt) =
|
||||
convertLoop Nothing loop comp [] stmt
|
||||
where loop c _ s = While c s
|
||||
convertStmt (DoWhile comp stmt) =
|
||||
convertLoop Nothing loop comp [] stmt
|
||||
where loop c _ s = DoWhile c s
|
||||
|
||||
convertStmt (Continue) = do
|
||||
loopDepth <- gets sLoopDepth
|
||||
|
|
|
|||
|
|
@ -68,6 +68,7 @@ executable sv2v
|
|||
Convert.BlockDecl
|
||||
Convert.Cast
|
||||
Convert.DimensionQuery
|
||||
Convert.DoWhile
|
||||
Convert.DuplicateGenvar
|
||||
Convert.EmptyArgs
|
||||
Convert.Enum
|
||||
|
|
|
|||
|
|
@ -0,0 +1,11 @@
|
|||
module top;
|
||||
integer x = 0;
|
||||
initial
|
||||
do begin
|
||||
$display("hi %0d", x);
|
||||
x++;
|
||||
if (x == 2)
|
||||
continue;
|
||||
$display("step");
|
||||
end while (0 < x && x < 3);
|
||||
endmodule
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
module top;
|
||||
integer x = 0;
|
||||
initial
|
||||
while (x < 3) begin
|
||||
$display("hi %0d", x);
|
||||
x++;
|
||||
if (x != 2)
|
||||
$display("step");
|
||||
end
|
||||
endmodule
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
module top;
|
||||
initial do
|
||||
$display("hi");
|
||||
while (0);
|
||||
endmodule
|
||||
Loading…
Reference in New Issue