+package dol.visitor.cell;
+
+import java.io.FileOutputStream;
+import java.io.OutputStream;
+
+import dol.datamodel.pn.Channel;
+import dol.datamodel.pn.Process;
+import dol.datamodel.pn.ProcessNetwork;
+import dol.visitor.PNVisitor;
+import dol.main.UserInterface;
+import dol.util.CodePrintStream;
+
+/**
+ * This class is a class for a constant file
+ *
+ * @author lschor, 2008-11-08
+ *
+ * Revision:
+ * 2008-11-08: Created
+ */
+public class CellConstantVisitor extends PNVisitor {
+
+ /**
+ * Constructor.
+ *
+ * @param dir path of this file
+ */
+ public CellConstantVisitor(String dir, CellMapping mapping) {
+ _dir = dir;
+ _mapping = mapping;
+ }
+
+ /**
+ * Visit process network.
+ *
+ * @param x process network that needs to be rendered
+ */
+ public void visitComponent(ProcessNetwork x) {
+ try {
+ _ui = UserInterface.getInstance();
+ String filename = _dir + _delimiter + "lib" + _delimiter + "constant.h";
+ OutputStream file = new FileOutputStream(filename);
+ _mainPS = new CodePrintStream(file);
+
+ int numSpes = 0;
+
+ for (Process p : x.getProcessList()) {
+ if (p.getNumOfInports() > 0 && p.getNumOfOutports() > 0)
+ numSpes++;
+ }
+
+ //create header section
+ _mainPS.println("// ========================");
+ _mainPS.println("// constant.h file");
+ _mainPS.println("// ========================");
+
+ // Includes
+ _mainPS.println("#include <stdio.h>");
+
+ // Define the number of FIFO queues and the number of processes
+ _mainPS.println("#ifndef _CONSTANT_H_");
+ _mainPS.println("#define _CONSTANT_H_");
+ _mainPS.println("");
+ _mainPS.println("#define NUM_PROCS " + x.getProcessList().size()
+ + " // total number of processes");
+ _mainPS.println("#define NUM_PROCS_SPU " + _mapping.getNrSPUProcess()
+ + " // number of processes to map on the SPU");
+ _mainPS.println("#define NUM_PROCS_PPU " + _mapping.getNrPPUProcess()
+ + " // number of processes to map to the PPU");
+ _mainPS.println("#define NUM_SPES " + _mapping.getNrSPE()
+ + " // number of SPE's to be used (PS3 = 6)");
+ _mainPS.println("#define NUM_FIFO " + x.getChannelList().size()
+ + " // number of FIFOs we use");
+ _mainPS.println("#define FIFO_SIZE_FACTOR 10 "
+ + " // factor to increase the IN-Channels of the PPE");
+ _mainPS.println("#define ALIGNMENT_FACTOR 7 "
+ + " // alignment factor for the DMA transfers (at least 4, "
+ + "7 for optimal performance)");
+ _mainPS.println("#define ALIGNMENT_FACTOR_POWER2 128");
+ _mainPS.println("#define BLOCKED_MAX_NR 5 "
+ + " // number of times a process should wait until "
+ + "resending a request");
+ _mainPS.println("#define STORE_REQUESTS "
+ + " // defines if one would like to store requests which"
+ + "cannot be worked out currently (see also FastCommunication.cpp)");
+ _mainPS.println("");
+ _mainPS.print("static unsigned long int FIFO_SIZE[NUM_FIFO] = {");
+ for (int indx = 0; indx < x.getChannelList().size(); indx++) {
+ int size = x.getChannelList().elementAt(indx).getSize();
+ if (x.getChannelList().elementAt(indx).getTokenSize() != 0) {
+ size *= x.getChannelList().elementAt(indx).getTokenSize();
+ }
+ if(indx == x.getChannelList().size() - 1) {
+ _mainPS.print(size);
+ } else {
+ _mainPS.print(size + ", ");
+ }
+ }
+
+ _mainPS.println("}; // Size of the FIFOs");
+ _mainPS.println("");
+ _mainPS.println("#endif // _CONSTANT_H_ ");
+ }
+ catch (Exception e) {
+ System.out.println("CellModuleVisitor: exception occured: "
+ + e.getMessage());
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ *
+ * @param x process that needs to be processed
+ */
+ public void visitComponent(Process x) {
+ }
+
+ /**
+ *
+ * @param x channel that needs to be processed
+ */
+ public void visitComponent(Channel x) {
+ }
+
+ protected CellMapping _mapping;
+ protected CodePrintStream _mainPS = null;
+ protected String _dir = null;
+}