Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: m-labs/nmigen
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 3b23645fb7ef
Choose a base ref
...
head repository: m-labs/nmigen
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 17d26c83297e
Choose a head ref
  • 3 commits
  • 4 files changed
  • 1 contributor

Commits on Dec 14, 2018

  1. compat.fhdl.module: fix specials.

    whitequark committed Dec 14, 2018
    Copy the full SHA
    3bc3647 View commit details
  2. Copy the full SHA
    88970ee View commit details
  3. compat: add run_simulation shim.

    whitequark committed Dec 14, 2018
    Copy the full SHA
    17d26c8 View commit details
Showing with 38 additions and 5 deletions.
  1. +3 −1 nmigen/back/pysim.py
  2. +1 −1 nmigen/compat/__init__.py
  3. +10 −3 nmigen/compat/fhdl/module.py
  4. +24 −0 nmigen/compat/sim/__init__.py
4 changes: 3 additions & 1 deletion nmigen/back/pysim.py
Original file line number Diff line number Diff line change
@@ -243,7 +243,9 @@ def sync_process():
try:
result = process.send(None)
while True:
result = process.send((yield (result or Tick(domain))))
if result is None:
result = Tick(domain)
result = process.send((yield result))
except StopIteration:
pass
self.add_process(sync_process())
2 changes: 1 addition & 1 deletion nmigen/compat/__init__.py
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
# from .fhdl.decorators import *
# from .fhdl.simplify import *

# from .sim import *
from .sim import *

# from .genlib.record import *
from .genlib.fsm import *
13 changes: 10 additions & 3 deletions nmigen/compat/fhdl/module.py
Original file line number Diff line number Diff line change
@@ -61,19 +61,19 @@ def __setattr__(self, name, value):
class _CompatModuleSpecials(_CompatModuleProxy):
@deprecated("instead of `self.specials.<name> =`, use `m.submodules.<name> =`")
def __setattr__(self, name, value):
self._cm._submodules += (name, value)
self._cm._specials.append((name, value))
setattr(self._cm, name, value)

@deprecated("instead of `self.specials +=`, use `m.submodules +=`")
def __iadd__(self, other):
self._cm._submodules += [(None, e) for e in _flat_list(other)]
self._cm._specials += [(None, e) for e in _flat_list(other)]
return self


class _CompatModuleSubmodules(_CompatModuleProxy):
@deprecated("instead of `self.submodules.<name> =`, use `m.submodules.<name> =`")
def __setattr__(self, name, value):
self._cm._submodules += (name, value)
self._cm._submodules.append((name, value))
setattr(self._cm, name, value)

@deprecated("instead of `self.submodules +=`, use `m.submodules +=`")
@@ -122,6 +122,9 @@ def __getattr__(self, name):
elif name == "_submodules":
self._submodules = []
return self._submodules
elif name == "_specials":
self._specials = []
return self._specials
elif name == "_clock_domains":
self._clock_domains = []
return self._clock_domains
@@ -132,6 +135,10 @@ def __getattr__(self, name):
raise AttributeError("'{}' object has no attribute '{}'"
.format(type(self).__name__, name))

def _finalize_specials(self):
for name, special in self._specials:
self._module._add_submodule(special, name)

def _finalize_submodules(self):
for name, submodule in self._submodules:
if not submodule.get_fragment_called:
24 changes: 24 additions & 0 deletions nmigen/compat/sim/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from ...back.pysim import *


__all__ = ["run_simulation"]


def run_simulation(fragment_or_module, generators, clocks={"sync": 10}, vcd_name=None,
special_overrides={}):
assert not special_overrides

if hasattr(fragment_or_module, "get_fragment"):
fragment = fragment_or_module.get_fragment().get_fragment(platform=None)
else:
fragment = fragment_or_module

if not isinstance(generators, dict):
generators = {"sync": generators}

with Simulator(fragment, vcd_file=open(vcd_name, "w") if vcd_name else None) as sim:
for domain, period in clocks.items():
sim.add_clock(period, domain)
for domain, process in generators.items():
sim.add_sync_process(process, domain)
sim.run()