Skip to content

Commit 8d2a651

Browse files
authored
Merge pull request #278 from pluveto/patch-1
Update report stmt documentation to include structured reporting
2 parents 79efc98 + d39c116 commit 8d2a651

File tree

1 file changed

+65
-1
lines changed
  • source/SpinalHDL/Other language features

1 file changed

+65
-1
lines changed

source/SpinalHDL/Other language features/report.rst

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Since SpinalHDL 1.4.4, the following syntax is also supported:
3030
3131
report(L"miaou $a $b $c $d")
3232
33-
You can display the current simulation time using the REPORT_TIME object
33+
You can display the current simulation time using the `REPORT_TIME` object:
3434

3535
.. code-block:: scala
3636
@@ -41,3 +41,67 @@ will result in:
4141
.. code-block:: verilog
4242
4343
$display("NOTE miaou %t", $time);
44+
45+
**Automatic Handling of Scala Primitive Types (SpinalHDL ^1.12.2)**
46+
47+
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.
48+
49+
.. code-block:: scala
50+
51+
val myInt = 123
52+
val myBool = True
53+
val myFloat = 3.14f
54+
val myBigInt = BigInt(0xABCD)
55+
report(L"My values: int=$myInt, bool=$myBool, float=$myFloat, bigInt=$myBigInt")
56+
57+
.. code-block:: scala
58+
59+
for (i <- 0 until cacheConfig.fetchWordsPerFetchGroup) {
60+
report(L"AdvICache: sCompareTags - Instruction ${i}: ${io.cpu.rsp.payload.instructions(i)}")
61+
}
62+
63+
**Structured Reporting for Complex Data Types (like Bundles) (SpinalHDL ^1.12.2)**
64+
65+
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.
66+
67+
First, define a `Formattable` trait and implement it in your Bundles:
68+
69+
.. code-block:: scala
70+
71+
trait Formattable {
72+
def format(): Seq[Any]
73+
}
74+
75+
case class DataPayload() extends Bundle with Formattable {
76+
val value = UInt(16 bits)
77+
val checksum = UInt(8 bits)
78+
override def format(): Seq[Any] = Seq(L"DataPayload(value=0x${value}, checksum=0x${checksum})")
79+
}
80+
81+
case class PacketHeader() extends Bundle with Formattable {
82+
val packetLength = UInt(8 bits)
83+
val packetType = UInt(4 bits)
84+
val payload = DataPayload()
85+
override def format(): Seq[Any] = Seq(
86+
L"PacketHeader(",
87+
L"packetLength=0x${packetLength},",
88+
L" packetType=0x${packetType},",
89+
L" payload=${payload.format},", // Nested format call
90+
L")"
91+
).flatten
92+
}
93+
94+
Then, you can report the entire structure:
95+
96+
.. code-block:: scala
97+
98+
class MyComponent extends Component {
99+
val io = PacketHeader() // Assume io is an instance of PacketHeader
100+
// ... some logic ...
101+
report(io.format)
102+
}
103+
104+
This will produce a compact, readable output like:
105+
106+
.. code-block:: text
107+
PacketHeader(packetLength=0x0c, packetType=0x1, payload=DataPayload(value=0x5678, checksum=0x78))

0 commit comments

Comments
 (0)