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.Epiphany.EpiphanyVisitor;
26 import dol.visitor.protothread.ProtothreadVisitor;
27 import dol.visitor.rtems.RtemsVisitor;
28 import dol.visitor.systemC.PNSystemCVisitor;
29 import dol.visitor.xml.PNXmlVisitor;
30 import dol.visitor.yapi.YapiVisitor;
33 * Distributed Operating Layer (DOL)
35 * This class is the main controlling part of DOL. In this class, the
36 * command line options are processed, the input and output files are set,
37 * and the complete compilation cycle is done. Also, this class is the
38 * final responder to exceptions occurring within the DOL.
43 * The main method of this class
45 * @param args The arguments to provide to DOL.
47 public static void main(String[] args) {
49 _ui = UserInterface.getInstance();
53 } catch (NumberFormatException e) {
54 System.out.println("Error in Command line options: "
55 + " the numerial format for an argument is"
56 + " incorrect. Message: "
59 } catch (IllegalArgumentException e) {
60 System.out.println("Error in Command line option: "
63 } catch (Exception e) {
64 System.out.println(e.getMessage());
71 //load process network specification from XML
72 if (_ui.getNetworkFileName() != null) {
73 PNXmlParser parserPN = new PNXmlParser();
74 _pn = parserPN.doParse(_ui.getNetworkFileName());
77 //load architecture specification from XML
78 if (_ui.getPlatformFileName() != null) {
79 ArchiXmlParser parserArch = new ArchiXmlParser();
80 _architecture = parserArch.doParse(
81 _ui.getPlatformFileName());
83 //not useful (archiPathFinderVisitor not functional)
84 //_architecture.setArchiConnections();
85 //_architecture.accept(new dol.visitor.pathFinder.
86 // archiPathFinderVisitor());
87 //_architecture.accept(new dol.visitor.pathFinder.
88 // archiPathPrinterVisitor());
91 //load mapping specification from XML
92 if ((_pn != null) && (_architecture != null)
93 && _ui.getMappingFileName() != null) {
94 MapXmlParser parserMap = new MapXmlParser(_pn, _architecture);
95 _mapping = parserMap.doParse(_ui.getMappingFileName());
99 if (_ui.getCheckFlag()){
100 System.out.println("Consistency check:");
101 //check process network
103 SanityCheck.getInstance().checkPN(_pn);
106 if (_architecture != null)
107 SanityCheck.getInstance().checkArch(_architecture);
110 if (_mapping != null)
111 SanityCheck.getInstance().checkMap(_mapping);
113 System.out.println(" -- Consistency check [Finished]");
114 System.out.println();
117 // analyze profiling data and fill into pn
118 if (_ui.getProfilingFlag() && (_pn != null)) {
119 System.out.println(" -- ProcessNetwork profiling");
120 Profiler p = new Profiler();
121 p.profilePN(_ui.getTraceName(), _pn);
122 System.out.println(" -- Profiling [Finished]");
123 System.out.println();
126 if (_ui.getVspLogFlag() && (_pn != null)) {
127 System.out.println("VSP log file back-annotation:");
128 VSPLogFileProfiler.annotateProcessNetwork(
129 _ui.getVspLogFileName(), _pn);
130 System.out.println(" -- Back-annotation [Finished]");
131 System.out.println();
134 if (_ui.getWorkloadFlag() && (_pn != null)) {
135 System.out.println("Workload file back-annotation:");
136 WorkloadAnnotator.annotateProcessNetwork(
137 _ui.getWorkloadFileName(), _pn);
138 System.out.println(" -- Back-annotation [Finished]");
139 System.out.println();
143 CodePrintStream printStream;
145 if (_ui.getDottyFlag()) {
146 OutputStream file = new FileOutputStream(_ui.getDottyFileName());
147 printStream = new CodePrintStream(file);
148 if (_mapping != null)
150 System.out.println("Generating Mapping in Dotty format:");
151 _mapping.accept(new MapDotVisitor(printStream));
153 else if (_pn != null)
155 System.out.println("Generating ProcessNetwork in Dotty format:");
156 _pn.accept(new PNDotVisitor(printStream));
158 else if (_architecture!=null) {
159 System.out.println("Generating Architecture in Dotty format:");
160 _architecture.registerRWPath2Resource();
161 _architecture.accept(new ArchDotVisitor(printStream));
163 System.out.println(" -- Generation [Finished]");
164 System.out.println();
167 if (_ui.getXmlGenFlag() && (_pn != null)) {
168 System.out.println("Generating ProcessNetwork in XML format:");
169 StringBuffer buffer = new StringBuffer();
170 _pn.accept(new PNXmlVisitor(buffer));
172 java.io.BufferedWriter writer =
173 new java.io.BufferedWriter(
174 new java.io.FileWriter(_ui.getOutputFileName()));
175 writer.write(buffer.toString());
177 } catch (java.io.IOException e) {
178 System.out.println(" -- DOL caught an exception while "
179 + "creating XML file: " + e.getMessage());
180 e.printStackTrace(System.out);
182 System.out.println(" -- Generation [Finished]");
183 System.out.println();
186 if (_ui.getSystemCFlag() && (_pn != null)) {
187 System.out.println("Generating SystemC package:");
188 _pn.accept(new PNSystemCVisitor(_ui.getCodeDirectoryName()));
189 System.out.println(" -- Generation [Finished]");
190 System.out.println();
193 if (_ui.getPipeAndFilterFlag() && (_pn != null)) {
194 System.out.println("Generating PipeAndFilter package:");
195 _pn.accept(new PipeAndFilterVisitor(
196 _ui.getPipeAndFilterCodeDirectoryName()));
197 System.out.println(" -- Generation [Finished]");
198 System.out.println();
201 if (_ui.getEpiphanyFlag() && (_pn != null)) {
202 System.out.println("Generating Epiphany package:");
203 _pn.accept(new EpiphanyVisitor(
204 _ui.getEpiphanyCodeDirectoryName()));
205 System.out.println(" -- Generation [Finished]");
206 System.out.println();
209 if (_ui.getProtothreadFlag() && (_pn != null)) {
210 System.out.println("Generating protothread package:");
211 _pn.accept(new ProtothreadVisitor(
212 _ui.getProtothreadCodeDirectoryName()));
213 System.out.println(" -- Generation [Finished]");
214 System.out.println();
217 if (_ui.getRtemsFlag() && (_pn != null)) {
218 String bsp = _ui.getRtemsBSP();
219 System.out.println("Generating RTEMS-" + bsp + " package:");
220 _pn.accept(new RtemsVisitor(
221 _ui.getRtemsCodeDirectoryName()));
222 System.out.println(" -- Generation [Finished]");
223 System.out.println();
226 if (_ui.getCbeFlag() && (_pn != null)) {
227 System.out.println("Generating Cell-package:");
228 _pn.accept(new CellVisitor(
229 _ui.getCbeCodeDirectoryName()));
230 System.out.println(" -- Generation [Finished]");
231 System.out.println();
234 if (_ui.getYapiFlag() && (_pn != null)) {
235 System.out.println("Generating YAPI-package:");
236 _pn.accept(new YapiVisitor(
237 _ui.getYapiCodeDirectoryName()));
238 System.out.println(" -- Generation [Finished]");
239 System.out.println();
242 if (_ui.getHdsFlag() && (_pn != null)) {
243 System.out.println("Generating HdS package:");
244 if ((_pn!=null) && (_architecture!=null) && (_mapping!=null)) {
245 System.out.println("Generating distributed HdS package:");
246 // Hds with networking supportSAXException
247 _mapping.accept(new HdsdVisitor(_ui.getHdsCodeDirectoryName()));
250 // Hds without networking support
251 _pn.accept(new HdsVisitor(_ui.getHdsCodeDirectoryName()));
253 System.out.println(" -- Generation [Finished]");
254 System.out.println();
258 catch (NumberFormatException e) {
259 System.out.println(" ERROR Occured in DOL: " + e.getMessage());
260 e.printStackTrace(System.out);
262 catch (Exception e) {
263 System.out.println(" DOL caught an exception: " + e.getMessage());
264 e.printStackTrace(System.out);
268 protected static ProcessNetwork _pn = null;
269 protected static Architecture _architecture = null;
270 protected static Mapping _mapping = null;
271 protected static UserInterface _ui = null;