Skip to content

Commit

Permalink
Merge 76fcd6e into 2c79cd9
Browse files Browse the repository at this point in the history
  • Loading branch information
rsetaluri committed Oct 28, 2019
2 parents 2c79cd9 + 76fcd6e commit ca7654b
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 0 deletions.
11 changes: 11 additions & 0 deletions magma/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,11 +476,22 @@ def __new__(metacls, name, bases, dct):
if hasattr(self, 'definition'):
pushDefinition(self)
self.definition()
self.check_unconnected()
self._is_definition = True
EndCircuit()

return self

def check_unconnected(self):
for port in self.interface.ports.values():
if port.isinput() and not port.driven():
report_wiring_warning(f"Output port {self.name}.{port.name} not driven", self.debug_info)

for inst in self.instances:
for port in inst.interface.ports.values():
if port.isinput() and not port.driven():
report_wiring_warning(f"Input port {inst.name}.{port.name} not driven", inst.debug_info)

@property
def is_definition(self):
return self._is_definition or self.verilog or self.verilogFile
Expand Down
15 changes: 15 additions & 0 deletions magma/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,18 @@ def set_debug_mode(value=True):

def get_debug_mode():
return __DEBUG_MODE


class _MagmaDebugSection:
def __init__(self):
self.__restore = get_debug_mode()

def __enter__(self):
set_debug_mode(True)

def __exit__(self, typ, value, traceback):
set_debug_mode(self.__restore)


def magma_debug_section():
return _MagmaDebugSection()
50 changes: 50 additions & 0 deletions tests/test_circuit/test_unconnected.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import pytest
import magma as m


def _make_unconnected_io():
class _Circuit(m.Circuit):
IO = ["I", m.In(m.Bits[1]), "O", m.Out(m.Bits[2])]

@classmethod
def definition(io):
# Leave io.O[1] unwired.
io.O[0] <= io.I[0]

return _Circuit


def _make_unconnected_instance():
class _Buffer(m.Circuit):
IO = ["I", m.In(m.Bit), "O", m.Out(m.Bit)]

@classmethod
def definition(io):
io.O <= io.I

class _Circuit(m.Circuit):
IO = ["I", m.In(m.Bit), "O", m.Out(m.Bit)]

@classmethod
def definition(io):
buf = _Buffer()
# Leave buf.I unwired.
io.O <= buf.O


def test_unconnected_io(caplog):
with m.config.magma_debug_section():
Circuit = _make_unconnected_io()
logs = caplog.records
assert len(logs) == 2
assert logs[0].msg == "\x1b[1mtests/test_circuit/test_unconnected.py:6: Output port _Circuit.O not driven" # nopep8
assert logs[1].msg == " class _Circuit(m.Circuit):\n"


def test_unconnected_instance(caplog):
with m.config.magma_debug_section():
Circuit = _make_unconnected_instance()
logs = caplog.records
assert len(logs) == 2
assert logs[0].msg == "\x1b[1mtests/test_circuit/test_unconnected.py:30: Input port buf.I not driven" # nopep8
assert logs[1].msg == " buf = _Buffer()\n"

0 comments on commit ca7654b

Please sign in to comment.