1 package dol.visitor.cell;
3 import java.io.FileOutputStream;
4 import java.io.OutputStream;
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;
14 * This class is a class for a constant file
16 * @author lschor, 2008-11-08
21 public class CellConstantVisitor extends PNVisitor {
26 * @param dir path of this file
28 public CellConstantVisitor(String dir, CellMapping mapping) {
34 * Visit process network.
36 * @param x process network that needs to be rendered
38 public void visitComponent(ProcessNetwork x) {
40 _ui = UserInterface.getInstance();
41 String filename = _dir + _delimiter + "lib" + _delimiter + "constant.h";
42 OutputStream file = new FileOutputStream(filename);
43 _mainPS = new CodePrintStream(file);
47 for (Process p : x.getProcessList()) {
48 if (p.getNumOfInports() > 0 && p.getNumOfOutports() > 0)
52 //create header section
53 _mainPS.println("// ========================");
54 _mainPS.println("// constant.h file");
55 _mainPS.println("// ========================");
58 _mainPS.println("#include <stdio.h>");
60 // Define the number of FIFO queues and the number of processes
61 _mainPS.println("#ifndef _CONSTANT_H_");
62 _mainPS.println("#define _CONSTANT_H_");
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)");
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();
93 if(indx == x.getChannelList().size() - 1) {
96 _mainPS.print(size + ", ");
100 _mainPS.println("}; // Size of the FIFOs");
102 _mainPS.println("#endif // _CONSTANT_H_ ");
104 catch (Exception e) {
105 System.out.println("CellModuleVisitor: exception occured: "
113 * @param x process that needs to be processed
115 public void visitComponent(Process x) {
120 * @param x channel that needs to be processed
122 public void visitComponent(Channel x) {
125 protected CellMapping _mapping;
126 protected CodePrintStream _mainPS = null;
127 protected String _dir = null;