dol: initial dol commit
[jump.git] / dol / src / dol / visitor / systemC / PNSystemCVisitor.java
diff --git a/dol/src/dol/visitor/systemC/PNSystemCVisitor.java b/dol/src/dol/visitor/systemC/PNSystemCVisitor.java
new file mode 100644 (file)
index 0000000..e043782
--- /dev/null
@@ -0,0 +1,101 @@
+/* $Id: PNSystemCVisitor.java 1 2010-02-24 13:03:05Z haidw $ */
+package dol.visitor.systemC;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+
+import dol.datamodel.pn.ProcessNetwork;
+import dol.util.CodePrintStream;
+import dol.util.Copier;
+import dol.visitor.PNVisitor;
+
+/**
+ * This class is a class for a visitor that is used to generate
+ * a SystemC package.
+ */
+public class PNSystemCVisitor extends PNVisitor {
+
+    /**
+     * Constructor.
+     *
+     * @param packageName Name of the SystemC directory
+     */
+    public PNSystemCVisitor(String packageName) {
+        _packageName = packageName;
+    }
+
+    /**
+     *
+     * @param x process network that needs to be rendered.
+     */
+    public void visitComponent(ProcessNetwork x) {
+        try {
+            //_packageName = x.getName() + "SystemCPackage";
+            _generateDirHierarchy();
+
+            x.accept(new MakefileVisitor(_srcDir));
+            x.accept(new SCModuleVisitor(_srcDir));
+            x.accept(new ProcessVisitor(_wrapperDir));
+
+        }
+        catch (Exception e) {
+            System.out.println(" SystemC PN Visitor: exception "
+                    + "occured: " + e.getMessage());
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     *
+     */
+    protected void _generateDirHierarchy()
+        throws IOException, FileNotFoundException {
+        File dir = new File(_packageName);
+        dir.mkdirs();
+
+        _srcDir = _packageName + _delimiter + _srcDirName;
+        dir = new File(_srcDir);
+        dir.mkdirs();
+
+        _libDir = _srcDir + _delimiter + _libDirName;
+        dir = new File(_libDir);
+        dir.mkdirs();
+
+        _processDir = _srcDir + _delimiter + _processDirName;
+        dir = new File(_processDir);
+        dir.mkdirs();
+
+        _wrapperDir = _srcDir + _delimiter + _wrapperDirName;
+        dir = new File(_wrapperDir);
+        dir.mkdirs();
+
+        //copy library files
+        File source = new File(_ui.getMySystemCLib());
+        File destination = new File(_libDir);
+        new Copier().copy(source, destination);
+
+        //copy process source code
+        source = new File(_srcDirName);
+        destination = new File(_processDir);
+        new Copier().copy(source, destination);
+    }
+
+    protected String _packageName = null;
+
+    protected String _srcDir = "";
+    protected static String _srcDirName = "src";
+
+    protected String _libDir = "";
+    protected static String _libDirName = "lib";
+
+    protected String _processDir = "";
+    protected static String _processDirName = "processes";
+
+    protected String _wrapperDir = "";
+    protected static String _wrapperDirName = "sc_wrappers";
+
+    protected String _threadPostfix = "_thread";
+
+    protected CodePrintStream _mainPS = null;
+}