dol: initial dol commit
[jump.git] / dol / src / dol / visitor / rtems / RtemsPropertiesVisitor.java
diff --git a/dol/src/dol/visitor/rtems/RtemsPropertiesVisitor.java b/dol/src/dol/visitor/rtems/RtemsPropertiesVisitor.java
new file mode 100644 (file)
index 0000000..71d9afd
--- /dev/null
@@ -0,0 +1,93 @@
+/* $Id: RtemsPropertiesVisitor.java 1 2010-02-24 13:03:05Z haidw $ */
+package dol.visitor.rtems;
+
+import java.io.FileOutputStream;
+import java.io.OutputStream;
+import java.io.PrintStream;
+
+import dol.datamodel.architecture.Architecture;
+import dol.datamodel.architecture.Processor;
+import dol.datamodel.mapping.Mapping;
+import dol.datamodel.pn.Process;
+import dol.datamodel.pn.ProcessNetwork;
+import dol.parser.xml.archischema.ArchiXmlParser;
+import dol.parser.xml.mapschema.MapXmlParser;
+import dol.visitor.PNVisitor;
+
+public class RtemsPropertiesVisitor extends PNVisitor {
+
+    protected String _dir = null;
+
+    public RtemsPropertiesVisitor(String dir) {
+        _dir = dir;
+    }
+
+    public void visitComponent(ProcessNetwork x) {
+        try {
+            String filename = _dir + _delimiter + "properties";
+            OutputStream file = new FileOutputStream(filename);
+            PrintStream ps = new PrintStream(file);
+
+            ps.println(getProperties(x));
+        } catch (Exception e) {
+            System.out.println("RtemsPropertiesVisitor: "
+                    + "exception occured: " + e.getMessage());
+            e.printStackTrace();
+        }
+    }
+
+    public String getProperties(ProcessNetwork x) {
+        String file = "";
+        String newline = System.getProperty("line.separator");
+        file += "<!-- Properties for ANT script for "
+                + "Multi-Processor System Testbed -->" + newline;
+
+        int maxProcessorIndex;
+        String processorList = null;
+        String processList = null;
+
+        if (_ui.getMappingFileName() == null) {
+            maxProcessorIndex = x.getProcessList().size() - 1;
+        } else {
+            ArchiXmlParser architectureParser =
+                new ArchiXmlParser();
+            Architecture architecture = architectureParser.doParse(
+                _ui.getPlatformFileName());
+
+            MapXmlParser mappingParser =
+                new MapXmlParser(x, architecture);
+            Mapping mapping = mappingParser.doParse(
+                _ui.getMappingFileName());
+
+            maxProcessorIndex = 0;
+            for (Processor p : mapping.getProcessorList()) {
+                if (p.getProcessList().size() > 0) {
+                    maxProcessorIndex =
+                            Math.max(p.getIteratorIndices().elementAt(0),
+                                     maxProcessorIndex);
+                }
+            }
+            //maxProcessorIndex = mapping.getProcessorList().size() - 1;
+        }
+
+        processorList = "1";
+        for (int i = 1; i <= maxProcessorIndex; i++) {
+            processorList += "," + (i + 1);
+        }
+
+        for (Process p : x.getProcessList()) {
+            if (processList == null) {
+                processList = p.getName();
+            } else {
+                processList += "," + p.getName();
+            }
+        }
+
+
+        file += "processors=" + (maxProcessorIndex + 1) + newline;
+        file += "processorList=" + processorList + newline;
+        file += "processList=" + processList + newline;
+
+        return file;
+    }
+}