pymtl / pymtl3

Pymtl 3 (Mamba), an open-source Python-based hardware generation, simulation, and verification framework
BSD 3-Clause "New" or "Revised" License
388 stars 46 forks source link

Slicing non-Bits signals inside update blocks does not generate very helpful error messages #197

Closed ptpan closed 11 months ago

ptpan commented 4 years ago

To reproduce, use the following code:

from pymtl3 import *

BitStruct = mk_bitstruct( "BitStruct", {
    "foo" : Bits32,
} )

class A( Component ):

  def construct( s ):

    s.in_ = InPort( BitStruct )
    s.out = OutPort( 16 )

    @update
    def upblk():
      s.out @= s.in_[0:16]

A().elaborate()

The slicing error on line s.out @= s.in_[0:16] gives the following error messages which do not refer to the offending signals:

(python3.7.4) [pp@server] $ python3 slice.py
Traceback (most recent call last):
  File "slice.py", line 18, in <module>
    A().elaborate()
  File "/.../pymtl3/dsl/Component.py", line 439, in elaborate
    super().elaborate()
  File "/.../pymtl3/dsl/ComponentLevel2.py", line 615, in elaborate
    c._elaborate_read_write_func()
  File "/.../pymtl3/dsl/ComponentLevel2.py", line 301, in _elaborate_read_write_func
    s._dsl.upblk_reads [ blk ] = extract_obj_from_names( blk, name_rd[ name ] )
  File "/.../pymtl3/dsl/ComponentLevel2.py", line 210, in extract_obj_from_names
    lookup_variable( s, 1, 1 )
  File "/.../pymtl3/dsl/ComponentLevel2.py", line 191, in lookup_variable
    else:       expand_array_index( child, name_depth,   node_depth+1, 0, idx )
  File "/.../pymtl3/dsl/ComponentLevel2.py", line 154, in expand_array_index
    child = obj[ current_idx ]
  File "/.../pymtl3/dsl/Connectable.py", line 233, in __getitem__
    raise InvalidConnectionError( "We don't allow slicing on non-Bits signals." )
pymtl3.dsl.errors.InvalidConnectionError: We don't allow slicing on non-Bits signals.
ptpan commented 11 months ago

Resolved by #259