Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 65 additions & 1 deletion source/SpinalHDL/Other language features/report.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

report(L"miaou $a $b $c $d")

You can display the current simulation time using the REPORT_TIME object
You can display the current simulation time using the `REPORT_TIME` object:

.. code-block:: scala

Expand All @@ -41,3 +41,67 @@
.. code-block:: verilog

$display("NOTE miaou %t", $time);

**Automatic Handling of Scala Primitive Types (SpinalHDL ^1.12.2)**

You can embed Scala primitive types (e.g., `Int`, `Boolean`, `Float`, `BigInt`, `BigDecimal`, `Char`, `Byte`, `Short`, `Long`) within `L""` interpolated strings without explicit `.toString()` calls.

.. code-block:: scala

val myInt = 123
val myBool = True
val myFloat = 3.14f
val myBigInt = BigInt(0xABCD)
report(L"My values: int=$myInt, bool=$myBool, float=$myFloat, bigInt=$myBigInt")

.. code-block:: scala

for (i <- 0 until cacheConfig.fetchWordsPerFetchGroup) {
report(L"AdvICache: sCompareTags - Instruction ${i}: ${io.cpu.rsp.payload.instructions(i)}")
}

**Structured Reporting for Complex Data Types (like Bundles) (SpinalHDL ^1.12.2)**

For `Bundle`s or other complex data structures, you can define a `Formattable` trait and implement a `format()` method returning `Seq[Any]` to define a structured, nested representation. This allows for clean, one-line reporting of entire complex objects.

First, define a `Formattable` trait and implement it in your Bundles:

.. code-block:: scala

trait Formattable {
def format(): Seq[Any]
}

case class DataPayload() extends Bundle with Formattable {
val value = UInt(16 bits)
val checksum = UInt(8 bits)
override def format(): Seq[Any] = Seq(L"DataPayload(value=0x${value}, checksum=0x${checksum})")
}

case class PacketHeader() extends Bundle with Formattable {
val packetLength = UInt(8 bits)
val packetType = UInt(4 bits)
val payload = DataPayload()
override def format(): Seq[Any] = Seq(
L"PacketHeader(",
L"packetLength=0x${packetLength},",
L" packetType=0x${packetType},",
L" payload=${payload.format},", // Nested format call
L")"
).flatten
}

Then, you can report the entire structure:

.. code-block:: scala

class MyComponent extends Component {
val io = PacketHeader() // Assume io is an instance of PacketHeader
// ... some logic ...
report(io.format)
}

This will produce a compact, readable output like:

.. code-block:: text
PacketHeader(packetLength=0x0c, packetType=0x1, payload=DataPayload(value=0x5678, checksum=0x78))

Check warning on line 107 in source/SpinalHDL/Other language features/report.rst

View workflow job for this annotation

GitHub Actions / build

Explicit markup ends without a blank line; unexpected unindent.

Check warning on line 107 in source/SpinalHDL/Other language features/report.rst

View workflow job for this annotation

GitHub Actions / test

Explicit markup ends without a blank line; unexpected unindent.
Loading