dol: initial dol commit
[jump.git] / dol / src / dol / visitor / cell / CellMakefileVisitor.java
diff --git a/dol/src/dol/visitor/cell/CellMakefileVisitor.java b/dol/src/dol/visitor/cell/CellMakefileVisitor.java
new file mode 100644 (file)
index 0000000..8c7e22e
--- /dev/null
@@ -0,0 +1,130 @@
+package dol.visitor.cell;
+
+import java.io.FileOutputStream;
+import java.io.OutputStream;
+import java.io.PrintStream;
+import java.util.Vector;
+
+import dol.datamodel.pn.Configuration;
+import dol.datamodel.pn.Process;
+import dol.datamodel.pn.ProcessNetwork;
+import dol.visitor.PNVisitor;
+
+/**
+ * This class is a class for a visitor that is used to generate a CBE package
+ * Makefile.
+ */
+public class CellMakefileVisitor extends PNVisitor {
+
+    /**
+     * Constructor.
+     *
+     * @param dir
+     *            path of the Makefile
+     */
+    public CellMakefileVisitor(String dir, CellMapping mapping) {
+        _dir = dir;
+        _mapping = mapping;
+    }
+
+    /**
+     * Create a Makefile for the given process network.
+     *
+     * @param pn
+     *            process network
+     */
+    public void visitComponent(ProcessNetwork pn) {
+        try {
+            String filename = _dir + _delimiter + "Makefile";
+            OutputStream file = new FileOutputStream(filename);
+            PrintStream ps = new PrintStream(file);
+
+            ps.println("####################");
+            ps.println("# Main Makefile for the DOL application on the CBE");
+            ps.println("####################");
+            ps.println();
+            ps.println("# Subdirectories");
+
+
+            // Subdirectories of baseprocesses on the SPU
+            String subdirectories = "";
+            Vector<String> pList = new Vector<String>();
+            for (Process process :  _mapping.getAllSpuBaseProcess()) {
+                String basename = process.getBasename();
+                subdirectories += "spu_" + basename + " ";
+            }
+
+            // Directory for the SPU OS'es (only if there are really processes on the SPE!
+            if (_mapping.getNrSPUProcess() > 0)
+                subdirectories += "spu";
+
+            String srcdirectories = "";
+
+            // Subdirectory of baseprocesses on the PPU
+            for (Process process :  _mapping.getAllPPUBaseProcess()) {
+                String basename = process.getBasename();
+                srcdirectories += " $(wildcard ppu_" + basename + "/*.cpp)";
+            }
+
+            // Directory for the PPU OS'es
+            srcdirectories += " $(wildcard ppu/*.cpp)";
+
+            String linkList = "";
+            String srcList = "";
+            for (Process process : _mapping.getAllPPUBaseProcess()) {
+                String basename = process.getBasename();
+                linkList += "ppu_" + basename + "/ppu_" + basename + ".o ";
+                srcList += "$(wildcard ppu_" + basename + "/*.cpp) ";
+            }
+            pList.clear();
+
+            ps.println("DIRS     := " + subdirectories);
+            ps.println("");
+
+            ps.println("# General definitions:");
+            ps.println("CC = ppu-g++");
+            ps.println("CCFLAGS = -ftree-vectorize -O3 -maltivec -funroll-loops -mabi=altivec -mcpu=cell");
+            ps.println("COMPILE = $(CC) $(CCFLAGS) -c");
+            ps.print("LINK = $(CC) -lspe2 -lpthread ");
+            for (Configuration conf : pn.getCfgList()) {
+                if (conf.getName().equals("DYNAMIC_LINK"))
+                    ps.print(conf.getValue() + " ");
+            }
+            ps.println("");
+
+            ps.println("CBE_INCLUDE = /opt/cell/sdk/usr/include");
+            ps.println("LIB_INC = -I lib -I lib/ppu -I lib/pt -I . -I $(CBE_INCLUDE)");
+            ps.println("RM = rm");
+            ps.println("ECHO = echo");
+            ps.println("EXE = sc_application");
+            ps.println("");
+            ps.println("src := $(wildcard lib/ppu/*.cpp) $(wildcard *.cpp)" + srcdirectories);
+            ps.println("srcAll := $(wildcard lib/ppu/*.cpp) $(wildcard *.cpp) " + srcList);
+            ps.println("srcspu := $(wildcard lib/spu/*.cpp) ");
+            ps.println("obj = $(src:.cpp=.o)");
+            ps.println("objspu = $(srcspu:.cpp=.o)");
+            ps.println("");
+            ps.println("$(EXE): $(obj) $(srcAll)");
+            ps.println("\tfor d in $(DIRS); do (cd $$d; $(MAKE) ); done");
+            ps.println("\t$(LINK) -o $(EXE) $(obj)");
+            ps.println("");
+            ps.println("%.o :");
+            ps.println("\t$(COMPILE) -o $(*D)/$(*F).o $(*D)/$(*F).cpp $(LIB_INC)");
+            ps.println("");
+            ps.println("clean:");
+            ps.println("\tfor d in $(DIRS); do (cd $$d; $(MAKE) clean ); done");
+            ps.println("\trm $(objspu)");
+            ps.println("\trm $(obj) ");
+            ps.println("\trm $(EXE)");
+            ps.println("");
+
+        } catch (Exception e) {
+            System.out.println("CbeMakefileVisitor: exception occured: "
+                    + e.getMessage());
+            e.printStackTrace();
+        }
+    }
+
+    protected String _dir = null;
+    protected CellMapping _mapping;
+}