Skip to content

Commit

Permalink
Add failing example to docs
Browse files Browse the repository at this point in the history
Better docs for the error

Update error message to not mention the p-interpolator
  • Loading branch information
adkian-sifive committed Sep 29, 2022
1 parent 2472786 commit 7a11bd4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion core/src/main/scala/chisel3/Printf.scala
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ object printf {
case q"scala.StringContext.apply(..$_).s(..$_)" =>
c.error(
c.enclosingPosition,
"s-interpolators for Chisel assert, assume and printf statements are deprecated (since 3.5); use p or cf interpolators instead"
"The s-interpolator for Chisel assert, assume and printf statements are deprecated (since 3.5); use the cf interpolator instead"
)
case _ =>
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/chisel3/VerificationStatement.scala
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ object assert extends VerifPrintMacrosDoc {
case q"scala.StringContext.apply(..$_).s(..$_)" =>
c.error(
c.enclosingPosition,
"s-interpolators for Chisel assert, assume and printf statements are deprecated (since 3.5); use p or cf interpolators instead"
"The s-interpolator for Chisel assert, assume and printf statements are deprecated (since 3.5); use the cf interpolator instead"
)
case _ =>
}
Expand Down Expand Up @@ -292,7 +292,7 @@ object assume extends VerifPrintMacrosDoc {
case q"scala.StringContext.apply(..$_).s(..$_)" =>
c.error(
c.enclosingPosition,
"s-interpolators for Chisel assert, assume and printf statements are deprecated (since 3.5); use p or cf interpolators instead"
"The s-interpolator for Chisel assert, assume and printf statements are deprecated (since 3.5); use the cf interpolator instead"
)
case _ =>
}
Expand Down
14 changes: 11 additions & 3 deletions docs/src/explanations/printing.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,21 @@ Chisel provides the `printf` function for debugging purposes. It comes in two fl

### Scala-style

Chisel also supports printf in a style similar to [Scala's String Interpolation](http://docs.scala-lang.org/overviews/core/string-interpolation.html). Chisel provides a custom string interpolator `cf` which follows C-style format specifiers (see section [C-style](#c-style) below). Here's a few examples of using the `cf` interpolator:
Chisel also supports printf in a style similar to [Scala's String Interpolation](http://docs.scala-lang.org/overviews/core/string-interpolation.html). Chisel provides a custom string interpolator `cf` which follows C-style format specifiers (see section [C-style](#c-style) below). Note that the Scala s-interpolator is not supported and will throw an error:

```scala mdoc:invisible
import chisel3._
```

```scala mdoc:fail
class MyModule extends Module {
val in = IO(Input(UInt(8.W)))
printf(s"in = $in\n")
}
```

Here's a few examples of using the `cf` interpolator:

```scala mdoc:compile-only
val myUInt = 33.U
printf(cf"myUInt = $myUInt") // myUInt = 33
Expand Down Expand Up @@ -103,8 +113,6 @@ Message:

Notice the use of `+` between `cf` interpolated "strings". The results of `cf` interpolation can be concatenated by using the `+` operator.

> :warning: The Scala s-interpolator is deprecated since 3.5 and will output the warning: "s-interpolators for Chisel assert, assume and printf statements are deprecated (since 3.5); use p or cf interpolators instead"
### C-Style

Chisel provides `printf` in a similar style to its C namesake. It accepts a double-quoted format string and a variable number of arguments which will then be printed on rising clock edges. Chisel supports the following format specifiers:
Expand Down

0 comments on commit 7a11bd4

Please sign in to comment.