1 /* $Id: RtemsVisitor.java 1 2010-02-24 13:03:05Z haidw $ */
2 package dol.visitor.rtems;
5 import java.util.HashMap;
6 import java.util.Vector;
8 import dol.datamodel.pn.Port;
9 import dol.datamodel.pn.Process;
10 import dol.datamodel.pn.ProcessNetwork;
11 import dol.util.Copier;
12 import dol.visitor.PNVisitor;
15 * This class is a class for a visitor that is used to generate
18 public class RtemsVisitor extends PNVisitor {
23 * @param packageName name of the Rtems directory
25 public RtemsVisitor(String packageName) {
26 _packageName = packageName;
30 * Visit process network.
32 * @param pn process network that needs to be rendered.
34 public void visitComponent(ProcessNetwork pn) {
36 File dir = new File(_packageName);
40 File source = new File(_ui.getMySystemCLib().
41 replaceAll("systemC", "rtems"));
42 new Copier().copy(source, dir);
44 //copy process source code
45 source = new File(_srcDirName);
46 new Copier().copy(source, dir);
50 pn.accept(new RtemsMakefileVisitor(_packageName));
51 pn.accept(new RtemsProcessVisitor(_packageName,_portMap,_sinkMap));
52 pn.accept(new RtemsModuleVisitor(_packageName, _portMap));
53 pn.accept(new RtemsShaperVisitor(_packageName, _sinkMap));
54 pn.accept(new RtemsPropertiesVisitor(_packageName));
57 System.out.println("RtemsVisitor: exception occured: "
64 * Create a hashmap which maps each port of the given process network
65 * to an integer. For each process, ports are numbered with integers
68 * @param pn process network for which the map should be generated
70 protected void createPortMap(ProcessNetwork pn) {
71 _portMap = new HashMap<Port, Integer>();
73 for (Process process : pn.getProcessList()) {
75 Vector<Port> portList = process.getPortList();
76 Vector<String> portNameList = new Vector<String>();
78 HashMap<String, Integer> portMap =
79 new HashMap<String, Integer>();
82 for (int i = 0; i < portList.size(); i++) {
83 //treat single ports differently than iterated ports
84 String portName = portList.elementAt(i).getName();
85 String baseName = portList.elementAt(i).getBasename();
87 if (portName.equals(baseName)) {
88 portNameList.add(portName);
89 portMap.put(portName, portCount++);
91 String range_indices = portList.elementAt(i).getRange();
92 Vector<Integer> range_indices_values = getIndex(range_indices, ";");
94 String port_indices = portName;
95 port_indices.replaceAll(baseName, "");
96 Vector<Integer> port_indices_values = getIndex(port_indices, "_");
98 if (!portNameList.contains(baseName)) {
99 portNameList.add(baseName);
100 portMap.put(baseName, portCount);
103 for (int j = 0; j < range_indices_values.size(); j++) {
104 size *= range_indices_values.elementAt(j);
109 int portId = portMap.get(baseName);
110 for (int j = 0; j < port_indices_values.size(); j++) {
112 for (int k = j + 1; k < range_indices_values.size(); k++) {
113 weight *= range_indices_values.elementAt(k);
115 portId += port_indices_values.elementAt(j) * weight;
117 portMap.put(portName, portId);
121 for (int i = 0; i < portList.size(); i++) {
122 _portMap.put(portList.elementAt(i),
123 portMap.get(portList.elementAt(i).getName()));
130 * Create a hashmap which maps each sink of the given process network
131 * to an integer. For each process, sinks are numbered with integers
134 * @param pn process network for which the map should be generated
136 protected void createSinkMap(ProcessNetwork pn) {
137 _sinkMap = new HashMap<Process, Integer>();
140 for (Process process : pn.getProcessList()) {
141 if (!process.hasOutPorts()) {
142 _sinkMap.put(process, i);
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 protected HashMap<Port, Integer> _portMap;
174 protected HashMap<Process, Integer> _sinkMap;
175 protected String _packageName = null;
177 protected String _srcDir = "";
178 protected static String _srcDirName = "src";