1 /* $Id: ArchDotVisitor.java 1 2010-02-24 13:03:05Z haidw $ */
2 package dol.visitor.dot;
4 import java.util.Iterator;
6 import dol.datamodel.architecture.ArchiConnection;
7 import dol.datamodel.architecture.Architecture;
8 import dol.datamodel.architecture.HWChannel;
9 import dol.datamodel.architecture.Memory;
10 import dol.datamodel.architecture.Processor;
11 import dol.datamodel.architecture.ReadPath;
12 import dol.datamodel.architecture.WritePath;
13 import dol.datamodel.pn.Process;
14 import dol.util.CodePrintStream;
15 import dol.visitor.ArchiVisitor;
18 * Helps to generate DOTTY information for architecture resources.
20 public class ArchDotVisitor extends ArchiVisitor
25 * @param printStream print stream to which the contents is written
27 public ArchDotVisitor(CodePrintStream printStream) {
28 _printStream = printStream;
29 _pnVisitor = new PNDotVisitor(printStream);
33 * Print a .dot file in the correct format for DOTTY.
35 * @param arch architecture that needs to be rendered
37 public void visitComponent(Architecture arch) {
38 _printStream.printPrefixln("digraph architecture {");
39 _printStream.println();
40 _printStream.prefixInc();
41 _printStream.printPrefixln("ratio = auto;");
42 _printStream.printPrefixln("rankdir = LR;");
43 _printStream.printPrefixln("ranksep = 2;");
44 _printStream.printPrefixln("nodesep = 0.2;");
45 _printStream.printPrefixln("center = true;");
46 _printStream.printPrefixln("");
47 _printStream.printPrefixln("node [ fontsize=12, height=0.4, "
48 + "width=0.4, style=filled, color=\"0.65 0.20 1.00\" ]");
49 _printStream.println();
51 //visit all processors
53 Iterator<Processor> processorIter = arch.getProcessorList().iterator();
54 while( processorIter.hasNext() ) {
55 processor = processorIter.next();
56 processor.accept(this);
59 //visit all hw_channels
61 Iterator<HWChannel> chanIter = arch.getHWChannelList().iterator();
62 while(chanIter.hasNext()) {
63 chan = chanIter.next();
69 Iterator<Memory> memIter = arch.getMemoryList().iterator();
70 while(memIter.hasNext()) {
75 //visit all connections
77 Iterator<ArchiConnection> cnIter = arch.getConnectionList().iterator();
78 while(cnIter.hasNext()) {
84 Iterator<ReadPath> rpIter = arch.getReadPathList().iterator();
85 while(rpIter.hasNext()) {
86 rPath = rpIter.next();
91 Iterator<WritePath> wpIter = arch.getWritePathList().iterator();
92 while(wpIter.hasNext()) {
93 wPath = wpIter.next();
97 _printStream.prefixDec();
98 _printStream.println();
99 _printStream.printPrefixln("}");
102 public void visitComponent(HWChannel chan)
104 _printStream.printPrefixln("subgraph cluster_"
105 + chan.getName().replaceAll("\\.", "") + " {");
106 _printStream.prefixInc();
107 _printStream.printPrefixln("label = \"" + chan.getName() + "\"");
109 if (!chan.getPathList().isEmpty()) {
110 Iterator<String> pIter = chan.getPathList().iterator();
112 while (pIter.hasNext()) {
113 path = (String) pIter.next();
114 _printStream.printPrefixln("\"" + path + "_" + chan.getName()
116 "\" shape=circle style=solid]");
120 _printStream.prefixDec();
121 _printStream.printPrefixln("}");
122 _printStream.println();
125 public void visitComponent(Memory mem)
127 _printStream.printPrefixln("subgraph cluster_"
128 + mem.getName().replaceAll("\\.", "") + " {");
129 _printStream.prefixInc();
130 _printStream.printPrefixln("label = \"" + mem.getName() + "\"");
132 if (!mem.getRXBufList().isEmpty()) {
133 Iterator<String> rIter = mem.getRXBufList().iterator();
135 while (rIter.hasNext()) {
136 rxBuf = (String) rIter.next();
137 _printStream.printPrefixln("\"" + rxBuf.replaceAll("\\.", "")
138 + "_RX\" [label=\"RX"
139 + "\" shape=circle style=dotted]");
143 if (!mem.getTXBufList().isEmpty()) {
144 Iterator<String> rIter = mem.getTXBufList().iterator();
146 while (rIter.hasNext()) {
147 txBuf = (String) rIter.next();
148 _printStream.printPrefixln("\"" + txBuf.replaceAll("\\.", "")
149 + "_TX\" [label=\"TX"
150 + "\" shape=circle style=dashed]");
154 if (!mem.getCHBufList().isEmpty()) {
155 Iterator<String> rIter = mem.getCHBufList().iterator();
157 while (rIter.hasNext()) {
158 chBuf = (String) rIter.next();
159 _printStream.printPrefixln("\"" + chBuf.replaceAll("\\.", "")
160 + "_CH\" [label=\"CH"
161 + "\" shape=circle style=bold]");
165 _printStream.prefixDec();
166 _printStream.printPrefixln("}");
167 _printStream.println();
171 public void visitComponent(ArchiConnection cn)
173 _printStream.printPrefix();
174 _printStream.print("\""
175 + cn.getOrigin().getName().replaceAll("\\.", "") + "\" -> \""
176 + cn.getTarget().getName().replaceAll("\\.", "")
177 + "\" [ color=" + _color + " ];");
178 _printStream.println();
181 public void visitComponent(ReadPath rp)
183 String rName = rp.getName().replaceAll("\\.", "");
185 _printStream.printPrefix();
186 _printStream.print(rName + "_RPath_CH->" );
188 Iterator<HWChannel> cIter = rp.getHWChannelList().iterator();
189 while (cIter.hasNext()) {
190 HWChannel channel = cIter.next();
191 _printStream.print(rName + "_RPath_"
192 + channel.getName().replaceAll("\\.", "")
195 _printStream.println(rName + "_RX");
198 public void visitComponent(WritePath rp)
200 String rName = rp.getName().replaceAll("\\.", "");
202 _printStream.printPrefix();
203 _printStream.print(rName + "_TX->" );
205 Iterator<HWChannel> cIter = rp.getHWChannelList().iterator();
206 while (cIter.hasNext()) {
207 HWChannel channel = cIter.next();
208 _printStream.print(rName + "_WPath_"
209 + channel.getName().replaceAll("\\.", "")
212 _printStream.println(rName + "_WPath_CH");
216 * Clusters all processes of this processor.
218 public void visitComponent(Processor processor)
221 _printStream.printPrefix();
222 _printStream.print("\"" + processor.getName() + "\" [ label=\""
223 + processor.getName() + "\", color=" + _color
225 _printStream.println();
228 _printStream.printPrefixln("subgraph cluster_"
229 + processor.getName().replaceAll("\\.", "") + " {");
230 _printStream.prefixInc();
231 _printStream.printPrefixln("label = \"" + processor.getName() + "\"");
233 // labeleling clusters with dot2.8 & graphviz2.8 seems buggy
234 //_printStream.printPrefixln("label = \"" + processor.getName()+"\";");
235 if (!processor.getProcessList().isEmpty()) {
236 Iterator<Process> pIter = processor.getProcessList().iterator();
237 while (pIter.hasNext()) {
238 pIter.next().accept(_pnVisitor);
241 _printStream.prefixDec();
242 _printStream.printPrefixln("}");
243 _printStream.println();
246 /** DOT Visitor to visit process network resources */
247 protected PNDotVisitor _pnVisitor = null;
249 protected String _color = "dimgray";