diff --git a/src/main/java/syscamstranslator/SysCAMSTBlockDE.java b/src/main/java/syscamstranslator/SysCAMSTBlockDE.java index eadee80a3d5d5ee664d828627c53e2b204f21505..cba5c33600e3e1db6d77b8c4633f58e3ca6abe3c 100644 --- a/src/main/java/syscamstranslator/SysCAMSTBlockDE.java +++ b/src/main/java/syscamstranslator/SysCAMSTBlockDE.java @@ -49,15 +49,16 @@ import java.util.LinkedList; */ public class SysCAMSTBlockDE extends SysCAMSTComponent { - private String name; private int period; + private String code; private LinkedList<SysCAMSTPortDE> portDE; - public SysCAMSTBlockDE(String _name, int _period) { + public SysCAMSTBlockDE(String _name, int _period, String _code) { name = _name; period = _period; + code = _code; portDE = new LinkedList<SysCAMSTPortDE>(); } @@ -69,6 +70,10 @@ public class SysCAMSTBlockDE extends SysCAMSTComponent { return name; } + public String getCode() { + return code; + } + public LinkedList<SysCAMSTPortDE> getPortDE(){ return portDE; } @@ -76,4 +81,4 @@ public class SysCAMSTBlockDE extends SysCAMSTComponent { public void addPortDE(SysCAMSTPortDE de){ portDE.add(de); } -} +} \ No newline at end of file diff --git a/src/main/java/syscamstranslator/SysCAMSTCluster.java b/src/main/java/syscamstranslator/SysCAMSTCluster.java index be055e4a8243b0bcc8aadaf705b066483d3032bb..6d0558d75bccc495572d13fe66cbf2bf6fc656b6 100644 --- a/src/main/java/syscamstranslator/SysCAMSTCluster.java +++ b/src/main/java/syscamstranslator/SysCAMSTCluster.java @@ -42,22 +42,22 @@ import java.util.LinkedList; /** * Class SysCAMSTCluster - * Paramters of a SystemC-AMS cluster + * Parameters of a SystemC-AMS cluster * Creation: 19/05/2018 * @version 1.0 19/05/2018 * @author Irina Kit Yan LEE */ public class SysCAMSTCluster extends SysCAMSTComponent { - private String clusterName; - private LinkedList<SysCAMSTBlockTDF> blocks; + private LinkedList<SysCAMSTBlockTDF> blockTDF; + private LinkedList<SysCAMSTBlockDE> blockDE; public SysCAMSTCluster(String _clusterName) { - super(); clusterName = _clusterName; - blocks = new LinkedList<SysCAMSTBlockTDF>(); + blockTDF = new LinkedList<SysCAMSTBlockTDF>(); + blockDE = new LinkedList<SysCAMSTBlockDE>(); } public String getClusterName() { @@ -65,10 +65,18 @@ public class SysCAMSTCluster extends SysCAMSTComponent { } public LinkedList<SysCAMSTBlockTDF> getBlockTDF(){ - return blocks; + return blockTDF; + } + + public void addBlockTDF(SysCAMSTBlockTDF _blockTDF){ + blockTDF.add(_blockTDF); + } + + public LinkedList<SysCAMSTBlockDE> getBlockDE(){ + return blockDE; } - public void addBlockTDF(SysCAMSTBlockTDF tdf){ - blocks.add(tdf); + public void addBlockDE(SysCAMSTBlockDE _blockDE){ + blockDE.add(_blockDE); } -} +} \ 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 7849d28a960a450cc5528e278aaf292fdf4eda3a..6a08a46d7c90bdaf13a68fcb9cb315754abfe718 100644 --- a/src/main/java/syscamstranslator/toSysCAMS/Header.java +++ b/src/main/java/syscamstranslator/toSysCAMS/Header.java @@ -58,22 +58,35 @@ import syscamstranslator.*; */ public class Header { - static private String headerPrimitive; + 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 getPrimitiveHeader(SysCAMSTBlockTDF tdf) { + public static String getPrimitiveHeaderTDF(SysCAMSTBlockTDF tdf) { if (tdf != null) { - headerPrimitive = "#ifndef " + tdf.getName().toUpperCase() + "_H"+ CR + headerPrimitiveTDF = "#ifndef " + tdf.getName().toUpperCase() + "_H"+ CR + "#define " + tdf.getName().toUpperCase() + "_H" + CR2 + "#include <cmath>" + CR + "#include <iostream>" + CR + "#include <systemc-ams>" + CR2; } else { - headerPrimitive = ""; + headerPrimitiveTDF = ""; + } + return headerPrimitiveTDF; + } + + public static String getPrimitiveHeaderDE(SysCAMSTBlockDE de) { + if (de != null) { + headerPrimitiveDE = "#ifndef " + de.getName().toUpperCase() + "_H"+ CR + + "#define " + de.getName().toUpperCase() + "_H" + CR2 + + "#include <cmath>" + CR + "#include <iostream>" + CR + "#include <systemc>" + CR2; + } else { + headerPrimitiveDE = ""; } - return headerPrimitive; + return headerPrimitiveDE; } public static String getClusterHeader(SysCAMSTCluster cluster) { @@ -91,4 +104,4 @@ public class Header { } return headerCluster; } -} +} \ No newline at end of file diff --git a/src/main/java/syscamstranslator/toSysCAMS/PrimitiveCode.java b/src/main/java/syscamstranslator/toSysCAMS/PrimitiveCode.java index 87fd951cacaec3f4c1cbeda574e5b56dd8e40075..d159dac6c5fe0fa2fef84a59e75fff1f7038d23e 100644 --- a/src/main/java/syscamstranslator/toSysCAMS/PrimitiveCode.java +++ b/src/main/java/syscamstranslator/toSysCAMS/PrimitiveCode.java @@ -58,13 +58,14 @@ import syscamstranslator.*; */ public class PrimitiveCode { - static private String corpsPrimitive; + 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 getPrimitiveCode(SysCAMSTBlockTDF tdf) { + public static String getPrimitiveCodeTDF(SysCAMSTBlockTDF tdf) { if (tdf != null) { LinkedList<SysCAMSTPortTDF> tdfports = tdf.getPortTDF(); LinkedList<SysCAMSTPortConverter> convports = tdf.getPortConverter(); @@ -72,24 +73,24 @@ public class PrimitiveCode { int cpt2 = 0; if ((!tdf.getTypeTemplate().equals("")) || (!tdf.getNameTemplate().equals(""))) { - corpsPrimitive = "template<" + tdf.getTypeTemplate() + " " + tdf.getNameTemplate() + ">" + CR; + corpsPrimitiveTDF = "template<" + tdf.getTypeTemplate() + " " + tdf.getNameTemplate() + ">" + CR; } //corpsPrimitive = "SCA_TDF_MODULE(" + tdf.getName() + ") {" + CR2; - corpsPrimitive = corpsPrimitive + "class " + tdf.getName() + " : public sca_tdf::sca_module {" + CR2 + "public:" + CR; + 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(" : "); - corpsPrimitive = corpsPrimitive + "\ttypedef " + split[1] + "<" + tdf.getNameTemplate() + "> " + split[0] + ";" + CR; + corpsPrimitiveTDF = corpsPrimitiveTDF + "\ttypedef " + split[1] + "<" + tdf.getNameTemplate() + "> " + split[0] + ";" + CR; if (i == tdf.getListTypedef().getSize()-1) { - corpsPrimitive = corpsPrimitive + CR; + corpsPrimitiveTDF = corpsPrimitiveTDF + CR; } } } if (tdf.getListStruct().getSize() != 0) { - corpsPrimitive = corpsPrimitive + "\tstruct parameters {" + CR; + corpsPrimitiveTDF = corpsPrimitiveTDF + "\tstruct parameters {" + CR; String identifier, value, type; for (int i = 0; i < tdf.getListStruct().size(); i++) { @@ -104,10 +105,10 @@ public class PrimitiveCode { } else { type = splitc[0]; } - corpsPrimitive = corpsPrimitive + "\t\t" + type + " " + identifier + ";" + CR; + corpsPrimitiveTDF = corpsPrimitiveTDF + "\t\t" + type + " " + identifier + ";" + CR; } - corpsPrimitive = corpsPrimitive + "\t\tparameters()" + CR; + corpsPrimitiveTDF = corpsPrimitiveTDF + "\t\tparameters()" + CR; for (int i = 0; i < tdf.getListStruct().size(); i++) { String select = tdf.getListStruct().get(i); @@ -122,61 +123,61 @@ public class PrimitiveCode { type = splitc[0]; } if (i == 0) { - corpsPrimitive = corpsPrimitive + "\t\t: " + identifier + "(" + value + ")" + CR; + corpsPrimitiveTDF = corpsPrimitiveTDF + "\t\t: " + identifier + "(" + value + ")" + CR; } if ((i > 0) && (i < tdf.getListStruct().getSize()-1)) { - corpsPrimitive = corpsPrimitive + "\t\t, " + identifier + "(" + value + ")" + CR; + corpsPrimitiveTDF = corpsPrimitiveTDF + "\t\t, " + identifier + "(" + value + ")" + CR; } if (i == tdf.getListStruct().getSize()-1) { - corpsPrimitive = corpsPrimitive + "\t\t, " + identifier + "(" + value + ")" + CR + "\t\t{}" + CR; + corpsPrimitiveTDF = corpsPrimitiveTDF + "\t\t, " + identifier + "(" + value + ")" + CR + "\t\t{}" + CR; } } - corpsPrimitive = corpsPrimitive + "\t};" + CR; + corpsPrimitiveTDF = corpsPrimitiveTDF + "\t};" + CR; } if (!tdfports.isEmpty()) { - corpsPrimitive = corpsPrimitive + CR; + corpsPrimitiveTDF = corpsPrimitiveTDF + CR; for (SysCAMSTPortTDF t : tdfports) { if (t.getOrigin() == 0) { - corpsPrimitive = corpsPrimitive + "\tsca_tdf::sca_in<" + t.getTDFType() + "> " + t.getName() + ";" + CR; + corpsPrimitiveTDF = corpsPrimitiveTDF + "\tsca_tdf::sca_in<" + t.getTDFType() + "> " + t.getName() + ";" + CR; } else if (t.getOrigin() == 1) { - corpsPrimitive = corpsPrimitive + "\tsca_tdf::sca_out<" + t.getTDFType() + "> " + t.getName() + ";" + CR; + corpsPrimitiveTDF = corpsPrimitiveTDF + "\tsca_tdf::sca_out<" + t.getTDFType() + "> " + t.getName() + ";" + CR; } } } if (!convports.isEmpty()) { - corpsPrimitive = corpsPrimitive + CR; + corpsPrimitiveTDF = corpsPrimitiveTDF + CR; for (SysCAMSTPortConverter conv : convports) { if (conv.getOrigin() == 0) { - corpsPrimitive = corpsPrimitive + "\tsca_tdf::sca_de::sca_in<" + conv.getConvType() + "> " + conv.getName() + ";" + CR; + corpsPrimitiveTDF = corpsPrimitiveTDF + "\tsca_tdf::sca_de::sca_in<" + conv.getConvType() + "> " + conv.getName() + ";" + CR; } else if (conv.getOrigin() == 1) { - corpsPrimitive = corpsPrimitive + "\tsca_tdf::sca_de::sca_out<" + conv.getConvType() + "> " + conv.getName() + ";" + CR; + corpsPrimitiveTDF = corpsPrimitiveTDF + "\tsca_tdf::sca_de::sca_out<" + conv.getConvType() + "> " + conv.getName() + ";" + CR; } } } //corpsPrimitive = corpsPrimitive + CR + "\t// Constructor" + CR + "\tSCA_CTOR(" + tdf.getName() + ")" + CR; - corpsPrimitive = corpsPrimitive + CR + "\texplicit " + tdf.getName() + "(sc_core::sc_module_name nm"; + corpsPrimitiveTDF = corpsPrimitiveTDF + CR + "\texplicit " + tdf.getName() + "(sc_core::sc_module_name nm"; if (tdf.getListStruct().getSize() != 0) { - corpsPrimitive = corpsPrimitive + ", const parameters& p = parameters())" + CR; + corpsPrimitiveTDF = corpsPrimitiveTDF + ", const parameters& p = parameters())" + CR; } else { - corpsPrimitive = corpsPrimitive + ")" + CR; + corpsPrimitiveTDF = corpsPrimitiveTDF + ")" + CR; } if (!tdfports.isEmpty() || !convports.isEmpty() || !tdf.getListStruct().isEmpty()) { - corpsPrimitive = corpsPrimitive + "\t: "; + corpsPrimitiveTDF = corpsPrimitiveTDF + "\t: "; if (!tdfports.isEmpty()) { 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() + "\")" + CR; + corpsPrimitiveTDF = corpsPrimitiveTDF + tdfports.get(i).getName() + "(\"" + tdfports.get(i).getName() + "\")" + CR; cpt++; } else { - corpsPrimitive = corpsPrimitive + "\t, " + tdfports.get(i).getName() + "(\"" + tdfports.get(i).getName() + "\")" + CR; + corpsPrimitiveTDF = corpsPrimitiveTDF + "\t, " + tdfports.get(i).getName() + "(\"" + tdfports.get(i).getName() + "\")" + CR; } } else { - corpsPrimitive = corpsPrimitive + tdfports.get(i).getName() + "(\"" + tdfports.get(i).getName() + "\")" + CR; + corpsPrimitiveTDF = corpsPrimitiveTDF + tdfports.get(i).getName() + "(\"" + tdfports.get(i).getName() + "\")" + CR; cpt++; } } @@ -185,13 +186,13 @@ public class PrimitiveCode { 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() + "\")" + CR; + corpsPrimitiveTDF = corpsPrimitiveTDF + convports.get(i).getName() + "(\"" + convports.get(i).getName() + "\")" + CR; cpt++; } else { - corpsPrimitive = corpsPrimitive + "\t, " + convports.get(i).getName() + "(\"" + convports.get(i).getName() + "\")" + CR; + corpsPrimitiveTDF = corpsPrimitiveTDF + "\t, " + convports.get(i).getName() + "(\"" + convports.get(i).getName() + "\")" + CR; } } else { - corpsPrimitive = corpsPrimitive + convports.get(i).getName() + "(\"" + convports.get(i).getName() + "\")" + CR; + corpsPrimitiveTDF = corpsPrimitiveTDF + convports.get(i).getName() + "(\"" + convports.get(i).getName() + "\")" + CR; cpt++; } } @@ -204,60 +205,60 @@ public class PrimitiveCode { identifier = splita[0]; if (tdf.getListStruct().getSize() > 1) { if (cpt == 0) { - corpsPrimitive = corpsPrimitive + identifier + "(p." + identifier + ")" + CR; + corpsPrimitiveTDF = corpsPrimitiveTDF + identifier + "(p." + identifier + ")" + CR; cpt++; } else { - corpsPrimitive = corpsPrimitive + "\t, " + identifier + "(p." + identifier + ")" + CR; + corpsPrimitiveTDF = corpsPrimitiveTDF + "\t, " + identifier + "(p." + identifier + ")" + CR; } } else { - corpsPrimitive = corpsPrimitive + identifier + "(p." + identifier + ")" + CR; + corpsPrimitiveTDF = corpsPrimitiveTDF + identifier + "(p." + identifier + ")" + CR; cpt++; } } } - corpsPrimitive = corpsPrimitive + "\t{}" + CR2 + "protected:" + CR; + corpsPrimitiveTDF = corpsPrimitiveTDF + "\t{}" + CR2 + "protected:" + CR; } if (tdf.getPeriod() != -1) { - corpsPrimitive = corpsPrimitive + "\tvoid set_attributes() {" + CR + "\t\t" + "set_timestep(" + tdf.getPeriod() + ", sc_core::SC_MS);" + CR; + corpsPrimitiveTDF = corpsPrimitiveTDF + "\tvoid set_attributes() {" + CR + "\t\t" + "set_timestep(" + tdf.getPeriod() + ", sc_core::SC_MS);" + CR; cpt2++; } if (cpt2 > 0) { for (SysCAMSTPortTDF t : tdfports) { if (t.getPeriod() != -1) { - corpsPrimitive = corpsPrimitive + "\t\t" + t.getName() + ".set_timestep(" + t.getPeriod() + ", sc_core::SC_" + t.getTime().toUpperCase() + ");" + CR; + corpsPrimitiveTDF = corpsPrimitiveTDF + "\t\t" + t.getName() + ".set_timestep(" + t.getPeriod() + ", sc_core::SC_" + t.getTime().toUpperCase() + ");" + CR; } if (t.getRate() != -1) { - corpsPrimitive = corpsPrimitive + "\t\t" + t.getName() + ".set_rate(" + t.getRate() + ");" + CR; + corpsPrimitiveTDF = corpsPrimitiveTDF + "\t\t" + t.getName() + ".set_rate(" + t.getRate() + ");" + CR; } if (t.getDelay() != -1) { - corpsPrimitive = corpsPrimitive + "\t\t" + t.getName() + ".set_delay(" + t.getDelay() + ");" + CR; + corpsPrimitiveTDF = corpsPrimitiveTDF + "\t\t" + t.getName() + ".set_delay(" + t.getDelay() + ");" + CR; } } } else { for (SysCAMSTPortTDF t : tdfports) { if (t.getPeriod() != -1) { if (cpt2 == 0) { - corpsPrimitive = corpsPrimitive + "\tvoid set_attributes() {" + CR + "\t\t" + t.getName() + ".set_timestep(" + t.getPeriod() + ", sc_core::SC_" + t.getTime().toUpperCase() + ");" + CR; + corpsPrimitiveTDF = corpsPrimitiveTDF + "\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; + corpsPrimitiveTDF = corpsPrimitiveTDF + "\t\t" + t.getName() + ".set_timestep(" + t.getPeriod() + ", sc_core::SC_" + t.getTime().toUpperCase() + ");" + CR; } } if (t.getRate() != -1) { if (cpt2 == 0) { - corpsPrimitive = corpsPrimitive + "\tvoid set_attributes() {" + CR + "\t\t" + t.getName() + ".set_rate(" + t.getRate() + ");" + CR; + corpsPrimitiveTDF = corpsPrimitiveTDF + "\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; + corpsPrimitiveTDF = corpsPrimitiveTDF + "\t\t" + t.getName() + ".set_rate(" + t.getRate() + ");" + CR; } } if (t.getDelay() != -1) { if (cpt2 == 0) { - corpsPrimitive = corpsPrimitive + "\tvoid set_attributes() {" + CR + "\t\t" + t.getName() + ".set_delay(" + t.getDelay() + ");" + CR; + corpsPrimitiveTDF = corpsPrimitiveTDF + "\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; + corpsPrimitiveTDF = corpsPrimitiveTDF + "\t\t" + t.getName() + ".set_delay(" + t.getDelay() + ");" + CR; } } } @@ -265,46 +266,46 @@ public class PrimitiveCode { if (cpt2 > 0) { for (SysCAMSTPortConverter t : convports) { if (t.getPeriod() != -1) { - corpsPrimitive = corpsPrimitive + "\t\t" + t.getName() + ".set_timestep(" + t.getPeriod() + ", sc_core::SC_" + t.getTime().toUpperCase() + ");" + CR; + corpsPrimitiveTDF = corpsPrimitiveTDF + "\t\t" + t.getName() + ".set_timestep(" + t.getPeriod() + ", sc_core::SC_" + t.getTime().toUpperCase() + ");" + CR; } if (t.getRate() != -1) { - corpsPrimitive = corpsPrimitive + "\t\t" + t.getName() + ".set_rate(" + t.getRate() + ");" + CR; + corpsPrimitiveTDF = corpsPrimitiveTDF + "\t\t" + t.getName() + ".set_rate(" + t.getRate() + ");" + CR; } if (t.getDelay() != -1) { - corpsPrimitive = corpsPrimitive + "\t\t" + t.getName() + ".set_delay(" + t.getDelay() + ");" + CR; + corpsPrimitiveTDF = corpsPrimitiveTDF + "\t\t" + t.getName() + ".set_delay(" + t.getDelay() + ");" + CR; } } } else { for (SysCAMSTPortConverter t : convports) { if (t.getPeriod() != -1) { if (cpt2 == 0) { - corpsPrimitive = corpsPrimitive + "\tvoid set_attributes() {" + CR + "\t\t" + t.getName() + ".set_timestep(" + t.getPeriod() + ", sc_core::SC_" + t.getTime().toUpperCase() + ");" + CR; + corpsPrimitiveTDF = corpsPrimitiveTDF + "\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; + 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) { - corpsPrimitive = corpsPrimitive + "\tvoid set_attributes() {" + CR + "\t\t" + t.getName() + ".set_rate(" + t.getRate() + ");" + CR; + corpsPrimitiveTDF = corpsPrimitiveTDF + "\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; + corpsPrimitiveTDF = corpsPrimitiveTDF + "\t\t" + t.getName() + ".set_rate(" + t.getRate() + ");" + CR; } } if (t.getDelay() != -1 && cpt2 == 0) { if (cpt2 == 0) { - corpsPrimitive = corpsPrimitive + "\tvoid set_attributes() {" + CR + "\t\t" + t.getName() + ".set_delay(" + t.getDelay() + ");" + CR; + corpsPrimitiveTDF = corpsPrimitiveTDF + "\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; + corpsPrimitiveTDF = corpsPrimitiveTDF + "\t\t" + t.getName() + ".set_delay(" + t.getDelay() + ");" + CR; } } } } if (cpt2 > 0) { - corpsPrimitive = corpsPrimitive + "\t}" + CR2; + corpsPrimitiveTDF = corpsPrimitiveTDF + "\t}" + CR2; } StringBuffer pcbuf = new StringBuffer(tdf.getProcessCode()); @@ -341,10 +342,10 @@ public class PrimitiveCode { String pc = buffer.toString(); - corpsPrimitive = corpsPrimitive + "\t" + pc + CR; + corpsPrimitiveTDF = corpsPrimitiveTDF + "\t" + pc + CR; if (tdf.getListStruct().getSize() != 0) { - corpsPrimitive = corpsPrimitive + "private:" + CR; + corpsPrimitiveTDF = corpsPrimitiveTDF + "private:" + CR; String identifier, type, constant; for (int i = 0; i < tdf.getListStruct().size(); i++) { @@ -361,16 +362,154 @@ public class PrimitiveCode { type = splitc[0]; } if (constant.equals("")) { - corpsPrimitive = corpsPrimitive + "\t" + type + " " + identifier + ";" + CR; + corpsPrimitiveTDF = corpsPrimitiveTDF + "\t" + type + " " + identifier + ";" + CR; } else { - corpsPrimitive = corpsPrimitive + "\t" + constant + " " + type + " " + identifier + ";" + CR; + corpsPrimitiveTDF = corpsPrimitiveTDF + "\t" + constant + " " + type + " " + identifier + ";" + CR; } } } - corpsPrimitive = corpsPrimitive + "};" + CR2 + "#endif" + " // " + tdf.getName().toUpperCase() + "_H"; + corpsPrimitiveTDF = corpsPrimitiveTDF + "};" + CR2 + "#endif" + " // " + tdf.getName().toUpperCase() + "_H"; } else { - corpsPrimitive = ""; + corpsPrimitiveTDF = ""; } - return corpsPrimitive; + return corpsPrimitiveTDF; + } + + public static String getPrimitiveCodeDE(SysCAMSTBlockDE de) { + if (de != null) { + LinkedList<SysCAMSTPortDE> deports = de.getPortDE(); + int cpt = 0; +// int cpt2 = 0; + + corpsPrimitiveDE = corpsPrimitiveDE + "class " + de.getName() + " : public sca_core::sca_module {" + CR2 + "public:" + CR; + + if (!deports.isEmpty()) { + corpsPrimitiveDE = corpsPrimitiveDE + CR; + 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)" + CR; + + if (!deports.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++; + } + } + } + } + + if (!de.getCode().equals("")) { + corpsPrimitiveDE = corpsPrimitiveDE + "\t{" + CR + "\t\tSC_METHOD(" + block.getNameFn() + ");" + CR; + } else { + corpsPrimitiveDE = corpsPrimitiveDE + "\t{}" + CR2; + } + +// if (de.getPeriod() != -1) { +// corpsPrimitiveDE = corpsPrimitiveDE + "\tvoid set_attributes() {" + CR + "\t\t" + "set_timestep(" + de.getPeriod() + ", sc_core::SC_MS);" + CR; +// cpt2++; +// } + +// if (cpt2 > 0) { +// for (SysCAMSTPortDE t : deports) { +// if (t.getPeriod() != -1) { +// corpsPrimitiveDE = corpsPrimitiveDE + "\t\t" + t.getName() + ".set_timestep(" + t.getPeriod() + ", sc_core::SC_" + t.getTime().toUpperCase() + ");" + CR; +// } +// if (t.getRate() != -1) { +// corpsPrimitiveDE = corpsPrimitiveDE + "\t\t" + t.getName() + ".set_rate(" + t.getRate() + ");" + CR; +// } +// if (t.getDelay() != -1) { +// corpsPrimitiveDE = corpsPrimitiveDE + "\t\t" + t.getName() + ".set_delay(" + t.getDelay() + ");" + CR; +// } +// } +// } else { +// for (SysCAMSTPortDE t : deports) { +// if (t.getPeriod() != -1) { +// if (cpt2 == 0) { +// corpsPrimitiveDE = corpsPrimitiveDE + "\tvoid set_attributes() {" + CR + "\t\t" + t.getName() + ".set_timestep(" + t.getPeriod() + ", sc_core::SC_" + t.getTime().toUpperCase() + ");" + CR; +// cpt2++; +// } else { +// corpsPrimitiveDE = corpsPrimitiveDE + "\t\t" + t.getName() + ".set_timestep(" + t.getPeriod() + ", sc_core::SC_" + t.getTime().toUpperCase() + ");" + CR; +// } +// } +// if (t.getRate() != -1) { +// if (cpt2 == 0) { +// corpsPrimitiveDE = corpsPrimitiveDE + "\tvoid set_attributes() {" + CR + "\t\t" + t.getName() + ".set_rate(" + t.getRate() + ");" + CR; +// cpt2++; +// } else { +// corpsPrimitiveDE = corpsPrimitiveDE + "\t\t" + t.getName() + ".set_rate(" + t.getRate() + ");" + CR; +// } +// } +// if (t.getDelay() != -1) { +// if (cpt2 == 0) { +// corpsPrimitiveDE = corpsPrimitiveDE + "\tvoid set_attributes() {" + CR + "\t\t" + t.getName() + ".set_delay(" + t.getDelay() + ");" + CR; +// cpt2++; +// } else { +// corpsPrimitiveDE = corpsPrimitiveDE + "\t\t" + t.getName() + ".set_delay(" + t.getDelay() + ");" + CR; +// } +// } +// } +// } + +// if (cpt2 > 0) { +// corpsPrimitiveDE = corpsPrimitiveDE + "\t}" + CR2; +// } + + 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 + CR + "};" + CR2 + "#endif" + " // " + de.getName().toUpperCase() + "_H"; + } else { + corpsPrimitiveDE = ""; + } + return corpsPrimitiveDE; } } \ 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 a00723da92880e9b2e7d4bfa866935e38ecf9834..f563b4abbeeb0cd147ed6136409a096fbc74a63a 100644 --- a/src/main/java/syscamstranslator/toSysCAMS/TopCellGenerator.java +++ b/src/main/java/syscamstranslator/toSysCAMS/TopCellGenerator.java @@ -130,13 +130,27 @@ public class TopCellGenerator { public void saveFileBlockTDF(String path, SysCAMSTCluster c) { String header, code; LinkedList<SysCAMSTBlockTDF> tdf = c.getBlockTDF(); + LinkedList<SysCAMSTBlockDE> de = c.getBlockDE(); 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); + header = Header.getPrimitiveHeaderTDF(t); fw.write(header); - code = PrimitiveCode.getPrimitiveCode(t); + code = PrimitiveCode.getPrimitiveCodeTDF(t); + fw.write(code); + fw.close(); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + for (SysCAMSTBlockDE t : de) { + try { + System.err.println(path + GENERATED_PATH2 + t.getName() + ".h"); + FileWriter fw = new FileWriter(path + GENERATED_PATH2 + "/" + t.getName() + ".h"); + header = Header.getPrimitiveHeaderDE(t); + fw.write(header); + code = PrimitiveCode.getPrimitiveCodeDE(t); fw.write(code); fw.close(); } catch (Exception ex) { diff --git a/src/main/java/ui/SysCAMSPanelTranslator.java b/src/main/java/ui/SysCAMSPanelTranslator.java index 2e144c60afb31c04ab54715de1b891d1ee6c80a8..7424526de139154d131b7dc90fb4170572f634a0 100644 --- a/src/main/java/ui/SysCAMSPanelTranslator.java +++ b/src/main/java/ui/SysCAMSPanelTranslator.java @@ -97,8 +97,9 @@ public class SysCAMSPanelTranslator { String blockDEName = blockDE.getValue(); int periodBlock = blockDE.getPeriod(); + String code = blockDE.getCode(); - SysCAMSTBlockDE syscamsBlockDE = new SysCAMSTBlockDE(blockDEName, periodBlock); + SysCAMSTBlockDE syscamsBlockDE = new SysCAMSTBlockDE(blockDEName, periodBlock, code); List<SysCAMSPortDE> portsDE = blockDE.getAllInternalPortsDE(); for (int i = 0; i < portsDE.size(); i++) { @@ -128,6 +129,7 @@ public class SysCAMSPanelTranslator { SysCAMSTCluster syscamsCluster = new SysCAMSTCluster(clusterName); List<SysCAMSBlockTDF> blocksTDF = cluster.getAllBlockTDFComponents(); + List<SysCAMSBlockDE> blocksDE = cluster.getAllBlockDEComponents(); for (int i = 0; i < blocksTDF.size(); i++) { SysCAMSBlockTDF blockTDF = blocksTDF.get(i); @@ -181,6 +183,37 @@ public class SysCAMSPanelTranslator { syscamsCluster.addBlockTDF(syscamsBlockTDF); syscamsComponents.add(syscamsBlockTDF); } + for (int i = 0; i < blocksDE.size(); i++) { + SysCAMSBlockDE blockDE = (SysCAMSBlockDE) dp; + + String blockDEName = blockDE.getValue(); + int periodBlock = blockDE.getPeriod(); + String code = blockDE.getCode(); + + SysCAMSTBlockDE syscamsBlockDE = new SysCAMSTBlockDE(blockDEName, periodBlock, code); + + List<SysCAMSPortDE> portsDE = blockDE.getAllInternalPortsDE(); + for (int j = 0; j < portsDE.size(); j++) { + SysCAMSPortDE portDE = portsDE.get(j); + + String portName = portDE.getPortName(); + int periodPort = portDE.getPeriod(); + String time = portDE.getTime(); + int rate = portDE.getRate(); + int delay = portDE.getDelay(); + String type = portDE.getDEType(); + int origin = portDE.getOrigin(); + + SysCAMSTPortDE syscamsPortDE = new SysCAMSTPortDE(portName, periodPort, time, rate, delay, origin, type, syscamsBlockDE); + + syscamsMap.put(portDE, syscamsPortDE); + syscamsBlockDE.addPortDE(syscamsPortDE); + syscamsComponents.add(syscamsPortDE); + } + syscamsMap.put(blockDE, syscamsBlockDE); + syscamsCluster.addBlockDE(syscamsBlockDE); + syscamsComponents.add(syscamsBlockDE); + } syscamsMap.put(cluster, syscamsCluster); syscamsComponents.add(syscamsCluster); } else if (dp instanceof SysCAMSPortConnector) { diff --git a/src/main/java/ui/syscams/SysCAMSCompositeComponent.java b/src/main/java/ui/syscams/SysCAMSCompositeComponent.java index 271359851291f8d9006172da62791cb5ee1f7b6b..6818355c240799babf30ed90874a2c2d7acddd15 100644 --- a/src/main/java/ui/syscams/SysCAMSCompositeComponent.java +++ b/src/main/java/ui/syscams/SysCAMSCompositeComponent.java @@ -305,6 +305,19 @@ public class SysCAMSCompositeComponent extends TGCScalableWithInternalComponent return ll; } + public java.util.List<SysCAMSBlockDE> getAllBlockDEComponents() { + ArrayList<SysCAMSBlockDE> ll = new ArrayList<SysCAMSBlockDE>(); + for(int i=0; i<nbInternalTGComponent; i++) { + if (tgcomponent[i] instanceof SysCAMSCompositeComponent) { + ll.addAll(((SysCAMSCompositeComponent)tgcomponent[i]).getAllBlockDEComponents()); + } + if (tgcomponent[i] instanceof SysCAMSBlockDE) { + ll.add(((SysCAMSBlockDE)(tgcomponent[i]))); + } + } + return ll; + } + public void getAllCompositeComponents(ArrayList<String> list, String _name) { String s; SysCAMSCompositeComponent syscamscc; diff --git a/src/main/java/ui/window/JDialogSysCAMSBlockDE.java b/src/main/java/ui/window/JDialogSysCAMSBlockDE.java index 6079dfca94fddd1e5693df739746a4a9b9ca6a0a..7162b70481baf261d2247ddff98f088240395fae 100644 --- a/src/main/java/ui/window/JDialogSysCAMSBlockDE.java +++ b/src/main/java/ui/window/JDialogSysCAMSBlockDE.java @@ -62,8 +62,8 @@ public class JDialogSysCAMSBlockDE extends JDialog implements ActionListener { private String listPeriodString[]; private JComboBox<String> periodComboBoxString; - private JPanel processMainPanel; - private JTextArea processCodeTextArea; + private JPanel codeMainPanel; + private JTextArea codeTextArea; private String finalString; private SysCAMSBlockDE block; @@ -165,9 +165,9 @@ public class JDialogSysCAMSBlockDE extends JDialog implements ActionListener { JPanel attributesMainPanel = new JPanel(); if (block.getFather() != null) { JTabbedPane tabbedPane = new JTabbedPane(); - processMainPanel = new JPanel(); + codeMainPanel = new JPanel(); tabbedPane.add("Attributes", attributesMainPanel); - tabbedPane.add("Process Code", processMainPanel); + tabbedPane.add("Process Code", codeMainPanel); mainPanel.add(tabbedPane, BorderLayout.NORTH); } else { @@ -243,10 +243,10 @@ public class JDialogSysCAMSBlockDE extends JDialog implements ActionListener { // --- ProcessCode ---// if (block.getFather() != null) { - processMainPanel.setLayout(new BorderLayout()); + codeMainPanel.setLayout(new BorderLayout()); Box codeBox = Box.createVerticalBox(); - codeBox.setBorder(BorderFactory.createTitledBorder("Behavior function of TDF block")); + codeBox.setBorder(BorderFactory.createTitledBorder("Method of DE block")); JPanel codeBoxPanel = new JPanel(new BorderLayout()); @@ -254,24 +254,24 @@ public class JDialogSysCAMSBlockDE extends JDialog implements ActionListener { String beginString = stringbuf.toString(); finalString = beginString.replaceAll("\t}", "}"); - processCodeTextArea = new JTextArea(finalString); - processCodeTextArea.setSize(100, 100); - processCodeTextArea.setTabSize(2); + codeTextArea = new JTextArea(finalString); + codeTextArea.setSize(100, 100); + codeTextArea.setTabSize(2); - processCodeTextArea.setFont(new Font("Arial", Font.PLAIN, 16)); - processCodeTextArea.setLineWrap(true); - processCodeTextArea.setWrapStyleWord(true); + codeTextArea.setFont(new Font("Arial", Font.PLAIN, 16)); + codeTextArea.setLineWrap(true); + codeTextArea.setWrapStyleWord(true); - JScrollPane processScrollPane = new JScrollPane(processCodeTextArea); - processScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); - processScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); - processScrollPane.setPreferredSize(new Dimension(200, 200)); - processScrollPane.setBorder(new EmptyBorder(15, 10, 15, 10)); + JScrollPane codeScrollPane = new JScrollPane(codeTextArea); + codeScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); + codeScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); + codeScrollPane.setPreferredSize(new Dimension(200, 200)); + codeScrollPane.setBorder(new EmptyBorder(15, 10, 15, 10)); - codeBoxPanel.add(processScrollPane, BorderLayout.SOUTH); + codeBoxPanel.add(codeScrollPane, BorderLayout.SOUTH); codeBox.add(codeBoxPanel); - processMainPanel.add(codeBox, BorderLayout.PAGE_START); + codeMainPanel.add(codeBox, BorderLayout.PAGE_START); } // -- Button -- / @@ -321,7 +321,7 @@ public class JDialogSysCAMSBlockDE extends JDialog implements ActionListener { } if (block.getFather() != null) { - block.setCode(processCodeTextArea.getText()); + block.setCode(codeTextArea.getText()); } this.dispose();