forked from M-Labs/artiq
1
0
Fork 0

transforms/interleave: support try statements

This commit is contained in:
Sebastien Bourdeauducq 2014-09-29 18:09:48 +08:00
parent 2a40d69290
commit 1ae7724a15
1 changed files with 15 additions and 0 deletions

View File

@ -17,6 +17,15 @@ def _get_duration(stmt):
return 0
else:
return -1
elif isinstance(stmt, ast.Try):
if (all(_get_duration(s) == 0 for s in stmt.body)
and all(_get_duration(s) == 0 for s in stmt.orelse)
and all(_get_duration(s) == 0 for s in stmt.finalbody)
and all(_get_duration(s) == 0 for s in handler.body
for handler in stmt.handlers)):
return 0
else:
return -1
elif isinstance(stmt, ast.Call) and isinstance(stmt.func, ast.Name):
name = stmt.func.id
if name == "delay":
@ -89,6 +98,12 @@ def _interleave_stmts(stmts):
if isinstance(stmt, (ast.For, ast.While, ast.If)):
_interleave_stmts(stmt.body)
_interleave_stmts(stmt.orelse)
elif isinstance(stmt, ast.Try):
_interleave_stmts(stmt.body)
_interleave_stmts(stmt.orelse)
_interleave_stmts(stmt.finalbody)
for handler in stmt.handlers:
_interleave_stmts(handler.body)
elif isinstance(stmt, ast.With):
btype = stmt.items[0].context_expr.id
if btype == "sequential":