Skip to content

Commit abaf2b2

Browse files
authored
Wrap printfs in the Verification layerblock (#4506)
Change the emission of printfs to emit these under the `Verification` layerblock. This is done as part of replacing the `firtool` extract-test-code feature with layers and the "advanced layer sink" `firtool` feature. The extract-test-code feature will extract asserts _and_ printfs together. This is technically a deviation from this behavior. However, it seems better to not lump these in with asserts. Nonetheless, this is a backwards compatible change from the perspective of extract-test-code because the `Verification` layer is always loaded if the `Assert` layer is present. (Prints will always show up if you turn on assertions.) In the future, we probably want to add a `Debug` layer under the `Verification` layer where these will live. I would like to hold off on making this change until extract-test-code is gone. Signed-off-by: Schuyler Eldridge <[email protected]>
1 parent 7ade4df commit abaf2b2

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

core/src/main/scala-2/chisel3/PrintfMacros.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package chisel3
55
import chisel3.internal._
66
import chisel3.internal.Builder.pushCommand
77
import chisel3.experimental.SourceInfo
8+
import chisel3.{layer, layers}
89
import scala.language.experimental.macros
910
import scala.reflect.macros.blackbox
1011

@@ -75,7 +76,9 @@ object PrintfMacrosCompat {
7576

7677
Printable.checkScope(pable)
7778

78-
pushCommand(chisel3.internal.firrtl.ir.Printf(printfId, sourceInfo, clock.ref, pable))
79+
layer.block(layers.Verification, skipIfAlreadyInBlock = true, skipIfLayersEnabled = true) {
80+
pushCommand(chisel3.internal.firrtl.ir.Printf(printfId, sourceInfo, clock.ref, pable))
81+
}
7982
printfId
8083
}
8184

src/test/scala/chiselTests/Printf.scala

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,20 @@ import circt.stage.ChiselStage
88
class SinglePrintfTester() extends Module {
99
val x = 254.U
1010
printf("x=%x", x)
11-
stop()
1211
}
1312

1413
class ASCIIPrintfTester() extends Module {
1514
printf((0x20 to 0x7e).map(_.toChar).mkString.replace("%", "%%"))
16-
stop()
1715
}
1816

1917
class MultiPrintfTester() extends Module {
2018
val x = 254.U
2119
val y = 255.U
2220
printf("x=%x y=%x", x, y)
23-
stop()
2421
}
2522

2623
class ASCIIPrintableTester extends Module {
2724
printf(PString((0x20 to 0x7e).map(_.toChar).mkString("")))
28-
stop()
2925
}
3026

3127
class ScopeTesterModule extends Module {
@@ -42,7 +38,10 @@ class ScopeTesterModule extends Module {
4238

4339
class PrintfSpec extends ChiselFlatSpec {
4440
"A printf with a single argument" should "elaborate" in {
45-
ChiselStage.emitCHIRRTL(new SinglePrintfTester)
41+
val chirrtl = ChiselStage.emitCHIRRTL(new SinglePrintfTester)
42+
43+
info("printfs are wrapped in the `Verification` layerblock by default")
44+
chirrtl should include("layerblock Verification")
4645
}
4746
"A printf with multiple arguments" should "elaborate" in {
4847
ChiselStage.emitCHIRRTL(new MultiPrintfTester)

0 commit comments

Comments
 (0)