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) {
corpsPrimitiveTDF = corpsPrimitiveTDF + "\t\t, " + identifier + "(" + value + ")" + CR + "\t\t{}" + CR;
corpsPrimitiveTDF = corpsPrimitiveTDF + "\t};" + CR;
corpsPrimitiveTDF = corpsPrimitiveTDF + CR;
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 + CR;
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];
if (tdf.getListStruct().getSize() > 1) {
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;
corpsPrimitiveTDF = corpsPrimitiveTDF + "\tvoid set_attributes() {" + CR + "\t\t" + "set_timestep(" + tdf.getPeriod() + ", sc_core::SC_MS);" + 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) {
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
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++;
}
}
}
}
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;
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
} 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;