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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/**Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille
ludovic.apvrille AT enst.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.
/**
* Class TIFTranslator
* Linecommand application for translating TIF to other languages
* Creation: 29/06/2007
* @version 1.0 29/06/2007
* @author Ludovic APVRILLE
* @see
*/
import java.io.*;
import java.util.*;
import tmltranslator.*;
import tmltranslator.touppaal.*;
import tmltranslator.tomappingsystemc.*;
import tmltranslator.tomappingsystemc2.*;
import tmltranslator.toturtle.*;
import translator.*;
import myutil.*;
//import uppaaldesc.*;
public class TMLTranslator {
// 0 -> LOTOS
// 1 -> UPPAAL
// 2 -> SystemC
// 3 -> SystemC2
public static int conversionType;
public static File inputFile;
public static File outputFile;
public static String outputFileName;
public static String inputData;
public static String outputData;
public static TMLModeling tmlm;
public static TMLMapping tmap;
public static boolean debug = false;
public static boolean optimize = false;
public static void printCopyright() {
System.out.println("TMLTranslator: (C) GET/ENST, Ludovic Apvrille, Ludovic.Apvrille@enst.fr");
System.out.println("TMLTranslator is released under a CECILL License. See http://www.cecill.info/index.en.html");
System.out.println("For more information on TURTLE related technologies, please consult http://labsoc.comelec.enst.fr/turtle/");
System.out.println("Enjoy!!!\n");
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
}
public static void printUsage() {
System.out.println("TMLTranlator: usage");
System.out.println("TMLTranlator <options> <language> <inputfile> [<outputfile> or <outputdirectory>]");
System.out.println("<options> are optional. There might be : -debug or -optimize");
System.out.println("<language> may be: LOTOS, UPPAAL, SystemC, SystemC2, TML");
System.out.println("LOTOS, UPPAAL: an output file must be provided");
System.out.println("For SystemC, SystemC2, TML: a target directory must be provided");
System.out.println("<inputfile> should be in TML format, and be readable");
System.out.println("<outputfile> or <outputdirectory> should be writeable");
}
public static boolean checkArgs(String [] args) {
return !(args.length < 3);
}
public static boolean hasDebug(String [] args) {
if (args[0].equals("-debug")) {
return true;
}
if (args[1].equals("-debug")) {
return true;
}
return false;
}
public static boolean hasOptimize(String [] args) {
if (args[0].equals("-optimize")) {
return true;
}
if (args[1].equals("-optimize")) {
return true;
}
return false;
}
public static boolean analyseArgs(String [] args) {
System.out.println("Converting to " + args[0]);
if (args[0].toUpperCase().equals("LOTOS")) {
conversionType = 0;
} else if (args[0].toUpperCase().equals("UPPAAL")) {
conversionType = 1;
} else if (args[0].toUpperCase().equals("SYSTEMC")) {
conversionType = 2;
} else if (args[0].toUpperCase().equals("SYSTEMC2")) {
conversionType = 3;
} else if (args[0].toUpperCase().equals("TML")) {
conversionType = 4;
} else {
return false;
}
return true;
}
public static boolean prepareFiles(String args[]) {
inputFile = new File(args[1]);
outputFile = new File(args[2]);
outputFileName = args[2];
try {
if (!FileUtils.checkFileForOpen(inputFile)) {
System.out.println("Cannot read file: " + args[1]);
return false;
}
inputData = FileUtils.loadFileData(inputFile);
if ((conversionType == 0) || (conversionType == 1)) {
if (!FileUtils.checkFileForSave(outputFile)) {
System.out.println("Cannot create / open file: " + args[1]);
return false;
}
}
} catch (Exception e) {
System.out.println("Exception: " + e.getMessage());
return false;
}
return true;
}
public static boolean checkSyntax(TMLSyntaxChecking syntax) {
System.out.println("Syntax checking phase");
syntax.checkSyntax();
return (syntax.hasErrors() == 0);
}
public static boolean loadMapping(String title, String path) {
boolean ret = false;
//System.out.println("load");
TMLMappingTextSpecification spec = new TMLMappingTextSpecification(title);
ret = spec.makeTMLMapping(inputData, path);
System.out.println("load ended");
ArrayList<TMLError> warnings;
if (!ret) {
System.out.println("Compilation:\n" + spec.printSummary());
}
if (ret) {
//System.out.println("Format OK");
tmap = spec.getTMLMapping();
tmlm = tmap.getTMLModeling();
//System.out.println("\n\n*** TML Modeling *** \n");
//TMLTextSpecification textspec = new TMLTextSpecification("toto");
//String s = textspec.toTextFormat(tmlm);
//System.out.println(s);
System.out.println("--- Checking syntax of the whole specification (TML, TARCHI, TMAP)---");
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
TMLSyntaxChecking syntax = new TMLSyntaxChecking(tmap);
ret = checkSyntax(syntax);
if (!ret) {
System.out.println("Compilation:\n" + syntax.printSummary());
return false;
}
System.out.println("Compilation:\n" + spec.printSummary());
if (optimize) {
warnings = tmlm.optimize();
System.out.println(tmlm.printSummary(warnings));
}
//spec.toTextFormat(tmlm);
//System.out.println("TMLModeling=" + spec);
}
return ret;
}
public static boolean loadTML(String title) {
boolean ret = false;
ArrayList<TMLError> warnings;
//System.out.println("load");
TMLTextSpecification spec = new TMLTextSpecification(title, true);
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
ret = spec.makeTMLModeling(inputData);
//System.out.println("load ended");
tmlm = spec.getTMLModeling();
if (!ret) {
System.out.println("Compilation:\n" + spec.printSummary());
}
if (ret) {
//System.out.println("Format OK");
spec.toTextFormat(tmlm);
//System.out.println("TMLModeling=" + spec);
TMLSyntaxChecking syntax = new TMLSyntaxChecking(tmlm);
ret = checkSyntax(syntax);
if (!ret) {
System.out.println("Compilation:\n" + syntax.printSummary());
return false;
}
System.out.println("Compilation:\n" + spec.printSummary());
if (optimize) {
warnings = tmlm.optimize();
System.out.println(tmlm.printSummary(warnings) + "\n");
}
}
return ret;
}
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
public static boolean convertToLOTOSFromMapping() {
Mapping2TIF m2tif = new Mapping2TIF(tmap);
m2tif.setShowSampleChannels(false);
m2tif.setShowChannels(true);
m2tif.setShowEvents(true);
m2tif.setShowRequests(true);
m2tif.setShowExecs(false);
m2tif.setShowBusTransfers(false);
m2tif.setShowScheduling(false);
m2tif.setIsClocked(false);
m2tif.setTickValue("10");
m2tif.setIsEndClocked(false);
m2tif.setIsCountTick(true);
m2tif.hasMaxCountTick(false);
m2tif.setShowTaskState(false);
m2tif.setShowChannelState(false);
m2tif.setShowBlockedCPU(false);
m2tif.setShowTerminateCPUs(true);
m2tif.setShowBranching(false);
m2tif.setRandomTasks(false);
TURTLEModeling tm = m2tif.generateTURTLEModeling();
TURTLETranslator tt = new TURTLETranslator(tm);
outputData = tt.generateLOTOS(true);
try {
FileOutputStream fos = new FileOutputStream(outputFile);
fos.write(outputData.getBytes());
fos.close();
} catch (Exception e) {
System.out.println("Error when writing LOTOS file");
return false;
}
return true;
}
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
public static boolean convertToLOTOS() {
TML2TURTLE totif = new TML2TURTLE(tmlm);
TURTLEModeling tm = totif.generateTURTLEModeling();
TURTLETranslator tt = new TURTLETranslator(tm);
outputData = tt.generateLOTOS(true);
try {
FileOutputStream fos = new FileOutputStream(outputFile);
fos.write(outputData.getBytes());
fos.close();
} catch (Exception e) {
System.out.println("Error when writing LOTOS file");
return false;
}
return true;
}
public static boolean convertToUPPAAL() {
TML2UPPAAL toup = new TML2UPPAAL(tmlm);
toup.generateUPPAAL(debug);
try {
toup.saveInPathFile(outputFileName);
} catch (Exception e) {
System.out.println("Error when writing UPPAAL specification: " + e.getMessage());
return false;
}
return true;
}
public static boolean convertToSystemC() {
tmltranslator.tomappingsystemc.TML2MappingSystemC map;
if (tmap == null) {
map = new tmltranslator.tomappingsystemc.TML2MappingSystemC(tmlm);
} else {
map = new tmltranslator.tomappingsystemc.TML2MappingSystemC(tmap);
}
map.generateSystemC(debug, true);
try {
map.saveFile(outputFileName, "appmodel");
} catch (Exception e) {
System.out.println("SystemC generation failed: " + e.getMessage());
return false;
}
//System.out.println("SystemC conversion not yet implemented");
return true;
}
public static boolean convertToSystemC2() {
//System.out.println("Converting to SystemC2 ... yo!");
tmltranslator.tomappingsystemc2.TML2MappingSystemC map;
if (tmap == null) {
map = new tmltranslator.tomappingsystemc2.TML2MappingSystemC(tmlm);
} else {
map = new tmltranslator.tomappingsystemc2.TML2MappingSystemC(tmap);
}
map.generateSystemC(debug, true);
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
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
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
try {
map.saveFile(outputFileName, "appmodel");
} catch (Exception e) {
System.out.println("SystemC generation failed: " + e.getMessage());
return false;
}
//System.out.println("SystemC conversion not yet implemented");
return true;
}
public static boolean convertToTML() {
if (tmap == null) {
TMLTextSpecification tspec = new TMLTextSpecification("spec");
tspec.toTextFormat(tmlm);
try {
tspec.saveFile(outputFileName, "spec");
} catch (Exception e) {
System.out.println("TML generation failed: " + e.getMessage());
return false;
}
} else {
TMLMappingTextSpecification mapspec = new TMLMappingTextSpecification("spec");
mapspec.toTextFormat(tmap);
try {
mapspec.saveFile(outputFileName, "spec");
} catch (Exception e) {
System.out.println("TML/Mapping generation failed: " + e.getMessage());
return false;
}
}
return true;
}
public static boolean saveData() {
try {
FileOutputStream fos = new FileOutputStream(outputFile);
fos.write(outputData.getBytes());
fos.close();
} catch (Exception e) {
System.out.println("Error when writing output file");
return false;
}
return true;
}
public static void main(String[] args) {
String[] tmp;
printCopyright();
if (!checkArgs(args)) {
printUsage();
return;
}
int nbOfOptions = 0;
if (hasDebug(args)) {
debug = true;
nbOfOptions ++;
}
if (hasOptimize(args)) {
optimize = true;
nbOfOptions ++;
}
if (nbOfOptions > 0) {
debug = true;
tmp = new String[args.length - nbOfOptions];
for(int i=nbOfOptions; i<args.length; i++) {
tmp[i-nbOfOptions] = args[i];
}
args = tmp;
}
if (!analyseArgs(args)) {
printUsage();
return;
}
if (!prepareFiles(args)) {
printUsage();
return;
}
if (args[1].endsWith(".tmap")) {
String path;
int index;
index = args[1].lastIndexOf(File.separatorChar);
if (index != -1) {
path = args[1].substring(0, index+1);
} else {
path = "." + File.separatorChar;
}
//System.out.println("path=" + path);
if (!loadMapping(args[1], path)) {
System.out.println("Compilation failed => no code generation");
return;
}
} else {
if (!loadTML(args[1])) {
System.out.println("Compilation failed => no code generation");
return;
}
}
boolean convert = false;
//testSplit();
/*String s = "\t \ttoto";
System.out.println("toto=" + s);
s = s.trim();
System.out.println("toto=" + s);*/
switch(conversionType) {
case 0:
if (tmap == null) {
convert = convertToLOTOS();
} else {
convert = convertToLOTOSFromMapping();
}
break;
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
case 1:
convert = convertToUPPAAL();
break;
case 2:
convert = convertToSystemC();
break;
case 3:
convert = convertToSystemC2();
break;
case 4:
convert = convertToTML();
break;
}
if (!convert) {
System.out.println("Error during conversion");
return;
}
System.out.println("Conversion done");
/*if (!saveData()) {
return;
}*/
//System.out.println("Specification written in " + outputFile.getName() + ": " + outputData.length() + " bytes");
}
} // Class TMLTranslator