diff --git a/src/tmltranslator/toturtle/Mapping2TIF.java b/src/tmltranslator/toturtle/Mapping2TIF.java index 8fa1534c0b3def39a00665ca6664060ea39c04e9..f93f8356fb078cb8a46fdcf6c33df8e8ab6bc47a 100755 --- a/src/tmltranslator/toturtle/Mapping2TIF.java +++ b/src/tmltranslator/toturtle/Mapping2TIF.java @@ -72,6 +72,7 @@ public class Mapping2TIF { private TURTLEModeling tm; private Vector checkingErrors; + private boolean showSampleChannels = false; private boolean showChannels = false; private boolean showEvents = false; private boolean showRequests = false; @@ -117,6 +118,10 @@ public class Mapping2TIF { return checkingErrors; } + public void setShowSampleChannels(boolean _b) { + showSampleChannels = _b; + } + public void setShowChannels(boolean _b) { showChannels = _b; } @@ -1216,6 +1221,10 @@ public class Mapping2TIF { for(TMLChannel channel: localChannels) { tcpu.addNewParamIfApplicable("toWrite__" + channel.getName(), "nat", "0"); tcpu.addNewParamIfApplicable("toRead__" + channel.getName(), "nat", "0"); + if (showSampleChannels) { + tcpu.addNewParamIfApplicable("totalWritten__" + channel.getName(), "nat", "0"); + tcpu.addNewParamIfApplicable("totalRead__" + channel.getName(), "nat", "0"); + } switch(channel.getType()) { case TMLChannel.BRBW: //System.out.println("BRBW"); @@ -2047,14 +2056,15 @@ public class Mapping2TIF { private int makeCPUADTaskBehaviorComponent(TClass tcpu, HwCPU cpu, ActivityDiagram ad, ADChoice stateChoice, ADJunction endJunction, TMLTask task, int cpt, ArrayList<TMLTask> tasks, int stateId, int branchStateId, TMLActivityElement element) { ADActionStateWithParam actionp0, actionp1, actionp2, actionp3, actionp4, actionp5, actionp6, actionp7, actionp8, actionp9; + ADActionStateWithParam actionpspe = null; ADActionStateWithGate actiong0, actiong1, actiong2, actiongd; Gate g0, g1, g2; TMLSendRequest sendreq; ADComponent previous; TMLRequest req; TMLForLoop tmlforloop; - ADChoice choice0, choice1, choice2; - ADJunction adj0; + ADChoice choice0, choice1 = null, choice2; + ADJunction adj0, adj1 = null; Param param0, param1, param2, param3; TMLWriteChannel tmlwc; TMLReadChannel tmlrc; @@ -2067,8 +2077,8 @@ public class Mapping2TIF { String guard0, guard1, guard2; int index, i; - String gateName, paramName, cpts, action0, action1, action2, action3; - String name; + String gateName, gateName0, paramName, cpts, action0, action1, action2, action3; + String name, nameTot; //System.out.println("task=" + task.getName() + " stateid=" + stateId + " elt=" + element); @@ -2118,10 +2128,36 @@ public class Mapping2TIF { param1 = tcpu.getParamByName("toWrite__" + name); paramName = param1.getName(); - gateName = cpu.getName() + "__" + task.getName() + "__wr__" + name; + gateName = cpu.getName() + "__" + task.getName() + "__wro__" + name; + gateName0 = cpu.getName() + "__" + task.getName() + "__wr__" + name; if (showChannels) { tcpu.addNewGateIfApplicable(gateName); } + if (showSampleChannels) { + //System.out.println("Show sample channels"); + tcpu.addNewGateIfApplicable(gateName0); + nameTot = "totalWritten__" + ch.getName(); + + actionpspe = getActionStateWithParam(tcpu, ad, nameTot, nameTot + " + written"); + adj1 = new ADJunction(); + ad.add(adj1); + actionpspe.addNext(adj1); + choice1 = new ADChoice(); + ad.add(choice1); + adj1.addNext(choice1); + + guard0 = "[ " + nameTot + " < " + ch.getSize() + "]"; + guard1 = "[ not(" + nameTot + " < " + ch.getSize() + ")]"; + + choice1.addGuard(guard1); + actiong0 = getActionGate(tcpu, ad, gateName0, "!" + ch.getSize() + "!" + ch.getSize()); + actionp0 = getActionStateWithParam(tcpu, ad, nameTot, nameTot + " - " + ch.getSize()); + choice1.addNext(actiong0); + actiong0.addNext(actionp0); + actionp0.addNext(adj1); + + choice1.addGuard(guard0); + } // Init: nb to write in channel actionp1 = getActionStateWithParam(tcpu, ad, param1.getName(), "(" + modifyString(tmlwc.getNbOfSamples(), task) + ") * (" + ch.getSize() + ")"); @@ -2205,12 +2241,18 @@ public class Mapping2TIF { choice2.addNext(actionp5); choice2.addGuard(guard2); actionp6 = getNTickActionStateWithParam(tcpu, cpu, ad); + if (showSampleChannels) { + choice1.addNext(actionp6); + previous = actionpspe; + } else { + previous = actionp6; + } if (showChannels) { actiong0 = getActionGate(tcpu, ad, gateName, "!written!" + ch.getSize()); actionp5.addNext(actiong0); - actiong0.addNext(actionp6); + actiong0.addNext(previous); } else { - actionp5.addNext(actionp6); + actionp5.addNext(previous); } actionp7 = getActionStateWithParam(tcpu, ad, paramName, paramName + " - written"); actionp6.addNext(actionp7); @@ -2226,12 +2268,18 @@ public class Mapping2TIF { actionp5 = getActionStateWithParam(tcpu, ad, "written", "min(" + paramName + ", " + cpu.getName() + "__byteDataSize)"); choice0.addNext(actionp5); actionp6 = getNTickActionStateWithParam(tcpu, cpu, ad); + if (showSampleChannels) { + choice1.addNext(actionp6); + previous = actionpspe; + } else { + previous = actionp6; + } if (showChannels) { actiong0 = getActionGate(tcpu, ad, gateName, "!written!" + ch.getSize()); actionp5.addNext(actiong0); - actiong0.addNext(actionp6); + actiong0.addNext(previous); } else { - actionp5.addNext(actionp6); + actionp5.addNext(previous); } actionp7 = getActionStateWithParam(tcpu, ad, paramName, paramName + " - written"); actionp6.addNext(actionp7); @@ -2247,12 +2295,18 @@ public class Mapping2TIF { actionp5 = getActionStateWithParam(tcpu, ad, "written", "min(" + paramName + ", " + cpu.getName() + "__byteDataSize)"); choice0.addNext(actionp5); actionp6 = getNTickActionStateWithParam(tcpu, cpu, ad); + if (showSampleChannels) { + choice1.addNext(actionp6); + previous = actionpspe; + } else { + previous = actionp6; + } if (showChannels) { actiong0 = getActionGate(tcpu, ad, gateName, "!written!" + ch.getSize()); actionp5.addNext(actiong0); - actiong0.addNext(actionp6); + actiong0.addNext(previous); } else { - actionp5.addNext(actionp6); + actionp5.addNext(previous); } actionp7 = getActionStateWithParam(tcpu, ad, paramName, paramName + " - written"); actionp6.addNext(actionp7); @@ -2276,11 +2330,39 @@ public class Mapping2TIF { param1 = tcpu.getParamByName("toRead__" + name); paramName = param1.getName(); - gateName = cpu.getName() + "__" + task.getName() + "__rd__" + name; + gateName = cpu.getName() + "__" + task.getName() + "__rdo__" + name; + gateName0 = cpu.getName() + "__" + task.getName() + "__rd__" + name; + if (showChannels) { tcpu.addNewGateIfApplicable(gateName); } + if (showSampleChannels) { + //System.out.println("Show sample channels"); + tcpu.addNewGateIfApplicable(gateName0); + nameTot = "totalRead__" + ch.getName(); + + actionpspe = getActionStateWithParam(tcpu, ad, nameTot, nameTot + " + read"); + adj1 = new ADJunction(); + ad.add(adj1); + actionpspe.addNext(adj1); + choice1 = new ADChoice(); + ad.add(choice1); + adj1.addNext(choice1); + + guard0 = "[ " + nameTot + " < " + ch.getSize() + "]"; + guard1 = "[ not(" + nameTot + " < " + ch.getSize() + ")]"; + + choice1.addGuard(guard1); + actiong0 = getActionGate(tcpu, ad, gateName0, "!" + ch.getSize() + "!" + ch.getSize()); + actionp0 = getActionStateWithParam(tcpu, ad, nameTot, nameTot + " - " + ch.getSize()); + choice1.addNext(actiong0); + actiong0.addNext(actionp0); + actionp0.addNext(adj1); + + choice1.addGuard(guard0); + } + // Init: nb to read from channel actionp1 = getActionStateWithParam(tcpu, ad, param1.getName(), "(" + modifyString(tmlrc.getNbOfSamples(), task) + ") * (" + ch.getSize() + ")"); stateIdGuard(stateChoice, actionp1, stateId, task); @@ -2306,9 +2388,9 @@ public class Mapping2TIF { case TMLChannel.BRBW: case TMLChannel.BRNBW: choice0.addGuard("[not(" + guard0 + ")]"); - choice1 = new ADChoice(); - ad.add(choice1); - choice0.addNext(choice1); + choice2 = new ADChoice(); + ad.add(choice2); + choice0.addNext(choice2); guard2 = "n__" + name + "__tmpdest == 0"; guard0 = "[" + guard2 + "]"; @@ -2317,8 +2399,8 @@ public class Mapping2TIF { // If nothing in channel -> must block // Blocked branch actionp1 = getStateActionStateWithParam(tcpu, ad, task, "2"); - choice1.addNext(actionp1); - choice1.addGuard(guard0); + choice2.addNext(actionp1); + choice2.addGuard(guard0); index = allcommunications.indexOf(ch); actionp0 = getBlockedOnActionStateWithParam(tcpu, ad, (2 * index) + 1); actionp1.addNext(actionp0); @@ -2326,15 +2408,21 @@ public class Mapping2TIF { // Not blocked branch actionp5 = getActionStateWithParam(tcpu, ad, "read", "min(min(" + paramName + ", " + cpu.getName() + "__byteDataSize), n__" + name + "__tmpdest)"); - choice1.addNext(actionp5); - choice1.addGuard(guard1); + choice2.addNext(actionp5); + choice2.addGuard(guard1); actionp6 = getNTickActionStateWithParam(tcpu, cpu, ad); + if (showSampleChannels) { + choice1.addNext(actionp6); + previous = actionpspe; + } else { + previous = actionp6; + } if (showChannels) { actiong0 = getActionGate(tcpu, ad, gateName, "!read!" + ch.getSize()); actionp5.addNext(actiong0); - actiong0.addNext(actionp6); + actiong0.addNext(previous); } else { - actionp5.addNext(actionp6); + actionp5.addNext(previous); } actionp7 = getActionStateWithParam(tcpu, ad, paramName, paramName + " - read"); actionp6.addNext(actionp7); @@ -2383,12 +2471,18 @@ public class Mapping2TIF { choice0.addNext(actionp5); choice0.addGuard("[not(" + guard0 + ")]"); actionp6 = getNTickActionStateWithParam(tcpu, cpu, ad); + if (showSampleChannels) { + choice1.addNext(actionp6); + previous = actionpspe; + } else { + previous = actionp6; + } if (showChannels) { actiong0 = getActionGate(tcpu, ad, gateName, "!read!" + ch.getSize()); actionp5.addNext(actiong0); - actiong0.addNext(actionp6); + actiong0.addNext(previous); } else { - actionp5.addNext(actionp6); + actionp5.addNext(previous); } actionp7 = getActionStateWithParam(tcpu, ad, paramName, paramName + " - read"); actionp6.addNext(actionp7); diff --git a/src/ui/GTURTLEModeling.java b/src/ui/GTURTLEModeling.java index c68debbb42dd969f76699229b09e17422a28cfb2..fb40cdee42545bd72b93acb24ced7a9a4144fb40 100755 --- a/src/ui/GTURTLEModeling.java +++ b/src/ui/GTURTLEModeling.java @@ -4022,19 +4022,28 @@ public class GTURTLEModeling { if (tdp == null) { throw new MalformedModelingException(); } - + boolean error = false; + for(int i=0; i<nl.getLength(); i++) { n = nl.item(i); if (n.getNodeType() == Node.ELEMENT_NODE) { - tgc = makeXMLComponent(n, tdp); - if ((tgc != null) && (tgc.getFather() == null)) { - //System.out.println("Component added to diagram tgc=" + tgc); - tdp.addBuiltComponent(tgc); - } else { - //System.out.println("Component not added to diagram"); + try { + tgc = makeXMLComponent(n, tdp); + if ((tgc != null) && (tgc.getFather() == null)) { + //System.out.println("Component added to diagram tgc=" + tgc); + tdp.addBuiltComponent(tgc); + } else { + //System.out.println("Component not added to diagram"); + } + } catch (MalformedModelingException mme) { + error = true; } } } + + if (error) { + throw new MalformedModelingException(); + } } @@ -4851,8 +4860,9 @@ public class GTURTLEModeling { } } - public boolean translateTMLMapping(boolean _channel, boolean _event, boolean _request, boolean _exec, boolean _busTransfers, boolean _scheduling, boolean _taskState, boolean _channelState, boolean _branching, boolean _terminateCPU, boolean _terminateCPUs, boolean _clocked, String _tickValue, boolean _endClocked, boolean _countTick, boolean _maxCountTick, String _maxCountTickValue, boolean _randomTask) { + public boolean translateTMLMapping(boolean _sample, boolean _channel, boolean _event, boolean _request, boolean _exec, boolean _busTransfers, boolean _scheduling, boolean _taskState, boolean _channelState, boolean _branching, boolean _terminateCPU, boolean _terminateCPUs, boolean _clocked, String _tickValue, boolean _endClocked, boolean _countTick, boolean _maxCountTick, String _maxCountTickValue, boolean _randomTask) { Mapping2TIF m2tif = new Mapping2TIF(tmap); + m2tif.setShowSampleChannels(_sample); m2tif.setShowChannels(_channel); m2tif.setShowEvents(_event); m2tif.setShowRequests(_request); @@ -4875,13 +4885,13 @@ public class GTURTLEModeling { m2tif.setRandomTasks(_randomTask); tm = m2tif.generateTURTLEModeling(); tmState = 1; - System.out.println("tm generated"); + System.out.println("tm generated from TMAP"); checkingErrors = m2tif.getCheckingErrors(); if ((checkingErrors != null) && (checkingErrors.size() > 0)){ return false; } else { // Optimize - System.out.println("Optimize"); + System.out.println("Optimize TIF"); //tm.optimize(); //System.out.println("Optimize done"); //tm.print(); diff --git a/src/ui/MainGUI.java b/src/ui/MainGUI.java index a9b96506e306c099906476809a97e9f8c2aa45ce..3a9a7a2c5c0f2160b96dfeff56894b2879b2a366 100755 --- a/src/ui/MainGUI.java +++ b/src/ui/MainGUI.java @@ -2492,7 +2492,9 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener { dtree.toBeUpdated(); return false; } - return true; + if (!automatic) { + return true; + } } //System.out.println("generate LOTOS"); @@ -2531,6 +2533,13 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener { jds.setVisible(true); // Blocked until dialog has been closed } else { jds.closeDialog(); + b = gtm.translateTMLMapping(jds.getSample(), jds.getChannel(), jds.getEvent(), jds.getRequest(), jds.getExec(), jds.getBusTransfer(), jds.getScheduling(), jds.getTaskState(), jds.getChannelState(), jds.getBranching(), jds.getTerminateCPU(), jds.getTerminateCPUs(), jds.getClocked(), jds.getTickIntervalValue(), jds.getEndClocked(), jds.getCountTick(), jds.getMaxCountTick(), jds.getMaxCountTickValue(), jds.getRandomTask()); + if (b) { + setMode(MainGUI.GEN_SYSTEMC_OK); + setMode(MainGUI.MODEL_OK); + return true; + } + return false; } if (!jds.isCancelled()) { diff --git a/src/ui/graph/AUTGraph.java b/src/ui/graph/AUTGraph.java index 7c0ab503a3c7fee4721699c41691aba367ca6649..73666fa8f6b24be15a755cd06c342fe3ed23a3a3 100755 --- a/src/ui/graph/AUTGraph.java +++ b/src/ui/graph/AUTGraph.java @@ -345,5 +345,34 @@ public class AUTGraph implements myutil.Graph { state.met = false; } } + + public AUTState findFirstOriginState() { + AUTState state; + + for(int i=0; i<states.size(); i++) { + state = states.get(i); + //System.out.println("id=" + state.id + " transitions to me = " +state.inTransitions.size()); + if (state.inTransitions.size() == 0) { + return state; + } + } + + return null; + } + + public void putTransitionsFromInitFirst() { + ArrayList<AUTTransition> tmp = new ArrayList<AUTTransition>(); + + for(AUTTransition aut1 : transitions) { + if (aut1.origin == 0) { + tmp.add(aut1); + } + } + + for(AUTTransition aut2 : tmp) { + transitions.remove(aut2); + transitions.add(0, aut2); + } + } } \ No newline at end of file diff --git a/src/ui/graph/AUTMappingGraph.java b/src/ui/graph/AUTMappingGraph.java index 817db4bee224c3fa2d77af20af5d981a94120e24..4d7e251a70706ae7d20b7820d270dfe1324268be 100755 --- a/src/ui/graph/AUTMappingGraph.java +++ b/src/ui/graph/AUTMappingGraph.java @@ -214,7 +214,7 @@ public class AUTMappingGraph extends AUTGraph { return; } - System.out.println("Found two transitions to merge: " + aut1.transition + " and " + aut2.transition); + //System.out.println("Found two transitions to merge: " + aut1.transition + " and " + aut2.transition); // Must check that this is the same channel String tmp1 = aut1.transition.substring(index1 + keyword.length(), aut1.transition.length()); @@ -423,5 +423,25 @@ public class AUTMappingGraph extends AUTGraph { } } + public void putFirstStateFirst() { + + computeStates(); + AUTState state = findFirstOriginState(); + if (state == null) { + System.out.println("no first state"); + return; + } + + System.out.println("First state = " + state.id); + + if ((state != null) && (state != states.get(0))){ + System.out.println("First state = " + state.id); + states.remove(state); + states.add(0, state); + updateStateIds(); + putTransitionsFromInitFirst(); + } + } + } \ No newline at end of file diff --git a/src/ui/window/JDialogGraphModification.java b/src/ui/window/JDialogGraphModification.java index 730794df8bcdb899ae7b2f6764fd0e7d5eabd13d..cdec5c4de92f83d196e0d3e6e37199c22872030a 100755 --- a/src/ui/window/JDialogGraphModification.java +++ b/src/ui/window/JDialogGraphModification.java @@ -406,8 +406,13 @@ public class JDialogGraphModification extends javax.swing.JDialog implements Act //System.out.println("Printing graph:\n" + graph.toAUTStringFormat()); jta.append("Splitting transitions\n"); graph.splitTransitions(); + //modifiedGraphAUT = graph.toAUTStringFormat(); + //System.out.println("Printing graph:\n" + modifiedGraphAUT); + + jta.append("Reordering transitions\n"); + graph.putFirstStateFirst(); modifiedGraphAUT = graph.toAUTStringFormat(); - //System.out.println("Printing graph:\n" + modifiedaut); + //System.out.println("Printing graph:\n" + modifiedGraphAUT); jta.append("Translation in DOT format\n"); diff --git a/src/ui/window/JDialogScheduling.java b/src/ui/window/JDialogScheduling.java index a3a4da2162df9c5de82d6836cb2ccfe92888a8c2..14d6780b1b6d8590e0f233569ed21ee77cf916ba 100755 --- a/src/ui/window/JDialogScheduling.java +++ b/src/ui/window/JDialogScheduling.java @@ -56,7 +56,7 @@ import myutil.*; import ui.*; public class JDialogScheduling extends javax.swing.JDialog implements ActionListener, Runnable { - private static boolean channelChecked= false, eventChecked = false, requestChecked = false, execChecked = false, busTransferChecked = false, schedulingChecked = false, taskStateChecked = false, channelStateChecked = false, branchingChecked = false, terminateCPUChecked = false, terminateCPUsChecked = true, clockedChecked = false, clockedEndChecked = false, countTickChecked=false, maxCountTickChecked=false, randomTaskChecked = true; + private static boolean sampleChecked=false, channelChecked= false, eventChecked = false, requestChecked = false, execChecked = false, busTransferChecked = false, schedulingChecked = false, taskStateChecked = false, channelStateChecked = false, branchingChecked = false, terminateCPUChecked = false, terminateCPUsChecked = true, clockedChecked = false, clockedEndChecked = false, countTickChecked=false, maxCountTickChecked=false, randomTaskChecked = true; private static String tickIntervalValue = "1", maxCountTickValue = "1000"; protected MainGUI mgui; @@ -75,7 +75,7 @@ public class JDialogScheduling extends javax.swing.JDialog implements ActionList protected JScrollPane jsp; protected JButton checkAll, uncheckAll; - protected JCheckBox channel, event, request, exec, busTransfer, scheduling, taskState, channelState, branching, terminateCPU, terminateCPUs, clocked, endClocked, countTick, maxCountTick, randomTask; + protected JCheckBox sample, channel, event, request, exec, busTransfer, scheduling, taskState, channelState, branching, terminateCPU, terminateCPUs, clocked, endClocked, countTick, maxCountTick, randomTask; protected JTextField tickIntervalValueText, maxCountTickText; public boolean cancelled = false; @@ -132,6 +132,11 @@ public class JDialogScheduling extends javax.swing.JDialog implements ActionList c1.fill = GridBagConstraints.BOTH; c1.gridheight = 1; + sample = new JCheckBox("Show sample read / write in channels"); + sample.addActionListener(this); + jp1.add(sample, c1); + sample.setSelected(sampleChecked); + channel = new JCheckBox("Show read / write in channels"); channel.addActionListener(this); jp1.add(channel, c1); @@ -330,6 +335,7 @@ public class JDialogScheduling extends javax.swing.JDialog implements ActionList int size=0, size1; jta.append("Generating TIF specification, please wait\n"); + sampleChecked = sample.isSelected(); channelChecked = channel.isSelected(); eventChecked = event.isSelected(); requestChecked = request.isSelected(); @@ -348,7 +354,7 @@ public class JDialogScheduling extends javax.swing.JDialog implements ActionList maxCountTickChecked = maxCountTick.isSelected(); maxCountTickValue = maxCountTickText.getText(); randomTaskChecked = randomTask.isSelected(); - debug = mgui.gtm.translateTMLMapping(getChannel(), getEvent(), getRequest(), getExec(), getBusTransfer(), getScheduling(), getTaskState(), getChannelState(), getBranching(), getTerminateCPU(), getTerminateCPUs(), getClocked(), getTickIntervalValue(), getEndClocked(), getCountTick(), getMaxCountTick(), getMaxCountTickValue(), getRandomTask()); + debug = mgui.gtm.translateTMLMapping(getSample(), getChannel(), getEvent(), getRequest(), getExec(), getBusTransfer(), getScheduling(), getTaskState(), getChannelState(), getBranching(), getTerminateCPU(), getTerminateCPUs(), getClocked(), getTickIntervalValue(), getEndClocked(), getCountTick(), getMaxCountTick(), getMaxCountTickValue(), getRandomTask()); if (!debug) { setError(); jta.append("*** TIF specification generation failed: ***\n"); @@ -425,6 +431,7 @@ public class JDialogScheduling extends javax.swing.JDialog implements ActionList } public void checkAll(boolean b) { + sample.setSelected(b); channel.setSelected(b); event.setSelected(b); request.setSelected(b); @@ -445,6 +452,10 @@ public class JDialogScheduling extends javax.swing.JDialog implements ActionList tickIntervalValueText.setEnabled(clocked.isSelected()); } + public boolean getSample() { + return sampleChecked; + } + public boolean getChannel() { return channelChecked; }