From 0d6774f3088bad8732a5e6cda4658598a79ffcbd Mon Sep 17 00:00:00 2001 From: Andrea Enrici <andrea.enrici@nokia.com> Date: Tue, 10 Feb 2015 13:44:57 +0000 Subject: [PATCH] added to svn the code to transform models to generate the code as Jair did --- src/Ctranslator/CPMEC.java | 82 ++++ src/Ctranslator/CpuLoadMEC.java | 90 ++++ src/Ctranslator/CpuStoreMEC.java | 90 ++++ src/Ctranslator/CwaMEC.java | 9 +- src/Ctranslator/CwlMEC.java | 100 +++++ src/Ctranslator/CwmMEC.java | 73 ++-- src/Ctranslator/CwpMEC.java | 100 +++++ src/Ctranslator/DmaMEC.java | 145 ++++--- src/Ctranslator/FftMEC.java | 10 +- src/Ctranslator/SumMEC.java | 12 +- src/Ctranslator/TMLCCodeGeneration.java | 405 ++++++++++++++++++ src/Ctranslator/TaskMEC.java | 29 +- src/tmltranslator/TMLCPTextSpecification.java | 37 +- src/tmltranslator/TMLMapping.java | 43 +- src/tmltranslator/TMLTask.java | 26 +- src/ui/GTURTLEModeling.java | 9 +- src/ui/tmldd/TMLArchiPortArtifact.java | 12 +- src/ui/window/JDialogPortArtifact.java | 44 +- 18 files changed, 1147 insertions(+), 169 deletions(-) create mode 100755 src/Ctranslator/CPMEC.java create mode 100644 src/Ctranslator/CpuLoadMEC.java create mode 100644 src/Ctranslator/CpuStoreMEC.java create mode 100755 src/Ctranslator/CwlMEC.java create mode 100755 src/Ctranslator/CwpMEC.java create mode 100755 src/Ctranslator/TMLCCodeGeneration.java diff --git a/src/Ctranslator/CPMEC.java b/src/Ctranslator/CPMEC.java new file mode 100755 index 0000000000..6616c0c2af --- /dev/null +++ b/src/Ctranslator/CPMEC.java @@ -0,0 +1,82 @@ +/**Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille, Andrea Enrici + + ludovic.apvrille AT enst.fr + andrea.enrici AT enstr.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 CPMEC, Model Extension Construct (MEC) class for Communication Patterns + * Creation: 06/02/2014 + * @version 1.0 06/02/2014 + * @author Andrea ENRICI + * @see + */ + +package Ctranslator; + +import java.util.*; +import java.nio.*; +import myutil.*; +//import Ctranslator.*; + +public abstract class CPMEC { + + public String CR = "\n"; + public String node_type = new String(); + public String inst_type = new String(); + public String inst_decl = new String(); + public String buff_type = new String(); + public String buff_init = new String(); + public String init_code = new String(); + public String exec_code = new String(); + public String messages_code = new String(); + public String attributes_code = new String(); + public String cleanup_code = new String(); + + public CPMEC() { + node_type = "1"; + } + + public String toString() { + return node_type + CR + inst_decl + CR + inst_type + CR + buff_type + CR + buff_init + CR + exec_code + CR + init_code + CR + messages_code + CR + attributes_code + CR + cleanup_code; + } + + public void saveFile( String path, String filename ) throws FileException { + + TraceManager.addUser( "Saving C CP file in " + path + filename ); + FileUtils.saveFile( path + filename, this.toString() ); + } + +} //End of class diff --git a/src/Ctranslator/CpuLoadMEC.java b/src/Ctranslator/CpuLoadMEC.java new file mode 100644 index 0000000000..f4a674ec6e --- /dev/null +++ b/src/Ctranslator/CpuLoadMEC.java @@ -0,0 +1,90 @@ +/**Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille, Andrea Enrici + + ludovic.apvrille AT enst.fr + andrea.enrici AT enstr.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 CpuLoadMEC, Model Extension Construct (MEC) class for Embb non-cachable CPU load operation + * Creation: 05/02/2014 + * @version 1.0 05/02/2014 + * @author Andrea ENRICI + * @see + */ + +package Ctranslator; + +import java.util.*; +//import Ctranslator.*; + +public class CpuLoadMEC extends CPMEC { + + public CpuLoadMEC() { + node_type = "FEP"; + inst_type = "SUM"; + inst_decl = "FEP_CONTEXT"; + buff_type = "FEP_BUFF_TYPE"; + buff_init = "= {/*l,b,q,t*/};"; + exec_code = "/*firm instruction*/" + CR + + " fep_set_qx(&$XOP$,((FEP_BUFF_TYPE*)sig[$ID0$].pBuff)->q);" + CR + + "/*start execution*/" + CR + + "fep_start(&$XOP$);" + CR; + + init_code ="/***** INIT $XOP$ *******/" + CR + + "void init_$XOP$(void){" + CR + + " fep_ctx_init(&$XOP$,0);" + CR + + " // initialize context" + CR + + " fep_set_op(&$XOP$,FEP_OP_MOV);" + CR + + " fep_set_r(&$XOP$, /*USER TODO*/);" + CR + + " fep_set_l(&$XOP$,/*USER TODO*/);" + CR + + " fep_set_bx(&$XOP$,/*USER TODO*/);" + CR + + " fep_set_qx(&$XOP$,/*USER TODO*/);" + CR + + " fep_set_wx(&$XOP$,/*USER TODO*/);" + CR + + " fep_set_tx(&$XOP$,/*USER TODO*/);" + CR + + " fep_set_sx(&$XOP$,/*USER TODO*/);" + CR + + " fep_set_nx(&$XOP$,/*USER TODO*/);" + CR + + " fep_set_mx(&$XOP$,/*USER TODO*/);" + CR + + " fep_set_px(&$XOP$,/*USER TODO*/);" + CR + + " fep_set_dx(&$XOP$,/*USER TODO*/);" + CR + + " fep_set_vrx(&$XOP$,/*USER TODO*/);" + CR + + " fep_set_vix(&$XOP$,/*USER TODO*/);" + CR + + " fep_set_sma(&$XOP$,2);" + CR + + " fep_set_qs(&$XOP$,((FEP_BUFF_TYPE*)sig[$OD0$].pBuff)->q);" + CR + + " fep_set_bs(&$XOP$,((FEP_BUFF_TYPE*)sig[$OD0$].pBuff)->b);" + CR + + "}" + CR; + cleanup_code = "fep_ctx_cleanup(&$XOP$);"; + } + +} //End of class diff --git a/src/Ctranslator/CpuStoreMEC.java b/src/Ctranslator/CpuStoreMEC.java new file mode 100644 index 0000000000..eb3ae23fa9 --- /dev/null +++ b/src/Ctranslator/CpuStoreMEC.java @@ -0,0 +1,90 @@ +/**Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille, Andrea Enrici + + ludovic.apvrille AT enst.fr + andrea.enrici AT enstr.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 CpuStoreMEC, Model Extension Construct (MEC) class for Embb non-cachable CPU store operation + * Creation: 06/02/2014 + * @version 1.0 06/02/2014 + * @author Andrea ENRICI + * @see + */ + +package Ctranslator; + +import java.util.*; +//import Ctranslator.*; + +public class CpuStoreMEC extends CPMEC { + + public CpuStoreMEC() { + node_type = "FEP"; + inst_type = "SUM"; + inst_decl = "FEP_CONTEXT"; + buff_type = "FEP_BUFF_TYPE"; + buff_init = "= {/*l,b,q,t*/};"; + exec_code = "/*firm instruction*/" + CR + + " fep_set_qx(&$XOP$,((FEP_BUFF_TYPE*)sig[$ID0$].pBuff)->q);" + CR + + "/*start execution*/" + CR + + "fep_start(&$XOP$);" + CR; + + init_code ="/***** INIT $XOP$ *******/" + CR + + "void init_$XOP$(void){" + CR + + " fep_ctx_init(&$XOP$,0);" + CR + + " // initialize context" + CR + + " fep_set_op(&$XOP$,FEP_OP_MOV);" + CR + + " fep_set_r(&$XOP$, /*USER TODO*/);" + CR + + " fep_set_l(&$XOP$,/*USER TODO*/);" + CR + + " fep_set_bx(&$XOP$,/*USER TODO*/);" + CR + + " fep_set_qx(&$XOP$,/*USER TODO*/);" + CR + + " fep_set_wx(&$XOP$,/*USER TODO*/);" + CR + + " fep_set_tx(&$XOP$,/*USER TODO*/);" + CR + + " fep_set_sx(&$XOP$,/*USER TODO*/);" + CR + + " fep_set_nx(&$XOP$,/*USER TODO*/);" + CR + + " fep_set_mx(&$XOP$,/*USER TODO*/);" + CR + + " fep_set_px(&$XOP$,/*USER TODO*/);" + CR + + " fep_set_dx(&$XOP$,/*USER TODO*/);" + CR + + " fep_set_vrx(&$XOP$,/*USER TODO*/);" + CR + + " fep_set_vix(&$XOP$,/*USER TODO*/);" + CR + + " fep_set_sma(&$XOP$,2);" + CR + + " fep_set_qs(&$XOP$,((FEP_BUFF_TYPE*)sig[$OD0$].pBuff)->q);" + CR + + " fep_set_bs(&$XOP$,((FEP_BUFF_TYPE*)sig[$OD0$].pBuff)->b);" + CR + + "}" + CR; + cleanup_code = "fep_ctx_cleanup(&$XOP$);"; + } + +} //End of class diff --git a/src/Ctranslator/CwaMEC.java b/src/Ctranslator/CwaMEC.java index 465d254d2e..19df390abf 100644 --- a/src/Ctranslator/CwaMEC.java +++ b/src/Ctranslator/CwaMEC.java @@ -44,16 +44,14 @@ * @see */ -//package Ctranslator; +package Ctranslator; import java.util.*; //import Ctranslator.*; public class CwaMEC extends TaskMEC { - private String CR = "\n"; - - public CwaMEC() { + public CwaMEC( String XOP, String ID0, String OD0, String BTC ) { node_type = "FEP"; inst_type = "CWA"; @@ -109,7 +107,4 @@ public class CwaMEC extends TaskMEC { cleanup_code = "fep_ctx_cleanup(&$XOP$);"; } - public String toString() { - return node_type + CR + inst_decl + CR + inst_type + CR + buff_type + CR + buff_init + CR + exec_code + init_code + cleanup_code; - } } //End of class diff --git a/src/Ctranslator/CwlMEC.java b/src/Ctranslator/CwlMEC.java new file mode 100755 index 0000000000..77375bdb4f --- /dev/null +++ b/src/Ctranslator/CwlMEC.java @@ -0,0 +1,100 @@ +/**Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille, Andrea Enrici + + ludovic.apvrille AT enst.fr + andrea.enrici AT enstr.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 CwlMEC, Model Extension Construct (MEC) class for Embb Component Wise Lookup operation + * Creation: 05/02/2014 + * @version 1.0 05/02/2014 + * @author Andrea ENRICI + * @see + */ + +package Ctranslator; + +import java.util.*; +//import Ctranslator.*; + +public class CwlMEC extends TaskMEC { + + public CwlMEC( String XOP, String ID0, String OD0, String BTC ) { + + node_type = "FEP"; + inst_type = "CWL"; + inst_decl = "FEP_CONTEXT"; + buff_type = "FEP_BUFF_TYPE"; + buff_init = "= {/*l,b,q,t*/};"; + exec_code = "/*firm instruction*/" + CR + + " fep_set_l(&" + XOP + ", ((FEP_BUFF_TYPE*)sig[" + ID0 + "].pBuff)->l);" + CR + + " fep_set_qx(&" + XOP + ",((FEP_BUFF_TYPE*)sig[" + ID0 + "].pBuff)->q);" + CR + + " fep_set_bx(&" + XOP + ",sig[" + ID0 + "].roff + ((FEP_BUFF_TYPE*)sig[" + ID0 + "].pBuff)->b);" + CR + + " fep_set_tx(&" + XOP + ",((FEP_BUFF_TYPE*)sig[" + ID0 + "].pBuff)->t);" + CR + + " fep_set_qz(&" + XOP + ",((FEP_BUFF_TYPE*)sig[" + OD0 + "].pBuff)->q);" + CR + + " fep_set_bz(&" + XOP + ",sig[" + OD0 + "].woff + ((FEP_BUFF_TYPE*)sig[" + OD0 + "].pBuff)->b);" + CR + + " fep_set_tz(&" + XOP + ",((FEP_BUFF_TYPE*)sig[" + OD0 + "].pBuff)->t);" + CR + + "/*start execution*/" + CR + + "fep_start(&" + XOP + ");" + CR; + + init_code ="/***** INIT " + XOP + " *******/" + CR + + "void init_" + XOP + "(void){" + CR + + " fep_ctx_init(&" + XOP + ",0);" + CR + + " // initialize context" + CR + + " fep_set_op(&" + XOP + ",FEP_OP_CWL );" + CR + + " fep_set_r(&" + XOP + ",/*USER TODO*/);" + CR + + " fep_set_l(&" + XOP + ",((FEP_BUFF_TYPE*)sig[" + OD0 + "].pBuff)->l);" + CR + + " fep_set_wx(&" + XOP + ",/*USER TODO*/);" + CR + + " fep_set_sx(&" + XOP + ",/*USER TODO*/);" + CR + + " fep_set_nx(&" + XOP + ",/*USER TODO*/);" + CR + + " fep_set_mx(&" + XOP + ",/*USER TODO*/);" + CR + + " fep_set_px(&" + XOP + ",/*USER TODO*/);" + CR + + " fep_set_dx(&" + XOP + ",/*USER TODO*/);" + CR + + " fep_set_vrx(&" + XOP + ",/*USER TODO*/);" + CR + + " fep_set_vix(&" + XOP + ",/*USER TODO*/);" + CR + + " fep_set_qz(&" + XOP + ",((FEP_BUFF_TYPE*)sig[" + OD0 + "].pBuff)->q);" + CR + + " fep_set_bz(&" + XOP + ",((FEP_BUFF_TYPE*)sig[" + OD0 + "].pBuff)->b);" + CR + + " fep_set_tz(&" + XOP + ",((FEP_BUFF_TYPE*)sig[" + OD0 + "].pBuff)->t);" + CR + + " fep_set_wz(&" + XOP + ",/*USER TODO*/);" + CR + + " fep_set_ri(&" + XOP + ",/*USER TODO*/);" + CR + + " fep_set_sz(&" + XOP + ",/*USER TODO*/);" + CR + + " fep_set_nz(&" + XOP + ",/*USER TODO*/);" + CR + + " fep_set_mz(&" + XOP + ",/*USER TODO*/);" + CR + + " fep_set_sma(&" + XOP + ",1);" + CR + + "}" + CR; + cleanup_code = "fep_ctx_cleanup(&" + XOP + ");"; + } + +} //End of class diff --git a/src/Ctranslator/CwmMEC.java b/src/Ctranslator/CwmMEC.java index 7ca62c41bb..f842c63812 100755 --- a/src/Ctranslator/CwmMEC.java +++ b/src/Ctranslator/CwmMEC.java @@ -44,16 +44,14 @@ * @see */ -//package Ctranslator; +package Ctranslator; import java.util.*; //import Ctranslator.*; public class CwmMEC extends TaskMEC { - private String CR = "\n"; - - public CwmMEC() { + public CwmMEC( String XOP, String ID0, String OD0, String BTC ) { node_type = "FEP"; inst_type = "CWM"; @@ -61,45 +59,42 @@ public class CwmMEC extends TaskMEC { buff_type = "FEP_BUFF_TYPE"; buff_init = "= {/*l,b,q,t*/};"; exec_code = "/*firm instruction*/" + CR + - " fep_set_l(&$XOP$, ((FEP_BUFF_TYPE*)sig[$ID0$].pBuff)->l);" + CR + - " fep_set_qx(&$XOP$,((FEP_BUFF_TYPE*)sig[$ID0$].pBuff)->q);" + CR + - " fep_set_bx(&$XOP$,sig[$ID0$].roff + ((FEP_BUFF_TYPE*)sig[$ID0$].pBuff)->b);" + CR + - " fep_set_tx(&$XOP$,((FEP_BUFF_TYPE*)sig[$ID0$].pBuff)->t);" + CR + - " fep_set_qz(&$XOP$,((FEP_BUFF_TYPE*)sig[$OD0$].pBuff)->q);" + CR + - " fep_set_bz(&$XOP$,sig[$OD0$].woff + ((FEP_BUFF_TYPE*)sig[$OD0$].pBuff)->b);" + CR + - " fep_set_tz(&$XOP$,((FEP_BUFF_TYPE*)sig[$OD0$].pBuff)->t);" + CR + + " fep_set_l(&" + XOP + ", ((FEP_BUFF_TYPE*)sig[" + ID0 + "].pBuff)->l);" + CR + + " fep_set_qx(&" + XOP + ",((FEP_BUFF_TYPE*)sig[" + ID0 + "].pBuff)->q);" + CR + + " fep_set_bx(&" + XOP + ",sig[" + ID0 + "].roff + ((FEP_BUFF_TYPE*)sig[" + ID0 + "].pBuff)->b);" + CR + + " fep_set_tx(&" + XOP + ",((FEP_BUFF_TYPE*)sig[" + ID0 + "].pBuff)->t);" + CR + + " fep_set_qz(&" + XOP + ",((FEP_BUFF_TYPE*)sig[" + OD0 + "].pBuff)->q);" + CR + + " fep_set_bz(&" + XOP + ",sig[" + OD0 + "].woff + ((FEP_BUFF_TYPE*)sig[" + OD0 + "].pBuff)->b);" + CR + + " fep_set_tz(&" + XOP + ",((FEP_BUFF_TYPE*)sig[" + OD0 + "].pBuff)->t);" + CR + "/*start execution*/" + CR + - "fep_start(&$XOP$);" + CR; + "fep_start(&" + XOP + ");" + CR; - init_code ="/***** INIT $XOP$ *******/" + CR + - "void init_$XOP$(void){" + CR + - " fep_ctx_init(&$XOP$,0);" + CR + + init_code ="/***** INIT " + XOP + " *******/" + CR + + "void init_" + XOP + "(void){" + CR + + " fep_ctx_init(&" + XOP + ",0);" + CR + " // initialize context" + CR + - " fep_set_op(&$XOP$,FEP_OP_CWM );" + CR + - " fep_set_r(&$XOP$,/*USER TODO*/);" + CR + - " fep_set_l(&$XOP$,((FEP_BUFF_TYPE*)sig[$OD0$].pBuff)->l);" + CR + - " fep_set_wx(&$XOP$,/*USER TODO*/);" + CR + - " fep_set_sx(&$XOP$,/*USER TODO*/);" + CR + - " fep_set_nx(&$XOP$,/*USER TODO*/);" + CR + - " fep_set_mx(&$XOP$,/*USER TODO*/);" + CR + - " fep_set_px(&$XOP$,/*USER TODO*/);" + CR + - " fep_set_dx(&$XOP$,/*USER TODO*/);" + CR + - " fep_set_vrx(&$XOP$,/*USER TODO*/);" + CR + - " fep_set_vix(&$XOP$,/*USER TODO*/);" + CR + - " fep_set_qz(&$XOP$,((FEP_BUFF_TYPE*)sig[$OD0$].pBuff)->q);" + CR + - " fep_set_bz(&$XOP$,((FEP_BUFF_TYPE*)sig[$OD0$].pBuff)->b);" + CR + - " fep_set_tz(&$XOP$,((FEP_BUFF_TYPE*)sig[$OD0$].pBuff)->t);" + CR + - " fep_set_wz(&$XOP$,/*USER TODO*/);" + CR + - " fep_set_ri(&$XOP$,/*USER TODO*/);" + CR + - " fep_set_sz(&$XOP$,/*USER TODO*/);" + CR + - " fep_set_nz(&$XOP$,/*USER TODO*/);" + CR + - " fep_set_mz(&$XOP$,/*USER TODO*/);" + CR + - " fep_set_sma(&$XOP$,1);" + CR + + " fep_set_op(&" + XOP + ",FEP_OP_CWM );" + CR + + " fep_set_r(&" + XOP + ",/*USER TODO*/);" + CR + + " fep_set_l(&" + XOP + ",((FEP_BUFF_TYPE*)sig[" + OD0 + "].pBuff)->l);" + CR + + " fep_set_wx(&" + XOP + ",/*USER TODO*/);" + CR + + " fep_set_sx(&" + XOP + ",/*USER TODO*/);" + CR + + " fep_set_nx(&" + XOP + ",/*USER TODO*/);" + CR + + " fep_set_mx(&" + XOP + ",/*USER TODO*/);" + CR + + " fep_set_px(&" + XOP + ",/*USER TODO*/);" + CR + + " fep_set_dx(&" + XOP + ",/*USER TODO*/);" + CR + + " fep_set_vrx(&" + XOP + ",/*USER TODO*/);" + CR + + " fep_set_vix(&" + XOP + ",/*USER TODO*/);" + CR + + " fep_set_qz(&" + XOP + ",((FEP_BUFF_TYPE*)sig[" + OD0 + "].pBuff)->q);" + CR + + " fep_set_bz(&" + XOP + ",((FEP_BUFF_TYPE*)sig[" + OD0 + "].pBuff)->b);" + CR + + " fep_set_tz(&" + XOP + ",((FEP_BUFF_TYPE*)sig[" + OD0 + "].pBuff)->t);" + CR + + " fep_set_wz(&" + XOP + ",/*USER TODO*/);" + CR + + " fep_set_ri(&" + XOP + ",/*USER TODO*/);" + CR + + " fep_set_sz(&" + XOP + ",/*USER TODO*/);" + CR + + " fep_set_nz(&" + XOP + ",/*USER TODO*/);" + CR + + " fep_set_mz(&" + XOP + ",/*USER TODO*/);" + CR + + " fep_set_sma(&" + XOP + ",1);" + CR + "}" + CR; - cleanup_code = "fep_ctx_cleanup(&$XOP$);"; + cleanup_code = "fep_ctx_cleanup(&" + XOP + ");"; } - public String toString() { - return node_type + CR + inst_decl + CR + inst_type + CR + buff_type + CR + buff_init + CR + exec_code + init_code + cleanup_code; - } } //End of class diff --git a/src/Ctranslator/CwpMEC.java b/src/Ctranslator/CwpMEC.java new file mode 100755 index 0000000000..c46647895a --- /dev/null +++ b/src/Ctranslator/CwpMEC.java @@ -0,0 +1,100 @@ +/**Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille, Andrea Enrici + + ludovic.apvrille AT enst.fr + andrea.enrici AT enstr.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 CwpMEC, Model Extension Construct (MEC) class for Embb Component Wise Product operation + * Creation: 05/02/2014 + * @version 1.0 05/02/2014 + * @author Andrea ENRICI + * @see + */ + +package Ctranslator; + +import java.util.*; +//import Ctranslator.*; + +public class CwpMEC extends TaskMEC { + + public CwpMEC( String XOP, String ID0, String OD0, String BTC ) { + + node_type = "FEP"; + inst_type = "CWP"; + inst_decl = "FEP_CONTEXT"; + buff_type = "FEP_BUFF_TYPE"; + buff_init = "= {/*l,b,q,t*/};"; + exec_code = "/*firm instruction*/" + CR + + " fep_set_l(&" + XOP + ", ((FEP_BUFF_TYPE*)sig[" + ID0 + "].pBuff)->l);" + CR + + " fep_set_qx(&" + XOP + ",((FEP_BUFF_TYPE*)sig[" + ID0 + "].pBuff)->q);" + CR + + " fep_set_bx(&" + XOP + ",sig[" + ID0 + "].roff + ((FEP_BUFF_TYPE*)sig[" + ID0 + "].pBuff)->b);" + CR + + " fep_set_tx(&" + XOP + ",((FEP_BUFF_TYPE*)sig[" + ID0 + "].pBuff)->t);" + CR + + " fep_set_qz(&" + XOP + ",((FEP_BUFF_TYPE*)sig[" + OD0 + "].pBuff)->q);" + CR + + " fep_set_bz(&" + XOP + ",sig[" + OD0 + "].woff + ((FEP_BUFF_TYPE*)sig[" + OD0 + "].pBuff)->b);" + CR + + " fep_set_tz(&" + XOP + ",((FEP_BUFF_TYPE*)sig[" + OD0 + "].pBuff)->t);" + CR + + "/*start execution*/" + CR + + "fep_start(&" + XOP + ");" + CR; + + init_code ="/***** INIT " + XOP + " *******/" + CR + + "void init_" + XOP + "(void){" + CR + + " fep_ctx_init(&" + XOP + ",0);" + CR + + " // initialize context" + CR + + " fep_set_op(&" + XOP + ",FEP_OP_CWP );" + CR + + " fep_set_r(&" + XOP + ",/*USER TODO*/);" + CR + + " fep_set_l(&" + XOP + ",((FEP_BUFF_TYPE*)sig[" + OD0 + "].pBuff)->l);" + CR + + " fep_set_wx(&" + XOP + ",/*USER TODO*/);" + CR + + " fep_set_sx(&" + XOP + ",/*USER TODO*/);" + CR + + " fep_set_nx(&" + XOP + ",/*USER TODO*/);" + CR + + " fep_set_mx(&" + XOP + ",/*USER TODO*/);" + CR + + " fep_set_px(&" + XOP + ",/*USER TODO*/);" + CR + + " fep_set_dx(&" + XOP + ",/*USER TODO*/);" + CR + + " fep_set_vrx(&" + XOP + ",/*USER TODO*/);" + CR + + " fep_set_vix(&" + XOP + ",/*USER TODO*/);" + CR + + " fep_set_qz(&" + XOP + ",((FEP_BUFF_TYPE*)sig[" + OD0 + "].pBuff)->q);" + CR + + " fep_set_bz(&" + XOP + ",((FEP_BUFF_TYPE*)sig[" + OD0 + "].pBuff)->b);" + CR + + " fep_set_tz(&" + XOP + ",((FEP_BUFF_TYPE*)sig[" + OD0 + "].pBuff)->t);" + CR + + " fep_set_wz(&" + XOP + ",/*USER TODO*/);" + CR + + " fep_set_ri(&" + XOP + ",/*USER TODO*/);" + CR + + " fep_set_sz(&" + XOP + ",/*USER TODO*/);" + CR + + " fep_set_nz(&" + XOP + ",/*USER TODO*/);" + CR + + " fep_set_mz(&" + XOP + ",/*USER TODO*/);" + CR + + " fep_set_sma(&" + XOP + ",1);" + CR + + "}" + CR; + cleanup_code = "fep_ctx_cleanup(&" + XOP + ");"; + } + +} //End of class diff --git a/src/Ctranslator/DmaMEC.java b/src/Ctranslator/DmaMEC.java index 932707f44f..80c90a87b4 100755 --- a/src/Ctranslator/DmaMEC.java +++ b/src/Ctranslator/DmaMEC.java @@ -1,68 +1,77 @@ -/**Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille, Andrea Enrici - - ludovic.apvrille AT enst.fr - andrea.enrici AT enstr.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 EmbbDmaMEC, Model Extension Construct (MEC) class for Embb's dma - * Creation: 05/02/2014 - * @version 1.0 05/02/2014 - * @author Andrea ENRICI - * @see - */ - -package tmltranslator.tmlcp;; - -import java.util.*; -import tmltranslator.*; -import myutil.*; -//import compiler.tmlCPparser.myexceptions.*; - -public class EmbbDmaMEC { - - private String context = "struct embb_dma_context_s ctx_"; - private String dmaStart = "embb_dma_start("; - private String dmaWait = "embb_dma_wait("; - private String dmaCtxInit = "embb_dma_ctx_init("; - private TMLCP tmlcp; - - /* The tmlcp CP of a DMA transfer */ - public DmaMEC( TMLCP _tmlcp ) { - tmlcp = _tmlcp; - } - - -} //End of class +/**Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille, Andrea Enrici + + ludovic.apvrille AT enst.fr + andrea.enrici AT enstr.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 DmaMEC, Model Extension Construct (MEC) class for a DMA data transfer + * Creation: 05/02/2014 + * @version 1.0 05/02/2014 + * @author Andrea ENRICI + * @see + */ + +package Ctranslator; + +import java.util.*; +//import Ctranslator.*; + +/* This is the code from Jair MEC. It refers to old drivers. So far I am just interested in the proof of concepts of generating + * code. */ +public class DmaMEC extends CPMEC { + + public DmaMEC() { + + node_type = "DMA"; + inst_type = "I2M"; + inst_decl = "DMA_CONTEXT"; + buff_type = "MM_BUFF_TYPE"; + buff_init = "= {/*bl*/,$OD0$_dat};"; + exec_code = "/*firm instruction*/" + CR + + " dma_set_loc(&$XOP$, sig[$ID0$].roff * (((FEP_BUFF_TYPE*)sig[$ID0$].pBuff)->t+1) + ((FEP_BUFF_TYPE*)sig[$ID0$].pBuff)->b + ((FEP_BUFF_TYPE*)sig[$ID0$].pBuff)->q * FEP_QSIZE );" + CR + + " dma_set_mem(&$XOP$, sig[$OD0$].woff*4 + ((MM_BUFF_TYPE*)sig[$OD0$].pBuff)->b);" + CR + + " dma_set_bsize(&$XOP$, ((MM_BUFF_TYPE*)sig[$OD0$].pBuff)->bl );" + CR + + "dma_start_i2m(&$XOP$);" + CR; + init_code = "/***** INIT $XOP$ I2M*******/" + CR + + "void init_$XOP$(void){" + CR + + " dma_ctx_init(&$XOP$, 0);" + CR + + " /* initialize context*/" + CR + + " dma_set_mem(&$XOP$, ((MM_BUFF_TYPE*)sig[$OD0$].pBuff)->b);" + CR + + "}" + CR; + cleanup_code = "dma_ctx_cleanup(&$XOP$);"; + } + +} //End of class diff --git a/src/Ctranslator/FftMEC.java b/src/Ctranslator/FftMEC.java index 0a52034174..6765736343 100644 --- a/src/Ctranslator/FftMEC.java +++ b/src/Ctranslator/FftMEC.java @@ -44,16 +44,14 @@ * @see */ -//package Ctranslator; +package Ctranslator; import java.util.*; //import Ctranslator.*; public class FftMEC extends TaskMEC { - private String CR = "\n"; - - public FftMEC() { + public FftMEC( String XOP, String ID0, String OD0, String BTC ) { node_type = "FEP"; inst_type = "FFT"; inst_decl = "FEP_CONTEXT"; @@ -84,8 +82,4 @@ public class FftMEC extends TaskMEC { cleanup_code = "fep_ctx_cleanup(&$XOP$);"; } - public String toString() { - return node_type + CR + inst_decl + CR + inst_type + CR + buff_type + CR + buff_init + CR + exec_code + init_code + cleanup_code; - } - } //End of class diff --git a/src/Ctranslator/SumMEC.java b/src/Ctranslator/SumMEC.java index b09957987c..c1eb31c0b1 100644 --- a/src/Ctranslator/SumMEC.java +++ b/src/Ctranslator/SumMEC.java @@ -44,17 +44,15 @@ * @see */ -//package Ctranslator; +package Ctranslator; import java.util.*; //import Ctranslator.*; public class SumMEC extends TaskMEC { - private String CR = "\n"; - - public SumMEC() { - node_type = "FEP";/* */ + public SumMEC( String XOP, String ID0, String OD0, String BTC ) { + node_type = "FEP"; inst_type = "SUM"; inst_decl = "FEP_CONTEXT"; buff_type = "FEP_BUFF_TYPE"; @@ -89,8 +87,4 @@ public class SumMEC extends TaskMEC { cleanup_code = "fep_ctx_cleanup(&$XOP$);"; } - public String toString() { - return node_type + CR + inst_decl + CR + inst_type + CR + buff_type + CR + buff_init + CR + exec_code + init_code + cleanup_code; - } - } //End of class diff --git a/src/Ctranslator/TMLCCodeGeneration.java b/src/Ctranslator/TMLCCodeGeneration.java new file mode 100755 index 0000000000..9d08265bf2 --- /dev/null +++ b/src/Ctranslator/TMLCCodeGeneration.java @@ -0,0 +1,405 @@ +/**Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille, Andrea Enrici + + ludovic.apvrille AT enst.fr + andrea.enrici AT enstr.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 TMLCCodeGeneration + * Creation: 09/02/2014 + * @version 1.0 09/02/2014 + * @author Andrea ENRICI + * @see + */ + +package Ctranslator; + +import java.util.*; +import java.nio.*; +import myutil.*; + +import tmltranslator.*; + +public class TMLCCodeGeneration { + + public String title; + + private String applicationName; + private String CR = "\n"; + private String CR2 = "\n\n"; + private String TAB = "\t"; + private String TAB2 = "\t\t"; + private String TAB3 = "\t\t\t"; + private String TAB4 = "\t\t\t\t"; + private TMLMapping tmap; + private String headerString; + private String programString; + private String initString; + private ArrayList<TMLTask> mappedTasks; + private ArrayList<TMLElement> commElts; + + public TMLCCodeGeneration( String _title, String _applicationName ) { + title = _title; + applicationName = _applicationName; + init(); + } + + private void init() { + headerString = ""; + programString = ""; + initString = ""; + mappedTasks = new ArrayList<TMLTask>(); + commElts = new ArrayList<TMLElement>(); + } + + public void toTextFormat( TMLMapping _tmap ) { + + tmap = _tmap; + ArrayList<TMLTask> mappedTasks = tmap.getMappedTasks(); + ArrayList<TMLElement> commElts = tmap.getMappedCommunicationElement(); + + //Fill the data structure to get the needed information + for( TMLTask task: mappedTasks ) { + TraceManager.addDev( "Task " + task.getName() ); + TraceManager.addDev( "Write channel: " + task.getWriteChannels().toString() ); + TraceManager.addDev( "Read channel: " + task.getReadChannels().toString() ); + } + + //Generate the C code + generateHeaderFile( mappedTasks ); + generateCProgram( mappedTasks ); + generateInitProgram( mappedTasks ); + } + + public void generateHeaderFile( ArrayList<TMLTask> mappedTasks ) { + + headerString += libraries(); + headerString += prototypes(); + headerString += buffers(); + headerString += instructions(); + headerString += signals( mappedTasks ); + headerString += variables(); + } + + private String libraries() { + String s = "#ifndef " + applicationName + "_H" + CR + + "#define " + applicationName + "_H" + CR + + "#include <stdio.h>" + CR + + "#include <stdint.h>" + CR + + "#include <embb/fep.h>" + CR + + "#include <embb/memory.h>" + CR + + "#include <embb/intl.h>" + CR + + "#include \"eMIMO.h\"" + CR2; + return s; + } + + private String prototypes() { + String s = "/**** prototypes *****/" + CR + + "extern int " + applicationName + "_final(void);" + CR + + "extern void " + applicationName + "_final_init();" + CR + + "extern void register_operations(void);" + CR + + "extern void register_fire_rules(void);" + CR + + "extern void signal_to_buffer_init();" + CR + + "extern void init_operations_context(void);" + CR + + "extern void cleanup_operations_context(void);" + CR2; + return s; + } + + private String buffers() { + String s = "/**** Buffers *****/" + CR2; + return s; + } + + private String instructions() { + String s = "/**** Instructions *****/" + CR2; + return s; + } + + private String signals( ArrayList<TMLTask> mappedTasks ) { + + String tasksList = ""; + String s = ""; + for( TMLTask task: mappedTasks ) { + String XOD = task.getName().split( "__" )[1]; + tasksList += XOD + ",\n"; + } + String temp = tasksList.substring(0, tasksList.length() - 1 ); + tasksList = temp; + + s = "/********* SIGNAL TYPE ***************/" + CR + + "struct SIG_TYPE {" + CR + + "bool f; // new signal flag=1" + CR + + "int woff; // write offset" + CR + + "int roff; // read offset" + CR + + "void *pBuff; // pointer to buffer" + CR + + "}; typedef struct SIG_TYPE SIG_TYPE;" + CR2 + + + "enum sigs_enu {" + CR + + getListOfWriteChannelPorts( mappedTasks ) + CR + /* list of comma separated output ports*/ + "NUM_SIGS };" + CR2 + + "enum ops_enu {" + CR + + tasksList + CR + /* list of comma separated tasks*/ + "NUM_SIGS };" + CR2; + return s; + } + + //Returns a string containing the list of all output ports name for channels + private String getListOfWriteChannelPorts( ArrayList<TMLTask> mappedTasks ) { + + String s = ""; + for( TMLTask task: mappedTasks ) { + if( task.getWriteChannels().size() > 0 ) { + s += task.getWriteChannels().toString().split("__")[1] + ",\n"; + } + } + return s.substring( 0, s.length()-1 ); + } + + private String variables() { + String s = "/**** variables *****/" + CR + + "#endif"; + return s; + } + + private void generateCProgram( ArrayList<TMLTask> mappedTasks ) { + programString += "#include " + "\"" + applicationName + ".h\"" + CR + + "int (*operation[NUM_OPS])();" + CR + + "bool (*fire_rule[NUM_OPS])();" + CR + + "SIG_TYPE sig[NUM_SIGS]={{0}};" + CR2 + + "/******** " + applicationName + "_final function *********/" + CR + + "int " + applicationName + "_final(void) {" + CR + + "bool valid_signal = false;" + CR + + "bool blocked = true;" + CR + + "int status = 0;" + CR2 + + "register_operations();" + CR + + "register_fire_rules();" + CR + + "signal_to_buffer_init();" + CR + + "init_operations_context();" + CR + + "/********* INIT PREX OPs signals ********/" + CR + + "sig[feed_out].f=true;" + CR + + "sig[src_out].f=true;" + CR + + "/********* OPs scheduller ***************/" + CR + + TAB + "while( ERROR: there are not exit signals ) {" + CR + + TAB2 + "for( int n_op = 0; n_op < NUM_OPS; ++n_op ) {" + CR + + TAB3 + "valid_signal = (*fire_rule[n_op])();" + CR + + TAB3 + "if( valid_signal ) {" + CR + + TAB4 + "status = (*operation[n_op])();" + CR + + TAB4 + "blocked = false;" + CR + + TAB3 + "}" + CR + + TAB2 + "}" + CR + + TAB2 + "if( blocked ) {" + CR + + TAB3 + "printf(\"ERROR:the system got blocked, no new signals\\n\");" + CR + + TAB3 + "return 1;" + CR + + TAB2 + "}" + CR + + TAB2 + "blocked = true;" + CR + + TAB + "}" + CR + + "cleanup_operations_context();" + CR + "}" + CR2; + generateOperations( mappedTasks ); + registerOperations( mappedTasks ); + fireRules( mappedTasks ); + registerFireRules( mappedTasks ); + } + + private void generateOperations( ArrayList<TMLTask> mappedTasks ) { //generate the code for the execution operations + + //for each operations add the exec code + the info for all the signals and stuff + String exec_code = ""; + + for( TMLTask task: mappedTasks ) { + String XOD = task.getName().split( "__" )[1]; + String functionName = "int op_" + XOD + "()\t{" + CR + + "int status=0;" + CR + + "static int size;" + CR + + "sig[ovlp_out].f = false;" + CR2; + if( XOD.contains( "CWP" ) || XOD.contains( "cwp" ) ) { + CwpMEC cwp = new CwpMEC( XOD, "", "", "" ); + exec_code = cwp.getExecCode(); + } + if( XOD.contains( "CWM" ) || XOD.contains( "cwm" ) ) { + CwmMEC cwm = new CwmMEC( XOD, "", "", "" ); + exec_code = cwm.getExecCode(); + } + if( XOD.contains( "CWA" ) || XOD.contains( "cwa" ) ) { + CwaMEC cwa = new CwaMEC( XOD, "", "", "" ); + exec_code = cwa.getExecCode(); + } + if( XOD.contains( "CWL" ) || XOD.contains( "cwl" ) ) { + CwlMEC cwl = new CwlMEC( XOD, "", "", "" ); + exec_code = cwl.getExecCode(); + } + if( XOD.contains( "SUM" ) || XOD.contains( "sum" ) ) { + SumMEC sum = new SumMEC( XOD, "", "", "" ); + exec_code = sum.getExecCode(); + } + if( XOD.contains( "FFT" ) || XOD.contains( "fft" ) ) { + FftMEC fft = new FftMEC( XOD, "", "", "" ); + exec_code = fft.getExecCode(); + } + String endCode = "sig[fft_out].f=true;" + CR + + "return status;" + CR + + "}" + CR2; + programString += functionName + exec_code + endCode; + exec_code = ""; + } + } + + private void registerOperations( ArrayList<TMLTask> mappedTasks ) { + + programString += "void register_operations( void )\t{" + CR; + for( TMLTask task: mappedTasks ) { + String XOD = task.getName().split( "__" )[1]; + programString += TAB + "operation[" + XOD + "] = " + "op_" + XOD + ";" + CR; + } + programString += "}" + CR2; + } + + private void fireRules( ArrayList<TMLTask> mappedTasks ) { + + programString += "/**** OPs FIRE RULES ****/"; + for( TMLTask task: mappedTasks ) { + String XOD = task.getName().split( "__" )[1]; + programString += "bool fr_" + XOD + "( void )\t" + CR; + programString += "return (" + generateFireRuleCondition( task ) + " );" + CR; + programString += "}" + CR; + } + programString += CR; + } + + private String generateFireRuleCondition( TMLTask task ) { + return ""; + } + + private void registerFireRules( ArrayList<TMLTask> mappedTasks ) { + + programString += "void register_fire_rules( void )\t{" + CR; + for( TMLTask task: mappedTasks ) { + String XOD = task.getName().split( "__" )[1]; + programString += TAB + "fire_rule[" + XOD + "] = " + "fr_" + XOD + ";" + CR; + } + programString += "}"; + } + + private void generateInitProgram( ArrayList<TMLTask> mappedTasks ) { + + String init_code = ""; + + initString += "#include \"" + applicationName + "_final.h\"" + CR2; + + initString += "/**** variables ****/" + CR2; + + initString += "/**** buffers ****/" + CR2; + + initString += "/**** instructions ****/" + CR; + for( String s: getTaskNamePerMappedUnit( "FEP", mappedTasks ) ) { + initString += "FEP_CONTEXT " + s + ";" + CR; + } + initString += CR; + + initString += "/**** init buffers ****/" + CR + + "void signal_to_buffer_init()\t{" + CR + "}" + CR2; + + initString += "/**** init code ****/" + CR; + + for( TMLTask task: mappedTasks ) { + String XOD = task.getName().split( "__" )[1]; + if( XOD.contains( "CWP" ) || XOD.contains( "cwp" ) ) { + CwpMEC cwp = new CwpMEC( XOD, "", "", "" ); + init_code = cwp.getInitCode(); + } + if( XOD.contains( "CWM" ) || XOD.contains( "cwm" ) ) { + CwmMEC cwm = new CwmMEC( XOD, "", "", "" ); + init_code = cwm.getInitCode(); + } + if( XOD.contains( "CWA" ) || XOD.contains( "cwa" ) ) { + CwaMEC cwa = new CwaMEC( XOD, "", "", "" ); + init_code = cwa.getInitCode(); + } + if( XOD.contains( "CWL" ) || XOD.contains( "cwl" ) ) { + CwlMEC cwl = new CwlMEC( XOD, "", "", "" ); + init_code = cwl.getInitCode(); + } + if( XOD.contains( "SUM" ) || XOD.contains( "sum" ) ) { + SumMEC sum = new SumMEC( XOD, "", "", "" ); + init_code = sum.getInitCode(); + } + if( XOD.contains( "FFT" ) || XOD.contains( "fft" ) ) { + FftMEC fft = new FftMEC( XOD, "", "", "" ); + init_code = fft.getInitCode(); + } + initString += init_code + CR; + init_code = ""; + } + + initString += "/**** init contexts ****/" + CR + + "void init_operations_context(void)\t{" + CR; + for( String s: getTaskNamePerMappedUnit( "FEP", mappedTasks ) ) { + initString += TAB + "init_" + s + "();" + CR; + } + initString += "}" + CR2; + + initString += "/**** cleanup contexts ****/" + CR; + initString += "void cleanup_operations_context( void )\t{" + CR; + for( String s: getTaskNamePerMappedUnit( "FEP", mappedTasks ) ) { + initString += TAB + "fep_ctx_cleanup( &" + s + " );" + CR; + } + initString += "}"; + } + + private ArrayList<String> getTaskNamePerMappedUnit( String mappedUnit, ArrayList<TMLTask> mappedTasks ) { + + ArrayList<String> list = new ArrayList<String>(); + + for( TMLTask task: mappedTasks ) { + HwNode hwNode = tmap.getHwNodeOf( task ); + if( hwNode.getName().contains( mappedUnit.toUpperCase() ) || hwNode.getName().contains( mappedUnit.toLowerCase() ) ) { + String XOP = task.getName().split( "__" )[1]; + list.add( XOP ); + } + } + return list; + } + + public String toString() { + return headerString + programString; + } + + public void saveFile( String path, String filename ) throws FileException { + + TraceManager.addUser( "Saving C files in " + path + filename ); + FileUtils.saveFile( path + filename + ".h", headerString ); + FileUtils.saveFile( path + filename + ".c", programString ); + FileUtils.saveFile( path + filename + "_init.c", initString ); + } +} //End of class diff --git a/src/Ctranslator/TaskMEC.java b/src/Ctranslator/TaskMEC.java index c1577880b7..fb2f8055b8 100755 --- a/src/Ctranslator/TaskMEC.java +++ b/src/Ctranslator/TaskMEC.java @@ -44,13 +44,16 @@ * @see */ -//package Ctranslator; +package Ctranslator; import java.util.*; +import java.nio.*; +import myutil.*; //import Ctranslator.*; public abstract class TaskMEC { + public String CR = "\n"; public String node_type = new String(); public String inst_type = new String(); public String inst_decl = new String(); @@ -59,9 +62,31 @@ public abstract class TaskMEC { public String init_code = new String(); public String exec_code = new String(); public String cleanup_code = new String(); - + + public String ID0 = new String(); + public String OD0 = new String(); + public String XOP = new String(); + public String BTC = new String(); + public TaskMEC() { node_type = "1"; } + public String getExecCode() { + return exec_code; + } + + public String getInitCode() { + return init_code; + } + + public String toString() { + return node_type + CR + inst_decl + CR + inst_type + CR + buff_type + CR + buff_init + CR + exec_code + CR + init_code + CR + cleanup_code; + } + + public void saveFile( String path, String filename ) throws FileException { + + TraceManager.addUser( "Saving C CP file in " + path + filename ); + FileUtils.saveFile( path + filename, this.toString() ); + } } //End of class diff --git a/src/tmltranslator/TMLCPTextSpecification.java b/src/tmltranslator/TMLCPTextSpecification.java index e575839b32..c36aa4f54a 100755 --- a/src/tmltranslator/TMLCPTextSpecification.java +++ b/src/tmltranslator/TMLCPTextSpecification.java @@ -249,7 +249,9 @@ public class TMLCPTextSpecification { ArrayList<tmltranslator.tmlcp.TMLSDInstance> listInstances = seqDiag.getInstances(); if( seqDiag.getAttributes().size() > 0 ) { for( TMLAttribute attribute: seqDiag.getAttributes() ) { - sbAttributes.append( attribute.toString() + CR ); + if( !sbAttributes.toString().contains( attribute.toString() ) ) { //if attribute not already contained, then add it + sbAttributes.append( attribute.toString() + CR ); + } } } for( tmltranslator.tmlcp.TMLSDInstance inst: listInstances ) { @@ -307,18 +309,21 @@ public class TMLCPTextSpecification { sb.append( makeSingleActivityDiagram( ad ) + CR + TAB + "END" + CR ); sb.append( CR + "END " + ad.getName() + CR ); } - + + //return sb.toString(); ArrayList<String> junctionTMLCodeList = new ArrayList<String>(); ArrayList<String> junctionNamesList = new ArrayList<String>(); for( TMLCPActivityDiagram ad: junctionDiagList ) { - String temp = makeSingleJunctionDiagram( ad ); - sb2.append( temp ); //the total text + String temp = new String( CR + "ACTIVITY " + ad.getName() + CR2 + TAB + "MAIN" + CR + TAB ); + temp += makeSingleJunctionDiagram( ad ); + temp += ( TAB + "><" + CR + TAB + "END" + CR2 + "END " + ad.getName() + CR ); + sb.append( temp ); //the total text junctionTMLCodeList.add( temp ); //each entry contains the text for one single junctionAD junctionNamesList.add( getJunctionName( temp ) ); } //Merge nested junction-choice - ArrayList<Integer> indexToRemove = new ArrayList<Integer>(); + /*ArrayList<Integer> indexToRemove = new ArrayList<Integer>(); for( String s: junctionTMLCodeList ) { if( !s.equals("") ) { if( s.contains( "JUNCTION" ) ) { @@ -352,7 +357,7 @@ public class TMLCPTextSpecification { String[] v = sb.toString().split( "JUNCTION " + s ); sb = new StringBuffer( v[0] + junctionTMLCodeList.get( junctionNamesList.indexOf( s ) ) + v[1] ); } - } + }*/ return sb.toString(); } @@ -372,7 +377,7 @@ public class TMLCPTextSpecification { private String makeSingleActivityDiagram( TMLCPActivityDiagram ad ) { - StringBuffer sb = new StringBuffer( "\n\t<>; " ); + StringBuffer sb = new StringBuffer( TAB + CR + TAB + "<>; " ); TMLCPElement currentElement, nextElement; ArrayList<TMLCPElement> nextElements; @@ -388,7 +393,7 @@ public class TMLCPTextSpecification { else { // currentElement is either a refToDiag or a junction if( isAJunction( currentElement ) ) { String s = ( (TMLCPRefAD) currentElement ).getName(); - sb.append( CR + "JUNCTION" + SP + s + CR ); + sb.append( s + ";" + CR ); } else { sb.append( parseSequence( currentElement ) ); @@ -397,7 +402,7 @@ public class TMLCPTextSpecification { currentElement = currentElement.getNextElements().get(0); } - return sb.toString() + "><"; + return sb.toString() + TAB + "><"; } private String parseSequence( TMLCPElement element ) { @@ -440,7 +445,7 @@ public class TMLCPTextSpecification { private String makeSingleJunctionDiagram( TMLCPActivityDiagram ad ) { - StringBuffer sb = new StringBuffer( ad.getName() + ":" + SP ); + StringBuffer sb = new StringBuffer( "<>;" + SP ); TMLCPElement currentElement, nextElement; ArrayList<TMLCPElement> nextElements; @@ -468,7 +473,7 @@ public class TMLCPTextSpecification { private String parseChoice( TMLCPElement currentElement, TMLCPActivityDiagram ad ) { - StringBuffer sb = new StringBuffer( CR + TAB + "LOOP" + SP + ad.getName() ); + StringBuffer sb = new StringBuffer( /*CR + TAB + "LOOP" + SP + ad.getName()*/ ); //this LOOP is the keywork that is used to look for the junction diagram name, removing it, causing the generation not to work ArrayList<TMLCPElement> nextElements; int index = 0; @@ -482,7 +487,7 @@ public class TMLCPTextSpecification { if( nextElements.size() > 1 ) { // currentElement is a fork node sbFork = new StringBuffer(); element = parseFork( nextElements ).getNextElements().get(0); // use attribute sbFork - element is the element after the join node - sb.append( sbFork.toString() ); + sb.append( sbFork.toString() + ";" ); sbFork.setLength(0); } else { //it is a simple sequence with no nested junctions, use element @@ -490,10 +495,10 @@ public class TMLCPTextSpecification { String s = ( (TMLCPRefAD) element ).getName(); sb = removeTrailingSymbol( sb ); if( s.equals( ad.getName() ) ) { - sb.append( SP + "GOTO" + SP + s ); // it is a reference to the same junction-choice block + sb.append( SP + s + ";" + SP + "><" ); // it is a reference to the same junction-choice block } else { - sb.append( SP + "GOTO" + SP + "JUNCTION" + s ); //it is a reference to another junction-choice block + sb.append( SP + s + ";" + SP + "><" ); //it is a reference to another junction-choice block } break; } @@ -503,13 +508,13 @@ public class TMLCPTextSpecification { element = element.getNextElements().get(0); if( element instanceof TMLCPStop ) { sb = removeTrailingSymbol( sb ); - sb.append( SP + "GOTO END" + SP + ad.getName() ); + sb.append( TAB + "><" ); } } } // end of while index++; } // end of for - sb.append( CR + TAB + "END" + SP + ad.getName() + CR ); + sb.append( CR ); return sb.toString(); } diff --git a/src/tmltranslator/TMLMapping.java b/src/tmltranslator/TMLMapping.java index f3bb4bc2bd..a5d6e1ee9f 100755 --- a/src/tmltranslator/TMLMapping.java +++ b/src/tmltranslator/TMLMapping.java @@ -518,8 +518,9 @@ public class TMLMapping { } } - public String getSummaryTaskMapping() { + public ArrayList<String> getSummaryTaskMapping() { StringBuffer sb = new StringBuffer(""); + ArrayList<String> list = new ArrayList<String>(); int cpt = 0; int found = 0; @@ -539,10 +540,48 @@ public class TMLMapping { cpt ++; } sb.append(") "); + list.add( sb.toString() ); + sb = new StringBuffer(""); } } - return sb.toString(); + return list; + + } + + public ArrayList<String> getSummaryCPMapping() { + ArrayList<String> list = new ArrayList<String>(); + return list; + } + + public ArrayList<String> getSummaryCommMapping() { + StringBuffer sb = new StringBuffer(""); + ArrayList<String> list = new ArrayList<String>(); + int cpt = 0; + int found = 0; + + for (HwNode node: tmla.getHwNodes()) { + if (node instanceof HwCommunicationNode) { + sb.append(node.getName() + "("); + found = 0; + cpt = 0; + for(HwCommunicationNode ex: oncommnodes) { + if (ex == node) { + if (found > 0) { + sb.append(", "); + } + found = 1; + sb.append(mappedcommelts.get(cpt).getName()); + } + cpt ++; + } + sb.append(") "); + list.add( sb.toString() ); + sb = new StringBuffer(""); + } + } + + return list; } diff --git a/src/tmltranslator/TMLTask.java b/src/tmltranslator/TMLTask.java index a67ba25f86..7f639b0e8f 100755 --- a/src/tmltranslator/TMLTask.java +++ b/src/tmltranslator/TMLTask.java @@ -135,6 +135,30 @@ public class TMLTask extends TMLElement { } return null; } + + public ArrayList<TMLReadChannel> getReadChannels() { + + ArrayList<TMLReadChannel> list = new ArrayList<TMLReadChannel>(); + for( int i = 0; i < getActivityDiagram().nElements(); i++ ) { + if( getActivityDiagram().get(i) instanceof TMLReadChannel ) { + list.add( (TMLReadChannel) getActivityDiagram().get(i) ); + //TraceManager.addDev( "Element: " + task.getActivityDiagram().get(i).toString() ); + } + } + return list; + } + + public ArrayList<TMLWriteChannel> getWriteChannels() { + + ArrayList<TMLWriteChannel> list = new ArrayList<TMLWriteChannel>(); + for( int i = 0; i < getActivityDiagram().nElements(); i++ ) { + if( getActivityDiagram().get(i) instanceof TMLWriteChannel ) { + list.add( (TMLWriteChannel) getActivityDiagram().get(i) ); + //TraceManager.addDev( "Element: " + task.getActivityDiagram().get(i).toString() ); + } + } + return list; + } public TMLActivity getActivityDiagram() { return activity; @@ -223,4 +247,4 @@ public class TMLTask extends TMLElement { } -} \ No newline at end of file +} diff --git a/src/ui/GTURTLEModeling.java b/src/ui/GTURTLEModeling.java index ca6150fd3f..c869fce209 100755 --- a/src/ui/GTURTLEModeling.java +++ b/src/ui/GTURTLEModeling.java @@ -411,13 +411,14 @@ public class GTURTLEModeling { public boolean generateCcode( String _title ) { - CwmMEC myCwm = new CwmMEC(); - TMLMappingTextSpecification spec = new TMLMappingTextSpecification( _title ); spec.toTextFormat( tmap ); //TMLMapping - + + TMLCCodeGeneration myCode = new TMLCCodeGeneration( _title, "test" ); + myCode.toTextFormat( tmap ); + try { - myCwm.saveFile( ConfigurationTTool.CcodeDirectory + File.separator, "application.c" ); + myCode.saveFile( ConfigurationTTool.CcodeDirectory + File.separator, "test" ); } catch( Exception e ) { TraceManager.addError( "Application C files could not be saved: " + e.getMessage() ); diff --git a/src/ui/tmldd/TMLArchiPortArtifact.java b/src/ui/tmldd/TMLArchiPortArtifact.java index a8decbb3fb..c536f57670 100644 --- a/src/ui/tmldd/TMLArchiPortArtifact.java +++ b/src/ui/tmldd/TMLArchiPortArtifact.java @@ -70,6 +70,8 @@ public class TMLArchiPortArtifact extends TGCWithoutInternalComponent implements protected String referenceCommunicationName = "TMLCommunication"; protected String portName = "name"; protected String typeName = "port"; + protected String startAddress = ""; + protected String endAddress = ""; protected int priority = 5; // Between 0 and 10 public TMLArchiPortArtifact(int _x, int _y, int _minX, int _maxX, int _minY, int _maxY, boolean _pos, TGComponent _father, TDiagramPanel _tdp) { @@ -161,11 +163,13 @@ public class TMLArchiPortArtifact extends TGCWithoutInternalComponent implements String tmp; boolean error = false; - JDialogPortArtifact dialog = new JDialogPortArtifact(frame, "Setting port artifact attributes", this, mappedMemory ); + JDialogPortArtifact dialog = new JDialogPortArtifact(frame, "Setting port artifact attributes", this, mappedMemory, startAddress, endAddress, value ); dialog.setSize(700, 600); GraphicLib.centerOnParent(dialog); dialog.show(); // blocked until dialog has been closed mappedMemory = dialog.getMappedMemory(); + startAddress = dialog.getStartAddress(); + endAddress = dialog.getEndAddress(); if (!dialog.isRegularClose()) { return false; @@ -235,6 +239,9 @@ public class TMLArchiPortArtifact extends TGCWithoutInternalComponent implements /*sb.append("\" priority=\""); sb.append(priority);*/ sb.append("\" typeName=\"" + typeName); + sb.append("\" mappedMemory=\"" + mappedMemory ); + sb.append("\" startAddress=\"" + startAddress ); + sb.append("\" endAddress=\"" + endAddress ); sb.append("\" />\n"); sb.append("</extraparam>\n"); return new String(sb); @@ -266,6 +273,9 @@ public class TMLArchiPortArtifact extends TGCWithoutInternalComponent implements sname = elt.getAttribute("portName"); sreferenceCommunication = elt.getAttribute("referenceCommunicationName"); stype = elt.getAttribute("typeName"); + mappedMemory = elt.getAttribute("mappedMemory"); + startAddress = elt.getAttribute("startAddress"); + endAddress = elt.getAttribute("endAddress"); //prio = elt.getAttribute("priority"); } if (svalue != null) { diff --git a/src/ui/window/JDialogPortArtifact.java b/src/ui/window/JDialogPortArtifact.java index 1f27cc0887..2d1125b030 100755 --- a/src/ui/window/JDialogPortArtifact.java +++ b/src/ui/window/JDialogPortArtifact.java @@ -69,20 +69,22 @@ public class JDialogPortArtifact extends javax.swing.JDialog implements ActionLi private TMLArchiPortArtifact artifact; private String mappedMemory = "VOID"; protected JComboBox referenceCommunicationName, priority, memory; - protected JTextField startAddress, endAddress; + protected JTextField startAddressTF, endAddressTF; + protected String startAddress, endAddress, mappedPort; // Main Panel private JButton closeButton; private JButton cancelButton; /** Creates new form */ - public JDialogPortArtifact(Frame _frame, String _title, TMLArchiPortArtifact _artifact, String _mappedMemory ) { + public JDialogPortArtifact(Frame _frame, String _title, TMLArchiPortArtifact _artifact, String _mappedMemory, String _startAddress, String _endAddress, String _mappedPort ) { super(_frame, _title, true); frame = _frame; artifact = _artifact; mappedMemory = _mappedMemory; - - //System.out.println("New window"); + startAddress = _startAddress; + endAddress = _endAddress; + mappedPort = _mappedPort; TraceManager.addDev("init components"); @@ -155,10 +157,13 @@ public class JDialogPortArtifact extends javax.swing.JDialog implements ActionLi TraceManager.addDev("Got communications"); referenceCommunicationName = new JComboBox(portsList); - referenceCommunicationName.setSelectedIndex(index); + if( mappedPort.equals( "VOID" ) || mappedPort.equals( "" ) ) { + referenceCommunicationName.setSelectedIndex( 0 ); + } + else { + referenceCommunicationName.setSelectedIndex( portsList.indexOf( mappedPort ) ); + } referenceCommunicationName.addActionListener(this); - //referenceTaskName.setEditable(true); - //referenceTaskName.setFont(new Font("times", Font.PLAIN, 12)); panel2.add(referenceCommunicationName, c1); list = new Vector<String>(); @@ -189,14 +194,14 @@ public class JDialogPortArtifact extends javax.swing.JDialog implements ActionLi panel2.add( new JLabel( "Memory: "), c2 ); panel2.add( memory, c1 ); - startAddress = new JTextField("", 5 ); + startAddressTF = new JTextField( startAddress, 5 ); panel2.add( new JLabel( "Start address = "), c2 ); c1.gridwidth = GridBagConstraints.REMAINDER; - panel2.add( startAddress, c1 ); + panel2.add( startAddressTF, c1 ); - endAddress = new JTextField("", 5 ); + endAddressTF = new JTextField( endAddress, 5 ); panel2.add( new JLabel( "End address = "), c2 ); - panel2.add( endAddress, c1 ); + panel2.add( endAddressTF, c1 ); /*c1.gridwidth = 1; c1.gridheight = 1; c1.weighty = 1.0; @@ -261,13 +266,28 @@ public class JDialogPortArtifact extends javax.swing.JDialog implements ActionLi public void closeDialog() { regularClose = true; mappedMemory = (String) memory.getItemAt( memory.getSelectedIndex() ); + startAddress = (String) startAddressTF.getText(); + endAddress = (String) endAddressTF.getText(); + //mappedPort = (String) referenceCommunicationName.getItemAt( .getSelectedIndex() ); dispose(); } + public String getMappedPort() { + return mappedPort; + } + public String getMappedMemory() { return mappedMemory; } - + + public String getStartAddress() { + return startAddress; + } + + public String getEndAddress() { + return endAddress; + } + public void cancelDialog() { dispose(); } -- GitLab