From 2c21e581ced7abbffbe04722899ec4b16198ca63 Mon Sep 17 00:00:00 2001 From: Etudiant Master SESI <irina.lee@etu.upmc.fr> Date: Sat, 26 May 2018 14:52:54 +0200 Subject: [PATCH] add new files --- .../toSysCAMS/ClusterCode.java | 131 ++++++++++++++++ .../syscamstranslator/toSysCAMS/Header.java | 15 +- .../toSysCAMS/PrimitiveCode.java | 147 +++++++++++------- .../toSysCAMS/TopCellGenerator.java | 117 ++++++-------- 4 files changed, 277 insertions(+), 133 deletions(-) create mode 100644 src/main/java/syscamstranslator/toSysCAMS/ClusterCode.java diff --git a/src/main/java/syscamstranslator/toSysCAMS/ClusterCode.java b/src/main/java/syscamstranslator/toSysCAMS/ClusterCode.java new file mode 100644 index 0000000000..75f2705f69 --- /dev/null +++ b/src/main/java/syscamstranslator/toSysCAMS/ClusterCode.java @@ -0,0 +1,131 @@ +/* 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 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 = 1; + int nb_block = 1; + + if (cluster != null) { + LinkedList<SysCAMSTBlockTDF> tdf = cluster.getBlockTDF(); + + corpsCluster = "// Simulation entry point." + CR + "int sc_main(int argc, char *argv[]) {" + CR2 + + "\tusing namespace sc_core;" + CR + "\tusing namespace sca_util;" + CR2; + + corpsCluster = corpsCluster + "\t// Declare signal to interconnect." + CR; + + for (SysCAMSTConnector c : connectors) { + corpsCluster = corpsCluster + "\tsca_tdf::sca_signal<" + ((SysCAMSTPortTDF) c.get_p1().getComponent()).getTDFType() + "> " + + "sig_" + nb_con + "(\"" + + "sig_" + nb_con + "\");" + CR; + nb_con++; + } + + corpsCluster = corpsCluster + CR + "\t// Instantiate source and sink as well as bind their ports to the signal." + CR; + + for (SysCAMSTBlockTDF t : tdf) { + corpsCluster = corpsCluster + "\t" + t.getName() + " " + t.getName() + "_" + nb_block + "(\"" + t.getName() + "_" + nb_block + "\");" + CR; + + LinkedList<SysCAMSTPortTDF> port = t.getPortTDF(); + for (SysCAMSTPortTDF p : port) { + corpsCluster = corpsCluster + "\t" + t.getName() + "_" + nb_block + "." + p.getName() + "("; + for (int i = 0; i < connectors.size(); i++) { + nb_con = i+1; + if (((SysCAMSTPortTDF) connectors.get(i).get_p1().getComponent()).getName().equals(p.getName())) { + corpsCluster = corpsCluster + "sig_" + nb_con + ");" + CR; + } else if (((SysCAMSTPortTDF) connectors.get(i).get_p2().getComponent()).getName().equals(p.getName())) { + corpsCluster = corpsCluster + "sig_" + nb_con + ");" + CR; + } + } + } + corpsCluster = corpsCluster + CR; + nb_block++; + } + + String filename = ""; + for (int i = 0; i < tdf.size(); i++) { + filename = filename + tdf.get(i).getName() + "_"; + } + filename = filename + "tb"; + + corpsCluster = corpsCluster + "\t// Configure signal tracing." + CR + + "\tsca_trace_file* tfp = sca_create_tabular_trace_file(\"" + filename +"\");" + CR; + + nb_con = 1; + for (int i = 0; i < connectors.size(); i++) { + corpsCluster = corpsCluster + "\tsca_trace(tfp, "+ "sig_" + nb_con + ", \"" + "sig_" + nb_con + "\");"; + nb_con++; + } + corpsCluster = corpsCluster + CR2 + "\t// Start simulation." + CR + "\tsc_start(100.0, SC_MS);" + CR2 + + "\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 + + "\tsc_stop();" + CR + "\treturn 0;" + CR + "}" + CR2; + } else { + corpsCluster = ""; + } + return corpsCluster; + } +} \ No newline at end of file diff --git a/src/main/java/syscamstranslator/toSysCAMS/Header.java b/src/main/java/syscamstranslator/toSysCAMS/Header.java index a8fe2e4d8c..7849d28a96 100644 --- a/src/main/java/syscamstranslator/toSysCAMS/Header.java +++ b/src/main/java/syscamstranslator/toSysCAMS/Header.java @@ -45,10 +45,9 @@ package syscamstranslator.toSysCAMS; -import java.util.List; +import java.util.LinkedList; import syscamstranslator.*; -import ui.syscams.SysCAMSBlockTDF; /** * Class Header @@ -68,9 +67,8 @@ public class Header { public static String getPrimitiveHeader(SysCAMSTBlockTDF tdf) { if (tdf != null) { - headerPrimitive = "//-------------------------------Header------------------------------------" + CR2 - + "#ifndef " + tdf.getBlockTDFName().toUpperCase() + "_H"+ CR - + "#define " + tdf.getBlockTDFName().toUpperCase() + "_H" + CR2 + headerPrimitive = "#ifndef " + tdf.getName().toUpperCase() + "_H"+ CR + + "#define " + tdf.getName().toUpperCase() + "_H" + CR2 + "#include <cmath>" + CR + "#include <iostream>" + CR + "#include <systemc-ams>" + CR2; } else { headerPrimitive = ""; @@ -80,13 +78,12 @@ public class Header { public static String getClusterHeader(SysCAMSTCluster cluster) { if (cluster != null) { - LinkedList<SysCAMSTBlockTDF> blocks = cluster.getTDFBlocks(); + LinkedList<SysCAMSTBlockTDF> blocks = cluster.getBlockTDF(); - headerCluster = "//-------------------------------Header------------------------------------" + CR2 - + "#include <systemc-ams>" + CR2; + headerCluster = "#include <systemc-ams>" + CR; for (SysCAMSTBlockTDF b : blocks) { - headerCluster = headerCluster + "#include \"" + b.getTDFname() + ".h\"" + CR; + headerCluster = headerCluster + "#include \"" + b.getName() + ".h\"" + CR; } headerCluster = headerCluster + CR; } else { diff --git a/src/main/java/syscamstranslator/toSysCAMS/PrimitiveCode.java b/src/main/java/syscamstranslator/toSysCAMS/PrimitiveCode.java index f3fb9282da..c7d3bf4ac2 100644 --- a/src/main/java/syscamstranslator/toSysCAMS/PrimitiveCode.java +++ b/src/main/java/syscamstranslator/toSysCAMS/PrimitiveCode.java @@ -45,115 +45,148 @@ package syscamstranslator.toSysCAMS; -import java.util.List; +import java.util.LinkedList; import syscamstranslator.*; -import ui.syscams.SysCAMSBlockTDF; -import ui.syscams.SysCAMSPortConverter; -import ui.syscams.SysCAMSPortTDF; /** * Class PrimitiveCode - * Code of the TDF blocks for files .h + * Principal code of a primive component * Creation: 14/05/2018 * @version 1.0 14/05/2018 * @author Irina Kit Yan LEE */ public class PrimitiveCode { - private String corpsPrimitive; - private String corpsCluster; + static private String corpsPrimitive; private final static String CR = "\n"; private final static String CR2 = "\n\n"; PrimitiveCode() {} - public static String getPrimitiveCorps(SysCAMSTBlockTDF tdf) { + public static String getPrimitiveCode(SysCAMSTBlockTDF tdf) { if (tdf != null) { - List<SysCAMSPortTDF> tdfports = tdf.getTdfports(); - List<SysCAMSPortConverter> convports = tdf.getConvports(); + LinkedList<SysCAMSTPortTDF> tdfports = tdf.getPortTDF(); + LinkedList<SysCAMSTPortConverter> convports = tdf.getPortConverter(); + int cpt = 0; + int cpt2 = 0; - corpsPrimitive = "//-------------------------------Corps------------------------------------" + CR2 - + "SCA_TDF_MODULE(" + tdf.getBlockTDFName() + ") {" + CR2; + corpsPrimitive = "SCA_TDF_MODULE(" + tdf.getName() + ") {" + CR2; if (!tdfports.isEmpty()) { corpsPrimitive = corpsPrimitive + "\t// TDF port declarations" + CR; - for (SysCAMSPortTDF t : tdfports) { + for (SysCAMSTPortTDF t : tdfports) { if (t.getOrigin() == 0) { - corpsPrimitive = corpsPrimitive + "\tsca_tdf::sca_in<" + t.getTDFType() + "> " + t.getPortName() + CR; + corpsPrimitive = corpsPrimitive + "\tsca_tdf::sca_in<" + t.getTDFType() + "> " + t.getName() + ";" + CR; } else if (t.getOrigin() == 1) { - corpsPrimitive = corpsPrimitive + "\tsca_tdf::sca_out<" + t.getTDFType() + "> " + t.getPortName() + CR; + corpsPrimitive = corpsPrimitive + "\tsca_tdf::sca_out<" + t.getTDFType() + "> " + t.getName() + ";" + CR; } } } if (!convports.isEmpty()) { corpsPrimitive = corpsPrimitive + "\t// Converter port declarations" + CR; - for (SysCAMSPortConverter conv : convports) { + for (SysCAMSTPortConverter conv : convports) { if (conv.getOrigin() == 0) { - corpsPrimitive = corpsPrimitive + "\tsca_tdf::sca_de::sca_in<" + conv.getConvType() + "> " + conv.getPortName() + CR; + corpsPrimitive = corpsPrimitive + "\tsca_tdf::sca_de::sca_in<" + conv.getConvType() + "> " + conv.getName() + ";" + CR; } else if (conv.getOrigin() == 1) { - corpsPrimitive = corpsPrimitive + "\tsca_tdf::sca_de::out<" + conv.getConvType() + "> " + conv.getPortName() + CR; + corpsPrimitive = corpsPrimitive + "\tsca_tdf::sca_de::out<" + conv.getConvType() + "> " + conv.getName() + ";" + CR; } } } - corpsPrimitive = corpsPrimitive + CR + "\t// Constructor" + CR + "\tSCA_CTOR(" + tdf.getBlockTDFName() + ")" + CR; + corpsPrimitive = corpsPrimitive + CR + "\t// Constructor" + CR + "\tSCA_CTOR(" + tdf.getName() + ")" + CR; if (!tdfports.isEmpty() || !convports.isEmpty()) { - corpsPrimitive = corpsPrimitive + ": "; + corpsPrimitive = corpsPrimitive + "\t: "; if (!tdfports.isEmpty()) { - for (SysCAMSPortTDF t : tdfports) { - corpsPrimitive = corpsPrimitive + "\t" + t.getPortName() + "(\"" + t.getPortName() + "\")"+ CR; + for (int i = 0; i < tdfports.size(); i++) { + if (tdfports.size() > 1) { + if (cpt == 0) { + corpsPrimitive = corpsPrimitive + tdfports.get(i).getName() + "(\"" + tdfports.get(i).getName() + "\")"; + cpt++; + } else { + corpsPrimitive = corpsPrimitive + "," + CR + "\t" + tdfports.get(i).getName() + "(\"" + tdfports.get(i).getName() + "\")"+ CR; + } + } else { + corpsPrimitive = corpsPrimitive + tdfports.get(i).getName() + "(\"" + tdfports.get(i).getName() + "\")" + CR; + cpt++; + } } } if (!convports.isEmpty()) { - for (SysCAMSPortConverter conv : convports) { - corpsPrimitive = corpsPrimitive + "\t" + conv.getPortName() + "(\"" + conv.getPortName() + "\")"+ CR; + for (int i = 0; i < convports.size(); i++) { + if (convports.size() > 1) { + if (cpt == 0) { + corpsPrimitive = corpsPrimitive + convports.get(i).getName() + "(\"" + convports.get(i).getName() + "\")"; + cpt++; + } else { + corpsPrimitive = corpsPrimitive + "," + CR + "\t" + convports.get(i).getName() + "(\"" + convports.get(i).getName() + "\")"+ CR; + } + } else { + corpsPrimitive = corpsPrimitive + convports.get(i).getName() + "(\"" + convports.get(i).getName() + "\")" + CR; + cpt++; + } } } corpsPrimitive = corpsPrimitive + "\t{}" + CR2; } - corpsPrimitive = corpsPrimitive + "\tvoid set_attributes() {" + CR; - // Block period if (tdf.getPeriod() != 0) { - corpsPrimitive = corpsPrimitive + "\t\t" + "set_timestep(" + tdf.getPeriod() + ", sc_core::SC_MS);" + CR; + corpsPrimitive = corpsPrimitive + "\tvoid set_attributes() {" + CR + "\t\t" + "set_timestep(" + tdf.getPeriod() + ", sc_core::SC_MS);" + CR; + cpt2++; } - for (SysCAMSPortTDF t : tdfports) { - if (t.getPeriod() != 0) { - corpsPrimitive = corpsPrimitive + "\t\t" + t.getPortName() + ".set_timestep(" + t.getPeriod() + ", sc_core::SC_US);" + CR; - } - if (t.getRate() != 0) { - corpsPrimitive = corpsPrimitive + "\t\t" + t.getPortName() + ".set_rate(" + t.getRate() + ");" + CR; - } - if (t.getDelay() != 0) { - corpsPrimitive = corpsPrimitive + "\t\t" + t.getPortName() + ".set_delay(" + t.getDelay() + ");" + CR; - } + if (cpt2 > 0) { + for (SysCAMSTPortTDF t : tdfports) { + if (t.getPeriod() != 0) { + corpsPrimitive = corpsPrimitive + "\t\t" + t.getName() + ".set_timestep(" + t.getPeriod() + ", sc_core::SC_" + t.getTime().toUpperCase() + ");" + CR; + } + if (t.getRate() != 0) { + corpsPrimitive = corpsPrimitive + "\t\t" + t.getName() + ".set_rate(" + t.getRate() + ");" + CR; + } + if (t.getDelay() != 0) { + corpsPrimitive = corpsPrimitive + "\t\t" + t.getName() + ".set_delay(" + t.getDelay() + ");" + CR; + } + } + } else { + for (SysCAMSTPortTDF t : tdfports) { + if (t.getPeriod() != 0) { + if (cpt2 == 0) { + corpsPrimitive = corpsPrimitive + "\tvoid set_attributes() {" + CR + "\t\t" + t.getName() + ".set_timestep(" + t.getPeriod() + ", sc_core::SC_" + t.getTime().toUpperCase() + ");" + CR; + cpt2++; + } else { + corpsPrimitive = corpsPrimitive + "\t\t" + t.getName() + ".set_timestep(" + t.getPeriod() + ", sc_core::SC_" + t.getTime().toUpperCase() + ");" + CR; + } + } + if (t.getRate() != 0 && cpt2 == 0) { + if (cpt2 == 0) { + corpsPrimitive = corpsPrimitive + "\tvoid set_attributes() {" + CR + "\t\t" + t.getName() + ".set_rate(" + t.getRate() + ");" + CR; + cpt2++; + } else { + corpsPrimitive = corpsPrimitive + "\t\t" + t.getName() + ".set_rate(" + t.getRate() + ");" + CR; + } + } + if (t.getDelay() != 0 && cpt2 == 0) { + if (cpt2 == 0) { + corpsPrimitive = corpsPrimitive + "\tvoid set_attributes() {" + CR + "\t\t" + t.getName() + ".set_delay(" + t.getDelay() + ");" + CR; + cpt2++; + } else { + corpsPrimitive = corpsPrimitive + "\t\t" + t.getName() + ".set_delay(" + t.getDelay() + ");" + CR; + } + } + } } // Block processCode - corpsPrimitive = corpsPrimitive + "\t}" + CR2 + "\t" + tdf.getProcessCode() + CR2 + "};" + CR2 + "# endif" - + " // " + tdf.getBlockTDFName().toUpperCase() + "_H"; + + if (cpt2 > 0) { + corpsPrimitive = corpsPrimitive + "\t}" + CR2; + } + + corpsPrimitive = corpsPrimitive + "\t" + tdf.getProcessCode() + CR2 + "};" + CR2 + "#endif" + + " // " + tdf.getName().toUpperCase() + "_H"; } else { corpsPrimitive = ""; } return corpsPrimitive; } - - public static String getClusterCorps(SysCAMSTCluster cluster) { - if (cluster != null) { - List<SysCAMSBlockTDF> blocks = cluster.getBlocks(); - - corpsCluster = "//-------------------------------Header------------------------------------" + CR2 - + "#include <systemc-ams>" + CR2; - - for (SysCAMSBlockTDF b : blocks) { - corpsCluster = corpsCluster + "#include \"" + b.getValue() + ".h\"" + CR; - } - corpsCluster = corpsCluster + CR; - } else { - corpsCluster = ""; - } - return corpsCluster; - } -} +} \ No newline at end of file diff --git a/src/main/java/syscamstranslator/toSysCAMS/TopCellGenerator.java b/src/main/java/syscamstranslator/toSysCAMS/TopCellGenerator.java index 36a2a6aebf..05a5731174 100644 --- a/src/main/java/syscamstranslator/toSysCAMS/TopCellGenerator.java +++ b/src/main/java/syscamstranslator/toSysCAMS/TopCellGenerator.java @@ -47,53 +47,29 @@ package syscamstranslator.toSysCAMS; import syscamstranslator.*; -import syscamstranslator.toSysCAMS.*; -import ui.syscams.SysCAMSBlockTDF; import java.io.*; -import java.util.ArrayList; import java.util.LinkedList; -import java.util.List; + +/** + * Class TopCellGenerator + * Save the components and connectors in files + * Creation: 14/05/2018 + * @version 1.0 14/05/2018 + * @author Irina Kit Yan LEE +*/ public class TopCellGenerator { - // --------------- accessing Avatardd ----------------- public static SysCAMSSpecification syscams; - // --------------------------------------------------- - - public String VCIparameters; - public String config; - public String mainFile; - public String src; - public String top; - public String deployinfo; - public String deployinfo_map; - public String deployinfo_ram; - public String platform_desc; - public String procinfo; - public String nbproc; - public final String DOTH = ".h"; - public final String DOTCPP = ".cpp"; - public final String SYSTEM_INCLUDE = "#include \"systemc.h\""; - public final String CR = "\n"; - public final String CR2 = "\n\n"; - public final String SCCR = ";\n"; - public final String EFCR = "}\n"; - public final String EFCR2 = "}\n\n"; - public final String EF = "}"; - public final String COTE = ""; - public final String NAME_RST = "signal_resetn"; - public final String TYPEDEF = "typedef"; - - private final static String GENERATED_PATH = "generated_topcell" + File.separator; - private boolean tracing; - - public TopCellGenerator(SysCAMSSpecification sys, boolean _tracing) { + + private final static String GENERATED_PATH1 = "generated_CPP" + File.separator; + private final static String GENERATED_PATH2 = "generated_H" + File.separator; + + public TopCellGenerator(SysCAMSSpecification sys) { syscams = sys; - tracing = _tracing; } - public String generateTopCell(SysCAMSTBlockTDF tdf) { - /* first test validity of the hardware platform */ + public String generateTopCell(SysCAMSTCluster c, LinkedList<SysCAMSTConnector> connectors) { if (TopCellGenerator.syscams.getNbCluster() == 0) { System.out.println("***Warning: require at least one cluster***"); } @@ -112,43 +88,50 @@ public class TopCellGenerator { if (TopCellGenerator.syscams.getNbPortConverter() == 0) { System.out.println("***Warning: require at least one converter port***"); } - String top = Header.getPrimitiveHeader(tdf) + Corps.getPrimitiveCorps(tdf); + if (TopCellGenerator.syscams.getNbConnector() == 0) { + System.out.println("***Warning: require at least one connector***"); + } + String top = Header.getClusterHeader(c) + ClusterCode.getClusterCode(c, connectors); return (top); } - public static void saveFile(String path) { -// try { -// System.err.println(path + GENERATED_PATH + "top.cc"); -// FileWriter fw = new FileWriter(path + GENERATED_PATH + "/top.cc"); -// top = generateTopCell(); -// fw.write(top); -// fw.close(); -// } catch (IOException ex) { -// } - saveFileBlockTDF(path); - } - - public static void saveFileBlockTDF(String path) { + public void saveFile(String path) { LinkedList<SysCAMSTCluster> clusters = TopCellGenerator.syscams.getAllCluster(); - String code; + LinkedList<SysCAMSTConnector> connectors = TopCellGenerator.syscams.getAllConnector(); + + String top; for (SysCAMSTCluster c : clusters) { - List<SysCAMSBlockTDF> tdf = c.getBlocks(); - for (SysCAMSBlockTDF t : tdf) { - try { - System.err.println(path + GENERATED_PATH + t.getValue() + ".h"); - FileWriter fw = new FileWriter(path + GENERATED_PATH + "/" + t.getValue() + ".h"); - code = PrimitiveCode.getPrimitiveCode(t); - fw.write(code); - fw.close(); - } catch (Exception ex) { - ex.printStackTrace(); - } + try { + // Save file .cpp + System.err.println(path + GENERATED_PATH1 + c.getClusterName() + ".cpp"); + FileWriter fw = new FileWriter(path + GENERATED_PATH1 + "/" + c.getClusterName() + ".cpp"); + top = generateTopCell(c, connectors); + fw.write(top); + fw.close(); + } catch (Exception ex) { + ex.printStackTrace(); } + // Save files .h + saveFileBlockTDF(path, c); } } - - public static void main (String[] args) { - saveFile("/main/syscamstranslator/"); + + public void saveFileBlockTDF(String path, SysCAMSTCluster c) { + String header, code; + LinkedList<SysCAMSTBlockTDF> tdf = c.getBlockTDF(); + for (SysCAMSTBlockTDF t : tdf) { + try { + System.err.println(path + GENERATED_PATH2 + t.getName() + ".h"); + FileWriter fw = new FileWriter(path + GENERATED_PATH2 + "/" + t.getName() + ".h"); + header = Header.getPrimitiveHeader(t); + fw.write(header); + code = PrimitiveCode.getPrimitiveCode(t); + fw.write(code); + fw.close(); + } catch (Exception ex) { + ex.printStackTrace(); + } + } } } -- GitLab