dol: initial dol commit
[jump.git] / dol / src / dol / visitor / cbe / CbeBuildFileVisitor.java
diff --git a/dol/src/dol/visitor/cbe/CbeBuildFileVisitor.java b/dol/src/dol/visitor/cbe/CbeBuildFileVisitor.java
new file mode 100644 (file)
index 0000000..4500d91
--- /dev/null
@@ -0,0 +1,109 @@
+/* $Id: CbeBuildFileVisitor.java 1 2010-02-24 13:03:05Z haidw $ */\r
+package dol.visitor.cbe;\r
+\r
+import java.io.FileOutputStream;\r
+import java.io.OutputStream;\r
+import java.io.PrintStream;\r
+import java.util.Vector;\r
+\r
+import dol.datamodel.pn.Process;\r
+import dol.datamodel.pn.ProcessNetwork;\r
+import dol.visitor.PNVisitor;\r
+\r
+/**\r
+ * This class is a class for a visitor that is used to generate the build\r
+ * file for the application on the CBE (i.e. a bash file for the CBE)\r
+ *\r
+ * @author lschor, 2008-10-30\r
+ *\r
+ * Revision:\r
+ * 2008-10-30: Updated the file for the CBE\r
+ * 2008-11-08: Add double buffering\r
+ */\r
+public class CbeBuildFileVisitor extends PNVisitor {\r
+\r
+    /**\r
+     * Constructor.\r
+     *\r
+     * @param dir path of the Makefile\r
+     */\r
+    public CbeBuildFileVisitor(String dir) {\r
+        _dir = dir;\r
+    }\r
+\r
+    /**\r
+     * Create a Makefile for the given process network.\r
+     *\r
+     * @param pn process network\r
+     */\r
+    public void visitComponent(ProcessNetwork pn) {\r
+        try {\r
+            String filename = _dir + _delimiter + "pncbe.sh";\r
+            OutputStream file = new FileOutputStream(filename);\r
+            PrintStream ps = new PrintStream(file);\r
+\r
+            // General information / notes and commands\r
+            ps.println("#!/bin/bash");\r
+            ps.println("clear");\r
+            ps.println();\r
+            ps.println("# Bash file to run a DOL application on the CBE");\r
+            ps.println("# Start the CBE-Simulator and enter the "\r
+                    + "following commands: ");\r
+            ps.println("# callthru source <Absolute path to the folder "\r
+                    + "of this file>/pncbe.sh > pncbe.sh");\r
+            ps.println("# for example: callthru source /opt/cell/sdk/src/"\r
+                    + "tutorial/pn_test/pncbe.sh > pncbe.sh");\r
+            ps.println("# chmod +x pncbe.sh");\r
+            ps.println();\r
+            ps.println("# To run the DOL application, use the following "\r
+                    + "command: ");\r
+            ps.println("# ./pncbe.sh");\r
+            ps.println();\r
+            ps.println("# Folder in which the application is stored");\r
+            ps.println("FOLDER=/opt/cell/sdk/src/tutorial/pn_test");\r
+            ps.println();\r
+\r
+            // Go through each process and copy its data to the Cell\r
+            String subdirectory = "";\r
+            String applicationName = "";\r
+            Vector<String> pList = new Vector<String>();\r
+\r
+            for (Process process : pn.getProcessList()) {\r
+                String basename = process.getBasename();\r
+                if (!pList.contains(basename)\r
+                        && process.getNumOfInports() > 0\r
+                        && process.getNumOfOutports() > 0) {\r
+                    subdirectory = "spu_" + basename;\r
+                    applicationName = subdirectory + "/spu_"\r
+                            + basename + "_wrapper";\r
+\r
+                    ps.println("# " + basename);\r
+                    ps.println("if [ ! -d " + subdirectory + " ]; then");\r
+                    ps.println("\tmkdir " + subdirectory);\r
+                    ps.println("fi;");\r
+                    ps.println("callthru source $FOLDER/"\r
+                            + applicationName + " > " + applicationName);\r
+                    ps.println("chmod +x " + applicationName);\r
+                    ps.println();\r
+                    pList.add(basename);\r
+                }\r
+            }\r
+\r
+            // Load also the main application to the CBE\r
+            ps.println("# Main program");\r
+            ps.println("callthru source $FOLDER/ppu_main > ppu_main");\r
+            ps.println("chmod +x ppu_main");\r
+            ps.println();\r
+\r
+            // Run the main program\r
+            ps.println("# run the main program");\r
+            ps.println("./ppu_main");\r
+        } catch (Exception e) {\r
+            System.out.println("CbeMakefileVisitor: exception occured: "\r
+                    + e.getMessage());\r
+            e.printStackTrace();\r
+        }\r
+    }\r
+\r
+    protected String _dir = null;\r
+}\r