-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the ability to render printf statements (#24)
- default behavior is not to do it - added test to show it being included or not - Fix help message for --dot-timeout-seconds - Reduce size of literals bigger than 32 characters
- Loading branch information
Showing
5 changed files
with
141 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// See LICENSE for license details. | ||
|
||
package dotvisualizer.dotnodes | ||
|
||
import firrtl.WRef | ||
import firrtl.ir.Print | ||
|
||
import scala.collection.mutable | ||
|
||
case class PrintfNode(name: String, formatString: String, parentOpt: Option[DotNode]) extends DotNode { | ||
|
||
val text = new mutable.StringBuilder() | ||
|
||
override def absoluteName: String = "struct_" + super.absoluteName | ||
|
||
text.append( | ||
s""" | ||
|$absoluteName [shape="plaintext" label=< | ||
|<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4" BGCOLOR="#EA3076"> | ||
| <TR> | ||
| <TD>printf("$formatString") </TD> | ||
| </TR> | ||
""".stripMargin) | ||
|
||
def addArgument(displayName: String, connectTarget: String, connect: String): PrintfArgument = { | ||
val port = PrintfArgument(displayName, connect, connectTarget) | ||
text.append(s" ${port.render}") | ||
port | ||
} | ||
|
||
def finish() { | ||
text.append( | ||
""" | ||
|</TABLE>>]; | ||
""".stripMargin) | ||
} | ||
|
||
def render: String = text.toString() | ||
} | ||
|
||
case class PrintfArgument(name: String, override val absoluteName: String, connectTarget: String) extends DotNode { | ||
val parentOpt : Option[DotNode] = None // doesn't need to know parent | ||
def render: String = { | ||
s""" | ||
|<TR><TD PORT="$name">$name</TD></TR> | ||
""".stripMargin | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// See README.md for license details. | ||
|
||
package dotvisualizer | ||
|
||
import org.scalatest.{FreeSpec, Matchers} | ||
import chisel3._ | ||
import firrtl.FileUtils | ||
|
||
class HasPrintf extends MultiIOModule { | ||
val in = IO(Input(Bool())) | ||
val out = IO(Output(Bool())) | ||
out := in | ||
printf("in %d, out %d\n", in, out) | ||
} | ||
class PrintfSpec extends FreeSpec with Matchers { | ||
|
||
"printfs can now be rendered" - { | ||
val dirName = "test_run_dir/has_printf_on/" | ||
|
||
def makeDotFile(showPrintfs: Boolean): String = { | ||
val circuit = chisel3.Driver.elaborate(() => new HasPrintf) | ||
val firrtl = chisel3.Driver.emit(circuit) | ||
val config = Config( | ||
targetDir = dirName, | ||
firrtlSource = firrtl, | ||
rankDir = "TB", | ||
useRanking = true, | ||
showPrintfs = showPrintfs, | ||
openProgram = "" | ||
) | ||
FirrtlDiagrammer.run(config) | ||
|
||
FileUtils.getText(s"${dirName}HasPrintf.dot") | ||
} | ||
|
||
"showPrintfs=true will render printfs in dot file" in { | ||
val dotText = makeDotFile(showPrintfs = true) | ||
|
||
dotText.contains("struct_cluster_HasPrintf_printf_1") should be(true) | ||
dotText.contains("""printf("in %d, out %d\n")""") should be(true) | ||
} | ||
|
||
"default behavior will not render printfs in dot file" in { | ||
val dotText = makeDotFile(showPrintfs = false) | ||
|
||
dotText.contains("struct_cluster_HasPrintf_printf_1") should be(false) | ||
dotText.contains("""printf("in %d, out %d\n")""") should be(false) | ||
} | ||
} | ||
} |