Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap printfs in the Verification layerblock #4506

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion core/src/main/scala-2/chisel3/PrintfMacros.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package chisel3
import chisel3.internal._
import chisel3.internal.Builder.pushCommand
import chisel3.experimental.SourceInfo
import chisel3.{layer, layers}
import scala.language.experimental.macros
import scala.reflect.macros.blackbox

Expand Down Expand Up @@ -75,7 +76,9 @@ object PrintfMacrosCompat {

Printable.checkScope(pable)

pushCommand(chisel3.internal.firrtl.ir.Printf(printfId, sourceInfo, clock.ref, pable))
layer.block(layers.Verification, skipIfAlreadyInBlock = true, skipIfLayersEnabled = true) {
pushCommand(chisel3.internal.firrtl.ir.Printf(printfId, sourceInfo, clock.ref, pable))
}
printfId
}

Expand Down
9 changes: 4 additions & 5 deletions src/test/scala/chiselTests/Printf.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,20 @@ import circt.stage.ChiselStage
class SinglePrintfTester() extends Module {
val x = 254.U
printf("x=%x", x)
stop()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This stop is removed so that the test can simply check if a layerblock shows up. Stops are placed under layerblocks which means that the test would pass even without the change in this PR to move printfs under layers.

FileCheck would really help here. 🙃

}

class ASCIIPrintfTester() extends Module {
printf((0x20 to 0x7e).map(_.toChar).mkString.replace("%", "%%"))
stop()
}

class MultiPrintfTester() extends Module {
val x = 254.U
val y = 255.U
printf("x=%x y=%x", x, y)
stop()
}

class ASCIIPrintableTester extends Module {
printf(PString((0x20 to 0x7e).map(_.toChar).mkString("")))
stop()
}

class ScopeTesterModule extends Module {
Expand All @@ -42,7 +38,10 @@ class ScopeTesterModule extends Module {

class PrintfSpec extends ChiselFlatSpec {
"A printf with a single argument" should "elaborate" in {
ChiselStage.emitCHIRRTL(new SinglePrintfTester)
val chirrtl = ChiselStage.emitCHIRRTL(new SinglePrintfTester)

info("printfs are wrapped in the `Verification` layerblock by default")
chirrtl should include("layerblock Verification")
}
"A printf with multiple arguments" should "elaborate" in {
ChiselStage.emitCHIRRTL(new MultiPrintfTester)
Expand Down