Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/* 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;
* Creation: 14/05/2018
* @version 1.0 14/05/2018
* @author Irina Kit Yan LEE
static private String corpsPrimitiveTDF;
static private String corpsPrimitiveDE;
private final static String CR = "\n";
private final static String CR2 = "\n\n";
public static String getPrimitiveCodeTDF(SysCAMSTBlockTDF tdf) {
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;
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;
corpsPrimitiveTDF = corpsPrimitiveTDF + "\tsca_tdf::sca_in<" + t.getTDFType() + "> " + t.getName() + ";" + CR;
corpsPrimitiveTDF = corpsPrimitiveTDF + "\tsca_tdf::sca_out<" + t.getTDFType() + "> " + t.getName() + ";" + CR;
}
}
}
if (!convports.isEmpty()) {
corpsPrimitiveTDF = corpsPrimitiveTDF + "\tsca_tdf::sca_de::sca_in<" + 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;
corpsPrimitiveTDF = corpsPrimitiveTDF + CR + "\texplicit " + tdf.getName() + "(sc_core::sc_module_name nm";
if (tdf.getListStruct().getSize() != 0) {
corpsPrimitiveTDF = corpsPrimitiveTDF + ", const parameters& p = parameters())" + CR;
corpsPrimitiveTDF = corpsPrimitiveTDF + ")" + CR;
if (!tdfports.isEmpty() || !convports.isEmpty() || !tdf.getListStruct().isEmpty()) {
corpsPrimitiveTDF = corpsPrimitiveTDF + "\t: ";
corpsPrimitiveTDF = corpsPrimitiveTDF + tdfports.get(i).getName() + "(\"" + tdfports.get(i).getName() + "\")" + CR;
corpsPrimitiveTDF = corpsPrimitiveTDF + "\t, " + tdfports.get(i).getName() + "(\"" + tdfports.get(i).getName() + "\")" + CR;
corpsPrimitiveTDF = corpsPrimitiveTDF + tdfports.get(i).getName() + "(\"" + tdfports.get(i).getName() + "\")" + CR;
corpsPrimitiveTDF = corpsPrimitiveTDF + convports.get(i).getName() + "(\"" + convports.get(i).getName() + "\")" + CR;
corpsPrimitiveTDF = corpsPrimitiveTDF + "\t, " + convports.get(i).getName() + "(\"" + convports.get(i).getName() + "\")" + CR;
corpsPrimitiveTDF = corpsPrimitiveTDF + convports.get(i).getName() + "(\"" + convports.get(i).getName() + "\")" + CR;
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];
corpsPrimitiveTDF = corpsPrimitiveTDF + identifier + "(p." + identifier + ")" + CR;
corpsPrimitiveTDF = corpsPrimitiveTDF + "\t, " + identifier + "(p." + identifier + ")" + CR;
corpsPrimitiveTDF = corpsPrimitiveTDF + identifier + "(p." + identifier + ")" + CR;
corpsPrimitiveTDF = corpsPrimitiveTDF + "\t{}" + CR2 + "protected:" + CR;
Rodrigo Cortes
committed
corpsPrimitiveTDF = corpsPrimitiveTDF + "\tvoid set_attributes() {" + CR + "\t\t" + "set_timestep(" + tdf.getPeriod() + ", sc_core::SC_" + tdf.getTime().toUpperCase() + ");" + CR;
corpsPrimitiveTDF = corpsPrimitiveTDF + "\t\t" + t.getName() + ".set_timestep(" + t.getPeriod() + ", sc_core::SC_" + t.getTime().toUpperCase() + ");" + CR;
corpsPrimitiveTDF = corpsPrimitiveTDF + "\t\t" + t.getName() + ".set_rate(" + t.getRate() + ");" + CR;
corpsPrimitiveTDF = corpsPrimitiveTDF + "\t\t" + t.getName() + ".set_delay(" + t.getDelay() + ");" + CR;
corpsPrimitiveTDF = corpsPrimitiveTDF + "\tvoid set_attributes() {" + CR + "\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;
corpsPrimitiveTDF = corpsPrimitiveTDF + "\tvoid set_attributes() {" + CR + "\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) {
corpsPrimitiveTDF = corpsPrimitiveTDF + "\tvoid set_attributes() {" + CR + "\t\t" + t.getName() + ".set_delay(" + t.getDelay() + ");" + CR;
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;
corpsPrimitiveTDF = corpsPrimitiveTDF + "\t\t" + t.getName() + ".set_rate(" + t.getRate() + ");" + CR;
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;
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;
corpsPrimitiveTDF = corpsPrimitiveTDF + "\t\t" + t.getName() + ".set_rate(" + t.getRate() + ");" + CR;
}
}
if (t.getDelay() != -1 && cpt2 == 0) {
corpsPrimitiveTDF = corpsPrimitiveTDF + "\tvoid set_attributes() {" + CR + "\t\t" + t.getName() + ".set_delay(" + t.getDelay() + ");" + CR;
corpsPrimitiveTDF = corpsPrimitiveTDF + "\t\t" + t.getName() + ".set_delay(" + t.getDelay() + ");" + CR;
corpsPrimitiveTDF = corpsPrimitiveTDF + "\t}" + CR2;
StringBuffer pcbuf = new StringBuffer(tdf.getProcessCode());
StringBuffer buffer = new StringBuffer("");
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
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];
}
corpsPrimitiveTDF = corpsPrimitiveTDF + "\t" + type + " " + identifier + ";" + CR;
corpsPrimitiveTDF = corpsPrimitiveTDF + "\t" + constant + " " + type + " " + identifier + ";" + CR;
corpsPrimitiveTDF = corpsPrimitiveTDF + "};" + CR2 + "#endif" + " // " + tdf.getName().toUpperCase() + "_H";
return corpsPrimitiveTDF;
}
public static String getPrimitiveCodeDE(SysCAMSTBlockDE de) {
if (de != null) {
LinkedList<SysCAMSTPortDE> deports = de.getPortDE();
int cpt = 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;
}
}
}
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
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 (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;
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")) {
} else if (t.getSensitiveMethod().equals("negative")) {
}
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;
}
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
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 + CR + "};" + CR2 + "#endif" + " // " + de.getName().toUpperCase() + "_H";
} else {
corpsPrimitiveDE = "";
}
return corpsPrimitiveDE;