X-Git-Url: http://sraa.de/git/?a=blobdiff_plain;f=dol%2Fsrc%2Fdol%2Fvisitor%2Fyapi%2FYapiModuleVisitor.java;fp=dol%2Fsrc%2Fdol%2Fvisitor%2Fyapi%2FYapiModuleVisitor.java;h=bf2f699d2d67bfaf24ab920208e2b51a2b108dd0;hb=8c411cf24ed0eb889191aaeafd8fa1e69081df42;hp=0000000000000000000000000000000000000000;hpb=dea7a4fb1ed110d3ce6e6d9255103d724bd66c0e;p=jump.git diff --git a/dol/src/dol/visitor/yapi/YapiModuleVisitor.java b/dol/src/dol/visitor/yapi/YapiModuleVisitor.java new file mode 100644 index 0000000..bf2f699 --- /dev/null +++ b/dol/src/dol/visitor/yapi/YapiModuleVisitor.java @@ -0,0 +1,126 @@ +/* $Id: YapiModuleVisitor.java 1 2010-02-24 13:03:05Z haidw $ */ +package dol.visitor.yapi; + +import java.io.FileOutputStream; +import java.io.OutputStream; +import java.util.Vector; + +import dol.datamodel.pn.Channel; +import dol.datamodel.pn.Port; +import dol.datamodel.pn.Process; +import dol.datamodel.pn.ProcessNetwork; +import dol.util.CodePrintStream; +import dol.visitor.PNVisitor; + +/** + * This class is a class for a visitor that is used to generate + * the main program. + */ +public class YapiModuleVisitor extends PNVisitor { + + /** + * Constructor. + */ + public YapiModuleVisitor(String dir) { + _dir = dir; + } + + /** + * + */ + public void visitComponent(ProcessNetwork pn) { + try { + //create header file + String filename = _dir + _delimiter + "application.h"; + OutputStream file = new FileOutputStream(filename); + _code = new CodePrintStream(file); + + _code.println("#include \"yapi.h\""); + _code.println(); + + Vector processList = new Vector(); + for (Process p : pn.getProcessList()) { + String basename = p.getBasename(); + if (!processList.contains(basename)) { + processList.add(basename); + _code.println("#include \"" + + p.getBasename() + "_wrapper.h\""); + } + } + _code.println(); + _code.println("class Application : public ProcessNetwork"); + _code.println("{"); + _code.println("public:"); + _code.println(" Application(const Id& n);"); + _code.println(" const char* type() const;"); + _code.println(); + _code.println("private:"); + + for (Channel c : pn.getChannelList()) { + if (c.getType().equals("fifo")) { + _code.println(" Fifo " + c.getName() + + ";"); + } else if (c.getType().equals("wfifo")) { + System.out.println("Warning: YAPI visitor does not " + + "support windowed FIFOs."); + } + } + _code.println(); + + for (Process p : pn.getProcessList()) { + _code.println(" " + p.getBasename() + "_wrapper " + + p.getName() + ";"); + } + _code.println("};"); + file.close(); + + + //create cpp file + filename = _dir + _delimiter + "application.cpp"; + file = new FileOutputStream(filename); + _code = new CodePrintStream(file); + + _code.println("#include \"application.h\""); + _code.println(); + _code.println("Application::Application(const Id& n) :"); + _code.print(" ProcessNetwork(n)"); + for (Channel c : pn.getChannelList()) { + if (c.getType().equals("fifo")) { + _code.print(",\n " + c.getName() + "(id(\"" + + c.getName() + "\"))"); + } else if (c.getType().equals("wfifo")) { + System.out.println("Warning: YAPI visitor does not " + + "support windowed FIFOs."); + } + } + for (Process p : pn.getProcessList()) { + _code.print(",\n " + p.getName() + "(\"" + + p.getName() + "\", id(\"" + p.getName() + + "\")"); + + for (Port port : p.getPortList()) { + _code.print(", " + port.getPeerResource().getName()); + } + _code.print(")"); + } + _code.println(); + _code.println("{ }"); + _code.println(); + _code.println("const char* Application::type() const"); + _code.println("{"); + _code.println(" return \"Application\";"); + _code.println("}"); + } + catch (Exception e) { + System.out.println("YapiModuleVisitor: " + + "exception occured: " + e.getMessage()); + e.printStackTrace(); + } + } + + protected CodePrintStream _code = null; + protected String _dir = null; + protected OutputStream _file; + protected CodePrintStream _pn; +} +