1 /* $Id: CbeBuildFileVisitor.java 1 2010-02-24 13:03:05Z haidw $ */
\r
2 package dol.visitor.cbe;
\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
9 import dol.datamodel.pn.Process;
\r
10 import dol.datamodel.pn.ProcessNetwork;
\r
11 import dol.visitor.PNVisitor;
\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
17 * @author lschor, 2008-10-30
\r
20 * 2008-10-30: Updated the file for the CBE
\r
21 * 2008-11-08: Add double buffering
\r
23 public class CbeBuildFileVisitor extends PNVisitor {
\r
28 * @param dir path of the Makefile
\r
30 public CbeBuildFileVisitor(String dir) {
\r
35 * Create a Makefile for the given process network.
\r
37 * @param pn process network
\r
39 public void visitComponent(ProcessNetwork pn) {
\r
41 String filename = _dir + _delimiter + "pncbe.sh";
\r
42 OutputStream file = new FileOutputStream(filename);
\r
43 PrintStream ps = new PrintStream(file);
\r
45 // General information / notes and commands
\r
46 ps.println("#!/bin/bash");
\r
47 ps.println("clear");
\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
58 ps.println("# To run the DOL application, use the following "
\r
60 ps.println("# ./pncbe.sh");
\r
62 ps.println("# Folder in which the application is stored");
\r
63 ps.println("FOLDER=/opt/cell/sdk/src/tutorial/pn_test");
\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
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
80 ps.println("# " + basename);
\r
81 ps.println("if [ ! -d " + subdirectory + " ]; then");
\r
82 ps.println("\tmkdir " + subdirectory);
\r
84 ps.println("callthru source $FOLDER/"
\r
85 + applicationName + " > " + applicationName);
\r
86 ps.println("chmod +x " + applicationName);
\r
88 pList.add(basename);
\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
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
104 e.printStackTrace();
\r
108 protected String _dir = null;
\r