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

Printf: Add support for tabs, and give helpful error messages #1323

Merged
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
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