1 /* $Id: Architecture.java 1 2010-02-24 13:03:05Z haidw $ */
2 package dol.datamodel.architecture;
4 import java.util.Hashtable;
5 import java.util.Vector;
7 import dol.visitor.ArchiVisitor;
11 * This class defines an architecture.
13 public class Architecture extends ArchiResource {
15 * Constructor to create an architecture with a name,
16 * empty processor list, empty memory list, empty hwChannel list and empty connection list.
18 public Architecture(String 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>>>();
36 * @param x visitor object
38 public void accept(ArchiVisitor x) {
39 x.visitComponent(this);
43 * Clone this Architecture.
45 * @return new instance of the Architecure
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());
65 * Get the processor list of a Architecture.
67 * @return the processor list
69 public Vector<Processor> getProcessorList() {
70 return _processorList;
74 * Get the memory list of a Architecture.
76 * @return the memory list
78 public Vector<Memory> getMemoryList() {
83 * Get the hwChannel list of a Architecture.
85 * @return the hwChannel list
87 public Vector<HWChannel> getHWChannelList() {
88 return _hwChannelList;
92 * Get the paths list of a Architecture.
94 * @return the paths list
96 public Vector<ReadPath> getReadPathList() {
101 * Get the write paths list of a Architecture.
103 * @return the paths list
105 public Vector<WritePath> getWritePathList( ) {
106 return _writePathList;
110 * Set the processor paths list of a Architecture.
112 * @param pathList The new list
114 public void setPathList(Vector<Path> pathList) {
115 _pathList = pathList;
119 * Get the processor paths list of a Architecture.
121 * @return the processor paths list
123 public Vector<Path> getPathList() {
128 * Return a processor/memory/hwChannel which has a specific name. Return null if
129 * processor cannot be found.
131 * @param name the name of the processor/memory/hwChannel to search for.
132 * @return the processor/memory/hwChannel with the specific name.
134 public Processor getProcessor(String name) {
135 for (Processor processor : _processorList) {
136 if (processor.getName().equals(name)) {
146 public Memory getMemory(String name) {
147 for (Memory memory : _memoryList) {
148 if (memory.getName().equals(name)) {
158 public HWChannel getHWChannel(String name) {
159 for (HWChannel hwChannel : _hwChannelList) {
160 if (hwChannel.getName().equals(name)) {
169 * Return a read path which has a specific name. Return null if
172 * @param name the name of the read path to search for.
173 * @return the read path with the specific name.
175 public ReadPath getReadPath(String name) {
176 for (ReadPath p : _readPathList) {
177 if (p.getName().equals(name)) {
185 * Return a write path which has a specific name. Return null if
188 * @param name the name of the write path to search for.
189 * @return the write path with the specific name.
191 public WritePath getWritePath(String name) {
192 for (WritePath p : _writePathList) {
193 if (p.getName().equals(name)) {
200 public Vector<Variable> getVarList() { return _varList; }
202 public Vector<ArchiConnection> getConnectionList() {
203 return _connectionList;
207 * Compute all paths between processors.
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);
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 ? " -> " : ""));
230 System.out.println();
232 System.out.println("Found " + _pathList.size() + " paths.");
235 computeProcessorPath();
239 * Compute all write path from one processor to another processor
240 * in this architecture.
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();
248 //create new hashtable entry for this start processor
249 if (!_processorPathList.containsKey(startProcessor)) {
250 Hashtable<Processor, Vector<Path>>
251 processorPathList = new Hashtable<Processor,
253 _processorPathList.put(startProcessor, processorPathList);
256 Hashtable<Processor, Vector<Path>>
257 processorPathList = _processorPathList.
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);
266 Vector<Path> processorPath =
267 processorPathList.get(targetProcessor);
269 //add this path to the list of paths
270 processorPath.add(_pathList.elementAt(j));
274 //print all processor to processor path
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++) {
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 ? " -> " : ""));
289 System.out.println();
293 System.out.println("Found " + pathCounter + " paths.");
298 * Get all write paths from the given start processor to the given
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
306 public Vector<Path> getPaths(
307 Processor startProcessor, Processor targetProcessor) {
308 if (_processorPathList.get(startProcessor) == null) {
311 return _processorPathList.get(startProcessor).get(targetProcessor);
315 * Register the RX/TX/CH buffer to each resource.
316 * Can be used for dotty generation.
318 public void registerRWPath2Resource()
320 for (ReadPath r : _readPathList) {
322 String memName = r.getRXBuf().getName();
323 for (Memory m : _memoryList) {
324 if (m.getName().equals(memName)) {
325 m.getRXBufList().add(r.getName());
330 memName = r.getCHBuf().getName();
331 for (Memory m : _memoryList) {
332 if (m.getName().equals(memName)) {
333 m.getCHBufList().add(r.getName() + "_RPath");
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");
346 for (WritePath w : _writePathList) {
348 String memName = w.getTXBuf().getName();
349 for (Memory m : _memoryList) {
350 if (m.getName().equals(memName)) {
351 m.getTXBufList().add(w.getName());
356 memName = w.getCHBuf().getName();
357 for (Memory m : _memoryList) {
358 if (m.getName().equals(memName)) {
359 m.getCHBufList().add(w.getName() + "_WPath");
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");
373 /** List of the processors in the Architecture */
374 protected Vector<Processor> _processorList = null;
376 /** List of the memories in the Architecture */
377 protected Vector<Memory> _memoryList = null;
379 /** List of hwChannels in the Architecture */
380 protected Vector<HWChannel> _hwChannelList = null;
382 /** List of variables in the Architecture */
383 protected Vector<Variable> _varList = null;
385 /** List of connections in the Architecture: for simplified arch*/
386 protected Vector<ArchiConnection> _connectionList = null;
388 /** List of read paths in the Architecture: for detail arch */
389 protected Vector<ReadPath> _readPathList = null;
391 /** List of write paths in the Architecture: for detail arch */
392 protected Vector<WritePath> _writePathList = null;
394 /** List of paths in the Architecture */
395 protected Vector<Path> _pathList = null;
397 /** hashtable to access all processor to processor path */
398 protected Hashtable<Processor, Hashtable<Processor,
399 Vector<Path>>> _processorPathList = null;