1 /* $Id: Main.java 203 2010-10-11 08:59:47Z dchokshi $ */
4 import java.io.FileOutputStream;
5 import java.io.OutputStream;
7 import dol.check.SanityCheck;
8 import dol.datamodel.architecture.Architecture;
9 import dol.datamodel.mapping.Mapping;
10 import dol.datamodel.pn.ProcessNetwork;
11 import dol.helper.profiler.Profiler;
12 import dol.helper.profiler.VSPLogFileProfiler;
13 import dol.helper.profiler.WorkloadAnnotator;
14 import dol.parser.xml.archischema.ArchiXmlParser;
15 import dol.parser.xml.mapschema.MapXmlParser;
16 import dol.parser.xml.pnschema.PNXmlParser;
17 import dol.util.CodePrintStream;
18 import dol.visitor.PipeAndFilter.PipeAndFilterVisitor;
19 import dol.visitor.cell.CellVisitor;
20 import dol.visitor.dot.ArchDotVisitor;
21 import dol.visitor.dot.MapDotVisitor;
22 import dol.visitor.dot.PNDotVisitor;
23 import dol.visitor.hds.HdsVisitor;
24 import dol.visitor.hdsd.HdsdVisitor;
25 import dol.visitor.protothread.ProtothreadVisitor;
26 import dol.visitor.rtems.RtemsVisitor;
27 import dol.visitor.systemC.PNSystemCVisitor;
28 import dol.visitor.xml.PNXmlVisitor;
29 import dol.visitor.yapi.YapiVisitor;
32 * Distributed Operating Layer (DOL)
34 * This class is the main controlling part of DOL. In this class, the
35 * command line options are processed, the input and output files are set,
36 * and the complete compilation cycle is done. Also, this class is the
37 * final responder to exceptions occurring within the DOL.
42 * The main method of this class
44 * @param args The arguments to provide to DOL.
46 public static void main(String[] args) {
48 _ui = UserInterface.getInstance();
52 } catch (NumberFormatException e) {
53 System.out.println("Error in Command line options: "
54 + " the numerial format for an argument is"
55 + " incorrect. Message: "
58 } catch (IllegalArgumentException e) {
59 System.out.println("Error in Command line option: "
62 } catch (Exception e) {
63 System.out.println(e.getMessage());
70 //load process network specification from XML
71 if (_ui.getNetworkFileName() != null) {
72 PNXmlParser parserPN = new PNXmlParser();
73 _pn = parserPN.doParse(_ui.getNetworkFileName());
76 //load architecture specification from XML
77 if (_ui.getPlatformFileName() != null) {
78 ArchiXmlParser parserArch = new ArchiXmlParser();
79 _architecture = parserArch.doParse(
80 _ui.getPlatformFileName());
82 //not useful (archiPathFinderVisitor not functional)
83 //_architecture.setArchiConnections();
84 //_architecture.accept(new dol.visitor.pathFinder.
85 // archiPathFinderVisitor());
86 //_architecture.accept(new dol.visitor.pathFinder.
87 // archiPathPrinterVisitor());
90 //load mapping specification from XML
91 if ((_pn != null) && (_architecture != null)
92 && _ui.getMappingFileName() != null) {
93 MapXmlParser parserMap = new MapXmlParser(_pn, _architecture);
94 _mapping = parserMap.doParse(_ui.getMappingFileName());
98 if (_ui.getCheckFlag()){
99 System.out.println("Consistency check:");
100 //check process network
102 SanityCheck.getInstance().checkPN(_pn);
105 if (_architecture != null)
106 SanityCheck.getInstance().checkArch(_architecture);
109 if (_mapping != null)
110 SanityCheck.getInstance().checkMap(_mapping);
112 System.out.println(" -- Consistency check [Finished]");
113 System.out.println();
116 // analyze profiling data and fill into pn
117 if (_ui.getProfilingFlag() && (_pn != null)) {
118 System.out.println(" -- ProcessNetwork profiling");
119 Profiler p = new Profiler();
120 p.profilePN(_ui.getTraceName(), _pn);
121 System.out.println(" -- Profiling [Finished]");
122 System.out.println();
125 if (_ui.getVspLogFlag() && (_pn != null)) {
126 System.out.println("VSP log file back-annotation:");
127 VSPLogFileProfiler.annotateProcessNetwork(
128 _ui.getVspLogFileName(), _pn);
129 System.out.println(" -- Back-annotation [Finished]");
130 System.out.println();
133 if (_ui.getWorkloadFlag() && (_pn != null)) {
134 System.out.println("Workload file back-annotation:");
135 WorkloadAnnotator.annotateProcessNetwork(
136 _ui.getWorkloadFileName(), _pn);
137 System.out.println(" -- Back-annotation [Finished]");
138 System.out.println();
142 CodePrintStream printStream;
144 if (_ui.getDottyFlag()) {
145 OutputStream file = new FileOutputStream(_ui.getDottyFileName());
146 printStream = new CodePrintStream(file);
147 if (_mapping != null)
149 System.out.println("Generating Mapping in Dotty format:");
150 _mapping.accept(new MapDotVisitor(printStream));
152 else if (_pn != null)
154 System.out.println("Generating ProcessNetwork in Dotty format:");
155 _pn.accept(new PNDotVisitor(printStream));
157 else if (_architecture!=null) {
158 System.out.println("Generating Architecture in Dotty format:");
159 _architecture.registerRWPath2Resource();
160 _architecture.accept(new ArchDotVisitor(printStream));
162 System.out.println(" -- Generation [Finished]");
163 System.out.println();
166 if (_ui.getXmlGenFlag() && (_pn != null)) {
167 System.out.println("Generating ProcessNetwork in XML format:");
168 StringBuffer buffer = new StringBuffer();
169 _pn.accept(new PNXmlVisitor(buffer));
171 java.io.BufferedWriter writer =
172 new java.io.BufferedWriter(
173 new java.io.FileWriter(_ui.getOutputFileName()));
174 writer.write(buffer.toString());
176 } catch (java.io.IOException e) {
177 System.out.println(" -- DOL caught an exception while "
178 + "creating XML file: " + e.getMessage());
179 e.printStackTrace(System.out);
181 System.out.println(" -- Generation [Finished]");
182 System.out.println();
185 if (_ui.getSystemCFlag() && (_pn != null)) {
186 System.out.println("Generating SystemC package:");
187 _pn.accept(new PNSystemCVisitor(_ui.getCodeDirectoryName()));
188 System.out.println(" -- Generation [Finished]");
189 System.out.println();
192 if (_ui.getPipeAndFilterFlag() && (_pn != null)) {
193 System.out.println("Generating PipeAndFilter package:");
194 _pn.accept(new PipeAndFilterVisitor(
195 _ui.getPipeAndFilterCodeDirectoryName()));
196 System.out.println(" -- Generation [Finished]");
197 System.out.println();
200 if (_ui.getProtothreadFlag() && (_pn != null)) {
201 System.out.println("Generating protothread package:");
202 _pn.accept(new ProtothreadVisitor(
203 _ui.getProtothreadCodeDirectoryName()));
204 System.out.println(" -- Generation [Finished]");
205 System.out.println();
208 if (_ui.getRtemsFlag() && (_pn != null)) {
209 String bsp = _ui.getRtemsBSP();
210 System.out.println("Generating RTEMS-" + bsp + " package:");
211 _pn.accept(new RtemsVisitor(
212 _ui.getRtemsCodeDirectoryName()));
213 System.out.println(" -- Generation [Finished]");
214 System.out.println();
217 if (_ui.getCbeFlag() && (_pn != null)) {
218 System.out.println("Generating Cell-package:");
219 _pn.accept(new CellVisitor(
220 _ui.getCbeCodeDirectoryName()));
221 System.out.println(" -- Generation [Finished]");
222 System.out.println();
225 if (_ui.getYapiFlag() && (_pn != null)) {
226 System.out.println("Generating YAPI-package:");
227 _pn.accept(new YapiVisitor(
228 _ui.getYapiCodeDirectoryName()));
229 System.out.println(" -- Generation [Finished]");
230 System.out.println();
233 if (_ui.getHdsFlag() && (_pn != null)) {
234 System.out.println("Generating HdS package:");
235 if ((_pn!=null) && (_architecture!=null) && (_mapping!=null)) {
236 System.out.println("Generating distributed HdS package:");
237 // Hds with networking supportSAXException
238 _mapping.accept(new HdsdVisitor(_ui.getHdsCodeDirectoryName()));
241 // Hds without networking support
242 _pn.accept(new HdsVisitor(_ui.getHdsCodeDirectoryName()));
244 System.out.println(" -- Generation [Finished]");
245 System.out.println();
249 catch (NumberFormatException e) {
250 System.out.println(" ERROR Occured in DOL: " + e.getMessage());
251 e.printStackTrace(System.out);
253 catch (Exception e) {
254 System.out.println(" DOL caught an exception: " + e.getMessage());
255 e.printStackTrace(System.out);
259 protected static ProcessNetwork _pn = null;
260 protected static Architecture _architecture = null;
261 protected static Mapping _mapping = null;
262 protected static UserInterface _ui = null;