dol: initial dol commit
[jump.git] / dol / src / dol / visitor / cbe / CbeBuildFileVisitor.java
1 /* $Id: CbeBuildFileVisitor.java 1 2010-02-24 13:03:05Z haidw $ */\r
2 package dol.visitor.cbe;\r
3 \r
4 import java.io.FileOutputStream;\r
5 import java.io.OutputStream;\r
6 import java.io.PrintStream;\r
7 import java.util.Vector;\r
8 \r
9 import dol.datamodel.pn.Process;\r
10 import dol.datamodel.pn.ProcessNetwork;\r
11 import dol.visitor.PNVisitor;\r
12 \r
13 /**\r
14  * This class is a class for a visitor that is used to generate the build\r
15  * file for the application on the CBE (i.e. a bash file for the CBE)\r
16  *\r
17  * @author lschor, 2008-10-30\r
18  *\r
19  * Revision:\r
20  * 2008-10-30: Updated the file for the CBE\r
21  * 2008-11-08: Add double buffering\r
22  */\r
23 public class CbeBuildFileVisitor extends PNVisitor {\r
24 \r
25     /**\r
26      * Constructor.\r
27      *\r
28      * @param dir path of the Makefile\r
29      */\r
30     public CbeBuildFileVisitor(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 process network\r
38      */\r
39     public void visitComponent(ProcessNetwork pn) {\r
40         try {\r
41             String filename = _dir + _delimiter + "pncbe.sh";\r
42             OutputStream file = new FileOutputStream(filename);\r
43             PrintStream ps = new PrintStream(file);\r
44 \r
45             // General information / notes and commands\r
46             ps.println("#!/bin/bash");\r
47             ps.println("clear");\r
48             ps.println();\r
49             ps.println("# Bash file to run a DOL application on the CBE");\r
50             ps.println("# Start the CBE-Simulator and enter the "\r
51                     + "following commands: ");\r
52             ps.println("# callthru source <Absolute path to the folder "\r
53                     + "of this file>/pncbe.sh > pncbe.sh");\r
54             ps.println("# for example: callthru source /opt/cell/sdk/src/"\r
55                     + "tutorial/pn_test/pncbe.sh > pncbe.sh");\r
56             ps.println("# chmod +x pncbe.sh");\r
57             ps.println();\r
58             ps.println("# To run the DOL application, use the following "\r
59                     + "command: ");\r
60             ps.println("# ./pncbe.sh");\r
61             ps.println();\r
62             ps.println("# Folder in which the application is stored");\r
63             ps.println("FOLDER=/opt/cell/sdk/src/tutorial/pn_test");\r
64             ps.println();\r
65 \r
66             // Go through each process and copy its data to the Cell\r
67             String subdirectory = "";\r
68             String applicationName = "";\r
69             Vector<String> pList = new Vector<String>();\r
70 \r
71             for (Process process : pn.getProcessList()) {\r
72                 String basename = process.getBasename();\r
73                 if (!pList.contains(basename)\r
74                         && process.getNumOfInports() > 0\r
75                         && 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("\tmkdir " + subdirectory);\r
83                     ps.println("fi;");\r
84                     ps.println("callthru source $FOLDER/"\r
85                             + applicationName + " > " + 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