Skip to content

Commit

Permalink
describing how and when to override clone, and link to scope property
Browse files Browse the repository at this point in the history
  • Loading branch information
ronan-lashermes committed Jan 25, 2022
1 parent 68d4ad5 commit aeb9875
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ then you can activate the virtual enviroment (in bash) and install the dependenc
.. code:: shell
source .venv/bin/activate
pip install -r requiremets.txt
pip install -r requirements.txt
and then you can use ``make`` the usual way

Expand Down
49 changes: 47 additions & 2 deletions source/SpinalHDL/Design errors/spinal_cant_clone.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ Introduction
This error happens when SpinalHDL wants to create a new datatype instance via the ``cloneOf`` function but isn't able to do it.
The reason for this is nearly always because it can't retrieve the construction parameters of a ``Bundle``.

Example
-------
Example 1
---------

The following code:

Expand Down Expand Up @@ -47,3 +47,48 @@ A fix could be:
class TopLevel extends Component {
val tmp = Stream(RGB(8))
}
Example 2
---------

The following code:

.. code-block:: scala
case class Xlen(val xlen: Int) {}
case class MemoryAddress()(implicit xlenConfig: Xlen) extends Bundle {
val address = UInt(xlenConfig.xlen bits)
}
class DebugMemory(implicit config: Xlen) extends Component {
val io = new Bundle {
val inputAddress = in(MemoryAddress())
}
val someAddress = RegNext(io.inputAddress) // -> ERROR *****************************
}
raises an exeption:

.. code-block:: text
[error] *** Spinal can't clone class debug.MemoryAddress datatype
In this case, a solution is to override the clone function to propagate the implicit parameter.

.. code-block:: scala
case class MemoryAddress()(implicit xlenConfig: Xlen) extends Bundle {
val address = UInt(xlenConfig.xlen bits)
override def clone = MemoryAddress()
}
.. note::

We need to clone the hardware element, not the eventually assigned value in it.

.. note::

An alternative is to used :ref:`ScopeProperty <scopeproperty>`.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.. _scopeproperty:

ScopeProperty
==================
Expand Down

0 comments on commit aeb9875

Please sign in to comment.