dol: initial dol commit
[jump.git] / dol / src / dol / visitor / hdsd / HdsdVisitor.java
1 package dol.visitor.hdsd;
2
3 import java.io.File;
4 import java.io.FileNotFoundException;
5 import java.io.IOException;
6
7 import dol.datamodel.mapping.Mapping;
8 import dol.util.CodePrintStream;
9 import dol.util.Copier;
10 import dol.visitor.MapVisitor;
11
12 /**
13  * This class is a class for a visitor that is used to generate
14  * a HdS package with distributed simulation support.
15  */
16 public class HdsdVisitor extends MapVisitor {
17
18     /**
19      * Constructor.
20      *
21      * @param packageName name of the HdSd directory
22      */
23     public HdsdVisitor(String packageName) {
24         _packageName = packageName;
25     }
26
27     /**
28      *
29      * @param x mapping that needs to be rendered.
30      */
31     public void visitComponent(Mapping x) {
32         try {
33             _generateDirHierarchy();
34
35             x.accept(new HdsdMakefileVisitor(_srcDir));
36             x.accept(new HdsdModuleVisitor(_srcDir));
37             x.getPN().accept(new HdsdProcessVisitor(_wrapperDir));
38             x.accept(new HdsdScriptVisitor(_srcDir));
39         }
40         catch (Exception e) {
41             System.out.println("HdSdVisitor: exception occured: "
42                     + e.getMessage());
43             e.printStackTrace();
44         }
45     }
46
47     /**
48      *
49      */
50     protected void _generateDirHierarchy()
51         throws IOException, FileNotFoundException {
52         File dir = new File(_packageName);
53         dir.mkdirs();
54
55         _srcDir = _packageName + "/" + _srcDirName;
56         dir = new File(_srcDir);
57         dir.mkdirs();
58
59         _libDir = _srcDir + "/" + _libDirName;
60         dir = new File(_libDir);
61         dir.mkdirs();
62         
63         _scdDir = _srcDir + "/" + _scdDirName;
64         dir = new File(_scdDir);
65         dir.mkdirs();
66
67         _processDir = _srcDir + "/" + _processDirName;
68         dir = new File(_processDir);
69         dir.mkdirs();
70
71         _wrapperDir = _srcDir + "/" + _wrapperDirName;
72         dir = new File(_wrapperDir);
73         dir.mkdirs();
74
75         //copy library files
76         String sdir = _ui.getVisitorDir() + "hdsd" + "/" + "lib";
77         File source = new File(sdir);
78         File destination = new File(_libDir);
79         new Copier().copy(source, destination);
80         
81         // copy scd library files
82         sdir = _ui.getVisitorDir() + "hdsd" + "/" + "scd";
83         source = new File(sdir);
84         destination = new File(_scdDir);
85         new Copier().copy(source, destination);
86
87         //copy process source code
88         source = new File(_srcDirName);
89         destination = new File(_processDir);
90         new Copier().copy(source, destination);
91     }
92
93     protected String _packageName = null;
94
95     protected String _srcDir = "";
96     protected static String _srcDirName = "src";
97
98     protected String _libDir = "";
99     protected static String _libDirName = "lib";
100     
101     protected String _scdDir = "";
102     protected static String _scdDirName = "scd";
103
104     protected String _processDir = "";
105     protected static String _processDirName = "processes";
106
107     protected String _wrapperDir = "";
108     protected static String _wrapperDirName = "sc_wrappers";
109
110     protected String _threadPostfix = "_thread";
111
112     protected CodePrintStream _mainPS = null;
113 }