mirror of https://github.com/zachjs/sv2v.git
fix simple loop jump guarded conversion
This commit is contained in:
parent
31ebf181bb
commit
937a583e41
|
|
@ -117,9 +117,10 @@ convertStmts stmts = do
|
||||||
return stmts'
|
return stmts'
|
||||||
|
|
||||||
|
|
||||||
pattern SimpleLoopInits :: Type -> Identifier -> Expr
|
pattern SimpleLoopInits :: String -> Type -> Identifier -> Expr
|
||||||
-> Either [Decl] [(LHS, Expr)]
|
-> Either [Decl] [(LHS, Expr)]
|
||||||
pattern SimpleLoopInits typ var expr = Left [Variable Local typ var [] expr]
|
pattern SimpleLoopInits msg typ var expr =
|
||||||
|
Left [CommentDecl msg, Variable Local typ var [] expr]
|
||||||
|
|
||||||
pattern SimpleLoopGuard :: BinOp -> Identifier -> Expr -> Expr
|
pattern SimpleLoopGuard :: BinOp -> Identifier -> Expr -> Expr
|
||||||
pattern SimpleLoopGuard cmp var bound = BinOp cmp (Ident var) bound
|
pattern SimpleLoopGuard cmp var bound = BinOp cmp (Ident var) bound
|
||||||
|
|
@ -177,7 +178,7 @@ convertStmt (Case unique kw expr cases) = do
|
||||||
return $ Case unique kw expr cases'
|
return $ Case unique kw expr cases'
|
||||||
|
|
||||||
convertStmt (For
|
convertStmt (For
|
||||||
(inits @ (SimpleLoopInits _ var1 _))
|
(inits @ (SimpleLoopInits _ _ var1 _))
|
||||||
(comp @ (SimpleLoopGuard _ var2 _))
|
(comp @ (SimpleLoopGuard _ var2 _))
|
||||||
(incr @ (SimpleLoopIncrs var3 _ _))
|
(incr @ (SimpleLoopIncrs var3 _ _))
|
||||||
stmt) =
|
stmt) =
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
module top;
|
||||||
|
function automatic integer f;
|
||||||
|
input integer inp;
|
||||||
|
f = 1;
|
||||||
|
for (integer idx = 0; idx < inp; idx = idx + 1) begin
|
||||||
|
if (f == 32)
|
||||||
|
break;
|
||||||
|
f = f * 2;
|
||||||
|
end
|
||||||
|
endfunction
|
||||||
|
integer i;
|
||||||
|
initial
|
||||||
|
for (i = 0; i < 10; i = i + 1)
|
||||||
|
$display("f(%0d) = %0d", i, f(i));
|
||||||
|
endmodule
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
module top;
|
||||||
|
function automatic integer f;
|
||||||
|
input integer inp;
|
||||||
|
if (inp > 5)
|
||||||
|
f = 32;
|
||||||
|
else
|
||||||
|
f = 2 ** inp;
|
||||||
|
endfunction
|
||||||
|
integer i;
|
||||||
|
initial
|
||||||
|
for (i = 0; i < 10; i = i + 1)
|
||||||
|
$display("f(%0d) = %0d", i, f(i));
|
||||||
|
endmodule
|
||||||
Loading…
Reference in New Issue