diff --git a/src/main/scala/uncore/tilelink2/LazyModule.scala b/src/main/scala/uncore/tilelink2/LazyModule.scala
index 37c0e0d9..87398092 100644
--- a/src/main/scala/uncore/tilelink2/LazyModule.scala
+++ b/src/main/scala/uncore/tilelink2/LazyModule.scala
@@ -34,11 +34,49 @@ abstract class LazyModule
}
bindings.reverse.foreach { f => f () }
}
+
+ def omitGraphML = nodes.isEmpty && children.isEmpty
+ lazy val graphML: String = parent.map(_.graphML).getOrElse {
+ val buf = new StringBuilder
+ buf ++= "\n"
+ buf ++= "\n"
+ buf ++= " \n"
+ buf ++= " \n"
+ nodesGraphML(buf, " ")
+ edgesGraphML(buf, " ")
+ buf ++= " \n"
+ buf ++= "\n"
+ buf.toString
+ }
+
+ private val index = { LazyModule.index = LazyModule.index + 1; LazyModule.index }
+
+ private def nodesGraphML(buf: StringBuilder, pad: String) {
+ buf ++= s"""${pad}\n"""
+ buf ++= s"""${pad} ${name}\n"""
+ buf ++= s"""${pad} \n"""
+ nodes.filter(!_.omitGraphML).foreach { n =>
+ buf ++= s"""${pad} \n"""
+ }
+ children.filter(!_.omitGraphML).foreach { _.nodesGraphML(buf, pad + " ") }
+ buf ++= s"""${pad} \n"""
+ buf ++= s"""${pad}\n"""
+ }
+ private def edgesGraphML(buf: StringBuilder, pad: String) {
+ nodes.filter(!_.omitGraphML) foreach { n => n.outputs.filter(!_.omitGraphML).foreach { o =>
+ buf ++= pad
+ buf ++= "\n"""
+ } }
+ children.filter(!_.omitGraphML).foreach { c => c.edgesGraphML(buf, pad) }
+ }
}
object LazyModule
{
protected[tilelink2] var stack = List[LazyModule]()
+ private var index = 0
def apply[T <: LazyModule](bc: T)(implicit sourceInfo: SourceInfo): T = {
// Make sure the user put LazyModule around modules in the correct order