verilog, sim: accept iterables in FHDL statements

This commit is contained in:
Sebastien Bourdeauducq 2015-10-19 19:17:26 +08:00
parent 4d9b2fff63
commit 0999a17319
2 changed files with 4 additions and 2 deletions

View File

@ -1,5 +1,6 @@
from functools import partial from functools import partial
from operator import itemgetter from operator import itemgetter
import collections
from migen.fhdl.structure import * from migen.fhdl.structure import *
from migen.fhdl.structure import _Operator, _Slice, _Assign, _Fragment from migen.fhdl.structure import _Operator, _Slice, _Assign, _Fragment
@ -128,7 +129,7 @@ def _printnode(ns, at, level, node):
else: else:
assignment = " <= " assignment = " <= "
return "\t"*level + _printexpr(ns, node.l)[0] + assignment + _printexpr(ns, node.r)[0] + ";\n" return "\t"*level + _printexpr(ns, node.l)[0] + assignment + _printexpr(ns, node.r)[0] + ";\n"
elif isinstance(node, (list, tuple)): elif isinstance(node, collections.Iterable):
return "".join(list(map(partial(_printnode, ns, at, level), node))) return "".join(list(map(partial(_printnode, ns, at, level), node)))
elif isinstance(node, If): elif isinstance(node, If):
r = "\t"*level + "if (" + _printexpr(ns, node.cond)[0] + ") begin\n" r = "\t"*level + "if (" + _printexpr(ns, node.cond)[0] + ") begin\n"

View File

@ -1,4 +1,5 @@
import operator import operator
import collections
from migen.fhdl.structure import * from migen.fhdl.structure import *
from migen.fhdl.structure import (_Value, _Statement, from migen.fhdl.structure import (_Value, _Statement,
@ -193,7 +194,7 @@ class Evaluator:
return return
if "default" in s.cases: if "default" in s.cases:
self.execute(s.cases["default"]) self.execute(s.cases["default"])
elif isinstance(s, list): elif isinstance(s, collections.Iterable):
self.execute(s) self.execute(s)
else: else:
raise NotImplementedError raise NotImplementedError