1 /* $Id: YapiModuleVisitor.java 1 2010-02-24 13:03:05Z haidw $ */
2 package dol.visitor.yapi;
4 import java.io.FileOutputStream;
5 import java.io.OutputStream;
6 import java.util.Vector;
8 import dol.datamodel.pn.Channel;
9 import dol.datamodel.pn.Port;
10 import dol.datamodel.pn.Process;
11 import dol.datamodel.pn.ProcessNetwork;
12 import dol.util.CodePrintStream;
13 import dol.visitor.PNVisitor;
16 * This class is a class for a visitor that is used to generate
19 public class YapiModuleVisitor extends PNVisitor {
24 public YapiModuleVisitor(String dir) {
31 public void visitComponent(ProcessNetwork pn) {
34 String filename = _dir + _delimiter + "application.h";
35 OutputStream file = new FileOutputStream(filename);
36 _code = new CodePrintStream(file);
38 _code.println("#include \"yapi.h\"");
41 Vector<String> processList = new Vector<String>();
42 for (Process p : pn.getProcessList()) {
43 String basename = p.getBasename();
44 if (!processList.contains(basename)) {
45 processList.add(basename);
46 _code.println("#include \""
47 + p.getBasename() + "_wrapper.h\"");
51 _code.println("class Application : public ProcessNetwork");
53 _code.println("public:");
54 _code.println(" Application(const Id& n);");
55 _code.println(" const char* type() const;");
57 _code.println("private:");
59 for (Channel c : pn.getChannelList()) {
60 if (c.getType().equals("fifo")) {
61 _code.println(" Fifo<char> " + c.getName()
63 } else if (c.getType().equals("wfifo")) {
64 System.out.println("Warning: YAPI visitor does not "
65 + "support windowed FIFOs.");
70 for (Process p : pn.getProcessList()) {
71 _code.println(" " + p.getBasename() + "_wrapper "
79 filename = _dir + _delimiter + "application.cpp";
80 file = new FileOutputStream(filename);
81 _code = new CodePrintStream(file);
83 _code.println("#include \"application.h\"");
85 _code.println("Application::Application(const Id& n) :");
86 _code.print(" ProcessNetwork(n)");
87 for (Channel c : pn.getChannelList()) {
88 if (c.getType().equals("fifo")) {
89 _code.print(",\n " + c.getName() + "(id(\""
90 + c.getName() + "\"))");
91 } else if (c.getType().equals("wfifo")) {
92 System.out.println("Warning: YAPI visitor does not "
93 + "support windowed FIFOs.");
96 for (Process p : pn.getProcessList()) {
97 _code.print(",\n " + p.getName() + "(\""
98 + p.getName() + "\", id(\"" + p.getName()
101 for (Port port : p.getPortList()) {
102 _code.print(", " + port.getPeerResource().getName());
107 _code.println("{ }");
109 _code.println("const char* Application::type() const");
111 _code.println(" return \"Application\";");
114 catch (Exception e) {
115 System.out.println("YapiModuleVisitor: "
116 + "exception occured: " + e.getMessage());
121 protected CodePrintStream _code = null;
122 protected String _dir = null;
123 protected OutputStream _file;
124 protected CodePrintStream _pn;