dol: initial dol commit
[jump.git] / dol / src / dol / main / Main.java
diff --git a/dol/src/dol/main/Main.java b/dol/src/dol/main/Main.java
new file mode 100644 (file)
index 0000000..6d0cd95
--- /dev/null
@@ -0,0 +1,263 @@
+/* $Id: Main.java 203 2010-10-11 08:59:47Z dchokshi $ */
+package dol.main;
+
+import java.io.FileOutputStream;
+import java.io.OutputStream;
+
+import dol.check.SanityCheck;
+import dol.datamodel.architecture.Architecture;
+import dol.datamodel.mapping.Mapping;
+import dol.datamodel.pn.ProcessNetwork;
+import dol.helper.profiler.Profiler;
+import dol.helper.profiler.VSPLogFileProfiler;
+import dol.helper.profiler.WorkloadAnnotator;
+import dol.parser.xml.archischema.ArchiXmlParser;
+import dol.parser.xml.mapschema.MapXmlParser;
+import dol.parser.xml.pnschema.PNXmlParser;
+import dol.util.CodePrintStream;
+import dol.visitor.PipeAndFilter.PipeAndFilterVisitor;
+import dol.visitor.cell.CellVisitor;
+import dol.visitor.dot.ArchDotVisitor;
+import dol.visitor.dot.MapDotVisitor;
+import dol.visitor.dot.PNDotVisitor;
+import dol.visitor.hds.HdsVisitor;
+import dol.visitor.hdsd.HdsdVisitor;
+import dol.visitor.protothread.ProtothreadVisitor;
+import dol.visitor.rtems.RtemsVisitor;
+import dol.visitor.systemC.PNSystemCVisitor;
+import dol.visitor.xml.PNXmlVisitor;
+import dol.visitor.yapi.YapiVisitor;
+
+/**
+ * Distributed Operating Layer (DOL)
+ *
+ * This class is the main controlling part of DOL. In this class, the
+ * command line options are processed, the input and output files are set,
+ * and the complete compilation cycle is done. Also, this class is the
+ * final responder to exceptions occurring within the DOL.
+ */
+public class Main {
+
+    /**
+     * The main method of this class
+     *
+     * @param args The arguments to provide to DOL.
+     */
+    public static void main(String[] args) {
+
+        _ui = UserInterface.getInstance();
+
+        try {
+            new Options(args);
+        } catch (NumberFormatException e) {
+            System.out.println("Error in Command line options: "
+                               + " the numerial format for an argument is"
+                               + " incorrect. Message: "
+                               + e.getMessage());
+            System.exit(-1);
+        } catch (IllegalArgumentException e) {
+            System.out.println("Error in Command line option: "
+                               + e.getMessage());
+            System.exit(-1);
+        } catch (Exception e) {
+            System.out.println(e.getMessage());
+            System.exit(-1);
+        }
+
+        try {
+            //loader
+
+            //load process network specification from XML
+            if (_ui.getNetworkFileName() != null) {
+                PNXmlParser parserPN = new PNXmlParser();
+                _pn = parserPN.doParse(_ui.getNetworkFileName());
+            }
+
+            //load architecture specification from XML
+            if (_ui.getPlatformFileName() != null) {
+                ArchiXmlParser parserArch = new ArchiXmlParser();
+                _architecture = parserArch.doParse(
+                        _ui.getPlatformFileName());
+
+                //not useful (archiPathFinderVisitor not functional)
+                //_architecture.setArchiConnections();
+                //_architecture.accept(new dol.visitor.pathFinder.
+                //        archiPathFinderVisitor());
+                //_architecture.accept(new dol.visitor.pathFinder.
+                //        archiPathPrinterVisitor());
+            }
+
+            //load mapping specification from XML
+            if ((_pn != null) && (_architecture != null)
+                    && _ui.getMappingFileName() != null) {
+                MapXmlParser parserMap = new MapXmlParser(_pn, _architecture);
+                _mapping = parserMap.doParse(_ui.getMappingFileName());
+            }
+
+            //sanity check
+            if (_ui.getCheckFlag()){
+                System.out.println("Consistency check:");
+                //check process network
+                if (_pn != null)
+                    SanityCheck.getInstance().checkPN(_pn);
+
+                //check architecture
+                if (_architecture != null)
+                    SanityCheck.getInstance().checkArch(_architecture);
+
+                //check mapping
+                if (_mapping != null)
+                    SanityCheck.getInstance().checkMap(_mapping);
+
+                System.out.println(" -- Consistency check [Finished]");
+                System.out.println();
+            }
+
+            // analyze profiling data and fill into pn
+            if (_ui.getProfilingFlag() && (_pn != null)) {
+                System.out.println(" -- ProcessNetwork profiling");
+                Profiler p = new Profiler();
+                p.profilePN(_ui.getTraceName(), _pn);
+                System.out.println(" -- Profiling [Finished]");
+                System.out.println();
+            }
+
+            if (_ui.getVspLogFlag() && (_pn != null)) {
+                System.out.println("VSP log file back-annotation:");
+                VSPLogFileProfiler.annotateProcessNetwork(
+                        _ui.getVspLogFileName(), _pn);
+                System.out.println(" -- Back-annotation [Finished]");
+                System.out.println();
+            }
+
+            if (_ui.getWorkloadFlag() && (_pn != null)) {
+                System.out.println("Workload file back-annotation:");
+                WorkloadAnnotator.annotateProcessNetwork(
+                        _ui.getWorkloadFileName(), _pn);
+                System.out.println(" -- Back-annotation [Finished]");
+                System.out.println();
+            }
+
+            //Generator
+            CodePrintStream printStream;
+
+            if (_ui.getDottyFlag()) {
+                OutputStream file = new FileOutputStream(_ui.getDottyFileName());
+                printStream = new CodePrintStream(file);
+                if (_mapping != null)
+                {
+                    System.out.println("Generating Mapping in Dotty format:");
+                    _mapping.accept(new MapDotVisitor(printStream));
+                }
+                else if (_pn != null)
+                {
+                    System.out.println("Generating ProcessNetwork in Dotty format:");
+                    _pn.accept(new PNDotVisitor(printStream));
+                }
+                else if (_architecture!=null) {
+                    System.out.println("Generating Architecture in Dotty format:");
+                    _architecture.registerRWPath2Resource();
+                    _architecture.accept(new ArchDotVisitor(printStream));
+                }
+                System.out.println(" -- Generation [Finished]");
+                System.out.println();
+            }
+
+            if (_ui.getXmlGenFlag() && (_pn != null)) {
+                System.out.println("Generating ProcessNetwork in XML format:");
+                StringBuffer buffer = new StringBuffer();
+                _pn.accept(new PNXmlVisitor(buffer));
+                try {
+                    java.io.BufferedWriter writer =
+                            new java.io.BufferedWriter(
+                            new java.io.FileWriter(_ui.getOutputFileName()));
+                    writer.write(buffer.toString());
+                    writer.close();
+                } catch (java.io.IOException e) {
+                    System.out.println(" -- DOL caught an exception while "
+                            + "creating XML file: " + e.getMessage());
+                    e.printStackTrace(System.out);
+                }
+                System.out.println(" -- Generation [Finished]");
+                System.out.println();
+            }
+
+            if (_ui.getSystemCFlag() && (_pn != null)) {
+                System.out.println("Generating SystemC package:");
+                _pn.accept(new PNSystemCVisitor(_ui.getCodeDirectoryName()));
+                System.out.println(" -- Generation [Finished]");
+                System.out.println();
+            }
+
+            if (_ui.getPipeAndFilterFlag() && (_pn != null)) {
+                System.out.println("Generating PipeAndFilter package:");
+                _pn.accept(new PipeAndFilterVisitor(
+                        _ui.getPipeAndFilterCodeDirectoryName()));
+                System.out.println(" -- Generation [Finished]");
+                System.out.println();
+            }
+
+            if (_ui.getProtothreadFlag() && (_pn != null)) {
+                System.out.println("Generating protothread package:");
+                _pn.accept(new ProtothreadVisitor(
+                        _ui.getProtothreadCodeDirectoryName()));
+                System.out.println(" -- Generation [Finished]");
+                System.out.println();
+            }
+
+            if (_ui.getRtemsFlag() && (_pn != null)) {
+                String bsp = _ui.getRtemsBSP();
+                System.out.println("Generating RTEMS-" + bsp + " package:");
+                _pn.accept(new RtemsVisitor(
+                    _ui.getRtemsCodeDirectoryName()));
+                System.out.println(" -- Generation [Finished]");
+                System.out.println();
+            }
+
+            if (_ui.getCbeFlag() && (_pn != null)) {
+                System.out.println("Generating Cell-package:");
+                _pn.accept(new CellVisitor(
+                    _ui.getCbeCodeDirectoryName()));
+                System.out.println(" -- Generation [Finished]");
+                System.out.println();
+            }
+
+            if (_ui.getYapiFlag() && (_pn != null)) {
+                System.out.println("Generating YAPI-package:");
+                _pn.accept(new YapiVisitor(
+                    _ui.getYapiCodeDirectoryName()));
+                System.out.println(" -- Generation [Finished]");
+                System.out.println();
+            }
+            
+            if (_ui.getHdsFlag() && (_pn != null)) {
+                System.out.println("Generating HdS package:");
+                if ((_pn!=null) && (_architecture!=null) && (_mapping!=null)) {
+                    System.out.println("Generating distributed HdS package:");
+                    // Hds with networking supportSAXException
+                    _mapping.accept(new HdsdVisitor(_ui.getHdsCodeDirectoryName()));
+
+                } else {
+                    // Hds without networking support
+                    _pn.accept(new HdsVisitor(_ui.getHdsCodeDirectoryName()));
+                }
+                System.out.println(" -- Generation [Finished]");
+                System.out.println();
+            }
+
+        }
+        catch (NumberFormatException e) {
+            System.out.println(" ERROR Occured in DOL: " + e.getMessage());
+            e.printStackTrace(System.out);
+        }
+        catch (Exception e) {
+            System.out.println(" DOL caught an exception: " + e.getMessage());
+            e.printStackTrace(System.out);
+        }
+    }
+
+    protected static ProcessNetwork _pn = null;
+    protected static Architecture _architecture = null;
+    protected static Mapping _mapping = null;
+    protected static UserInterface _ui = null;
+}