06d510d12d76e61e94a2f0b3f49f23ed95c69168
[jump.git] / dol / src / dol / datamodel / architecture / Architecture.java
1 /* $Id: Architecture.java 1 2010-02-24 13:03:05Z haidw $ */
2 package dol.datamodel.architecture;
3
4 import java.util.Hashtable;
5 import java.util.Vector;
6
7 import dol.visitor.ArchiVisitor;
8
9
10 /**
11  * This class defines an architecture.
12  */
13 public class Architecture extends ArchiResource {
14     /**
15      *  Constructor to create an architecture with a name,
16      *  empty processor list, empty memory list, empty hwChannel list and empty connection list.
17      */
18     public Architecture(String name) {
19         super(name);
20         _processorList = new Vector<Processor>();
21         _memoryList = new Vector<Memory>();
22         _hwChannelList = new Vector<HWChannel>();
23         _varList = new Vector<Variable>();
24         _connectionList = new Vector<ArchiConnection>();
25         _readPathList = new Vector<ReadPath>();
26         _writePathList = new Vector<WritePath>();
27         _pathList = new Vector<Path>();
28         _processorPathList = new Hashtable<Processor,
29                 Hashtable<Processor, Vector<Path>>>();
30
31     }
32
33     /**
34      * Accept a visitor
35      *
36      * @param x visitor object
37      */
38     public void accept(ArchiVisitor x) {
39         x.visitComponent(this);
40     }
41
42     /**
43      * Clone this Architecture.
44      *
45      * @return new instance of the Architecure
46      */
47     /*
48     @SuppressWarnings("unchecked")
49     public Object clone() {
50         Architecture newObj = (Architecture) super.clone();
51         newObj.setProcessorList((Vector<Processor>)_processorList.clone());
52         newObj.setMemoryList((Vector<Memory>)_memoryList.clone());
53         newObj.setHWChannelList((Vector<HWChannel>)_hwChannelList.clone());
54         newObj.setVarList((Vector<Variable>)_varList.clone());
55         newObj.setConnectionList((Vector<ArchiConnection>)_connectionList.clone());
56         newObj.setReadPathList((Vector<ReadPath>)_readPathList.clone());
57         newObj.setWritePathList((Vector<WritePath>)_writePathList.clone());
58         newObj.setPathList((Vector<Vector<Node>>)_pathList.clone());
59         return newObj;
60     }
61     */
62
63
64     /**
65      * Get the processor list of a Architecture.
66      *
67      * @return the processor list
68      */
69     public Vector<Processor> getProcessorList() {
70         return _processorList;
71     }
72
73     /**
74      * Get the memory list of a Architecture.
75      *
76      * @return the memory list
77      */
78     public Vector<Memory> getMemoryList() {
79         return _memoryList;
80     }
81
82     /**
83      * Get the hwChannel list of a Architecture.
84      *
85      * @return the hwChannel list
86      */
87     public Vector<HWChannel> getHWChannelList() {
88         return _hwChannelList;
89     }
90
91     /**
92      * Get the  paths list of a Architecture.
93      *
94      * @return the paths list
95      */
96     public Vector<ReadPath> getReadPathList() {
97         return _readPathList;
98     }
99
100     /**
101      * Get the write paths list of a Architecture.
102      *
103      * @return the paths list
104      */
105     public Vector<WritePath> getWritePathList( ) {
106         return _writePathList;
107     }
108
109     /**
110      * Set the processor paths list of a Architecture.
111      *
112      * @param pathList The new list
113      */
114     public void setPathList(Vector<Path> pathList) {
115         _pathList = pathList;
116     }
117
118     /**
119      * Get the processor paths list of a Architecture.
120      *
121      * @return the processor paths list
122      */
123     public Vector<Path> getPathList() {
124         return _pathList;
125     }
126
127     /**
128      * Return a processor/memory/hwChannel which has a specific name. Return null if
129      * processor cannot be found.
130      *
131      * @param name the name of the processor/memory/hwChannel to search for.
132      * @return the processor/memory/hwChannel with the specific name.
133      */
134     public Processor getProcessor(String name) {
135         for (Processor processor : _processorList) {
136             if (processor.getName().equals(name)) {
137                 return processor;
138             }
139         }
140         return null;
141     }
142
143     /**
144      *
145      */
146     public Memory getMemory(String name) {
147         for (Memory memory : _memoryList) {
148             if (memory.getName().equals(name)) {
149                 return memory;
150             }
151         }
152         return null;
153     }
154
155     /**
156      *
157      */
158     public HWChannel getHWChannel(String name) {
159         for (HWChannel hwChannel : _hwChannelList) {
160             if (hwChannel.getName().equals(name)) {
161                 return hwChannel;
162             }
163         }
164         return null;
165     }
166
167     
168     /**
169      * Return a read path which has a specific name. Return null if
170      * not found.
171      *
172      * @param  name the name of the read path to search for.
173      * @return the read path with the specific name.
174      */
175     public ReadPath getReadPath(String name) {
176         for (ReadPath p : _readPathList) {
177             if (p.getName().equals(name)) {
178                 return p;
179             }
180         }
181         return null;
182     }
183     
184     /**
185      * Return a write path which has a specific name. Return null if
186      * not found.
187      *
188      * @param  name the name of the write path to search for.
189      * @return the write path with the specific name.
190      */
191     public WritePath getWritePath(String name) {
192         for (WritePath p : _writePathList) {
193             if (p.getName().equals(name)) {
194                 return p;
195             }
196         }
197         return null;
198     }
199     
200     public Vector<Variable> getVarList() { return _varList; }
201
202     public Vector<ArchiConnection> getConnectionList() {
203         return _connectionList;
204     }
205
206     /**
207      * Compute all paths between processors.
208      */
209     public void computePaths() {
210         for (WritePath w : _writePathList) {
211             String channelBuffer = w.getCHBuf().getName();
212             for (ReadPath r : _readPathList) {
213                 if (r.getCHBuf().getName().equals(channelBuffer)) {
214                     Path path = new Path();
215                     path.setWritePath(w);
216                     path.setReadPath(r);
217                     _pathList.add(path);
218                 }
219             }
220         }
221
222         /*
223         //print all paths in this architecture
224         for (int j = 0; j < _pathList.size(); j++) {
225             Vector<ArchiResource> path = _pathList.elementAt(j).getPath();
226             for (int k = 0; k < path.size(); k++) {
227                 System.out.print(path.elementAt(k).
228                         getName() + (k < path.size() - 1 ? " -> " : ""));
229             }
230             System.out.println();
231         }
232         System.out.println("Found " + _pathList.size() + " paths.");
233         */
234
235         computeProcessorPath();
236     }
237
238     /**
239      * Compute all write path from one processor to another processor
240      * in this architecture.
241      */
242     protected void computeProcessorPath() {
243         //iterate over all path in this architecture
244         for (int j = 0; j < _pathList.size(); j++) {
245             Processor startProcessor = _pathList.elementAt(j).getStartProcessor();
246             Processor targetProcessor = _pathList.elementAt(j).getTargetProcessor();
247
248             //create new hashtable entry for this start processor
249             if (!_processorPathList.containsKey(startProcessor)) {
250                 Hashtable<Processor, Vector<Path>>
251                         processorPathList = new Hashtable<Processor,
252                         Vector<Path>>();
253                 _processorPathList.put(startProcessor, processorPathList);
254             }
255
256             Hashtable<Processor, Vector<Path>>
257                     processorPathList = _processorPathList.
258                     get(startProcessor);
259
260             //create new path list for this target processor
261             if(!processorPathList.containsKey(targetProcessor)) {
262                 Vector<Path> processorPath = new Vector<Path>();
263                 processorPathList.put(targetProcessor, processorPath);
264             }
265
266             Vector<Path> processorPath =
267                     processorPathList.get(targetProcessor);
268
269             //add this path to the list of paths
270             processorPath.add(_pathList.elementAt(j));
271         }
272
273         /*
274         //print all processor to processor path
275         int pathCounter = 0;
276         for (int j = 0; j < _processorList.size(); j++) {
277             for (int k = 0; k < _processorList.size(); k++) {
278                 Vector<Path> processorPathList =
279                         getPaths(_processorList.elementAt(j),
280                         _processorList.elementAt(k));
281                 for (int l = 0; l < processorPathList.size(); l++) {
282                     pathCounter++;
283                     Vector<ArchiResource> path = processorPathList.
284                             elementAt(l).getPath();
285                     for (int m = 0; m < path.size(); m++) {
286                         System.out.print(path.elementAt(m).getName()
287                         + (m < path.size() - 1 ? " -> " : ""));
288                     }
289                     System.out.println();
290                 }
291             }
292         }
293         System.out.println("Found " + pathCounter + " paths.");
294         */
295     }
296
297     /**
298      * Get all write paths from the given start processor to the given
299      * target processor.
300      *
301      * @param startProcessor processor where write path begins
302      * @param targetProcessor processor where write path ends
303      * @return vector of all write paths between startProcessor and
304      *         targetProcessor
305      */
306     public Vector<Path> getPaths(
307             Processor startProcessor, Processor targetProcessor) {
308         if (_processorPathList.get(startProcessor) == null) {
309             return null;
310         }
311         return _processorPathList.get(startProcessor).get(targetProcessor);
312     }
313
314     /**
315      * Register the RX/TX/CH buffer to each resource.
316      * Can be used for dotty generation.
317      */
318     public void registerRWPath2Resource()
319     {
320         for (ReadPath r : _readPathList) {
321             // register rxbuf
322             String memName = r.getRXBuf().getName();
323             for (Memory m : _memoryList) {
324                 if (m.getName().equals(memName)) {
325                     m.getRXBufList().add(r.getName());
326                 }
327             }
328
329             // register chbuf
330             memName = r.getCHBuf().getName();
331             for (Memory m : _memoryList) {
332                 if (m.getName().equals(memName)) {
333                     m.getCHBufList().add(r.getName() + "_RPath");
334                 }
335             }
336
337             // register pathes via a communication resource
338             for (HWChannel c : r.getHWChannelList()) {
339                 if (c.getName().equals(r.getName())) {
340                     // premise: a path cannot go via a bus twice.
341                     c.getPathList().add(r.getName() + "_RPath");
342                 }
343             }
344         }
345
346         for (WritePath w : _writePathList) {
347             // register txbuf
348             String memName = w.getTXBuf().getName();
349             for (Memory m : _memoryList) {
350                 if (m.getName().equals(memName)) {
351                     m.getTXBufList().add(w.getName());
352                 }
353             }
354
355             // register chbuf
356             memName = w.getCHBuf().getName();
357             for (Memory m : _memoryList) {
358                 if (m.getName().equals(memName)) {
359                     m.getCHBufList().add(w.getName() + "_WPath");
360                 }
361             }
362
363             // register pathes via a communication resource
364             for (HWChannel c : w.getHWChannelList()) {
365                 if (c.getName().equals(w.getName())) {
366                     // premise: a path cannot go via a bus twice.
367                     c.getPathList().add(w.getName() + "_WPath");
368                 }
369             }
370         }
371     }
372
373     /** List of the processors in the Architecture */
374     protected Vector<Processor> _processorList = null;
375
376     /** List of the memories in the Architecture */
377     protected Vector<Memory> _memoryList = null;
378
379     /** List of hwChannels in the Architecture */
380     protected Vector<HWChannel> _hwChannelList = null;
381
382     /** List of variables in the Architecture */
383     protected Vector<Variable> _varList = null;
384
385     /** List of connections in the Architecture: for simplified arch*/
386     protected Vector<ArchiConnection> _connectionList = null;
387
388     /** List of read paths in the Architecture: for detail arch */
389     protected Vector<ReadPath> _readPathList = null;
390
391     /** List of write paths in the Architecture: for detail arch */
392     protected Vector<WritePath> _writePathList = null;
393
394     /** List of paths in the Architecture */
395     protected Vector<Path> _pathList = null;
396
397     /** hashtable to access all processor to processor path */
398     protected Hashtable<Processor, Hashtable<Processor,
399             Vector<Path>>> _processorPathList = null;
400 }