dol: initial dol commit
[jump.git] / dol / src / dol / visitor / cell / CellConstantVisitor.java
1 package dol.visitor.cell;
2
3 import java.io.FileOutputStream;
4 import java.io.OutputStream;
5
6 import dol.datamodel.pn.Channel;
7 import dol.datamodel.pn.Process;
8 import dol.datamodel.pn.ProcessNetwork;
9 import dol.visitor.PNVisitor;
10 import dol.main.UserInterface;
11 import dol.util.CodePrintStream;
12
13 /**
14  * This class is a class for a constant file
15  *
16  * @author lschor, 2008-11-08
17  *
18  * Revision:
19  * 2008-11-08: Created
20  */
21 public class CellConstantVisitor extends PNVisitor {
22
23     /**
24      * Constructor.
25      *
26      * @param dir path of this file
27      */
28     public CellConstantVisitor(String dir, CellMapping mapping) {
29         _dir = dir;
30         _mapping = mapping;
31     }
32
33     /**
34      * Visit process network.
35      *
36      * @param x process network that needs to be rendered
37      */
38     public void visitComponent(ProcessNetwork x) {
39         try {
40             _ui = UserInterface.getInstance();
41             String filename = _dir + _delimiter + "lib" + _delimiter + "constant.h";
42             OutputStream file = new FileOutputStream(filename);
43             _mainPS = new CodePrintStream(file);
44
45             int numSpes = 0;
46
47             for (Process p : x.getProcessList()) {
48                 if (p.getNumOfInports() > 0 && p.getNumOfOutports() > 0)
49                     numSpes++;
50             }
51
52             //create header section
53             _mainPS.println("// ========================");
54             _mainPS.println("// constant.h file");
55             _mainPS.println("// ========================");
56
57             // Includes
58             _mainPS.println("#include <stdio.h>");
59
60             // Define the number of FIFO queues and the number of processes
61             _mainPS.println("#ifndef _CONSTANT_H_");
62             _mainPS.println("#define _CONSTANT_H_");
63             _mainPS.println("");
64             _mainPS.println("#define NUM_PROCS " + x.getProcessList().size()
65                 + "           // total number of processes");
66             _mainPS.println("#define NUM_PROCS_SPU " + _mapping.getNrSPUProcess()
67                 + "       // number of processes to map on the SPU");
68             _mainPS.println("#define NUM_PROCS_PPU " + _mapping.getNrPPUProcess()
69                 + "       // number of processes to map to the PPU");
70             _mainPS.println("#define NUM_SPES " + _mapping.getNrSPE()
71                 + "            // number of SPE's to be used (PS3 = 6)");
72             _mainPS.println("#define NUM_FIFO " + x.getChannelList().size()
73                 + "           // number of FIFOs we use");
74             _mainPS.println("#define FIFO_SIZE_FACTOR 10  "
75                 + " // factor to increase the IN-Channels of the PPE");
76             _mainPS.println("#define ALIGNMENT_FACTOR 7   "
77                 + " // alignment factor for the DMA transfers (at least 4, "
78                 + "7 for optimal performance)");
79             _mainPS.println("#define ALIGNMENT_FACTOR_POWER2 128");
80             _mainPS.println("#define BLOCKED_MAX_NR 5     "
81                 + " // number of times a process should wait until "
82                 + "resending a request");
83             _mainPS.println("#define STORE_REQUESTS       "
84                 + " // defines if one would like to store requests which"
85                 + "cannot be worked out currently (see also FastCommunication.cpp)");
86             _mainPS.println("");
87             _mainPS.print("static unsigned long int FIFO_SIZE[NUM_FIFO] = {");
88             for (int indx = 0; indx < x.getChannelList().size(); indx++) {
89                 int size = x.getChannelList().elementAt(indx).getSize();
90                 if (x.getChannelList().elementAt(indx).getTokenSize() != 0) {
91                     size *= x.getChannelList().elementAt(indx).getTokenSize();
92                 }
93                 if(indx == x.getChannelList().size() - 1) {
94                     _mainPS.print(size);
95                 } else {
96                     _mainPS.print(size + ", ");
97                 }
98             }
99
100             _mainPS.println("};  // Size of the FIFOs");
101             _mainPS.println("");
102             _mainPS.println("#endif // _CONSTANT_H_ ");
103         }
104         catch (Exception e) {
105             System.out.println("CellModuleVisitor: exception occured: "
106                     + e.getMessage());
107             e.printStackTrace();
108         }
109     }
110
111     /**
112      *
113      * @param x process that needs to be processed
114      */
115     public void visitComponent(Process x) {
116     }
117
118     /**
119      *
120      * @param x channel that needs to be processed
121      */
122     public void visitComponent(Channel x) {
123     }
124
125     protected CellMapping _mapping;
126     protected CodePrintStream _mainPS = null;
127     protected String _dir = null;
128 }