dol: initial dol commit
[jump.git] / dol / src / dol / visitor / cell / CellBuildFileVisitor.java
1 package dol.visitor.cell;\r
2 \r
3 import java.io.FileOutputStream;\r
4 import java.io.OutputStream;\r
5 import java.io.PrintStream;\r
6 import java.util.Vector;\r
7 \r
8 import dol.datamodel.pn.Process;\r
9 import dol.datamodel.pn.ProcessNetwork;\r
10 import dol.visitor.PNVisitor;\r
11 \r
12 /**\r
13  * This class is a class for a visitor that is used to generate the build file\r
14  * for the Application on the CBE (i.e. a bash file for the cell\r
15  * \r
16  * @author lschor, 2008-10-30\r
17  * \r
18  * Revision: \r
19  * 2008-10-30: Updated the file for the CBE\r
20  * 2008-11-08: Add double buffering\r
21  */\r
22 public class CellBuildFileVisitor extends PNVisitor {\r
23 \r
24         /**\r
25          * Constructor.\r
26          * \r
27          * @param dir\r
28          *            path of the Makefile\r
29          */\r
30         public CellBuildFileVisitor(String dir) {\r
31                 _dir = dir;\r
32         }\r
33 \r
34         /**\r
35          * Create a Makefile for the given process network.\r
36          * \r
37          * @param pn\r
38          *            process network\r
39          */\r
40         public void visitComponent(ProcessNetwork pn) {\r
41                 try {\r
42                         String filename = _dir + _delimiter + "pncbe.sh";\r
43                         OutputStream file = new FileOutputStream(filename);\r
44                         PrintStream ps = new PrintStream(file);\r
45 \r
46                         // General information / notes and commands\r
47                         ps.println("#!/bin/bash");\r
48                         ps.println("clear");\r
49                         ps.println();\r
50                         ps\r
51                                         .println("# Bash file to run the DOL application on the Cell processor");\r
52                         ps\r
53                                         .println("# Start the Cell-Simulator and enter the following commands: ");\r
54                         ps\r
55                                         .println("# callthru source <Absolute path to the folder of this file>/pncbe.sh > pncbe.sh");\r
56                         ps\r
57                                         .println("# for example: callthru source /opt/cell/sdk/src/tutorial/pn_test/pncbe.sh > pncbe.sh");\r
58                         ps.println("# chmod +x pncbe.sh");\r
59                         ps.println();\r
60                         ps\r
61                                         .println("# To run the DOL application, use the following command: ");\r
62                         ps.println("# ./pncbe.sh");\r
63                         ps.println();\r
64                         ps.println("# Folder in which the application is stored");\r
65                         ps.println("FOLDER=/opt/cell/sdk/src/tutorial/pn_test");\r
66                         ps.println();\r
67 \r
68                         // Go through each process and copy its data to the Cell\r
69                         String subdirectory = "";\r
70                         String applicationName = "";\r
71                         Vector<String> pList = new Vector<String>();\r
72 \r
73                         for (Process process : pn.getProcessList()) {\r
74                                 String basename = process.getBasename();\r
75                                 if (!pList.contains(basename) && process.getNumOfInports() > 0 && process.getNumOfOutports() > 0) {\r
76                                         subdirectory = "spu_" + basename;\r
77                                         applicationName = subdirectory + "/spu_"\r
78                                                         + basename + "_wrapper";\r
79 \r
80                                         ps.println("# " + basename);\r
81                                         ps.println("if [ ! -d " + subdirectory + " ]; then");\r
82                                         ps.println("    mkdir " + subdirectory);\r
83                                         ps.println("fi;");\r
84                                         ps.println("callthru source $FOLDER/" + applicationName\r
85                                                         + " > " + applicationName);\r
86                                         ps.println("chmod +x " + applicationName);\r
87                                         ps.println();\r
88                                         pList.add(basename);\r
89                                 }\r
90                         }\r
91 \r
92                         // Load also the main application to the CBE\r
93                         ps.println("# Main program");\r
94                         ps.println("callthru source $FOLDER/ppu_main > ppu_main");\r
95                         ps.println("chmod +x ppu_main");\r
96                         ps.println();\r
97 \r
98                         // Run the main program\r
99                         ps.println("# run the main program");\r
100                         ps.println("./ppu_main");\r
101                 } catch (Exception e) {\r
102                         System.out.println("CbeMakefileVisitor: exception occured: "\r
103                                         + e.getMessage());\r
104                         e.printStackTrace();\r
105                 }\r
106         }\r
107 \r
108         protected String _dir = null;\r
109 \r
110 }\r