--- /dev/null
+package dol.visitor.cell;\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 file\r
+ * for the Application on the CBE (i.e. a bash file for the cell\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 CellBuildFileVisitor extends PNVisitor {\r
+\r
+ /**\r
+ * Constructor.\r
+ * \r
+ * @param dir\r
+ * path of the Makefile\r
+ */\r
+ public CellBuildFileVisitor(String dir) {\r
+ _dir = dir;\r
+ }\r
+\r
+ /**\r
+ * Create a Makefile for the given process network.\r
+ * \r
+ * @param pn\r
+ * 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\r
+ .println("# Bash file to run the DOL application on the Cell processor");\r
+ ps\r
+ .println("# Start the Cell-Simulator and enter the following commands: ");\r
+ ps\r
+ .println("# callthru source <Absolute path to the folder of this file>/pncbe.sh > pncbe.sh");\r
+ ps\r
+ .println("# for example: callthru source /opt/cell/sdk/src/tutorial/pn_test/pncbe.sh > pncbe.sh");\r
+ ps.println("# chmod +x pncbe.sh");\r
+ ps.println();\r
+ ps\r
+ .println("# To run the DOL application, use the following 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) && process.getNumOfInports() > 0 && 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(" mkdir " + subdirectory);\r
+ ps.println("fi;");\r
+ ps.println("callthru source $FOLDER/" + applicationName\r
+ + " > " + 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
+}\r