1 package dol.visitor.hdsd;
3 import dol.datamodel.architecture.Processor;
4 import dol.datamodel.mapping.Mapping;
5 import dol.datamodel.pn.Channel;
6 import dol.datamodel.pn.Port;
7 import dol.datamodel.pn.Process;
8 import dol.datamodel.pn.Resource;
9 import dol.util.CodePrintStream;
10 import dol.visitor.PNVisitor;
13 * Visitor that generates the main program thread of a process
14 * and the process network in the constructor.
16 public class HdsdModulePNVisitor extends PNVisitor {
21 public HdsdModulePNVisitor(Processor processor, CodePrintStream stream) {
22 _processor = processor;
27 * Generates the thread for this process.
29 * @param x process that needs to be rendered
31 public void visitComponent(Process x) {
32 _mainPS.printPrefixln("void thread_" + x.getName() + "()");
33 _mainPS.printLeftBracket();
34 _mainPS.printPrefixln("while (!" + x.getName()
35 + "_ins.isDetached())");
36 _mainPS.printLeftBracket();
38 /* begin of profiling: start event */
39 _mainPS.printPrefixln("#ifdef INCLUDE_PROFILER");
40 _mainPS.printPrefixln("if (profiler_output_file != NULL) fprintf(profiler_output_file, \"%u "+ x.getName() + " started.\\n\", profiler_event_counter++);");
41 _mainPS.printPrefixln("#endif");
42 /* end of profiling */
44 _mainPS.printPrefixln(x.getName() + "_ins.fire();");
46 /* begin of profiling: stop event */
47 _mainPS.printPrefixln("#ifdef INCLUDE_PROFILER");
48 _mainPS.printPrefixln("if (profiler_output_file != NULL) fprintf(profiler_output_file, \"%u "+ x.getName() + " stopped.\\n\", profiler_event_counter++);");
49 _mainPS.printPrefixln("#endif");
50 /* end of profiling */
52 _mainPS.printPrefixln("eventList.push_back(&" + x.getName()
54 _mainPS.printPrefixln("sched_event.notify(SC_ZERO_TIME);");
55 _mainPS.printPrefixln("wait(" + x.getName() + "_event);");
57 _mainPS.printRightBracket();
58 _mainPS.printRightBracket();
62 * Generates the process network. This is the channel content
63 * in the model constructor.
64 * @param x channel that needs to be rendered
66 public void visitComponent(Channel x) {
67 for (Port p : x.getPortList()) {
68 Port peerPort = (Port)(p.getPeerPort());
69 Resource peerResource = p.getPeerResource();
71 if (!_processor.hasProcess(peerResource.getName()))
74 if (peerPort.getRange() != null) {
76 _mainPS.printPrefixln(peerResource.getName()
78 + peerPort.getBasename()
79 + peerPort.getName().replace(
80 peerPort.getBasename(), "").replaceAll(
81 "_([0-9]+)", "[$1]") + "(" + x.getName()
84 else if (p.isInPort()) {
85 _mainPS.printPrefixln(peerResource.getName()
87 + peerPort.getBasename()
88 + peerPort.getName().replace(
89 peerPort.getBasename(), "").replaceAll(
90 "_([0-9]+)", "[$1]") + "(" + x.getName()
96 _mainPS.printPrefixln(peerResource.getName()
97 + "_ins.INPORT_" + peerPort.getName()
98 + "(" + x.getName() + "_ins);");
100 else if (p.isInPort()) {
101 _mainPS.printPrefixln(peerResource.getName()
102 + "_ins.OUTPORT_" + peerPort.getName()
103 + "(" + x.getName() + "_ins);");
109 protected CodePrintStream _mainPS = null;
110 protected String _dir = null;
111 protected Mapping _map = null;
112 protected Processor _processor = null;