diff --git a/src/main/java/avatartranslator/AvatarBlockTemplate.java b/src/main/java/avatartranslator/AvatarBlockTemplate.java index 8cc9904e5bb90eda8724c1ba5dfc62cd5ddd1cd9..1f043ce784aedfadd46bccb792381cce04f86d71 100644 --- a/src/main/java/avatartranslator/AvatarBlockTemplate.java +++ b/src/main/java/avatartranslator/AvatarBlockTemplate.java @@ -37,21 +37,21 @@ */ - - - package avatartranslator; import myutil.TraceManager; +import java.util.Vector; + /** * Class AvatarBlockTemplate * Templates of AVATAR blocks (Timers, etc.) * Creation: 09/07/2010 - * @version 1.0 09/07/2010 + * * @author Ludovic APVRILLE + * @version 2.0 14/11/2019 */ -public class AvatarBlockTemplate { +public class AvatarBlockTemplate { public AvatarBlockTemplate() { } @@ -69,7 +69,7 @@ public class AvatarBlockTemplate { AvatarSignal set = new AvatarSignal("set", AvatarSignal.IN, _referenceBlock); AvatarSignal reset = new AvatarSignal("reset", AvatarSignal.IN, _referenceBlock); AvatarSignal expire = new AvatarSignal("expire", AvatarSignal.OUT, _referenceBlock); - + AvatarAttribute val = new AvatarAttribute("value", AvatarType.INTEGER, ab, aa.getReferenceObject()); set.addParameter(val); ab.addSignal(set); @@ -143,172 +143,207 @@ public class AvatarBlockTemplate { return at; } - + // WARNING: Does not handle the non blocking case public static AvatarBlock getFifoBlock(String _name, AvatarSpecification _avspec, AvatarRelation _ar, Object _referenceRelation, AvatarSignal _sig1, AvatarSignal _sig2, int _sizeOfFifo, int FIFO_ID) { AvatarBlock ab = new AvatarBlock(_name, _avspec, _referenceRelation); - // Create the read and write signals - AvatarSignal write = new AvatarSignal("write", AvatarSignal.IN, _referenceRelation); - AvatarSignal read = new AvatarSignal("read", AvatarSignal.OUT, _referenceRelation); - - ab.addSignal(write); // corresponds to sig1 - ab.addSignal(read); // corresponds to sig2 - - - // Creating the attributes of the signals - // Same attributes for all signals - for(AvatarAttribute aa: _sig1.getListOfAttributes()) { - write.addParameter(aa.advancedClone(null)); - } - for(AvatarAttribute aa: _sig2.getListOfAttributes()) { - read.addParameter(aa.advancedClone(null)); - } - - - // Creating the attributes to support the FIFO - // For each parameter, we create an attribute that is similar to the one of e.g. sig1 - // We duplicate this for the size of the fifo - for(AvatarAttribute aa: _sig1.getListOfAttributes()) { - for(int i=0; i<_sizeOfFifo; i++) { - AvatarAttribute newA = aa.advancedClone(null); - newA.setName("arg__" + aa.getName() + "__" + i); - ab.addAttribute(newA); - } - } - - // If lossy, add corresponding lossy attributes - if (_ar.isLossy()) { - for(AvatarAttribute aa: _sig1.getListOfAttributes()) { - AvatarAttribute newL = aa.advancedClone(null); - newL.setName("loss__" + aa.getName()); - ab.addAttribute(newL); - } - } - - // If non blocking, then, we need extra attributes - if (!(_ar.isBlocking())) { - for(AvatarAttribute aa: _sig1.getListOfAttributes()) { - AvatarAttribute newL = aa.advancedClone(null); - newL.setName("bucket__" + aa.getName()); - ab.addAttribute(newL); - } - } - - // We create the attribute to manage the FIFO - AvatarAttribute size = new AvatarAttribute("size", AvatarType.INTEGER, ab, _referenceRelation); - size.setInitialValue("0"); - ab.addAttribute(size); - - AvatarAttribute maxSize = new AvatarAttribute("maxSize", AvatarType.INTEGER, ab, _referenceRelation); - TraceManager.addDev("*********************************** Size of FIFO=" + _sizeOfFifo); - maxSize.setInitialValue("" + _sizeOfFifo); - ab.addAttribute(maxSize); - - // Where we write: the head - AvatarAttribute head = new AvatarAttribute("head", AvatarType.INTEGER, ab, _referenceRelation); - head.setInitialValue("0"); - ab.addAttribute(head); - - // Where we read: the tail - AvatarAttribute tail = new AvatarAttribute("tail", AvatarType.INTEGER, ab, _referenceRelation); - tail.setInitialValue("0"); - ab.addAttribute(tail); - - - // Creating the state machine - // Don't forget the isLossy - - AvatarTransition at; - AvatarStateMachine asm = ab.getStateMachine(); - - // Start state + // Create the read and write signals + AvatarSignal write = new AvatarSignal("write", AvatarSignal.IN, _referenceRelation); + AvatarSignal read = new AvatarSignal("read", AvatarSignal.OUT, _referenceRelation); + + ab.addSignal(write); // corresponds to sig1 + ab.addSignal(read); // corresponds to sig2 + + + // Creating the attributes of the signals + // Same attributes for all signals + for (AvatarAttribute aa : _sig1.getListOfAttributes()) { + write.addParameter(aa.advancedClone(null)); + } + for (AvatarAttribute aa : _sig2.getListOfAttributes()) { + read.addParameter(aa.advancedClone(null)); + } + + + // Creating the attributes to support the FIFO + // For each parameter, we create an attribute that is similar to the one of e.g. sig1 + // We duplicate this for the size of the fifo + for (AvatarAttribute aa : _sig1.getListOfAttributes()) { + for (int i = 0; i < _sizeOfFifo; i++) { + AvatarAttribute newA = aa.advancedClone(null); + newA.setName("arg__" + aa.getName() + "__" + i); + ab.addAttribute(newA); + } + } + + // If lossy, add corresponding lossy attributes + if (_ar.isLossy()) { + for (AvatarAttribute aa : _sig1.getListOfAttributes()) { + AvatarAttribute newL = aa.advancedClone(null); + newL.setName("loss__" + aa.getName()); + ab.addAttribute(newL); + } + } + + // If non blocking, then, we need extra attributes + if (!(_ar.isBlocking())) { + for (AvatarAttribute aa : _sig1.getListOfAttributes()) { + AvatarAttribute newL = aa.advancedClone(null); + newL.setName("bucket__" + aa.getName()); + ab.addAttribute(newL); + } + } + + // We create the attribute to manage the FIFO + AvatarAttribute size = new AvatarAttribute("size", AvatarType.INTEGER, ab, _referenceRelation); + size.setInitialValue("0"); + ab.addAttribute(size); + + AvatarAttribute maxSize = new AvatarAttribute("maxSize", AvatarType.INTEGER, ab, _referenceRelation); + TraceManager.addDev("*********************************** Size of FIFO=" + _sizeOfFifo); + maxSize.setInitialValue("" + _sizeOfFifo); + ab.addAttribute(maxSize); + + // Where we write: the head + AvatarAttribute head = new AvatarAttribute("head", AvatarType.INTEGER, ab, _referenceRelation); + head.setInitialValue("0"); + ab.addAttribute(head); + + // Where we read: the tail + AvatarAttribute tail = new AvatarAttribute("tail", AvatarType.INTEGER, ab, _referenceRelation); + tail.setInitialValue("0"); + ab.addAttribute(tail); + + + // Creating the state machine + // Don't forget the isLossy + + AvatarTransition at; + AvatarStateMachine asm = ab.getStateMachine(); + + // Start state AvatarStartState ass = new AvatarStartState("start", _referenceRelation); - asm.setStartState(ass); + asm.setStartState(ass); asm.addElement(ass); - // Main state: Wait4Request - AvatarState main = new AvatarState("Wait4Request", _referenceRelation); + // Main state: Wait4Request + AvatarState main = new AvatarState("Wait4Request", _referenceRelation); asm.addElement(main); - at = makeAvatarEmptyTransitionBetween(ab, asm, ass, main, _referenceRelation); + at = makeAvatarEmptyTransitionBetween(ab, asm, ass, main, _referenceRelation); - // Can write only if fifo is not full only if transition - AvatarState testHead = new AvatarState("testHead", _referenceRelation); + // Can write only if fifo is not full only if transition + AvatarState testHead = new AvatarState("testHead", _referenceRelation); asm.addElement(testHead); - at = makeAvatarEmptyTransitionBetween(ab, asm, testHead, main, _referenceRelation); - at.setGuard("[head<maxSize]"); - at = makeAvatarEmptyTransitionBetween(ab, asm, testHead, main, _referenceRelation); - at.setGuard("[head==maxSize]"); - at.addAction("head=0"); - - for(int i=0; i<_sizeOfFifo; i++) { - AvatarActionOnSignal aaos_write = new AvatarActionOnSignal("write__" + i, write, _referenceRelation); - for(AvatarAttribute aa: _sig1.getListOfAttributes()) { - aaos_write.addValue("arg__" + aa.getName() + "__" + i); - } - asm.addElement(aaos_write); - at = makeAvatarEmptyTransitionBetween(ab, asm, main, aaos_write, _referenceRelation); - at.setGuard("[(size < maxSize) && (head==" + i + ")]"); - at = makeAvatarEmptyTransitionBetween(ab, asm, aaos_write, testHead, _referenceRelation); - at.addAction("head = head + 1"); - at.addAction("size = size + 1"); - - } - // if is lossy, can write, and does not store this nor increase the fifo size - if (_ar.isLossy()) { - AvatarActionOnSignal aaos_write_loss = new AvatarActionOnSignal("writeloss__", write, _referenceRelation); - for(AvatarAttribute aa: _sig1.getListOfAttributes()) { - aaos_write_loss.addValue("loss__" + aa.getName()); - } - asm.addElement(aaos_write_loss); - at = makeAvatarEmptyTransitionBetween(ab, asm, main, aaos_write_loss, _referenceRelation); - at.setGuard("[(size < maxSize)]"); - at = makeAvatarEmptyTransitionBetween(ab, asm, aaos_write_loss, main, _referenceRelation); - } - - // If it is blocking, then, the new message is written but not added - if (!(_ar.isBlocking())) { - AvatarActionOnSignal aaos_write_bucket = new AvatarActionOnSignal("writebucket__", write, _referenceRelation); - for(AvatarAttribute aa: _sig1.getListOfAttributes()) { - aaos_write_bucket.addValue("bucket__" + aa.getName()); - } - asm.addElement(aaos_write_bucket); - at = makeAvatarEmptyTransitionBetween(ab, asm, main, aaos_write_bucket, _referenceRelation); - at.setGuard("[(size == maxSize)]"); - at = makeAvatarEmptyTransitionBetween(ab, asm, aaos_write_bucket, main, _referenceRelation); - } - - // Read - AvatarState testTail = new AvatarState("testTail", _referenceRelation); + at = makeAvatarEmptyTransitionBetween(ab, asm, testHead, main, _referenceRelation); + at.setGuard("[head<maxSize]"); + at = makeAvatarEmptyTransitionBetween(ab, asm, testHead, main, _referenceRelation); + at.setGuard("[head==maxSize]"); + at.addAction("head=0"); + + for (int i = 0; i < _sizeOfFifo; i++) { + AvatarActionOnSignal aaos_write = new AvatarActionOnSignal("write__" + i, write, _referenceRelation); + for (AvatarAttribute aa : _sig1.getListOfAttributes()) { + aaos_write.addValue("arg__" + aa.getName() + "__" + i); + } + asm.addElement(aaos_write); + at = makeAvatarEmptyTransitionBetween(ab, asm, main, aaos_write, _referenceRelation); + at.setGuard("[(size < maxSize) && (head==" + i + ")]"); + at = makeAvatarEmptyTransitionBetween(ab, asm, aaos_write, testHead, _referenceRelation); + at.addAction("head = head + 1"); + at.addAction("size = size + 1"); + + } + // if is lossy, can write, and does not store this nor increase the fifo size + if (_ar.isLossy()) { + AvatarActionOnSignal aaos_write_loss = new AvatarActionOnSignal("writeloss__", write, _referenceRelation); + for (AvatarAttribute aa : _sig1.getListOfAttributes()) { + aaos_write_loss.addValue("loss__" + aa.getName()); + } + asm.addElement(aaos_write_loss); + at = makeAvatarEmptyTransitionBetween(ab, asm, main, aaos_write_loss, _referenceRelation); + at.setGuard("[(size < maxSize)]"); + at = makeAvatarEmptyTransitionBetween(ab, asm, aaos_write_loss, main, _referenceRelation); + } + + // If it is blocking, then, the new message is written but not added + if (!(_ar.isBlocking())) { + AvatarActionOnSignal aaos_write_bucket = new AvatarActionOnSignal("writebucket__", write, _referenceRelation); + for (AvatarAttribute aa : _sig1.getListOfAttributes()) { + aaos_write_bucket.addValue("bucket__" + aa.getName()); + } + asm.addElement(aaos_write_bucket); + at = makeAvatarEmptyTransitionBetween(ab, asm, main, aaos_write_bucket, _referenceRelation); + at.setGuard("[(size == maxSize)]"); + at = makeAvatarEmptyTransitionBetween(ab, asm, aaos_write_bucket, main, _referenceRelation); + } + + // Read + AvatarState testTail = new AvatarState("testTail", _referenceRelation); asm.addElement(testTail); - at = makeAvatarEmptyTransitionBetween(ab, asm, testTail, main, _referenceRelation); - at.setGuard("[tail<maxSize]"); - at = makeAvatarEmptyTransitionBetween(ab, asm, testTail, main, _referenceRelation); - at.setGuard("[tail==maxSize]"); - at.addAction("tail=0"); - for(int i=0; i<_sizeOfFifo; i++) { - AvatarActionOnSignal aaos_read = new AvatarActionOnSignal("read__" + i, read, _referenceRelation); - for(AvatarAttribute aa: _sig1.getListOfAttributes()) { - aaos_read.addValue("arg__" + aa.getName() + "__" + i); - } - asm.addElement(aaos_read); - at = makeAvatarEmptyTransitionBetween(ab, asm, main, aaos_read, _referenceRelation); - at.setGuard("[(size > 0) && (tail==" + i + ")]"); - at = makeAvatarEmptyTransitionBetween(ab, asm, aaos_read, testTail, _referenceRelation); - at.addAction("tail = tail + 1"); - at.addAction("size = size - 1"); - } - - - - // Block is finished! - - return ab; + at = makeAvatarEmptyTransitionBetween(ab, asm, testTail, main, _referenceRelation); + at.setGuard("[tail<maxSize]"); + at = makeAvatarEmptyTransitionBetween(ab, asm, testTail, main, _referenceRelation); + at.setGuard("[tail==maxSize]"); + at.addAction("tail=0"); + for (int i = 0; i < _sizeOfFifo; i++) { + AvatarActionOnSignal aaos_read = new AvatarActionOnSignal("read__" + i, read, _referenceRelation); + for (AvatarAttribute aa : _sig1.getListOfAttributes()) { + aaos_read.addValue("arg__" + aa.getName() + "__" + i); + } + asm.addElement(aaos_read); + at = makeAvatarEmptyTransitionBetween(ab, asm, main, aaos_read, _referenceRelation); + at.setGuard("[(size > 0) && (tail==" + i + ")]"); + at = makeAvatarEmptyTransitionBetween(ab, asm, aaos_read, testTail, _referenceRelation); + at.addAction("tail = tail + 1"); + at.addAction("size = size - 1"); + } + + + // Block is finished! + + return ab; + } + + + public static AvatarBlock getSWGraphBlock(String _name, AvatarSpecification _avspec, Object _referenceBlock, + int duration, Vector<String> unblocks, Vector<String> blocks) { + + AvatarBlock ab = new AvatarBlock(_name, _avspec, _referenceBlock); + + // Create signals + AvatarSignal selectP = new AvatarSignal("selectP", AvatarSignal.IN, _referenceBlock); + AvatarSignal stepP = new AvatarSignal("stepP", AvatarSignal.IN, _referenceBlock); + AvatarAttribute att1 = new AvatarAttribute("step", AvatarType.INTEGER, ab, _referenceBlock); + stepP.addParameter(att1); + AvatarSignal preemptP = new AvatarSignal("preemptP", AvatarSignal.IN, _referenceBlock); + AvatarSignal finishP = new AvatarSignal("finishP", AvatarSignal.OUT, _referenceBlock); + + ab.addSignal(selectP); + ab.addSignal(stepP); + ab.addSignal(preemptP); + ab.addSignal(finishP); + + // block / unblock signals + + //for(int) + + + // Create attributes + AvatarAttribute durationAtt = new AvatarAttribute("duration", AvatarType.INTEGER, ab, _referenceBlock); + durationAtt.setInitialValue(""+duration); + ab.addAttribute(durationAtt); + + AvatarAttribute stepAtt = new AvatarAttribute("step", AvatarType.INTEGER, ab, _referenceBlock); + ab.addAttribute(stepAtt); + + // State machines + + + + return ab; } - - - } diff --git a/src/main/java/tmltranslator/schedulegraph/SWTask.java b/src/main/java/tmltranslator/schedulegraph/SWTask.java deleted file mode 100644 index 27304abd4e9d5c6fa524cfbbc443e6e95c887391..0000000000000000000000000000000000000000 --- a/src/main/java/tmltranslator/schedulegraph/SWTask.java +++ /dev/null @@ -1,183 +0,0 @@ - -/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille - * - * ludovic.apvrille AT enst.fr - * - * This software is a computer program whose purpose is to allow the - * edition of TURTLE analysis, design and deployment diagrams, to - * allow the generation of RT-LOTOS or Java code from this diagram, - * and at last to allow the analysis of formal validation traces - * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP - * from INRIA Rhone-Alpes. - * - * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, - * modify and/ or redistribute the software under the terms of the CeCILL - * license as circulated by CEA, CNRS and INRIA at the following URL - * "http://www.cecill.info". - * - * As a counterpart to the access to the source code and rights to copy, - * modify and redistribute granted by the license, users are provided only - * with a limited warranty and the software's author, the holder of the - * economic rights, and the successive licensors have only limited - * liability. - * - * In this respect, the user's attention is drawn to the risks associated - * with loading, using, modifying and/or developing or reproducing the - * software by the user in light of its specific status of free software, - * that may mean that it is complicated to manipulate, and that also - * therefore means that it is reserved for developers and experienced - * professionals having in-depth computer knowledge. Users are therefore - * encouraged to load and test the software's suitability as regards their - * requirements in conditions enabling the security of their systems and/or - * data to be ensured and, more generally, to use and operate it in the - * same conditions as regards security. - * - * The fact that you are presently reading this means that you have had - * knowledge of the CeCILL license and that you accept its terms. - */ - - -package tmltranslator.schedulegraph; - -import tmltranslator.*; - -import java.util.Vector; - - -/** - * Class SWTask - * Creation: 14/11/2019 - * - * @author Ludovic Apvrille - * @version 1.0 14/11/2019 - */ -public class SWTask extends TMLTask { - private int duration = 10; - - - public SWTask(String name, Object referenceToClass, Object referenceToActivityDiagram) { - super(name, referenceToClass, referenceToActivityDiagram); - } - - public void setDuration(int duration) { - this.duration = duration; - } - - public void generate() { - - TMLSendEvent sendEvt; - TMLWaitEvent waitEvt; - TMLStopState stop; - - // Attributes - TMLAttribute durationAtt = new TMLAttribute("duraction", "duraction", new TMLType(TMLType.NATURAL), "0"); - this.addAttribute(durationAtt); - TMLAttribute dstX = new TMLAttribute("dstX", "dstX", new TMLType(TMLType.NATURAL), "0"); - this.addAttribute(dstX); - TMLAttribute dstY = new TMLAttribute("dstY", "dstY", new TMLType(TMLType.NATURAL), "0"); - this.addAttribute(dstY); - TMLAttribute vc = new TMLAttribute("vc", "vc", new TMLType(TMLType.NATURAL), "0"); - this.addAttribute(vc); - TMLAttribute eop = new TMLAttribute("eop", "eop", new TMLType(TMLType.NATURAL), "0"); - this.addAttribute(eop); - TMLAttribute chid = new TMLAttribute("chid", "chid", new TMLType(TMLType.NATURAL), "0"); - this.addAttribute(chid); - TMLAttribute j = new TMLAttribute("j", "j", new TMLType(TMLType.NATURAL), "0"); - this.addAttribute(j); - - // Events - addTMLEvent(vcSelect); - for(TMLEvent evt: inPacketEvents) { - addTMLEvent(evt); - } - - addTMLEvent(outVCEvent); - for(TMLEvent evt: outFeedbackEvents) { - addTMLEvent(evt); - } - - // Activity Diagram - TMLStartState start = new TMLStartState("mainStart", referenceObject); - activity.setFirst(start); - - // Loop forever - TMLForLoop mainLoop = new TMLForLoop("MainLoop", referenceObject); - mainLoop.setInfinite(true); - activity.addLinkElement(start,mainLoop); - - // Select Event - TMLSelectEvt select = new TMLSelectEvt("selectEvent", referenceObject); - activity.addLinkElement(mainLoop, select); - - // Branch for each input event - for(int i=0; i<inPacketEvents.size(); i++) { - TMLWaitEvent waitPacket = new TMLWaitEvent("WaitForFirstFlit", referenceObject); - waitPacket.setEvent(inPacketEvents.get(i)); - waitPacket.addParam("pktlen"); - waitPacket.addParam("dstX"); - waitPacket.addParam("dstY"); - waitPacket.addParam("vc"); - waitPacket.addParam("eop"); - waitPacket.addParam("chid"); - activity.addLinkElement(select, waitPacket); - - // loop on packet size - TMLForLoop packetLoop = new TMLForLoop("packetLoop", referenceObject); - packetLoop.setInit("j=0"); - packetLoop.setCondition("j<pktlen"); - packetLoop.setIncrement("j=j+1"); - activity.addLinkElement(waitPacket, packetLoop); - - // Inside packetloop - TMLSendEvent sendFlitEvt = new TMLSendEvent("PacketInfo", referenceObject); - sendFlitEvt.setEvent(outVCEvent); - sendFlitEvt.addParam("pktlen"); - sendFlitEvt.addParam("dstX"); - sendFlitEvt.addParam("dstY"); - sendFlitEvt.addParam("vc"); - sendFlitEvt.addParam("eop"); - sendFlitEvt.addParam("chid"); - activity.addLinkElement(packetLoop, sendFlitEvt); - - waitEvt = new TMLWaitEvent("ReturnFromVC", referenceObject); - waitEvt.setEvent(vcSelect); - activity.addLinkElement(sendFlitEvt, waitEvt); - - sendEvt = new TMLSendEvent("Feedback", referenceObject); - sendEvt.setEvent(outFeedbackEvents.get(i)); - activity.addLinkElement(waitEvt, sendEvt); - - TMLChoice choice = new TMLChoice("ChoiceOnEOP", referenceObject); - activity.addLinkElement(sendEvt, choice); - - // Left branch of choice - TMLWaitEvent waitNextFlit = new TMLWaitEvent("WaitForNextFlit", referenceObject); - waitNextFlit.setEvent(inPacketEvents.get(i)); - waitNextFlit.addParam("pktlen"); - waitNextFlit.addParam("dstX"); - waitNextFlit.addParam("dstY"); - waitNextFlit.addParam("vc"); - waitNextFlit.addParam("eop"); - waitNextFlit.addParam("chid"); - activity.addLinkElement(choice, waitNextFlit); - choice.addGuard("eop == 0"); - - TMLStopState stopAfterFlit = new TMLStopState("StopStateLeftChoice", referenceObject); - activity.addLinkElement(waitNextFlit, stopAfterFlit); - - //Right branch of choice - TMLStopState stopEOP = new TMLStopState("StopStateRightChoice", referenceObject); - activity.addLinkElement(choice, stopEOP); - choice.addGuard("eop > 0"); - - // Exit of the loop - stop = new TMLStopState("EndOfPacketLoop", referenceObject); - activity.addLinkElement(packetLoop, stop); - } - - - - } - -}