summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Waterman2016-04-15 00:39:32 -0700
committerAndrew Waterman2016-04-15 00:39:32 -0700
commit4249c7dea0fece098df99c4713987a44cebf84b0 (patch)
treeb36963de23c6941453a32d8cc923938f03cace88
parent09ce36e79ba5a999d0e47ec482bbf06857cf7043 (diff)
Test FIRRTL string literals more aggressively
-rw-r--r--src/main/scala/Chisel/internal/firrtl/IR.scala15
-rw-r--r--src/test/scala/chiselTests/Printf.scala8
2 files changed, 15 insertions, 8 deletions
diff --git a/src/main/scala/Chisel/internal/firrtl/IR.scala b/src/main/scala/Chisel/internal/firrtl/IR.scala
index beb32e6c..4c039e9a 100644
--- a/src/main/scala/Chisel/internal/firrtl/IR.scala
+++ b/src/main/scala/Chisel/internal/firrtl/IR.scala
@@ -167,16 +167,15 @@ case class Port(id: Data, dir: Direction)
case class Printf(clk: Arg, formatIn: String, ids: Seq[Arg]) extends Command {
require(formatIn.forall(c => c.toInt > 0 && c.toInt < 128), "format strings must comprise non-null ASCII values")
def format: String = {
- def escaped(x: Char) =
- if (x == '"' || x == '\\' || x == '?') {
- "\\" + x
- } else if (x == '\n') {
- "\\n"
- } else if (x.toInt < 32) {
- s"\\x${BigInt(x.toInt).toString(16)}"
- } else {
+ def escaped(x: Char) = {
+ require(x.toInt >= 0)
+ if (x == '"' || x == '\\') s"\\${x}"
+ else if (x == '\n') "\\n"
+ else {
+ require(x.toInt >= 32) // TODO \xNN once FIRRTL issue #59 is resolved
x
}
+ }
formatIn.map(escaped _).mkString
}
}
diff --git a/src/test/scala/chiselTests/Printf.scala b/src/test/scala/chiselTests/Printf.scala
index 950f315a..eb8b4b25 100644
--- a/src/test/scala/chiselTests/Printf.scala
+++ b/src/test/scala/chiselTests/Printf.scala
@@ -12,6 +12,11 @@ class SinglePrintfTester() extends BasicTester {
stop()
}
+class ASCIIPrintfTester() extends BasicTester {
+ printf((0x20 to 0x7e).map(_ toChar).mkString.replace("%", "%%"))
+ stop()
+}
+
class MultiPrintfTester() extends BasicTester {
val x = UInt(254)
val y = UInt(255)
@@ -26,4 +31,7 @@ class PrintfSpec extends ChiselFlatSpec {
"A printf with multiple arguments" should "run" in {
assertTesterPasses { new MultiPrintfTester }
}
+ "A printf with ASCII characters 1-127" should "run" in {
+ assertTesterPasses { new ASCIIPrintfTester }
+ }
}