X-Git-Url: http://sraa.de/git/?a=blobdiff_plain;f=dol%2Fsrc%2Fdol%2Fvisitor%2Fdot%2FArchDotVisitor.java;fp=dol%2Fsrc%2Fdol%2Fvisitor%2Fdot%2FArchDotVisitor.java;h=5f71ee8d62e1063fe07ab6ced7b057c253eb56af;hb=8c411cf24ed0eb889191aaeafd8fa1e69081df42;hp=0000000000000000000000000000000000000000;hpb=dea7a4fb1ed110d3ce6e6d9255103d724bd66c0e;p=jump.git diff --git a/dol/src/dol/visitor/dot/ArchDotVisitor.java b/dol/src/dol/visitor/dot/ArchDotVisitor.java new file mode 100644 index 0000000..5f71ee8 --- /dev/null +++ b/dol/src/dol/visitor/dot/ArchDotVisitor.java @@ -0,0 +1,250 @@ +/* $Id: ArchDotVisitor.java 1 2010-02-24 13:03:05Z haidw $ */ +package dol.visitor.dot; + +import java.util.Iterator; + +import dol.datamodel.architecture.ArchiConnection; +import dol.datamodel.architecture.Architecture; +import dol.datamodel.architecture.HWChannel; +import dol.datamodel.architecture.Memory; +import dol.datamodel.architecture.Processor; +import dol.datamodel.architecture.ReadPath; +import dol.datamodel.architecture.WritePath; +import dol.datamodel.pn.Process; +import dol.util.CodePrintStream; +import dol.visitor.ArchiVisitor; + +/** + * Helps to generate DOTTY information for architecture resources. + */ +public class ArchDotVisitor extends ArchiVisitor +{ + /** + * Constructor. + * + * @param printStream print stream to which the contents is written + */ + public ArchDotVisitor(CodePrintStream printStream) { + _printStream = printStream; + _pnVisitor = new PNDotVisitor(printStream); + } + + /** + * Print a .dot file in the correct format for DOTTY. + * + * @param arch architecture that needs to be rendered + */ + public void visitComponent(Architecture arch) { + _printStream.printPrefixln("digraph architecture {"); + _printStream.println(); + _printStream.prefixInc(); + _printStream.printPrefixln("ratio = auto;"); + _printStream.printPrefixln("rankdir = LR;"); + _printStream.printPrefixln("ranksep = 2;"); + _printStream.printPrefixln("nodesep = 0.2;"); + _printStream.printPrefixln("center = true;"); + _printStream.printPrefixln(""); + _printStream.printPrefixln("node [ fontsize=12, height=0.4, " + + "width=0.4, style=filled, color=\"0.65 0.20 1.00\" ]"); + _printStream.println(); + + //visit all processors + Processor processor; + Iterator processorIter = arch.getProcessorList().iterator(); + while( processorIter.hasNext() ) { + processor = processorIter.next(); + processor.accept(this); + } + + //visit all hw_channels + HWChannel chan; + Iterator chanIter = arch.getHWChannelList().iterator(); + while(chanIter.hasNext()) { + chan = chanIter.next(); + chan.accept(this); + } + + //visit all memories + Memory mem; + Iterator memIter = arch.getMemoryList().iterator(); + while(memIter.hasNext()) { + mem = memIter.next(); + mem.accept(this); + } + + //visit all connections + ArchiConnection cn; + Iterator cnIter = arch.getConnectionList().iterator(); + while(cnIter.hasNext()) { + cn = cnIter.next(); + cn.accept(this); + } + + ReadPath rPath; + Iterator rpIter = arch.getReadPathList().iterator(); + while(rpIter.hasNext()) { + rPath = rpIter.next(); + rPath.accept(this); + } + + WritePath wPath; + Iterator wpIter = arch.getWritePathList().iterator(); + while(wpIter.hasNext()) { + wPath = wpIter.next(); + wPath.accept(this); + } + + _printStream.prefixDec(); + _printStream.println(); + _printStream.printPrefixln("}"); + } + + public void visitComponent(HWChannel chan) + { + _printStream.printPrefixln("subgraph cluster_" + + chan.getName().replaceAll("\\.", "") + " {"); + _printStream.prefixInc(); + _printStream.printPrefixln("label = \"" + chan.getName() + "\""); + + if (!chan.getPathList().isEmpty()) { + Iterator pIter = chan.getPathList().iterator(); + String path; + while (pIter.hasNext()) { + path = (String) pIter.next(); + _printStream.printPrefixln("\"" + path + "_" + chan.getName() + + "\" [label=\" " + + "\" shape=circle style=solid]"); + } + } + + _printStream.prefixDec(); + _printStream.printPrefixln("}"); + _printStream.println(); + } + + public void visitComponent(Memory mem) + { + _printStream.printPrefixln("subgraph cluster_" + + mem.getName().replaceAll("\\.", "") + " {"); + _printStream.prefixInc(); + _printStream.printPrefixln("label = \"" + mem.getName() + "\""); + + if (!mem.getRXBufList().isEmpty()) { + Iterator rIter = mem.getRXBufList().iterator(); + String rxBuf; + while (rIter.hasNext()) { + rxBuf = (String) rIter.next(); + _printStream.printPrefixln("\"" + rxBuf.replaceAll("\\.", "") + + "_RX\" [label=\"RX" + + "\" shape=circle style=dotted]"); + } + } + + if (!mem.getTXBufList().isEmpty()) { + Iterator rIter = mem.getTXBufList().iterator(); + String txBuf; + while (rIter.hasNext()) { + txBuf = (String) rIter.next(); + _printStream.printPrefixln("\"" + txBuf.replaceAll("\\.", "") + + "_TX\" [label=\"TX" + + "\" shape=circle style=dashed]"); + } + } + + if (!mem.getCHBufList().isEmpty()) { + Iterator rIter = mem.getCHBufList().iterator(); + String chBuf; + while (rIter.hasNext()) { + chBuf = (String) rIter.next(); + _printStream.printPrefixln("\"" + chBuf.replaceAll("\\.", "") + + "_CH\" [label=\"CH" + + "\" shape=circle style=bold]"); + } + } + + _printStream.prefixDec(); + _printStream.printPrefixln("}"); + _printStream.println(); + } + + + public void visitComponent(ArchiConnection cn) + { + _printStream.printPrefix(); + _printStream.print("\"" + + cn.getOrigin().getName().replaceAll("\\.", "") + "\" -> \"" + + cn.getTarget().getName().replaceAll("\\.", "") + + "\" [ color=" + _color + " ];"); + _printStream.println(); + } + + public void visitComponent(ReadPath rp) + { + String rName = rp.getName().replaceAll("\\.", ""); + + _printStream.printPrefix(); + _printStream.print(rName + "_RPath_CH->" ); + + Iterator cIter = rp.getHWChannelList().iterator(); + while (cIter.hasNext()) { + HWChannel channel = cIter.next(); + _printStream.print(rName + "_RPath_" + + channel.getName().replaceAll("\\.", "") + + "->"); + } + _printStream.println(rName + "_RX"); + } + + public void visitComponent(WritePath rp) + { + String rName = rp.getName().replaceAll("\\.", ""); + + _printStream.printPrefix(); + _printStream.print(rName + "_TX->" ); + + Iterator cIter = rp.getHWChannelList().iterator(); + while (cIter.hasNext()) { + HWChannel channel = cIter.next(); + _printStream.print(rName + "_WPath_" + + channel.getName().replaceAll("\\.", "") + + "->"); + } + _printStream.println(rName + "_WPath_CH"); + } + + /** + * Clusters all processes of this processor. + */ + public void visitComponent(Processor processor) + { + /* + _printStream.printPrefix(); + _printStream.print("\"" + processor.getName() + "\" [ label=\"" + + processor.getName() + "\", color=" + _color + + ", shape=box];"); + _printStream.println(); + */ + + _printStream.printPrefixln("subgraph cluster_" + + processor.getName().replaceAll("\\.", "") + " {"); + _printStream.prefixInc(); + _printStream.printPrefixln("label = \"" + processor.getName() + "\""); + + // labeleling clusters with dot2.8 & graphviz2.8 seems buggy + //_printStream.printPrefixln("label = \"" + processor.getName()+"\";"); + if (!processor.getProcessList().isEmpty()) { + Iterator pIter = processor.getProcessList().iterator(); + while (pIter.hasNext()) { + pIter.next().accept(_pnVisitor); + } + } + _printStream.prefixDec(); + _printStream.printPrefixln("}"); + _printStream.println(); + } + + /** DOT Visitor to visit process network resources */ + protected PNDotVisitor _pnVisitor = null; + + protected String _color = "dimgray"; +}