dol: initial dol commit
[jump.git] / dol / src / dol / visitor / cbe / CbeConstantVisitor.java
1 /* $Id: CbeConstantVisitor.java 1 2010-02-24 13:03:05Z haidw $ */
2 package dol.visitor.cbe;
3
4 import java.io.FileOutputStream;
5 import java.io.OutputStream;
6 import java.util.HashMap;
7
8 import dol.datamodel.pn.Channel;
9 import dol.datamodel.pn.Port;
10 import dol.datamodel.pn.Process;
11 import dol.datamodel.pn.ProcessNetwork;
12 import dol.main.UserInterface;
13 import dol.util.CodePrintStream;
14 import dol.visitor.PNVisitor;
15
16 /**
17  * This class is a class for a constant file
18  *
19  * @author lschor, 2008-11-08
20  *
21  * Revision:
22  * 2008-11-08: Created
23  */
24 public class CbeConstantVisitor extends PNVisitor {
25
26     /**
27      * Constructor.
28      *
29      * @param dir path of this file
30      */
31     public CbeConstantVisitor(String dir, HashMap<Port, Integer> portMap) {
32         _dir = dir;
33         _portMap = portMap;
34     }
35
36     /**
37      * Visit process network.
38      *
39      * @param x process network that needs to be rendered
40      */
41     public void visitComponent(ProcessNetwork x) {
42         try {
43             _ui = UserInterface.getInstance();
44             String filename = _dir + _delimiter + "lib" + _delimiter
45                     + "constant.h";
46             OutputStream file = new FileOutputStream(filename);
47             _mainPS = new CodePrintStream(file);
48
49             int numSpes = 0;
50
51             for (Process p : x.getProcessList())
52             {
53                 if (p.getNumOfInports() > 0 && p.getNumOfOutports() > 0)
54                     numSpes++;
55             }
56
57             //create header section
58             _mainPS.println("// ========================");
59             _mainPS.println("// constant.c file");
60             _mainPS.println("// ========================");
61
62             //includes
63             _mainPS.println("#include <stdio.h>");
64
65             //define the number of FIFO queues and the number of processes
66             _mainPS.println("#ifndef _CONSTANT_H_");
67             _mainPS.println("#define _CONSTANT_H_");
68             _mainPS.println("");
69             _mainPS.println("#define NUM_PROCS "
70                     + x.getProcessList().size());
71             _mainPS.println("#define NUM_SPES " + numSpes);
72             _mainPS.println("#define NUM_FIFO "
73                     + x.getChannelList().size());
74             _mainPS.println("");
75             _mainPS.println("#endif // _CONSTANT_H_ ");
76             _mainPS.println("");
77         }
78         catch (Exception e) {
79             System.out.println("CbeModuleVisitor: exception occured: "
80                                + e.getMessage());
81             e.printStackTrace();
82         }
83     }
84
85     /**
86      *
87      * @param x process that needs to be processed
88      */
89     public void visitComponent(Process x) {
90     }
91
92     /**
93      *
94      * @param x channel that needs to be processed
95      */
96     public void visitComponent(Channel x) {
97     }
98
99     protected CodePrintStream _mainPS = null;
100     protected String _dir = null;
101     protected HashMap<Port, Integer> _portMap;
102 }