From 5da2364c6f164353c3c19094de6353c59f90d9b0 Mon Sep 17 00:00:00 2001 From: dblouin <dominique.blouin@telecom-paristech.fr> Date: Wed, 25 Jan 2017 18:59:00 +0100 Subject: [PATCH] Issues # 22 and #23 + handling exception when an exception is thrown by the Diplodocus simulator code generator --- src/TMLTranslator.java | 4 +- src/dseengine/DSEConfiguration.java | 6 +- src/myutil/TraceManager.java | 10 ++ .../DiploSimulatorFactory.java | 16 +-- src/ui/window/JDialogSystemCGeneration.java | 99 ++++--------------- 5 files changed, 42 insertions(+), 93 deletions(-) diff --git a/src/TMLTranslator.java b/src/TMLTranslator.java index 2473eaf761..7504b9a395 100755 --- a/src/TMLTranslator.java +++ b/src/TMLTranslator.java @@ -353,10 +353,10 @@ public class TMLTranslator { final IDiploSimulatorCodeGenerator map; // tmltranslator.tomappingsystemc2.TML2MappingSystemC map; if (tmap == null) { - map = DiploSimulatorFactory.INSTANCE.createTranslator( tmlm ); + map = DiploSimulatorFactory.INSTANCE.createCodeGenerator( tmlm ); } else { - map = DiploSimulatorFactory.INSTANCE.createTranslator( tmap ); + map = DiploSimulatorFactory.INSTANCE.createCodeGenerator( tmap ); } map.generateSystemC(debug, true); diff --git a/src/dseengine/DSEConfiguration.java b/src/dseengine/DSEConfiguration.java index e962e34402..a58e97e158 100755 --- a/src/dseengine/DSEConfiguration.java +++ b/src/dseengine/DSEConfiguration.java @@ -671,7 +671,7 @@ public class DSEConfiguration implements Runnable { // Generating code TraceManager.addDev("\n\n\n**** Generating simulation code..."); - final IDiploSimulatorCodeGenerator map = DiploSimulatorFactory.INSTANCE.createTranslator( tmap ); + final IDiploSimulatorCodeGenerator map = DiploSimulatorFactory.INSTANCE.createCodeGenerator( tmap ); // TML2MappingSystemC map = new TML2MappingSystemC(tmap); try { @@ -709,7 +709,7 @@ public class DSEConfiguration implements Runnable { // Generating code TraceManager.addDev("\n\n\n**** Generating simulation code from mapping..."); - final IDiploSimulatorCodeGenerator map = DiploSimulatorFactory.INSTANCE.createTranslator( _tmlmap ); + final IDiploSimulatorCodeGenerator map = DiploSimulatorFactory.INSTANCE.createCodeGenerator( _tmlmap ); try { map.generateSystemC(_debug, _optimize); @@ -1247,7 +1247,7 @@ public class DSEConfiguration implements Runnable { TraceManager.addDev("\n\n\n**** Generating simulation code..."); - final IDiploSimulatorCodeGenerator map = DiploSimulatorFactory.INSTANCE.createTranslator( tmap ); + final IDiploSimulatorCodeGenerator map = DiploSimulatorFactory.INSTANCE.createCodeGenerator( tmap ); // TML2MappingSystemC map = new TML2MappingSystemC(tmap); try { map.generateSystemC(_debug, _optimize); diff --git a/src/myutil/TraceManager.java b/src/myutil/TraceManager.java index b19808c6c4..3270c67eca 100644 --- a/src/myutil/TraceManager.java +++ b/src/myutil/TraceManager.java @@ -46,6 +46,7 @@ package myutil; public class TraceManager { + public final static int TO_CONSOLE = 0; public final static int TO_FILE = 1; public final static int TO_BUFFER = 2; @@ -76,6 +77,15 @@ public class TraceManager { } } + public static void addError( final String message, + final Throwable error ) { + addError( message ); + + if ( error != null ) { + error.printStackTrace(); + } + } + public static void addError(String _s) { switch(errPolicy) { case TO_CONSOLE: diff --git a/src/tmltranslator/tomappingsystemc2/DiploSimulatorFactory.java b/src/tmltranslator/tomappingsystemc2/DiploSimulatorFactory.java index 651d5702e9..546b79b625 100644 --- a/src/tmltranslator/tomappingsystemc2/DiploSimulatorFactory.java +++ b/src/tmltranslator/tomappingsystemc2/DiploSimulatorFactory.java @@ -14,23 +14,23 @@ public class DiploSimulatorFactory { private DiploSimulatorFactory() { } - public IDiploSimulatorCodeGenerator createTranslator( final TMLModeling tmlModeling ) { + public IDiploSimulatorCodeGenerator createCodeGenerator( final TMLModeling tmlModeling ) { return new DiploSimulatorCodeGenerator( tmlModeling ); } - public IDiploSimulatorCodeGenerator createTranslator( final TMLMapping tmlMapping ) { + public IDiploSimulatorCodeGenerator createCodeGenerator( final TMLMapping tmlMapping ) { return new DiploSimulatorCodeGenerator( tmlMapping ); } - public IDiploSimulatorCodeGenerator createTranslator( final TMLModeling tmlModeling, - final List<EBRDD> ebrdds, - final List<TEPE> tepes ) { + public IDiploSimulatorCodeGenerator createCodeGenerator( final TMLModeling tmlModeling, + final List<EBRDD> ebrdds, + final List<TEPE> tepes ) { return new DiploSimulatorCodeGenerator( tmlModeling, ebrdds, tepes ); } - public IDiploSimulatorCodeGenerator createTranslator( final TMLMapping tmlMapping, - final List<EBRDD> ebrdds, - final List<TEPE> tepes ) { + public IDiploSimulatorCodeGenerator createCodeGenerator( final TMLMapping tmlMapping, + final List<EBRDD> ebrdds, + final List<TEPE> tepes ) { return new DiploSimulatorCodeGenerator( tmlMapping, ebrdds, tepes ); } } diff --git a/src/ui/window/JDialogSystemCGeneration.java b/src/ui/window/JDialogSystemCGeneration.java index 29da53423b..2e58d14652 100755 --- a/src/ui/window/JDialogSystemCGeneration.java +++ b/src/ui/window/JDialogSystemCGeneration.java @@ -697,8 +697,6 @@ public class JDialogSystemCGeneration extends javax.swing.JDialog implements Act private void generateCode() throws InterruptedException { String list; - // int cycle = 0; - jta.append("Generating SystemC code\n"); @@ -733,62 +731,20 @@ public class JDialogSystemCGeneration extends javax.swing.JDialog implements Act try { unitCycle = unitcycle.getText(); - // cycle = Integer.valueOf(unitCycle).intValue(); - } catch (Exception e) { + } + catch ( Exception e) { jta.append("Wrong number of cycles: " + unitcycle.getText()); jta.append("Aborting"); jta.append("\n\nReady to process next command\n"); checkMode(); setButtons(); + return; } - /*TML2SystemC tml2systc = new TML2SystemC(mgui.gtm.getTMLModeling()); - tml2systc.generateSystemC(debugmode.isSelected()); - - testGo(); - jta.append("SystemC code generation done\n"); - //t2j.printJavaClasses(); - try { - jta.append("Generating SystemC file\n"); - pathCode = code1.getText(); - tml2systc.saveFile(pathCode, "appmodel"); - jta.append("SystemC file generated\n"); - } catch (Exception e) { - jta.append("Could not generate SystemC file\n"); - }*/ - selectedItem = versionSimulator.getSelectedIndex(); - //System.out.println("Selected item=" + selectedItem); + switch( selectedItem ) { //Old SystemC generator - /*case 0: { - tmltranslator.tomappingsystemc.TML2MappingSystemC tml2systc; - if (mgui.gtm.getTMLMapping() == null) { - if (mgui.gtm.getArtificialTMLMapping() == null) { - tml2systc = new tmltranslator.tomappingsystemc.TML2MappingSystemC(mgui.gtm.getTMLModeling()); - } else { - TraceManager.addDev("Using artifical mapping"); - tml2systc = new tmltranslator.tomappingsystemc.TML2MappingSystemC(mgui.gtm.getArtificialTMLMapping()); - } - } - else { - tml2systc = new tmltranslator.tomappingsystemc.TML2MappingSystemC(mgui.gtm.getTMLMapping()); - } - tml2systc.generateSystemC(debugmode.isSelected(), optimizemode.isSelected()); - testGo(); - jta.append("SystemC code generation done\n"); - //t2j.printJavaClasses(); - try { - jta.append("Generating SystemC file\n"); - pathCode = code1.getText(); - tml2systc.saveFile(pathCode, "appmodel"); - jta.append("SystemC files generated\n"); - } - catch( Exception e ) { - jta.append("Could not generate SystemC file\n"); - } - break; - }*/ case 0: { //Simulator without CPs (Daniel's version) // Making EBRDDs ArrayList<EBRDD> al = new ArrayList<EBRDD>(); @@ -804,63 +760,46 @@ public class JDialogSystemCGeneration extends javax.swing.JDialog implements Act alTepe.add(tepe); jta.append("Done.\n"); } - /*EBRDDTranslator ebrddt; - EBRDDPanel ep; - EBRDD ebrdd; - - for(int k=0; k<val.size(); k++) { - testGo(); - ebrddt = new EBRDDTranslator(); - ep = (EBRDDPanel)(val.get(k)); - jta.append("EBRDD: " + ep.getName() + "\n"); - ebrdd = ebrddt.generateEBRDD(ep, ep.getName()); - jta.append("Checking syntax\n"); - if (ebrddt.getErrors().size() > 0) { - jta.append("Syntax error: ignoring EBRDD\n\n"); - } else { - jta.append("No Syntax error: EBRDD taken into account\n\n"); - al.add(ebrdd); - } - }*/ final IDiploSimulatorCodeGenerator tml2systc; // Generating code if (mgui.gtm.getTMLMapping() == null) { if (mgui.gtm.getArtificialTMLMapping() == null) { - tml2systc = DiploSimulatorFactory.INSTANCE.createTranslator( mgui.gtm.getTMLModeling(), al, alTepe ); + tml2systc = DiploSimulatorFactory.INSTANCE.createCodeGenerator( mgui.gtm.getTMLModeling(), al, alTepe ); //tml2systc = new tmltranslator.tomappingsystemc2.TML2MappingSystemC(mgui.gtm.getTMLModeling(), al, alTepe); } else { TraceManager.addDev("Using artifical mapping"); - tml2systc = DiploSimulatorFactory.INSTANCE.createTranslator( mgui.gtm.getArtificialTMLMapping(), al, alTepe ); + tml2systc = DiploSimulatorFactory.INSTANCE.createCodeGenerator( mgui.gtm.getArtificialTMLMapping(), al, alTepe ); //tml2systc = new tmltranslator.tomappingsystemc2.TML2MappingSystemC(mgui.gtm.getArtificialTMLMapping(), al, alTepe); } } else { - tml2systc = DiploSimulatorFactory.INSTANCE.createTranslator( mgui.gtm.getTMLMapping(), al, alTepe ); + tml2systc = DiploSimulatorFactory.INSTANCE.createCodeGenerator( mgui.gtm.getTMLMapping(), al, alTepe ); // tml2systc = new tmltranslator.tomappingsystemc2.TML2MappingSystemC(mgui.gtm.getTMLMapping(), al, alTepe); } - tml2systc.generateSystemC(debugmode.isSelected(), optimizemode.isSelected()); - testGo(); - jta.append("SystemC code generation done\n"); - - for(TEPE tep: alTepe) { - TraceManager.addDev(tep.toString()); - } - //t2j.printJavaClasses(); try { + tml2systc.generateSystemC(debugmode.isSelected(), optimizemode.isSelected()); + testGo(); + jta.append("SystemC code generation done\n"); + + for(TEPE tep: alTepe) { + TraceManager.addDev(tep.toString()); + } jta.append("Generating SystemC file\n"); pathCode = code1.getText(); tml2systc.saveFile(pathCode, "appmodel"); jta.append("SystemC files generated\n"); - } catch (Exception e) { - jta.append("Could not generate SystemC file\n"); + } + catch ( final Exception ex ) { + final String message = "Could not generate simulator code!"; + jta.append( message + System.lineSeparator() ); + TraceManager.addError( message );ex.printStackTrace(); } break; } - } } //End of method generateCode() -- GitLab