X-Git-Url: http://sraa.de/git/?a=blobdiff_plain;f=dol%2Fsrc%2Fdol%2Fvisitor%2Fhdsd%2FHdsdModulePNVisitor.java;fp=dol%2Fsrc%2Fdol%2Fvisitor%2Fhdsd%2FHdsdModulePNVisitor.java;h=466dba35509c7f0aba7944b3d684a7c5467db838;hb=8c411cf24ed0eb889191aaeafd8fa1e69081df42;hp=0000000000000000000000000000000000000000;hpb=dea7a4fb1ed110d3ce6e6d9255103d724bd66c0e;p=jump.git diff --git a/dol/src/dol/visitor/hdsd/HdsdModulePNVisitor.java b/dol/src/dol/visitor/hdsd/HdsdModulePNVisitor.java new file mode 100644 index 0000000..466dba3 --- /dev/null +++ b/dol/src/dol/visitor/hdsd/HdsdModulePNVisitor.java @@ -0,0 +1,113 @@ +package dol.visitor.hdsd; + +import dol.datamodel.architecture.Processor; +import dol.datamodel.mapping.Mapping; +import dol.datamodel.pn.Channel; +import dol.datamodel.pn.Port; +import dol.datamodel.pn.Process; +import dol.datamodel.pn.Resource; +import dol.util.CodePrintStream; +import dol.visitor.PNVisitor; + +/** + * Visitor that generates the main program thread of a process + * and the process network in the constructor. + */ +public class HdsdModulePNVisitor extends PNVisitor { + + /** + * Constructor. + */ + public HdsdModulePNVisitor(Processor processor, CodePrintStream stream) { + _processor = processor; + _mainPS = stream; + } + + /** + * Generates the thread for this process. + * + * @param x process that needs to be rendered + */ + public void visitComponent(Process x) { + _mainPS.printPrefixln("void thread_" + x.getName() + "()"); + _mainPS.printLeftBracket(); + _mainPS.printPrefixln("while (!" + x.getName() + + "_ins.isDetached())"); + _mainPS.printLeftBracket(); + + /* begin of profiling: start event */ + _mainPS.printPrefixln("#ifdef INCLUDE_PROFILER"); + _mainPS.printPrefixln("if (profiler_output_file != NULL) fprintf(profiler_output_file, \"%u "+ x.getName() + " started.\\n\", profiler_event_counter++);"); + _mainPS.printPrefixln("#endif"); + /* end of profiling */ + + _mainPS.printPrefixln(x.getName() + "_ins.fire();"); + + /* begin of profiling: stop event */ + _mainPS.printPrefixln("#ifdef INCLUDE_PROFILER"); + _mainPS.printPrefixln("if (profiler_output_file != NULL) fprintf(profiler_output_file, \"%u "+ x.getName() + " stopped.\\n\", profiler_event_counter++);"); + _mainPS.printPrefixln("#endif"); + /* end of profiling */ + + _mainPS.printPrefixln("eventList.push_back(&" + x.getName() + + "_event);"); + _mainPS.printPrefixln("sched_event.notify(SC_ZERO_TIME);"); + _mainPS.printPrefixln("wait(" + x.getName() + "_event);"); + + _mainPS.printRightBracket(); + _mainPS.printRightBracket(); + } + + /** + * Generates the process network. This is the channel content + * in the model constructor. + * @param x channel that needs to be rendered + */ + public void visitComponent(Channel x) { + for (Port p : x.getPortList()) { + Port peerPort = (Port)(p.getPeerPort()); + Resource peerResource = p.getPeerResource(); + + if (!_processor.hasProcess(peerResource.getName())) + continue; + + if (peerPort.getRange() != null) { + if (p.isOutPort()) { + _mainPS.printPrefixln(peerResource.getName() + + "_ins.INPORT_" + + peerPort.getBasename() + + peerPort.getName().replace( + peerPort.getBasename(), "").replaceAll( + "_([0-9]+)", "[$1]") + "(" + x.getName() + + "_ins);"); + } + else if (p.isInPort()) { + _mainPS.printPrefixln(peerResource.getName() + + "_ins.OUTPORT_" + + peerPort.getBasename() + + peerPort.getName().replace( + peerPort.getBasename(), "").replaceAll( + "_([0-9]+)", "[$1]") + "(" + x.getName() + + "_ins);"); + } + } + else { + if (p.isOutPort()) { + _mainPS.printPrefixln(peerResource.getName() + + "_ins.INPORT_" + peerPort.getName() + + "(" + x.getName() + "_ins);"); + } + else if (p.isInPort()) { + _mainPS.printPrefixln(peerResource.getName() + + "_ins.OUTPORT_" + peerPort.getName() + + "(" + x.getName() + "_ins);"); + } + } + } + } + + protected CodePrintStream _mainPS = null; + protected String _dir = null; + protected Mapping _map = null; + protected Processor _processor = null; +}