Skip to content

Commit

Permalink
Add support for using non-compat Elaboratable instances with compat.f…
Browse files Browse the repository at this point in the history
…hdl.verilog.convert and compat.run_simulation

Fixes m-labs#344
  • Loading branch information
programmerjake authored and whitequark committed Apr 2, 2020
1 parent 6e1145e commit 995f3a1
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
6 changes: 5 additions & 1 deletion nmigen/compat/fhdl/verilog.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from ...hdl.cd import ClockDomain
from ...back import verilog
from .conv_output import ConvOutput
from .module import Module


def convert(fi, ios=None, name="top", special_overrides=dict(),
Expand All @@ -17,11 +18,14 @@ def convert(fi, ios=None, name="top", special_overrides=dict(),
DeprecationWarning, stacklevel=1)
# TODO: attr_translate

if isinstance(fi, Module):
fi = fi.get_fragment()

def missing_domain(name):
if create_clock_domains:
return ClockDomain(name)
v_output = verilog.convert(
elaboratable=fi.get_fragment(),
elaboratable=fi,
name=name,
ports=ios or (),
missing_domain=missing_domain
Expand Down
6 changes: 5 additions & 1 deletion nmigen/compat/sim/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from collections.abc import Iterable
from ...hdl.cd import ClockDomain
from ...back.pysim import *
from ...hdl.ir import Fragment


__all__ = ["run_simulation", "passive"]
Expand All @@ -17,9 +18,12 @@ def run_simulation(fragment_or_module, generators, clocks={"sync": 10}, vcd_name
else:
fragment = fragment_or_module

fragment = Fragment.get(fragment, platform=None)

if not isinstance(generators, dict):
generators = {"sync": generators}
fragment.domains += ClockDomain("sync")
if "sync" not in fragment.domains:
fragment.add_domains(ClockDomain("sync"))

sim = Simulator(fragment)
for domain, period in clocks.items():
Expand Down
26 changes: 26 additions & 0 deletions nmigen/test/compat/test_run_simulation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import unittest
from ... import Signal, Module, Elaboratable
from .support import SimCase


class RunSimulation(SimCase, unittest.TestCase):
""" test for https://github.com/nmigen/nmigen/issues/344 """

class TestBench(Elaboratable):
def __init__(self):
self.a = Signal()

def elaborate(self, platform):
m = Module()
m.d.sync += self.a.eq(~self.a)
return m

def test_run_simulation(self):
def gen():
yield
for i in range(10):
yield
a = (yield self.tb.a)
self.assertEqual(a, i % 2)

self.run_with(gen())

0 comments on commit 995f3a1

Please sign in to comment.