dol: initial dol commit
[jump.git] / dol / src / dol / visitor / cbe / CbeConstantVisitor.java
diff --git a/dol/src/dol/visitor/cbe/CbeConstantVisitor.java b/dol/src/dol/visitor/cbe/CbeConstantVisitor.java
new file mode 100644 (file)
index 0000000..594673b
--- /dev/null
@@ -0,0 +1,102 @@
+/* $Id: CbeConstantVisitor.java 1 2010-02-24 13:03:05Z haidw $ */
+package dol.visitor.cbe;
+
+import java.io.FileOutputStream;
+import java.io.OutputStream;
+import java.util.HashMap;
+
+import dol.datamodel.pn.Channel;
+import dol.datamodel.pn.Port;
+import dol.datamodel.pn.Process;
+import dol.datamodel.pn.ProcessNetwork;
+import dol.main.UserInterface;
+import dol.util.CodePrintStream;
+import dol.visitor.PNVisitor;
+
+/**
+ * This class is a class for a constant file
+ *
+ * @author lschor, 2008-11-08
+ *
+ * Revision:
+ * 2008-11-08: Created
+ */
+public class CbeConstantVisitor extends PNVisitor {
+
+    /**
+     * Constructor.
+     *
+     * @param dir path of this file
+     */
+    public CbeConstantVisitor(String dir, HashMap<Port, Integer> portMap) {
+        _dir = dir;
+        _portMap = portMap;
+    }
+
+    /**
+     * 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.c 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());
+            _mainPS.println("#define NUM_SPES " + numSpes);
+            _mainPS.println("#define NUM_FIFO "
+                    + x.getChannelList().size());
+            _mainPS.println("");
+            _mainPS.println("#endif // _CONSTANT_H_ ");
+            _mainPS.println("");
+        }
+        catch (Exception e) {
+            System.out.println("CbeModuleVisitor: 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 CodePrintStream _mainPS = null;
+    protected String _dir = null;
+    protected HashMap<Port, Integer> _portMap;
+}