Skip to content

Commit

Permalink
Printf: Add support for tabs, and give helpful error messages (#1323) (
Browse files Browse the repository at this point in the history
…#1326)

Co-authored-by: Megan Wachs <megan@sifive.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Feb 10, 2020
1 parent 355d11e commit 9a209b8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 4 additions & 2 deletions chiselFrontend/src/main/scala/chisel3/Printf.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ object printf { // scalastyle:ignore object.name
require(formatIn forall (c => c.toInt > 0 && c.toInt < 128),
"format strings must comprise non-null ASCII values")
def escaped(x: Char) = {
require(x.toInt >= 0)
require(x.toInt >= 0, s"char ${x} to Int ${x.toInt} must be >= 0")
if (x == '"' || x == '\\') {
s"\\${x}"
} else if (x == '\n') {
"\\n"
} else if (x == '\t') {
"\\t"
} else {
require(x.toInt >= 32) // TODO \xNN once FIRRTL issue #59 is resolved
require(x.toInt >= 32, s"char ${x} to Int ${x.toInt} must be >= 32") // TODO \xNN once FIRRTL issue #59 is resolved
x
}
}
Expand Down
10 changes: 10 additions & 0 deletions src/test/scala/chiselTests/PrintableSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,16 @@ class PrintableSpec extends FlatSpec with Matchers {
case e => fail()
}
}
it should "correctly emit tab" in {
class MyModule extends BasicTester {
printf(p"\t")
}
val firrtl = Driver.emit(() => new MyModule)
getPrintfs(firrtl) match {
case Seq(Printf("\\t", Seq())) =>
case e => fail()
}
}
it should "support names of circuit elements including submodule IO" in {
// Submodule IO is a subtle issue because the Chisel element has a different
// parent module
Expand Down

0 comments on commit 9a209b8

Please # to comment.