1 package dol.visitor.cell;
4 import java.util.HashMap;
5 import java.util.Vector;
7 import dol.datamodel.pn.Port;
8 import dol.datamodel.pn.Process;
9 import dol.datamodel.pn.ProcessNetwork;
10 import dol.main.UserInterface;
11 import dol.visitor.PNVisitor;
12 import dol.util.Copier;
15 * This class is a class for a visitor that is used to generate
18 public class CellVisitor extends PNVisitor {
23 * @param packageName name of the Cell directory
25 public CellVisitor(String packageName) {
26 _packageName = packageName;
27 _ui = UserInterface.getInstance();
31 * Visit process network.
33 * @param pn process network that needs to be rendered.
35 public void visitComponent(ProcessNetwork pn) {
37 File dir = new File(_packageName);
41 File lib = new File(_packageName + _delimiter + "lib");
45 File source = new File(_ui.getMySystemCLib().
46 replaceAll("systemC", "cell").replace("%20", " "));
47 new Copier().copy(source, lib);
49 // Create the template
50 File template = new File(_packageName + _delimiter + "template");
54 source = new File(_ui.getMySystemCLib().replaceAll("systemC", "cell").replace("lib", "template").replace("%20", " "));
55 new Copier().copy(source, template);
57 // Some library files must be copied to the main directory
58 (new File(lib.getPath() + _delimiter + "ppu_main.h")).renameTo(new File (dir.getPath() + _delimiter + "ppu_main.h"));
60 //copy process source code
61 source = new File(_srcDirName.replace("%20", " "));
62 new Copier().copy(source, dir);
66 // Create the mapping for this process network on the cell
67 CellMapping mapping = new CellMapping(pn, "predefined", true, MAX_SPUS);
69 pn.accept(new CellMakefileVisitor(_packageName, mapping));
70 pn.accept(new CellProcessVisitor(_packageName, _portMap, mapping));
71 pn.accept(new CellModuleVisitor(_packageName, _portMap, mapping));
72 pn.accept(new CellConstantVisitor(_packageName, mapping));
73 pn.accept(new CellSPEVisitor(_packageName, mapping));
74 pn.accept(new CellPPEVisitor(_packageName, mapping));
77 System.out.println("CellVisitor: exception occured: "
84 * Create a hashmap which maps each port of the given process network
85 * to an integer. For each process, ports are numbered with integers
88 * @param pn process network for which the map should be generated
90 protected void createPortMap(ProcessNetwork pn) {
91 _portMap = new HashMap<Port, Integer>();
93 for (Process process : pn.getProcessList()) {
95 Vector<Port> portList = process.getPortList();
96 Vector<String> portNameList = new Vector<String>();
98 HashMap<String, Integer> portMap =
99 new HashMap<String, Integer>();
102 for (int i = 0; i < portList.size(); i++) {
103 //treat single ports differently than iterated ports
104 String portName = portList.elementAt(i).getName();
105 String baseName = portList.elementAt(i).getBasename();
107 if (portName.equals(baseName)) {
108 portNameList.add(portName);
109 portMap.put(portName, portCount++);
111 String range_indices = portList.elementAt(i).getRange();
112 Vector<Integer> range_indices_values = getIndex(range_indices, ";");
114 String port_indices = portName;
115 port_indices.replaceAll(baseName, "");
116 Vector<Integer> port_indices_values = getIndex(port_indices, "_");
118 if (!portNameList.contains(baseName)) {
119 portNameList.add(baseName);
120 portMap.put(baseName, portCount);
123 for (int j = 0; j < range_indices_values.size(); j++) {
124 size *= range_indices_values.elementAt(j);
129 int portId = portMap.get(baseName);
130 for (int j = 0; j < port_indices_values.size(); j++) {
132 for (int k = j + 1; k < range_indices_values.size(); k++) {
133 weight *= range_indices_values.elementAt(k);
135 portId += port_indices_values.elementAt(j) * weight;
137 portMap.put(portName, portId);
141 for (int i = 0; i < portList.size(); i++) {
142 _portMap.put(portList.elementAt(i),
143 portMap.get(portList.elementAt(i).getName()));
149 * Gets vector of indices of a string, where the index must be
150 * separated by the specified separator.
152 * getIndex("name_1_2", "_", 0) will return 1.
153 * getIndex("name_1_2", "_", 1) will return 2.
155 * @param range string to parse
156 * @param separator delimiter of indices
157 * @return vector of indices
159 protected Vector<Integer> getIndex(String range, String separator) {
160 Vector<Integer> indices = new Vector<Integer>();
161 String[] subranges = range.split(separator);
162 for (int i = 0; i < subranges.length; i++) {
164 int value = Integer.valueOf(subranges[i]);
166 } catch (Exception e) {
173 public final static int MAX_SPUS = 6;
174 protected HashMap<Port, Integer> _portMap;
175 protected String _packageName = null;
177 protected String _srcDir = "";
178 protected static String _srcDirName = "src";