From a6da7b51e8bd7c4bea1d3bd57bfcb2151857d03e Mon Sep 17 00:00:00 2001 From: Rodrigo CORTES PORTO <Rodrigo.Cortes-porto@lip6.fr> Date: Mon, 30 Jul 2018 17:14:02 +0200 Subject: [PATCH] New toSysCAMSCluster directory to hold the AMS cluster generation code for integration with SoCLib. --- MPSoC/Makefile.forsoclib | 5 + .../toSysCAMS/PrimitiveCode.java | 2 +- .../toSysCAMSCluster/ClusterCode.java | 311 +++++++++ .../toSysCAMSCluster/Header.java | 113 ++++ .../toSysCAMSCluster/MakefileCode.java | 113 ++++ .../toSysCAMSCluster/PrimitiveCode.java | 605 ++++++++++++++++++ .../TopCellGeneratorCluster.java | 149 +++++ ...DialogSysCAMSExecutableCodeGeneration.java | 3 + 8 files changed, 1300 insertions(+), 1 deletion(-) create mode 100644 src/main/java/syscamstranslator/toSysCAMSCluster/ClusterCode.java create mode 100644 src/main/java/syscamstranslator/toSysCAMSCluster/Header.java create mode 100644 src/main/java/syscamstranslator/toSysCAMSCluster/MakefileCode.java create mode 100644 src/main/java/syscamstranslator/toSysCAMSCluster/PrimitiveCode.java create mode 100644 src/main/java/syscamstranslator/toSysCAMSCluster/TopCellGeneratorCluster.java diff --git a/MPSoC/Makefile.forsoclib b/MPSoC/Makefile.forsoclib index f2f1601ccb..80c144da16 100755 --- a/MPSoC/Makefile.forsoclib +++ b/MPSoC/Makefile.forsoclib @@ -27,6 +27,11 @@ updategeneratedcode: cp Makefile.soclib mutekh/examples/avatar/Makefile compilesoclib: + rm soclib/soclib/platform/topcells/caba-vgmn-mutekh_kernel_tutorial/*_tdf.h ||: + cp ../SysCAMSGenerationCode/generated_CPP/*_tdf.h soclib/soclib/platform/topcells/caba-vgmn-mutekh_kernel_tutorial/ ||: + cp ../SysCAMSGenerationCode/generated_H/*_tdf.h soclib/soclib/platform/topcells/caba-vgmn-mutekh_kernel_tutorial/ ||: + rm ../SysCAMSGenerationCode/generated_H/*_tdf.h ||: + rm ../SysCAMSGenerationCode/generated_CPP/*_tdf.h ||: cp generated_topcell/top.cc soclib/soclib/platform/topcells/caba-vgmn-mutekh_kernel_tutorial/ cp generated_topcell/deployinfo.h mutekh/arch/soclib/ cp generated_topcell/deployinfo_map.h mutekh/arch/soclib/ diff --git a/src/main/java/syscamstranslator/toSysCAMS/PrimitiveCode.java b/src/main/java/syscamstranslator/toSysCAMS/PrimitiveCode.java index d088f050c8..595b6121ee 100644 --- a/src/main/java/syscamstranslator/toSysCAMS/PrimitiveCode.java +++ b/src/main/java/syscamstranslator/toSysCAMS/PrimitiveCode.java @@ -222,7 +222,7 @@ public class PrimitiveCode { } if (tdf.getPeriod() != -1) { - corpsPrimitiveTDF = corpsPrimitiveTDF + "\tvoid set_attributes() {" + CR + "\t\t" + "set_timestep(" + tdf.getPeriod() + ", sc_core::SC_" + tdf.getTime().toUpperCase() + CR; + corpsPrimitiveTDF = corpsPrimitiveTDF + "\tvoid set_attributes() {" + CR + "\t\t" + "set_timestep(" + tdf.getPeriod() + ", sc_core::SC_" + tdf.getTime().toUpperCase() + ");" + CR; cpt2++; } if (cpt2 > 0) { diff --git a/src/main/java/syscamstranslator/toSysCAMSCluster/ClusterCode.java b/src/main/java/syscamstranslator/toSysCAMSCluster/ClusterCode.java new file mode 100644 index 0000000000..fecbe00e61 --- /dev/null +++ b/src/main/java/syscamstranslator/toSysCAMSCluster/ClusterCode.java @@ -0,0 +1,311 @@ +/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + * Daniela Genius, Lip6, UMR 7606 + * + * ludovic.apvrille AT enst.fr + * daniela.genius@lip6.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. + */ + +/* this class produces the lines containing essentially the initial #includes; we include all potential components event if they are not used in the deployment diagram*/ + +/* authors: v1.0 Raja GATGOUT 2014 + v2.0 Daniela GENIUS, Julien HENON 2015 */ + +package syscamstranslator.toSysCAMSCluster; + +import java.util.LinkedList; + +import syscamstranslator.*; + +/** + * Class ClusterCode + * Principal code of a cluster component + * Creation: 14/05/2018 + * @version 1.0 14/05/2018 + * @author Irina Kit Yan LEE +*/ + +public class ClusterCode { + static private String corpsCluster; + private final static String CR = "\n"; + private final static String CR2 = "\n\n"; + + ClusterCode() {} + + public static String getClusterCode(SysCAMSTCluster cluster, LinkedList<SysCAMSTConnector> connectors) { + int nb_con = 0; + int nb_block = 0; + + LinkedList<String> names = new LinkedList<String>(); + + if (cluster != null) { + LinkedList<SysCAMSTBlockTDF> tdf = cluster.getBlockTDF(); + LinkedList<SysCAMSTBlockDE> de = cluster.getBlockDE(); + + System.out.println("Number of AMS connectors: " + connectors.size()); + + corpsCluster = "template <typename vci_param>" + CR + + "class " +cluster.getClusterName()+ " : public sc_core::sc_module { "+ CR; + + corpsCluster = corpsCluster + "\t// Declare signals to interconnect." + CR; + + //for (SysCAMSTConnector c : connectors) { + for (int i = 0; i < connectors.size(); i++) { + nb_con = i; + if ( !((connectors.get(i).get_p1().getComponent() instanceof SysCAMSTPortDE && ((SysCAMSTPortDE) connectors.get(i).get_p1().getComponent()).getBlockGPIO2VCI() != null) + || (connectors.get(i).get_p2().getComponent() instanceof SysCAMSTPortDE && ((SysCAMSTPortDE) connectors.get(i).get_p2().getComponent()).getBlockGPIO2VCI() != null)) ) { + /*if (connectors.get(i).get_p1().getComponent() instanceof SysCAMSTPortTDF) { + corpsCluster = corpsCluster + "\tsca_tdf::sca_signal<" + ((SysCAMSTPortTDF) connectors.get(i).get_p1().getComponent()).getTDFType() + "> " + + "sig_" + nb_con + ";" + CR; + //nb_con++; + } else if (connectors.get(i).get_p1().getComponent() instanceof SysCAMSTPortConverter) { + corpsCluster = corpsCluster + "\tsc_core::sc_signal<" + ((SysCAMSTPortConverter) connectors.get(i).get_p1().getComponent()).getConvType() + "> " + + "sig_" + nb_con + ";" + CR; + //nb_con++; + } else if (connectors.get(i).get_p1().getComponent() instanceof SysCAMSTPortDE) { + corpsCluster = corpsCluster + "\tsc_core::sc_signal<" + ((SysCAMSTPortDE) connectors.get(i).get_p1().getComponent()).getDEType() + "> " + + "sig_" + nb_con + ";" + CR; + //nb_con++; + }*/ + + if ((connectors.get(i).get_p1().getComponent() instanceof SysCAMSTPortTDF && connectors.get(i).get_p2().getComponent() instanceof SysCAMSTPortTDF) + || (connectors.get(i).get_p1().getComponent() instanceof SysCAMSTPortTDF && connectors.get(i).get_p2().getComponent() instanceof SysCAMSTPortTDF)) { + if (connectors.get(i).getName().equals("")) { + corpsCluster = corpsCluster + "\tsca_tdf::sca_signal<" + ((SysCAMSTPortTDF) connectors.get(i).get_p1().getComponent()).getTDFType() + "> " + + "sig_" + nb_con + ";" + CR; + names.add("sig_" + nb_con); + //nb_con++; + } else { + corpsCluster = corpsCluster + "\tsca_tdf::sca_signal<" + ((SysCAMSTPortTDF) connectors.get(i).get_p1().getComponent()).getTDFType() + "> " + + connectors.get(i).getName() + ";" + CR; + names.add(connectors.get(i).getName()); + } + } else if ((connectors.get(i).get_p1().getComponent() instanceof SysCAMSTPortConverter && connectors.get(i).get_p2().getComponent() instanceof SysCAMSTPortDE)) { + if (connectors.get(i).getName().equals("")) { + corpsCluster = corpsCluster + "\tsc_core::sc_signal<" + ((SysCAMSTPortConverter) connectors.get(i).get_p1().getComponent()).getConvType() + "> " + + "sig_" + nb_con + ";" + CR; + names.add("sig_" + nb_con); + //nb_con++; + } else { + corpsCluster = corpsCluster + "\tsc_core::sc_signal<" + ((SysCAMSTPortConverter) connectors.get(i).get_p1().getComponent()).getConvType() + "> " + + connectors.get(i).getName() + ";" + CR; + names.add(connectors.get(i).getName()); + } + } else if ((connectors.get(i).get_p2().getComponent() instanceof SysCAMSTPortConverter && connectors.get(i).get_p1().getComponent() instanceof SysCAMSTPortDE)) { + if (connectors.get(i).getName().equals("")) { + corpsCluster = corpsCluster + "\tsc_core::sc_signal<" + ((SysCAMSTPortConverter) connectors.get(i).get_p2().getComponent()).getConvType() + "> " + + "sig_" + nb_con + ";" + CR; + names.add("sig_" + nb_con); + //nb_con++; + } else { + corpsCluster = corpsCluster + "\tsc_core::sc_signal<" + ((SysCAMSTPortConverter) connectors.get(i).get_p2().getComponent()).getConvType() + "> " + + connectors.get(i).getName() + ";" + CR; + names.add(connectors.get(i).getName()); + } + } else if ((connectors.get(i).get_p1().getComponent() instanceof SysCAMSTPortDE && connectors.get(i).get_p2().getComponent() instanceof SysCAMSTPortDE) + || (connectors.get(i).get_p2().getComponent() instanceof SysCAMSTPortDE && connectors.get(i).get_p1 ().getComponent() instanceof SysCAMSTPortDE)) { + if (connectors.get(i).getName().equals("")) { + corpsCluster = corpsCluster + "\tsc_core::sc_signal<" + ((SysCAMSTPortDE) connectors.get(i).get_p1().getComponent()).getDEType() + "> " + + "sig_" + nb_con + ";" + CR; + names.add("sig_" + nb_con); + //nb_con++; + } else { + corpsCluster = corpsCluster + "\tsc_core::sc_signal<" + ((SysCAMSTPortDE) connectors.get(i).get_p1().getComponent()).getDEType() + "> " + + connectors.get(i).getName() + ";" + CR; + names.add(connectors.get(i).getName()); + } + } + + } else { + names.add("gpio_sig" + nb_con); + } + } + + corpsCluster = corpsCluster + CR + "\t// Instantiate cluster's modules." + CR; + for (SysCAMSTBlockTDF t : tdf) { + corpsCluster = corpsCluster + "\t" + t.getName() + " " + + t.getName() + "_" + nb_block + ";" + CR; + nb_block++; + } + + for (SysCAMSTBlockDE t : de) { + corpsCluster = corpsCluster + "\t" + t.getName() + " " + + t.getName() + "_" + nb_block + ";" + CR; + nb_block++; + } + + corpsCluster = corpsCluster + "public:" + CR; + corpsCluster = corpsCluster + "\tsc_in< typename vci_param::data_t > in_ams;" + CR; + corpsCluster = corpsCluster + "\tsc_out< typename vci_param::data_t > out_ams;" + CR2; + + nb_block = 0; + corpsCluster = corpsCluster + "\tSC_CTOR(" +cluster.getClusterName()+ ") :" + CR; + for (SysCAMSTBlockTDF t : tdf) { + corpsCluster = corpsCluster + "\t" + t.getName() + "_" + nb_block + "(\"" + t.getName() + "_" + nb_block + "\")," + CR; + nb_block++; + } + for (SysCAMSTBlockDE t : de) { + corpsCluster = corpsCluster + "\t" + t.getName() + "_" + nb_block + "(\"" + t.getName() + "_" + nb_block + "\")," + CR; + nb_block++; + } + corpsCluster = corpsCluster + "\tin_ams(\"in_ams\")," + CR; + corpsCluster = corpsCluster + "\tout_ams(\"out_ams\") {" + CR; + + nb_block = 0; + for (SysCAMSTBlockTDF t : tdf) { + //corpsCluster = corpsCluster + "\t" + t.getName() + " " + t.getName() + "_" + nb_block + "(\"" + t.getName() + "_" + nb_block + "\");" + CR; + + LinkedList<SysCAMSTPortTDF> portTDF = t.getPortTDF(); + LinkedList<SysCAMSTPortConverter> portConv = t.getPortConverter(); + + for (SysCAMSTPortTDF p : portTDF) { + for (int i = 0; i < connectors.size(); i++) { + if (connectors.get(i).get_p1().getComponent() instanceof SysCAMSTPortTDF && connectors.get(i).get_p2().getComponent() instanceof SysCAMSTPortTDF) { + if (((SysCAMSTPortTDF) connectors.get(i).get_p1().getComponent()).getName().equals(p.getName()) && ((SysCAMSTPortTDF) connectors.get(i).get_p1().getComponent()).getBlockTDF().getName().equals(t.getName())) { + corpsCluster = corpsCluster + "\t\t" + t.getName() + "_" + nb_block + "." + p.getName() + "(" + names.get(i) + ");" + CR; + } else if (((SysCAMSTPortTDF) connectors.get(i).get_p2().getComponent()).getName().equals(p.getName()) && ((SysCAMSTPortTDF) connectors.get(i).get_p2().getComponent()).getBlockTDF().getName().equals(t.getName())) { + corpsCluster = corpsCluster + "\t\t" + t.getName() + "_" + nb_block + "." + p.getName() + "(" + names.get(i) + ");" + CR; + } + } + } + } + + for (SysCAMSTPortConverter p : portConv) { + for (int i = 0; i < connectors.size(); i++) { + nb_con = i; + + if ( !((connectors.get(i).get_p1().getComponent() instanceof SysCAMSTPortDE && ((SysCAMSTPortDE) connectors.get(i).get_p1().getComponent()).getBlockGPIO2VCI() != null) + || (connectors.get(i).get_p2().getComponent() instanceof SysCAMSTPortDE && ((SysCAMSTPortDE) connectors.get(i).get_p2().getComponent()).getBlockGPIO2VCI() != null)) ) { + if (connectors.get(i).get_p1().getComponent() instanceof SysCAMSTPortConverter && connectors.get(i).get_p2().getComponent() instanceof SysCAMSTPortDE) { + if (((SysCAMSTPortConverter) connectors.get(i).get_p1().getComponent()).getName().equals(p.getName()) && ((SysCAMSTPortConverter) connectors.get(i).get_p1().getComponent()).getBlockTDF().getName().equals(t.getName())) { + corpsCluster = corpsCluster + "\t\t" + t.getName() + "_" + nb_block + "." + p.getName() + "(" + names.get(i) + ");" + CR; + } else if (((SysCAMSTPortDE) connectors.get(i).get_p2().getComponent()).getName().equals(p.getName()) && ((SysCAMSTPortDE) connectors.get(i).get_p2().getComponent()).getBlockDE().getName().equals(t.getName())) { + corpsCluster = corpsCluster + "\t\t" + t.getName() + "_" + nb_block + "." + p.getName() + "(" + names.get(i) + ");" + CR; + } + } else if (connectors.get(i).get_p2().getComponent() instanceof SysCAMSTPortConverter && connectors.get(i).get_p1().getComponent() instanceof SysCAMSTPortDE) { + if (((SysCAMSTPortConverter) connectors.get(i).get_p2().getComponent()).getName().equals(p.getName()) && ((SysCAMSTPortConverter) connectors.get(i).get_p2().getComponent()).getBlockTDF().getName().equals(t.getName())) { + corpsCluster = corpsCluster + "\t\t" + t.getName() + "_" + nb_block + "." + p.getName() + "(" + names.get(i) + ");" + CR; + } else if (((SysCAMSTPortDE) connectors.get(i).get_p1().getComponent()).getName().equals(p.getName()) && ((SysCAMSTPortDE) connectors.get(i).get_p1().getComponent()).getBlockDE().getName().equals(t.getName())) { + corpsCluster = corpsCluster + "\t\t" + t.getName() + "_" + nb_block + "." + p.getName() + "(" + names.get(i) + ");" + CR; + } + } + } else { + if (connectors.get(i).get_p1().getComponent() instanceof SysCAMSTPortDE && ((SysCAMSTPortDE) connectors.get(i).get_p1().getComponent()).getBlockGPIO2VCI() != null) { + if (connectors.get(i).get_p2().getComponent() instanceof SysCAMSTPortConverter) { + if (((SysCAMSTPortConverter) connectors.get(i).get_p2().getComponent()).getName().equals(p.getName()) && ((SysCAMSTPortConverter) connectors.get(i).get_p2().getComponent()).getBlockTDF().getName().equals(t.getName())) { + corpsCluster = corpsCluster + "\t\t" + t.getName() + "_" + nb_block + "." + p.getName() + "(in_ams);" + CR; + } + } + } else if (connectors.get(i).get_p2().getComponent() instanceof SysCAMSTPortDE && ((SysCAMSTPortDE) connectors.get(i).get_p2().getComponent()).getBlockGPIO2VCI() != null) { + if (connectors.get(i).get_p1().getComponent() instanceof SysCAMSTPortConverter) { + if (((SysCAMSTPortConverter) connectors.get(i).get_p1().getComponent()).getName().equals(p.getName()) && ((SysCAMSTPortConverter) connectors.get(i).get_p1().getComponent()).getBlockTDF().getName().equals(t.getName())) { + corpsCluster = corpsCluster + "\t\t" + t.getName() + "_" + nb_block + "." + p.getName() + "(out_ams);" + CR; + } + } + } + } + } + } + corpsCluster = corpsCluster + CR; + nb_block++; + } + + for (SysCAMSTBlockDE t : de) { + //corpsCluster = corpsCluster + "\t" + t.getName() + " " + t.getName() + "_" + nb_block + "(\"" + t.getName() + "_" + nb_block + "\");" + CR; + + LinkedList<SysCAMSTPortDE> portDE = t.getPortDE(); + + for (SysCAMSTPortDE p : portDE) { + for (int i = 0; i < connectors.size(); i++) { + /*nb_con = i; + if (connectors.get(i).get_p1().getComponent() instanceof SysCAMSTPortDE) { + if (((SysCAMSTPortDE) connectors.get(i).get_p1().getComponent()).getName().equals(p.getName()) && ((SysCAMSTPortDE) connectors.get(i).get_p1().getComponent()).getBlockDE().getName().equals(t.getName())) { + corpsCluster = corpsCluster + "\t\t" + t.getName() + "_" + nb_block + "." + p.getName() + "(" + "sig_" + nb_con + ");" + CR; + } + } else if (connectors.get(i).get_p2().getComponent() instanceof SysCAMSTPortDE) { + if (((SysCAMSTPortDE) connectors.get(i).get_p2().getComponent()).getName().equals(p.getName()) && ((SysCAMSTPortDE) connectors.get(i).get_p2().getComponent()).getBlockDE().getName().equals(t.getName())) { + corpsCluster = corpsCluster + "\t\t" + t.getName() + "_" + nb_block + "." + p.getName() + "(" + "sig_" + nb_con + ");" + CR; + } + }*/ + if (connectors.get(i).get_p1().getComponent() instanceof SysCAMSTPortDE && connectors.get(i).get_p2().getComponent() instanceof SysCAMSTPortDE) { + if (((SysCAMSTPortDE) connectors.get(i).get_p1().getComponent()).getName().equals(p.getName()) && ((SysCAMSTPortDE) connectors.get(i).get_p1().getComponent()).getBlockDE().getName().equals(t.getName())) { + corpsCluster = corpsCluster + "\t\t" + t.getName() + "_" + nb_block + "." + p.getName() + "(" + names.get(i) + ");" + CR; + } else if (((SysCAMSTPortDE) connectors.get(i).get_p2().getComponent()).getName().equals(p.getName()) && ((SysCAMSTPortDE) connectors.get(i).get_p2().getComponent()).getBlockDE().getName().equals(t.getName())) { + corpsCluster = corpsCluster + "\t\t" + t.getName() + "_" + nb_block + "." + p.getName() + "(" + names.get(i) + ");" + CR; + } + } else if (connectors.get(i).get_p1().getComponent() instanceof SysCAMSTPortConverter && connectors.get(i).get_p2().getComponent() instanceof SysCAMSTPortDE) { + if (((SysCAMSTPortConverter) connectors.get(i).get_p1().getComponent()).getName().equals(p.getName()) && ((SysCAMSTPortConverter) connectors.get(i).get_p1().getComponent()).getBlockTDF().getName().equals(t.getName())) { + corpsCluster = corpsCluster + "\t\t" + t.getName() + "_" + nb_block + "." + p.getName() + "(" + names.get(i) + ");" + CR; + } else if (((SysCAMSTPortDE) connectors.get(i).get_p2().getComponent()).getName().equals(p.getName()) && ((SysCAMSTPortDE) connectors.get(i).get_p2().getComponent()).getBlockDE().getName().equals(t.getName())) { + corpsCluster = corpsCluster + "\t\t" + t.getName() + "_" + nb_block + "." + p.getName() + "(" + names.get(i) + ");" + CR; + } + } else if (connectors.get(i).get_p2().getComponent() instanceof SysCAMSTPortConverter && connectors.get(i).get_p1().getComponent() instanceof SysCAMSTPortDE) { + if (((SysCAMSTPortConverter) connectors.get(i).get_p2().getComponent()).getName().equals(p.getName()) && ((SysCAMSTPortConverter) connectors.get(i).get_p2().getComponent()).getBlockTDF().getName().equals(t.getName())) { + corpsCluster = corpsCluster + "\t\t" + t.getName() + "_" + nb_block + "." + p.getName() + "(" + names.get(i) + ");" + CR; + } else if (((SysCAMSTPortDE) connectors.get(i).get_p1().getComponent()).getName().equals(p.getName()) && ((SysCAMSTPortDE) connectors.get(i).get_p1().getComponent()).getBlockDE().getName().equals(t.getName())) { + corpsCluster = corpsCluster + "\t\t" + t.getName() + "_" + nb_block + "." + p.getName() + "(" + names.get(i) + ");" + CR; + } + } + } + } + corpsCluster = corpsCluster + CR; + nb_block++; + } + + corpsCluster = corpsCluster + "\t}" + CR2; + + /*corpsCluster = corpsCluster + "\t// Configure signal tracing." + CR + + "\tsca_trace_file* tfp = sca_create_tabular_trace_file(\"" + cluster.getClusterName() + "_tb\");" + CR; + + nb_con = 0; + for (int i = 0; i < connectors.size(); i++) { + if ( !((connectors.get(i).get_p1().getComponent() instanceof SysCAMSTPortDE && ((SysCAMSTPortDE) connectors.get(i).get_p1().getComponent()).getBlockGPIO2VCI() != null) + || (connectors.get(i).get_p2().getComponent() instanceof SysCAMSTPortDE && ((SysCAMSTPortDE) connectors.get(i).get_p2().getComponent()).getBlockGPIO2VCI() != null)) ) { + corpsCluster = corpsCluster + "\tsca_trace(tfp, "+ "sig_" + nb_con + ", \"" + "sig_" + nb_con + "\");" + CR; + nb_con++; + } + } + corpsCluster = corpsCluster + CR + "\t// Close trace file and stop simulation to enable clean-up by" + CR + + "\t// asking SystemC to execute all end_of_simulation() callbacks." + CR + + "\tsca_close_tabular_trace_file(tfp);" + CR; + */ + corpsCluster = corpsCluster + "};" + CR2; + corpsCluster = corpsCluster + "#endif // " + cluster.getClusterName().toUpperCase() + "_TDF_H"+ CR; + } else { + corpsCluster = ""; + } + return corpsCluster; + } +} diff --git a/src/main/java/syscamstranslator/toSysCAMSCluster/Header.java b/src/main/java/syscamstranslator/toSysCAMSCluster/Header.java new file mode 100644 index 0000000000..e20067c572 --- /dev/null +++ b/src/main/java/syscamstranslator/toSysCAMSCluster/Header.java @@ -0,0 +1,113 @@ +/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + * Daniela Genius, Lip6, UMR 7606 + * + * ludovic.apvrille AT enst.fr + * daniela.genius@lip6.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. + */ + +/* this class produces the lines containing essentially the initial #includes; we include all potential components event if they are not used in the deployment diagram*/ + +/* authors: v1.0 Raja GATGOUT 2014 + v2.0 Daniela GENIUS, Julien HENON 2015 */ + +package syscamstranslator.toSysCAMSCluster; + +import java.util.LinkedList; + +import syscamstranslator.*; + +/** + * Class Header + * Header of files .h and .cpp + * Creation: 14/05/2018 + * @version 1.0 14/05/2018 + * @author Irina Kit Yan LEE +*/ + +public class Header { + static private String headerPrimitiveTDF; + static private String headerPrimitiveDE; + static private String headerCluster; + + private final static String CR = "\n"; + private final static String CR2 = "\n\n"; + + Header() {} + + public static String getPrimitiveHeaderTDF(SysCAMSTBlockTDF tdf) { + if (tdf != null) { + headerPrimitiveTDF = "#ifndef " + tdf.getName().toUpperCase() + "_TDF_H"+ CR + + "#define " + tdf.getName().toUpperCase() + "_TDF_H" + CR2 + + "#include <cmath>" + CR + "#include <iostream>" + CR + "#include <systemc-ams>" + CR2; + } else { + headerPrimitiveTDF = ""; + } + return headerPrimitiveTDF; + } + + public static String getPrimitiveHeaderDE(SysCAMSTBlockDE de) { + if (de != null) { + headerPrimitiveDE = "#ifndef " + de.getName().toUpperCase() + "_TDF_H"+ CR + + "#define " + de.getName().toUpperCase() + "_TDF_H" + CR2 + + "#include <cmath>" + CR + "#include <iostream>" + CR + "#include <systemc>" + CR2; + } else { + headerPrimitiveDE = ""; + } + return headerPrimitiveDE; + } + + public static String getClusterHeader(SysCAMSTCluster cluster) { + if (cluster != null) { + LinkedList<SysCAMSTBlockTDF> tdf = cluster.getBlockTDF(); + LinkedList<SysCAMSTBlockDE> de = cluster.getBlockDE(); + + headerCluster = "#ifndef " + cluster.getClusterName().toUpperCase() + "_TDF_H"+ CR + + "#define " + cluster.getClusterName().toUpperCase() + "_TDF_H" + CR2; + headerCluster += "#include <systemc-ams>" + CR; + + for (SysCAMSTBlockTDF b : tdf) { + headerCluster = headerCluster + "#include \"" + b.getName() + "_tdf.h\"" + CR; + } + for (SysCAMSTBlockDE b : de) { + headerCluster = headerCluster + "#include \"" + b.getName() + "_tdf.h\"" + CR; + } + headerCluster = headerCluster + CR; + } else { + headerCluster = ""; + } + return headerCluster; + } +} \ No newline at end of file diff --git a/src/main/java/syscamstranslator/toSysCAMSCluster/MakefileCode.java b/src/main/java/syscamstranslator/toSysCAMSCluster/MakefileCode.java new file mode 100644 index 0000000000..6080c5e4dd --- /dev/null +++ b/src/main/java/syscamstranslator/toSysCAMSCluster/MakefileCode.java @@ -0,0 +1,113 @@ +/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + * Daniela Genius, Lip6, UMR 7606 + * + * ludovic.apvrille AT enst.fr + * daniela.genius@lip6.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. + */ + +/* this class produces the lines containing essentially the initial #includes; we include all potential components event if they are not used in the deployment diagram*/ + +/* authors: v1.0 Raja GATGOUT 2014 + v2.0 Daniela GENIUS, Julien HENON 2015 */ + +package syscamstranslator.toSysCAMS; + +import java.util.LinkedList; + +import syscamstranslator.*; + +/** + * Class MakefileCode Principal code of a makefile Creation: 02/06/2018 + * + * @version 1.0 02/06/2018 + * @author Irina Kit Yan LEE + */ + +public class MakefileCode { + static private String corpsMakefile; + private final static String CR = "\n"; + private final static String CR2 = "\n\n"; + + MakefileCode() { + } + + public static String getMakefileCode(LinkedList<SysCAMSTCluster> clusters) { + if (clusters != null) { + corpsMakefile = "# Compiler and linker flags" + CR + "CXXFLAGS = -g -Wall -I. $(SYSTEMC_INCLUDE_DIRS)" + CR + + "LDFLAGS = $(SYSTEMC_LIBRARY_DIRS)" + CR2 + "# List of all ecutables to be compiled" + CR + + "EXECUTABLES = "; + + for (int i = 0; i < clusters.size(); i++) { + if (i == 0) { + corpsMakefile = corpsMakefile + clusters.get(i).getClusterName() + "_tb"; + } + if (i > 0) { + corpsMakefile = corpsMakefile + " " + clusters.get(i).getClusterName() + "_tb"; + } + if (i == clusters.size() - 1) { + corpsMakefile = corpsMakefile + CR2; + } + } + + corpsMakefile = corpsMakefile + "# .PHONY targets don't generate files" + CR + ".PHONY: all clean" + CR2 + + "# Default targets" + CR + "all: $(EXECUTABLES)" + CR2; + + for (int i = 0; i < clusters.size(); i++) { + LinkedList<SysCAMSTBlockTDF> tdf = clusters.get(i).getBlockTDF(); + LinkedList<SysCAMSTBlockDE> de = clusters.get(i).getBlockDE(); + + corpsMakefile = corpsMakefile + clusters.get(i).getClusterName() + "_tb: " + + clusters.get(i).getClusterName() + "_tb.cpp"; + + for (SysCAMSTBlockTDF t : tdf) { + corpsMakefile = corpsMakefile + " " + t.getName() + ".h"; + } + + for (SysCAMSTBlockDE t : de) { + corpsMakefile = corpsMakefile + " " + t.getName() + ".h"; + } + corpsMakefile = corpsMakefile + CR + + "\t$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $< -lsystemc-ams -lsystemc | c++filt" + CR2; + } + + corpsMakefile = corpsMakefile + "# Clean rule to delete temporary and generated files" + CR + "clean:" + CR + + "\trm -rf *~ *.o *.dat *.vcd *.dSYM $(EXECUTABLES)" + CR; + } else { + corpsMakefile = ""; + } + return corpsMakefile; + } +} \ No newline at end of file diff --git a/src/main/java/syscamstranslator/toSysCAMSCluster/PrimitiveCode.java b/src/main/java/syscamstranslator/toSysCAMSCluster/PrimitiveCode.java new file mode 100644 index 0000000000..b5bc316143 --- /dev/null +++ b/src/main/java/syscamstranslator/toSysCAMSCluster/PrimitiveCode.java @@ -0,0 +1,605 @@ +/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + * Daniela Genius, Lip6, UMR 7606 + * + * ludovic.apvrille AT enst.fr + * daniela.genius@lip6.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. + */ + +/* this class produces the lines containing essentially the initial #includes; we include all potential components event if they are not used in the deployment diagram*/ + +/* authors: v1.0 Raja GATGOUT 2014 + v2.0 Daniela GENIUS, Julien HENON 2015 */ + +package syscamstranslator.toSysCAMSCluster; + +import java.util.LinkedList; + +import syscamstranslator.*; + +/** + * Class PrimitiveCode + * Principal code of a primive component + * Creation: 14/05/2018 + * @version 1.0 14/05/2018 + * @author Irina Kit Yan LEE + */ + +public class PrimitiveCode { + static private String corpsPrimitiveTDF; + static private String corpsPrimitiveDE; + private final static String CR = "\n"; + private final static String CR2 = "\n\n"; + + PrimitiveCode() {} + + public static String getPrimitiveCodeTDF(SysCAMSTBlockTDF tdf) { + corpsPrimitiveTDF = ""; + + if (tdf != null) { + LinkedList<SysCAMSTPortTDF> tdfports = tdf.getPortTDF(); + LinkedList<SysCAMSTPortConverter> convports = tdf.getPortConverter(); + int cpt = 0; + int cpt2 = 0; + + if ((!tdf.getTypeTemplate().equals("")) && (!tdf.getNameTemplate().equals(""))) { + corpsPrimitiveTDF = corpsPrimitiveTDF + "template<" + tdf.getTypeTemplate() + " " + tdf.getNameTemplate() + ">" + CR; + } + //corpsPrimitive = "SCA_TDF_MODULE(" + tdf.getName() + ") {" + CR2; + corpsPrimitiveTDF = corpsPrimitiveTDF + "class " + tdf.getName() + " : public sca_tdf::sca_module {" + CR2 + "public:" + CR; + + if (!tdf.getListTypedef().isEmpty()) { + for (int i = 0; i < tdf.getListTypedef().getSize(); i++) { + String select = tdf.getListTypedef().get(i); + String[] split = select.split(" : "); + corpsPrimitiveTDF = corpsPrimitiveTDF + "\ttypedef " + split[1] + "<" + tdf.getNameTemplate() + "> " + split[0] + ";" + CR; + if (i == tdf.getListTypedef().getSize()-1) { + corpsPrimitiveTDF = corpsPrimitiveTDF + CR; + } + } + } + + if (tdf.getListStruct().getSize() != 0) { + corpsPrimitiveTDF = corpsPrimitiveTDF + "\tstruct parameters {" + CR; + + String identifier, value, type; + for (int i = 0; i < tdf.getListStruct().size(); i++) { + String select = tdf.getListStruct().get(i); + String[] splita = select.split(" = "); + identifier = splita[0]; + String[] splitb = splita[1].split(" : "); + value = splitb[0]; + String[] splitc = splitb[1].split(" "); + if (splitc[0].equals("const")) { + type = splitc[1]; + } else { + type = splitc[0]; + } + corpsPrimitiveTDF = corpsPrimitiveTDF + "\t\t" + type + " " + identifier + ";" + CR; + } + + corpsPrimitiveTDF = corpsPrimitiveTDF + "\t\tparameters()" + CR; + + for (int i = 0; i < tdf.getListStruct().size(); i++) { + String select = tdf.getListStruct().get(i); + String[] splita = select.split(" = "); + identifier = splita[0]; + String[] splitb = splita[1].split(" : "); + value = splitb[0]; + String[] splitc = splitb[1].split(" "); + if (splitc[0].equals("const")) { + type = splitc[1]; + } else { + type = splitc[0]; + } + if (i == 0) { + corpsPrimitiveTDF = corpsPrimitiveTDF + "\t\t: " + identifier + "(" + value + ")" + CR; + } + if ((i > 0) && (i < tdf.getListStruct().getSize()-1)) { + corpsPrimitiveTDF = corpsPrimitiveTDF + "\t\t, " + identifier + "(" + value + ")" + CR; + } + if (i == tdf.getListStruct().getSize()-1 && i != 0) { + corpsPrimitiveTDF = corpsPrimitiveTDF + "\t\t, " + identifier + "(" + value + ")" + CR + "\t\t{}" + CR; + } else { + corpsPrimitiveTDF = corpsPrimitiveTDF + "\t\t{}" + CR; + } + } + corpsPrimitiveTDF = corpsPrimitiveTDF + "\t};" + CR2; + } + + if (!tdfports.isEmpty()) { + for (SysCAMSTPortTDF t : tdfports) { + if (t.getOrigin() == 0) { + corpsPrimitiveTDF = corpsPrimitiveTDF + "\tsca_tdf::sca_in< " + t.getTDFType() + " > " + t.getName() + ";" + CR; + } else if (t.getOrigin() == 1) { + corpsPrimitiveTDF = corpsPrimitiveTDF + "\tsca_tdf::sca_out< " + t.getTDFType() + " > " + t.getName() + ";" + CR; + } + } + } + if (!convports.isEmpty()) { + for (SysCAMSTPortConverter conv : convports) { + if (conv.getOrigin() == 0) { + corpsPrimitiveTDF = corpsPrimitiveTDF + "\tsca_tdf::sca_de::sca_in< " + conv.getConvType() + " > " + conv.getName() + ";" + CR; + } else if (conv.getOrigin() == 1) { + corpsPrimitiveTDF = corpsPrimitiveTDF + "\tsca_tdf::sca_de::sca_out< " + conv.getConvType() + " > " + conv.getName() + ";" + CR; + } + } + } + + //corpsPrimitive = corpsPrimitive + CR + "\t// Constructor" + CR + "\tSCA_CTOR(" + tdf.getName() + ")" + CR; + corpsPrimitiveTDF = corpsPrimitiveTDF + CR + "\texplicit " + tdf.getName() + "(sc_core::sc_module_name nm"; + + if (tdf.getListStruct().getSize() != 0) { + corpsPrimitiveTDF = corpsPrimitiveTDF + ", const parameters& p = parameters())" + CR; + } else { + corpsPrimitiveTDF = corpsPrimitiveTDF + ")" + CR; + } + + if (!tdfports.isEmpty() || !convports.isEmpty() || !tdf.getListStruct().isEmpty()) { + corpsPrimitiveTDF = corpsPrimitiveTDF + "\t: "; + if (!tdfports.isEmpty()) { + for (int i = 0; i < tdfports.size(); i++) { + if (tdfports.size() >= 1) { + if (cpt == 0) { + corpsPrimitiveTDF = corpsPrimitiveTDF + tdfports.get(i).getName() + "(\"" + tdfports.get(i).getName() + "\")" + CR; + cpt++; + } else { + corpsPrimitiveTDF = corpsPrimitiveTDF + "\t, " + tdfports.get(i).getName() + "(\"" + tdfports.get(i).getName() + "\")" + CR; + } + } else { + corpsPrimitiveTDF = corpsPrimitiveTDF + tdfports.get(i).getName() + "(\"" + tdfports.get(i).getName() + "\")" + CR; + cpt++; + } + } + } + if (!convports.isEmpty()) { + for (int i = 0; i < convports.size(); i++) { + if (convports.size() >= 1) { + if (cpt == 0) { + corpsPrimitiveTDF = corpsPrimitiveTDF + convports.get(i).getName() + "(\"" + convports.get(i).getName() + "\")" + CR; + cpt++; + } else { + corpsPrimitiveTDF = corpsPrimitiveTDF + "\t, " + convports.get(i).getName() + "(\"" + convports.get(i).getName() + "\")" + CR; + } + } else { + corpsPrimitiveTDF = corpsPrimitiveTDF + convports.get(i).getName() + "(\"" + convports.get(i).getName() + "\")" + CR; + cpt++; + } + } + } + String identifier; + if (!tdf.getListStruct().isEmpty()) { + for (int i = 0; i < tdf.getListStruct().size(); i++) { + String select = tdf.getListStruct().get(i); + String[] splita = select.split(" = "); + identifier = splita[0]; + if (tdf.getListStruct().getSize() >= 1) { + if (cpt == 0) { + corpsPrimitiveTDF = corpsPrimitiveTDF + identifier + "(p." + identifier + ")" + CR; + cpt++; + } else { + corpsPrimitiveTDF = corpsPrimitiveTDF + "\t, " + identifier + "(p." + identifier + ")" + CR; + } + } else { + corpsPrimitiveTDF = corpsPrimitiveTDF + identifier + "(p." + identifier + ")" + CR; + cpt++; + } + } + } + corpsPrimitiveTDF = corpsPrimitiveTDF + "\t{}" + CR2 + "protected:" + CR; + } + + if (tdf.getPeriod() != -1) { + corpsPrimitiveTDF = corpsPrimitiveTDF + "\tvoid set_attributes() {" + CR + "\t\t" + "set_timestep(" + tdf.getPeriod() + ", sc_core::SC_" + tdf.getTime().toUpperCase() + ");" + CR; + cpt2++; + } + if (cpt2 > 0) { + for (SysCAMSTPortTDF t : tdfports) { + if (t.getPeriod() != -1) { + corpsPrimitiveTDF = corpsPrimitiveTDF + "\t\t" + t.getName() + ".set_timestep(" + t.getPeriod() + ", sc_core::SC_" + t.getTime().toUpperCase() + ");" + CR; + } + if (t.getRate() != -1) { + corpsPrimitiveTDF = corpsPrimitiveTDF + "\t\t" + t.getName() + ".set_rate(" + t.getRate() + ");" + CR; + } + if (t.getDelay() != -1) { + corpsPrimitiveTDF = corpsPrimitiveTDF + "\t\t" + t.getName() + ".set_delay(" + t.getDelay() + ");" + CR; + } + } + } else { + for (SysCAMSTPortTDF t : tdfports) { + if (t.getPeriod() != -1) { + if (cpt2 == 0) { + corpsPrimitiveTDF = corpsPrimitiveTDF + "\tvoid set_attributes() {" + CR + "\t\t" + t.getName() + ".set_timestep(" + t.getPeriod() + ", sc_core::SC_" + t.getTime().toUpperCase() + ");" + CR; + cpt2++; + } else { + corpsPrimitiveTDF = corpsPrimitiveTDF + "\t\t" + t.getName() + ".set_timestep(" + t.getPeriod() + ", sc_core::SC_" + t.getTime().toUpperCase() + ");" + CR; + } + } + if (t.getRate() != -1) { + if (cpt2 == 0) { + corpsPrimitiveTDF = corpsPrimitiveTDF + "\tvoid set_attributes() {" + CR + "\t\t" + t.getName() + ".set_rate(" + t.getRate() + ");" + CR; + cpt2++; + } else { + corpsPrimitiveTDF = corpsPrimitiveTDF + "\t\t" + t.getName() + ".set_rate(" + t.getRate() + ");" + CR; + } + } + if (t.getDelay() != -1) { + if (cpt2 == 0) { + corpsPrimitiveTDF = corpsPrimitiveTDF + "\tvoid set_attributes() {" + CR + "\t\t" + t.getName() + ".set_delay(" + t.getDelay() + ");" + CR; + cpt2++; + } else { + corpsPrimitiveTDF = corpsPrimitiveTDF + "\t\t" + t.getName() + ".set_delay(" + t.getDelay() + ");" + CR; + } + } + } + } + if (cpt2 > 0) { + for (SysCAMSTPortConverter t : convports) { + if (t.getPeriod() != -1) { + corpsPrimitiveTDF = corpsPrimitiveTDF + "\t\t" + t.getName() + ".set_timestep(" + t.getPeriod() + ", sc_core::SC_" + t.getTime().toUpperCase() + ");" + CR; + } + if (t.getRate() != -1) { + corpsPrimitiveTDF = corpsPrimitiveTDF + "\t\t" + t.getName() + ".set_rate(" + t.getRate() + ");" + CR; + } + if (t.getDelay() != -1) { + corpsPrimitiveTDF = corpsPrimitiveTDF + "\t\t" + t.getName() + ".set_delay(" + t.getDelay() + ");" + CR; + } + } + } else { + for (SysCAMSTPortConverter t : convports) { + if (t.getPeriod() != -1) { + if (cpt2 == 0) { + corpsPrimitiveTDF = corpsPrimitiveTDF + "\tvoid set_attributes() {" + CR + "\t\t" + t.getName() + ".set_timestep(" + t.getPeriod() + ", sc_core::SC_" + t.getTime().toUpperCase() + ");" + CR; + cpt2++; + } else { + corpsPrimitiveTDF = corpsPrimitiveTDF + "\t\t" + t.getName() + ".set_timestep(" + t.getPeriod() + ", sc_core::SC_" + t.getTime().toUpperCase() + ");" + CR; + } + } + if (t.getRate() != -1 && cpt2 == 0) { + if (cpt2 == 0) { + corpsPrimitiveTDF = corpsPrimitiveTDF + "\tvoid set_attributes() {" + CR + "\t\t" + t.getName() + ".set_rate(" + t.getRate() + ");" + CR; + cpt2++; + } else { + corpsPrimitiveTDF = corpsPrimitiveTDF + "\t\t" + t.getName() + ".set_rate(" + t.getRate() + ");" + CR; + } + } + if (t.getDelay() != -1 && cpt2 == 0) { + if (cpt2 == 0) { + corpsPrimitiveTDF = corpsPrimitiveTDF + "\tvoid set_attributes() {" + CR + "\t\t" + t.getName() + ".set_delay(" + t.getDelay() + ");" + CR; + cpt2++; + } else { + corpsPrimitiveTDF = corpsPrimitiveTDF + "\t\t" + t.getName() + ".set_delay(" + t.getDelay() + ");" + CR; + } + } + } + } + + if (cpt2 > 0) { + corpsPrimitiveTDF = corpsPrimitiveTDF + "\t}" + CR2; + } + + StringBuffer pcbuf = new StringBuffer(tdf.getProcessCode()); + StringBuffer buffer = new StringBuffer(""); + int tab = 0; + int begin = 0; + + for(int pos = 0; pos != tdf.getProcessCode().length(); pos++) { + char c = pcbuf.charAt(pos); + switch(c) { + case '\t': + begin = 1; + tab++; + break; + default: + if (begin == 1) { + int i = tab; + while (i >= 0) { + buffer.append("\t"); + i--; + } + buffer.append(pcbuf.charAt(pos)); + begin = 0; + tab = 0; + } else { + if (c == '}') { + buffer.append("\t"); + } + buffer.append(pcbuf.charAt(pos)); + } + break; + } + } + + String pc = buffer.toString(); + + corpsPrimitiveTDF = corpsPrimitiveTDF + "\t" + pc + CR; + + if (tdf.getListStruct().getSize() != 0) { + corpsPrimitiveTDF = corpsPrimitiveTDF + "private:" + CR; + + String identifier, type, constant; + for (int i = 0; i < tdf.getListStruct().size(); i++) { + String select = tdf.getListStruct().get(i); + String[] splita = select.split(" = "); + identifier = splita[0]; + String[] splitb = splita[1].split(" : "); + String[] splitc = splitb[1].split(" "); + if (splitc[0].equals("const")) { + constant = splitc[0]; + type = splitc[1]; + } else { + constant = ""; + type = splitc[0]; + } + if (constant.equals("")) { + corpsPrimitiveTDF = corpsPrimitiveTDF + "\t" + type + " " + identifier + ";" + CR; + } else { + corpsPrimitiveTDF = corpsPrimitiveTDF + "\t" + constant + " " + type + " " + identifier + ";" + CR; + } + } + } + corpsPrimitiveTDF = corpsPrimitiveTDF + "};" + CR2 + "#endif" + " // " + tdf.getName().toUpperCase() + "_TDF_H"; + } else { + corpsPrimitiveTDF = ""; + } + return corpsPrimitiveTDF; + } + + public static String getPrimitiveCodeDE(SysCAMSTBlockDE de) { + corpsPrimitiveDE = ""; + + if (de != null) { + LinkedList<SysCAMSTPortDE> deports = de.getPortDE(); + int cpt = 0; + int cpt2 = 0; + + if ((!de.getTypeTemplate().equals("")) && (!de.getNameTemplate().equals(""))) { + corpsPrimitiveDE = corpsPrimitiveDE + "template<" + de.getTypeTemplate() + " " + de.getNameTemplate() + ">" + CR; + } + //corpsPrimitive = "SCA_TDF_MODULE(" + de.getName() + ") {" + CR2; + corpsPrimitiveDE = corpsPrimitiveDE + "class " + de.getName() + " : public sca_core::sca_module {" + CR2 + "public:" + CR; + + if (!de.getListTypedef().isEmpty()) { + for (int i = 0; i < de.getListTypedef().getSize(); i++) { + String select = de.getListTypedef().get(i); + String[] split = select.split(" : "); + corpsPrimitiveDE = corpsPrimitiveDE + "\ttypedef " + split[1] + "<" + de.getNameTemplate() + "> " + split[0] + ";" + CR; + if (i == de.getListTypedef().getSize()-1) { + corpsPrimitiveDE = corpsPrimitiveDE + CR; + } + } + } + + if (de.getListStruct().getSize() != 0) { + corpsPrimitiveDE = corpsPrimitiveDE + "\tstruct parameters {" + CR; + + String identifier, value, type; + for (int i = 0; i < de.getListStruct().size(); i++) { + String select = de.getListStruct().get(i); + String[] splita = select.split(" = "); + identifier = splita[0]; + String[] splitb = splita[1].split(" : "); + value = splitb[0]; + String[] splitc = splitb[1].split(" "); + if (splitc[0].equals("const")) { + type = splitc[1]; + } else { + type = splitc[0]; + } + corpsPrimitiveDE = corpsPrimitiveDE + "\t\t" + type + " " + identifier + ";" + CR; + } + + corpsPrimitiveDE = corpsPrimitiveDE + "\t\tparameters()" + CR; + + for (int i = 0; i < de.getListStruct().size(); i++) { + String select = de.getListStruct().get(i); + String[] splita = select.split(" = "); + identifier = splita[0]; + String[] splitb = splita[1].split(" : "); + value = splitb[0]; + String[] splitc = splitb[1].split(" "); + if (splitc[0].equals("const")) { + type = splitc[1]; + } else { + type = splitc[0]; + } + if (i == 0) { + corpsPrimitiveDE = corpsPrimitiveDE + "\t\t: " + identifier + "(" + value + ")" + CR; + } + if ((i > 0) && (i < de.getListStruct().getSize()-1)) { + corpsPrimitiveDE = corpsPrimitiveDE + "\t\t, " + identifier + "(" + value + ")" + CR; + } + if (i == de.getListStruct().getSize()-1 && i != 0) { + corpsPrimitiveDE = corpsPrimitiveDE + "\t\t, " + identifier + "(" + value + ")" + CR + "\t\t{}" + CR; + } else { + corpsPrimitiveDE = corpsPrimitiveDE + "\t\t{}" + CR; + } + } + corpsPrimitiveDE = corpsPrimitiveDE + "\t};" + CR2; + } + + if (!deports.isEmpty()) { + for (SysCAMSTPortDE t : deports) { + if (t.getOrigin() == 0) { + corpsPrimitiveDE = corpsPrimitiveDE + "\tsca_core::sca_in<" + t.getDEType() + "> " + t.getName() + ";" + CR; + } else if (t.getOrigin() == 1) { + corpsPrimitiveDE = corpsPrimitiveDE + "\tsca_core::sca_out<" + t.getDEType() + "> " + t.getName() + ";" + CR; + } + } + } + + corpsPrimitiveDE = corpsPrimitiveDE + CR + "\tSC_HAS_PROCESS(" + de.getName() + ");" + CR + + "\texplicit " + de.getName() + "(sc_core::sc_module_name nm"; + + if (de.getListStruct().getSize() != 0) { + corpsPrimitiveDE = corpsPrimitiveDE + ", const parameters& p = parameters())" + CR; + } else { + corpsPrimitiveDE = corpsPrimitiveDE + ")" + CR; + } + + if (!deports.isEmpty() || !de.getListStruct().isEmpty()) { + corpsPrimitiveDE = corpsPrimitiveDE + "\t: "; + if (!deports.isEmpty()) { + for (int i = 0; i < deports.size(); i++) { + if (deports.size() >= 1) { + if (cpt == 0) { + corpsPrimitiveDE = corpsPrimitiveDE + deports.get(i).getName() + "(\"" + deports.get(i).getName() + "\")" + CR; + cpt++; + } else { + corpsPrimitiveDE = corpsPrimitiveDE + "\t, " + deports.get(i).getName() + "(\"" + deports.get(i).getName() + "\")" + CR; + } + } else { + corpsPrimitiveDE = corpsPrimitiveDE + deports.get(i).getName() + "(\"" + deports.get(i).getName() + "\")" + CR; + cpt++; + } + } + } + String identifier; + if (!de.getListStruct().isEmpty()) { + for (int i = 0; i < de.getListStruct().size(); i++) { + String select = de.getListStruct().get(i); + String[] splita = select.split(" = "); + identifier = splita[0]; + if (de.getListStruct().getSize() >= 1) { + if (cpt == 0) { + corpsPrimitiveDE = corpsPrimitiveDE + identifier + "(p." + identifier + ")" + CR; + cpt++; + } else { + corpsPrimitiveDE = corpsPrimitiveDE + "\t, " + identifier + "(p." + identifier + ")" + CR; + } + } else { + corpsPrimitiveDE = corpsPrimitiveDE + identifier + "(p." + identifier + ")" + CR; + cpt++; + } + } + } + } + + boolean sensitive = false, method = false; + if (!de.getCode().equals("")) { + corpsPrimitiveDE = corpsPrimitiveDE + "\t{" + CR + "\t\tSC_METHOD(" + de.getNameFn() + ");" + CR; + method = true; + } + + for (SysCAMSTPortDE t : deports) { + if (t.getSensitive() == true) { + if (method == false) { + corpsPrimitiveDE = corpsPrimitiveDE + "\t{" + CR; + } + corpsPrimitiveDE = corpsPrimitiveDE + "\t\tsensitive << " + t.getName() + "."; + if (t.getSensitiveMethod().equals("positive")) { + corpsPrimitiveDE = corpsPrimitiveDE + "pos();" + CR; + } else if (t.getSensitiveMethod().equals("negative")) { + corpsPrimitiveDE = corpsPrimitiveDE + "neg();" + CR; + } + sensitive = true; + } + } + if (sensitive == true || method == true) { + corpsPrimitiveDE = corpsPrimitiveDE + "\t}" + CR2; + } else { + corpsPrimitiveDE = corpsPrimitiveDE + "\t{}" + CR2; + } + + corpsPrimitiveDE = corpsPrimitiveDE + "private:" + CR; + + if (de.getListStruct().getSize() != 0) { + String identifier, type, constant; + for (int i = 0; i < de.getListStruct().size(); i++) { + String select = de.getListStruct().get(i); + String[] splita = select.split(" = "); + identifier = splita[0]; + String[] splitb = splita[1].split(" : "); + String[] splitc = splitb[1].split(" "); + if (splitc[0].equals("const")) { + constant = splitc[0]; + type = splitc[1]; + } else { + constant = ""; + type = splitc[0]; + } + if (constant.equals("")) { + corpsPrimitiveDE = corpsPrimitiveDE + "\t" + type + " " + identifier + ";" + CR; + } else { + corpsPrimitiveDE = corpsPrimitiveDE + "\t" + constant + " " + type + " " + identifier + ";" + CR; + } + if (i == de.getListStruct().size()-1) { + corpsPrimitiveDE = corpsPrimitiveDE + CR; + } + } + } + + StringBuffer pcbuf = new StringBuffer(de.getCode()); + StringBuffer buffer = new StringBuffer(""); + int tab = 0; + int begin = 0; + + for(int pos = 0; pos != de.getCode().length(); pos++) { + char c = pcbuf.charAt(pos); + switch(c) { + case '\t': + begin = 1; + tab++; + break; + default: + if (begin == 1) { + int i = tab; + while (i >= 0) { + buffer.append("\t"); + i--; + } + buffer.append(pcbuf.charAt(pos)); + begin = 0; + tab = 0; + } else { + if (c == '}') { + buffer.append("\t"); + } + buffer.append(pcbuf.charAt(pos)); + } + break; + } + } + + String pc = buffer.toString(); + corpsPrimitiveDE = corpsPrimitiveDE + "\t" + pc; + + corpsPrimitiveDE = corpsPrimitiveDE + CR + "};" + CR2 + "#endif" + " // " + de.getName().toUpperCase() + "_TDF_H"; + } else { + corpsPrimitiveDE = ""; + } + return corpsPrimitiveDE; + } +} \ No newline at end of file diff --git a/src/main/java/syscamstranslator/toSysCAMSCluster/TopCellGeneratorCluster.java b/src/main/java/syscamstranslator/toSysCAMSCluster/TopCellGeneratorCluster.java new file mode 100644 index 0000000000..fb6dfac0f6 --- /dev/null +++ b/src/main/java/syscamstranslator/toSysCAMSCluster/TopCellGeneratorCluster.java @@ -0,0 +1,149 @@ +/**Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + Daniela Genius, Lip6, UMR 7606 + + ludovic.apvrille AT enst.fr + daniela.genius@lip6.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. +*/ + +/* Generator of the top cell for simulation with SoCLib virtual component + library */ + +/* authors: v1.0 Raja GATGOUT 2014 + v2.0 Daniela GENIUS, Julien HENON 2015 */ + +package syscamstranslator.toSysCAMSCluster; + +import syscamstranslator.*; +import java.io.*; +import java.util.LinkedList; + +/** + * Class TopCellGeneratorCluster + * Save the components and connectors in files + * Creation: 14/05/2018 + * @version 1.0 14/05/2018 + * @author Irina Kit Yan LEE +*/ + +public class TopCellGeneratorCluster { + public static SysCAMSSpecification syscams; + + private final static String GENERATED_PATH1 = "generated_CPP" + File.separator; + private final static String GENERATED_PATH2 = "generated_H" + File.separator; + + public TopCellGeneratorCluster(SysCAMSSpecification sys) { + syscams = sys; + } + + public String generateTopCell(SysCAMSTCluster c, LinkedList<SysCAMSTConnector> connectors) { + if (c == null) { + System.out.println("***Warning: require at least one cluster***"); + } + if (TopCellGeneratorCluster.syscams.getNbBlockTDF() == 0) { + System.out.println("***Warning: require at least one TDF block***"); + } + if (TopCellGeneratorCluster.syscams.getNbPortTDF() == 0) { + System.out.println("***Warning: require at least one TDF port***"); + } + if (TopCellGeneratorCluster.syscams.getNbBlockDE() == 0) { + System.out.println("***Warning: require at least one DE block***"); + } + if (TopCellGeneratorCluster.syscams.getNbPortDE() == 0) { + System.out.println("***Warning: require at least one DE port***"); + } + if (TopCellGeneratorCluster.syscams.getNbPortConverter() == 0) { + System.out.println("***Warning: require at least one converter port***"); + } + if (TopCellGeneratorCluster.syscams.getNbConnectorCluster() == 0) { + System.out.println("***Warning: require at least one connector***"); + } + String top = Header.getClusterHeader(c) + ClusterCode.getClusterCode(c, connectors); + return (top); + } + + public void saveFile(String path) { + SysCAMSTCluster cluster = TopCellGeneratorCluster.syscams.getCluster(); + LinkedList<SysCAMSTConnector> connectors = TopCellGeneratorCluster.syscams.getAllConnectorCluster(); + + String top; + + try { + // Save file .cpp + System.err.println(path + GENERATED_PATH1 + cluster.getClusterName() + "_tdf.h"); + FileWriter fw = new FileWriter(path + GENERATED_PATH1 + "/" + cluster.getClusterName() + "_tdf.h"); + top = generateTopCell(cluster, connectors); + fw.write(top); + fw.close(); + } catch (Exception ex) { + ex.printStackTrace(); + } + // Save files .h + saveFileBlock(path, cluster); + } + + public void saveFileBlock(String path, SysCAMSTCluster c) { + String headerTDF, headerDE, codeTDF, codeDE; + LinkedList<SysCAMSTBlockTDF> tdf = c.getBlockTDF(); + LinkedList<SysCAMSTBlockDE> de = c.getBlockDE(); + + for (SysCAMSTBlockTDF t : tdf) { + try { + System.err.println(path + GENERATED_PATH2 + t.getName() + "_tdf.h"); + FileWriter fw = new FileWriter(path + GENERATED_PATH2 + "/" + t.getName() + "_tdf.h"); + headerTDF = Header.getPrimitiveHeaderTDF(t); + fw.write(headerTDF); + codeTDF = PrimitiveCode.getPrimitiveCodeTDF(t); + fw.write(codeTDF); + fw.close(); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + for (SysCAMSTBlockDE t : de) { + try { + System.err.println(path + GENERATED_PATH2 + t.getName() + "_tdf.h"); + FileWriter fw = new FileWriter(path + GENERATED_PATH2 + "/" + t.getName() + "_tdf.h"); + headerDE = Header.getPrimitiveHeaderDE(t); + fw.write(headerDE); + codeDE = PrimitiveCode.getPrimitiveCodeDE(t); + fw.write(codeDE); + fw.close(); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + } +} \ No newline at end of file diff --git a/src/main/java/ui/window/JDialogSysCAMSExecutableCodeGeneration.java b/src/main/java/ui/window/JDialogSysCAMSExecutableCodeGeneration.java index b87a16a335..f207d6f395 100644 --- a/src/main/java/ui/window/JDialogSysCAMSExecutableCodeGeneration.java +++ b/src/main/java/ui/window/JDialogSysCAMSExecutableCodeGeneration.java @@ -40,6 +40,7 @@ package ui.window; import syscamstranslator.toSysCAMS.MakefileCode; import syscamstranslator.toSysCAMS.TopCellGenerator; +import syscamstranslator.toSysCAMSCluster.TopCellGeneratorCluster; import launcher.LauncherException; import launcher.RshClient; import myutil.*; @@ -523,6 +524,7 @@ public class JDialogSysCAMSExecutableCodeGeneration extends javax.swing.JFrame i System.err.println("**SYSCAMS TOPCELL found"); TopCellGenerator topCellGenerator = new TopCellGenerator(syscalsspec); + TopCellGeneratorCluster topCellGeneratorCluster = new TopCellGeneratorCluster(syscalsspec); testGo(); jta.append("Generation of TopCell \"" + syscalsspec.getCluster().getClusterName() + "\" executable code: done\n"); @@ -533,6 +535,7 @@ public class JDialogSysCAMSExecutableCodeGeneration extends javax.swing.JFrame i System.err.println("SYSCAMS TOPCELL : " + syscalsspec.getCluster().getClusterName() + "saved in " + code2.getText()); topCellGenerator.saveFile(pathCode); + topCellGeneratorCluster.saveFile(pathCode); jta.append("Code saved\n"); } catch (Exception e) { -- GitLab