Skip to content

Commit

Permalink
Use debug name for type errors
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardt committed Aug 20, 2018
1 parent 6998248 commit 5b33c38
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
10 changes: 5 additions & 5 deletions magma/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ def wire(i, o, debug_info):
# print('Array.wire(', o, ', ', i, ')')

if not isinstance(o, ArrayType):
report_wiring_error(f'Cannot wire {repr(o)} (type={type(o)}) to'
f' {repr(i)} (type={type(i)}) because'
f' {repr(o)} is not an Array', debug_info)
report_wiring_error(f'Cannot wire {o.debug_name} (type={type(o)}) to'
f' {i.debug_name} (type={type(i)}) because'
f' {o.debug_name} is not an Array', debug_info)
return

if i.N != o.N:
report_wiring_error(f'Cannot wire {repr(o)} (type={type(o)},'
f' len={i.N}) to {repr(i)} (type={type(i)},'
report_wiring_error(f'Cannot wire {o.debug_name} (type={type(o)},'
f' len={i.N}) to {i.debug_name} (type={type(i)},'
f' len={o.N}) because the arrays do not have'
f' the same length', debug_info)
return
Expand Down
15 changes: 2 additions & 13 deletions magma/port.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def connect( self, o, i , debug_info):
if not o.anon():
#assert o.bit.direction is not None
if o.bit.isinput():
report_wiring_error(f"Using {o.debug_name} (an input) as an output", debug_info)
report_wiring_error(f"Using {o.bit.debug_name} (an input) as an output", debug_info)
return

if o not in self.outputs:
Expand All @@ -74,7 +74,7 @@ def connect( self, o, i , debug_info):
if not i.anon():
#assert i.bit.direction is not None
if i.bit.isoutput():
report_wiring_error(f"Using {i.debug_name} (an output) as an input", debug_info)
report_wiring_error(f"Using {i.bit.debug_name} (an output) as an input", debug_info)
return

if i not in self.inputs:
Expand Down Expand Up @@ -116,17 +116,6 @@ def __init__(self, bit):

self.wires = Wire()

@property
def debug_name(self):
defn_str = ""
inst_str = ""
if isinstance(self.bit.name, DefnRef):
defn_str = str(self.bit.name.defn.name) + "."
elif isinstance(self.bit.name, InstRef):
inst_str = str(type(self.bit.name.inst).name) + "_" + str(self.bit.name.inst.name) + "."
defn_str = str(self.bit.name.inst.defn.name) + "."
return f"{defn_str}{inst_str}{str(self)}"

def __repr__(self):
return repr(self.bit)

Expand Down
13 changes: 12 additions & 1 deletion magma/t.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .ref import Ref, AnonRef
from .ref import Ref, AnonRef, DefnRef, InstRef
from .port import INOUT, INPUT, OUTPUT
from .compatibility import IntegerTypes, StringTypes

Expand Down Expand Up @@ -56,6 +56,17 @@ def isinout(self):
def isbidir(self):
return False

@property
def debug_name(self):
defn_str = ""
inst_str = ""
if isinstance(self.name, DefnRef):
defn_str = str(self.name.defn.name) + "."
elif isinstance(self.name, InstRef):
inst_str = str(type(self.name.inst).name) + "_" + str(self.name.inst.name) + "."
defn_str = str(self.name.inst.defn.name) + "."
return f"{defn_str}{inst_str}{str(self)}"


class Kind(type):
def __init__(cls, name, bases, dct):
Expand Down
6 changes: 3 additions & 3 deletions tests/test_type/test_type_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def test_array_lengths(caplog):
buf = Buf()
wire(main.O, buf.I)
assert "\n".join(x.msg for x in caplog.records) == """\
\033[1mtests/test_type/test_type_errors.py:10: Cannot wire main.O (type=Array(7,In(Bit)), len=8) to inst0.I (type=Array(8,In(Bit)), len=7) because the arrays do not have the same length
\033[1mtests/test_type/test_type_errors.py:10: Cannot wire main.O (type=Array(7,In(Bit)), len=8) to main.Buf_inst0.I (type=Array(8,In(Bit)), len=7) because the arrays do not have the same length
wire(main.O, buf.I)
"""

Expand All @@ -22,7 +22,7 @@ def test_array_to_bit(caplog):
buf = Buf()
wire(main.O, buf.I)
assert "\n".join(x.msg for x in caplog.records) == """\
\033[1mtests/test_type/test_type_errors.py:23: Cannot wire main.O (type=In(Bit)) to inst0.I (type=Array(8,In(Bit))) because main.O is not an Array
\033[1mtests/test_type/test_type_errors.py:23: Cannot wire main.O (type=In(Bit)) to main.Buf_inst0.I (type=Array(8,In(Bit))) because main.O is not an Array
wire(main.O, buf.I)
"""

Expand All @@ -35,6 +35,6 @@ def test_bit_to_array(caplog):
buf = Buf()
wire(buf.I, main.O)
assert "\n".join(x.msg for x in caplog.records) == """\
\033[1mtests/test_type/test_type_errors.py:36: Cannot wire inst0.I (type=In(Bit)) to main.O (type=Array(7,In(Bit))) because inst0.I is not an Array
\033[1mtests/test_type/test_type_errors.py:36: Cannot wire main.Buf_inst0.I (type=In(Bit)) to main.O (type=Array(7,In(Bit))) because main.Buf_inst0.I is not an Array
wire(buf.I, main.O)
"""

0 comments on commit 5b33c38

Please sign in to comment.