diff --git a/src/tmltranslator/TMLActivity.java b/src/tmltranslator/TMLActivity.java index e9bb2510d7c1ececc3c9c5f8b60c4749aa491945..1ed6b6a92ca0e66548fa3652da277ea2e88e752b 100755 --- a/src/tmltranslator/TMLActivity.java +++ b/src/tmltranslator/TMLActivity.java @@ -1,47 +1,47 @@ /**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. - -/** - * Class TMLActivity - * Creation: 23/11/2005 - * @version 1.0 23/11/2005 - * @author Ludovic APVRILLE - * @see - */ + 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. + + /** + * Class TMLActivity + * Creation: 23/11/2005 + * @version 1.0 23/11/2005 + * @author Ludovic APVRILLE + * @see + */ package tmltranslator; @@ -53,47 +53,47 @@ import myutil.*; public class TMLActivity extends TMLElement { private TMLActivityElement first; private Vector elements; - - + + public TMLActivity(String name, Object reference) { super(name, reference); elements = new Vector(); } - - public boolean contains(TMLActivityElement _elt) { - return elements.contains(_elt); - } - + + public boolean contains(TMLActivityElement _elt) { + return elements.contains(_elt); + } + public void setFirst(TMLActivityElement _tmlae) { first = _tmlae; addElement(_tmlae); } - + public TMLActivityElement getFirst() { return first; } - + public TMLActivityElement get(int index) { return (TMLActivityElement)(elements.elementAt(index)); } - - public void removeElementAt(int index) { + + public void removeElementAt(int index) { elements.removeElementAt(index); } - - public void removeElement(TMLActivityElement _element) { + + public void removeElement(TMLActivityElement _element) { elements.remove(_element); } - + public int nElements() { return elements.size(); } - + public void addElement(TMLActivityElement _tmlae) { elements.add(_tmlae); } - - + + public TMLActivityElement findReferenceElement(Object reference) { TMLActivityElement ae; for(int i=0; i<elements.size(); i++) { @@ -104,307 +104,329 @@ public class TMLActivity extends TMLElement { } return null; } - - public int getMaximumSelectEvtSize() { - int found = -1; - int next; - TMLActivityElement ae; + + public int getMaximumSelectEvtSize() { + int found = -1; + int next; + TMLActivityElement ae; for(int i=0; i<elements.size(); i++) { ae = (TMLActivityElement)(elements.elementAt(i)); if (ae instanceof TMLSelectEvt) { - next = ae.getNbNext(); + next = ae.getNbNext(); if (next>found) { - found = next; - } + found = next; + } } } return found; - } - - private void replaceAllNext(TMLActivityElement _oldE, TMLActivityElement _newE) { - TMLActivityElement tmlae; - for(int i=0; i<elements.size(); i++) { - tmlae = (TMLActivityElement)(elements.elementAt(i)); - tmlae.setNewNext(_oldE, _newE); - } - } - - private TMLRandomSequence findTMLRandomSequence() { - TMLActivityElement tmlae; - for(int i=0; i<elements.size(); i++) { - tmlae = (TMLActivityElement)(elements.elementAt(i)); - if (tmlae instanceof TMLRandomSequence) { - return (TMLRandomSequence)tmlae; - } - } - - return null; - } - - public void removeAllRandomSequences(TMLTask _task) { - int idRandomSequence = 0; - TMLRandomSequence tmlrs = findTMLRandomSequence(); - - while(tmlrs != null) { - replaceRandomSequence(_task, tmlrs, idRandomSequence); - idRandomSequence ++; - tmlrs = findTMLRandomSequence(); - } - } - - private void replaceRandomSequence(TMLTask _task, TMLRandomSequence _tmlrs, int _idRandomSequence) { - int nnext = _tmlrs.getNbNext(); - int i; - - if (nnext == 0) { - TMLStopState adstop = new TMLStopState("stop", _tmlrs.getReferenceObject()); - addElement(adstop); - removeElement(_tmlrs); - replaceAllNext(_tmlrs, adstop); - return; - } - - // At least one next! - if (nnext == 1) { - TMLActivityElement tmlae = _tmlrs.getNextElement(0); - removeElement(_tmlrs); - replaceAllNext(_tmlrs, tmlae); - return; - } - - // At least two nexts -> use of a loop combined with a choice - String name; - TMLChoice choice = new TMLChoice("choice for random sequence", _tmlrs.getReferenceObject()); - elements.addElement(choice); - - TMLForLoop loop = new TMLForLoop("loop for random sequence", _tmlrs.getReferenceObject()); - elements.addElement(loop); - name = "looprd__" + _idRandomSequence; - TMLAttribute loopAttribute = new TMLAttribute(name, name, new TMLType(TMLType.NATURAL), "0"); - _task.addAttribute(loopAttribute); - loop.setInit(name + "=0"); - loop.setCondition(name + " < " + nnext); - loop.setIncrement(name + " = " + name + " + 1"); - - TMLStopState tmlstop = new TMLStopState("stop", _tmlrs.getReferenceObject()); - addElement(tmlstop); - - TMLActionState [] tmlactions = new TMLActionState[nnext]; - TMLActionState tmlaction; - TMLAttribute[] attributes = new TMLAttribute[nnext]; - - - for(i=0; i<nnext; i++) { - name = "rd__" + _idRandomSequence + "__" + i; - attributes[i] = new TMLAttribute(name, name, new TMLType(TMLType.BOOLEAN), "false"); - _task.addAttribute(attributes[i]); - - tmlactions[i] = new TMLActionState("Setting random sequence", _tmlrs.getReferenceObject()); - elements.add(tmlactions[i]); - tmlactions[i].setAction(name + " = false"); - - tmlaction = new TMLActionState("Setting random sequence", _tmlrs.getReferenceObject()); - elements.add(tmlaction); - tmlaction.setAction(name + " = true"); - tmlaction.addNext(_tmlrs.getNextElement(i)); - - choice.addNext(tmlaction); - choice.addGuard("[not(" + name + ")]"); - - if (i!=0) { - tmlactions[i-1].addNext(tmlactions[i]); - } - } - - replaceAllNext(_tmlrs, tmlactions[0]); - tmlactions[nnext-1].addNext(loop); - loop.addNext(choice); - loop.addNext(tmlstop); - removeElement(_tmlrs); - } - - public void splitActionStatesWithUnderscoreVariables(TMLTask _task) { - //TraceManager.addDev("Splitting actions in task " + _task.getName()); - - TMLActivityElement ae; - Vector<TMLActionState> states = new Vector<TMLActionState>(); + } + + private void replaceAllNext(TMLActivityElement _oldE, TMLActivityElement _newE) { + TMLActivityElement tmlae; + for(int i=0; i<elements.size(); i++) { + tmlae = (TMLActivityElement)(elements.elementAt(i)); + tmlae.setNewNext(_oldE, _newE); + } + } + + private TMLRandomSequence findTMLRandomSequence() { + TMLActivityElement tmlae; + for(int i=0; i<elements.size(); i++) { + tmlae = (TMLActivityElement)(elements.elementAt(i)); + if (tmlae instanceof TMLRandomSequence) { + return (TMLRandomSequence)tmlae; + } + } + + return null; + } + + public void removeAllRandomSequences(TMLTask _task) { + int idRandomSequence = 0; + TMLRandomSequence tmlrs = findTMLRandomSequence(); + + while(tmlrs != null) { + replaceRandomSequence(_task, tmlrs, idRandomSequence); + idRandomSequence ++; + tmlrs = findTMLRandomSequence(); + } + } + + private void replaceRandomSequence(TMLTask _task, TMLRandomSequence _tmlrs, int _idRandomSequence) { + int nnext = _tmlrs.getNbNext(); + int i; + + if (nnext == 0) { + TMLStopState adstop = new TMLStopState("stop", _tmlrs.getReferenceObject()); + addElement(adstop); + removeElement(_tmlrs); + replaceAllNext(_tmlrs, adstop); + return; + } + + // At least one next! + if (nnext == 1) { + TMLActivityElement tmlae = _tmlrs.getNextElement(0); + removeElement(_tmlrs); + replaceAllNext(_tmlrs, tmlae); + return; + } + + // At least two nexts -> use of a loop combined with a choice + String name; + TMLChoice choice = new TMLChoice("choice for random sequence", _tmlrs.getReferenceObject()); + elements.addElement(choice); + + TMLForLoop loop = new TMLForLoop("loop for random sequence", _tmlrs.getReferenceObject()); + elements.addElement(loop); + name = "looprd__" + _idRandomSequence; + TMLAttribute loopAttribute = new TMLAttribute(name, name, new TMLType(TMLType.NATURAL), "0"); + _task.addAttribute(loopAttribute); + loop.setInit(name + "=0"); + loop.setCondition(name + " < " + nnext); + loop.setIncrement(name + " = " + name + " + 1"); + + TMLStopState tmlstop = new TMLStopState("stop", _tmlrs.getReferenceObject()); + addElement(tmlstop); + + TMLActionState [] tmlactions = new TMLActionState[nnext]; + TMLActionState tmlaction; + TMLAttribute[] attributes = new TMLAttribute[nnext]; + + + for(i=0; i<nnext; i++) { + name = "rd__" + _idRandomSequence + "__" + i; + attributes[i] = new TMLAttribute(name, name, new TMLType(TMLType.BOOLEAN), "false"); + _task.addAttribute(attributes[i]); + + tmlactions[i] = new TMLActionState("Setting random sequence", _tmlrs.getReferenceObject()); + elements.add(tmlactions[i]); + tmlactions[i].setAction(name + " = false"); + + tmlaction = new TMLActionState("Setting random sequence", _tmlrs.getReferenceObject()); + elements.add(tmlaction); + tmlaction.setAction(name + " = true"); + tmlaction.addNext(_tmlrs.getNextElement(i)); + + choice.addNext(tmlaction); + choice.addGuard("[not(" + name + ")]"); + + if (i!=0) { + tmlactions[i-1].addNext(tmlactions[i]); + } + } + + replaceAllNext(_tmlrs, tmlactions[0]); + tmlactions[nnext-1].addNext(loop); + loop.addNext(choice); + loop.addNext(tmlstop); + removeElement(_tmlrs); + } + + public void splitActionStatesWithUnderscoreVariables(TMLTask _task) { + //TraceManager.addDev("Splitting actions in task " + _task.getName()); + + TMLActivityElement ae; + Vector<TMLActionState> states = new Vector<TMLActionState>(); for(int i=0; i<elements.size(); i++) { ae = (TMLActivityElement)(elements.elementAt(i)); if (ae instanceof TMLActionState) { - states.add((TMLActionState)ae); + states.add((TMLActionState)ae); } } - - for(TMLActionState as: states) { - splitActionStatesWithUnderscoreVariables(as, _task); - } - - } - - private void splitActionStatesWithUnderscoreVariables(TMLActionState _ae, TMLTask _task) { - // Is ae if the form name0 = name1 with variables in the task of type name0__ and name1__ ? - String s = _ae.getAction(); - - if (s == null) { - return; - } - - //TraceManager.addDev("Analyzing action to split : " + s); - - s = s.trim(); - - if (s.length() == 0) { - return; - } - - int index0 = s.indexOf('='); - if (index0 == -1) { - return; - } - - String name0 = s.substring(0, index0).trim(); - String name1 = s.substring(index0+1, s.length()).trim(); - - //TraceManager.addDev("name0=" + name0 + " name1=" + name1); - - if (!TMLTextSpecification.isAValidId(name0)) { - return; - } - - if (!TMLTextSpecification.isAValidId(name1)) { - return; - } - - Vector<TMLAttribute> v0 = _task.getAllTMLAttributesStartingWith(name0 + "__"); - Vector<TMLAttribute> v1 = _task.getAllTMLAttributesStartingWith(name1 + "__"); - - //TraceManager.addDev("size"); - - if ((v0.size() == 0) || (v0.size() != v1.size())) { - return; - } - - //TraceManager.addDev("Analyzing types"); - for(int i=0; i<v0.size(); i++) { - if (v0.get(i).getType() == v1.get(i).getType()) { - return; - } - } - - //TraceManager.addDev("Found action to split : " + s); - - TMLActionState previous, tmlas; - TMLActivityElement tmlae = _ae.getNextElement(0); - - _ae.setAction(v0.get(0).getName() + " = " + v1.get(0).getName()); - - if (v0.size() == 1) { - return; - } - - _ae.clearNexts(); - previous = _ae; - - for(int i=1; i<v0.size(); i++) { - tmlas = new TMLActionState(previous.getName(), previous.getReferenceObject()); - tmlas.setAction(v0.get(i).getName() + " = " + v1.get(i).getName()); - elements.add(tmlas); - previous.addNext(tmlas); - previous = tmlas; - } - - previous.addNext(tmlae); - - } - - public void splitActionStatesWithDollars(TMLTask _task) { - //TraceManager.addDev("Splitting actions in task " + _task.getName()); - - TMLActivityElement ae; - Vector<TMLActionState> states = new Vector<TMLActionState>(); + + for(TMLActionState as: states) { + splitActionStatesWithUnderscoreVariables(as, _task); + } + + } + + private void splitActionStatesWithUnderscoreVariables(TMLActionState _ae, TMLTask _task) { + // Is ae if the form name0 = name1 with variables in the task of type name0__ and name1__ ? + String s = _ae.getAction(); + + if (s == null) { + return; + } + + //TraceManager.addDev("Analyzing action to split : " + s); + + s = s.trim(); + + if (s.length() == 0) { + return; + } + + int index0 = s.indexOf('='); + if (index0 == -1) { + return; + } + + String name0 = s.substring(0, index0).trim(); + String name1 = s.substring(index0+1, s.length()).trim(); + + //TraceManager.addDev("name0=" + name0 + " name1=" + name1); + + if (!TMLTextSpecification.isAValidId(name0)) { + return; + } + + if (!TMLTextSpecification.isAValidId(name1)) { + return; + } + + Vector<TMLAttribute> v0 = _task.getAllTMLAttributesStartingWith(name0 + "__"); + Vector<TMLAttribute> v1 = _task.getAllTMLAttributesStartingWith(name1 + "__"); + + //TraceManager.addDev("size"); + + if ((v0.size() == 0) || (v0.size() != v1.size())) { + return; + } + + //TraceManager.addDev("Analyzing types"); + for(int i=0; i<v0.size(); i++) { + if (v0.get(i).getType() == v1.get(i).getType()) { + return; + } + } + + //TraceManager.addDev("Found action to split : " + s); + + TMLActionState previous, tmlas; + TMLActivityElement tmlae = _ae.getNextElement(0); + + _ae.setAction(v0.get(0).getName() + " = " + v1.get(0).getName()); + + if (v0.size() == 1) { + return; + } + + _ae.clearNexts(); + previous = _ae; + + for(int i=1; i<v0.size(); i++) { + tmlas = new TMLActionState(previous.getName(), previous.getReferenceObject()); + tmlas.setAction(v0.get(i).getName() + " = " + v1.get(i).getName()); + elements.add(tmlas); + previous.addNext(tmlas); + previous = tmlas; + } + + previous.addNext(tmlae); + + } + + public void splitActionStatesWithDollars(TMLTask _task) { + //TraceManager.addDev("Splitting actions in task " + _task.getName()); + + TMLActivityElement ae; + Vector<TMLActionState> states = new Vector<TMLActionState>(); for(int i=0; i<elements.size(); i++) { ae = (TMLActivityElement)(elements.elementAt(i)); if (ae instanceof TMLActionState) { - states.add((TMLActionState)ae); + states.add((TMLActionState)ae); } } - - for(TMLActionState as: states) { - splitActionStatesWithDollars(as, _task); - } - - } - - private void splitActionStatesWithDollars(TMLActionState _ae, TMLTask _task) { - // Is ae if the form name0 = name1 with variables in the task of type name0__ and name1__ ? - String s = _ae.getAction(); - - if (s == null) { - return; - } - - //TraceManager.addDev("Analyzing action to split : " + s); - - s = s.trim(); - - if (s.length() == 0) { - return; - } - - int index0 = s.indexOf('$'); - if (index0 == -1) { - return; - } - - String name0 = s.substring(0, index0).trim(); - String name1 = s.substring(index0+1, s.length()).trim(); - - if ((name0.length() ==0) || (name1.length() == 0)) { - _ae.setAction(Conversion.replaceAllString(_ae.getAction(), "$", " ").trim()); - return; - } - - //TraceManager.addDev("Found action to split : " + s); - - TMLActionState previous, tmlas; - TMLActivityElement tmlae = _ae.getNextElement(0); - - TraceManager.addDev("Setting action0 to " + name0); - _ae.setAction(name0); - _ae.clearNexts(); - previous = _ae; - - tmlas = new TMLActionState(previous.getName(), previous.getReferenceObject()); - tmlas.setAction(name1); - TraceManager.addDev("Setting action1 to " + name1); - elements.add(tmlas); - previous.addNext(tmlas); - previous = tmlas; - previous.addNext(tmlae); - - splitActionStatesWithDollars(tmlas, _task); - - } - - public int computeMaxID() { - int max = -1; - TMLActivityElement ae; - for(int i=0; i<elements.size(); i++) { + + for(TMLActionState as: states) { + splitActionStatesWithDollars(as, _task); + } + + } + + private void splitActionStatesWithDollars(TMLActionState _ae, TMLTask _task) { + // Is ae if the form name0 = name1 with variables in the task of type name0__ and name1__ ? + String s = _ae.getAction(); + + if (s == null) { + return; + } + + //TraceManager.addDev("Analyzing action to split : " + s); + + s = s.trim(); + + if (s.length() == 0) { + return; + } + + int index0 = s.indexOf('$'); + if (index0 == -1) { + return; + } + + String name0 = s.substring(0, index0).trim(); + String name1 = s.substring(index0+1, s.length()).trim(); + + if ((name0.length() ==0) || (name1.length() == 0)) { + _ae.setAction(Conversion.replaceAllString(_ae.getAction(), "$", " ").trim()); + return; + } + + //TraceManager.addDev("Found action to split : " + s); + + TMLActionState previous, tmlas; + TMLActivityElement tmlae = _ae.getNextElement(0); + + TraceManager.addDev("Setting action0 to " + name0); + _ae.setAction(name0); + _ae.clearNexts(); + previous = _ae; + + tmlas = new TMLActionState(previous.getName(), previous.getReferenceObject()); + tmlas.setAction(name1); + TraceManager.addDev("Setting action1 to " + name1); + elements.add(tmlas); + previous.addNext(tmlas); + previous = tmlas; + previous.addNext(tmlae); + + splitActionStatesWithDollars(tmlas, _task); + + } + + public int computeMaxID() { + int max = -1; + TMLActivityElement ae; + for(int i=0; i<elements.size(); i++) { ae = (TMLActivityElement)(elements.elementAt(i)); - max = Math.max(max, ae.getID()); + max = Math.max(max, ae.getID()); } - return max; - } - - public void computeCorrespondance(TMLElement [] _correspondance) { - _correspondance[getID()] = this; - TMLActivityElement ae; - for(int i=0; i<elements.size(); i++) { + return max; + } + + public void computeCorrespondance(TMLElement [] _correspondance) { + _correspondance[getID()] = this; + TMLActivityElement ae; + for(int i=0; i<elements.size(); i++) { + ae = (TMLActivityElement)(elements.elementAt(i)); + _correspondance[ae.getID()] = ae; + } + + } + + public void replaceReadChannelWith(TMLChannel oldChan, TMLChannel newChan) { + TMLActivityElement ae; + + for(int i=0; i<elements.size(); i++) { ae = (TMLActivityElement)(elements.elementAt(i)); - _correspondance[ae.getID()] = ae; + if (ae instanceof TMLReadChannel) { + ((TMLReadChannel)ae).replaceChannelWith(oldChan, newChan); + } } - - } - - -} \ No newline at end of file + } + + public void replaceWriteChannelWith(TMLChannel oldChan, TMLChannel newChan) { + TMLActivityElement ae; + + for(int i=0; i<elements.size(); i++) { + ae = (TMLActivityElement)(elements.elementAt(i)); + if (ae instanceof TMLWriteChannel) { + ((TMLWriteChannel)ae).replaceChannelWith(oldChan, newChan); + } + } + } + + +} diff --git a/src/tmltranslator/TMLActivityElementChannel.java b/src/tmltranslator/TMLActivityElementChannel.java index c1e23d4cfed63da3f18111ddd082c2ec71c26e6a..c8490e2e2000417d6116ac198d73301f5df4e3ab 100755 --- a/src/tmltranslator/TMLActivityElementChannel.java +++ b/src/tmltranslator/TMLActivityElementChannel.java @@ -1,47 +1,47 @@ /**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. - -/** - * Class TMLReadChannel - * Creation: 23/11/2005 - * @version 1.0 23/11/2005 - * @author Ludovic APVRILLE - * @see - */ + 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. + + /** + * Class TMLReadChannel + * Creation: 23/11/2005 + * @version 1.1 18/02/2015 + * @author Ludovic APVRILLE + * @see + */ package tmltranslator; @@ -51,41 +51,36 @@ import java.util.*; public class TMLActivityElementChannel extends TMLActivityElement { protected ArrayList<TMLChannel> channels; protected String nbOfSamples; - + public TMLActivityElementChannel(String _name, Object _referenceObject) { - super(_name, _referenceObject); - channels = new ArrayList<TMLChannel>(); + super(_name, _referenceObject); + channels = new ArrayList<TMLChannel>(); } - + public void addChannel(TMLChannel _channel) { - channels.add(_channel); + channels.add(_channel); } - - /* To remove once TTool has been tested - public void setChannel(TMLChannel _channel) { - channels.add(_channel); - } - - public TMLChannel getChannel() { - return channels.get(0); + + public int getNbOfChannels() { + return channels.size(); } - Remove before */ - - public int getNbOfChannels() { - return channels.size(); - } - public TMLChannel getChannel(int _index) { return channels.get(_index); } - + public void setNbOfSamples(String _nbOfSamples) { nbOfSamples = _nbOfSamples; } - + public String getNbOfSamples() { return nbOfSamples; } - -} \ No newline at end of file + + public void replaceChannelWith(TMLChannel oldChan, TMLChannel newChan) { + if (channels.contains(oldChan)) { + channels.remove(oldChan); + channels.add(newChan); + } + } +} diff --git a/src/tmltranslator/TMLAttribute.java b/src/tmltranslator/TMLAttribute.java index b062a7b8a63fba3df0cb56ff41216a0ef5ea18eb..3eec3d5340b0a877bc6d46269daa61aec7605b53 100755 --- a/src/tmltranslator/TMLAttribute.java +++ b/src/tmltranslator/TMLAttribute.java @@ -49,85 +49,85 @@ package tmltranslator; public class TMLAttribute extends DIPLOElement { - + public TMLType type; public String name = ""; public String initialValue = ""; private String instanceName = ""; - + public TMLAttribute( String _name, String _instanceName, TMLType _type, String _initialValue ) { this.name = _name; - this.instanceName = _instanceName; + this.instanceName = _instanceName; this.type = _type; - this.initialValue = _initialValue; + this.initialValue = _initialValue; } - + public TMLAttribute( String _name, String _instanceName, TMLType _type ) { this.name = _name; - this.instanceName = _instanceName; + this.instanceName = _instanceName; this.type = _type; - this.initialValue = "NULL"; - } + this.initialValue = "NULL"; + } public TMLAttribute( String _name, TMLType _type ) { this.name = _name; - this.instanceName = "NO_NAME"; + this.instanceName = "NO_NAME"; this.type = _type; - this.initialValue = "NULL"; + this.initialValue = "NULL"; } public TMLAttribute( String _name ) { - this.name = _name; - this.instanceName = "NO_NAME"; - this.type = new TMLType( TMLType.OTHER ); - this.initialValue = "NULL"; + this.name = _name; + this.instanceName = "NO_NAME"; + this.type = new TMLType( TMLType.OTHER ); + this.initialValue = "NULL"; + } + + public String getInstanceName() { + return instanceName; } - public String getInstanceName() { - return instanceName; - } - public String getName() { - return name; + return name; } - + public TMLType getType() { - return type; + return type; + } + + public boolean isNat() { + return (type.getType() == TMLType.NATURAL); } - - public boolean isNat() { - return (type.getType() == TMLType.NATURAL); - } - - public boolean isBool() { - return (type.getType() == TMLType.BOOLEAN); - } - + + public boolean isBool() { + return (type.getType() == TMLType.BOOLEAN); + } + public String getInitialValue() { - return initialValue; + return initialValue; } - - public String toString() { - return instanceName + "." + name + ":" + type.toString() + "=" + initialValue; + + public String toString() { + return instanceName + "." + name + ":" + type.toString() + "=" + initialValue; } - + public boolean hasInitialValue() { - return ((initialValue != null) && (initialValue.length() > 0)); + return ((initialValue != null) && (initialValue.length() > 0)); + } + + public String getDefaultInitialValue() { + if (isNat()) { + return "0"; + } else { + if (isBool()) { + return "false"; + } + } + return "unknown"; + } + + public boolean equals( TMLAttribute _other ) { + + return ( (name.equals( _other.getName() )) && ( initialValue.equals( _other.getInitialValue() )) && (type.equals( _other.getType() )) ); } - - public String getDefaultInitialValue() { - if (isNat()) { - return "0"; - } else { - if (isBool()) { - return "false"; - } - } - return "unknown"; - } - - public boolean equals( TMLAttribute _other ) { - - return ( (name.equals( _other.getName() )) && ( initialValue.equals( _other.getInitialValue() )) && (type.equals( _other.getType() )) ); - } }//End of class diff --git a/src/tmltranslator/TMLChannel.java b/src/tmltranslator/TMLChannel.java index 19eb55e8369ebc663aa5c461f308665c4d901d85..4ed1b701858240b2c1a9a65765c79ec23c025456 100755 --- a/src/tmltranslator/TMLChannel.java +++ b/src/tmltranslator/TMLChannel.java @@ -157,6 +157,14 @@ public class TMLChannel extends TMLCommunicationElement { return true; } + public boolean isAForkChannel() { + return ((originTasks.size() == 1) && (destinationTasks.size() >= 1)); + } + + public boolean isAJoinChannel() { + return ((destinationTasks.size() == 1) && (originTasks.size() >= 1)); + } + public void toBasicIfPossible() { if ((originTasks.size() ==1) && (destinationTasks.size() ==1)) { originTask = originTasks.get(0); @@ -196,6 +204,13 @@ public class TMLChannel extends TMLCommunicationElement { return destinationPorts; } + public void removeComplexInformations() { + originTasks = new ArrayList<TMLTask>(); + destinationTasks = new ArrayList<TMLTask>(); + originPorts = new ArrayList<TMLPort>(); + destinationPorts = new ArrayList<TMLPort>(); + } + // Basic channels public void setTasks(TMLTask _origin, TMLTask _destination) { diff --git a/src/tmltranslator/TMLMapping.java b/src/tmltranslator/TMLMapping.java index b4bdc1d5accb136d0a149d0bd5506a4259fc8b7b..e504de11449bd6de28c76c1bceb68334268d86ec 100755 --- a/src/tmltranslator/TMLMapping.java +++ b/src/tmltranslator/TMLMapping.java @@ -126,8 +126,6 @@ public class TMLMapping { } } - - if (!tmla.hasBus()) { bus = new HwBus("defaultBus"); tmla.addHwNode(bus); @@ -601,4 +599,9 @@ public class TMLMapping { return tmla.getArchitectureComplexity(); } + + + public void removeForksAndJoins() { + tmlm.removeForksAndJoins(); + } } diff --git a/src/tmltranslator/TMLModeling.java b/src/tmltranslator/TMLModeling.java index 5dadb44165d8e6f4df66860e3ea36ac47bd85fc4..931484b4b81560c199e9a5bbd503dad396628051 100755 --- a/src/tmltranslator/TMLModeling.java +++ b/src/tmltranslator/TMLModeling.java @@ -1389,4 +1389,180 @@ public class TMLModeling { } + public void removeForksAndJoins() { + removeForks(); + removeJoins(); + } + + // Channels with one origin and several destinations + // Add a task at sending side + // Channel is tranformed into something else ... + public void removeForks() { + // Create new basic channels and tasks + ArrayList<TMLChannel> newChannels = new ArrayList<TMLChannel>(); + for(TMLChannel channel: channels) { + if (channel.isAForkChannel()) { + removeFork(channel, newChannels); + } + } + + for(TMLChannel chan: newChannels) { + addChannel(chan); + } + } + + public void removeFork(TMLChannel _ch, ArrayList<TMLChannel> _newChannels) { + int i; + + // Create the new task and its activity diagram + TMLTask forkTask = new TMLTask("FORKTASK__" + _ch.getName(), _ch.getReferenceObject(), null); + TMLActivity forkActivity = forkTask.getActivityDiagram(); + addTask(forkTask); + + // Create the new (basic) channels. The first branch of the fork is reused, others are created + int nb = _ch.getDestinationTasks().size(); + TMLChannel[] chans = new TMLChannel[nb]; + for(i=0; i<nb; i++) { + chans[i] = new TMLChannel("FORKCHANNEL__" + i + "__" + _ch.getName(), _ch.getReferenceObject()); + chans[i].setTasks(forkTask, _ch.getDestinationTasks().get(i)); + chans[i].setPorts(new TMLPort("FORKPORTORIGIN__" + i + "__" + _ch.getName(), _ch.getReferenceObject()), _ch.getDestinationPorts().get(i)); + chans[i].setType(_ch.getType()); + chans[i].setMax(_ch.getMax()); + chans[i].setSize(_ch.getSize()); + _newChannels.add(chans[i]); + } + + // Modify the activity diagram of tasks making a read in destination channels + // Modify the channel of red operators to the new channels! + for(i=0; i<nb; i++) { + _ch.getDestinationTasks().get(i).replaceReadChannelWith(_ch, chans[i]); + } + + + // Transform the original channel into a basic channel + _ch.setTasks(_ch.getOriginTasks().get(0), forkTask); + _ch.setPorts(_ch.getOriginPorts().get(0), new TMLPort("FORKPORTDESTINATION__" + _ch.getName(), _ch.getReferenceObject())); + _ch.removeComplexInformations(); + + // Make the activity diagram of the fork task + TMLStartState start = new TMLStartState("startOfFork", null); + forkActivity.setFirst(start); + TMLStopState stop = new TMLStopState("stopOfFork", null); + forkActivity.addElement(stop); + TMLForLoop junction = new TMLForLoop("junctionOfFork", null); + junction.setInit("i=0"); + junction.setCondition("i==1"); + junction.setIncrement("i=i"); + TMLAttribute attr = new TMLAttribute("i", "i", new TMLType(TMLType.NATURAL), "0"); + forkTask.addAttribute(attr); + forkActivity.addElement(junction); + TMLReadChannel read = new TMLReadChannel("ReadOfFork", null); + forkActivity.addElement(read); + read.addChannel(_ch); + read.setNbOfSamples("1"); + + TMLWriteChannel []writes = new TMLWriteChannel[nb]; + for(i=0; i<nb; i++) { + writes[i] = new TMLWriteChannel("WriteOfFork__" + i, null); + writes[i].addChannel(chans[i]); + writes[i].setNbOfSamples("1"); + forkActivity.addElement(writes[i]); + } + + start.addNext(junction); + junction.addNext(read); + read.addNext(writes[0]); + for(i=0; i<nb-1; i++) { + writes[i].addNext(writes[i+1]); + } + writes[nb-1].addNext(stop); + + + } + + // Channels with severals origins and one destination + // Add a task at receiving side + // Channel is tranformed into something else ... + public void removeJoins() { + // Create new basic channels and tasks + ArrayList<TMLChannel> newChannels = new ArrayList<TMLChannel>(); + for(TMLChannel channel: channels) { + if (channel.isAJoinChannel()) { + removeJoin(channel, newChannels); + } + } + + for(TMLChannel chan: newChannels) { + addChannel(chan); + } + } + + public void removeJoin(TMLChannel _ch, ArrayList<TMLChannel> _newChannels) { + int i; + + // Create the new task and its activity diagram + TMLTask joinTask = new TMLTask("JOINTASK__" + _ch.getName(), _ch.getReferenceObject(), null); + TMLActivity joinActivity = joinTask.getActivityDiagram(); + addTask(joinTask); + + // Create the new (basic) channels. The last branch of the join is reused, others are created + int nb = _ch.getOriginTasks().size(); + TMLChannel[] chans = new TMLChannel[nb]; + for(i=0; i<nb; i++) { + chans[i] = new TMLChannel("JOINCHANNEL__" + i + "__" + _ch.getName(), _ch.getReferenceObject()); + chans[i].setTasks(_ch.getOriginTasks().get(i), joinTask); + chans[i].setPorts(_ch.getOriginPorts().get(i), new TMLPort("JOINPORTDESTINATION__" + i + "__" + _ch.getName(), _ch.getReferenceObject())); + chans[i].setType(_ch.getType()); + chans[i].setMax(_ch.getMax()); + chans[i].setSize(_ch.getSize()); + _newChannels.add(chans[i]); + } + + // Modify the activity diagram of tasks making a write in origin channels + // Modify the channel of write operators to the new channels! + for(i=0; i<nb; i++) { + _ch.getOriginTasks().get(i).replaceWriteChannelWith(_ch, chans[i]); + } + + + // Transform the original channel into a basic channel + _ch.setTasks(joinTask, _ch.getDestinationTasks().get(0)); + _ch.setPorts(new TMLPort("JOINPORTORIGIN__" + _ch.getName(), _ch.getReferenceObject()), _ch.getDestinationPorts().get(0)); + _ch.removeComplexInformations(); + + // Make the activity diagram of the fork task + TMLStartState start = new TMLStartState("startOfJoin", null); + joinActivity.setFirst(start); + TMLStopState stop = new TMLStopState("stopOfJoin", null); + joinActivity.addElement(stop); + TMLForLoop junction = new TMLForLoop("junctionOfJoin", null); + junction.setInit("i=0"); + junction.setCondition("i==1"); + junction.setIncrement("i=i"); + TMLAttribute attr = new TMLAttribute("i", "i", new TMLType(TMLType.NATURAL), "0"); + joinTask.addAttribute(attr); + joinActivity.addElement(junction); + TMLWriteChannel write = new TMLWriteChannel("WriteOfJoin", null); + joinActivity.addElement(write); + write.addChannel(_ch); + write.setNbOfSamples("1"); + + TMLReadChannel []reads = new TMLReadChannel[nb]; + for(i=0; i<nb; i++) { + reads[i] = new TMLReadChannel("ReadOfJoin__" + i, null); + reads[i].addChannel(chans[i]); + reads[i].setNbOfSamples("1"); + joinActivity.addElement(reads[i]); + } + + // Nexts + start.addNext(junction); + junction.addNext(reads[0]); + write.addNext(stop); + for(i=0; i<nb-1; i++) { + reads[i].addNext(reads[i+1]); + } + reads[nb-1].addNext(write); + } + } diff --git a/src/tmltranslator/TMLTask.java b/src/tmltranslator/TMLTask.java index 8efb2ecb175a07d792e7abae04ea5dcd3fcf7487..ed4f2d4e7ea15073a5fdd1ce6d5e385762de706b 100755 --- a/src/tmltranslator/TMLTask.java +++ b/src/tmltranslator/TMLTask.java @@ -61,7 +61,7 @@ public class TMLTask extends TMLElement { public TMLTask(String name, Object referenceToClass, Object referenceToActivityDiagram) { super(name, referenceToClass); - //TraceManager.addDev("Creating new TMLTask:" + name); + //TraceManager.addDev("Creating new TMLTask:" + name); activity = new TMLActivity(name+"activity_diagram", referenceToActivityDiagram); attributes = new ArrayList<TMLAttribute>(); } @@ -275,4 +275,12 @@ public class TMLTask extends TMLElement { } + public void replaceReadChannelWith(TMLChannel oldChan, TMLChannel newChan) { + activity.replaceReadChannelWith(oldChan, newChan); + } + + public void replaceWriteChannelWith(TMLChannel oldChan, TMLChannel newChan) { + activity.replaceWriteChannelWith(oldChan, newChan); + } + } diff --git a/src/tmltranslator/TMLTextSpecification.java b/src/tmltranslator/TMLTextSpecification.java index dda7c52e61edd48df9dd9bc1e1b08f68ba76c878..69525bf9bfda5a1ded5ea488a110c609c7ba85fc 100755 --- a/src/tmltranslator/TMLTextSpecification.java +++ b/src/tmltranslator/TMLTextSpecification.java @@ -175,6 +175,7 @@ public class TMLTextSpecification { } public String toTextFormat(TMLModeling tmlm) { + tmlm.removeForksAndJoins(); tmlm.sortByName(); spec = makeDeclarations(tmlm); spec += makeTasks(tmlm); diff --git a/src/tmltranslator/TMLWriteChannel.java b/src/tmltranslator/TMLWriteChannel.java index 0e590980e57d6861c250a63eb6d711f97b4e3546..b5afaaedb8e1c5805e698b7efe10e18b67a2d0e5 100755 --- a/src/tmltranslator/TMLWriteChannel.java +++ b/src/tmltranslator/TMLWriteChannel.java @@ -1,66 +1,66 @@ /**Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille -ludovic.apvrille AT enst.fr + 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 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". + 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. + 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. + 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. + The fact that you are presently reading this means that you have had + knowledge of the CeCILL license and that you accept its terms. -/** -* Class TMLWriteChannel -* Creation: 23/11/2005 -* @version 1.0 23/11/2005 -* @author Ludovic APVRILLE -* @see -*/ + /** + * Class TMLWriteChannel + * Creation: 23/11/2005 + * @version 1.0 23/11/2005 + * @author Ludovic APVRILLE + * @see + */ package tmltranslator; public class TMLWriteChannel extends TMLActivityElementChannel { - + public TMLWriteChannel(String _name, Object _referenceObject) { - super(_name, _referenceObject); + super(_name, _referenceObject); + } + + public String toString() { + String tmp = "Write " + nbOfSamples + " sample(s) in channel(s): "; + for(int k=0; k<getNbOfChannels(); k++) { + if (k!=0) { + tmp += " ,"; + } + tmp += getChannel(k).getName(); + } + return tmp; } - - public String toString() { - String tmp = "Write " + nbOfSamples + " sample(s) in channel(s): "; - for(int k=0; k<getNbOfChannels(); k++) { - if (k!=0) { - tmp += " ,"; - } - tmp += getChannel(k).getName(); - } - return tmp; - } - -} \ No newline at end of file + +} diff --git a/src/tmltranslator/tomappingsystemc2/MappedSystemCTask.java b/src/tmltranslator/tomappingsystemc2/MappedSystemCTask.java index 7c07f64db486739c00d20d612cc7caa71c557fc3..1867c6d6b193cddaab73677237ffa1e73c4ef3b9 100755 --- a/src/tmltranslator/tomappingsystemc2/MappedSystemCTask.java +++ b/src/tmltranslator/tomappingsystemc2/MappedSystemCTask.java @@ -51,934 +51,935 @@ import myutil.*; public class MappedSystemCTask { - //private TMLModeling tmlm; - private TMLTask task; - private String reference, cppcode, hcode, initCommand, functions, functionSig, chaining, firstCommand, commentText; - private ArrayList<TMLChannel> channels; - private ArrayList<TMLEvent> events; - private ArrayList<TMLRequest> requests; - private TMLMapping tmlmapping; - private int commentNum; - private boolean debug; - private boolean optimize; - private StaticAnalysis _analysis; - private LiveVariableNode _startAnaNode=null; - - private final static String DOTH = ".h"; - private final static String DOTCPP = ".cpp"; - private final static String SYSTEM_INCLUDE = "#include \"systemc.h\""; - private final static String CR = "\n"; - private final static String CR2 = "\n\n"; - private final static String SCCR = ";\n"; - private final static String EFCR = "}\n"; - private final static String EFCR2 = "}\n\n"; - private final static String EF = "}"; - - - public MappedSystemCTask(TMLTask _task, ArrayList<TMLChannel> _channels, ArrayList<TMLEvent> _events, ArrayList<TMLRequest> _requests, TMLMapping _tmlmapping, Set<Integer> _depChannels) { - task = _task; - channels = _channels; - events = _events; - requests = _requests; - tmlmapping=_tmlmapping; - reference = task.getName(); - cppcode = ""; - hcode = ""; - initCommand=""; - functions=""; - chaining=""; - firstCommand=""; - functionSig=""; - commentText=""; - commentNum=0; - optimize=false; - - //for(TMLAttribute att: task.getAttributes()) { - // TraceManager.addDev ("************ Attribute: " + att.name); - //} - - _analysis = new StaticAnalysis(_task, _channels, _events, _requests, _depChannels); - _startAnaNode = _analysis.startAnalysis(); - } - - public void saveInFiles(String path) throws FileException { - FileUtils.saveFile(path + reference + DOTH, getHCode()); - FileUtils.saveFile(path + reference + DOTCPP, getCPPCode()); - } - - public TMLTask getTMLTask() { - return task; - } - - public void generateSystemC(boolean _debug, boolean _optimize) { - //_startAnaNode = _analysis.startAnalysis(); - //_analysis.determineCheckpoints(aStatistics); //NEW - debug = _debug; - optimize=_optimize; - basicCPPCode(); - makeClassCode(); - } - - public void print() { - TraceManager.addDev("task: " + reference + DOTH + hcode); - TraceManager.addDev("task: " + reference + DOTCPP + cppcode); - } - - - public String getCPPCode() { - return cppcode; - } - - public String getHCode() { - return hcode; - } - - public String getReference() { - return reference; - } - - // H-Code - private String basicHCode() { - String code=""; - code += "#ifndef " + reference.toUpperCase() + "__H" + CR; - code += "#define " + reference.toUpperCase() + "__H" + CR2; - code += "#include <TMLTask.h>\n#include <definitions.h>\n\n"; - code += "#include <TMLbrbwChannel.h>\n#include <TMLbrnbwChannel.h>\n#include <TMLnbrnbwChannel.h>\n\n"; - code += "#include <TMLEventBChannel.h>\n#include <TMLEventFChannel.h>\n#include <TMLEventFBChannel.h>\n\n"; - code += "#include <TMLActionCommand.h>\n#include <TMLChoiceCommand.h>\n#include <TMLRandomChoiceCommand.h>\n#include <TMLExeciCommand.h>\n"; - code += "#include <TMLSelectCommand.h>\n#include <TMLReadCommand.h>\n#include <TMLNotifiedCommand.h>\n#include<TMLExeciRangeCommand.h>\n"; - code += "#include <TMLRequestCommand.h>\n#include <TMLSendCommand.h>\n#include <TMLWaitCommand.h>\n"; - code += "#include <TMLWriteCommand.h>\n#include <TMLStopCommand.h>\n#include<TMLWriteMultCommand.h>\n#include <TMLRandomCommand.h>\n\n"; - code += "extern \"C\" bool condFunc(TMLTask* _ioTask_);\n"; - return code; - } - - private void classHCode() { - } - - // CPP Code - private void basicCPPCode() { - cppcode += "#include <" + reference + DOTH + ">" + CR2; - } - - private void makeClassCode(){ - makeHeaderClassH(); - makeEndClassH(); - - cppcode+=reference+ "::" + makeConstructorSignature()+":TMLTask(iID, iPriority,iName,iCPUs,iNumOfCPUs)"+ CR + makeAttributesCode(); - cppcode+=initCommand + CR + "{" + CR; - if (commentNum!=0) cppcode+= "_comment = new std::string[" + commentNum + "]" + SCCR + commentText + CR; - cppcode+= "//generate task variable look-up table"+ CR; - for(TMLAttribute att: task.getAttributes()) { - //att = (TMLAttribute)(iterator.next()); - //code += TMLType.getStringType(att.type.getType()) + " " + att.name; - cppcode += "_varLookUpName[\"" + att.name + "\"]=&" + att.name +SCCR; - cppcode += "_varLookUpID[" + att.getID() + "]=&" + att.name +SCCR; - } - cppcode += "_varLookUpName[\"rnd__0\"]=&rnd__0" + SCCR + CR; - cppcode+= "//set blocked read task/set blocked write task"+ CR; - for(TMLChannel ch: channels) { - if (ch.getOriginTask()==task) - cppcode+=ch.getExtendedName() + "->setBlockedWriteTask(this)"+SCCR; - else - cppcode+=ch.getExtendedName() + "->setBlockedReadTask(this)"+SCCR; - } - for(TMLEvent evt: events) { - if (evt.getOriginTask()==task) - cppcode+=evt.getExtendedName() + "->setBlockedWriteTask(this)"+SCCR; - else - cppcode+=evt.getExtendedName() + "->setBlockedReadTask(this)"+SCCR; - } - if (task.isRequested()) cppcode+="requestChannel->setBlockedReadTask(this)" +SCCR; - for(TMLRequest req: requests) { - if (req.isAnOriginTask(task)) cppcode+=req.getExtendedName() + "->setBlockedWriteTask(this)" +SCCR; - } - cppcode+=CR + "//command chaining"+ CR; - cppcode+= chaining + "_currCommand=" + firstCommand + SCCR + "_firstCommand=" + firstCommand +SCCR + CR; - int aSeq=0; - for(TMLChannel ch: channels) { - cppcode+= "_channels[" + aSeq + "] = " + ch.getExtendedName() + SCCR; - aSeq++; - } - for(TMLEvent evt: events) { - cppcode+= "_channels[" + aSeq + "] = " + evt.getExtendedName() + SCCR; - aSeq++; - } - if (task.isRequested()){ - cppcode+= "_channels[" + aSeq + "] = requestChannel" + SCCR; - } - TMLActivityElement currElem=task.getActivityDiagram().getFirst(); - LiveVariableNode currNode; - do{ - currNode = _analysis.getLiveVarNodeByCommand(currElem); - currElem = currElem.getNextElement(0); - }while (currNode==null && currElem!=null); - if (currNode!=null) cppcode+= "refreshStateHash(" + currNode.getStartLiveVariableString() + ")" +SCCR; - cppcode+="}"+ CR2 + functions; // + makeDestructor(); - hcode = Conversion.indentString(hcode, 4); - cppcode = Conversion.indentString(cppcode, 4); - } - - private String makeDestructor(){ - String dest=reference + "::~" + reference + "(){" + CR; - if (commentNum!=0) dest+="delete[] _comment" + SCCR; - return dest+"}"+CR; - } - - private String makeConstructorSignature(){ - String constSig=reference+ "(ID iID, Priority iPriority, std::string iName, CPU** iCPUs, unsigned int iNumOfCPUs"+CR; - for(TMLChannel ch: channels) { - constSig+=", TMLChannel* "+ ch.getExtendedName() + CR; - } - for(TMLEvent evt: events) { - constSig+=", TMLEventChannel* "+ evt.getExtendedName() +CR; - } - for(TMLRequest req: requests) { - //if (req.isAnOriginTask(task)) constSig+=", TMLEventBChannel* " + req.getExtendedName() + CR; - if (req.isAnOriginTask(task)) constSig+=", TMLEventChannel* " + req.getExtendedName() + CR; - } - if (task.isRequested()){ - //constSig+=", TMLEventBChannel* requestChannel"+CR; - constSig+=", TMLEventChannel* requestChannel"+CR; - } - return constSig+")"; - } - - private void makeHeaderClassH() { - String hcodeBegin=""; - hcodeBegin = "class " + reference + ": public TMLTask {" + CR; - hcodeBegin += "private:" + CR; - - hcodeBegin += "// Attributes" + CR; - - if (task.isRequested()) { - int params = task.getRequest().getNbOfParams(); - firstCommand="_waitOnRequest"; - hcode+="TMLWaitCommand " + firstCommand + SCCR; - initCommand+= "," + firstCommand + "(" + task.getActivityDiagram().getFirst().getID() + ",this,requestChannel,"; - if (params==0){ - initCommand+= "0,"+ getFormattedLiveVarStr(_startAnaNode) + ")" + CR; - }else{ - initCommand+= "(ParamFuncPointer)&" + reference + "::" + "waitOnRequest_func," + getFormattedLiveVarStr(_startAnaNode) + ")" + CR; - //functionSig+="Parameter<ParamType>* waitOnRequest_func(Parameter<ParamType>* ioParam)" + SCCR; - //functions+="Parameter<ParamType>* " + reference + "::waitOnRequest_func(Parameter<ParamType>* ioParam){" + CR; - - functionSig+="Parameter* waitOnRequest_func(Parameter* ioParam)" + SCCR; - functions+="Parameter* " + reference + "::waitOnRequest_func(Parameter* ioParam){" + CR; - functions+= "ioParam->getP(&arg1__req"; - for (int i=1; i<params; i++){ - functions+= ", &arg" + (i+1) + "__req"; - } - functions+=")" + SCCR + "return 0" + SCCR; - functions+="}\n\n"; - } - String xx = firstCommand + ".setNextCommand(array(1,(TMLCommand*)" + makeCommands(task.getActivityDiagram().getFirst(),false,"&"+firstCommand,null) + "))"+ SCCR; - firstCommand="&"+firstCommand; - chaining+=xx; - }else{ - firstCommand=makeCommands(task.getActivityDiagram().getFirst(),false,"0",null); - } - - hcode = basicHCode() + hcodeBegin + makeAttributesDeclaration() + CR + hcode; - // public dec - hcode += CR + functionSig + CR + "public:" + CR; - hcode += "friend bool condFunc(TMLTask* _ioTask_);\n"; - hcode += "friend class CurrentComponents;\n"; - // Simulation - hcode += makeConstructorSignature() + SCCR; // + "~" + reference + "()" + SCCR; - makeSerializableFuncs(); - } - - private void makeSerializableFuncs(){ - hcode += "std::istream& readObject(std::istream& i_stream_var)" + SCCR; - hcode += "std::ostream& writeObject(std::ostream& i_stream_var)" + SCCR; - //hcode += "unsigned long getStateHash() const" + SCCR; - functions+= "std::istream& " + reference + "::readObject(std::istream& i_stream_var){\n"; - for (TMLAttribute att:task.getAttributes()){ - //att = (TMLAttribute)(iterator.next()); - functions += "READ_STREAM(i_stream_var," + att.name + ")" + SCCR; - functions += "#ifdef DEBUG_SERIALIZE\n"; - functions += "std::cout << \"Read: Variable " + att.name + " \" << " + att.name + " << std::endl" + SCCR; - functions += "#endif\n"; - } - functions+= "TMLTask::readObject(i_stream_var);\nreturn i_stream_var;\n}\n\n"; - functions+= "std::ostream& " + reference + "::writeObject(std::ostream& i_stream_var){\n"; - for (TMLAttribute att:task.getAttributes()){ - functions += "WRITE_STREAM(i_stream_var," + att.name + ")" + SCCR; - functions += "#ifdef DEBUG_SERIALIZE\n"; - functions += "std::cout << \"Write: Variable " + att.name + " \" << " + att.name + " << std::endl" + SCCR; - functions += "#endif\n"; - } - functions+= "TMLTask::writeObject(i_stream_var);\nreturn i_stream_var;\n}\n\n"; - hcode += "void reset()" + SCCR; - functions+= "void "+reference + "::reset(){\nTMLTask::reset();\n"; - for (TMLAttribute att:task.getAttributes()){ - functions += att.name + "="; - if (att.hasInitialValue()) - functions += att.initialValue + SCCR; - else - functions += "0" + SCCR; - } - functions+= "}\n\n"; - /*hcode += "void refreshStateHash(const char* iLiveVarList);\n"; - functions+= "void " + reference + "::refreshStateHash(const char* iLiveVarList){\n"; - int aSeq=0; - functions += "_stateHash.init((HashValueType)_ID,30);\nif(iLiveVarList!=0){\n";*/ - hcode += "HashValueType getStateHash();\n"; - functions+= "HashValueType " + reference + "::getStateHash(){\n"; - int aSeq=0; - //functions += "if(_liveVarList!=0 && _hashInvalidated){\n"; - functions += "if(_hashInvalidated){\n"; - functions += "_hashInvalidated=false;\n_stateHash.init((HashValueType)_ID,30);\n"; - functions += "if(_liveVarList!=0){\n"; - for(TMLAttribute att: task.getAttributes()) { - functions += "if ((_liveVarList[" + (aSeq >>> 3) + "] & " + (1 << (aSeq & 0x7)) + ")!=0) _stateHash.addValue(" + att.getName() + ");\n"; - //functions += "_stateHash.addValue(" + att.getName() + ");\n"; - aSeq++; - } - int i=0; - //for channels: include hash only if performed action is blocking - //for events: include filling level for senders (notified possible), include parameters for readers (if parameters set) - for(TMLChannel ch: channels) { - if (ch.getType()==TMLChannel.BRBW || (ch.getType()==TMLChannel.BRNBW && ch.getDestinationTask()==task)) functions += "_channels[" + i +"]->setSignificance(this, " + "((_liveVarList[" + (aSeq >>> 3) + "] & " + (1 << (aSeq & 0x7)) + ")!=0));\n"; - //if (ch.getType()==TMLChannel.BRBW || (ch.getType()==TMLChannel.BRNBW && ch.getDestinationTask()==task)) functions += "_channels[" + i +"]->setSignificance(this, true);\n"; - - aSeq++; i++; - } - for(TMLEvent evt: events) { - if (evt.isBlocking() || evt.getDestinationTask()==task) functions += " _channels[" + i +"]->setSignificance(this, " + "((_liveVarList[" + (aSeq >>> 3) + "] & " + (1 << (aSeq & 0x7)) + ")!=0));\n"; - //if (evt.isBlocking() || evt.getDestinationTask()==task) functions += " _channels[" + i +"]->setSignificance(this, true);\n"; - aSeq++; i++; - } - if (task.isRequested()){ - functions += " _channels[" + i +"]->setSignificance(this, " + "((_liveVarList[" + (aSeq >>> 3) + "] & " + (1 << (aSeq & 0x7)) + ")!=0));\n"; - //functions += " _channels[" + i +"]->setSignificance(this, true);\n"; - } - /*for(i=0; i< channels.size() + events.size() + (task.isRequested()? 1:0) ; i++){ - functions += "if ((iLiveVarList[" + (aSeq >>> 3) + "] & " + (1 << (aSeq & 0x7)) + ")!=0) _channels[" + i +"]->getStateHash(iHash);\n"; - aSeq++; - }*/ - //functions += "}\n}\n\n"; - functions += "}\n}\nreturn _stateHash.getHash();\n}\n\n"; - } - - private String getFormattedLiveVarStr(TMLActivityElement currElem){ - return getFormattedLiveVarStr(_analysis.getLiveVarNodeByCommand(currElem)); - //return getFormattedLiveVarStr((LiveVariableNode)null); - } - - private String getFormattedLiveVarStr(LiveVariableNode currNode){ - if (currNode==null){ - return "0, false"; - }else{ - String checkpoint = (currNode.isCheckpoint())? "true":"false"; - //String checkpoint = "true"; - return currNode.getLiveVariableString() + "," + checkpoint; - } - } - - - - private String makeCommands(TMLActivityElement currElem, boolean skip, String retElement, String retElseElement){ - String nextCommand="",cmdName=""; - - if (skip) return makeCommands(currElem.getNextElement(0), false,retElement,null); - - if (currElem==null){ - if (debug) TraceManager.addDev("Checking null\n"); - return retElement; - } - - if (debug) TraceManager.addDev("Checking " + currElem.getName() + CR); - - if (currElem instanceof TMLStartState) { - if (debug) TraceManager.addDev("Checking Start\n"); - return makeCommands(currElem.getNextElement(0), false,retElement,null); - - } else if (currElem instanceof TMLStopState){ - //add stop state if (retElement.equals("0")) - if (debug) TraceManager.addDev("Checking Stop\n"); - if (retElement.equals("0")){ - cmdName= "_stop" + currElem.getID(); - hcode+="TMLStopCommand " + cmdName + SCCR; - initCommand+= "," + cmdName + "(" + currElem.getID() + ",this)" + CR; - }else - return retElement; - - }else if (currElem instanceof TMLRandom){ - if (debug) TraceManager.addDev("Checking Random\n"); - cmdName= "_random" + currElem.getID(); - TMLRandom random = (TMLRandom)currElem; - hcode+="TMLRandomCommand " + cmdName + SCCR; - initCommand+= "," + cmdName + "("+ currElem.getID() + ",this," + makeCommandRangeFunc(cmdName, random.getMinValue(), random.getMaxValue()) + ",&" + random.getVariable() + "," + getFormattedLiveVarStr(currElem) + ")"+CR; - nextCommand= cmdName + ".setNextCommand(array(1,(TMLCommand*)" + makeCommands(currElem.getNextElement(0),false,retElement,null) + "));\n"; - //functions+="void "+ reference + "::" + cmdName + "_func(ParamType& oMin, ParamType& oMax){\n oMin=" + modifyString(random.getMinValue()) + ";\noMax=" + modifyString(random.getMaxValue()) + SCCR; - //functions+= "}" + CR2; - //functionSig+="void " + cmdName + "_func(ParamType & oMin, ParamType& oMax)" + SCCR; - - } else if (currElem instanceof TMLActionState || currElem instanceof TMLDelay){ - String action,comment; - if (currElem instanceof TMLActionState){ - if (debug) TraceManager.addDev("Checking Action\n"); - action = formatAction(((TMLActionState)currElem).getAction()); - comment=action; - }else{ - if (debug) TraceManager.addDev("Checking Delay\n"); - int masterClockFreq = tmlmapping.getTMLArchitecture().getMasterClockFrequency(); - TMLDelay delay=(TMLDelay)currElem; - action = "TMLTime tmpDelayxy = " + delay.getMaxDelay() + "*" + masterClockFreq + delay.getMasterClockFactor() + ";"; - comment=action; - action+= "\nif (tmpDelayxy==0) tmpDelayxy=1;\n"; - if (delay.getMinDelay().equals(delay.getMaxDelay())){ - action += "_endLastTransaction+=tmpDelayxy"; - }else{ - action += "TMLTime tmpDelayxx = " + delay.getMinDelay() + "*" + masterClockFreq + delay.getMasterClockFactor() + ";\nif (tmpDelayxx==0) tmpDelayxx=1;\n"; - action += "_endLastTransaction+=myrand(tmpDelayxx,tmpDelayxy)"; - } - } - //cmdName= "_action" + currElem.getID(); - String elemName=currElem.getName(), idString; - if (elemName.charAt(0)=='#'){ - int pos=elemName.indexOf('\\'); - idString=elemName.substring(1,pos); - //TraceManager.addDev(elemName + "***" + pos + "***" + idString + "***"+ elemName.length()); - cmdName="_" + elemName.substring(pos+1) + idString; - }else{ - cmdName= "_action" + currElem.getID(); - idString=String.valueOf(currElem.getID()); - } - hcode+="TMLActionCommand " + cmdName + SCCR; - initCommand+= "," + cmdName + "("+ idString + ",this,(ActionFuncPointer)&" + reference + "::" + cmdName + "_func, " + getFormattedLiveVarStr(currElem) + ")"+CR; - nextCommand= cmdName + ".setNextCommand(array(1,(TMLCommand*)" + makeCommands(currElem.getNextElement(0),false,retElement,null) + "));\n"; - functions+="void "+ reference + "::" + cmdName + "_func(){\n#ifdef ADD_COMMENTS\naddComment(new Comment(_endLastTransaction,0," + commentNum + "));\n#endif\n" + modifyString(addSemicolonIfNecessary(action)) + CR; - //functions+="return 0"+ SCCR; - functions+= "}" + CR2; - commentText+="_comment[" + commentNum + "]=std::string(\"Action " + comment + "\");\n"; - commentNum++; - functionSig+="void " + cmdName + "_func()" + SCCR; - - } else if (currElem instanceof TMLExecI){ - if (debug) TraceManager.addDev("Checking Execi\n"); - cmdName= "_execi" + currElem.getID(); - hcode+="TMLExeciCommand " + cmdName + SCCR; - //initCommand+= "," + cmdName + "(this,"+ ((TMLExecI)currElem).getAction() + ",0,0)"+CR; - if (isIntValue(((TMLExecI)currElem).getAction())) - initCommand+= "," + cmdName + "(" + currElem.getID() + ",this,0,0," + ((TMLExecI)currElem).getAction() + "," + getFormattedLiveVarStr(currElem) + ")" + CR; - else - initCommand+= "," + cmdName + "(" + currElem.getID() + ",this," + makeCommandLenFunc(cmdName, ((TMLExecI)currElem).getAction(), null) + ",0,1," + getFormattedLiveVarStr(currElem) + ")" + CR; - nextCommand= cmdName + ".setNextCommand(array(1,(TMLCommand*)" + makeCommands(currElem.getNextElement(0),false,retElement,null) + "))"+ SCCR; - - } else if (currElem instanceof TMLExecC){ - if (debug) TraceManager.addDev("Checking ExecC\n"); - cmdName= "_execc" + currElem.getID(); - hcode+="TMLExeciCommand " + cmdName + SCCR; - if (isIntValue(((TMLExecC)currElem).getAction())) - initCommand+= "," + cmdName + "(" + currElem.getID() + ",this,0,1," + ((TMLExecC)currElem).getAction() + "," + getFormattedLiveVarStr(currElem) + ")" + CR; - else - initCommand+= "," + cmdName + "("+ currElem.getID() + ",this,"+ makeCommandLenFunc(cmdName, ((TMLExecC)currElem).getAction(), null) + ",1,1," + getFormattedLiveVarStr(currElem) + ")"+CR; - - nextCommand= cmdName + ".setNextCommand(array(1,(TMLCommand*)" + makeCommands(currElem.getNextElement(0),false,retElement,null) + "))"+ SCCR; - - } else if (currElem instanceof TMLExecIInterval){ - /*if (debug) TraceManager.addDev("Checking ExeciInterv\n"); - cmdName= "_execi" + currElem.getID(); - hcode+="TMLExeciCommand " + cmdName + SCCR; - //initCommand+= "," + cmdName + "(this,"+ ((TMLExecIInterval)currElem).getMinDelay()+ "," + ((TMLExecIInterval)currElem).getMaxDelay() + ",0)"+CR; - initCommand+= "," + cmdName + "("+currElem.getID()+",this,"+ makeCommandLenFunc(cmdName, ((TMLExecIInterval)currElem).getMinDelay(), ((TMLExecIInterval)currElem).getMaxDelay()) + ",0,1," + getFormattedLiveVarStr(currElem) + ")" +CR; - nextCommand= cmdName + ".setNextCommand(array(1,(TMLCommand*)" + makeCommands(currElem.getNextElement(0),false,retElement,null) + "))"+ SCCR;*/ - if (debug) TraceManager.addDev("Checking ExeciInterv\n"); - cmdName= "_execi" + currElem.getID(); - hcode+="TMLExeciRangeCommand " + cmdName + SCCR; - initCommand+= "," + cmdName + "("+currElem.getID()+",this,"+ makeCommandRangeFunc(cmdName, ((TMLExecIInterval)currElem).getMinDelay(), ((TMLExecIInterval)currElem).getMaxDelay()) + ",0," + getFormattedLiveVarStr(currElem) + ")" +CR; - nextCommand= cmdName + ".setNextCommand(array(1,(TMLCommand*)" + makeCommands(currElem.getNextElement(0),false,retElement,null) + "))"+ SCCR; - - } else if (currElem instanceof TMLExecCInterval){ - if (debug) TraceManager.addDev("Checking ExecCInterv\n"); - cmdName= "_execc" + currElem.getID(); - hcode+="TMLExeciCommand " + cmdName + SCCR; - //initCommand+= "," + cmdName + "(this,"+ ((TMLExecIInterval)currElem).getMinDelay()+ "," + ((TMLExecIInterval)currElem).getMaxDelay() + ",1)"+CR; - initCommand+= "," + cmdName + "("+currElem.getID()+",this,"+ makeCommandLenFunc(cmdName, ((TMLExecCInterval)currElem).getMinDelay(), ((TMLExecCInterval)currElem).getMaxDelay()) + ",1,1," + getFormattedLiveVarStr(currElem) + ")"+CR; - nextCommand= cmdName + ".setNextCommand(array(1,(TMLCommand*)" + makeCommands(currElem.getNextElement(0),false,retElement,null) + "))"+ SCCR; - - - } else if (currElem instanceof TMLForLoop){ - //makeCommands(TMLActivityElement currElem, boolean skip, String retElement, MergedCmdStr nextCommandCont, String retElseElement) - if (debug) TraceManager.addDev("Checking Loop\n"); - TMLForLoop fl = (TMLForLoop)currElem; - if (fl.getCondition().isEmpty() || fl.getCondition().trim().toUpperCase().equals("TRUE")){ - //initAction.addNext(fl.getNextElement(0)); //inside loop - TMLActionState incAction=new TMLActionState("#"+ fl.getID() + "\\lpIncAc",null); - incAction.setAction(fl.getIncrement()); - String firstCmdInLoop= makeCommands(fl.getNextElement(0), false, "&_lpIncAc" + fl.getID(), null); - makeCommands(incAction, false, firstCmdInLoop, null); - if (fl.getInit().isEmpty()){ - return firstCmdInLoop; - }else{ - TMLActionState initAction=new TMLActionState("lpInitAc",null); - initAction.setAction(fl.getInit()); - return makeCommands(initAction, false, firstCmdInLoop,null); - } - - }else{ - TMLChoice lpChoice=new TMLChoice("#"+ fl.getID() + "\\lpChoice",null); - //if (fl.getCondition().isEmpty()) - // lpChoice.addGuard("[ true ]"); - //else - lpChoice.addGuard("[ " + fl.getCondition() + " ]"); - lpChoice.addGuard("[ else ]"); - lpChoice.addNext(fl.getNextElement(0)); //inside loop - lpChoice.addNext(fl.getNextElement(1)); //after loop cmdName= "_choice" + currElem.getID(); - if (fl.getIncrement().isEmpty()){ - makeCommands(lpChoice, false, "&_lpChoice" + fl.getID(), retElement); - }else{ - TMLActionState incAction=new TMLActionState("#"+ fl.getID() + "\\lpIncAc",null); - incAction.setAction(fl.getIncrement()); - makeCommands(incAction, false, "&_lpChoice" + fl.getID(), null); - makeCommands(lpChoice, false, "&_lpIncAc" + fl.getID(), retElement); - } - if (fl.getInit().isEmpty()){ - return "&_lpChoice" + fl.getID(); - }else{ - TMLActionState initAction=new TMLActionState("lpInitAc",null); - initAction.setAction(fl.getInit()); - return makeCommands(initAction, false, "&_lpChoice" + fl.getID(), null); - } - } - - } else if (currElem instanceof TMLReadChannel){ - if (debug) TraceManager.addDev("Checking Read\n"); - cmdName= "_read" + currElem.getID(); - hcode+="TMLReadCommand " + cmdName + SCCR; - TMLReadChannel rCommand=(TMLReadChannel)currElem; - if (isIntValue(rCommand.getNbOfSamples())) - //initCommand+= "," + cmdName + "("+currElem.getID()+",this,0," + rCommand.getChannel(0).getExtendedName() + "," + rCommand.getChannel(0).getSize() + "*" + rCommand.getNbOfSamples() + ")"+CR; - initCommand+= "," + cmdName + "("+currElem.getID()+",this,0," + rCommand.getChannel(0).getExtendedName() + "," + getFormattedLiveVarStr(currElem) + "," + rCommand.getNbOfSamples() + ")"+CR; - - else - //initCommand+= "," + cmdName + "("+currElem.getID()+",this," + makeCommandLenFunc(cmdName, rCommand.getChannel(0).getSize() + "*(" + rCommand.getNbOfSamples()+")",null) + "," + rCommand.getChannel(0).getExtendedName() + ")"+CR; - initCommand+= "," + cmdName + "("+currElem.getID()+",this," + makeCommandLenFunc(cmdName, rCommand.getNbOfSamples(),null) + "," + rCommand.getChannel(0).getExtendedName() + "," + getFormattedLiveVarStr(currElem) + ")"+CR; - nextCommand= cmdName + ".setNextCommand(array(1,(TMLCommand*)" + makeCommands(currElem.getNextElement(0),false,retElement,null) + "))"+ SCCR; - - } else if (currElem instanceof TMLWriteChannel){ - String channels; - TMLWriteChannel wCommand=(TMLWriteChannel)currElem; - if (wCommand.getNbOfChannels()>1){ - if (ChannelMappedOnSameHW(wCommand)){ - if (debug) TraceManager.addDev("Checking WriteMult with multicast\n"); - cmdName= "_mwrite" + currElem.getID(); - hcode+="TMLWriteMultCommand " + cmdName + SCCR; - channels="array("+wCommand.getNbOfChannels(); - for(int i=0; i<wCommand.getNbOfChannels(); i++){ - channels+="," + wCommand.getChannel(i).getExtendedName(); - } - channels+=")," + wCommand.getNbOfChannels(); - }else{ - if (debug) TraceManager.addDev("Checking WriteMult with unicast\n"); - TMLWriteChannel prevWrite = null, firstWrite=null; - for(int i=0; i<wCommand.getNbOfChannels(); i++){ - TMLWriteChannel newWrite = new TMLWriteChannel("WriteMult",null); - if(i==0) firstWrite=newWrite; - newWrite.addChannel(wCommand.getChannel(i)); - newWrite.setNbOfSamples(wCommand.getNbOfSamples()); - if (prevWrite!=null) prevWrite.addNext(newWrite); - prevWrite=newWrite; - } - prevWrite.addNext(wCommand.getNextElement(0)); - return makeCommands(firstWrite, false, retElement,null); - } - }else{ - cmdName= "_write" + currElem.getID(); - hcode+="TMLWriteCommand " + cmdName + SCCR; - channels=wCommand.getChannel(0).getExtendedName(); - } - if (isIntValue(wCommand.getNbOfSamples())) - initCommand+= "," + cmdName + "("+currElem.getID()+",this,0," + channels + "," + getFormattedLiveVarStr(currElem) + "," + wCommand.getNbOfSamples() + ")" +CR; - else - initCommand+= "," + cmdName + "("+currElem.getID()+",this," + makeCommandLenFunc(cmdName, wCommand.getNbOfSamples(), null) + "," + channels + "," + getFormattedLiveVarStr(currElem) + ")"+CR; - nextCommand= cmdName + ".setNextCommand(array(1,(TMLCommand*)" + makeCommands(currElem.getNextElement(0),false,retElement,null) + "))"+ SCCR; - - } else if (currElem instanceof TMLSendEvent){ - if (debug) TraceManager.addDev("Checking Send\n"); - TMLSendEvent sendEvt=(TMLSendEvent)currElem; - cmdName= "_send" + currElem.getID(); - hcode+="TMLSendCommand " + cmdName + SCCR; - handleParameters(currElem, cmdName, false, getFormattedLiveVarStr(currElem)); - nextCommand= cmdName + ".setNextCommand(array(1,(TMLCommand*)" + makeCommands(currElem.getNextElement(0),false,retElement,null) + "))"+ SCCR; - - } else if (currElem instanceof TMLSendRequest){ - if (debug) TraceManager.addDev("Checking Request\n"); - TMLSendRequest sendReq=(TMLSendRequest)currElem; - cmdName= "_request" + currElem.getID(); - hcode+="TMLRequestCommand " + cmdName + SCCR; - handleParameters(currElem, cmdName, false, getFormattedLiveVarStr(currElem)); - nextCommand= cmdName + ".setNextCommand(array(1,(TMLCommand*)" + makeCommands(currElem.getNextElement(0),false,retElement,null) + "))"+ SCCR; - - } else if (currElem instanceof TMLWaitEvent){ - if (debug) TraceManager.addDev("Checking Wait\n"); - TMLWaitEvent waitEvt = (TMLWaitEvent)currElem; - cmdName= "_wait" + currElem.getID(); - hcode+="TMLWaitCommand " + cmdName + SCCR; - handleParameters(currElem, cmdName, true, getFormattedLiveVarStr(currElem)); - nextCommand= cmdName + ".setNextCommand(array(1,(TMLCommand*)" + makeCommands(currElem.getNextElement(0),false,retElement,null) + "))"+ SCCR; - - } else if (currElem instanceof TMLNotifiedEvent){ - if (debug) TraceManager.addDev("Checking Notified\n"); - cmdName= "_notified" + currElem.getID(); - hcode+="TMLNotifiedCommand " + cmdName + SCCR; - initCommand+= "," + cmdName + "("+currElem.getID()+",this," + ((TMLNotifiedEvent)currElem).getEvent().getExtendedName() + ",&" + ((TMLNotifiedEvent)currElem).getVariable() +",\"" + ((TMLNotifiedEvent)currElem).getVariable() + "\"," + getFormattedLiveVarStr(currElem) + ")" + CR; - nextCommand= cmdName + ".setNextCommand(array(1,(TMLCommand*)" + makeCommands(currElem.getNextElement(0),false,retElement,null) + "))"+ SCCR; - - } else if (currElem instanceof TMLSequence){ - TMLSequence tmlseq = (TMLSequence)currElem; - if (debug) TraceManager.addDev("Checking Sequence with "+ tmlseq.getNbNext()+ " elements."); - if (tmlseq.getNbNext() == 0) { - return retElement; - } else { - if (tmlseq.getNbNext() == 1) { - return makeCommands(currElem.getNextElement(0), false,retElement,null); - } else { - String nextBranch; - tmlseq.sortNexts(); - if (debug) TraceManager.addDev("Checking Sequence branch "+ (tmlseq.getNbNext()-1)); - nextBranch= makeCommands(currElem.getNextElement(currElem.getNbNext() - 1),false,retElement,null); - for(int i=currElem.getNbNext() - 2; i>=0; i--) { - if (debug) TraceManager.addDev("Checking Sequence branch "+ i); - nextBranch=makeCommands(currElem.getNextElement(i),false,nextBranch,null); - } - return nextBranch; - } - } - - } else if (currElem instanceof TMLChoice){ - String elemName=currElem.getName(), idString; - if (elemName.charAt(0)=='#'){ - int pos=elemName.indexOf('\\'); - idString=elemName.substring(1,pos); - //TraceManager.addDev(elemName + "***" + pos + "***" + idString + "***"+ elemName.length()); - cmdName="_" + elemName.substring(pos+1) + idString; - }else{ - cmdName= "_choice" + currElem.getID(); - idString=String.valueOf(currElem.getID()); - } - TMLChoice choice = (TMLChoice)currElem; - String code = "", nextCommandTemp="", stopCmdToAdd=""; - int noOfGuards=0; - if (debug) TraceManager.addDev("Checking Choice\n"); - if (choice.getNbGuard() !=0 ) { - //int indexElseG = choice.getElseGuard(), indexAfterG = choice.getAfterGuard(); - int noNonDetGuards = choice.nbOfNonDeterministicGuard(); - int noStochGuards = choice.nbOfStochasticGuard(); - if (noNonDetGuards>0){ //Non-Deterministic choice - code+= "oMin=0;\n"; - code+= "oMax=" + (noNonDetGuards-1) + SCCR; - //code += "rnd__0 = myrand(0, "+ noNonDetGuards + ")" + SCCR; - code += "return myrand(0, "+ (noNonDetGuards-1) + ")" + SCCR; - for(int i=0; i<noNonDetGuards; i++) { - //code += "if (rnd__0 < " + Math.floor(100/noNonDetGuards)*(i+1) + ") return " + i + SCCR; - nextCommandTemp+= ",(TMLCommand*)" + makeCommands(choice.getNextElement(i), false, retElement,null); - } - noOfGuards = noNonDetGuards; - //code+= "return " + (noNonDetGuards-1) + SCCR; - }else if(noStochGuards>0){ //Stochastic choice - code+= "oMin=0;\n"; - code+= "oMax=" + (noStochGuards-1) + SCCR; - code += "rnd__0 = myrand(0, 99)" + SCCR; - String composedGuard=""; - for(int i=0; i<choice.getNbGuard(); i++) { - if (choice.isStochasticGuard(i)) { - if (composedGuard.isEmpty()) { - composedGuard = formatGuard(choice.getStochasticGuard(i)); - } else { - composedGuard = composedGuard + "+" + formatGuard(choice.getStochasticGuard(i)); - } - code += "if (rnd__0 < (" + composedGuard + ")) return " + noOfGuards + SCCR; - nextCommandTemp+= ",(TMLCommand*)" + makeCommands(choice.getNextElement(i), false, retElement,null); - noOfGuards++; - } - } - - }else{ - int indElseGuard = choice.getElseGuard(), newIndElseGuard=-1; - code+= "unsigned int oC=0;\n"; - code+= "oMin=-1;\n"; - code+= "oMax=0;\n"; - for(int i=0; i<choice.getNbGuard(); i++) { - if (!(choice.isNonDeterministicGuard(i) || choice.isStochasticGuard(i))){ - if (i==indElseGuard){ - newIndElseGuard=noOfGuards; - if (retElseElement!=null) - nextCommandTemp+= ",(TMLCommand*)" +makeCommands(choice.getNextElement(indElseGuard), false, retElseElement,null); - else - nextCommandTemp+= ",(TMLCommand*)" + makeCommands(choice.getNextElement(indElseGuard), false, retElement,null); - - }else{ - code += "if "+ formatAction(formatGuard(choice.getGuard(i))) + "{\noC++;\n"; - code += "oMax += " + (1 << noOfGuards) + SCCR + "\n}\n"; - nextCommandTemp += ",(TMLCommand*)" + makeCommands(choice.getNextElement(i), false, retElement,null); - } - noOfGuards++; - } - } - //if (newIndElseGuard!=-1){ - if (newIndElseGuard==-1){ - newIndElseGuard= noOfGuards; - stopCmdToAdd = ",(TMLCommand*)&_stop" + idString; - noOfGuards++; - hcode+="TMLStopCommand " + "_stop" + idString + SCCR; - initCommand+= ", _stop" + idString + "(" + idString + ",this)" + CR; - } - code += "if (oMax==0){\n oMax=" + (1 << newIndElseGuard) + SCCR; - //code += "oC=1;\n}\n"; - code += "return " + newIndElseGuard + ";\n}\n"; - //} - code += "return getEnabledBranchNo(myrand(1,oC), oMax);\n"; - } - //nextCommand= cmdName + ".setNextCommand(array(" + noOfGuards + nextCommandTemp + "))" + SCCR; - nextCommand= cmdName + ".setNextCommand(array(" + noOfGuards + nextCommandTemp + stopCmdToAdd+ "))" + SCCR; - } - //if (choice.nbOfNonDeterministicGuard()==0 && choice.nbOfStochasticGuard()==0) - // hcode+="TMLChoiceCommand " + cmdName + SCCR; - //else - hcode+="TMLRandomChoiceCommand " + cmdName + SCCR; - initCommand+= "," + cmdName + "("+ idString +",this,(RangeFuncPointer)&" + reference + "::" + cmdName + "_func," + noOfGuards + "," + getFormattedLiveVarStr(currElem) + ")"+CR; - functions+="unsigned int "+ reference + "::" + cmdName + "_func(ParamType& oMin, ParamType& oMax){" + CR + code +CR+ "}" + CR2; - functionSig+="unsigned int " + cmdName + "_func(ParamType& oMin, ParamType& oMax)" + SCCR; - - } else if (currElem instanceof TMLSelectEvt){ - TMLEvent evt; - //Integer nbevt=0; - int nbevt=0; - String evtList="",paramList=""; - if (debug) TraceManager.addDev("Checking SelectEvt\n"); - cmdName= "_select" + currElem.getID(); - for(int i=0; i<currElem.getNbNext(); i++) { - evt=((TMLSelectEvt)currElem).getEvent(i); - if (evt!=null){ - nbevt++; - evtList += ",(TMLEventChannel*)"+ evt.getExtendedName(); - if (evt.getNbOfParams()==0) { - paramList+=",(ParamFuncPointer)0"; - }else{ - - //functionSig+="Parameter<ParamType>* " + cmdName + "_func_" + i + "(Parameter<ParamType>* ioParam)" + SCCR; - //functions+="Parameter<ParamType>* " + reference + "::" + cmdName + "_func_" + i + "(Parameter<ParamType>* ioParam){" + CR; - functionSig+="Parameter* " + cmdName + "_func_" + i + "(Parameter* ioParam)" + SCCR; - functions+="Parameter* " + reference + "::" + cmdName + "_func_" + i + "(Parameter* ioParam){" + CR; - - paramList+=",(ParamFuncPointer)&" + reference + "::" + cmdName + "_func_" + i + CR; - functions += "ioParam->getP(&" + ((TMLSelectEvt)currElem).getParam(i,0); - for(int j=1; j<evt.getNbOfParams(); j++) { - functions+= ", &" + ((TMLSelectEvt)currElem).getParam(i,j); - } - functions+=");\nreturn 0;\n}\n\n"; - } - nextCommand+= ",(TMLCommand*)" + makeCommands(currElem.getNextElement(i), true, retElement,null); - } - } - hcode+="TMLSelectCommand " + cmdName + SCCR; - initCommand+= "," + cmdName + "("+currElem.getID()+",this,array("+ nbevt + evtList + "),"+ nbevt + "," + getFormattedLiveVarStr(currElem) + ",array("+ nbevt + paramList + "))"+CR; - nextCommand=cmdName + ".setNextCommand(array(" + nbevt + nextCommand + "))" + SCCR; - - } else { - TraceManager.addDev("Operator: " + currElem + " of class " + currElem.getClass().getName() + " is not managed in the current version of this C++ code generator."); - } - chaining+=nextCommand; - return (cmdName.equals("0") || cmdName.charAt(0)=='&')? cmdName : "&"+cmdName; - } - - private String formatGuard(String guard){ - guard = Conversion.replaceAllChar(guard, '[', "("); - guard = Conversion.replaceAllChar(guard, ']', ")"); - return guard; - } - - public static String formatAction(String action){ - action = action.replaceAll("not\\s","!"); - action = action.replaceAll("not\\(","!("); - action = action.replaceAll("\\sand\\s","&&"); - action = action.replaceAll("\\sand\\(","&&("); - action = action.replaceAll("\\)and\\s",")&&"); - action = action.replaceAll("\\)and\\(",")&&("); - action = action.replaceAll("\\sor\\s","||"); - action = action.replaceAll("\\sor\\(","||("); - action = action.replaceAll("\\)or\\s",")||"); - action = action.replaceAll("\\)or\\(",")||("); - //action = action.replaceAll("[\\s(]or[\\s)]","||"); - return action; - } - - private boolean ChannelMappedOnSameHW(TMLWriteChannel writeCmd){ - LinkedList<HwCommunicationNode> commNodeRefList = tmlmapping.findNodesForElement(writeCmd.getChannel(0)); - for(int i=1; i<writeCmd.getNbOfChannels(); i++){ - LinkedList<HwCommunicationNode> commNodeCmpList = tmlmapping.findNodesForElement(writeCmd.getChannel(i)); - if (commNodeCmpList.size()!=commNodeRefList.size()) return false; - Iterator it = commNodeCmpList.iterator(); - for(HwCommunicationNode cmnode: commNodeRefList) { - if (it.next()!=cmnode) return false; - } - } - return true; - } - - - private String makeCommandLenFunc(String cmdName, String lowerLimit, String upperLimit){ - if (upperLimit==null) - functions+="TMLLength "+ reference + "::" + cmdName + "_func(){\nreturn (TMLLength)(" + modifyString(lowerLimit) + ");\n}" + CR2; - else - functions+="TMLLength "+ reference + "::" + cmdName + "_func(){\nreturn (TMLLength)myrand(" + lowerLimit + "," + modifyString(upperLimit) + ");\n}" + CR2; - functionSig+="TMLLength " + cmdName + "_func()" + SCCR; - return "(LengthFuncPointer)&" + reference + "::" + cmdName + "_func"; - } - - private String makeCommandRangeFunc(String cmdName, String lowerLimit, String upperLimit){ - functions+="unsigned int "+ reference + "::" + cmdName + "_func(ParamType& oMin, ParamType& oMax){\n oMin=" + modifyString(lowerLimit) + ";\noMax=" + modifyString(upperLimit) + SCCR + "return myrand(oMin, oMax)" + SCCR; - functions+= "}" + CR2; - functionSig+="unsigned int " + cmdName + "_func(ParamType & oMin, ParamType& oMax)" + SCCR; - return "(RangeFuncPointer)&" + reference + "::" + cmdName + "_func"; - } - - private boolean isIntValue(String input){ - try{ - Integer.parseInt(input); - return true; - }catch(Exception e){ - return false; - } - } - - private void handleParameters(TMLActivityElement currElem, String cmdName, boolean wait, String liveVarString){ - String concatParams="", channelName=""; - String[] paramArray=null; - //boolean areStatic=true; - int nbOfParams=0; - String address=(wait)? "&":""; - if (currElem instanceof TMLActivityElementEvent){ - nbOfParams=((TMLActivityElementEvent)currElem).getNbOfParams(); - paramArray = new String[nbOfParams]; - for (int i=0; i< nbOfParams; i++){ - paramArray[i]=((TMLActivityElementEvent)currElem).getParam(i); - } - channelName = ((TMLActivityElementEvent)currElem).getEvent().getExtendedName(); - } - else if (currElem instanceof TMLSendRequest){ - nbOfParams=((TMLSendRequest)currElem).getNbOfParams(); - paramArray = new String[nbOfParams]; - for (int i=0; i< nbOfParams; i++){ - paramArray[i]=((TMLSendRequest)currElem).getParam(i); - } - channelName = ((TMLSendRequest)currElem).getRequest().getExtendedName(); - } - if (nbOfParams==0){ - initCommand+= "," + cmdName + "("+ currElem.getID() +",this," + channelName + ",0," + liveVarString +")"+CR; - }else{ - for(int i=0; i<nbOfParams; i++){ - //if(areStatic && !isIntValue(paramArray[i])) areStatic=false; - if (i>0) concatParams+=","; - //concatParams+=","; - if (paramArray[i]==null || paramArray[i].isEmpty()) concatParams+="0"; else concatParams+= address + paramArray[i]; - } - //if (areStatic){ - //initCommand+= "," + cmdName + "("+ currElem.getID() +",this," + channelName + ",0," + liveVarString + ",Parameter<ParamType>(" + nbOfParams + "," + concatParams + "))"+CR; - //initCommand+= "," + cmdName + "("+ currElem.getID() +",this," + channelName + ",0," + liveVarString + ",new SizedParameter<ParamType," + nbOfParams + ">(" + concatParams + "))"+CR; - //}else{ - initCommand+= "," + cmdName + "("+ currElem.getID() +",this," + channelName + ",(ParamFuncPointer)&" + reference + "::" + cmdName + "_func,"+ liveVarString + ")" + CR; - //functionSig+="Parameter<ParamType>* " + cmdName + "_func(Parameter<ParamType>* ioParam)" + SCCR; - //functions+="Parameter<ParamType>* " + reference + "::" + cmdName + "_func(Parameter<ParamType>* ioParam){" + CR; - functionSig+="Parameter* " + cmdName + "_func(Parameter* ioParam)" + SCCR; - functions+="Parameter* " + reference + "::" + cmdName + "_func(Parameter* ioParam){" + CR; - if (wait) - functions += "ioParam->getP(" + concatParams + ")" + SCCR + "return 0" + SCCR; - else - //functions += "return new Parameter<ParamType>(" + nbOfParams + "," + concatParams + ")" + SCCR; - functions += "return new SizedParameter<ParamType," + nbOfParams + ">(" + concatParams + ")" + SCCR; - functions+="}\n\n"; - //} - } - } - - private void makeEndClassH() { - hcode += "};" + CR + "#endif" + CR; - } - - - private String makeAttributesCode() { - String code = ""; - int i; - for(TMLAttribute att: task.getAttributes()) { - //if (!att.name.endsWith("__req")){ //NEW - if (att.hasInitialValue()) - code += ","+ att.name + "(" + att.initialValue + ")"+CR; - else - code += ","+ att.name + "(0)"+CR; - //} - } - //code += ",arg1__req(0)"+CR; - //code += ",arg2__req(0)"+CR; - //code += ",arg3__req(0)"+CR; - return code; - } - - private String makeAttributesDeclaration() { - String code = ""; - int i; - for(TMLAttribute att: task.getAttributes()) { - //if (!att.name.endsWith("__req")){ //NEW - code += "ParamType " + att.name; - code += ";\n"; - //} - } - //code += "ParamType arg1__req" + SCCR; - //code += "ParamType arg2__req" + SCCR; - //code += "ParamType arg3__req" + SCCR; - code += "ParamType rnd__0" + SCCR; - code += "TMLChannel* _channels[" + (channels.size() + events.size() + (task.isRequested()? 1:0)) + "]" + SCCR; - return code; - } - - - private String addSemicolonIfNecessary(String _input) { - String code1 = _input.trim(); - if (!(code1.endsWith(";"))) { - code1 += ";"; - } - return code1; - } - - private String modifyString(String _input) { - _input = Conversion.changeBinaryOperatorWithUnary(_input, "div", "/"); - _input = Conversion.changeBinaryOperatorWithUnary(_input, "mod", "%"); - return _input; - } - - public String getIdentifierNameByID(int id){ - //Channels, Events, Requests, Variables, Choice, Random - id=Math.abs(id); - for (TMLChannel channel: channels){ - if (channel.getID()==id) return channel.getName(); - } - for (TMLEvent event: events){ - if (event.getID()==id) return event.getName(); - /*int param = Integer.MAX_VALUE - 3 * event.getID() - id + 1; - if (param>0 && param<4) return event.getName() + "_param" + param;*/ - } - for (TMLRequest request: requests){ - if (request.getID()==id) return request.getName(); - /*int param = Integer.MAX_VALUE - 3 * request.getID() - id +1; - if (param>0 && param<4) return request.getName() + "_param!" + param;*/ - } - for(TMLAttribute att: task.getAttributes()){ - if (att.getID()==id) return reference + ":" + att.getName(); - } - for(int i=0; i<task.getActivityDiagram().nElements();i++) - if (task.getActivityDiagram().get(i).getID()==id) return reference + ":Command " + id; - return null; - } - - public void determineCheckpoints(int[] aStatistics){ - _analysis.determineCheckpoints(aStatistics); - } - - public StaticAnalysis getAnalysis(){ - return _analysis; - } + //private TMLModeling tmlm; + private TMLTask task; + private String reference, cppcode, hcode, initCommand, functions, functionSig, chaining, firstCommand, commentText; + private ArrayList<TMLChannel> channels; + private ArrayList<TMLEvent> events; + private ArrayList<TMLRequest> requests; + private TMLMapping tmlmapping; + private int commentNum; + private boolean debug; + private boolean optimize; + private StaticAnalysis _analysis; + private LiveVariableNode _startAnaNode=null; + + private final static String DOTH = ".h"; + private final static String DOTCPP = ".cpp"; + private final static String SYSTEM_INCLUDE = "#include \"systemc.h\""; + private final static String CR = "\n"; + private final static String CR2 = "\n\n"; + private final static String SCCR = ";\n"; + private final static String EFCR = "}\n"; + private final static String EFCR2 = "}\n\n"; + private final static String EF = "}"; + + + public MappedSystemCTask(TMLTask _task, ArrayList<TMLChannel> _channels, ArrayList<TMLEvent> _events, ArrayList<TMLRequest> _requests, TMLMapping _tmlmapping, Set<Integer> _depChannels) { + task = _task; + channels = _channels; + events = _events; + requests = _requests; + tmlmapping=_tmlmapping; + reference = task.getName(); + cppcode = ""; + hcode = ""; + initCommand=""; + functions=""; + chaining=""; + firstCommand=""; + functionSig=""; + commentText=""; + commentNum=0; + optimize=false; + + //for(TMLAttribute att: task.getAttributes()) { + // TraceManager.addDev ("************ Attribute: " + att.name); + //} + + _analysis = new StaticAnalysis(_task, _channels, _events, _requests, _depChannels); + _startAnaNode = _analysis.startAnalysis(); + } + + public void saveInFiles(String path) throws FileException { + FileUtils.saveFile(path + reference + DOTH, getHCode()); + FileUtils.saveFile(path + reference + DOTCPP, getCPPCode()); + } + + public TMLTask getTMLTask() { + return task; + } + + public void generateSystemC(boolean _debug, boolean _optimize) { + //_startAnaNode = _analysis.startAnalysis(); + //_analysis.determineCheckpoints(aStatistics); //NEW + debug = _debug; + optimize=_optimize; + basicCPPCode(); + makeClassCode(); + } + + public void print() { + TraceManager.addDev("task: " + reference + DOTH + hcode); + TraceManager.addDev("task: " + reference + DOTCPP + cppcode); + } + + + public String getCPPCode() { + return cppcode; + } + + public String getHCode() { + return hcode; + } + + public String getReference() { + return reference; + } + + // H-Code + private String basicHCode() { + String code=""; + code += "#ifndef " + reference.toUpperCase() + "__H" + CR; + code += "#define " + reference.toUpperCase() + "__H" + CR2; + code += "#include <TMLTask.h>\n#include <definitions.h>\n\n"; + code += "#include <TMLbrbwChannel.h>\n#include <TMLbrnbwChannel.h>\n#include <TMLnbrnbwChannel.h>\n\n"; + code += "#include <TMLEventBChannel.h>\n#include <TMLEventFChannel.h>\n#include <TMLEventFBChannel.h>\n\n"; + code += "#include <TMLActionCommand.h>\n#include <TMLChoiceCommand.h>\n#include <TMLRandomChoiceCommand.h>\n#include <TMLExeciCommand.h>\n"; + code += "#include <TMLSelectCommand.h>\n#include <TMLReadCommand.h>\n#include <TMLNotifiedCommand.h>\n#include<TMLExeciRangeCommand.h>\n"; + code += "#include <TMLRequestCommand.h>\n#include <TMLSendCommand.h>\n#include <TMLWaitCommand.h>\n"; + code += "#include <TMLWriteCommand.h>\n#include <TMLStopCommand.h>\n#include<TMLWriteMultCommand.h>\n#include <TMLRandomCommand.h>\n\n"; + code += "extern \"C\" bool condFunc(TMLTask* _ioTask_);\n"; + return code; + } + + private void classHCode() { + } + + // CPP Code + private void basicCPPCode() { + cppcode += "#include <" + reference + DOTH + ">" + CR2; + } + + private void makeClassCode(){ + makeHeaderClassH(); + makeEndClassH(); + + cppcode+=reference+ "::" + makeConstructorSignature()+":TMLTask(iID, iPriority,iName,iCPUs,iNumOfCPUs)"+ CR + makeAttributesCode(); + cppcode+=initCommand + CR + "{" + CR; + if (commentNum!=0) cppcode+= "_comment = new std::string[" + commentNum + "]" + SCCR + commentText + CR; + cppcode+= "//generate task variable look-up table"+ CR; + for(TMLAttribute att: task.getAttributes()) { + //att = (TMLAttribute)(iterator.next()); + //code += TMLType.getStringType(att.type.getType()) + " " + att.name; + cppcode += "_varLookUpName[\"" + att.name + "\"]=&" + att.name +SCCR; + cppcode += "_varLookUpID[" + att.getID() + "]=&" + att.name +SCCR; + } + cppcode += "_varLookUpName[\"rnd__0\"]=&rnd__0" + SCCR + CR; + cppcode+= "//set blocked read task/set blocked write task"+ CR; + for(TMLChannel ch: channels) { + if (ch.getOriginTask()==task) + cppcode+=ch.getExtendedName() + "->setBlockedWriteTask(this)"+SCCR; + else + cppcode+=ch.getExtendedName() + "->setBlockedReadTask(this)"+SCCR; + } + for(TMLEvent evt: events) { + if (evt.getOriginTask()==task) + cppcode+=evt.getExtendedName() + "->setBlockedWriteTask(this)"+SCCR; + else + cppcode+=evt.getExtendedName() + "->setBlockedReadTask(this)"+SCCR; + } + if (task.isRequested()) cppcode+="requestChannel->setBlockedReadTask(this)" +SCCR; + for(TMLRequest req: requests) { + if (req.isAnOriginTask(task)) cppcode+=req.getExtendedName() + "->setBlockedWriteTask(this)" +SCCR; + } + cppcode+=CR + "//command chaining"+ CR; + cppcode+= chaining + "_currCommand=" + firstCommand + SCCR + "_firstCommand=" + firstCommand +SCCR + CR; + int aSeq=0; + for(TMLChannel ch: channels) { + cppcode+= "_channels[" + aSeq + "] = " + ch.getExtendedName() + SCCR; + aSeq++; + } + for(TMLEvent evt: events) { + cppcode+= "_channels[" + aSeq + "] = " + evt.getExtendedName() + SCCR; + aSeq++; + } + if (task.isRequested()){ + cppcode+= "_channels[" + aSeq + "] = requestChannel" + SCCR; + } + TMLActivityElement currElem=task.getActivityDiagram().getFirst(); + LiveVariableNode currNode; + do{ + currNode = _analysis.getLiveVarNodeByCommand(currElem); + TraceManager.addDev("currElem=" + currElem); + currElem = currElem.getNextElement(0); + }while (currNode==null && currElem!=null); + if (currNode!=null) cppcode+= "refreshStateHash(" + currNode.getStartLiveVariableString() + ")" +SCCR; + cppcode+="}"+ CR2 + functions; // + makeDestructor(); + hcode = Conversion.indentString(hcode, 4); + cppcode = Conversion.indentString(cppcode, 4); + } + + private String makeDestructor(){ + String dest=reference + "::~" + reference + "(){" + CR; + if (commentNum!=0) dest+="delete[] _comment" + SCCR; + return dest+"}"+CR; + } + + private String makeConstructorSignature(){ + String constSig=reference+ "(ID iID, Priority iPriority, std::string iName, CPU** iCPUs, unsigned int iNumOfCPUs"+CR; + for(TMLChannel ch: channels) { + constSig+=", TMLChannel* "+ ch.getExtendedName() + CR; + } + for(TMLEvent evt: events) { + constSig+=", TMLEventChannel* "+ evt.getExtendedName() +CR; + } + for(TMLRequest req: requests) { + //if (req.isAnOriginTask(task)) constSig+=", TMLEventBChannel* " + req.getExtendedName() + CR; + if (req.isAnOriginTask(task)) constSig+=", TMLEventChannel* " + req.getExtendedName() + CR; + } + if (task.isRequested()){ + //constSig+=", TMLEventBChannel* requestChannel"+CR; + constSig+=", TMLEventChannel* requestChannel"+CR; + } + return constSig+")"; + } + + private void makeHeaderClassH() { + String hcodeBegin=""; + hcodeBegin = "class " + reference + ": public TMLTask {" + CR; + hcodeBegin += "private:" + CR; + + hcodeBegin += "// Attributes" + CR; + + if (task.isRequested()) { + int params = task.getRequest().getNbOfParams(); + firstCommand="_waitOnRequest"; + hcode+="TMLWaitCommand " + firstCommand + SCCR; + initCommand+= "," + firstCommand + "(" + task.getActivityDiagram().getFirst().getID() + ",this,requestChannel,"; + if (params==0){ + initCommand+= "0,"+ getFormattedLiveVarStr(_startAnaNode) + ")" + CR; + }else{ + initCommand+= "(ParamFuncPointer)&" + reference + "::" + "waitOnRequest_func," + getFormattedLiveVarStr(_startAnaNode) + ")" + CR; + //functionSig+="Parameter<ParamType>* waitOnRequest_func(Parameter<ParamType>* ioParam)" + SCCR; + //functions+="Parameter<ParamType>* " + reference + "::waitOnRequest_func(Parameter<ParamType>* ioParam){" + CR; + + functionSig+="Parameter* waitOnRequest_func(Parameter* ioParam)" + SCCR; + functions+="Parameter* " + reference + "::waitOnRequest_func(Parameter* ioParam){" + CR; + functions+= "ioParam->getP(&arg1__req"; + for (int i=1; i<params; i++){ + functions+= ", &arg" + (i+1) + "__req"; + } + functions+=")" + SCCR + "return 0" + SCCR; + functions+="}\n\n"; + } + String xx = firstCommand + ".setNextCommand(array(1,(TMLCommand*)" + makeCommands(task.getActivityDiagram().getFirst(),false,"&"+firstCommand,null) + "))"+ SCCR; + firstCommand="&"+firstCommand; + chaining+=xx; + }else{ + firstCommand=makeCommands(task.getActivityDiagram().getFirst(),false,"0",null); + } + + hcode = basicHCode() + hcodeBegin + makeAttributesDeclaration() + CR + hcode; + // public dec + hcode += CR + functionSig + CR + "public:" + CR; + hcode += "friend bool condFunc(TMLTask* _ioTask_);\n"; + hcode += "friend class CurrentComponents;\n"; + // Simulation + hcode += makeConstructorSignature() + SCCR; // + "~" + reference + "()" + SCCR; + makeSerializableFuncs(); + } + + private void makeSerializableFuncs(){ + hcode += "std::istream& readObject(std::istream& i_stream_var)" + SCCR; + hcode += "std::ostream& writeObject(std::ostream& i_stream_var)" + SCCR; + //hcode += "unsigned long getStateHash() const" + SCCR; + functions+= "std::istream& " + reference + "::readObject(std::istream& i_stream_var){\n"; + for (TMLAttribute att:task.getAttributes()){ + //att = (TMLAttribute)(iterator.next()); + functions += "READ_STREAM(i_stream_var," + att.name + ")" + SCCR; + functions += "#ifdef DEBUG_SERIALIZE\n"; + functions += "std::cout << \"Read: Variable " + att.name + " \" << " + att.name + " << std::endl" + SCCR; + functions += "#endif\n"; + } + functions+= "TMLTask::readObject(i_stream_var);\nreturn i_stream_var;\n}\n\n"; + functions+= "std::ostream& " + reference + "::writeObject(std::ostream& i_stream_var){\n"; + for (TMLAttribute att:task.getAttributes()){ + functions += "WRITE_STREAM(i_stream_var," + att.name + ")" + SCCR; + functions += "#ifdef DEBUG_SERIALIZE\n"; + functions += "std::cout << \"Write: Variable " + att.name + " \" << " + att.name + " << std::endl" + SCCR; + functions += "#endif\n"; + } + functions+= "TMLTask::writeObject(i_stream_var);\nreturn i_stream_var;\n}\n\n"; + hcode += "void reset()" + SCCR; + functions+= "void "+reference + "::reset(){\nTMLTask::reset();\n"; + for (TMLAttribute att:task.getAttributes()){ + functions += att.name + "="; + if (att.hasInitialValue()) + functions += att.initialValue + SCCR; + else + functions += "0" + SCCR; + } + functions+= "}\n\n"; + /*hcode += "void refreshStateHash(const char* iLiveVarList);\n"; + functions+= "void " + reference + "::refreshStateHash(const char* iLiveVarList){\n"; + int aSeq=0; + functions += "_stateHash.init((HashValueType)_ID,30);\nif(iLiveVarList!=0){\n";*/ + hcode += "HashValueType getStateHash();\n"; + functions+= "HashValueType " + reference + "::getStateHash(){\n"; + int aSeq=0; + //functions += "if(_liveVarList!=0 && _hashInvalidated){\n"; + functions += "if(_hashInvalidated){\n"; + functions += "_hashInvalidated=false;\n_stateHash.init((HashValueType)_ID,30);\n"; + functions += "if(_liveVarList!=0){\n"; + for(TMLAttribute att: task.getAttributes()) { + functions += "if ((_liveVarList[" + (aSeq >>> 3) + "] & " + (1 << (aSeq & 0x7)) + ")!=0) _stateHash.addValue(" + att.getName() + ");\n"; + //functions += "_stateHash.addValue(" + att.getName() + ");\n"; + aSeq++; + } + int i=0; + //for channels: include hash only if performed action is blocking + //for events: include filling level for senders (notified possible), include parameters for readers (if parameters set) + for(TMLChannel ch: channels) { + if (ch.getType()==TMLChannel.BRBW || (ch.getType()==TMLChannel.BRNBW && ch.getDestinationTask()==task)) functions += "_channels[" + i +"]->setSignificance(this, " + "((_liveVarList[" + (aSeq >>> 3) + "] & " + (1 << (aSeq & 0x7)) + ")!=0));\n"; + //if (ch.getType()==TMLChannel.BRBW || (ch.getType()==TMLChannel.BRNBW && ch.getDestinationTask()==task)) functions += "_channels[" + i +"]->setSignificance(this, true);\n"; + + aSeq++; i++; + } + for(TMLEvent evt: events) { + if (evt.isBlocking() || evt.getDestinationTask()==task) functions += " _channels[" + i +"]->setSignificance(this, " + "((_liveVarList[" + (aSeq >>> 3) + "] & " + (1 << (aSeq & 0x7)) + ")!=0));\n"; + //if (evt.isBlocking() || evt.getDestinationTask()==task) functions += " _channels[" + i +"]->setSignificance(this, true);\n"; + aSeq++; i++; + } + if (task.isRequested()){ + functions += " _channels[" + i +"]->setSignificance(this, " + "((_liveVarList[" + (aSeq >>> 3) + "] & " + (1 << (aSeq & 0x7)) + ")!=0));\n"; + //functions += " _channels[" + i +"]->setSignificance(this, true);\n"; + } + /*for(i=0; i< channels.size() + events.size() + (task.isRequested()? 1:0) ; i++){ + functions += "if ((iLiveVarList[" + (aSeq >>> 3) + "] & " + (1 << (aSeq & 0x7)) + ")!=0) _channels[" + i +"]->getStateHash(iHash);\n"; + aSeq++; + }*/ + //functions += "}\n}\n\n"; + functions += "}\n}\nreturn _stateHash.getHash();\n}\n\n"; + } + + private String getFormattedLiveVarStr(TMLActivityElement currElem){ + return getFormattedLiveVarStr(_analysis.getLiveVarNodeByCommand(currElem)); + //return getFormattedLiveVarStr((LiveVariableNode)null); + } + + private String getFormattedLiveVarStr(LiveVariableNode currNode){ + if (currNode==null){ + return "0, false"; + }else{ + String checkpoint = (currNode.isCheckpoint())? "true":"false"; + //String checkpoint = "true"; + return currNode.getLiveVariableString() + "," + checkpoint; + } + } + + + + private String makeCommands(TMLActivityElement currElem, boolean skip, String retElement, String retElseElement){ + String nextCommand="",cmdName=""; + + if (skip) return makeCommands(currElem.getNextElement(0), false,retElement,null); + + if (currElem==null){ + if (debug) TraceManager.addDev("Checking null\n"); + return retElement; + } + + if (debug) TraceManager.addDev("Checking " + currElem.getName() + CR); + + if (currElem instanceof TMLStartState) { + if (debug) TraceManager.addDev("Checking Start\n"); + return makeCommands(currElem.getNextElement(0), false,retElement,null); + + } else if (currElem instanceof TMLStopState){ + //add stop state if (retElement.equals("0")) + if (debug) TraceManager.addDev("Checking Stop\n"); + if (retElement.equals("0")){ + cmdName= "_stop" + currElem.getID(); + hcode+="TMLStopCommand " + cmdName + SCCR; + initCommand+= "," + cmdName + "(" + currElem.getID() + ",this)" + CR; + }else + return retElement; + + }else if (currElem instanceof TMLRandom){ + if (debug) TraceManager.addDev("Checking Random\n"); + cmdName= "_random" + currElem.getID(); + TMLRandom random = (TMLRandom)currElem; + hcode+="TMLRandomCommand " + cmdName + SCCR; + initCommand+= "," + cmdName + "("+ currElem.getID() + ",this," + makeCommandRangeFunc(cmdName, random.getMinValue(), random.getMaxValue()) + ",&" + random.getVariable() + "," + getFormattedLiveVarStr(currElem) + ")"+CR; + nextCommand= cmdName + ".setNextCommand(array(1,(TMLCommand*)" + makeCommands(currElem.getNextElement(0),false,retElement,null) + "));\n"; + //functions+="void "+ reference + "::" + cmdName + "_func(ParamType& oMin, ParamType& oMax){\n oMin=" + modifyString(random.getMinValue()) + ";\noMax=" + modifyString(random.getMaxValue()) + SCCR; + //functions+= "}" + CR2; + //functionSig+="void " + cmdName + "_func(ParamType & oMin, ParamType& oMax)" + SCCR; + + } else if (currElem instanceof TMLActionState || currElem instanceof TMLDelay){ + String action,comment; + if (currElem instanceof TMLActionState){ + if (debug) TraceManager.addDev("Checking Action\n"); + action = formatAction(((TMLActionState)currElem).getAction()); + comment=action; + }else{ + if (debug) TraceManager.addDev("Checking Delay\n"); + int masterClockFreq = tmlmapping.getTMLArchitecture().getMasterClockFrequency(); + TMLDelay delay=(TMLDelay)currElem; + action = "TMLTime tmpDelayxy = " + delay.getMaxDelay() + "*" + masterClockFreq + delay.getMasterClockFactor() + ";"; + comment=action; + action+= "\nif (tmpDelayxy==0) tmpDelayxy=1;\n"; + if (delay.getMinDelay().equals(delay.getMaxDelay())){ + action += "_endLastTransaction+=tmpDelayxy"; + }else{ + action += "TMLTime tmpDelayxx = " + delay.getMinDelay() + "*" + masterClockFreq + delay.getMasterClockFactor() + ";\nif (tmpDelayxx==0) tmpDelayxx=1;\n"; + action += "_endLastTransaction+=myrand(tmpDelayxx,tmpDelayxy)"; + } + } + //cmdName= "_action" + currElem.getID(); + String elemName=currElem.getName(), idString; + if (elemName.charAt(0)=='#'){ + int pos=elemName.indexOf('\\'); + idString=elemName.substring(1,pos); + //TraceManager.addDev(elemName + "***" + pos + "***" + idString + "***"+ elemName.length()); + cmdName="_" + elemName.substring(pos+1) + idString; + }else{ + cmdName= "_action" + currElem.getID(); + idString=String.valueOf(currElem.getID()); + } + hcode+="TMLActionCommand " + cmdName + SCCR; + initCommand+= "," + cmdName + "("+ idString + ",this,(ActionFuncPointer)&" + reference + "::" + cmdName + "_func, " + getFormattedLiveVarStr(currElem) + ")"+CR; + nextCommand= cmdName + ".setNextCommand(array(1,(TMLCommand*)" + makeCommands(currElem.getNextElement(0),false,retElement,null) + "));\n"; + functions+="void "+ reference + "::" + cmdName + "_func(){\n#ifdef ADD_COMMENTS\naddComment(new Comment(_endLastTransaction,0," + commentNum + "));\n#endif\n" + modifyString(addSemicolonIfNecessary(action)) + CR; + //functions+="return 0"+ SCCR; + functions+= "}" + CR2; + commentText+="_comment[" + commentNum + "]=std::string(\"Action " + comment + "\");\n"; + commentNum++; + functionSig+="void " + cmdName + "_func()" + SCCR; + + } else if (currElem instanceof TMLExecI){ + if (debug) TraceManager.addDev("Checking Execi\n"); + cmdName= "_execi" + currElem.getID(); + hcode+="TMLExeciCommand " + cmdName + SCCR; + //initCommand+= "," + cmdName + "(this,"+ ((TMLExecI)currElem).getAction() + ",0,0)"+CR; + if (isIntValue(((TMLExecI)currElem).getAction())) + initCommand+= "," + cmdName + "(" + currElem.getID() + ",this,0,0," + ((TMLExecI)currElem).getAction() + "," + getFormattedLiveVarStr(currElem) + ")" + CR; + else + initCommand+= "," + cmdName + "(" + currElem.getID() + ",this," + makeCommandLenFunc(cmdName, ((TMLExecI)currElem).getAction(), null) + ",0,1," + getFormattedLiveVarStr(currElem) + ")" + CR; + nextCommand= cmdName + ".setNextCommand(array(1,(TMLCommand*)" + makeCommands(currElem.getNextElement(0),false,retElement,null) + "))"+ SCCR; + + } else if (currElem instanceof TMLExecC){ + if (debug) TraceManager.addDev("Checking ExecC\n"); + cmdName= "_execc" + currElem.getID(); + hcode+="TMLExeciCommand " + cmdName + SCCR; + if (isIntValue(((TMLExecC)currElem).getAction())) + initCommand+= "," + cmdName + "(" + currElem.getID() + ",this,0,1," + ((TMLExecC)currElem).getAction() + "," + getFormattedLiveVarStr(currElem) + ")" + CR; + else + initCommand+= "," + cmdName + "("+ currElem.getID() + ",this,"+ makeCommandLenFunc(cmdName, ((TMLExecC)currElem).getAction(), null) + ",1,1," + getFormattedLiveVarStr(currElem) + ")"+CR; + + nextCommand= cmdName + ".setNextCommand(array(1,(TMLCommand*)" + makeCommands(currElem.getNextElement(0),false,retElement,null) + "))"+ SCCR; + + } else if (currElem instanceof TMLExecIInterval){ + /*if (debug) TraceManager.addDev("Checking ExeciInterv\n"); + cmdName= "_execi" + currElem.getID(); + hcode+="TMLExeciCommand " + cmdName + SCCR; + //initCommand+= "," + cmdName + "(this,"+ ((TMLExecIInterval)currElem).getMinDelay()+ "," + ((TMLExecIInterval)currElem).getMaxDelay() + ",0)"+CR; + initCommand+= "," + cmdName + "("+currElem.getID()+",this,"+ makeCommandLenFunc(cmdName, ((TMLExecIInterval)currElem).getMinDelay(), ((TMLExecIInterval)currElem).getMaxDelay()) + ",0,1," + getFormattedLiveVarStr(currElem) + ")" +CR; + nextCommand= cmdName + ".setNextCommand(array(1,(TMLCommand*)" + makeCommands(currElem.getNextElement(0),false,retElement,null) + "))"+ SCCR;*/ + if (debug) TraceManager.addDev("Checking ExeciInterv\n"); + cmdName= "_execi" + currElem.getID(); + hcode+="TMLExeciRangeCommand " + cmdName + SCCR; + initCommand+= "," + cmdName + "("+currElem.getID()+",this,"+ makeCommandRangeFunc(cmdName, ((TMLExecIInterval)currElem).getMinDelay(), ((TMLExecIInterval)currElem).getMaxDelay()) + ",0," + getFormattedLiveVarStr(currElem) + ")" +CR; + nextCommand= cmdName + ".setNextCommand(array(1,(TMLCommand*)" + makeCommands(currElem.getNextElement(0),false,retElement,null) + "))"+ SCCR; + + } else if (currElem instanceof TMLExecCInterval){ + if (debug) TraceManager.addDev("Checking ExecCInterv\n"); + cmdName= "_execc" + currElem.getID(); + hcode+="TMLExeciCommand " + cmdName + SCCR; + //initCommand+= "," + cmdName + "(this,"+ ((TMLExecIInterval)currElem).getMinDelay()+ "," + ((TMLExecIInterval)currElem).getMaxDelay() + ",1)"+CR; + initCommand+= "," + cmdName + "("+currElem.getID()+",this,"+ makeCommandLenFunc(cmdName, ((TMLExecCInterval)currElem).getMinDelay(), ((TMLExecCInterval)currElem).getMaxDelay()) + ",1,1," + getFormattedLiveVarStr(currElem) + ")"+CR; + nextCommand= cmdName + ".setNextCommand(array(1,(TMLCommand*)" + makeCommands(currElem.getNextElement(0),false,retElement,null) + "))"+ SCCR; + + + } else if (currElem instanceof TMLForLoop){ + //makeCommands(TMLActivityElement currElem, boolean skip, String retElement, MergedCmdStr nextCommandCont, String retElseElement) + if (debug) TraceManager.addDev("Checking Loop\n"); + TMLForLoop fl = (TMLForLoop)currElem; + if (fl.getCondition().isEmpty() || fl.getCondition().trim().toUpperCase().equals("TRUE")){ + //initAction.addNext(fl.getNextElement(0)); //inside loop + TMLActionState incAction=new TMLActionState("#"+ fl.getID() + "\\lpIncAc",null); + incAction.setAction(fl.getIncrement()); + String firstCmdInLoop= makeCommands(fl.getNextElement(0), false, "&_lpIncAc" + fl.getID(), null); + makeCommands(incAction, false, firstCmdInLoop, null); + if (fl.getInit().isEmpty()){ + return firstCmdInLoop; + }else{ + TMLActionState initAction=new TMLActionState("lpInitAc",null); + initAction.setAction(fl.getInit()); + return makeCommands(initAction, false, firstCmdInLoop,null); + } + + }else{ + TMLChoice lpChoice=new TMLChoice("#"+ fl.getID() + "\\lpChoice",null); + //if (fl.getCondition().isEmpty()) + // lpChoice.addGuard("[ true ]"); + //else + lpChoice.addGuard("[ " + fl.getCondition() + " ]"); + lpChoice.addGuard("[ else ]"); + lpChoice.addNext(fl.getNextElement(0)); //inside loop + lpChoice.addNext(fl.getNextElement(1)); //after loop cmdName= "_choice" + currElem.getID(); + if (fl.getIncrement().isEmpty()){ + makeCommands(lpChoice, false, "&_lpChoice" + fl.getID(), retElement); + }else{ + TMLActionState incAction=new TMLActionState("#"+ fl.getID() + "\\lpIncAc",null); + incAction.setAction(fl.getIncrement()); + makeCommands(incAction, false, "&_lpChoice" + fl.getID(), null); + makeCommands(lpChoice, false, "&_lpIncAc" + fl.getID(), retElement); + } + if (fl.getInit().isEmpty()){ + return "&_lpChoice" + fl.getID(); + }else{ + TMLActionState initAction=new TMLActionState("lpInitAc",null); + initAction.setAction(fl.getInit()); + return makeCommands(initAction, false, "&_lpChoice" + fl.getID(), null); + } + } + + } else if (currElem instanceof TMLReadChannel){ + if (debug) TraceManager.addDev("Checking Read\n"); + cmdName= "_read" + currElem.getID(); + hcode+="TMLReadCommand " + cmdName + SCCR; + TMLReadChannel rCommand=(TMLReadChannel)currElem; + if (isIntValue(rCommand.getNbOfSamples())) + //initCommand+= "," + cmdName + "("+currElem.getID()+",this,0," + rCommand.getChannel(0).getExtendedName() + "," + rCommand.getChannel(0).getSize() + "*" + rCommand.getNbOfSamples() + ")"+CR; + initCommand+= "," + cmdName + "("+currElem.getID()+",this,0," + rCommand.getChannel(0).getExtendedName() + "," + getFormattedLiveVarStr(currElem) + "," + rCommand.getNbOfSamples() + ")"+CR; + + else + //initCommand+= "," + cmdName + "("+currElem.getID()+",this," + makeCommandLenFunc(cmdName, rCommand.getChannel(0).getSize() + "*(" + rCommand.getNbOfSamples()+")",null) + "," + rCommand.getChannel(0).getExtendedName() + ")"+CR; + initCommand+= "," + cmdName + "("+currElem.getID()+",this," + makeCommandLenFunc(cmdName, rCommand.getNbOfSamples(),null) + "," + rCommand.getChannel(0).getExtendedName() + "," + getFormattedLiveVarStr(currElem) + ")"+CR; + nextCommand= cmdName + ".setNextCommand(array(1,(TMLCommand*)" + makeCommands(currElem.getNextElement(0),false,retElement,null) + "))"+ SCCR; + + } else if (currElem instanceof TMLWriteChannel){ + String channels; + TMLWriteChannel wCommand=(TMLWriteChannel)currElem; + if (wCommand.getNbOfChannels()>1){ + if (ChannelMappedOnSameHW(wCommand)){ + if (debug) TraceManager.addDev("Checking WriteMult with multicast\n"); + cmdName= "_mwrite" + currElem.getID(); + hcode+="TMLWriteMultCommand " + cmdName + SCCR; + channels="array("+wCommand.getNbOfChannels(); + for(int i=0; i<wCommand.getNbOfChannels(); i++){ + channels+="," + wCommand.getChannel(i).getExtendedName(); + } + channels+=")," + wCommand.getNbOfChannels(); + }else{ + if (debug) TraceManager.addDev("Checking WriteMult with unicast\n"); + TMLWriteChannel prevWrite = null, firstWrite=null; + for(int i=0; i<wCommand.getNbOfChannels(); i++){ + TMLWriteChannel newWrite = new TMLWriteChannel("WriteMult",null); + if(i==0) firstWrite=newWrite; + newWrite.addChannel(wCommand.getChannel(i)); + newWrite.setNbOfSamples(wCommand.getNbOfSamples()); + if (prevWrite!=null) prevWrite.addNext(newWrite); + prevWrite=newWrite; + } + prevWrite.addNext(wCommand.getNextElement(0)); + return makeCommands(firstWrite, false, retElement,null); + } + }else{ + cmdName= "_write" + currElem.getID(); + hcode+="TMLWriteCommand " + cmdName + SCCR; + channels=wCommand.getChannel(0).getExtendedName(); + } + if (isIntValue(wCommand.getNbOfSamples())) + initCommand+= "," + cmdName + "("+currElem.getID()+",this,0," + channels + "," + getFormattedLiveVarStr(currElem) + "," + wCommand.getNbOfSamples() + ")" +CR; + else + initCommand+= "," + cmdName + "("+currElem.getID()+",this," + makeCommandLenFunc(cmdName, wCommand.getNbOfSamples(), null) + "," + channels + "," + getFormattedLiveVarStr(currElem) + ")"+CR; + nextCommand= cmdName + ".setNextCommand(array(1,(TMLCommand*)" + makeCommands(currElem.getNextElement(0),false,retElement,null) + "))"+ SCCR; + + } else if (currElem instanceof TMLSendEvent){ + if (debug) TraceManager.addDev("Checking Send\n"); + TMLSendEvent sendEvt=(TMLSendEvent)currElem; + cmdName= "_send" + currElem.getID(); + hcode+="TMLSendCommand " + cmdName + SCCR; + handleParameters(currElem, cmdName, false, getFormattedLiveVarStr(currElem)); + nextCommand= cmdName + ".setNextCommand(array(1,(TMLCommand*)" + makeCommands(currElem.getNextElement(0),false,retElement,null) + "))"+ SCCR; + + } else if (currElem instanceof TMLSendRequest){ + if (debug) TraceManager.addDev("Checking Request\n"); + TMLSendRequest sendReq=(TMLSendRequest)currElem; + cmdName= "_request" + currElem.getID(); + hcode+="TMLRequestCommand " + cmdName + SCCR; + handleParameters(currElem, cmdName, false, getFormattedLiveVarStr(currElem)); + nextCommand= cmdName + ".setNextCommand(array(1,(TMLCommand*)" + makeCommands(currElem.getNextElement(0),false,retElement,null) + "))"+ SCCR; + + } else if (currElem instanceof TMLWaitEvent){ + if (debug) TraceManager.addDev("Checking Wait\n"); + TMLWaitEvent waitEvt = (TMLWaitEvent)currElem; + cmdName= "_wait" + currElem.getID(); + hcode+="TMLWaitCommand " + cmdName + SCCR; + handleParameters(currElem, cmdName, true, getFormattedLiveVarStr(currElem)); + nextCommand= cmdName + ".setNextCommand(array(1,(TMLCommand*)" + makeCommands(currElem.getNextElement(0),false,retElement,null) + "))"+ SCCR; + + } else if (currElem instanceof TMLNotifiedEvent){ + if (debug) TraceManager.addDev("Checking Notified\n"); + cmdName= "_notified" + currElem.getID(); + hcode+="TMLNotifiedCommand " + cmdName + SCCR; + initCommand+= "," + cmdName + "("+currElem.getID()+",this," + ((TMLNotifiedEvent)currElem).getEvent().getExtendedName() + ",&" + ((TMLNotifiedEvent)currElem).getVariable() +",\"" + ((TMLNotifiedEvent)currElem).getVariable() + "\"," + getFormattedLiveVarStr(currElem) + ")" + CR; + nextCommand= cmdName + ".setNextCommand(array(1,(TMLCommand*)" + makeCommands(currElem.getNextElement(0),false,retElement,null) + "))"+ SCCR; + + } else if (currElem instanceof TMLSequence){ + TMLSequence tmlseq = (TMLSequence)currElem; + if (debug) TraceManager.addDev("Checking Sequence with "+ tmlseq.getNbNext()+ " elements."); + if (tmlseq.getNbNext() == 0) { + return retElement; + } else { + if (tmlseq.getNbNext() == 1) { + return makeCommands(currElem.getNextElement(0), false,retElement,null); + } else { + String nextBranch; + tmlseq.sortNexts(); + if (debug) TraceManager.addDev("Checking Sequence branch "+ (tmlseq.getNbNext()-1)); + nextBranch= makeCommands(currElem.getNextElement(currElem.getNbNext() - 1),false,retElement,null); + for(int i=currElem.getNbNext() - 2; i>=0; i--) { + if (debug) TraceManager.addDev("Checking Sequence branch "+ i); + nextBranch=makeCommands(currElem.getNextElement(i),false,nextBranch,null); + } + return nextBranch; + } + } + + } else if (currElem instanceof TMLChoice){ + String elemName=currElem.getName(), idString; + if (elemName.charAt(0)=='#'){ + int pos=elemName.indexOf('\\'); + idString=elemName.substring(1,pos); + //TraceManager.addDev(elemName + "***" + pos + "***" + idString + "***"+ elemName.length()); + cmdName="_" + elemName.substring(pos+1) + idString; + }else{ + cmdName= "_choice" + currElem.getID(); + idString=String.valueOf(currElem.getID()); + } + TMLChoice choice = (TMLChoice)currElem; + String code = "", nextCommandTemp="", stopCmdToAdd=""; + int noOfGuards=0; + if (debug) TraceManager.addDev("Checking Choice\n"); + if (choice.getNbGuard() !=0 ) { + //int indexElseG = choice.getElseGuard(), indexAfterG = choice.getAfterGuard(); + int noNonDetGuards = choice.nbOfNonDeterministicGuard(); + int noStochGuards = choice.nbOfStochasticGuard(); + if (noNonDetGuards>0){ //Non-Deterministic choice + code+= "oMin=0;\n"; + code+= "oMax=" + (noNonDetGuards-1) + SCCR; + //code += "rnd__0 = myrand(0, "+ noNonDetGuards + ")" + SCCR; + code += "return myrand(0, "+ (noNonDetGuards-1) + ")" + SCCR; + for(int i=0; i<noNonDetGuards; i++) { + //code += "if (rnd__0 < " + Math.floor(100/noNonDetGuards)*(i+1) + ") return " + i + SCCR; + nextCommandTemp+= ",(TMLCommand*)" + makeCommands(choice.getNextElement(i), false, retElement,null); + } + noOfGuards = noNonDetGuards; + //code+= "return " + (noNonDetGuards-1) + SCCR; + }else if(noStochGuards>0){ //Stochastic choice + code+= "oMin=0;\n"; + code+= "oMax=" + (noStochGuards-1) + SCCR; + code += "rnd__0 = myrand(0, 99)" + SCCR; + String composedGuard=""; + for(int i=0; i<choice.getNbGuard(); i++) { + if (choice.isStochasticGuard(i)) { + if (composedGuard.isEmpty()) { + composedGuard = formatGuard(choice.getStochasticGuard(i)); + } else { + composedGuard = composedGuard + "+" + formatGuard(choice.getStochasticGuard(i)); + } + code += "if (rnd__0 < (" + composedGuard + ")) return " + noOfGuards + SCCR; + nextCommandTemp+= ",(TMLCommand*)" + makeCommands(choice.getNextElement(i), false, retElement,null); + noOfGuards++; + } + } + + }else{ + int indElseGuard = choice.getElseGuard(), newIndElseGuard=-1; + code+= "unsigned int oC=0;\n"; + code+= "oMin=-1;\n"; + code+= "oMax=0;\n"; + for(int i=0; i<choice.getNbGuard(); i++) { + if (!(choice.isNonDeterministicGuard(i) || choice.isStochasticGuard(i))){ + if (i==indElseGuard){ + newIndElseGuard=noOfGuards; + if (retElseElement!=null) + nextCommandTemp+= ",(TMLCommand*)" +makeCommands(choice.getNextElement(indElseGuard), false, retElseElement,null); + else + nextCommandTemp+= ",(TMLCommand*)" + makeCommands(choice.getNextElement(indElseGuard), false, retElement,null); + + }else{ + code += "if "+ formatAction(formatGuard(choice.getGuard(i))) + "{\noC++;\n"; + code += "oMax += " + (1 << noOfGuards) + SCCR + "\n}\n"; + nextCommandTemp += ",(TMLCommand*)" + makeCommands(choice.getNextElement(i), false, retElement,null); + } + noOfGuards++; + } + } + //if (newIndElseGuard!=-1){ + if (newIndElseGuard==-1){ + newIndElseGuard= noOfGuards; + stopCmdToAdd = ",(TMLCommand*)&_stop" + idString; + noOfGuards++; + hcode+="TMLStopCommand " + "_stop" + idString + SCCR; + initCommand+= ", _stop" + idString + "(" + idString + ",this)" + CR; + } + code += "if (oMax==0){\n oMax=" + (1 << newIndElseGuard) + SCCR; + //code += "oC=1;\n}\n"; + code += "return " + newIndElseGuard + ";\n}\n"; + //} + code += "return getEnabledBranchNo(myrand(1,oC), oMax);\n"; + } + //nextCommand= cmdName + ".setNextCommand(array(" + noOfGuards + nextCommandTemp + "))" + SCCR; + nextCommand= cmdName + ".setNextCommand(array(" + noOfGuards + nextCommandTemp + stopCmdToAdd+ "))" + SCCR; + } + //if (choice.nbOfNonDeterministicGuard()==0 && choice.nbOfStochasticGuard()==0) + // hcode+="TMLChoiceCommand " + cmdName + SCCR; + //else + hcode+="TMLRandomChoiceCommand " + cmdName + SCCR; + initCommand+= "," + cmdName + "("+ idString +",this,(RangeFuncPointer)&" + reference + "::" + cmdName + "_func," + noOfGuards + "," + getFormattedLiveVarStr(currElem) + ")"+CR; + functions+="unsigned int "+ reference + "::" + cmdName + "_func(ParamType& oMin, ParamType& oMax){" + CR + code +CR+ "}" + CR2; + functionSig+="unsigned int " + cmdName + "_func(ParamType& oMin, ParamType& oMax)" + SCCR; + + } else if (currElem instanceof TMLSelectEvt){ + TMLEvent evt; + //Integer nbevt=0; + int nbevt=0; + String evtList="",paramList=""; + if (debug) TraceManager.addDev("Checking SelectEvt\n"); + cmdName= "_select" + currElem.getID(); + for(int i=0; i<currElem.getNbNext(); i++) { + evt=((TMLSelectEvt)currElem).getEvent(i); + if (evt!=null){ + nbevt++; + evtList += ",(TMLEventChannel*)"+ evt.getExtendedName(); + if (evt.getNbOfParams()==0) { + paramList+=",(ParamFuncPointer)0"; + }else{ + + //functionSig+="Parameter<ParamType>* " + cmdName + "_func_" + i + "(Parameter<ParamType>* ioParam)" + SCCR; + //functions+="Parameter<ParamType>* " + reference + "::" + cmdName + "_func_" + i + "(Parameter<ParamType>* ioParam){" + CR; + functionSig+="Parameter* " + cmdName + "_func_" + i + "(Parameter* ioParam)" + SCCR; + functions+="Parameter* " + reference + "::" + cmdName + "_func_" + i + "(Parameter* ioParam){" + CR; + + paramList+=",(ParamFuncPointer)&" + reference + "::" + cmdName + "_func_" + i + CR; + functions += "ioParam->getP(&" + ((TMLSelectEvt)currElem).getParam(i,0); + for(int j=1; j<evt.getNbOfParams(); j++) { + functions+= ", &" + ((TMLSelectEvt)currElem).getParam(i,j); + } + functions+=");\nreturn 0;\n}\n\n"; + } + nextCommand+= ",(TMLCommand*)" + makeCommands(currElem.getNextElement(i), true, retElement,null); + } + } + hcode+="TMLSelectCommand " + cmdName + SCCR; + initCommand+= "," + cmdName + "("+currElem.getID()+",this,array("+ nbevt + evtList + "),"+ nbevt + "," + getFormattedLiveVarStr(currElem) + ",array("+ nbevt + paramList + "))"+CR; + nextCommand=cmdName + ".setNextCommand(array(" + nbevt + nextCommand + "))" + SCCR; + + } else { + TraceManager.addDev("Operator: " + currElem + " of class " + currElem.getClass().getName() + " is not managed in the current version of this C++ code generator."); + } + chaining+=nextCommand; + return (cmdName.equals("0") || cmdName.charAt(0)=='&')? cmdName : "&"+cmdName; + } + + private String formatGuard(String guard){ + guard = Conversion.replaceAllChar(guard, '[', "("); + guard = Conversion.replaceAllChar(guard, ']', ")"); + return guard; + } + + public static String formatAction(String action){ + action = action.replaceAll("not\\s","!"); + action = action.replaceAll("not\\(","!("); + action = action.replaceAll("\\sand\\s","&&"); + action = action.replaceAll("\\sand\\(","&&("); + action = action.replaceAll("\\)and\\s",")&&"); + action = action.replaceAll("\\)and\\(",")&&("); + action = action.replaceAll("\\sor\\s","||"); + action = action.replaceAll("\\sor\\(","||("); + action = action.replaceAll("\\)or\\s",")||"); + action = action.replaceAll("\\)or\\(",")||("); + //action = action.replaceAll("[\\s(]or[\\s)]","||"); + return action; + } + + private boolean ChannelMappedOnSameHW(TMLWriteChannel writeCmd){ + LinkedList<HwCommunicationNode> commNodeRefList = tmlmapping.findNodesForElement(writeCmd.getChannel(0)); + for(int i=1; i<writeCmd.getNbOfChannels(); i++){ + LinkedList<HwCommunicationNode> commNodeCmpList = tmlmapping.findNodesForElement(writeCmd.getChannel(i)); + if (commNodeCmpList.size()!=commNodeRefList.size()) return false; + Iterator it = commNodeCmpList.iterator(); + for(HwCommunicationNode cmnode: commNodeRefList) { + if (it.next()!=cmnode) return false; + } + } + return true; + } + + + private String makeCommandLenFunc(String cmdName, String lowerLimit, String upperLimit){ + if (upperLimit==null) + functions+="TMLLength "+ reference + "::" + cmdName + "_func(){\nreturn (TMLLength)(" + modifyString(lowerLimit) + ");\n}" + CR2; + else + functions+="TMLLength "+ reference + "::" + cmdName + "_func(){\nreturn (TMLLength)myrand(" + lowerLimit + "," + modifyString(upperLimit) + ");\n}" + CR2; + functionSig+="TMLLength " + cmdName + "_func()" + SCCR; + return "(LengthFuncPointer)&" + reference + "::" + cmdName + "_func"; + } + + private String makeCommandRangeFunc(String cmdName, String lowerLimit, String upperLimit){ + functions+="unsigned int "+ reference + "::" + cmdName + "_func(ParamType& oMin, ParamType& oMax){\n oMin=" + modifyString(lowerLimit) + ";\noMax=" + modifyString(upperLimit) + SCCR + "return myrand(oMin, oMax)" + SCCR; + functions+= "}" + CR2; + functionSig+="unsigned int " + cmdName + "_func(ParamType & oMin, ParamType& oMax)" + SCCR; + return "(RangeFuncPointer)&" + reference + "::" + cmdName + "_func"; + } + + private boolean isIntValue(String input){ + try{ + Integer.parseInt(input); + return true; + }catch(Exception e){ + return false; + } + } + + private void handleParameters(TMLActivityElement currElem, String cmdName, boolean wait, String liveVarString){ + String concatParams="", channelName=""; + String[] paramArray=null; + //boolean areStatic=true; + int nbOfParams=0; + String address=(wait)? "&":""; + if (currElem instanceof TMLActivityElementEvent){ + nbOfParams=((TMLActivityElementEvent)currElem).getNbOfParams(); + paramArray = new String[nbOfParams]; + for (int i=0; i< nbOfParams; i++){ + paramArray[i]=((TMLActivityElementEvent)currElem).getParam(i); + } + channelName = ((TMLActivityElementEvent)currElem).getEvent().getExtendedName(); + } + else if (currElem instanceof TMLSendRequest){ + nbOfParams=((TMLSendRequest)currElem).getNbOfParams(); + paramArray = new String[nbOfParams]; + for (int i=0; i< nbOfParams; i++){ + paramArray[i]=((TMLSendRequest)currElem).getParam(i); + } + channelName = ((TMLSendRequest)currElem).getRequest().getExtendedName(); + } + if (nbOfParams==0){ + initCommand+= "," + cmdName + "("+ currElem.getID() +",this," + channelName + ",0," + liveVarString +")"+CR; + }else{ + for(int i=0; i<nbOfParams; i++){ + //if(areStatic && !isIntValue(paramArray[i])) areStatic=false; + if (i>0) concatParams+=","; + //concatParams+=","; + if (paramArray[i]==null || paramArray[i].isEmpty()) concatParams+="0"; else concatParams+= address + paramArray[i]; + } + //if (areStatic){ + //initCommand+= "," + cmdName + "("+ currElem.getID() +",this," + channelName + ",0," + liveVarString + ",Parameter<ParamType>(" + nbOfParams + "," + concatParams + "))"+CR; + //initCommand+= "," + cmdName + "("+ currElem.getID() +",this," + channelName + ",0," + liveVarString + ",new SizedParameter<ParamType," + nbOfParams + ">(" + concatParams + "))"+CR; + //}else{ + initCommand+= "," + cmdName + "("+ currElem.getID() +",this," + channelName + ",(ParamFuncPointer)&" + reference + "::" + cmdName + "_func,"+ liveVarString + ")" + CR; + //functionSig+="Parameter<ParamType>* " + cmdName + "_func(Parameter<ParamType>* ioParam)" + SCCR; + //functions+="Parameter<ParamType>* " + reference + "::" + cmdName + "_func(Parameter<ParamType>* ioParam){" + CR; + functionSig+="Parameter* " + cmdName + "_func(Parameter* ioParam)" + SCCR; + functions+="Parameter* " + reference + "::" + cmdName + "_func(Parameter* ioParam){" + CR; + if (wait) + functions += "ioParam->getP(" + concatParams + ")" + SCCR + "return 0" + SCCR; + else + //functions += "return new Parameter<ParamType>(" + nbOfParams + "," + concatParams + ")" + SCCR; + functions += "return new SizedParameter<ParamType," + nbOfParams + ">(" + concatParams + ")" + SCCR; + functions+="}\n\n"; + //} + } + } + + private void makeEndClassH() { + hcode += "};" + CR + "#endif" + CR; + } + + + private String makeAttributesCode() { + String code = ""; + int i; + for(TMLAttribute att: task.getAttributes()) { + //if (!att.name.endsWith("__req")){ //NEW + if (att.hasInitialValue()) + code += ","+ att.name + "(" + att.initialValue + ")"+CR; + else + code += ","+ att.name + "(0)"+CR; + //} + } + //code += ",arg1__req(0)"+CR; + //code += ",arg2__req(0)"+CR; + //code += ",arg3__req(0)"+CR; + return code; + } + + private String makeAttributesDeclaration() { + String code = ""; + int i; + for(TMLAttribute att: task.getAttributes()) { + //if (!att.name.endsWith("__req")){ //NEW + code += "ParamType " + att.name; + code += ";\n"; + //} + } + //code += "ParamType arg1__req" + SCCR; + //code += "ParamType arg2__req" + SCCR; + //code += "ParamType arg3__req" + SCCR; + code += "ParamType rnd__0" + SCCR; + code += "TMLChannel* _channels[" + (channels.size() + events.size() + (task.isRequested()? 1:0)) + "]" + SCCR; + return code; + } + + + private String addSemicolonIfNecessary(String _input) { + String code1 = _input.trim(); + if (!(code1.endsWith(";"))) { + code1 += ";"; + } + return code1; + } + + private String modifyString(String _input) { + _input = Conversion.changeBinaryOperatorWithUnary(_input, "div", "/"); + _input = Conversion.changeBinaryOperatorWithUnary(_input, "mod", "%"); + return _input; + } + + public String getIdentifierNameByID(int id){ + //Channels, Events, Requests, Variables, Choice, Random + id=Math.abs(id); + for (TMLChannel channel: channels){ + if (channel.getID()==id) return channel.getName(); + } + for (TMLEvent event: events){ + if (event.getID()==id) return event.getName(); + /*int param = Integer.MAX_VALUE - 3 * event.getID() - id + 1; + if (param>0 && param<4) return event.getName() + "_param" + param;*/ + } + for (TMLRequest request: requests){ + if (request.getID()==id) return request.getName(); + /*int param = Integer.MAX_VALUE - 3 * request.getID() - id +1; + if (param>0 && param<4) return request.getName() + "_param!" + param;*/ + } + for(TMLAttribute att: task.getAttributes()){ + if (att.getID()==id) return reference + ":" + att.getName(); + } + for(int i=0; i<task.getActivityDiagram().nElements();i++) + if (task.getActivityDiagram().get(i).getID()==id) return reference + ":Command " + id; + return null; + } + + public void determineCheckpoints(int[] aStatistics){ + _analysis.determineCheckpoints(aStatistics); + } + + public StaticAnalysis getAnalysis(){ + return _analysis; + } } diff --git a/src/tmltranslator/tomappingsystemc2/TML2MappingSystemC.java b/src/tmltranslator/tomappingsystemc2/TML2MappingSystemC.java index 715b4ee16d38497e36b3d318e7dc97a3c7399a39..53889dbce9af5670399db9fbb3691c40d5009877 100755 --- a/src/tmltranslator/tomappingsystemc2/TML2MappingSystemC.java +++ b/src/tmltranslator/tomappingsystemc2/TML2MappingSystemC.java @@ -1,47 +1,47 @@ /**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. - -/** - * Class TML2MappingSystemC - * Creation: 03/09/2007 - * @version 1.0 03/09/2007 - * @author Daniel Knorreck - * @see - */ + 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. + + /** + * Class TML2MappingSystemC + * Creation: 03/09/2007 + * @version 1.0 03/09/2007 + * @author Daniel Knorreck + * @see + */ package tmltranslator.tomappingsystemc2; @@ -54,676 +54,677 @@ import tepe.*; public class TML2MappingSystemC { - - private final static String CR = "\n"; - private final static String CR2 = "\n\n"; - private final static String SCCR = ";\n"; - private final static String EFCR = "}\n"; - private final static String EFCR2 = "}\n\n"; - private final static String EF = "}"; - private final static int MAX_EVENT = 1024; - - private TMLModeling tmlmodeling; - private TMLMapping tmlmapping; - - private boolean debug; - private boolean optimize; - private String header, declaration, mainFile, src; - private ArrayList<MappedSystemCTask> tasks; - - //private ArrayList<EBRDD> ebrdds; - //private ArrayList<TEPE> tepes; - SystemCTEPE tepeTranslator; - //private ArrayList<SystemCEBRDD> systemCebrdds = new ArrayList<SystemCEBRDD>(); - - public TML2MappingSystemC(TMLModeling _tmlm) { - tmlmodeling = _tmlm; - tmlmapping = tmlmodeling.getDefaultMapping(); - tepeTranslator = new SystemCTEPE(new ArrayList<TEPE>(), this); - } - - public TML2MappingSystemC(TMLMapping _tmlmapping) { - tmlmapping = _tmlmapping; - tmlmapping.makeMinimumMapping(); - tepeTranslator = new SystemCTEPE(new ArrayList<TEPE>(), this); - } - - public TML2MappingSystemC(TMLModeling _tmlm, ArrayList<EBRDD> _ebrdds, ArrayList<TEPE> _tepes) { - tmlmodeling = _tmlm; - //ebrdds = _ebrdds; - tmlmapping = tmlmodeling.getDefaultMapping(); - tepeTranslator = new SystemCTEPE(_tepes, this); - //tepeTranslator.generateTEPEs(); - } - - public TML2MappingSystemC(TMLMapping _tmlmapping, ArrayList<EBRDD> _ebrdds, ArrayList<TEPE> _tepes) { - tmlmapping = _tmlmapping; - //ebrdds = _ebrdds; - tmlmapping.makeMinimumMapping(); - tepeTranslator = new SystemCTEPE(_tepes, this); - //tepeTranslator.generateTEPEs(); - } - - public void saveFile(String path, String filename) throws FileException { - generateTaskFiles(path); - FileUtils.saveFile(path + filename + ".cpp", getFullCode()); - src += filename + ".cpp"; - FileUtils.saveFile(path + "Makefile.src", src); - //tepeTranslator.saveFile(path + "src_simulator/TEPE/test.h"); - } - - public String getFullCode() { - return mainFile; - } - - public void generateSystemC(boolean _debug, boolean _optimize) { - debug = _debug; - optimize = _optimize; - tmlmapping.removeAllRandomSequences(); - tmlmodeling = tmlmapping.getTMLModeling(); - tasks = new ArrayList<MappedSystemCTask>(); - //generateSystemCTasks(); - //generateEBRDDs(); - generateMainFile(); - generateMakefileSrc(); - } - - private void generateMainFile() { - makeHeader(); - makeDeclarations(); - header += tepeTranslator.getEqFuncDeclaration() + "\n"; - mainFile = header + declaration; - mainFile = Conversion.indentString(mainFile, 4); - } - - private void generateMakefileSrc() { - src = "SRCS = "; - for(TMLTask mst: tmlmapping.getMappedTasks()) { - src += mst.getName() + ".cpp "; - } - //for(EBRDD ebrdd: ebrdds){ - // src += ebrdd.getName() + ".cpp "; - //} - } - - private void makeHeader() { - // System headers - header = "#include <Simulator.h>" + CR; - header += "#include <AliasConstraint.h>\n#include <EqConstraint.h>\n#include <LogConstraint.h>\n#include <PropLabConstraint.h>\n"; - header += "#include <PropRelConstraint.h>\n#include <SeqConstraint.h>\n#include <SignalConstraint.h>\n#include <TimeMMConstraint.h>\n"; - header += "#include <TimeTConstraint.h>\n"; - header += "#include <CPU.h>\n#include <SingleCoreCPU.h>\n#include <RRScheduler.h>\n#include <RRPrioScheduler.h>\n#include <PrioScheduler.h>\n#include <Bus.h>\n"; - header += "#include <Bridge.h>\n#include <Memory.h>\n#include <TMLbrbwChannel.h>\n#include <TMLnbrnbwChannel.h>\n"; - header += "#include <TMLbrnbwChannel.h>\n#include <TMLEventBChannel.h>\n#include <TMLEventFChannel.h>\n#include <TMLEventFBChannel.h>\n"; - header += "#include <TMLTransaction.h>\n#include <TMLCommand.h>\n#include <TMLTask.h>\n"; - header += "#include <SimComponents.h>\n#include <Server.h>\n#include <SimServSyncInfo.h>\n#include <ListenersSimCmd.h>\n"; - - // Generate tasks header - for(TMLTask mst: tmlmapping.getMappedTasks()) { - //header += "#include <" + mst.getReference() + ".h>" + CR; - header += "#include <" + mst.getName() + ".h>" + CR; - } - //for(EBRDD ebrdd: ebrdds){ - // header += "#include <" + ebrdd.getName() + ".h>" + CR; - //} - header += CR; - } - - private void makeDeclarations() { - declaration = "class CurrentComponents: public SimComponents{\npublic:\nCurrentComponents():SimComponents(" + tmlmapping.getHashCode() + "){\n"; - - // Declaration of HW nodes - declaration += "//Declaration of CPUs" + CR; - for(HwNode node: tmlmapping.getTMLArchitecture().getHwNodes()) { - if (node instanceof HwCPU) { - HwCPU exNode = (HwCPU)node; - if (exNode.getType().equals("CPURRPB")) - declaration += "PrioScheduler* " + exNode.getName() + "_scheduler = new PrioScheduler(\"" + exNode.getName() + "_PrioSched\",0)" + SCCR; - else - //tmlmapping.getTMLArchitecture().getMasterClockFrequency() * exNode.sliceTime - //declaration += "RRScheduler* " + exNode.getName() + "_scheduler = new RRScheduler(\"" + exNode.getName() + "_RRSched\", 0, 5, " + (int) Math.ceil(((float)exNode.execiTime)*(1+((float)exNode.branchingPredictionPenalty)/100)) + " ) " + SCCR; - declaration += "RRScheduler* " + exNode.getName() + "_scheduler = new RRScheduler(\"" + exNode.getName() + "_RRSched\", 0, " + (tmlmapping.getTMLArchitecture().getMasterClockFrequency() * exNode.sliceTime) + ", " + (int) Math.ceil((float)(exNode.clockRatio * Math.max(exNode.execiTime,exNode.execcTime) * (exNode.branchingPredictionPenalty * exNode.pipelineSize +100 - exNode.branchingPredictionPenalty))/100) + " ) " + SCCR; - //for(int cores=0; cores<exNode.nbOfCores; cores++){ - for(int cores=0; cores<1; cores++){ - //if (tmlmapping.isAUsedHwNode(node)) { - declaration += "CPU* " + exNode.getName() + cores + " = new SingleCoreCPU(" + exNode.getID() + ", \"" + exNode.getName() + "_" + cores + "\", " + exNode.getName() + "_scheduler" + ", "; - - declaration += exNode.clockRatio + ", " + exNode.execiTime + ", " + exNode.execcTime + ", " + exNode.pipelineSize + ", " + exNode.taskSwitchingTime + ", " + exNode.branchingPredictionPenalty + ", " + exNode.goIdleTime + ", " + exNode.maxConsecutiveIdleCycles + ", " + exNode.byteDataSize + ")" + SCCR; - if (cores!=0) declaration+= node.getName() + cores + "->setScheduler(" + exNode.getName() + "_scheduler,false)" + SCCR; - declaration += "addCPU("+ node.getName() + cores +")"+ SCCR; - } - } - if (node instanceof HwA) { - HwA hwaNode = (HwA)node; - declaration += "RRScheduler* " + hwaNode.getName() + "_scheduler = new RRScheduler(\"" + hwaNode.getName() + "_RRSched\", 0, " + (tmlmapping.getTMLArchitecture().getMasterClockFrequency() * hwaNode.DEFAULT_SLICE_TIME) + ", " + (int) Math.ceil((float)(hwaNode.clockRatio * Math.max(hwaNode.execiTime,hwaNode.execcTime) * (hwaNode.DEFAULT_BRANCHING_PREDICTION_PENALTY * hwaNode.DEFAULT_PIPELINE_SIZE +100 - hwaNode.DEFAULT_BRANCHING_PREDICTION_PENALTY))/100) + " ) " + SCCR; - for(int cores=0; cores<1; cores++){ - //if (tmlmapping.isAUsedHwNode(node)) { - declaration += "CPU* " + hwaNode.getName() + cores + " = new SingleCoreCPU(" + hwaNode.getID() + ", \"" + hwaNode.getName() + "_" + cores + "\", " + hwaNode.getName() + "_scheduler" + ", "; - - declaration += hwaNode.clockRatio + ", " + hwaNode.execiTime + ", " + hwaNode.execcTime + ", " + hwaNode.DEFAULT_PIPELINE_SIZE + ", " + hwaNode.DEFAULT_TASK_SWITCHING_TIME + ", " + hwaNode.DEFAULT_BRANCHING_PREDICTION_PENALTY + ", " + hwaNode.DEFAULT_GO_IDLE_TIME + ", " + hwaNode.DEFAULT_MAX_CONSECUTIVE_IDLE_CYCLES + ", " + hwaNode.byteDataSize + ")" + SCCR; - if (cores!=0) declaration+= node.getName() + cores + "->setScheduler(" + hwaNode.getName() + "_scheduler,false)" + SCCR; - declaration += "addCPU("+ node.getName() + cores +")"+ SCCR; - } - - } - } - declaration += CR; - - // Declaration of Buses - declaration += "//Declaration of Buses" + CR; - //declaration+="Bus* defaultBus = new Bus(-1,\"defaultBus\",100,1,1)" + SCCR; - //declaration += "addBus(defaultBus)"+ SCCR; - for(HwNode node: tmlmapping.getTMLArchitecture().getHwNodes()) { - if (node instanceof HwBus) { - //if (tmlmapping.isAUsedHwNode(node)) { - HwBus thisBus = (HwBus)node; - for(int i=0; i< thisBus.pipelineSize; i++){ - declaration += "Bus* " + node.getName() + "_" + i + " = new Bus("+ node.getID() + ",\"" + node.getName() + "_" + i + "\",0, 100, "+ thisBus.byteDataSize + ", " + node.clockRatio + ","; - if(thisBus.arbitration==HwBus.CAN) declaration +="true"; else declaration +="false"; - declaration += ");\naddBus("+ node.getName() + "_" + i + ")"+ SCCR; - } - //} - } - } - declaration += CR; - - // Declaration of Bridges - declaration += "//Declaration of Bridges" + CR; - for(HwNode node: tmlmapping.getTMLArchitecture().getHwNodes()) { - if (node instanceof HwBridge) { - declaration+= "Bridge* " + node.getName() + " = new Bridge("+ node.getID() + ",\"" + node.getName() + "\", " + node.clockRatio + ", " + ((HwBridge)node).bufferByteSize + ")" +SCCR; - declaration += "addBridge("+ node.getName() +")"+ SCCR; - } - } - declaration += CR; - - // Declaration of Memories - //declaration += "//Declaration of Memories\nMemory* defaultMemory = new Memory(-1,\"defaultMemory\",1,4)" + SCCR; - //declaration += "addMem(defaultMemory)"+ SCCR; - declaration += "//Declaration of Memories" + CR; - for(HwNode node: tmlmapping.getTMLArchitecture().getHwNodes()) { - if (node instanceof HwMemory) { - declaration+= "Memory* " + node.getName() + " = new Memory("+ node.getID() + ",\"" + node.getName() + "\", " + node.clockRatio + ", " + ((HwMemory)node).byteDataSize + ")" +SCCR; - declaration += "addMem("+ node.getName() +")"+ SCCR; - } - } - declaration += CR; - - //Declaration of Bus masters - declaration += "//Declaration of Bus masters" + CR; - for(HwNode node: tmlmapping.getTMLArchitecture().getHwNodes()){ - if (node instanceof HwExecutionNode || node instanceof HwBridge){ - ArrayList<HwLink> nodeLinks= tmlmapping.getTMLArchitecture().getLinkByHwNode(node); - if (!nodeLinks.isEmpty()){ - //declaration+= "BusMaster* " + node.getName() + "2defaultBus = new BusMaster(\"" + node.getName() + "2defaultBus\", 0, defaultBus)" + SCCR; - //else{ - for(HwLink link: nodeLinks){ - //declaration+= "BusMaster* " + node.getName() + "_" + link.bus.getName() + "_Master = new BusMaster(\"" + node.getName() + "_" + link.bus.getName() + "_Master\", " + link.getPriority() + ", 1, array(1, (SchedulableCommDevice*)" + link.bus.getName() + "))" + SCCR; - int noOfCores; - //if (node instanceof HwCPU) noOfCores= ((HwCPU)node).nbOfCores; else noOfCores=1; - noOfCores=1; - for (int cores=0; cores<noOfCores; cores++){ - String nodeName=node.getName(); - if ((node instanceof HwCPU) || (node instanceof HwA) ) - nodeName+= cores; - declaration+= "BusMaster* " + nodeName + "_" + link.bus.getName() + "_Master = new BusMaster(\"" + nodeName + "_" + link.bus.getName() + "_Master\", " + link.getPriority() + ", " + link.bus.pipelineSize + ", array(" + link.bus.pipelineSize; - for(int i=0; i< link.bus.pipelineSize; i++) - declaration+= ", (SchedulableCommDevice*)" + link.bus.getName() + "_" + i; - declaration+= "))" + SCCR; - declaration+= nodeName + "->addBusMaster(" + nodeName + "_" + link.bus.getName() + "_Master)" + SCCR; - } - } - } - } - } - declaration += CR; - - // Declaration of channels - TMLChannel channel; - String tmp,param; - declaration += "//Declaration of channels" + CR; - for(TMLElement elem: tmlmodeling.getChannels()){ - if (elem instanceof TMLChannel) { - channel = (TMLChannel)elem; - switch(channel.getType()) { - case TMLChannel.BRBW: - tmp = "TMLbrbwChannel"; - param= "," + channel.getMax() + ",0"; - break; - case TMLChannel.BRNBW: - tmp = "TMLbrnbwChannel"; - param= ",0"; - break; - case TMLChannel.NBRNBW: - default: - tmp = "TMLnbrnbwChannel"; - param= ""; - } - declaration += tmp + "* " + channel.getExtendedName() + " = new " + tmp +"(" + channel.getID() + ",\"" + channel.getName() + "\"," + channel.getSize() + ","; - TraceManager.addDev("Channel: " + channel.getName()); - //TraceManager.addDev("Channel origin node: " + channel.getOriginTask().getName() + " dest node: " + channel.getDestinationTask().getName()); - TraceManager.addDev( "the list of mapped tasks: " + tmlmapping.getMappedTasks().toString() ); - declaration+= determineRouting(tmlmapping.getHwNodeOf(channel.getOriginTask()), tmlmapping.getHwNodeOf(channel.getDestinationTask()), elem) + param + "," + channel.getPriority(); - if (channel.isLossy() && channel.getType()!=TMLChannel.NBRNBW) declaration += "," + channel.getLossPercentage() + "," + channel.getMaxNbOfLoss(); - declaration += ")"+ SCCR; - declaration += "addChannel("+ channel.getExtendedName() +")"+ SCCR; - } - } - declaration += CR; - - // Declaration of events - declaration += "//Declaration of events" + CR; - for(TMLEvent evt: tmlmodeling.getEvents()) { - if (evt.isInfinite()) { - tmp = "TMLEventBChannel<ParamType," + evt.getNbOfParams() + ">"; - param= ",0,false,false"; - } else { - if (evt.isBlocking()) { - tmp = "TMLEventFBChannel<ParamType," + evt.getNbOfParams() + ">"; - param= "," + evt.getMaxSize() + ",0"; - } else { - tmp = "TMLEventFChannel<ParamType," + evt.getNbOfParams() + ">"; - param= "," + evt.getMaxSize() + ",0"; - } - } - //param += "," + evt.getNbOfParams(); - if (tmlmapping.isCommNodeMappedOn(evt,null)){ - TraceManager.addDev("Evt: " + evt.getName()); - declaration += tmp + "* " + evt.getExtendedName() + " = new " + tmp + "(" + evt.getID() + ",\"" + evt.getName() + "\"," + determineRouting(tmlmapping.getHwNodeOf(evt.getOriginTask()), tmlmapping.getHwNodeOf(evt.getDestinationTask()), evt) + param; - - }else{ - declaration += tmp + "* " + evt.getExtendedName() + " = new " + tmp + "(" + evt.getID() + ",\"" + evt.getName() + "\",0,0,0" + param; ///old command - } - if (evt.isLossy()) declaration += "," + evt.getLossPercentage() + "," + evt.getMaxNbOfLoss(); - declaration += ")" + SCCR; - declaration += "addEvent("+ evt.getExtendedName() +")"+ SCCR; - } - declaration += CR; - - // Declaration of requests - declaration += "//Declaration of requests" + CR; - for(TMLTask task: tmlmodeling.getTasks()) { - if (task.isRequested()){ - TMLRequest req = task.getRequest(); - if (tmlmapping.isCommNodeMappedOn(req,null)){ - //declaration += "TMLEventBChannel* reqChannel_"+ task.getName() + " = new TMLEventBChannel(" + - TraceManager.addDev("Request: " + req.getName()); - declaration += "TMLEventBChannel<ParamType," + req.getNbOfParams() + ">* reqChannel_"+ task.getName() + " = new TMLEventBChannel<ParamType," + req.getNbOfParams() + ">(" + - req.getID() + ",\"reqChannel"+ task.getName() + "\"," + - determineRouting(tmlmapping.getHwNodeOf(req.getOriginTasks().get(0)), //tmlmapping.getHwNodeOf(req.getDestinationTask()), req) + ",0," + req.getNbOfParams() + ",true)" + SCCR; - tmlmapping.getHwNodeOf(req.getDestinationTask()), req) + ",0,true,false"; - }else{ - declaration += "TMLEventBChannel<ParamType," + req.getNbOfParams() + ">* reqChannel_"+ task.getName() + " = new TMLEventBChannel<ParamType," + req.getNbOfParams() + ">(" + //req.getID() + ",\"reqChannel"+ task.getName() + "\",0,0,0,0," + req.getNbOfParams() + ",true)" + SCCR; - req.getID() + ",\"reqChannel"+ task.getName() + "\",0,0,0,0,true,false"; - } - if (req.isLossy()) declaration += "," + req.getLossPercentage() + "," + req.getMaxNbOfLoss(); - declaration += ")" + SCCR; - declaration += "addRequest(reqChannel_"+ task.getName() +")"+ SCCR; - } - } - declaration += CR; - - ///Set bus schedulers - declaration += "//Set bus schedulers" + CR; - for(HwNode node: tmlmapping.getTMLArchitecture().getHwNodes()) { - if (node instanceof HwBus) { - ArrayList<HwLink> busLinks= tmlmapping.getTMLArchitecture().getLinkByBus((HwBus)node); - String devices=""; - int numDevices=0; - if (!busLinks.isEmpty()){ - for(HwLink link: busLinks){ - if (link.hwnode instanceof HwExecutionNode || link.hwnode instanceof HwBridge){ - if ((link.hwnode instanceof HwCPU) || (link.hwnode instanceof HwA)){ - //for (int cores=0; cores< ((HwCPU)link.hwnode).nbOfCores; cores++){ - for (int cores=0; cores< 1; cores++){ - devices += ", (WorkloadSource*)" + link.hwnode.getName()+ cores + "_" + node.getName() + "_Master"; - numDevices++; - } - }else{ - devices += ", (WorkloadSource*)" + link.hwnode.getName()+ "_" + node.getName() + "_Master"; - numDevices++; - } - } - } - declaration += node.getName() + "_0->setScheduler((WorkloadSource*) new "; - if (((HwBus)node).arbitration==HwBus.BASIC_ROUND_ROBIN) - //declaration+="RRScheduler(\"" + node.getName() + "_RRSched\", 0, 5, " + (int) Math.ceil(((float)node.clockRatio)/((float)((HwBus)node).byteDataSize)) + ", array("; - declaration+="RRScheduler(\"" + node.getName() + "_RRSched\", 0, 5, " + (int) Math.ceil(((float)node.clockRatio)/((float)((HwBus)node).byteDataSize)) + ", array("; - else - declaration+="PrioScheduler(\"" + node.getName() + "_PrioSched\", 0, array("; - declaration+= numDevices + devices + "), " + numDevices + "))" + SCCR; - } - for(int i=1; i< ((HwBus)node).pipelineSize; i++) - declaration+=node.getName() + "_" + i + "->setScheduler(" + node.getName() + "_0->getScheduler(),false)" +SCCR; - } - } - declaration += CR; - - - //Declaration of Tasks - ListIterator iterator = tmlmapping.getNodes().listIterator(); - declaration += "//Declaration of tasks" + CR; - HwExecutionNode node; - //for(TMLTask task: tmlmodeling.getTasks()) { - ArrayList<TMLChannel> channels; - ArrayList<TMLEvent> events; - ArrayList<TMLRequest> requests; - int[] aStatistics = new int[8]; - Set<Integer> mappedChannels = new HashSet<Integer>(); - for(TMLTask task: tmlmapping.getMappedTasks()){ - node=(HwExecutionNode)iterator.next(); - int noOfCores; - declaration += task.getName() + "* task__" + task.getName() + " = new " + task.getName() + "("+ task.getID() +","+ task.getPriority() + ",\"" + task.getName() + "\", array("; - - if (node instanceof HwCPU){ - //declaration+= ((HwCPU)node).nbOfCores; - declaration+= 1; - //for (int cores=0; cores< ((HwCPU)node).nbOfCores; cores++){ - for (int cores=0; cores< 1; cores++){ - declaration+= "," + node.getName()+cores; - } - //declaration+= ")," + ((HwCPU)node).nbOfCores + CR; - declaration+= "),1" + CR; - }else if (node instanceof HwA){ - //declaration+= ((HwCPU)node).nbOfCores; - declaration+= 1; - //for (int cores=0; cores< ((HwCPU)node).nbOfCores; cores++){ - for (int cores=0; cores< 1; cores++){ - declaration+= "," + node.getName()+cores; - } - //declaration+= ")," + ((HwCPU)node).nbOfCores + CR; - declaration+= "),1" + CR; - } else { - declaration += "1," + node.getName() + "),1" + CR; - } - - - MappedSystemCTask mst; - channels = new ArrayList<TMLChannel>(tmlmodeling.getChannels(task)); - events = new ArrayList<TMLEvent>(tmlmodeling.getEvents(task)); - requests = new ArrayList<TMLRequest>(tmlmodeling.getRequests(task)); - - mst = new MappedSystemCTask(task, channels, events, requests, tmlmapping, mappedChannels); - //mst.generateSystemC(debug, optimize, dependencies); - //mst.generateSystemC(debug, optimize); - tasks.add(mst); - for(TMLChannel channelb: channels) - declaration += "," + channelb.getExtendedName()+CR; - - for(TMLEvent evt: events) - declaration += "," + evt.getExtendedName()+CR; - - for(TMLRequest req: requests) - if (req.isAnOriginTask(task)) declaration+=",reqChannel_" + req.getDestinationTask().getName()+CR; - - if (task.isRequested()) declaration += ",reqChannel_"+task.getName()+CR; - declaration += ")" + SCCR; - declaration += "addTask(task__"+ task.getName() +")"+ SCCR; - } - //int[] aStatistics = new int[8]; - declaration += "\n}\n\n"; - - //Declaration of TEPEs - declaration += "void generateTEPEs(){" + CR; - declaration += "//Declaration of TEPEs" + CR; - tepeTranslator.generateTEPEs(); - declaration += tepeTranslator.getCode(); - - //Generation of tasks - for(MappedSystemCTask task: tasks){ - task.determineCheckpoints(aStatistics); - task.generateSystemC(debug, optimize); - } - - //Declaration of TEPEs continued - declaration += CR; - declaration += "}\n};\n\n" + tepeTranslator.getEqFuncs(); - declaration +="#include <main.h>\n"; - - if (aStatistics[0]!=0) TraceManager.addDev("Global gain variables " + 100 * aStatistics[1] / aStatistics[0]); - if (aStatistics[2]!=0) TraceManager.addDev("Global gain Channels " + 100 * aStatistics[3] / aStatistics[2]); - if (aStatistics[4]!=0) TraceManager.addDev("Global gain events " + 100 * aStatistics[5] / aStatistics[4]); - if (aStatistics[6]!=0) TraceManager.addDev("Global gain checkpoints " + 100 * aStatistics[7] / aStatistics[6]); - - //Declaration of EBRDDs - /*declaration += "//Declaration of EBRDDs" + CR; - for(EBRDD ebrdd: ebrdds){ - declaration += ebrdd.getName() + "* ebrdd__" + ebrdd.getName() + " = new " + ebrdd.getName() + "(0, \""+ ebrdd.getName() + "\");\n"; - declaration += "addEBRDD(ebrdd__"+ ebrdd.getName() +")"+ SCCR; - }*/ - } - - - private int extractPath(LinkedList<HwCommunicationNode> path, strwrap masters, strwrap slaves, HwNode startNode, HwNode destNode, boolean reverseIn){ - String firstPart=""; //lastBus=""; - int masterCount=0; - boolean reverse=reverseIn; - if (reverseIn) - slaves.str+=",static_cast<Slave*>(0)"; - else - firstPart=startNode.getName() + "0"; - /*TraceManager.addDev("------------------------------------------------------"); - for(HwCommunicationNode commElem:path){ - TraceManager.addDev("CommELem to process: " + commElem.getName()); - } - TraceManager.addDev("------------------------------------------------------");*/ - for(HwCommunicationNode commElem:path){ - //TraceManager.addDev("CommELem to process: " + commElem.getName()); - //String commElemName = commElem.getName(); - //if (commElem instanceof HwCPU) commElemName += "0"; - //System.out.println("Next elem in path: " + commElem.getName()); - if (commElem instanceof HwMemory){ - reverse=true; - slaves.str+= ",static_cast<Slave*>(" + commElem.getName() + "),static_cast<Slave*>(" + commElem.getName() + ")"; - //firstPart=lastBus; - firstPart=""; - }else{ - if (reverse){ - if (firstPart.length()==0){ - firstPart=commElem.getName(); - //firstPart=commElemName; - }else{ - masters.str+= "," + commElem.getName() + "_" + firstPart + "_Master"; - //masters.str+= "," + commElemName + "_" + firstPart + "_Master"; - masterCount++; - slaves.str+= ",static_cast<Slave*>(" + commElem.getName() + ")"; - firstPart=""; - } - }else{ - if (firstPart.length()==0){ - firstPart=commElem.getName(); - slaves.str+= ",static_cast<Slave*>(" + firstPart + ")"; - }else{ - //lastBus=commElem.getName(); - masters.str+= "," + firstPart + "_" + commElem.getName() + "_Master"; - masterCount++; - firstPart=""; - } - } - } - } - if (reverse){ - //masters.str+= "," + destNode.getName() + "_" + firstPart + "_Master"; - masters.str+= "," + destNode.getName() + "0_" + firstPart + "_Master"; - return masterCount+1; - }else{ - slaves.str+=",static_cast<Slave*>(0)"; - return -masterCount; - } - } - - private String determineRouting( HwNode startNode, HwNode destNode, TMLElement commElemToRoute ){ - - //TraceManager.addDev( "Determine routing from " + startNode.getName() + " to " + destNode.getName() ); - strwrap masters=new strwrap(), slaves=new strwrap(); - LinkedList<HwCommunicationNode> path = new LinkedList<HwCommunicationNode>(); - LinkedList<HwCommunicationNode> commNodes = new LinkedList<HwCommunicationNode>(); - - for( HwNode node: tmlmapping.getTMLArchitecture().getHwNodes() ) { - if( node instanceof HwCommunicationNode ) { - commNodes.add((HwCommunicationNode) node); - TraceManager.addDev( "Inserted: " + ((HwCommunicationNode)node).getName() ); - } - } - if( startNode == null ) { - TraceManager.addDev( "NULL REFERENCE" ); - } - else { - TraceManager.addDev( "startNode: " + startNode.getName() ); - } - HwMemory memory = getMemConnectedToBusChannelMapped( commNodes, null, commElemToRoute ); - if( memory == null ) { - System.out.println( "no memories to map" ); - exploreBuses( 0, commNodes, path, startNode, destNode, commElemToRoute ); - } - else { - LinkedList<HwCommunicationNode> commNodes2 = new LinkedList<HwCommunicationNode>(commNodes); - //exploreBuses(0, commNodes, path, startNode, memory, commElemToRoute); - if( !exploreBuses( 0, commNodes, path, startNode, memory, commElemToRoute ) ) { - TraceManager.addDev("NO route to " + memory.getName() + "found!!!!!!!!!!!!!!!!!!!!!!!!!!"); - } - path.add( memory ); - exploreBuses( 0, commNodes2, path, memory, destNode, commElemToRoute ); - } - int hopNum; - if ( (hopNum=extractPath(path, masters, slaves, startNode, destNode, false))<0){ - hopNum=extractPath(path, masters, slaves, destNode, destNode, true)-hopNum; - } - TraceManager.addDev(commElemToRoute.getName() + " is mapped on:"); - for(HwCommunicationNode commElem:path){ - TraceManager.addDev(commElem.getName()); - } - TraceManager.addDev("number of elements: " + hopNum); - TraceManager.addDev("masters: " + masters.str); - TraceManager.addDev("slaves: " + slaves.str); - return hopNum + ",array(" + hopNum + masters.str + "),array(" + hopNum + slaves.str + ")"; - } - - private boolean exploreBuses(int depth, LinkedList<HwCommunicationNode> commNodes, LinkedList<HwCommunicationNode> path, HwNode startNode, HwNode destNode, TMLElement commElemToRoute){ - //first called with Maping:getCommunicationNodes - LinkedList<HwCommunicationNode> nodesToExplore; - TraceManager.addDev("No of comm nodes " + commNodes.size()); - boolean busExploreMode = ((depth & 1) == 0); - //if (depth % 2 == 0){ - if(busExploreMode){ - TraceManager.addDev("search for buses connected to " + startNode.getName()); - nodesToExplore=getBusesConnectedToNode(commNodes, startNode); - }else{ - TraceManager.addDev("search for bridges connected to: " + startNode.getName()); - nodesToExplore=getBridgesConnectedToBus(commNodes, (HwBus)startNode); - } - //HwMemory memory = null; - TraceManager.addDev("no of elements found: " + nodesToExplore.size()); - for(HwCommunicationNode currNode:nodesToExplore){ - //memory = null; - if (busExploreMode){ - //memory = getMemConnectedToBusChannelMapped(commNodes, (HwBus)currNode, commElemToRoute); - if(isBusConnectedToNode(currNode, destNode)){ - TraceManager.addDev(currNode.getName() + " is last node"); - path.add(currNode); - //if (memory!=null) path.add(memory); - commNodes.remove(currNode); - return true; - } - } - if(tmlmapping.isCommNodeMappedOn(commElemToRoute, currNode)){ - TraceManager.addDev(currNode.getName() + " mapping found for " + commElemToRoute.getName()); - path.add(currNode); - //if (memory!=null) path.add(memory); - commNodes.remove(currNode); - if (exploreBuses(depth+1, commNodes, path, currNode, destNode, commElemToRoute)) return true; - path.remove(currNode); - //if (memory!=null) path.remove(memory); - commNodes.add(currNode); - } - } - for(HwCommunicationNode currNode:nodesToExplore){ - //if (busExploreMode) memory = getMemConnectedToBusChannelMapped(commNodes, (HwBus)currNode, commElemToRoute); else memory=null; - path.add(currNode); - //if (memory!=null) path.add(memory); - commNodes.remove(currNode); - //for (int i=0; i<path.size(); i++) System.out.print(" "); - TraceManager.addDev(currNode.getName()); - if (exploreBuses(depth+1, commNodes, path, currNode, destNode, commElemToRoute)) return true; - path.remove(currNode); - //if (memory!=null) path.remove(memory); - commNodes.add(currNode); - } - return false; - } - - private HwMemory getMemConnectedToBusChannelMapped( LinkedList<HwCommunicationNode> _commNodes, HwBus _bus, TMLElement _channel ) { - for( HwCommunicationNode commNode: _commNodes ) { - if( commNode instanceof HwMemory ) { - if( _bus != null ) System.out.println(commNode.getName() + " connected to bus " + _bus.getName() + ": " + tmlmapping.getTMLArchitecture().isNodeConnectedToBus(commNode, _bus)); - System.out.println(_channel.getName() + " is mapped onto " + commNode.getName() + ": " + tmlmapping.isCommNodeMappedOn(_channel,commNode)); - if( ( _bus == null || tmlmapping.getTMLArchitecture().isNodeConnectedToBus( commNode, _bus ) ) - && tmlmapping.isCommNodeMappedOn( _channel, commNode ) ) { - return (HwMemory)commNode; - } - } - } - return null; - } - - private LinkedList<HwCommunicationNode> getBusesConnectedToNode(LinkedList<HwCommunicationNode> _commNodes, HwNode _node){ - LinkedList<HwCommunicationNode> resultList = new LinkedList<HwCommunicationNode>(); - for(HwCommunicationNode commNode: _commNodes){ - if (commNode instanceof HwBus){ - if (tmlmapping.getTMLArchitecture().isNodeConnectedToBus(_node, (HwBus)commNode)) resultList.add((HwBus)commNode); - } - } - return resultList; - } - - private LinkedList<HwCommunicationNode> getBridgesConnectedToBus(LinkedList<HwCommunicationNode> _commNodes, HwBus _bus){ - LinkedList<HwCommunicationNode> resultList = new LinkedList<HwCommunicationNode>(); - for(HwCommunicationNode commNode: _commNodes){ - if (commNode instanceof HwBridge){ - if (tmlmapping.getTMLArchitecture().isNodeConnectedToBus(commNode, _bus)) resultList.add((HwBridge)commNode); - } - } - return resultList; - } - - private boolean isBusConnectedToNode(HwCommunicationNode commNode, HwNode node){ - for(HwLink link: tmlmapping.getTMLArchitecture().getHwLinks()) { - if(link.bus==commNode && link.hwnode==node) return true; - } - return false; - } - - private String getIdentifierNameByID(int id){ - - for(MappedSystemCTask task: tasks){ - String tmp = task.getIdentifierNameByID(id); - if (tmp!=null) return tmp; - } - return null; - } - - /*private void generateEBRDDs(){ - for(EBRDD ebrdd: ebrdds){ - SystemCEBRDD newEbrdd = new SystemCEBRDD(ebrdd, tmlmodeling, tmlmapping); - newEbrdd.generateSystemC(debug); - systemCebrdds.add(newEbrdd); - } - }*/ - - private void generateTaskFiles(String path) throws FileException { - for(MappedSystemCTask mst: tasks) { - mst.saveInFiles(path); - } - //for(SystemCEBRDD ebrdd: systemCebrdds) { - // ebrdd.saveInFiles(path); - //} - } - - - public MappedSystemCTask getMappedTaskByName(String iName){ - for(MappedSystemCTask task: tasks){ - if (task.getTMLTask().getName().equals(iName)) return task; - } - return null; - } + + private final static String CR = "\n"; + private final static String CR2 = "\n\n"; + private final static String SCCR = ";\n"; + private final static String EFCR = "}\n"; + private final static String EFCR2 = "}\n\n"; + private final static String EF = "}"; + private final static int MAX_EVENT = 1024; + + private TMLModeling tmlmodeling; + private TMLMapping tmlmapping; + + private boolean debug; + private boolean optimize; + private String header, declaration, mainFile, src; + private ArrayList<MappedSystemCTask> tasks; + + //private ArrayList<EBRDD> ebrdds; + //private ArrayList<TEPE> tepes; + SystemCTEPE tepeTranslator; + //private ArrayList<SystemCEBRDD> systemCebrdds = new ArrayList<SystemCEBRDD>(); + + public TML2MappingSystemC(TMLModeling _tmlm) { + tmlmodeling = _tmlm; + tmlmodeling.removeForksAndJoins(); + tmlmapping = tmlmodeling.getDefaultMapping(); + tepeTranslator = new SystemCTEPE(new ArrayList<TEPE>(), this); + } + + public TML2MappingSystemC(TMLMapping _tmlmapping) { + tmlmapping = _tmlmapping; + tmlmapping.makeMinimumMapping(); + tepeTranslator = new SystemCTEPE(new ArrayList<TEPE>(), this); + } + + public TML2MappingSystemC(TMLModeling _tmlm, ArrayList<EBRDD> _ebrdds, ArrayList<TEPE> _tepes) { + tmlmodeling = _tmlm; + //ebrdds = _ebrdds; + tmlmapping = tmlmodeling.getDefaultMapping(); + tepeTranslator = new SystemCTEPE(_tepes, this); + //tepeTranslator.generateTEPEs(); + } + + public TML2MappingSystemC(TMLMapping _tmlmapping, ArrayList<EBRDD> _ebrdds, ArrayList<TEPE> _tepes) { + tmlmapping = _tmlmapping; + //ebrdds = _ebrdds; + tmlmapping.makeMinimumMapping(); + tepeTranslator = new SystemCTEPE(_tepes, this); + //tepeTranslator.generateTEPEs(); + } + + public void saveFile(String path, String filename) throws FileException { + generateTaskFiles(path); + FileUtils.saveFile(path + filename + ".cpp", getFullCode()); + src += filename + ".cpp"; + FileUtils.saveFile(path + "Makefile.src", src); + //tepeTranslator.saveFile(path + "src_simulator/TEPE/test.h"); + } + + public String getFullCode() { + return mainFile; + } + + public void generateSystemC(boolean _debug, boolean _optimize) { + debug = _debug; + optimize = _optimize; + tmlmapping.removeAllRandomSequences(); + tmlmodeling = tmlmapping.getTMLModeling(); + tasks = new ArrayList<MappedSystemCTask>(); + //generateSystemCTasks(); + //generateEBRDDs(); + generateMainFile(); + generateMakefileSrc(); + } + + private void generateMainFile() { + makeHeader(); + makeDeclarations(); + header += tepeTranslator.getEqFuncDeclaration() + "\n"; + mainFile = header + declaration; + mainFile = Conversion.indentString(mainFile, 4); + } + + private void generateMakefileSrc() { + src = "SRCS = "; + for(TMLTask mst: tmlmapping.getMappedTasks()) { + src += mst.getName() + ".cpp "; + } + //for(EBRDD ebrdd: ebrdds){ + // src += ebrdd.getName() + ".cpp "; + //} + } + + private void makeHeader() { + // System headers + header = "#include <Simulator.h>" + CR; + header += "#include <AliasConstraint.h>\n#include <EqConstraint.h>\n#include <LogConstraint.h>\n#include <PropLabConstraint.h>\n"; + header += "#include <PropRelConstraint.h>\n#include <SeqConstraint.h>\n#include <SignalConstraint.h>\n#include <TimeMMConstraint.h>\n"; + header += "#include <TimeTConstraint.h>\n"; + header += "#include <CPU.h>\n#include <SingleCoreCPU.h>\n#include <RRScheduler.h>\n#include <RRPrioScheduler.h>\n#include <PrioScheduler.h>\n#include <Bus.h>\n"; + header += "#include <Bridge.h>\n#include <Memory.h>\n#include <TMLbrbwChannel.h>\n#include <TMLnbrnbwChannel.h>\n"; + header += "#include <TMLbrnbwChannel.h>\n#include <TMLEventBChannel.h>\n#include <TMLEventFChannel.h>\n#include <TMLEventFBChannel.h>\n"; + header += "#include <TMLTransaction.h>\n#include <TMLCommand.h>\n#include <TMLTask.h>\n"; + header += "#include <SimComponents.h>\n#include <Server.h>\n#include <SimServSyncInfo.h>\n#include <ListenersSimCmd.h>\n"; + + // Generate tasks header + for(TMLTask mst: tmlmapping.getMappedTasks()) { + //header += "#include <" + mst.getReference() + ".h>" + CR; + header += "#include <" + mst.getName() + ".h>" + CR; + } + //for(EBRDD ebrdd: ebrdds){ + // header += "#include <" + ebrdd.getName() + ".h>" + CR; + //} + header += CR; + } + + private void makeDeclarations() { + declaration = "class CurrentComponents: public SimComponents{\npublic:\nCurrentComponents():SimComponents(" + tmlmapping.getHashCode() + "){\n"; + + // Declaration of HW nodes + declaration += "//Declaration of CPUs" + CR; + for(HwNode node: tmlmapping.getTMLArchitecture().getHwNodes()) { + if (node instanceof HwCPU) { + HwCPU exNode = (HwCPU)node; + if (exNode.getType().equals("CPURRPB")) + declaration += "PrioScheduler* " + exNode.getName() + "_scheduler = new PrioScheduler(\"" + exNode.getName() + "_PrioSched\",0)" + SCCR; + else + //tmlmapping.getTMLArchitecture().getMasterClockFrequency() * exNode.sliceTime + //declaration += "RRScheduler* " + exNode.getName() + "_scheduler = new RRScheduler(\"" + exNode.getName() + "_RRSched\", 0, 5, " + (int) Math.ceil(((float)exNode.execiTime)*(1+((float)exNode.branchingPredictionPenalty)/100)) + " ) " + SCCR; + declaration += "RRScheduler* " + exNode.getName() + "_scheduler = new RRScheduler(\"" + exNode.getName() + "_RRSched\", 0, " + (tmlmapping.getTMLArchitecture().getMasterClockFrequency() * exNode.sliceTime) + ", " + (int) Math.ceil((float)(exNode.clockRatio * Math.max(exNode.execiTime,exNode.execcTime) * (exNode.branchingPredictionPenalty * exNode.pipelineSize +100 - exNode.branchingPredictionPenalty))/100) + " ) " + SCCR; + //for(int cores=0; cores<exNode.nbOfCores; cores++){ + for(int cores=0; cores<1; cores++){ + //if (tmlmapping.isAUsedHwNode(node)) { + declaration += "CPU* " + exNode.getName() + cores + " = new SingleCoreCPU(" + exNode.getID() + ", \"" + exNode.getName() + "_" + cores + "\", " + exNode.getName() + "_scheduler" + ", "; + + declaration += exNode.clockRatio + ", " + exNode.execiTime + ", " + exNode.execcTime + ", " + exNode.pipelineSize + ", " + exNode.taskSwitchingTime + ", " + exNode.branchingPredictionPenalty + ", " + exNode.goIdleTime + ", " + exNode.maxConsecutiveIdleCycles + ", " + exNode.byteDataSize + ")" + SCCR; + if (cores!=0) declaration+= node.getName() + cores + "->setScheduler(" + exNode.getName() + "_scheduler,false)" + SCCR; + declaration += "addCPU("+ node.getName() + cores +")"+ SCCR; + } + } + if (node instanceof HwA) { + HwA hwaNode = (HwA)node; + declaration += "RRScheduler* " + hwaNode.getName() + "_scheduler = new RRScheduler(\"" + hwaNode.getName() + "_RRSched\", 0, " + (tmlmapping.getTMLArchitecture().getMasterClockFrequency() * hwaNode.DEFAULT_SLICE_TIME) + ", " + (int) Math.ceil((float)(hwaNode.clockRatio * Math.max(hwaNode.execiTime,hwaNode.execcTime) * (hwaNode.DEFAULT_BRANCHING_PREDICTION_PENALTY * hwaNode.DEFAULT_PIPELINE_SIZE +100 - hwaNode.DEFAULT_BRANCHING_PREDICTION_PENALTY))/100) + " ) " + SCCR; + for(int cores=0; cores<1; cores++){ + //if (tmlmapping.isAUsedHwNode(node)) { + declaration += "CPU* " + hwaNode.getName() + cores + " = new SingleCoreCPU(" + hwaNode.getID() + ", \"" + hwaNode.getName() + "_" + cores + "\", " + hwaNode.getName() + "_scheduler" + ", "; + + declaration += hwaNode.clockRatio + ", " + hwaNode.execiTime + ", " + hwaNode.execcTime + ", " + hwaNode.DEFAULT_PIPELINE_SIZE + ", " + hwaNode.DEFAULT_TASK_SWITCHING_TIME + ", " + hwaNode.DEFAULT_BRANCHING_PREDICTION_PENALTY + ", " + hwaNode.DEFAULT_GO_IDLE_TIME + ", " + hwaNode.DEFAULT_MAX_CONSECUTIVE_IDLE_CYCLES + ", " + hwaNode.byteDataSize + ")" + SCCR; + if (cores!=0) declaration+= node.getName() + cores + "->setScheduler(" + hwaNode.getName() + "_scheduler,false)" + SCCR; + declaration += "addCPU("+ node.getName() + cores +")"+ SCCR; + } + + } + } + declaration += CR; + + // Declaration of Buses + declaration += "//Declaration of Buses" + CR; + //declaration+="Bus* defaultBus = new Bus(-1,\"defaultBus\",100,1,1)" + SCCR; + //declaration += "addBus(defaultBus)"+ SCCR; + for(HwNode node: tmlmapping.getTMLArchitecture().getHwNodes()) { + if (node instanceof HwBus) { + //if (tmlmapping.isAUsedHwNode(node)) { + HwBus thisBus = (HwBus)node; + for(int i=0; i< thisBus.pipelineSize; i++){ + declaration += "Bus* " + node.getName() + "_" + i + " = new Bus("+ node.getID() + ",\"" + node.getName() + "_" + i + "\",0, 100, "+ thisBus.byteDataSize + ", " + node.clockRatio + ","; + if(thisBus.arbitration==HwBus.CAN) declaration +="true"; else declaration +="false"; + declaration += ");\naddBus("+ node.getName() + "_" + i + ")"+ SCCR; + } + //} + } + } + declaration += CR; + + // Declaration of Bridges + declaration += "//Declaration of Bridges" + CR; + for(HwNode node: tmlmapping.getTMLArchitecture().getHwNodes()) { + if (node instanceof HwBridge) { + declaration+= "Bridge* " + node.getName() + " = new Bridge("+ node.getID() + ",\"" + node.getName() + "\", " + node.clockRatio + ", " + ((HwBridge)node).bufferByteSize + ")" +SCCR; + declaration += "addBridge("+ node.getName() +")"+ SCCR; + } + } + declaration += CR; + + // Declaration of Memories + //declaration += "//Declaration of Memories\nMemory* defaultMemory = new Memory(-1,\"defaultMemory\",1,4)" + SCCR; + //declaration += "addMem(defaultMemory)"+ SCCR; + declaration += "//Declaration of Memories" + CR; + for(HwNode node: tmlmapping.getTMLArchitecture().getHwNodes()) { + if (node instanceof HwMemory) { + declaration+= "Memory* " + node.getName() + " = new Memory("+ node.getID() + ",\"" + node.getName() + "\", " + node.clockRatio + ", " + ((HwMemory)node).byteDataSize + ")" +SCCR; + declaration += "addMem("+ node.getName() +")"+ SCCR; + } + } + declaration += CR; + + //Declaration of Bus masters + declaration += "//Declaration of Bus masters" + CR; + for(HwNode node: tmlmapping.getTMLArchitecture().getHwNodes()){ + if (node instanceof HwExecutionNode || node instanceof HwBridge){ + ArrayList<HwLink> nodeLinks= tmlmapping.getTMLArchitecture().getLinkByHwNode(node); + if (!nodeLinks.isEmpty()){ + //declaration+= "BusMaster* " + node.getName() + "2defaultBus = new BusMaster(\"" + node.getName() + "2defaultBus\", 0, defaultBus)" + SCCR; + //else{ + for(HwLink link: nodeLinks){ + //declaration+= "BusMaster* " + node.getName() + "_" + link.bus.getName() + "_Master = new BusMaster(\"" + node.getName() + "_" + link.bus.getName() + "_Master\", " + link.getPriority() + ", 1, array(1, (SchedulableCommDevice*)" + link.bus.getName() + "))" + SCCR; + int noOfCores; + //if (node instanceof HwCPU) noOfCores= ((HwCPU)node).nbOfCores; else noOfCores=1; + noOfCores=1; + for (int cores=0; cores<noOfCores; cores++){ + String nodeName=node.getName(); + if ((node instanceof HwCPU) || (node instanceof HwA) ) + nodeName+= cores; + declaration+= "BusMaster* " + nodeName + "_" + link.bus.getName() + "_Master = new BusMaster(\"" + nodeName + "_" + link.bus.getName() + "_Master\", " + link.getPriority() + ", " + link.bus.pipelineSize + ", array(" + link.bus.pipelineSize; + for(int i=0; i< link.bus.pipelineSize; i++) + declaration+= ", (SchedulableCommDevice*)" + link.bus.getName() + "_" + i; + declaration+= "))" + SCCR; + declaration+= nodeName + "->addBusMaster(" + nodeName + "_" + link.bus.getName() + "_Master)" + SCCR; + } + } + } + } + } + declaration += CR; + + // Declaration of channels + TMLChannel channel; + String tmp,param; + declaration += "//Declaration of channels" + CR; + for(TMLElement elem: tmlmodeling.getChannels()){ + if (elem instanceof TMLChannel) { + channel = (TMLChannel)elem; + switch(channel.getType()) { + case TMLChannel.BRBW: + tmp = "TMLbrbwChannel"; + param= "," + channel.getMax() + ",0"; + break; + case TMLChannel.BRNBW: + tmp = "TMLbrnbwChannel"; + param= ",0"; + break; + case TMLChannel.NBRNBW: + default: + tmp = "TMLnbrnbwChannel"; + param= ""; + } + declaration += tmp + "* " + channel.getExtendedName() + " = new " + tmp +"(" + channel.getID() + ",\"" + channel.getName() + "\"," + channel.getSize() + ","; + TraceManager.addDev("Channel: " + channel.getName()); + //TraceManager.addDev("Channel origin node: " + channel.getOriginTask().getName() + " dest node: " + channel.getDestinationTask().getName()); + TraceManager.addDev( "the list of mapped tasks: " + tmlmapping.getMappedTasks().toString() ); + declaration+= determineRouting(tmlmapping.getHwNodeOf(channel.getOriginTask()), tmlmapping.getHwNodeOf(channel.getDestinationTask()), elem) + param + "," + channel.getPriority(); + if (channel.isLossy() && channel.getType()!=TMLChannel.NBRNBW) declaration += "," + channel.getLossPercentage() + "," + channel.getMaxNbOfLoss(); + declaration += ")"+ SCCR; + declaration += "addChannel("+ channel.getExtendedName() +")"+ SCCR; + } + } + declaration += CR; + + // Declaration of events + declaration += "//Declaration of events" + CR; + for(TMLEvent evt: tmlmodeling.getEvents()) { + if (evt.isInfinite()) { + tmp = "TMLEventBChannel<ParamType," + evt.getNbOfParams() + ">"; + param= ",0,false,false"; + } else { + if (evt.isBlocking()) { + tmp = "TMLEventFBChannel<ParamType," + evt.getNbOfParams() + ">"; + param= "," + evt.getMaxSize() + ",0"; + } else { + tmp = "TMLEventFChannel<ParamType," + evt.getNbOfParams() + ">"; + param= "," + evt.getMaxSize() + ",0"; + } + } + //param += "," + evt.getNbOfParams(); + if (tmlmapping.isCommNodeMappedOn(evt,null)){ + TraceManager.addDev("Evt: " + evt.getName()); + declaration += tmp + "* " + evt.getExtendedName() + " = new " + tmp + "(" + evt.getID() + ",\"" + evt.getName() + "\"," + determineRouting(tmlmapping.getHwNodeOf(evt.getOriginTask()), tmlmapping.getHwNodeOf(evt.getDestinationTask()), evt) + param; + + }else{ + declaration += tmp + "* " + evt.getExtendedName() + " = new " + tmp + "(" + evt.getID() + ",\"" + evt.getName() + "\",0,0,0" + param; ///old command + } + if (evt.isLossy()) declaration += "," + evt.getLossPercentage() + "," + evt.getMaxNbOfLoss(); + declaration += ")" + SCCR; + declaration += "addEvent("+ evt.getExtendedName() +")"+ SCCR; + } + declaration += CR; + + // Declaration of requests + declaration += "//Declaration of requests" + CR; + for(TMLTask task: tmlmodeling.getTasks()) { + if (task.isRequested()){ + TMLRequest req = task.getRequest(); + if (tmlmapping.isCommNodeMappedOn(req,null)){ + //declaration += "TMLEventBChannel* reqChannel_"+ task.getName() + " = new TMLEventBChannel(" + + TraceManager.addDev("Request: " + req.getName()); + declaration += "TMLEventBChannel<ParamType," + req.getNbOfParams() + ">* reqChannel_"+ task.getName() + " = new TMLEventBChannel<ParamType," + req.getNbOfParams() + ">(" + + req.getID() + ",\"reqChannel"+ task.getName() + "\"," + + determineRouting(tmlmapping.getHwNodeOf(req.getOriginTasks().get(0)), //tmlmapping.getHwNodeOf(req.getDestinationTask()), req) + ",0," + req.getNbOfParams() + ",true)" + SCCR; + tmlmapping.getHwNodeOf(req.getDestinationTask()), req) + ",0,true,false"; + }else{ + declaration += "TMLEventBChannel<ParamType," + req.getNbOfParams() + ">* reqChannel_"+ task.getName() + " = new TMLEventBChannel<ParamType," + req.getNbOfParams() + ">(" + //req.getID() + ",\"reqChannel"+ task.getName() + "\",0,0,0,0," + req.getNbOfParams() + ",true)" + SCCR; + req.getID() + ",\"reqChannel"+ task.getName() + "\",0,0,0,0,true,false"; + } + if (req.isLossy()) declaration += "," + req.getLossPercentage() + "," + req.getMaxNbOfLoss(); + declaration += ")" + SCCR; + declaration += "addRequest(reqChannel_"+ task.getName() +")"+ SCCR; + } + } + declaration += CR; + + ///Set bus schedulers + declaration += "//Set bus schedulers" + CR; + for(HwNode node: tmlmapping.getTMLArchitecture().getHwNodes()) { + if (node instanceof HwBus) { + ArrayList<HwLink> busLinks= tmlmapping.getTMLArchitecture().getLinkByBus((HwBus)node); + String devices=""; + int numDevices=0; + if (!busLinks.isEmpty()){ + for(HwLink link: busLinks){ + if (link.hwnode instanceof HwExecutionNode || link.hwnode instanceof HwBridge){ + if ((link.hwnode instanceof HwCPU) || (link.hwnode instanceof HwA)){ + //for (int cores=0; cores< ((HwCPU)link.hwnode).nbOfCores; cores++){ + for (int cores=0; cores< 1; cores++){ + devices += ", (WorkloadSource*)" + link.hwnode.getName()+ cores + "_" + node.getName() + "_Master"; + numDevices++; + } + }else{ + devices += ", (WorkloadSource*)" + link.hwnode.getName()+ "_" + node.getName() + "_Master"; + numDevices++; + } + } + } + declaration += node.getName() + "_0->setScheduler((WorkloadSource*) new "; + if (((HwBus)node).arbitration==HwBus.BASIC_ROUND_ROBIN) + //declaration+="RRScheduler(\"" + node.getName() + "_RRSched\", 0, 5, " + (int) Math.ceil(((float)node.clockRatio)/((float)((HwBus)node).byteDataSize)) + ", array("; + declaration+="RRScheduler(\"" + node.getName() + "_RRSched\", 0, 5, " + (int) Math.ceil(((float)node.clockRatio)/((float)((HwBus)node).byteDataSize)) + ", array("; + else + declaration+="PrioScheduler(\"" + node.getName() + "_PrioSched\", 0, array("; + declaration+= numDevices + devices + "), " + numDevices + "))" + SCCR; + } + for(int i=1; i< ((HwBus)node).pipelineSize; i++) + declaration+=node.getName() + "_" + i + "->setScheduler(" + node.getName() + "_0->getScheduler(),false)" +SCCR; + } + } + declaration += CR; + + + //Declaration of Tasks + ListIterator iterator = tmlmapping.getNodes().listIterator(); + declaration += "//Declaration of tasks" + CR; + HwExecutionNode node; + //for(TMLTask task: tmlmodeling.getTasks()) { + ArrayList<TMLChannel> channels; + ArrayList<TMLEvent> events; + ArrayList<TMLRequest> requests; + int[] aStatistics = new int[8]; + Set<Integer> mappedChannels = new HashSet<Integer>(); + for(TMLTask task: tmlmapping.getMappedTasks()){ + node=(HwExecutionNode)iterator.next(); + int noOfCores; + declaration += task.getName() + "* task__" + task.getName() + " = new " + task.getName() + "("+ task.getID() +","+ task.getPriority() + ",\"" + task.getName() + "\", array("; + + if (node instanceof HwCPU){ + //declaration+= ((HwCPU)node).nbOfCores; + declaration+= 1; + //for (int cores=0; cores< ((HwCPU)node).nbOfCores; cores++){ + for (int cores=0; cores< 1; cores++){ + declaration+= "," + node.getName()+cores; + } + //declaration+= ")," + ((HwCPU)node).nbOfCores + CR; + declaration+= "),1" + CR; + }else if (node instanceof HwA){ + //declaration+= ((HwCPU)node).nbOfCores; + declaration+= 1; + //for (int cores=0; cores< ((HwCPU)node).nbOfCores; cores++){ + for (int cores=0; cores< 1; cores++){ + declaration+= "," + node.getName()+cores; + } + //declaration+= ")," + ((HwCPU)node).nbOfCores + CR; + declaration+= "),1" + CR; + } else { + declaration += "1," + node.getName() + "),1" + CR; + } + + + MappedSystemCTask mst; + channels = new ArrayList<TMLChannel>(tmlmodeling.getChannels(task)); + events = new ArrayList<TMLEvent>(tmlmodeling.getEvents(task)); + requests = new ArrayList<TMLRequest>(tmlmodeling.getRequests(task)); + + mst = new MappedSystemCTask(task, channels, events, requests, tmlmapping, mappedChannels); + //mst.generateSystemC(debug, optimize, dependencies); + //mst.generateSystemC(debug, optimize); + tasks.add(mst); + for(TMLChannel channelb: channels) + declaration += "," + channelb.getExtendedName()+CR; + + for(TMLEvent evt: events) + declaration += "," + evt.getExtendedName()+CR; + + for(TMLRequest req: requests) + if (req.isAnOriginTask(task)) declaration+=",reqChannel_" + req.getDestinationTask().getName()+CR; + + if (task.isRequested()) declaration += ",reqChannel_"+task.getName()+CR; + declaration += ")" + SCCR; + declaration += "addTask(task__"+ task.getName() +")"+ SCCR; + } + //int[] aStatistics = new int[8]; + declaration += "\n}\n\n"; + + //Declaration of TEPEs + declaration += "void generateTEPEs(){" + CR; + declaration += "//Declaration of TEPEs" + CR; + tepeTranslator.generateTEPEs(); + declaration += tepeTranslator.getCode(); + + //Generation of tasks + for(MappedSystemCTask task: tasks){ + task.determineCheckpoints(aStatistics); + task.generateSystemC(debug, optimize); + } + + //Declaration of TEPEs continued + declaration += CR; + declaration += "}\n};\n\n" + tepeTranslator.getEqFuncs(); + declaration +="#include <main.h>\n"; + + if (aStatistics[0]!=0) TraceManager.addDev("Global gain variables " + 100 * aStatistics[1] / aStatistics[0]); + if (aStatistics[2]!=0) TraceManager.addDev("Global gain Channels " + 100 * aStatistics[3] / aStatistics[2]); + if (aStatistics[4]!=0) TraceManager.addDev("Global gain events " + 100 * aStatistics[5] / aStatistics[4]); + if (aStatistics[6]!=0) TraceManager.addDev("Global gain checkpoints " + 100 * aStatistics[7] / aStatistics[6]); + + //Declaration of EBRDDs + /*declaration += "//Declaration of EBRDDs" + CR; + for(EBRDD ebrdd: ebrdds){ + declaration += ebrdd.getName() + "* ebrdd__" + ebrdd.getName() + " = new " + ebrdd.getName() + "(0, \""+ ebrdd.getName() + "\");\n"; + declaration += "addEBRDD(ebrdd__"+ ebrdd.getName() +")"+ SCCR; + }*/ + } + + + private int extractPath(LinkedList<HwCommunicationNode> path, strwrap masters, strwrap slaves, HwNode startNode, HwNode destNode, boolean reverseIn){ + String firstPart=""; //lastBus=""; + int masterCount=0; + boolean reverse=reverseIn; + if (reverseIn) + slaves.str+=",static_cast<Slave*>(0)"; + else + firstPart=startNode.getName() + "0"; + /*TraceManager.addDev("------------------------------------------------------"); + for(HwCommunicationNode commElem:path){ + TraceManager.addDev("CommELem to process: " + commElem.getName()); + } + TraceManager.addDev("------------------------------------------------------");*/ + for(HwCommunicationNode commElem:path){ + //TraceManager.addDev("CommELem to process: " + commElem.getName()); + //String commElemName = commElem.getName(); + //if (commElem instanceof HwCPU) commElemName += "0"; + //System.out.println("Next elem in path: " + commElem.getName()); + if (commElem instanceof HwMemory){ + reverse=true; + slaves.str+= ",static_cast<Slave*>(" + commElem.getName() + "),static_cast<Slave*>(" + commElem.getName() + ")"; + //firstPart=lastBus; + firstPart=""; + }else{ + if (reverse){ + if (firstPart.length()==0){ + firstPart=commElem.getName(); + //firstPart=commElemName; + }else{ + masters.str+= "," + commElem.getName() + "_" + firstPart + "_Master"; + //masters.str+= "," + commElemName + "_" + firstPart + "_Master"; + masterCount++; + slaves.str+= ",static_cast<Slave*>(" + commElem.getName() + ")"; + firstPart=""; + } + }else{ + if (firstPart.length()==0){ + firstPart=commElem.getName(); + slaves.str+= ",static_cast<Slave*>(" + firstPart + ")"; + }else{ + //lastBus=commElem.getName(); + masters.str+= "," + firstPart + "_" + commElem.getName() + "_Master"; + masterCount++; + firstPart=""; + } + } + } + } + if (reverse){ + //masters.str+= "," + destNode.getName() + "_" + firstPart + "_Master"; + masters.str+= "," + destNode.getName() + "0_" + firstPart + "_Master"; + return masterCount+1; + }else{ + slaves.str+=",static_cast<Slave*>(0)"; + return -masterCount; + } + } + + private String determineRouting( HwNode startNode, HwNode destNode, TMLElement commElemToRoute ){ + + //TraceManager.addDev( "Determine routing from " + startNode.getName() + " to " + destNode.getName() ); + strwrap masters=new strwrap(), slaves=new strwrap(); + LinkedList<HwCommunicationNode> path = new LinkedList<HwCommunicationNode>(); + LinkedList<HwCommunicationNode> commNodes = new LinkedList<HwCommunicationNode>(); + + for( HwNode node: tmlmapping.getTMLArchitecture().getHwNodes() ) { + if( node instanceof HwCommunicationNode ) { + commNodes.add((HwCommunicationNode) node); + TraceManager.addDev( "Inserted: " + ((HwCommunicationNode)node).getName() ); + } + } + if( startNode == null ) { + TraceManager.addDev( "NULL REFERENCE" ); + } + else { + TraceManager.addDev( "startNode: " + startNode.getName() ); + } + HwMemory memory = getMemConnectedToBusChannelMapped( commNodes, null, commElemToRoute ); + if( memory == null ) { + System.out.println( "no memories to map" ); + exploreBuses( 0, commNodes, path, startNode, destNode, commElemToRoute ); + } + else { + LinkedList<HwCommunicationNode> commNodes2 = new LinkedList<HwCommunicationNode>(commNodes); + //exploreBuses(0, commNodes, path, startNode, memory, commElemToRoute); + if( !exploreBuses( 0, commNodes, path, startNode, memory, commElemToRoute ) ) { + TraceManager.addDev("NO route to " + memory.getName() + "found!!!!!!!!!!!!!!!!!!!!!!!!!!"); + } + path.add( memory ); + exploreBuses( 0, commNodes2, path, memory, destNode, commElemToRoute ); + } + int hopNum; + if ( (hopNum=extractPath(path, masters, slaves, startNode, destNode, false))<0){ + hopNum=extractPath(path, masters, slaves, destNode, destNode, true)-hopNum; + } + TraceManager.addDev(commElemToRoute.getName() + " is mapped on:"); + for(HwCommunicationNode commElem:path){ + TraceManager.addDev(commElem.getName()); + } + TraceManager.addDev("number of elements: " + hopNum); + TraceManager.addDev("masters: " + masters.str); + TraceManager.addDev("slaves: " + slaves.str); + return hopNum + ",array(" + hopNum + masters.str + "),array(" + hopNum + slaves.str + ")"; + } + + private boolean exploreBuses(int depth, LinkedList<HwCommunicationNode> commNodes, LinkedList<HwCommunicationNode> path, HwNode startNode, HwNode destNode, TMLElement commElemToRoute){ + //first called with Maping:getCommunicationNodes + LinkedList<HwCommunicationNode> nodesToExplore; + TraceManager.addDev("No of comm nodes " + commNodes.size()); + boolean busExploreMode = ((depth & 1) == 0); + //if (depth % 2 == 0){ + if(busExploreMode){ + TraceManager.addDev("search for buses connected to " + startNode.getName()); + nodesToExplore=getBusesConnectedToNode(commNodes, startNode); + }else{ + TraceManager.addDev("search for bridges connected to: " + startNode.getName()); + nodesToExplore=getBridgesConnectedToBus(commNodes, (HwBus)startNode); + } + //HwMemory memory = null; + TraceManager.addDev("no of elements found: " + nodesToExplore.size()); + for(HwCommunicationNode currNode:nodesToExplore){ + //memory = null; + if (busExploreMode){ + //memory = getMemConnectedToBusChannelMapped(commNodes, (HwBus)currNode, commElemToRoute); + if(isBusConnectedToNode(currNode, destNode)){ + TraceManager.addDev(currNode.getName() + " is last node"); + path.add(currNode); + //if (memory!=null) path.add(memory); + commNodes.remove(currNode); + return true; + } + } + if(tmlmapping.isCommNodeMappedOn(commElemToRoute, currNode)){ + TraceManager.addDev(currNode.getName() + " mapping found for " + commElemToRoute.getName()); + path.add(currNode); + //if (memory!=null) path.add(memory); + commNodes.remove(currNode); + if (exploreBuses(depth+1, commNodes, path, currNode, destNode, commElemToRoute)) return true; + path.remove(currNode); + //if (memory!=null) path.remove(memory); + commNodes.add(currNode); + } + } + for(HwCommunicationNode currNode:nodesToExplore){ + //if (busExploreMode) memory = getMemConnectedToBusChannelMapped(commNodes, (HwBus)currNode, commElemToRoute); else memory=null; + path.add(currNode); + //if (memory!=null) path.add(memory); + commNodes.remove(currNode); + //for (int i=0; i<path.size(); i++) System.out.print(" "); + TraceManager.addDev(currNode.getName()); + if (exploreBuses(depth+1, commNodes, path, currNode, destNode, commElemToRoute)) return true; + path.remove(currNode); + //if (memory!=null) path.remove(memory); + commNodes.add(currNode); + } + return false; + } + + private HwMemory getMemConnectedToBusChannelMapped( LinkedList<HwCommunicationNode> _commNodes, HwBus _bus, TMLElement _channel ) { + for( HwCommunicationNode commNode: _commNodes ) { + if( commNode instanceof HwMemory ) { + if( _bus != null ) System.out.println(commNode.getName() + " connected to bus " + _bus.getName() + ": " + tmlmapping.getTMLArchitecture().isNodeConnectedToBus(commNode, _bus)); + System.out.println(_channel.getName() + " is mapped onto " + commNode.getName() + ": " + tmlmapping.isCommNodeMappedOn(_channel,commNode)); + if( ( _bus == null || tmlmapping.getTMLArchitecture().isNodeConnectedToBus( commNode, _bus ) ) + && tmlmapping.isCommNodeMappedOn( _channel, commNode ) ) { + return (HwMemory)commNode; + } + } + } + return null; + } + + private LinkedList<HwCommunicationNode> getBusesConnectedToNode(LinkedList<HwCommunicationNode> _commNodes, HwNode _node){ + LinkedList<HwCommunicationNode> resultList = new LinkedList<HwCommunicationNode>(); + for(HwCommunicationNode commNode: _commNodes){ + if (commNode instanceof HwBus){ + if (tmlmapping.getTMLArchitecture().isNodeConnectedToBus(_node, (HwBus)commNode)) resultList.add((HwBus)commNode); + } + } + return resultList; + } + + private LinkedList<HwCommunicationNode> getBridgesConnectedToBus(LinkedList<HwCommunicationNode> _commNodes, HwBus _bus){ + LinkedList<HwCommunicationNode> resultList = new LinkedList<HwCommunicationNode>(); + for(HwCommunicationNode commNode: _commNodes){ + if (commNode instanceof HwBridge){ + if (tmlmapping.getTMLArchitecture().isNodeConnectedToBus(commNode, _bus)) resultList.add((HwBridge)commNode); + } + } + return resultList; + } + + private boolean isBusConnectedToNode(HwCommunicationNode commNode, HwNode node){ + for(HwLink link: tmlmapping.getTMLArchitecture().getHwLinks()) { + if(link.bus==commNode && link.hwnode==node) return true; + } + return false; + } + + private String getIdentifierNameByID(int id){ + + for(MappedSystemCTask task: tasks){ + String tmp = task.getIdentifierNameByID(id); + if (tmp!=null) return tmp; + } + return null; + } + + /*private void generateEBRDDs(){ + for(EBRDD ebrdd: ebrdds){ + SystemCEBRDD newEbrdd = new SystemCEBRDD(ebrdd, tmlmodeling, tmlmapping); + newEbrdd.generateSystemC(debug); + systemCebrdds.add(newEbrdd); + } + }*/ + + private void generateTaskFiles(String path) throws FileException { + for(MappedSystemCTask mst: tasks) { + mst.saveInFiles(path); + } + //for(SystemCEBRDD ebrdd: systemCebrdds) { + // ebrdd.saveInFiles(path); + //} + } + + + public MappedSystemCTask getMappedTaskByName(String iName){ + for(MappedSystemCTask task: tasks){ + if (task.getTMLTask().getName().equals(iName)) return task; + } + return null; + } } diff --git a/src/ui/window/JDialogSystemCGeneration.java b/src/ui/window/JDialogSystemCGeneration.java index 4ef96a0f189e272e12ab82fad6e8d8b84324c5d9..290b8ba89ddf1ffe6185fae5074b62fbd92d248a 100755 --- a/src/ui/window/JDialogSystemCGeneration.java +++ b/src/ui/window/JDialogSystemCGeneration.java @@ -67,270 +67,270 @@ import launcher.*; public class JDialogSystemCGeneration extends javax.swing.JDialog implements ActionListener, Runnable, MasterProcessInterface, ListSelectionListener { - + protected MainGUI mgui; - + private static String textSysC1 = "Generate SystemC code in"; private static String textSysC2 = "Compile SystemC code in"; //private String textSysC3 = "with"; private static String textSysC4 = "Run simulation to completion:"; - private static String textSysC5 = "Run interactive simulation:"; - private static String textSysC6 = "Run formal verification:"; - + private static String textSysC5 = "Run interactive simulation:"; + private static String textSysC6 = "Run formal verification:"; + private static String unitCycle = "1"; - - private static String[] simus = { "SystemC Simulator - LabSoC version", - "C++ Simulator - LabSoc version", - "C++ Simulator with Communication Patterns" }; - private static int selectedItem = 1; - + + private static String[] simus = { "SystemC Simulator - LabSoC version", + "C++ Simulator - LabSoc version", + "C++ Simulator with Communication Patterns" }; + private static int selectedItem = 1; + protected static String pathCode; protected static String pathCompiler; protected static String pathExecute; - protected static String pathInteractiveExecute; - protected static String pathFormalExecute; - - protected static boolean interactiveSimulationSelected = true; - protected static boolean optimizeModeSelected = true; - + protected static String pathInteractiveExecute; + protected static String pathFormalExecute; + + protected static boolean interactiveSimulationSelected = true; + protected static boolean optimizeModeSelected = true; + protected final static int NOT_STARTED = 1; protected final static int STARTED = 2; protected final static int STOPPED = 3; - + int mode; - - - + + + //components protected JTextArea jta; protected JButton start; protected JButton stop; protected JButton close; - - protected JRadioButton exe, exeint, exeformal; - protected ButtonGroup exegroup; + + protected JRadioButton exe, exeint, exeformal; + protected ButtonGroup exegroup; protected JLabel gen, comp; protected JTextField code1, code2, unitcycle, compiler1, exe1, exe2, exe3, exe2int, exe2formal; protected JTabbedPane jp1; protected JScrollPane jsp; protected JCheckBox removeCppFiles, removeXFiles, debugmode, optimizemode; - protected JComboBox versionSimulator; - - //EBRDD - /*private static Vector validated, ignored; - private Vector val, ign; - private JList listIgnored; - private JList listValidated; - private JButton allValidated; - private JButton addOneValidated; - private JButton addOneIgnored; - private JButton allIgnored; - private JPanel panele1, panele2, panele3, panele4, panel5, panel6;*/ - - - //TEPED - private static Vector validatedTepe, ignoredTepe; - private Vector valTepe, ignTepe; - private JList listIgnoredTepe; + protected JComboBox versionSimulator; + + //EBRDD + /*private static Vector validated, ignored; + private Vector val, ign; + private JList listIgnored; + private JList listValidated; + private JButton allValidated; + private JButton addOneValidated; + private JButton addOneIgnored; + private JButton allIgnored; + private JPanel panele1, panele2, panele3, panele4, panel5, panel6;*/ + + + //TEPED + private static Vector validatedTepe, ignoredTepe; + private Vector valTepe, ignTepe; + private JList listIgnoredTepe; private JList listValidatedTepe; private JButton allValidatedTepe; private JButton addOneValidatedTepe; private JButton addOneIgnoredTepe; private JButton allIgnoredTepe; - private JPanel panele1Tepe, panele2Tepe, panele3Tepe, panele4Tepe, panel5Tepe, panel6Tepe; - - - - + private JPanel panele1Tepe, panele2Tepe, panele3Tepe, panele4Tepe, panel5Tepe, panel6Tepe; + + + + private Thread t; private boolean go = false; //private ProcessThread pt; private boolean hasError = false; - protected boolean startProcess = false; - + protected boolean startProcess = false; + //private TURTLE2Java t2j; - + private String hostSystemC; - + protected RshClient rshc; - + // Automatic modes public final static int MANUAL = 0; public final static int ONE_TRACE = 1; public final static int ANIMATION = 2; public final static int FORMAL_VERIFICATION = 3; - + private int automatic; private boolean wasClosed = false; - - + + /** Creates new form */ public JDialogSystemCGeneration(Frame f, MainGUI _mgui, String title, String _hostSystemC, String _pathCode, String _pathCompiler, String _pathExecute, String _pathInteractiveExecute, String _graphPath, int _automatic) { super(f, title, true); - + mgui = _mgui; - + if (pathCode == null) { pathCode = _pathCode; } - + if (pathCompiler == null) pathCompiler = _pathCompiler; - + if (pathExecute == null) pathExecute = _pathExecute; - - if (pathInteractiveExecute == null) { - if (_graphPath != null) { - _pathInteractiveExecute += " -gpath " + _graphPath; - } + + if (pathInteractiveExecute == null) { + if (_graphPath != null) { + _pathInteractiveExecute += " -gpath " + _graphPath; + } pathInteractiveExecute = _pathInteractiveExecute; - } - - if (pathFormalExecute == null) { - pathFormalExecute = pathInteractiveExecute; - - int index = pathFormalExecute.indexOf("-server"); - if (index != -1) { - pathFormalExecute = pathFormalExecute.substring(0, index) + pathFormalExecute.substring(index+7, pathFormalExecute.length()); - pathFormalExecute += " -explo"; - } - } - + } + + if (pathFormalExecute == null) { + pathFormalExecute = pathInteractiveExecute; + + int index = pathFormalExecute.indexOf("-server"); + if (index != -1) { + pathFormalExecute = pathFormalExecute.substring(0, index) + pathFormalExecute.substring(index+7, pathFormalExecute.length()); + pathFormalExecute += " -explo"; + } + } + hostSystemC = _hostSystemC; - + automatic = _automatic; - - makeLists(); - + + makeLists(); + initComponents(); myInitComponents(); pack(); - + //getGlassPane().addMouseListener( new MouseAdapter() {}); getGlassPane().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); - + if (automatic > 0) { - startProcess(); + startProcess(); + } + } + + protected void makeLists() { + if (validatedTepe == null) { + validatedTepe = new Vector(); + } + + if (ignoredTepe == null) { + ignoredTepe = new Vector(); + } + + valTepe = new Vector(); + ignTepe = new Vector(); + + ArrayList<AvatarPDPanel> al = mgui.getAllAvatarPDPanels(); + + for(AvatarPDPanel panel: al) { + if(validatedTepe.contains(panel)) { + valTepe.add(panel); + } else { + ignTepe.add(panel); + } } } - - protected void makeLists() { - if (validatedTepe == null) { - validatedTepe = new Vector(); - } - - if (ignoredTepe == null) { - ignoredTepe = new Vector(); - } - - valTepe = new Vector(); - ignTepe = new Vector(); - - ArrayList<AvatarPDPanel> al = mgui.getAllAvatarPDPanels(); - - for(AvatarPDPanel panel: al) { - if(validatedTepe.contains(panel)) { - valTepe.add(panel); - } else { - ignTepe.add(panel); - } - } - } - - + + protected void myInitComponents() { mode = NOT_STARTED; setButtons(); - setList(); - updateInteractiveSimulation(); + setList(); + updateInteractiveSimulation(); } - + protected void initComponents() { - + Container c = getContentPane(); setFont(new Font("Helvetica", Font.PLAIN, 14)); c.setLayout(new BorderLayout()); //setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - + jp1 = new JTabbedPane(); - + JPanel jp01 = new JPanel(); GridBagLayout gridbag01 = new GridBagLayout(); GridBagConstraints c01 = new GridBagConstraints(); jp01.setLayout(gridbag01); jp01.setBorder(new javax.swing.border.TitledBorder("Code generation")); - + JPanel jp02 = new JPanel(); GridBagLayout gridbag02 = new GridBagLayout(); GridBagConstraints c02 = new GridBagConstraints(); jp02.setLayout(gridbag02); jp02.setBorder(new javax.swing.border.TitledBorder("Compilation")); - + JPanel jp03 = new JPanel(); GridBagLayout gridbag03 = new GridBagLayout(); GridBagConstraints c03 = new GridBagConstraints(); jp03.setLayout(gridbag03); jp03.setBorder(new javax.swing.border.TitledBorder("Execution")); - - + + c01.gridheight = 1; c01.weighty = 1.0; c01.weightx = 1.0; c01.gridwidth = GridBagConstraints.REMAINDER; //end row c01.fill = GridBagConstraints.BOTH; c01.gridheight = 1; - + gen = new JLabel(textSysC1); //genJava.addActionListener(this); jp01.add(gen, c01); - + code1 = new JTextField(pathCode, 100); jp01.add(code1, c01); - + jp01.add(new JLabel(" "), c01); c01.gridwidth = GridBagConstraints.REMAINDER; //end row - + c01.gridwidth = GridBagConstraints.REMAINDER; //end row jp01.add(new JLabel("1 time unit = "), c01); - + unitcycle = new JTextField(unitCycle, 10); jp01.add(unitcycle, c01); - + jp01.add(new JLabel("cycle"), c01); - + removeCppFiles = new JCheckBox("Remove old .h / .cpp files"); removeCppFiles.setSelected(true); jp01.add(removeCppFiles, c01); - + removeXFiles = new JCheckBox("Remove old .x files"); removeXFiles.setSelected(true); jp01.add(removeXFiles, c01); - + debugmode = new JCheckBox("Put debug information in code"); debugmode.setSelected(false); jp01.add(debugmode, c01); - - optimizemode = new JCheckBox("Optimize code"); - optimizemode.setSelected(optimizeModeSelected); + + optimizemode = new JCheckBox("Optimize code"); + optimizemode.setSelected(optimizeModeSelected); jp01.add(optimizemode, c01); - - jp01.add(new JLabel("Simulator used:"), c01); - - versionSimulator = new JComboBox(simus); - versionSimulator.setSelectedIndex(selectedItem); - versionSimulator.addActionListener(this); - jp01.add(versionSimulator, c01); - //System.out.println("selectedItem=" + selectedItem); - - //devmode = new JCheckBox("Development version of the simulator"); + + jp01.add(new JLabel("Simulator used:"), c01); + + versionSimulator = new JComboBox(simus); + versionSimulator.setSelectedIndex(selectedItem); + versionSimulator.addActionListener(this); + jp01.add(versionSimulator, c01); + //System.out.println("selectedItem=" + selectedItem); + + //devmode = new JCheckBox("Development version of the simulator"); //devmode.setSelected(true); //jp01.add(devmode, c01); - + jp01.add(new JLabel(" "), c01); - - //EBRDDs - panele1Tepe = new JPanel(); + + //EBRDDs + panele1Tepe = new JPanel(); panele1Tepe.setLayout(new BorderLayout()); panele1Tepe.setBorder(new javax.swing.border.TitledBorder("Ignored TEPE Diagrams")); listIgnoredTepe = new JList(ignTepe); @@ -340,7 +340,7 @@ public class JDialogSystemCGeneration extends javax.swing.JDialog implements Act JScrollPane scrollPane1 = new JScrollPane(listIgnoredTepe); panele1Tepe.add(scrollPane1, BorderLayout.CENTER); panele1Tepe.setPreferredSize(new Dimension(200, 250)); - + // validated list panele2Tepe = new JPanel(); panele2Tepe.setLayout(new BorderLayout()); @@ -352,60 +352,60 @@ public class JDialogSystemCGeneration extends javax.swing.JDialog implements Act JScrollPane scrollPane2 = new JScrollPane(listValidatedTepe); panele2Tepe.add(scrollPane2, BorderLayout.CENTER); panele2Tepe.setPreferredSize(new Dimension(200, 250)); - - + + // central buttons panele3Tepe = new JPanel(); - GridBagLayout gridbage1 = new GridBagLayout(); + GridBagLayout gridbage1 = new GridBagLayout(); GridBagConstraints ce1 = new GridBagConstraints(); panele3Tepe.setLayout(gridbage1); - + ce1.weighty = 1.0; ce1.weightx = 1.0; ce1.gridwidth = GridBagConstraints.REMAINDER; //end row ce1.fill = GridBagConstraints.HORIZONTAL; ce1.gridheight = 1; - + allValidatedTepe = new JButton(IconManager.imgic50); allValidatedTepe.setPreferredSize(new Dimension(50, 25)); allValidatedTepe.addActionListener(this); allValidatedTepe.setActionCommand("allValidatedTepe"); panele3Tepe.add(allValidatedTepe, ce1); - + addOneValidatedTepe = new JButton(IconManager.imgic48); addOneValidatedTepe.setPreferredSize(new Dimension(50, 25)); addOneValidatedTepe.addActionListener(this); addOneValidatedTepe.setActionCommand("addOneValidatedTepe"); panele3Tepe.add(addOneValidatedTepe, ce1); - + panele3Tepe.add(new JLabel(" "), ce1); - + addOneIgnoredTepe = new JButton(IconManager.imgic46); addOneIgnoredTepe.addActionListener(this); addOneIgnoredTepe.setPreferredSize(new Dimension(50, 25)); addOneIgnoredTepe.setActionCommand("addOneIgnoredTepe"); panele3Tepe.add(addOneIgnoredTepe, ce1); - + allIgnoredTepe = new JButton(IconManager.imgic44); allIgnoredTepe.addActionListener(this); allIgnoredTepe.setPreferredSize(new Dimension(50, 25)); allIgnoredTepe.setActionCommand("allIgnoredTepe"); panele3Tepe.add(allIgnoredTepe, ce1); - - - panele4Tepe = new JPanel(); - panele4Tepe.setLayout(new BorderLayout()); - panele4Tepe.add(panele1Tepe, BorderLayout.WEST); - panele4Tepe.add(panele2Tepe, BorderLayout.EAST); - panele4Tepe.add(panele3Tepe, BorderLayout.CENTER); - - jp01.add(panele4Tepe, c01); - if (automatic > 0) { - //GraphicLib.enableComponents(jp01, false); + + + panele4Tepe = new JPanel(); + panele4Tepe.setLayout(new BorderLayout()); + panele4Tepe.add(panele1Tepe, BorderLayout.WEST); + panele4Tepe.add(panele2Tepe, BorderLayout.EAST); + panele4Tepe.add(panele3Tepe, BorderLayout.CENTER); + + jp01.add(panele4Tepe, c01); + if (automatic > 0) { + //GraphicLib.enableComponents(jp01, false); } - + jp1.add("Generate code", jp01); - + // Panel 02 c02.gridheight = 1; c02.weighty = 1.0; @@ -413,23 +413,23 @@ public class JDialogSystemCGeneration extends javax.swing.JDialog implements Act c02.gridwidth = GridBagConstraints.REMAINDER; //end row c02.fill = GridBagConstraints.BOTH; c02.gridheight = 1; - + comp = new JLabel(textSysC2); //compJava.addActionListener(this); jp02.add(comp, c02); - + code2 = new JTextField(pathCode, 100); jp02.add(code2, c02); - + jp02.add(new JLabel("with"), c02); - + compiler1 = new JTextField(pathCompiler, 100); jp02.add(compiler1, c02); - + jp02.add(new JLabel(" "), c02); - + jp1.add("Compile", jp02); - + // Panel 03 c03.gridheight = 1; c03.weighty = 1.0; @@ -437,104 +437,104 @@ public class JDialogSystemCGeneration extends javax.swing.JDialog implements Act c03.gridwidth = GridBagConstraints.REMAINDER; //end row c03.fill = GridBagConstraints.BOTH; c03.gridheight = 1; - - exegroup = new ButtonGroup(); + + exegroup = new ButtonGroup(); exe = new JRadioButton(textSysC4, false); - exe.addActionListener(this); - exegroup.add(exe); + exe.addActionListener(this); + exegroup.add(exe); //exeJava.addActionListener(this); jp03.add(exe, c03); - + exe2 = new JTextField(pathExecute, 100); jp03.add(exe2, c02); - - - - exeint = new JRadioButton(textSysC5, true); - exeint.addActionListener(this); - exegroup.add(exeint); + + + + exeint = new JRadioButton(textSysC5, true); + exeint.addActionListener(this); + exegroup.add(exeint); //exeJava.addActionListener(this); jp03.add(exeint, c03); exe2int = new JTextField(pathInteractiveExecute, 100); jp03.add(exe2int, c02); - - + + exeformal = new JRadioButton(textSysC6, true); - exeformal.addActionListener(this); - exegroup.add(exeformal); - jp03.add(exeformal, c03); - exe2formal = new JTextField(pathFormalExecute, 100); + exeformal.addActionListener(this); + exegroup.add(exeformal); + jp03.add(exeformal, c03); + exe2formal = new JTextField(pathFormalExecute, 100); jp03.add(exe2formal, c02); - + jp03.add(new JLabel(" "), c03); - + jp1.add("Execute", jp03); - + c.add(jp1, BorderLayout.NORTH); if (automatic > 0) { - //GraphicLib.enableComponents(jp03, false); - GraphicLib.enableComponents(jp1, false); + //GraphicLib.enableComponents(jp03, false); + GraphicLib.enableComponents(jp1, false); } - + jta = new ScrolledJTextArea(); jta.setEditable(false); jta.setMargin(new Insets(10, 10, 10, 10)); jta.setTabSize(3); if (automatic == 0) { - jta.append("Select options and then, click on 'start' to launch SystemC code generation / compilation\n"); + jta.append("Select options and then, click on 'start' to launch SystemC code generation / compilation\n"); } Font f = new Font("Courrier", Font.BOLD, 12); jta.setFont(f); jsp = new JScrollPane(jta, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); - + c.add(jsp, BorderLayout.CENTER); - - - start = new JButton("Start", IconManager.imgic53); - stop = new JButton("Stop", IconManager.imgic55); - - - start.setPreferredSize(new Dimension(100, 30)); - stop.setPreferredSize(new Dimension(100, 30)); - - - start.addActionListener(this); - stop.addActionListener(this); - - - + + + start = new JButton("Start", IconManager.imgic53); + stop = new JButton("Stop", IconManager.imgic55); + + + start.setPreferredSize(new Dimension(100, 30)); + stop.setPreferredSize(new Dimension(100, 30)); + + + start.addActionListener(this); + stop.addActionListener(this); + + + close = new JButton("Close", IconManager.imgic27); close.setPreferredSize(new Dimension(100, 30)); close.addActionListener(this); - + JPanel jp2 = new JPanel(); if (automatic == 0) { - jp2.add(start); - jp2.add(stop); + jp2.add(start); + jp2.add(stop); } jp2.add(close); - + c.add(jp2, BorderLayout.SOUTH); - + + } + + public void updateInteractiveSimulation() { + if (automatic == 0) { + exe2.setEnabled(exe.isSelected()); + exe2int.setEnabled(exeint.isSelected()); + exe2formal.setEnabled(exeformal.isSelected()); + } } - - public void updateInteractiveSimulation() { - if (automatic == 0) { - exe2.setEnabled(exe.isSelected()); - exe2int.setEnabled(exeint.isSelected()); - exe2formal.setEnabled(exeformal.isSelected()); - } - } - - public void actionPerformed(ActionEvent evt) { + + public void actionPerformed(ActionEvent evt) { String command = evt.getActionCommand(); //System.out.println("Actions"); - + // Compare the action command to the known actions. - updateInteractiveSimulation(); - - - if (command.equals("Start")) { + updateInteractiveSimulation(); + + + if (command.equals("Start")) { startProcess(); } else if (command.equals("Stop")) { stopProcess(); @@ -549,440 +549,440 @@ public class JDialogSystemCGeneration extends javax.swing.JDialog implements Act } else if (command.equals("allIgnoredTepe")) { allIgnoredTepe(); } else if (evt.getSource() == versionSimulator) { - selectedItem = versionSimulator.getSelectedIndex(); - } + selectedItem = versionSimulator.getSelectedIndex(); + } } - + public void closeDialog() { if (mode == STARTED) { stopProcess(); } - updateStaticList(); - optimizeModeSelected = optimizemode.isSelected(); - wasClosed = true; + updateStaticList(); + optimizeModeSelected = optimizemode.isSelected(); + wasClosed = true; dispose(); } - + public boolean wasClosed() { - return wasClosed; + return wasClosed; } - + public void stopProcess() { try { rshc.stopFillJTA(); } catch (LauncherException le) { - + } rshc = null; - mode = STOPPED; + mode = STOPPED; setButtons(); go = false; } - + public void startProcess() { - if (automatic > 0) { - startProcess = false; - t = new Thread(this); - mode = STARTED; - go = true; - t.start(); - } else { - /*if ((interactiveSimulationSelected) && (jp1.getSelectedIndex() == 2)) { - startProcess = true; - dispose(); - } else {*/ - startProcess = false; - t = new Thread(this); - mode = STARTED; - setButtons(); - go = true; - t.start(); - //} - } + if (automatic > 0) { + startProcess = false; + t = new Thread(this); + mode = STARTED; + go = true; + t.start(); + } else { + /*if ((interactiveSimulationSelected) && (jp1.getSelectedIndex() == 2)) { + startProcess = true; + dispose(); + } else {*/ + startProcess = false; + t = new Thread(this); + mode = STARTED; + setButtons(); + go = true; + t.start(); + //} + } } - + private void testGo() throws InterruptedException { if (go == false) { throw new InterruptedException("Stopped by user"); } } - + public void run() { String cmd; String data; - - + + hasError = false; - + try { - - if (automatic > 0) { - - generateCode(); - testGo(); - compileCode(); - testGo(); - executeSimulation(); - - } else { - - - // Code generation - if (jp1.getSelectedIndex() == 0) { - generateCode(); - } - - testGo(); - - - // Compilation - if (jp1.getSelectedIndex() == 1) { - compileCode(); - - } - - if (jp1.getSelectedIndex() == 2) { - executeSimulation(); - } - - if ((hasError == false) && (jp1.getSelectedIndex() < 2)) { - jp1.setSelectedIndex(jp1.getSelectedIndex() + 1); - } - + + if (automatic > 0) { + + generateCode(); + testGo(); + compileCode(); + testGo(); + executeSimulation(); + + } else { + + + // Code generation + if (jp1.getSelectedIndex() == 0) { + generateCode(); + } + + testGo(); + + + // Compilation + if (jp1.getSelectedIndex() == 1) { + compileCode(); + + } + + if (jp1.getSelectedIndex() == 2) { + executeSimulation(); + } + + if ((hasError == false) && (jp1.getSelectedIndex() < 2)) { + jp1.setSelectedIndex(jp1.getSelectedIndex() + 1); + } + } - + } catch (InterruptedException ie) { jta.append("Interrupted\n"); } - + jta.append("\n\nReady to process next command\n"); - + checkMode(); setButtons(); - - //System.out.println("Selected item=" + selectedItem); + + //System.out.println("Selected item=" + selectedItem); } - + private void generateCode() throws InterruptedException { - String list; + String list; int cycle = 0; - - - jta.append("Generating SystemC code\n"); - - if (removeCppFiles.isSelected()) { - jta.append("Removing all old h files\n"); - list = FileUtils.deleteFiles(code1.getText(), ".h"); - if (list.length() == 0) { - jta.append("No files were deleted\n"); - } else { - jta.append("Files deleted:\n" + list + "\n"); - } - jta.append("Removing all old cpp files\n"); - list = FileUtils.deleteFiles(code1.getText(), ".cpp"); - if (list.length() == 0) { - jta.append("No files were deleted\n"); - } else { - jta.append("Files deleted:\n" + list + "\n"); - } - } - - if (removeXFiles.isSelected()) { - jta.append("Removing all old x files\n"); - list = FileUtils.deleteFiles(code1.getText(), ".x"); - if (list.length() == 0) { - jta.append("No files were deleted\n"); - } else { - jta.append("Files deleted:\n" + list + "\n"); - } - } - - testGo(); - - try { - unitCycle = unitcycle.getText(); - cycle = Integer.valueOf(unitCycle).intValue(); - } catch (Exception e) { - jta.append("Wrong number of cycles: " + unitcycle.getText()); - jta.append("Aborting"); - jta.append("\n\nReady to process next command\n"); - checkMode(); - setButtons(); - return; - } - - /*TML2SystemC tml2systc = new TML2SystemC(mgui.gtm.getTMLModeling()); - tml2systc.generateSystemC(debugmode.isSelected()); - - testGo(); - jta.append("SystemC code generation done\n"); - //t2j.printJavaClasses(); - try { - jta.append("Generating SystemC file\n"); - pathCode = code1.getText(); - tml2systc.saveFile(pathCode, "appmodel"); - jta.append("SystemC file generated\n"); - } catch (Exception e) { - jta.append("Could not generate SystemC file\n"); - }*/ - - selectedItem = versionSimulator.getSelectedIndex(); - //System.out.println("Selected item=" + selectedItem); - switch( selectedItem ) { //Old SystemC generator - case 0: { - tmltranslator.tomappingsystemc.TML2MappingSystemC tml2systc; - if (mgui.gtm.getTMLMapping() == null) { - if (mgui.gtm.getArtificialTMLMapping() == null) { - tml2systc = new tmltranslator.tomappingsystemc.TML2MappingSystemC(mgui.gtm.getTMLModeling()); - } else { - TraceManager.addDev("Using artifical mapping"); - tml2systc = new tmltranslator.tomappingsystemc.TML2MappingSystemC(mgui.gtm.getArtificialTMLMapping()); - } - } - else { - tml2systc = new tmltranslator.tomappingsystemc.TML2MappingSystemC(mgui.gtm.getTMLMapping()); - } - tml2systc.generateSystemC(debugmode.isSelected(), optimizemode.isSelected()); - testGo(); - jta.append("SystemC code generation done\n"); - //t2j.printJavaClasses(); - try { - jta.append("Generating SystemC file\n"); - pathCode = code1.getText(); - tml2systc.saveFile(pathCode, "appmodel"); - jta.append("SystemC files generated\n"); - } - catch( Exception e ) { - jta.append("Could not generate SystemC file\n"); - } - break; - } - case 1: { //Simulator without CPs (Daniel's version) - tmltranslator.tomappingsystemc2.TML2MappingSystemC tml2systc; - // Making EBRDDs - ArrayList<EBRDD> al = new ArrayList<EBRDD>(); - ArrayList<TEPE> alTepe = new ArrayList<TEPE>(); - TEPE tepe; - AvatarRequirementPanelTranslator arpt = new AvatarRequirementPanelTranslator(); - for(int k=0; k<valTepe.size(); k++) { - testGo(); - tepe = arpt.generateTEPESpecification((AvatarPDPanel)(valTepe.get(k))); - jta.append("TEPE: " + tepe.getName() + "\n"); - jta.append("Checking syntax\n"); - // tepe.checkSyntax(); - alTepe.add(tepe); - jta.append("Done.\n"); - } - /*EBRDDTranslator ebrddt; - EBRDDPanel ep; - EBRDD ebrdd; - - for(int k=0; k<val.size(); k++) { - testGo(); - ebrddt = new EBRDDTranslator(); - ep = (EBRDDPanel)(val.get(k)); - jta.append("EBRDD: " + ep.getName() + "\n"); - ebrdd = ebrddt.generateEBRDD(ep, ep.getName()); - jta.append("Checking syntax\n"); - if (ebrddt.getErrors().size() > 0) { - jta.append("Syntax error: ignoring EBRDD\n\n"); - } else { - jta.append("No Syntax error: EBRDD taken into account\n\n"); - al.add(ebrdd); - } - }*/ - - // Generating code - if (mgui.gtm.getTMLMapping() == null) { - if (mgui.gtm.getArtificialTMLMapping() == null) { - tml2systc = new tmltranslator.tomappingsystemc2.TML2MappingSystemC(mgui.gtm.getTMLModeling(), al, alTepe); - } else { - TraceManager.addDev("Using artifical mapping"); - tml2systc = new tmltranslator.tomappingsystemc2.TML2MappingSystemC(mgui.gtm.getArtificialTMLMapping(), al, alTepe); - } - } else { - tml2systc = new tmltranslator.tomappingsystemc2.TML2MappingSystemC(mgui.gtm.getTMLMapping(), al, alTepe); - } - tml2systc.generateSystemC(debugmode.isSelected(), optimizemode.isSelected()); - testGo(); - jta.append("SystemC code generation done\n"); - - for(TEPE tep: alTepe) { - TraceManager.addDev(tep.toString()); - } - //t2j.printJavaClasses(); - try { - jta.append("Generating SystemC file\n"); - pathCode = code1.getText(); - tml2systc.saveFile(pathCode, "appmodel"); - jta.append("SystemC files generated\n"); - } catch (Exception e) { - jta.append("Could not generate SystemC file\n"); - } - break; - } - case 2: { //Simulator version with CPs - tmltranslator.tomappingsystemc3.TML2MappingSystemC tml2systc; - // Making EBRDDs - ArrayList<EBRDD> al = new ArrayList<EBRDD>(); - ArrayList<TEPE> alTepe = new ArrayList<TEPE>(); - TEPE tepe; - AvatarRequirementPanelTranslator arpt = new AvatarRequirementPanelTranslator(); - for(int k=0; k<valTepe.size(); k++) { - testGo(); - tepe = arpt.generateTEPESpecification((AvatarPDPanel)(valTepe.get(k))); - jta.append("TEPE: " + tepe.getName() + "\n"); - jta.append("Checking syntax\n"); - // tepe.checkSyntax(); - alTepe.add(tepe); - jta.append("Done.\n"); - } - /*EBRDDTranslator ebrddt; - EBRDDPanel ep; - EBRDD ebrdd; - - for(int k=0; k<val.size(); k++) { - testGo(); - ebrddt = new EBRDDTranslator(); - ep = (EBRDDPanel)(val.get(k)); - jta.append("EBRDD: " + ep.getName() + "\n"); - ebrdd = ebrddt.generateEBRDD(ep, ep.getName()); - jta.append("Checking syntax\n"); - if (ebrddt.getErrors().size() > 0) { - jta.append("Syntax error: ignoring EBRDD\n\n"); - } else { - jta.append("No Syntax error: EBRDD taken into account\n\n"); - al.add(ebrdd); - } - }*/ - - // Generating code - if (mgui.gtm.getTMLMapping() == null) { - if (mgui.gtm.getArtificialTMLMapping() == null) { - tml2systc = new tmltranslator.tomappingsystemc3.TML2MappingSystemC(mgui.gtm.getTMLModeling(), al, alTepe); - } else { - TraceManager.addDev("Using artifical mapping"); - tml2systc = new tmltranslator.tomappingsystemc3.TML2MappingSystemC(mgui.gtm.getArtificialTMLMapping(), al, alTepe); - } - } - else { - tml2systc = new tmltranslator.tomappingsystemc3.TML2MappingSystemC(mgui.gtm.getTMLMapping(), al, alTepe); - } - TraceManager.addDev( "Before exception" ); - tml2systc.generateSystemC( debugmode.isSelected(), optimizemode.isSelected() ); - testGo(); - jta.append("SystemC code generation done\n"); - - for(TEPE tep: alTepe) { - TraceManager.addDev(tep.toString()); - } - //t2j.printJavaClasses(); - try { - jta.append("Generating SystemC file\n"); - pathCode = code1.getText(); - tml2systc.saveFile(pathCode, "appmodel"); - jta.append("SystemC files generated\n"); - } catch (Exception e) { - jta.append("Could not generate SystemC file\n"); - } - break; - } - } - } //End of method generateCode() - + + + jta.append("Generating SystemC code\n"); + + if (removeCppFiles.isSelected()) { + jta.append("Removing all old h files\n"); + list = FileUtils.deleteFiles(code1.getText(), ".h"); + if (list.length() == 0) { + jta.append("No files were deleted\n"); + } else { + jta.append("Files deleted:\n" + list + "\n"); + } + jta.append("Removing all old cpp files\n"); + list = FileUtils.deleteFiles(code1.getText(), ".cpp"); + if (list.length() == 0) { + jta.append("No files were deleted\n"); + } else { + jta.append("Files deleted:\n" + list + "\n"); + } + } + + if (removeXFiles.isSelected()) { + jta.append("Removing all old x files\n"); + list = FileUtils.deleteFiles(code1.getText(), ".x"); + if (list.length() == 0) { + jta.append("No files were deleted\n"); + } else { + jta.append("Files deleted:\n" + list + "\n"); + } + } + + testGo(); + + try { + unitCycle = unitcycle.getText(); + cycle = Integer.valueOf(unitCycle).intValue(); + } catch (Exception e) { + jta.append("Wrong number of cycles: " + unitcycle.getText()); + jta.append("Aborting"); + jta.append("\n\nReady to process next command\n"); + checkMode(); + setButtons(); + return; + } + + /*TML2SystemC tml2systc = new TML2SystemC(mgui.gtm.getTMLModeling()); + tml2systc.generateSystemC(debugmode.isSelected()); + + testGo(); + jta.append("SystemC code generation done\n"); + //t2j.printJavaClasses(); + try { + jta.append("Generating SystemC file\n"); + pathCode = code1.getText(); + tml2systc.saveFile(pathCode, "appmodel"); + jta.append("SystemC file generated\n"); + } catch (Exception e) { + jta.append("Could not generate SystemC file\n"); + }*/ + + selectedItem = versionSimulator.getSelectedIndex(); + //System.out.println("Selected item=" + selectedItem); + switch( selectedItem ) { //Old SystemC generator + case 0: { + tmltranslator.tomappingsystemc.TML2MappingSystemC tml2systc; + if (mgui.gtm.getTMLMapping() == null) { + if (mgui.gtm.getArtificialTMLMapping() == null) { + tml2systc = new tmltranslator.tomappingsystemc.TML2MappingSystemC(mgui.gtm.getTMLModeling()); + } else { + TraceManager.addDev("Using artifical mapping"); + tml2systc = new tmltranslator.tomappingsystemc.TML2MappingSystemC(mgui.gtm.getArtificialTMLMapping()); + } + } + else { + tml2systc = new tmltranslator.tomappingsystemc.TML2MappingSystemC(mgui.gtm.getTMLMapping()); + } + tml2systc.generateSystemC(debugmode.isSelected(), optimizemode.isSelected()); + testGo(); + jta.append("SystemC code generation done\n"); + //t2j.printJavaClasses(); + try { + jta.append("Generating SystemC file\n"); + pathCode = code1.getText(); + tml2systc.saveFile(pathCode, "appmodel"); + jta.append("SystemC files generated\n"); + } + catch( Exception e ) { + jta.append("Could not generate SystemC file\n"); + } + break; + } + case 1: { //Simulator without CPs (Daniel's version) + tmltranslator.tomappingsystemc2.TML2MappingSystemC tml2systc; + // Making EBRDDs + ArrayList<EBRDD> al = new ArrayList<EBRDD>(); + ArrayList<TEPE> alTepe = new ArrayList<TEPE>(); + TEPE tepe; + AvatarRequirementPanelTranslator arpt = new AvatarRequirementPanelTranslator(); + for(int k=0; k<valTepe.size(); k++) { + testGo(); + tepe = arpt.generateTEPESpecification((AvatarPDPanel)(valTepe.get(k))); + jta.append("TEPE: " + tepe.getName() + "\n"); + jta.append("Checking syntax\n"); + // tepe.checkSyntax(); + alTepe.add(tepe); + jta.append("Done.\n"); + } + /*EBRDDTranslator ebrddt; + EBRDDPanel ep; + EBRDD ebrdd; + + for(int k=0; k<val.size(); k++) { + testGo(); + ebrddt = new EBRDDTranslator(); + ep = (EBRDDPanel)(val.get(k)); + jta.append("EBRDD: " + ep.getName() + "\n"); + ebrdd = ebrddt.generateEBRDD(ep, ep.getName()); + jta.append("Checking syntax\n"); + if (ebrddt.getErrors().size() > 0) { + jta.append("Syntax error: ignoring EBRDD\n\n"); + } else { + jta.append("No Syntax error: EBRDD taken into account\n\n"); + al.add(ebrdd); + } + }*/ + + // Generating code + if (mgui.gtm.getTMLMapping() == null) { + if (mgui.gtm.getArtificialTMLMapping() == null) { + tml2systc = new tmltranslator.tomappingsystemc2.TML2MappingSystemC(mgui.gtm.getTMLModeling(), al, alTepe); + } else { + TraceManager.addDev("Using artifical mapping"); + tml2systc = new tmltranslator.tomappingsystemc2.TML2MappingSystemC(mgui.gtm.getArtificialTMLMapping(), al, alTepe); + } + } else { + tml2systc = new tmltranslator.tomappingsystemc2.TML2MappingSystemC(mgui.gtm.getTMLMapping(), al, alTepe); + } + tml2systc.generateSystemC(debugmode.isSelected(), optimizemode.isSelected()); + testGo(); + jta.append("SystemC code generation done\n"); + + for(TEPE tep: alTepe) { + TraceManager.addDev(tep.toString()); + } + //t2j.printJavaClasses(); + try { + jta.append("Generating SystemC file\n"); + pathCode = code1.getText(); + tml2systc.saveFile(pathCode, "appmodel"); + jta.append("SystemC files generated\n"); + } catch (Exception e) { + jta.append("Could not generate SystemC file\n"); + } + break; + } + case 2: { //Simulator version with CPs + tmltranslator.tomappingsystemc3.TML2MappingSystemC tml2systc; + // Making EBRDDs + ArrayList<EBRDD> al = new ArrayList<EBRDD>(); + ArrayList<TEPE> alTepe = new ArrayList<TEPE>(); + TEPE tepe; + AvatarRequirementPanelTranslator arpt = new AvatarRequirementPanelTranslator(); + for(int k=0; k<valTepe.size(); k++) { + testGo(); + tepe = arpt.generateTEPESpecification((AvatarPDPanel)(valTepe.get(k))); + jta.append("TEPE: " + tepe.getName() + "\n"); + jta.append("Checking syntax\n"); + // tepe.checkSyntax(); + alTepe.add(tepe); + jta.append("Done.\n"); + } + /*EBRDDTranslator ebrddt; + EBRDDPanel ep; + EBRDD ebrdd; + + for(int k=0; k<val.size(); k++) { + testGo(); + ebrddt = new EBRDDTranslator(); + ep = (EBRDDPanel)(val.get(k)); + jta.append("EBRDD: " + ep.getName() + "\n"); + ebrdd = ebrddt.generateEBRDD(ep, ep.getName()); + jta.append("Checking syntax\n"); + if (ebrddt.getErrors().size() > 0) { + jta.append("Syntax error: ignoring EBRDD\n\n"); + } else { + jta.append("No Syntax error: EBRDD taken into account\n\n"); + al.add(ebrdd); + } + }*/ + + // Generating code + if (mgui.gtm.getTMLMapping() == null) { + if (mgui.gtm.getArtificialTMLMapping() == null) { + tml2systc = new tmltranslator.tomappingsystemc3.TML2MappingSystemC(mgui.gtm.getTMLModeling(), al, alTepe); + } else { + TraceManager.addDev("Using artifical mapping"); + tml2systc = new tmltranslator.tomappingsystemc3.TML2MappingSystemC(mgui.gtm.getArtificialTMLMapping(), al, alTepe); + } + } + else { + tml2systc = new tmltranslator.tomappingsystemc3.TML2MappingSystemC(mgui.gtm.getTMLMapping(), al, alTepe); + } + TraceManager.addDev( "Before exception" ); + tml2systc.generateSystemC( debugmode.isSelected(), optimizemode.isSelected() ); + testGo(); + jta.append("SystemC code generation done\n"); + + for(TEPE tep: alTepe) { + TraceManager.addDev(tep.toString()); + } + //t2j.printJavaClasses(); + try { + jta.append("Generating SystemC file\n"); + pathCode = code1.getText(); + tml2systc.saveFile(pathCode, "appmodel"); + jta.append("SystemC files generated\n"); + } catch (Exception e) { + jta.append("Could not generate SystemC file\n"); + } + break; + } + } + } //End of method generateCode() + public void compileCode() throws InterruptedException { - String cmd = compiler1.getText(); - - jta.append("Compiling SystemC code with command: \n" + cmd + "\n"); - - rshc = new RshClient(hostSystemC); - // Assuma data are on the remote host - // Command - try { - processCmd(cmd, jta); - //jta.append(data); - jta.append("Compilation done\n"); - } catch (LauncherException le) { - jta.append("Error: " + le.getMessage() + "\n"); - mode = STOPPED; - setButtons(); - return; - } catch (Exception e) { - mode = STOPPED; - setButtons(); - return; - } + String cmd = compiler1.getText(); + + jta.append("Compiling SystemC code with command: \n" + cmd + "\n"); + + rshc = new RshClient(hostSystemC); + // Assuma data are on the remote host + // Command + try { + processCmd(cmd, jta); + //jta.append(data); + jta.append("Compilation done\n"); + } catch (LauncherException le) { + jta.append("Error: " + le.getMessage() + "\n"); + mode = STOPPED; + setButtons(); + return; + } catch (Exception e) { + mode = STOPPED; + setButtons(); + return; + } } - - + + public void executeSimulation() throws InterruptedException { - if (hasError) { - jta.append("Simulation not executed: error"); - return; - } - - int toDo = automatic; - - if (toDo == 0) { - if (exe.isSelected()) { - toDo = ONE_TRACE; - } else if (exeint.isSelected()) { - toDo = ANIMATION; - } else { - toDo = FORMAL_VERIFICATION; - } - } - - - String cmd; - - switch(toDo) { - case ONE_TRACE: - executeSimulationCmd(exe2.getText(), "Generating one simulation trace"); - break; - case ANIMATION: - dispose(); - mgui.interactiveSimulationSystemC(getPathInteractiveExecute()); - break; - case FORMAL_VERIFICATION: - executeSimulationCmd(exe2formal.getText(), "Running formal verification"); - break; - - } - - } - - - public void executeSimulationCmd(String cmd, String text) throws InterruptedException { - - - try { - - - jta.append(text + " with command: \n" + cmd + "\n"); - - rshc = new RshClient(hostSystemC); - // It assumes that data are on the remote host - // Command - - processCmd(cmd, jta); - //jta.append(data); - jta.append("Execution done\n"); - } catch (LauncherException le) { - jta.append("Error: " + le.getMessage() + "\n"); - mode = STOPPED; - setButtons(); - return; - } catch (Exception e) { - mode = STOPPED; - setButtons(); - return; - } - } - - - - + if (hasError) { + jta.append("Simulation not executed: error"); + return; + } + + int toDo = automatic; + + if (toDo == 0) { + if (exe.isSelected()) { + toDo = ONE_TRACE; + } else if (exeint.isSelected()) { + toDo = ANIMATION; + } else { + toDo = FORMAL_VERIFICATION; + } + } + + + String cmd; + + switch(toDo) { + case ONE_TRACE: + executeSimulationCmd(exe2.getText(), "Generating one simulation trace"); + break; + case ANIMATION: + dispose(); + mgui.interactiveSimulationSystemC(getPathInteractiveExecute()); + break; + case FORMAL_VERIFICATION: + executeSimulationCmd(exe2formal.getText(), "Running formal verification"); + break; + + } + + } + + + public void executeSimulationCmd(String cmd, String text) throws InterruptedException { + + + try { + + + jta.append(text + " with command: \n" + cmd + "\n"); + + rshc = new RshClient(hostSystemC); + // It assumes that data are on the remote host + // Command + + processCmd(cmd, jta); + //jta.append(data); + jta.append("Execution done\n"); + } catch (LauncherException le) { + jta.append("Error: " + le.getMessage() + "\n"); + mode = STOPPED; + setButtons(); + return; + } catch (Exception e) { + mode = STOPPED; + setButtons(); + return; + } + } + + + + protected void processCmd(String cmd, JTextArea _jta) throws LauncherException { rshc.setCmd(cmd); String s = null; @@ -992,100 +992,100 @@ public class JDialogSystemCGeneration extends javax.swing.JDialog implements Act //return s; return; } - + protected void checkMode() { mode = NOT_STARTED; } - + protected void setButtons() { - if (automatic == 0) { - switch(mode) { - case NOT_STARTED: - start.setEnabled(true); - stop.setEnabled(false); - close.setEnabled(true); - //setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); - getGlassPane().setVisible(false); - break; - case STARTED: - start.setEnabled(false); - stop.setEnabled(true); - close.setEnabled(false); - getGlassPane().setVisible(true); - //setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); - break; - case STOPPED: - default: - start.setEnabled(false); - stop.setEnabled(false); - close.setEnabled(true); - getGlassPane().setVisible(false); - break; - } + if (automatic == 0) { + switch(mode) { + case NOT_STARTED: + start.setEnabled(true); + stop.setEnabled(false); + close.setEnabled(true); + //setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + getGlassPane().setVisible(false); + break; + case STARTED: + start.setEnabled(false); + stop.setEnabled(true); + close.setEnabled(false); + getGlassPane().setVisible(true); + //setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); + break; + case STOPPED: + default: + start.setEnabled(false); + stop.setEnabled(false); + close.setEnabled(true); + getGlassPane().setVisible(false); + break; + } } else { - close.setEnabled(true); + close.setEnabled(true); } } - + public boolean hasToContinue() { return (go == true); } - + public void appendOut(String s) { jta.append(s); } - + public void setError() { hasError = true; } - - public boolean isInteractiveSimulationSelected() { - return (startProcess && interactiveSimulationSelected); - } - - public String getPathInteractiveExecute() { - return pathInteractiveExecute; - } - - // List selection listener - public void valueChanged(ListSelectionEvent e) { + + public boolean isInteractiveSimulationSelected() { + return (startProcess && interactiveSimulationSelected); + } + + public String getPathInteractiveExecute() { + return pathInteractiveExecute; + } + + // List selection listener + public void valueChanged(ListSelectionEvent e) { setList(); } - - private void setList() { - if (automatic == 0) { - int i1 = listIgnoredTepe.getSelectedIndex(); - int i2 = listValidatedTepe.getSelectedIndex(); - - if (i1 == -1) { - addOneValidatedTepe.setEnabled(false); - } else { - addOneValidatedTepe.setEnabled(true); - //listValidated.clearSelection(); - } - - if (i2 == -1) { - addOneIgnoredTepe.setEnabled(false); - } else { - addOneIgnoredTepe.setEnabled(true); - //listIgnored.clearSelection(); - } - - if (ignTepe.size() ==0) { - allValidatedTepe.setEnabled(false); - } else { - allValidatedTepe.setEnabled(true); - } - - if (valTepe.size() ==0) { - allIgnoredTepe.setEnabled(false); - } else { - allIgnoredTepe.setEnabled(true); - } + + private void setList() { + if (automatic == 0) { + int i1 = listIgnoredTepe.getSelectedIndex(); + int i2 = listValidatedTepe.getSelectedIndex(); + + if (i1 == -1) { + addOneValidatedTepe.setEnabled(false); + } else { + addOneValidatedTepe.setEnabled(true); + //listValidated.clearSelection(); + } + + if (i2 == -1) { + addOneIgnoredTepe.setEnabled(false); + } else { + addOneIgnoredTepe.setEnabled(true); + //listIgnored.clearSelection(); + } + + if (ignTepe.size() ==0) { + allValidatedTepe.setEnabled(false); + } else { + allValidatedTepe.setEnabled(true); + } + + if (valTepe.size() ==0) { + allIgnoredTepe.setEnabled(false); + } else { + allIgnoredTepe.setEnabled(true); + } } } - - private void addOneIgnoredTepe() { + + private void addOneIgnoredTepe() { int [] list = listValidatedTepe.getSelectedIndices(); Vector v = new Vector(); Object o; @@ -1094,13 +1094,13 @@ public class JDialogSystemCGeneration extends javax.swing.JDialog implements Act ignTepe.addElement(o); v.addElement(o); } - + valTepe.removeAll(v); listIgnoredTepe.setListData(ignTepe); listValidatedTepe.setListData(valTepe); setList(); } - + private void addOneValidatedTepe() { int [] list = listIgnoredTepe.getSelectedIndices(); Vector v = new Vector(); @@ -1110,13 +1110,13 @@ public class JDialogSystemCGeneration extends javax.swing.JDialog implements Act valTepe.addElement(o); v.addElement(o); } - + ignTepe.removeAll(v); listIgnoredTepe.setListData(ignTepe); listValidatedTepe.setListData(valTepe); setList(); } - + private void allValidatedTepe() { valTepe.addAll(ignTepe); ignTepe.removeAllElements(); @@ -1124,7 +1124,7 @@ public class JDialogSystemCGeneration extends javax.swing.JDialog implements Act listValidatedTepe.setListData(valTepe); setList(); } - + private void allIgnoredTepe() { ignTepe.addAll(valTepe); valTepe.removeAllElements(); @@ -1132,18 +1132,18 @@ public class JDialogSystemCGeneration extends javax.swing.JDialog implements Act listValidatedTepe.setListData(valTepe); setList(); } - - private void updateStaticList() { - validatedTepe = new Vector(); - ignoredTepe = new Vector(); - int i; - - for(i=0; i<ignTepe.size(); i++) { - ignoredTepe.add(ignTepe.get(i)); - } - - for(i=0;i<valTepe.size(); i++) { - validatedTepe.add(valTepe.get(i)); - } - } + + private void updateStaticList() { + validatedTepe = new Vector(); + ignoredTepe = new Vector(); + int i; + + for(i=0; i<ignTepe.size(); i++) { + ignoredTepe.add(ignTepe.get(i)); + } + + for(i=0;i<valTepe.size(); i++) { + validatedTepe.add(valTepe.get(i)); + } + } }