Commit 937a583e by Zachary Snow

fix simple loop jump guarded conversion

parent 31ebf181
......@@ -117,9 +117,10 @@ convertStmts stmts = do
return stmts'
pattern SimpleLoopInits :: Type -> Identifier -> Expr
pattern SimpleLoopInits :: String -> Type -> Identifier -> 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 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'
convertStmt (For
(inits @ (SimpleLoopInits _ var1 _))
(inits @ (SimpleLoopInits _ _ var1 _))
(comp @ (SimpleLoopGuard _ var2 _))
(incr @ (SimpleLoopIncrs var3 _ _))
stmt) =
......
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
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
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