diff --git a/src/main/java/dseengine/DSEConfiguration.java b/src/main/java/dseengine/DSEConfiguration.java index ef0596784b1ad64f70806db8bf405cc21ebdcb99..6d529748523fbbfcf3288b0c7914d3d5486ac128 100755 --- a/src/main/java/dseengine/DSEConfiguration.java +++ b/src/main/java/dseengine/DSEConfiguration.java @@ -43,6 +43,7 @@ package dseengine; +import common.SpecConfigTTool; import myutil.Conversion; import myutil.FileException; import myutil.FileUtils; @@ -785,6 +786,10 @@ public class DSEConfiguration implements Runnable { try { TraceManager.addDev("Making directory:" + pathToSimulator); FileUtils.mkdir(pathToSimulator); + if (!SpecConfigTTool.checkAndCreateSystemCDir(pathToSimulator)) { + return -1; + } + map.generateSystemC(_debug, _optimize); map.saveFile(pathToSimulator, "appmodel"); } catch (Exception e) { diff --git a/src/main/java/tmltranslator/TMLMapping.java b/src/main/java/tmltranslator/TMLMapping.java index e1beb71f31036eaed1f406bd1070bc3e2d29d767..52bd2927ff596077f904e083ec58daf48edbe497 100755 --- a/src/main/java/tmltranslator/TMLMapping.java +++ b/src/main/java/tmltranslator/TMLMapping.java @@ -724,7 +724,7 @@ public class TMLMapping<E> { TMLChannel chan; - TraceManager.addDev("Number of tasks after remove fork/join: " + tmlm.getTasks().size()); + //TraceManager.addDev("Number of tasks after remove fork/join: " + tmlm.getTasks().size()); // We map the forked tasks to their origin node, and the join ones to their destination node @@ -739,16 +739,16 @@ public class TMLMapping<E> { if ((origin != null) && (isTaskMapped(origin))) { HwExecutionNode node = (HwExecutionNode)(getHwNodeOf(origin)); if (node != null) { - TraceManager.addDev("\n\nMapping fork task " + task.getName() + " to " + node.getName()); + //TraceManager.addDev("\n\nMapping fork task " + task.getName() + " to " + node.getName()); addTaskToHwExecutionNode(task, node); } } } } else { - TraceManager.addDev("\n\nFORKTASK is mapped: " + task.getName()); + //TraceManager.addDev("\n\nFORKTASK is mapped: " + task.getName()); } } else { - TraceManager.addDev("Non fork task found: " + task.getName()); + //TraceManager.addDev("Non fork task found: " + task.getName()); } if (task.getName().startsWith("JOINTASK_")) { if (!isTaskMapped(task)) { diff --git a/src/main/java/tmltranslator/TMLModeling.java b/src/main/java/tmltranslator/TMLModeling.java index b33aa9804d2f6df39af7663e8f442676b490ba72..bc1191c1cb27ac1729d04ef237fa90185c74688b 100755 --- a/src/main/java/tmltranslator/TMLModeling.java +++ b/src/main/java/tmltranslator/TMLModeling.java @@ -2285,9 +2285,9 @@ public class TMLModeling<E> { writes[nb-1].addNext(stop); } - // Channels with severals origins and one destination + // Channels with several origins and one destination // Add a task at receiving side - // Channel is tranformed into something else ... + // Channel is transformed into something else ... // Same for events. public void removeJoins() { // Create new basic channels and tasks @@ -2305,7 +2305,7 @@ public class TMLModeling<E> { // Create new basic events and tasks ArrayList<TMLEvent> newEvents = new ArrayList<TMLEvent>(); for(TMLEvent evt: events) { - TraceManager.addDev("Event:" + evt); + //TraceManager.addDev("Event:" + evt); if (evt.isAJoinEvent()) { TraceManager.addDev("Removing join of this event"); removeJoinEvent(evt, newEvents); diff --git a/src/main/java/tmltranslator/TMLSyntaxChecking.java b/src/main/java/tmltranslator/TMLSyntaxChecking.java index c96c63e00fad7b9f3505ab24cb9f3aff6abd63be..dad18cca5b160eb66c390bc56b5d24edc2a48cdc 100755 --- a/src/main/java/tmltranslator/TMLSyntaxChecking.java +++ b/src/main/java/tmltranslator/TMLSyntaxChecking.java @@ -219,7 +219,7 @@ public class TMLSyntaxChecking { if (inP != null) { addError(null, null,SAME_PORT_NAME + ": " + _p.getName() + "(" + origin + " ports)", TMLError.ERROR_STRUCTURE); } else { - TraceManager.addDev("Adding port with name=" + _p.getName() + " for kind=" + origin); + //TraceManager.addDev("Adding port with name=" + _p.getName() + " for kind=" + origin); map.put(_p.getName(), _p); } } diff --git a/src/main/java/tmltranslator/tomappingsystemc2/DiploSimulatorCodeGenerator.java b/src/main/java/tmltranslator/tomappingsystemc2/DiploSimulatorCodeGenerator.java index 5a4a9ea0da7460caf77e2828efe209793d26470c..9b1d60cefa8ca26b6da5a3512943beb82c722c68 100644 --- a/src/main/java/tmltranslator/tomappingsystemc2/DiploSimulatorCodeGenerator.java +++ b/src/main/java/tmltranslator/tomappingsystemc2/DiploSimulatorCodeGenerator.java @@ -37,8 +37,6 @@ */ - - package tmltranslator.tomappingsystemc2; import myutil.Conversion; @@ -55,8 +53,9 @@ import java.util.*; /** * Class TML2MappingSystemC * Creation: 03/09/2007 - * @version 1.1 03/09/2007 + * * @author Daniel Knorreck, Dominique Blouin, Ludovic Apvrille + * @version 1.1 03/09/2007 */ public class DiploSimulatorCodeGenerator implements IDiploSimulatorCodeGenerator { @@ -86,7 +85,7 @@ public class DiploSimulatorCodeGenerator implements IDiploSimulatorCodeGenerator private final NamesGenerationHelper namesGen; DiploSimulatorCodeGenerator(TMLModeling<?> _tmlm) { - this( _tmlm.getDefaultMapping() ); + this(_tmlm.getDefaultMapping()); tmlmodeling = _tmlm; tmlmodeling.removeForksAndJoins(); @@ -100,11 +99,11 @@ public class DiploSimulatorCodeGenerator implements IDiploSimulatorCodeGenerator // tmlmapping.removeForksAndJoins(); // tmlmapping.makeMinimumMapping(); // tepeTranslator = new SystemCTEPE(new ArrayList<TEPE>(), this); - this( _tmlmapping, null, new ArrayList<TEPE>() ); + this(_tmlmapping, null, new ArrayList<TEPE>()); } DiploSimulatorCodeGenerator(TMLModeling<?> _tmlm, List<EBRDD> _ebrdds, List<TEPE> _tepes) { - this( _tmlm.getDefaultMapping(), _ebrdds, _tepes ); + this(_tmlm.getDefaultMapping(), _ebrdds, _tepes); tmlmodeling = _tmlm; // tmlmapping = tmlmodeling.getDefaultMapping(); @@ -114,14 +113,14 @@ public class DiploSimulatorCodeGenerator implements IDiploSimulatorCodeGenerator DiploSimulatorCodeGenerator(TMLMapping<?> _tmlmapping, List<EBRDD> _ebrdds, List<TEPE> _tepes) { tmlmapping = _tmlmapping; - if ( tmlmapping == null ) { - throw new IllegalArgumentException( "TML Mapping is NULL." ); + if (tmlmapping == null) { + throw new IllegalArgumentException("TML Mapping is NULL."); } tmlmapping.handleCPs(); tmlmapping.removeForksAndJoins(); tmlmapping.makeMinimumMapping(); - tepeTranslator = new SystemCTEPE(_tepes, this ); + tepeTranslator = new SystemCTEPE(_tepes, this); namesGen = NamesGenerationHelper.INSTANCE; } @@ -160,8 +159,8 @@ public class DiploSimulatorCodeGenerator implements IDiploSimulatorCodeGenerator private void generateMakefileSrc() { src = "SRCS = "; - for(TMLTask mst: tmlmapping.getMappedTasks()) { - src += namesGen.cppFileName( mst.getName() ) + SPACE; + for (TMLTask mst : tmlmapping.getMappedTasks()) { + src += namesGen.cppFileName(mst.getName()) + SPACE; } //for(EBRDD ebrdd: ebrdds){ // src += ebrdd.getName() + ".cpp "; @@ -181,9 +180,9 @@ public class DiploSimulatorCodeGenerator implements IDiploSimulatorCodeGenerator header += "#include <SimComponents.h>\n#include <Server.h>\n#include <SimServSyncInfo.h>\n#include <ListenersSimCmd.h>\n"; // Generate tasks header - for(TMLTask mst: tmlmapping.getMappedTasks()) { + for (TMLTask mst : tmlmapping.getMappedTasks()) { //header += "#include <" + mst.getReference() + ".h>" + CR; - header += "#include " + NamesGenerationHelper.LEFT_ANGLE_RACKET + namesGen.headerFileName( mst.getName() ) + NamesGenerationHelper.RIGHT_ANGLE_RACKET + CR; + header += "#include " + NamesGenerationHelper.LEFT_ANGLE_RACKET + namesGen.headerFileName(mst.getName()) + NamesGenerationHelper.RIGHT_ANGLE_RACKET + CR; } //for(EBRDD ebrdd: ebrdds){ // header += "#include <" + ebrdd.getName() + ".h>" + CR; @@ -196,55 +195,53 @@ public class DiploSimulatorCodeGenerator implements IDiploSimulatorCodeGenerator // Declaration of HW nodes declaration += "//Declaration of CPUs" + CR; - for(HwNode node: tmlmapping.getTMLArchitecture().getHwNodes()) { - if ( node instanceof HwCPU ) { + for (HwNode node : tmlmapping.getTMLArchitecture().getHwNodes()) { + if (node instanceof HwCPU) { final HwCPU exNode = (HwCPU) node; final String schedulerInstName; - if ( exNode.getType().equals( "CPURRPB" ) ) { - schedulerInstName = namesGen.prioSchedulerInstanceName( exNode ); - declaration += "PrioScheduler* " + schedulerInstName + " = new PrioScheduler(\"" + namesGen.prioSchedulerName( exNode ) + "\", 0)" + SCCR; - } - else { + if (exNode.getType().equals("CPURRPB")) { + schedulerInstName = namesGen.prioSchedulerInstanceName(exNode); + declaration += "PrioScheduler* " + schedulerInstName + " = new PrioScheduler(\"" + namesGen.prioSchedulerName(exNode) + "\", 0)" + SCCR; + } else { //tmlmapping.getTMLArchitecture().getMasterClockFrequency() * exNode.sliceTime //declaration += "RRScheduler* " + exNode.getName() + "_scheduler = new RRScheduler(\"" + exNode.getName() + "_RRSched\", 0, 5, " + (int) Math.ceil(((float)exNode.execiTime)*(1+((float)exNode.branchingPredictionPenalty)/100)) + " ) " + SCCR; - schedulerInstName = namesGen.rrSchedulerInstanceName( exNode ); - declaration += "RRScheduler* " + schedulerInstName + " = new RRScheduler(\"" + namesGen.rrSchedulerName( exNode ) + "\", 0, " + (tmlmapping.getTMLArchitecture().getMasterClockFrequency() * exNode.sliceTime) + ", " + (int) Math.ceil((float)(exNode.clockRatio * Math.max(exNode.execiTime,exNode.execcTime) * (exNode.branchingPredictionPenalty * exNode.pipelineSize +100 - exNode.branchingPredictionPenalty))/100) + " ) " + SCCR; + schedulerInstName = namesGen.rrSchedulerInstanceName(exNode); + declaration += "RRScheduler* " + schedulerInstName + " = new RRScheduler(\"" + namesGen.rrSchedulerName(exNode) + "\", 0, " + (tmlmapping.getTMLArchitecture().getMasterClockFrequency() * exNode.sliceTime) + ", " + (int) Math.ceil((float) (exNode.clockRatio * Math.max(exNode.execiTime, exNode.execcTime) * (exNode.branchingPredictionPenalty * exNode.pipelineSize + 100 - exNode.branchingPredictionPenalty)) / 100) + " ) " + SCCR; } - TraceManager.addDev("cores " + exNode.nbOfCores); + //TraceManager.addDev("cores " + exNode.nbOfCores); - for(int cores = 0; cores < exNode.nbOfCores; cores++ ) { - final String cpuInstName = namesGen.cpuInstanceName( exNode, cores ); - declaration += "CPU* " + cpuInstName + " = new SingleCoreCPU(" + exNode.getID() + ", \"" + namesGen.cpuName( exNode, cores ) + "\", " + schedulerInstName + ", "; - declaration += exNode.clockRatio + ", " + exNode.execiTime + ", " + exNode.execcTime + ", " + exNode.pipelineSize + ", " + exNode.taskSwitchingTime + ", " + exNode.branchingPredictionPenalty + ", " + exNode.goIdleTime + ", " + exNode.maxConsecutiveIdleCycles + ", " + exNode.byteDataSize + ")" + SCCR; + for (int cores = 0; cores < exNode.nbOfCores; cores++) { + final String cpuInstName = namesGen.cpuInstanceName(exNode, cores); + declaration += "CPU* " + cpuInstName + " = new SingleCoreCPU(" + exNode.getID() + ", \"" + namesGen.cpuName(exNode, cores) + "\", " + schedulerInstName + ", "; + declaration += exNode.clockRatio + ", " + exNode.execiTime + ", " + exNode.execcTime + ", " + exNode.pipelineSize + ", " + exNode.taskSwitchingTime + ", " + exNode.branchingPredictionPenalty + ", " + exNode.goIdleTime + ", " + exNode.maxConsecutiveIdleCycles + ", " + exNode.byteDataSize + ")" + SCCR; - if ( cores != 0 ) { + if (cores != 0) { declaration += cpuInstName + "->setScheduler(" + schedulerInstName + ",false)" + SCCR; } - declaration += "addCPU(" + cpuInstName + ")"+ SCCR; + declaration += "addCPU(" + cpuInstName + ")" + SCCR; } - } - else if ( node instanceof HwA ) { + } else if (node instanceof HwA) { final HwA hwaNode = (HwA) node; - final String schedulerInstName = namesGen.rrSchedulerInstanceName( hwaNode ); - final String schedulerName = namesGen.rrSchedulerName( hwaNode ); - declaration += "RRScheduler* " + schedulerInstName + " = new RRScheduler(\"" + schedulerName + "\", 0, " + (tmlmapping.getTMLArchitecture().getMasterClockFrequency() * HwA.DEFAULT_SLICE_TIME) + ", " + (int) Math.ceil((float)(hwaNode.clockRatio * Math.max(hwaNode.execiTime,hwaNode.execcTime) * (HwA.DEFAULT_BRANCHING_PREDICTION_PENALTY * HwA.DEFAULT_PIPELINE_SIZE +100 - HwA.DEFAULT_BRANCHING_PREDICTION_PENALTY))/100) + " ) " + SCCR; + final String schedulerInstName = namesGen.rrSchedulerInstanceName(hwaNode); + final String schedulerName = namesGen.rrSchedulerName(hwaNode); + declaration += "RRScheduler* " + schedulerInstName + " = new RRScheduler(\"" + schedulerName + "\", 0, " + (tmlmapping.getTMLArchitecture().getMasterClockFrequency() * HwA.DEFAULT_SLICE_TIME) + ", " + (int) Math.ceil((float) (hwaNode.clockRatio * Math.max(hwaNode.execiTime, hwaNode.execcTime) * (HwA.DEFAULT_BRANCHING_PREDICTION_PENALTY * HwA.DEFAULT_PIPELINE_SIZE + 100 - HwA.DEFAULT_BRANCHING_PREDICTION_PENALTY)) / 100) + " ) " + SCCR; // DB: Issue #21 Why a for loop??? //for (int cores=0; cores<1; cores++){ - final String hwaInstName = namesGen.hwAccInstanceName( hwaNode ); - declaration += "CPU* " + hwaInstName + " = new SingleCoreCPU(" + hwaNode.getID() + ", \"" + namesGen.hwAccName( hwaNode ) + "\", " + schedulerInstName + ", "; + final String hwaInstName = namesGen.hwAccInstanceName(hwaNode); + declaration += "CPU* " + hwaInstName + " = new SingleCoreCPU(" + hwaNode.getID() + ", \"" + namesGen.hwAccName(hwaNode) + "\", " + schedulerInstName + ", "; - declaration += hwaNode.clockRatio + ", " + hwaNode.execiTime + ", " + hwaNode.execcTime + ", " + HwA.DEFAULT_PIPELINE_SIZE + ", " + HwA.DEFAULT_TASK_SWITCHING_TIME + ", " + HwA.DEFAULT_BRANCHING_PREDICTION_PENALTY + ", " + HwA.DEFAULT_GO_IDLE_TIME + ", " + HwA.DEFAULT_MAX_CONSECUTIVE_IDLE_CYCLES + ", " + hwaNode.byteDataSize + ")" + SCCR; + declaration += hwaNode.clockRatio + ", " + hwaNode.execiTime + ", " + hwaNode.execcTime + ", " + HwA.DEFAULT_PIPELINE_SIZE + ", " + HwA.DEFAULT_TASK_SWITCHING_TIME + ", " + HwA.DEFAULT_BRANCHING_PREDICTION_PENALTY + ", " + HwA.DEFAULT_GO_IDLE_TIME + ", " + HwA.DEFAULT_MAX_CONSECUTIVE_IDLE_CYCLES + ", " + hwaNode.byteDataSize + ")" + SCCR; // DB: Issue #21 TODO: Should there be a scheduler?? Given the for loop, cores is always 0 so this code is never executed // if (cores!=0) { // declaration+= cpuInstName + "->setScheduler(" + schedulerInstName + ",false)" + SCCR; // } - declaration += "addCPU(" + hwaInstName + ")"+ SCCR; + declaration += "addCPU(" + hwaInstName + ")" + SCCR; //} } } @@ -254,22 +251,21 @@ public class DiploSimulatorCodeGenerator implements IDiploSimulatorCodeGenerator // Declaration of Buses declaration += "//Declaration of Buses" + CR; - for( final HwNode node: tmlmapping.getTMLArchitecture().getHwNodes()) { + for (final HwNode node : tmlmapping.getTMLArchitecture().getHwNodes()) { if (node instanceof HwBus) { final HwBus thisBus = (HwBus) node; - for( int i=0; i< thisBus.pipelineSize; i++ ) { - final String busInstName = namesGen.busInstanceName( thisBus, i ); - declaration += "Bus* " + busInstName + " = new Bus("+ node.getID() + ",\"" + namesGen.busName( thisBus, i ) + "\",0, 100, "+ thisBus.byteDataSize + ", " + node.clockRatio + ","; + for (int i = 0; i < thisBus.pipelineSize; i++) { + final String busInstName = namesGen.busInstanceName(thisBus, i); + declaration += "Bus* " + busInstName + " = new Bus(" + node.getID() + ",\"" + namesGen.busName(thisBus, i) + "\",0, 100, " + thisBus.byteDataSize + ", " + node.clockRatio + ","; - if ( thisBus.arbitration==HwBus.CAN ) { + if (thisBus.arbitration == HwBus.CAN) { declaration += Boolean.TRUE.toString(); - } - else { + } else { declaration += Boolean.FALSE.toString(); } - declaration += ");\naddBus(" + busInstName + ")"+ SCCR; + declaration += ");\naddBus(" + busInstName + ")" + SCCR; } } } @@ -279,12 +275,12 @@ public class DiploSimulatorCodeGenerator implements IDiploSimulatorCodeGenerator // Declaration of Bridges declaration += "//Declaration of Bridges" + CR; - for(HwNode node: tmlmapping.getTMLArchitecture().getHwNodes()) { + for (HwNode node : tmlmapping.getTMLArchitecture().getHwNodes()) { if (node instanceof HwBridge) { final HwBridge bridge = (HwBridge) node; - final String bridgeInstName = namesGen.bridgeInstanceName( bridge ); - declaration+= "Bridge* " + bridgeInstName + " = new Bridge("+ node.getID() + ",\"" + namesGen.bridgeName( bridge ) + "\", " + node.clockRatio + ", " + ((HwBridge)node).bufferByteSize + ")" +SCCR; - declaration += "addBridge("+ bridgeInstName +")"+ SCCR; + final String bridgeInstName = namesGen.bridgeInstanceName(bridge); + declaration += "Bridge* " + bridgeInstName + " = new Bridge(" + node.getID() + ",\"" + namesGen.bridgeName(bridge) + "\", " + node.clockRatio + ", " + ((HwBridge) node).bufferByteSize + ")" + SCCR; + declaration += "addBridge(" + bridgeInstName + ")" + SCCR; } } @@ -293,12 +289,12 @@ public class DiploSimulatorCodeGenerator implements IDiploSimulatorCodeGenerator // Declaration of Memories declaration += "//Declaration of Memories" + CR; - for ( final HwNode node: tmlmapping.getTMLArchitecture().getHwNodes() ) { - if ( node instanceof HwMemory ) { + for (final HwNode node : tmlmapping.getTMLArchitecture().getHwNodes()) { + if (node instanceof HwMemory) { final HwMemory memory = (HwMemory) node; - final String memInstName = namesGen.memoryInstanceName( memory ); - declaration+= "Memory* " + memInstName + " = new Memory("+ node.getID() + ",\"" + namesGen.memoryName( memory ) + "\", " + node.clockRatio + ", " + ((HwMemory)node).byteDataSize + ")" +SCCR; - declaration += "addMem("+ memInstName +")"+ SCCR; + final String memInstName = namesGen.memoryInstanceName(memory); + declaration += "Memory* " + memInstName + " = new Memory(" + node.getID() + ",\"" + namesGen.memoryName(memory) + "\", " + node.clockRatio + ", " + ((HwMemory) node).byteDataSize + ")" + SCCR; + declaration += "addMem(" + memInstName + ")" + SCCR; } } @@ -306,41 +302,39 @@ public class DiploSimulatorCodeGenerator implements IDiploSimulatorCodeGenerator //Declaration of Bus masters declaration += "//Declaration of Bus masters" + CR; - for(HwNode node: tmlmapping.getTMLArchitecture().getHwNodes()){ - if (node instanceof HwExecutionNode || node instanceof HwBridge){ + for (HwNode node : tmlmapping.getTMLArchitecture().getHwNodes()) { + if (node instanceof HwExecutionNode || node instanceof HwBridge) { final List<HwLink> nodeLinks = tmlmapping.getTMLArchitecture().getLinkByHwNode(node); - for( final HwLink link: nodeLinks ) { + for (final HwLink link : nodeLinks) { final int noOfCores; - if ( node instanceof HwCPU ) { - noOfCores = ((HwCPU)node).nbOfCores; - } - else { + if (node instanceof HwCPU) { + noOfCores = ((HwCPU) node).nbOfCores; + } else { noOfCores = 1; } - for ( int cores = 0; cores < noOfCores; cores++ ) { + for (int cores = 0; cores < noOfCores; cores++) { final String nodeInstanceName; - if ( node instanceof HwCPU || node instanceof HwA ) { - nodeInstanceName = namesGen.executionNodeInstanceName( (HwExecutionNode) node, cores ); - } - else { - nodeInstanceName = namesGen.bridgeInstanceName( (HwBridge) node ); + if (node instanceof HwCPU || node instanceof HwA) { + nodeInstanceName = namesGen.executionNodeInstanceName((HwExecutionNode) node, cores); + } else { + nodeInstanceName = namesGen.bridgeInstanceName((HwBridge) node); } - final String busMasterInstName = namesGen.busMasterInstanceName( node, cores, link.bus ); + final String busMasterInstName = namesGen.busMasterInstanceName(node, cores, link.bus); - declaration+= "BusMaster* " + busMasterInstName + " = new BusMaster(\"" + namesGen.busMasterName( node, cores, link.bus ) + "\", " + link.getPriority() + ", " + link.bus.pipelineSize + ", array(" + link.bus.pipelineSize; + declaration += "BusMaster* " + busMasterInstName + " = new BusMaster(\"" + namesGen.busMasterName(node, cores, link.bus) + "\", " + link.getPriority() + ", " + link.bus.pipelineSize + ", array(" + link.bus.pipelineSize; - for(int i=0; i< link.bus.pipelineSize; i++) { - declaration+= ", (SchedulableCommDevice*) " + namesGen.schedComDeviceInstanceName( link.bus, i ); + for (int i = 0; i < link.bus.pipelineSize; i++) { + declaration += ", (SchedulableCommDevice*) " + namesGen.schedComDeviceInstanceName(link.bus, i); } - declaration+= "))" + SCCR; + declaration += "))" + SCCR; - declaration+= nodeInstanceName + "->addBusMaster(" + busMasterInstName + ")" + SCCR; + declaration += nodeInstanceName + "->addBusMaster(" + busMasterInstName + ")" + SCCR; } } } @@ -351,37 +345,37 @@ public class DiploSimulatorCodeGenerator implements IDiploSimulatorCodeGenerator // Declaration of channels declaration += "//Declaration of channels" + CR; - for ( final TMLElement elem : tmlmodeling.getChannels() ) { + for (final TMLElement elem : tmlmodeling.getChannels()) { if (elem instanceof TMLChannel) { - final TMLChannel channel = (TMLChannel)elem; + final TMLChannel channel = (TMLChannel) elem; - final String channelTypeName = namesGen.channelTypeName( channel ); - final String channelInstName = namesGen.channelInstanceName( channel ); + final String channelTypeName = namesGen.channelTypeName(channel); + final String channelInstName = namesGen.channelInstanceName(channel); - declaration += channelTypeName + "* " + channelInstName + " = new " + channelTypeName +"(" + channel.getID() + ",\"" + namesGen.channelName( channel ) + "\"," + channel.getSize() + ","; + declaration += channelTypeName + "* " + channelInstName + " = new " + channelTypeName + "(" + channel.getID() + ",\"" + namesGen.channelName(channel) + "\"," + channel.getSize() + ","; final String param; - switch(channel.getType()) { - case TMLChannel.BRBW: - param= "," + channel.getMax() + ",0"; - break; - case TMLChannel.BRNBW: - param= ",0"; - break; - case TMLChannel.NBRNBW: - default: - param= ""; + switch (channel.getType()) { + case TMLChannel.BRBW: + param = "," + channel.getMax() + ",0"; + break; + case TMLChannel.BRNBW: + param = ",0"; + break; + case TMLChannel.NBRNBW: + default: + param = ""; } declaration += determineRouting(tmlmapping.getHwNodeOf(channel.getOriginTask()), tmlmapping.getHwNodeOf(channel.getDestinationTask()), elem) + param + "," + channel.getPriority(); - if (channel.isLossy() && channel.getType()!=TMLChannel.NBRNBW) { + if (channel.isLossy() && channel.getType() != TMLChannel.NBRNBW) { declaration += "," + channel.getLossPercentage() + "," + channel.getMaxNbOfLoss(); } - declaration += ")"+ SCCR; - declaration += "addChannel("+ channelInstName +")"+ SCCR; + declaration += ")" + SCCR; + declaration += "addChannel(" + channelInstName + ")" + SCCR; } } @@ -390,32 +384,29 @@ public class DiploSimulatorCodeGenerator implements IDiploSimulatorCodeGenerator // Declaration of events declaration += "//Declaration of events" + CR; - for( final TMLEvent evt : tmlmodeling.getEvents() ) { - final String eventTypeName = namesGen.eventTypeName( evt ); + for (final TMLEvent evt : tmlmodeling.getEvents()) { + final String eventTypeName = namesGen.eventTypeName(evt); final String param; if (evt.isInfinite()) { - param= ",0,false,false"; - } - else { + param = ",0,false,false"; + } else { if (evt.isBlocking()) { - param= "," + evt.getMaxSize() + ",0"; - } - else { - param= "," + evt.getMaxSize() + ",0"; + param = "," + evt.getMaxSize() + ",0"; + } else { + param = "," + evt.getMaxSize() + ",0"; } } - final String eventInstName = namesGen.eventInstanceName( evt ); - final String eventName = namesGen.eventName( evt ); + final String eventInstName = namesGen.eventInstanceName(evt); + final String eventName = namesGen.eventName(evt); - if (tmlmapping.isCommNodeMappedOn(evt,null)){ - TraceManager.addDev("Evt: " + evt.getName()); + if (tmlmapping.isCommNodeMappedOn(evt, null)) { + //TraceManager.addDev("Evt: " + evt.getName()); declaration += eventTypeName + "* " + eventInstName + " = new " + eventTypeName + "(" + evt.getID() + ",\"" + eventName + "\"," + determineRouting(tmlmapping.getHwNodeOf(evt.getOriginTask()), tmlmapping.getHwNodeOf(evt.getDestinationTask()), evt) + param; - } - else{ + } else { declaration += eventTypeName + "* " + eventInstName + " = new " + eventTypeName + "(" + evt.getID() + ",\"" + eventName + "\",0,0,0" + param; ///old command } @@ -424,7 +415,7 @@ public class DiploSimulatorCodeGenerator implements IDiploSimulatorCodeGenerator } declaration += ")" + SCCR; - declaration += "addEvent("+ eventInstName +")"+ SCCR; + declaration += "addEvent(" + eventInstName + ")" + SCCR; } declaration += CR; @@ -432,30 +423,29 @@ public class DiploSimulatorCodeGenerator implements IDiploSimulatorCodeGenerator // Declaration of requests declaration += "//Declaration of requests" + CR; - for(TMLTask task: tmlmodeling.getTasks()) { + for (TMLTask task : tmlmodeling.getTasks()) { if (task.isRequested()) { - final String reqChannelInstName = namesGen.requestChannelInstanceName( task ); + final String reqChannelInstName = namesGen.requestChannelInstanceName(task); TMLRequest req = task.getRequest(); - if (tmlmapping.isCommNodeMappedOn(req,null)){ - TraceManager.addDev("Request: " + req.getName()); + if (tmlmapping.isCommNodeMappedOn(req, null)) { + //TraceManager.addDev("Request: " + req.getName()); declaration += "TMLEventBChannel<ParamType," + req.getNbOfParams() + ">* " + reqChannelInstName + " = new TMLEventBChannel<ParamType," + req.getNbOfParams() + ">(" + - req.getID() + ",\"" + reqChannelInstName + "\"," + - determineRouting(tmlmapping.getHwNodeOf(req.getOriginTasks().get(0)), //tmlmapping.getHwNodeOf(req.getDestinationTask()), req) + ",0," + req.getNbOfParams() + ",true)" + SCCR; - tmlmapping.getHwNodeOf(req.getDestinationTask()), req) + ",0,true,false"; - } - else { + req.getID() + ",\"" + reqChannelInstName + "\"," + + determineRouting(tmlmapping.getHwNodeOf(req.getOriginTasks().get(0)), //tmlmapping.getHwNodeOf(req.getDestinationTask()), req) + ",0," + req.getNbOfParams() + ",true)" + SCCR; + tmlmapping.getHwNodeOf(req.getDestinationTask()), req) + ",0,true,false"; + } else { declaration += "TMLEventBChannel<ParamType," + req.getNbOfParams() + ">* " + reqChannelInstName + " = new TMLEventBChannel<ParamType," + req.getNbOfParams() + ">(" + //req.getID() + ",\"reqChannel"+ task.getName() + "\",0,0,0,0," + req.getNbOfParams() + ",true)" + SCCR; - req.getID() + ",\"" + reqChannelInstName + "\",0,0,0,0,true,false"; + req.getID() + ",\"" + reqChannelInstName + "\",0,0,0,0,true,false"; } - if ( req.isLossy() ) { + if (req.isLossy()) { declaration += "," + req.getLossPercentage() + "," + req.getMaxNbOfLoss(); } declaration += ")" + SCCR; - declaration += "addRequest( " + reqChannelInstName +")"+ SCCR; + declaration += "addRequest( " + reqChannelInstName + ")" + SCCR; } } @@ -464,46 +454,44 @@ public class DiploSimulatorCodeGenerator implements IDiploSimulatorCodeGenerator //Set bus schedulers declaration += "//Set bus schedulers" + CR; - for ( final HwNode node : tmlmapping.getTMLArchitecture().getHwNodes() ) { - if ( node instanceof HwBus ) { + for (final HwNode node : tmlmapping.getTMLArchitecture().getHwNodes()) { + if (node instanceof HwBus) { final HwBus bus = (HwBus) node; - final List<HwLink> busLinks= tmlmapping.getTMLArchitecture().getLinkByBus((HwBus)node); - String devices=""; - int numDevices=0; + final List<HwLink> busLinks = tmlmapping.getTMLArchitecture().getLinkByBus((HwBus) node); + String devices = ""; + int numDevices = 0; - if (!busLinks.isEmpty()){ - for ( final HwLink link : busLinks ) { - if ( link.hwnode instanceof HwExecutionNode || link.hwnode instanceof HwBridge ) { + if (!busLinks.isEmpty()) { + for (final HwLink link : busLinks) { + if (link.hwnode instanceof HwExecutionNode || link.hwnode instanceof HwBridge) { // DB Issue #21: This is a bug according to the cast in the for loop line - if ( link.hwnode instanceof HwCPU ) { //|| (link.hwnode instanceof HwA)){ + if (link.hwnode instanceof HwCPU) { //|| (link.hwnode instanceof HwA)){ final HwCPU cpu = (HwCPU) link.hwnode; - for ( int cores = 0; cores < cpu.nbOfCores; cores++ ) { - devices += ", (WorkloadSource*) " + namesGen.workloadSourceInstanceName( cpu, cores, bus ); + for (int cores = 0; cores < cpu.nbOfCores; cores++) { + devices += ", (WorkloadSource*) " + namesGen.workloadSourceInstanceName(cpu, cores, bus); numDevices++; } - } - else { - devices += ", (WorkloadSource*) " + namesGen.workloadSourceInstanceName( link.hwnode, 0, bus ); + } else { + devices += ", (WorkloadSource*) " + namesGen.workloadSourceInstanceName(link.hwnode, 0, bus); numDevices++; } } } - declaration += namesGen.busInstanceName( bus, 0 ) + "->setScheduler( (WorkloadSource*) new "; + declaration += namesGen.busInstanceName(bus, 0) + "->setScheduler( (WorkloadSource*) new "; - if ( bus.arbitration == HwBus.BASIC_ROUND_ROBIN ) { - declaration+="RRScheduler(\"" + namesGen.rrSchedulerName( bus ) + "\", 0, 5, " + (int) Math.ceil(((float)node.clockRatio)/((float)((HwBus)node).byteDataSize)) + ", array("; - } - else { - declaration+="PrioScheduler(\"" + namesGen.prioSchedulerName( bus ) + "\", 0, array("; + if (bus.arbitration == HwBus.BASIC_ROUND_ROBIN) { + declaration += "RRScheduler(\"" + namesGen.rrSchedulerName(bus) + "\", 0, 5, " + (int) Math.ceil(((float) node.clockRatio) / ((float) ((HwBus) node).byteDataSize)) + ", array("; + } else { + declaration += "PrioScheduler(\"" + namesGen.prioSchedulerName(bus) + "\", 0, array("; } - declaration+= numDevices + devices + "), " + numDevices + "))" + SCCR; + declaration += numDevices + devices + "), " + numDevices + "))" + SCCR; } - for( int i = 1; i < bus.pipelineSize; i++ ) { - declaration+= namesGen.busInstanceName( bus, i ) + "->setScheduler(" + namesGen.busInstanceName( bus, 0 ) + "->getScheduler(),false)" +SCCR; + for (int i = 1; i < bus.pipelineSize; i++) { + declaration += namesGen.busInstanceName(bus, i) + "->setScheduler(" + namesGen.busInstanceName(bus, 0) + "->getScheduler(),false)" + SCCR; } } } @@ -521,25 +509,24 @@ public class DiploSimulatorCodeGenerator implements IDiploSimulatorCodeGenerator int[] aStatistics = new int[8]; Set<Integer> mappedChannels = new HashSet<Integer>(); - for ( final TMLTask task: tmlmapping.getMappedTasks() ) { - node= iterator.next(); + for (final TMLTask task : tmlmapping.getMappedTasks()) { + node = iterator.next(); - final String taskClassName = namesGen.taskTypeName( task ); - declaration += taskClassName + "* " + namesGen.taskInstanceName( task ) + " = new " + taskClassName + "("+ task.getID() +","+ task.getPriority() + ",\"" + namesGen.taskName( task ) + "\", array("; + final String taskClassName = namesGen.taskTypeName(task); + declaration += taskClassName + "* " + namesGen.taskInstanceName(task) + " = new " + taskClassName + "(" + task.getID() + "," + task.getPriority() + ",\"" + namesGen.taskName(task) + "\", array("; - if ( node instanceof HwCPU ) { + if (node instanceof HwCPU) { final HwCPU hwCpu = (HwCPU) node; declaration += hwCpu.nbOfCores; - for ( int cores = 0; cores< hwCpu.nbOfCores; cores++ ) { - declaration+= "," + namesGen.cpuInstanceName( hwCpu, cores ); + for (int cores = 0; cores < hwCpu.nbOfCores; cores++) { + declaration += "," + namesGen.cpuInstanceName(hwCpu, cores); } // declaration+= "),1" + CR; - } - else if ( node instanceof HwA ) { + } else if (node instanceof HwA) { final HwA hwAcc = (HwA) node; - declaration+= "1 ," + namesGen.hwAccInstanceName( hwAcc ); + declaration += "1 ," + namesGen.hwAccInstanceName(hwAcc); // DB Issue #22: copy paste error?? This causes class cast exception // declaration+= ((HwCPU)node).nbOfCores; @@ -549,40 +536,39 @@ public class DiploSimulatorCodeGenerator implements IDiploSimulatorCodeGenerator // } // // declaration+= ")," + ((HwCPU)node).nbOfCores + CR; - } - else { - throw new UnsupportedOperationException( "Not implemented for " + node.getClass().getSimpleName() + "!" ); + } else { + throw new UnsupportedOperationException("Not implemented for " + node.getClass().getSimpleName() + "!"); } - declaration+= "), 1" + CR; + declaration += "), 1" + CR; - final List<TMLChannel> channels = new ArrayList<TMLChannel>( tmlmodeling.getChannels( task ) ); - final List<TMLEvent> events = new ArrayList<TMLEvent>( tmlmodeling.getEvents( task ) ); - final List<TMLRequest> requests = new ArrayList<TMLRequest>( tmlmodeling.getRequests( task ) ); + final List<TMLChannel> channels = new ArrayList<TMLChannel>(tmlmodeling.getChannels(task)); + final List<TMLEvent> events = new ArrayList<TMLEvent>(tmlmodeling.getEvents(task)); + final List<TMLRequest> requests = new ArrayList<TMLRequest>(tmlmodeling.getRequests(task)); final MappedSystemCTask mst = new MappedSystemCTask(task, channels, events, requests, tmlmapping, mappedChannels); tasks.add(mst); - for( final TMLChannel channelb : channels ) { - declaration += "," + namesGen.channelInstanceName( channelb ) + CR; + for (final TMLChannel channelb : channels) { + declaration += "," + namesGen.channelInstanceName(channelb) + CR; } - for( final TMLEvent evt : events) { - declaration += "," + namesGen.eventInstanceName( evt ) + CR; + for (final TMLEvent evt : events) { + declaration += "," + namesGen.eventInstanceName(evt) + CR; } - for( final TMLRequest req: requests ) { - if ( req.isAnOriginTask( task ) ) { - declaration+=", " + namesGen.requestChannelInstanceName( req.getDestinationTask() ) + CR; + for (final TMLRequest req : requests) { + if (req.isAnOriginTask(task)) { + declaration += ", " + namesGen.requestChannelInstanceName(req.getDestinationTask()) + CR; } } - if ( task.isRequested() ) { - declaration += "," + namesGen.requestChannelInstanceName( task ) + CR; + if (task.isRequested()) { + declaration += "," + namesGen.requestChannelInstanceName(task) + CR; } declaration += ")" + SCCR; - declaration += "addTask(" + namesGen.taskInstanceName( task ) +")"+ SCCR; + declaration += "addTask(" + namesGen.taskInstanceName(task) + ")" + SCCR; } declaration += "}\n\n"; @@ -594,7 +580,7 @@ public class DiploSimulatorCodeGenerator implements IDiploSimulatorCodeGenerator declaration += tepeTranslator.getCode(); //Generation of tasks - for(MappedSystemCTask task: tasks){ + for (MappedSystemCTask task : tasks) { task.determineCheckpoints(aStatistics); task.generateSystemC(debug, optimize); } @@ -602,12 +588,13 @@ public class DiploSimulatorCodeGenerator implements IDiploSimulatorCodeGenerator //Declaration of TEPEs continued declaration += CR; declaration += "}\n};\n\n" + tepeTranslator.getEqFuncs(); - declaration +="#include <main.h>\n"; + declaration += "#include <main.h>\n"; - if (aStatistics[0]!=0) TraceManager.addDev("Global gain variables " + 100 * aStatistics[1] / aStatistics[0]); - if (aStatistics[2]!=0) TraceManager.addDev("Global gain Channels " + 100 * aStatistics[3] / aStatistics[2]); - if (aStatistics[4]!=0) TraceManager.addDev("Global gain events " + 100 * aStatistics[5] / aStatistics[4]); - if (aStatistics[6]!=0) TraceManager.addDev("Global gain checkpoints " + 100 * aStatistics[7] / aStatistics[6]); + //if (aStatistics[0] != 0) TraceManager.addDev("Global gain variables " + 100 * aStatistics[1] / aStatistics[0]); + //if (aStatistics[2] != 0) TraceManager.addDev("Global gain Channels " + 100 * aStatistics[3] / aStatistics[2]); + //if (aStatistics[4] != 0) TraceManager.addDev("Global gain events " + 100 * aStatistics[5] / aStatistics[4]); + //if (aStatistics[6] != 0) + // TraceManager.addDev("Global gain checkpoints " + 100 * aStatistics[7] / aStatistics[6]); //Declaration of EBRDDs /*declaration += "//Declaration of EBRDDs" + CR; @@ -617,12 +604,12 @@ public class DiploSimulatorCodeGenerator implements IDiploSimulatorCodeGenerator }*/ } - private int extractPath( final List<HwCommunicationNode> path, - final StrWrap masters, - final StrWrap slaves, - final HwNode startNode, - final HwNode destNode, - final boolean reverseIn ) { + private int extractPath(final List<HwCommunicationNode> path, + final StrWrap masters, + final StrWrap slaves, + final HwNode startNode, + final HwNode destNode, + final boolean reverseIn) { // String firstPart=""; HwNode firstNode = null; int masterCount = 0; @@ -630,46 +617,41 @@ public class DiploSimulatorCodeGenerator implements IDiploSimulatorCodeGenerator if (reverseIn) { slaves.str += ",static_cast<Slave*>(0)"; - } - else { + } else { //firstPart=startNode.getName() + "0"; firstNode = startNode; } - for( final HwCommunicationNode commElem : path ) { - if ( commElem instanceof HwMemory ) { + for (final HwCommunicationNode commElem : path) { + if (commElem instanceof HwMemory) { reverse = true; - final String memoryInstName = namesGen.memoryInstanceName( (HwMemory) commElem ); + final String memoryInstName = namesGen.memoryInstanceName((HwMemory) commElem); slaves.str += ",static_cast<Slave*>(" + memoryInstName + "),static_cast<Slave*>(" + memoryInstName + ")"; firstNode = null; // firstPart = ""; - } - else { - if ( reverse ) { - if ( firstNode == null ) { + } else { + if (reverse) { + if (firstNode == null) { // if ( firstPart.length()==0 ){ firstNode = commElem; // firstPart=commElem.getName(); - } - else { - masters.str += "," + namesGen.busMasterInstanceName( commElem, 0, (HwBus) firstNode ); + } else { + masters.str += "," + namesGen.busMasterInstanceName(commElem, 0, (HwBus) firstNode); // masters.str += "," + commElem.getName() + "_" + firstPart + "_Master"; masterCount++; - slaves.str += ",static_cast<Slave*>(" + namesGen.communicationNodeInstanceName( commElem, 0 ) + ")"; + slaves.str += ",static_cast<Slave*>(" + namesGen.communicationNodeInstanceName(commElem, 0) + ")"; firstNode = null; //firstPart=""; } - } - else { - if ( firstNode == null ) { + } else { + if (firstNode == null) { // if ( firstPart.length()==0 ){ firstNode = commElem; - slaves.str += ",static_cast<Slave*>(" + namesGen.communicationNodeInstanceName( commElem, 0 ) + ")"; + slaves.str += ",static_cast<Slave*>(" + namesGen.communicationNodeInstanceName(commElem, 0) + ")"; // firstPart = commElem.getName(); // slaves.str+= ",static_cast<Slave*>(" + firstPart + ")"; - } - else { - masters.str += "," + namesGen.busMasterInstanceName( firstNode, 0, (HwBus) commElem); + } else { + masters.str += "," + namesGen.busMasterInstanceName(firstNode, 0, (HwBus) commElem); // masters.str+= "," + firstPart + "_" + commElem.getName() + "_Master"; masterCount++; firstNode = null; @@ -679,19 +661,19 @@ public class DiploSimulatorCodeGenerator implements IDiploSimulatorCodeGenerator } } - if ( reverse ) { - masters.str += "," + namesGen.busMasterInstanceName( destNode, 0, (HwBus) firstNode ); + if (reverse) { + masters.str += "," + namesGen.busMasterInstanceName(destNode, 0, (HwBus) firstNode); // masters.str+= "," + destNode.getName() + "0_" + firstPart + "_Master"; - return masterCount + 1 ; + return masterCount + 1; } slaves.str += ",static_cast<Slave*>(0)"; - return - masterCount; + return -masterCount; } - private String determineRouting( HwNode startNode, HwNode destNode, TMLElement commElemToRoute ){ + private String determineRouting(HwNode startNode, HwNode destNode, TMLElement commElemToRoute) { //TraceManager.addDev( "Determine routing from " + startNode.getName() + " to " + destNode.getName() ); StrWrap masters = new StrWrap(); @@ -700,8 +682,8 @@ public class DiploSimulatorCodeGenerator implements IDiploSimulatorCodeGenerator List<HwCommunicationNode> path = new LinkedList<HwCommunicationNode>(); List<HwCommunicationNode> commNodes = new LinkedList<HwCommunicationNode>(); - for( HwNode node: tmlmapping.getTMLArchitecture().getHwNodes() ) { - if( node instanceof HwCommunicationNode ) { + for (HwNode node : tmlmapping.getTMLArchitecture().getHwNodes()) { + if (node instanceof HwCommunicationNode) { commNodes.add((HwCommunicationNode) node); } } @@ -712,99 +694,97 @@ public class DiploSimulatorCodeGenerator implements IDiploSimulatorCodeGenerator // //TraceManager.addDev( "startNode: " + startNode.getName() ); // } - HwMemory memory = getMemConnectedToBusChannelMapped( commNodes, null, commElemToRoute ); + HwMemory memory = getMemConnectedToBusChannelMapped(commNodes, null, commElemToRoute); - if( memory == null ) { - TraceManager.addDev( "no memories to map" ); - exploreBuses( 0, commNodes, path, startNode, destNode, commElemToRoute ); - } - else { + if (memory == null) { + //TraceManager.addDev("no memories to map"); + exploreBuses(0, commNodes, path, startNode, destNode, commElemToRoute); + } else { final List<HwCommunicationNode> commNodes2 = new LinkedList<HwCommunicationNode>(commNodes); - if( !exploreBuses( 0, commNodes, path, startNode, memory, commElemToRoute ) ) { - TraceManager.addDev("NO route to " + memory.getName() + "found!!!!!!!!!!!!!!!!!!!!!!!!!!"); + if (!exploreBuses(0, commNodes, path, startNode, memory, commElemToRoute)) { + //TraceManager.addDev("NO route to " + memory.getName() + "found!!!!!!!!!!!!!!!!!!!!!!!!!!"); } - path.add( memory ); + path.add(memory); - exploreBuses( 0, commNodes2, path, memory, destNode, commElemToRoute ); + exploreBuses(0, commNodes2, path, memory, destNode, commElemToRoute); } - int hopNum = extractPath( path, masters, slaves, startNode, destNode, false ); + int hopNum = extractPath(path, masters, slaves, startNode, destNode, false); - if ( hopNum < 0 ) { - hopNum = extractPath( path, masters, slaves, destNode, destNode, true ) - hopNum; + if (hopNum < 0) { + hopNum = extractPath(path, masters, slaves, destNode, destNode, true) - hopNum; } - TraceManager.addDev(commElemToRoute.getName() + " is mapped on:"); + //TraceManager.addDev(commElemToRoute.getName() + " is mapped on:"); - for(HwCommunicationNode commElem:path){ + /*for (HwCommunicationNode commElem : path) { TraceManager.addDev(commElem.getName()); - } + }*/ - TraceManager.addDev("number of elements: " + hopNum); - TraceManager.addDev("masters: " + masters.str); - TraceManager.addDev("slaves: " + slaves.str); + //TraceManager.addDev("number of elements: " + hopNum); + //TraceManager.addDev("masters: " + masters.str); + //TraceManager.addDev("slaves: " + slaves.str); return hopNum + ",array(" + hopNum + masters.str + "),array(" + hopNum + slaves.str + ")"; } - private boolean exploreBuses( final int depth, - final List<HwCommunicationNode> commNodes, - final List<HwCommunicationNode> path, - final HwNode startNode, - final HwNode destNode, - final TMLElement commElemToRoute ) { + private boolean exploreBuses(final int depth, + final List<HwCommunicationNode> commNodes, + final List<HwCommunicationNode> path, + final HwNode startNode, + final HwNode destNode, + final TMLElement commElemToRoute) { assert startNode != null : "Parameter 'startNode' should not be null."; //first called with Maping:getCommunicationNodes List<HwCommunicationNode> nodesToExplore; - TraceManager.addDev("No of comm nodes " + commNodes.size()); - TraceManager.addDev("startNode=" + startNode); + //TraceManager.addDev("No of comm nodes " + commNodes.size()); + //TraceManager.addDev("startNode=" + startNode); boolean busExploreMode = ((depth & 1) == 0); - if ( busExploreMode ) { - TraceManager.addDev("search for buses connected to " + startNode.getName()); - nodesToExplore=getBusesConnectedToNode(commNodes, startNode); - } - else { - TraceManager.addDev("search for bridges connected to: " + startNode.getName()); - nodesToExplore=getBridgesConnectedToBus(commNodes, (HwBus)startNode); + if (busExploreMode) { + //TraceManager.addDev("search for buses connected to " + startNode.getName()); + nodesToExplore = getBusesConnectedToNode(commNodes, startNode); + } else { + //TraceManager.addDev("search for bridges connected to: " + startNode.getName()); + nodesToExplore = getBridgesConnectedToBus(commNodes, (HwBus) startNode); } - TraceManager.addDev("no of elements found: " + nodesToExplore.size()); + //TraceManager.addDev("no of elements found: " + nodesToExplore.size()); - for(HwCommunicationNode currNode:nodesToExplore){ + for (HwCommunicationNode currNode : nodesToExplore) { //memory = null; - if (busExploreMode){ + if (busExploreMode) { //memory = getMemConnectedToBusChannelMapped(commNodes, (HwBus)currNode, commElemToRoute); - if(isBusConnectedToNode(currNode, destNode)){ - TraceManager.addDev(currNode.getName() + " is last node"); + if (isBusConnectedToNode(currNode, destNode)) { + //TraceManager.addDev(currNode.getName() + " is last node"); path.add(currNode); //if (memory!=null) path.add(memory); commNodes.remove(currNode); return true; } } - if(tmlmapping.isCommNodeMappedOn(commElemToRoute, currNode)){ - TraceManager.addDev(currNode.getName() + " mapping found for " + commElemToRoute.getName()); + if (tmlmapping.isCommNodeMappedOn(commElemToRoute, currNode)) { + //TraceManager.addDev(currNode.getName() + " mapping found for " + commElemToRoute.getName()); path.add(currNode); //if (memory!=null) path.add(memory); commNodes.remove(currNode); - if (exploreBuses(depth+1, commNodes, path, currNode, destNode, commElemToRoute)) return true; + if (exploreBuses(depth + 1, commNodes, path, currNode, destNode, commElemToRoute)) return true; path.remove(currNode); //if (memory!=null) path.remove(memory); commNodes.add(currNode); } } - for(HwCommunicationNode currNode:nodesToExplore){ + for (HwCommunicationNode currNode : nodesToExplore) { //if (busExploreMode) memory = getMemConnectedToBusChannelMapped(commNodes, (HwBus)currNode, commElemToRoute); else memory=null; path.add(currNode); //if (memory!=null) path.add(memory); commNodes.remove(currNode); //for (int i=0; i<path.size(); i++) System.out.print(" "); - TraceManager.addDev(currNode.getName()); - if (exploreBuses(depth+1, commNodes, path, currNode, destNode, commElemToRoute)) return true; + //TraceManager.addDev(currNode.getName()); + if (exploreBuses(depth + 1, commNodes, path, currNode, destNode, commElemToRoute)) return true; path.remove(currNode); //if (memory!=null) path.remove(memory); commNodes.add(currNode); @@ -812,55 +792,58 @@ public class DiploSimulatorCodeGenerator implements IDiploSimulatorCodeGenerator return false; } - private HwMemory getMemConnectedToBusChannelMapped( List<HwCommunicationNode> _commNodes, HwBus _bus, TMLElement _channel ) { - for( HwCommunicationNode commNode: _commNodes ) { - if( commNode instanceof HwMemory ) { - if( _bus != null ) TraceManager.addDev(commNode.getName() + " connected to bus " + _bus.getName() + ": " + tmlmapping.getTMLArchitecture().isNodeConnectedToBus(commNode, _bus)); - TraceManager.addDev(_channel.getName() + " is mapped onto " + commNode.getName() + ": " + tmlmapping.isCommNodeMappedOn(_channel,commNode)); - if( ( _bus == null || tmlmapping.getTMLArchitecture().isNodeConnectedToBus( commNode, _bus ) ) - && tmlmapping.isCommNodeMappedOn( _channel, commNode ) ) { - return (HwMemory)commNode; + private HwMemory getMemConnectedToBusChannelMapped(List<HwCommunicationNode> _commNodes, HwBus _bus, TMLElement _channel) { + for (HwCommunicationNode commNode : _commNodes) { + if (commNode instanceof HwMemory) { + if (_bus != null) { + //TraceManager.addDev(commNode.getName() + " connected to bus " + _bus.getName() + ": " + tmlmapping.getTMLArchitecture().isNodeConnectedToBus(commNode, _bus)); + } + //TraceManager.addDev(_channel.getName() + " is mapped onto " + commNode.getName() + ": " + tmlmapping.isCommNodeMappedOn(_channel, commNode)); + if ((_bus == null || tmlmapping.getTMLArchitecture().isNodeConnectedToBus(commNode, _bus)) + && tmlmapping.isCommNodeMappedOn(_channel, commNode)) { + return (HwMemory) commNode; } } } return null; } - private List<HwCommunicationNode> getBusesConnectedToNode(List<HwCommunicationNode> _commNodes, HwNode _node){ + private List<HwCommunicationNode> getBusesConnectedToNode(List<HwCommunicationNode> _commNodes, HwNode _node) { List<HwCommunicationNode> resultList = new LinkedList<HwCommunicationNode>(); - for(HwCommunicationNode commNode: _commNodes){ - if (commNode instanceof HwBus){ - if (tmlmapping.getTMLArchitecture().isNodeConnectedToBus(_node, (HwBus)commNode)) resultList.add(commNode); + for (HwCommunicationNode commNode : _commNodes) { + if (commNode instanceof HwBus) { + if (tmlmapping.getTMLArchitecture().isNodeConnectedToBus(_node, (HwBus) commNode)) + resultList.add(commNode); } } return resultList; } - private List<HwCommunicationNode> getBridgesConnectedToBus( List<HwCommunicationNode> _commNodes, HwBus _bus){ + private List<HwCommunicationNode> getBridgesConnectedToBus(List<HwCommunicationNode> _commNodes, HwBus _bus) { List<HwCommunicationNode> resultList = new LinkedList<HwCommunicationNode>(); - for(HwCommunicationNode commNode: _commNodes){ - if (commNode instanceof HwBridge){ + for (HwCommunicationNode commNode : _commNodes) { + if (commNode instanceof HwBridge) { if (tmlmapping.getTMLArchitecture().isNodeConnectedToBus(commNode, _bus)) resultList.add(commNode); } } return resultList; } - private boolean isBusConnectedToNode(HwCommunicationNode commNode, HwNode node){ - for(HwLink link: tmlmapping.getTMLArchitecture().getHwLinks()) { - if(link.bus==commNode && link.hwnode==node) return true; + private boolean isBusConnectedToNode(HwCommunicationNode commNode, HwNode node) { + for (HwLink link : tmlmapping.getTMLArchitecture().getHwLinks()) { + if (link.bus == commNode && link.hwnode == node) return true; } return false; } private void generateTaskFiles(String path) throws FileException { - for(MappedSystemCTask mst: tasks) { + for (MappedSystemCTask mst : tasks) { mst.saveInFiles(path); } } - public MappedSystemCTask getMappedTaskByName(String iName){ - for(MappedSystemCTask task: tasks){ + public MappedSystemCTask getMappedTaskByName(String iName) { + for (MappedSystemCTask task : tasks) { if (task.getTMLTask().getName().equals(iName)) return task; } return null; diff --git a/src/main/java/tmltranslator/tomappingsystemc2/MappedSystemCTask.java b/src/main/java/tmltranslator/tomappingsystemc2/MappedSystemCTask.java index c8c37c6fc4368208234613366e89c4ee26767179..614e0ecd7f121fdacb964729bd99f3142cfca54b 100644 --- a/src/main/java/tmltranslator/tomappingsystemc2/MappedSystemCTask.java +++ b/src/main/java/tmltranslator/tomappingsystemc2/MappedSystemCTask.java @@ -37,8 +37,6 @@ */ - - package tmltranslator.tomappingsystemc2; import myutil.Conversion; @@ -56,8 +54,9 @@ import java.util.Set; /** * Class MappedSystemCTask * Creation: 24/11/2005 - * @version 1.0 24/11/2005 + * * @author Daniel Knorreck + * @version 1.0 24/11/2005 */ public class MappedSystemCTask { //private TMLModeling tmlm; @@ -69,13 +68,13 @@ public class MappedSystemCTask { private TMLMapping<?> tmlmapping; private int commentNum; private boolean debug; - // private boolean optimize; + // private boolean optimize; private StaticAnalysis _analysis; - private LiveVariableNode _startAnaNode=null; + private LiveVariableNode _startAnaNode = null; private final static String DOTH = ".h"; private final static String DOTCPP = ".cpp"; -// private final static String SYSTEM_INCLUDE = "#include \"systemc.h\""; + // private final static String SYSTEM_INCLUDE = "#include \"systemc.h\""; private final static String CR = "\n"; private final static String CR2 = "\n\n"; private final static String SCCR = ";\n"; @@ -89,18 +88,18 @@ public class MappedSystemCTask { channels = _channels; events = _events; requests = _requests; - tmlmapping=_tmlmapping; + tmlmapping = _tmlmapping; reference = task.getName(); cppcode = ""; hcode = ""; - initCommand=""; - functions=""; - chaining=""; - firstCommand=""; - functionSig=""; - commentText=""; - commentNum=0; - // optimize=false; + initCommand = ""; + functions = ""; + chaining = ""; + firstCommand = ""; + functionSig = ""; + commentText = ""; + commentNum = 0; + // optimize=false; _analysis = new StaticAnalysis(_task, _channels, _events, _requests, _depChannels); _startAnaNode = _analysis.startAnalysis(); @@ -119,14 +118,14 @@ public class MappedSystemCTask { //_startAnaNode = _analysis.startAnalysis(); //_analysis.determineCheckpoints(aStatistics); //NEW debug = _debug; - // optimize=_optimize; + // optimize=_optimize; basicCPPCode(); makeClassCode(); } public void print() { - TraceManager.addDev("task: " + reference + DOTH + hcode); - TraceManager.addDev("task: " + reference + DOTCPP + cppcode); + //TraceManager.addDev("task: " + reference + DOTH + hcode); + //TraceManager.addDev("task: " + reference + DOTCPP + cppcode); } @@ -144,7 +143,7 @@ public class MappedSystemCTask { // H-Code private String basicHCode() { - String code=""; + String code = ""; code += "#ifndef " + reference.toUpperCase() + "__H" + CR; code += "#define " + reference.toUpperCase() + "__H" + CR2; code += "#include <TMLTask.h>\n#include <definitions.h>\n\n"; @@ -166,61 +165,61 @@ public class MappedSystemCTask { cppcode += "#include <" + reference + DOTH + ">" + CR2; } - private void makeClassCode(){ + private void makeClassCode() { makeHeaderClassH(); makeEndClassH(); - cppcode+=reference+ "::" + makeConstructorSignature()+":TMLTask(iID, iPriority,iName,iCPUs,iNumOfCPUs)"+ CR + makeAttributesCode(); - cppcode+=initCommand + CR + "{" + CR; - if (commentNum!=0) cppcode+= "_comment = new std::string[" + commentNum + "]" + SCCR + commentText + CR; - cppcode+= "//generate task variable look-up table"+ CR; - for(TMLAttribute att: task.getAttributes()) { + cppcode += reference + "::" + makeConstructorSignature() + ":TMLTask(iID, iPriority,iName,iCPUs,iNumOfCPUs)" + CR + makeAttributesCode(); + cppcode += initCommand + CR + "{" + CR; + if (commentNum != 0) cppcode += "_comment = new std::string[" + commentNum + "]" + SCCR + commentText + CR; + cppcode += "//generate task variable look-up table" + CR; + for (TMLAttribute att : task.getAttributes()) { //att = (TMLAttribute)(iterator.next()); //code += TMLType.getStringType(att.type.getType()) + " " + att.name; - cppcode += "_varLookUpName[\"" + att.name + "\"]=&" + att.name +SCCR; - cppcode += "_varLookUpID[" + att.getID() + "]=&" + att.name +SCCR; + cppcode += "_varLookUpName[\"" + att.name + "\"]=&" + att.name + SCCR; + cppcode += "_varLookUpID[" + att.getID() + "]=&" + att.name + SCCR; } cppcode += "_varLookUpName[\"rnd__0\"]=&rnd__0" + SCCR + CR; - cppcode+= "//set blocked read task/set blocked write task"+ CR; - for(TMLChannel ch: channels) { - if (ch.getOriginTask()==task) - cppcode+=ch.getExtendedName() + "->setBlockedWriteTask(this)"+SCCR; + cppcode += "//set blocked read task/set blocked write task" + CR; + for (TMLChannel ch : channels) { + if (ch.getOriginTask() == task) + cppcode += ch.getExtendedName() + "->setBlockedWriteTask(this)" + SCCR; else - cppcode+=ch.getExtendedName() + "->setBlockedReadTask(this)"+SCCR; + cppcode += ch.getExtendedName() + "->setBlockedReadTask(this)" + SCCR; } - for(TMLEvent evt: events) { - if (evt.getOriginTask()==task) - cppcode+=evt.getExtendedName() + "->setBlockedWriteTask(this)"+SCCR; + for (TMLEvent evt : events) { + if (evt.getOriginTask() == task) + cppcode += evt.getExtendedName() + "->setBlockedWriteTask(this)" + SCCR; else - cppcode+=evt.getExtendedName() + "->setBlockedReadTask(this)"+SCCR; + cppcode += evt.getExtendedName() + "->setBlockedReadTask(this)" + SCCR; } - if (task.isRequested()) cppcode+="requestChannel->setBlockedReadTask(this)" +SCCR; - for(TMLRequest req: requests) { - if (req.isAnOriginTask(task)) cppcode+=req.getExtendedName() + "->setBlockedWriteTask(this)" +SCCR; + if (task.isRequested()) cppcode += "requestChannel->setBlockedReadTask(this)" + SCCR; + for (TMLRequest req : requests) { + if (req.isAnOriginTask(task)) cppcode += req.getExtendedName() + "->setBlockedWriteTask(this)" + SCCR; } - cppcode+=CR + "//command chaining"+ CR; - cppcode+= chaining + "_currCommand=" + firstCommand + SCCR + "_firstCommand=" + firstCommand +SCCR + CR; - int aSeq=0; - for(TMLChannel ch: channels) { - cppcode+= "_channels[" + aSeq + "] = " + ch.getExtendedName() + SCCR; + cppcode += CR + "//command chaining" + CR; + cppcode += chaining + "_currCommand=" + firstCommand + SCCR + "_firstCommand=" + firstCommand + SCCR + CR; + int aSeq = 0; + for (TMLChannel ch : channels) { + cppcode += "_channels[" + aSeq + "] = " + ch.getExtendedName() + SCCR; aSeq++; } - for(TMLEvent evt: events) { - cppcode+= "_channels[" + aSeq + "] = " + evt.getExtendedName() + SCCR; + for (TMLEvent evt : events) { + cppcode += "_channels[" + aSeq + "] = " + evt.getExtendedName() + SCCR; aSeq++; } - if (task.isRequested()){ - cppcode+= "_channels[" + aSeq + "] = requestChannel" + SCCR; + if (task.isRequested()) { + cppcode += "_channels[" + aSeq + "] = requestChannel" + SCCR; } - TMLActivityElement currElem=task.getActivityDiagram().getFirst(); + TMLActivityElement currElem = task.getActivityDiagram().getFirst(); LiveVariableNode currNode; - do{ + do { currNode = _analysis.getLiveVarNodeByCommand(currElem); - TraceManager.addDev("currElem=" + currElem); + //TraceManager.addDev("currElem=" + currElem); currElem = currElem.getNextElement(0); - }while (currNode==null && currElem!=null); - if (currNode!=null) cppcode+= "refreshStateHash(" + currNode.getStartLiveVariableString() + ")" +SCCR; - cppcode+="}"+ CR2 + functions; // + makeDestructor(); + } while (currNode == null && currElem != null); + if (currNode != null) cppcode += "refreshStateHash(" + currNode.getStartLiveVariableString() + ")" + SCCR; + cppcode += "}" + CR2 + functions; // + makeDestructor(); hcode = Conversion.indentString(hcode, 4); cppcode = Conversion.indentString(cppcode, 4); } @@ -231,27 +230,27 @@ public class MappedSystemCTask { // return dest+"}"+CR; // } - private String makeConstructorSignature(){ - String constSig=reference+ "(ID iID, Priority iPriority, std::string iName, CPU** iCPUs, unsigned int iNumOfCPUs"+CR; - for(TMLChannel ch: channels) { - constSig+=", TMLChannel* "+ ch.getExtendedName() + CR; + private String makeConstructorSignature() { + String constSig = reference + "(ID iID, Priority iPriority, std::string iName, CPU** iCPUs, unsigned int iNumOfCPUs" + CR; + for (TMLChannel ch : channels) { + constSig += ", TMLChannel* " + ch.getExtendedName() + CR; } - for(TMLEvent evt: events) { - constSig+=", TMLEventChannel* "+ evt.getExtendedName() +CR; + for (TMLEvent evt : events) { + constSig += ", TMLEventChannel* " + evt.getExtendedName() + CR; } - for(TMLRequest req: requests) { + for (TMLRequest req : requests) { //if (req.isAnOriginTask(task)) constSig+=", TMLEventBChannel* " + req.getExtendedName() + CR; - if (req.isAnOriginTask(task)) constSig+=", TMLEventChannel* " + req.getExtendedName() + CR; + if (req.isAnOriginTask(task)) constSig += ", TMLEventChannel* " + req.getExtendedName() + CR; } - if (task.isRequested()){ + if (task.isRequested()) { //constSig+=", TMLEventBChannel* requestChannel"+CR; - constSig+=", TMLEventChannel* requestChannel"+CR; + constSig += ", TMLEventChannel* requestChannel" + CR; } - return constSig+")"; + return constSig + ")"; } private void makeHeaderClassH() { - String hcodeBegin=""; + String hcodeBegin = ""; hcodeBegin = "class " + reference + ": public TMLTask {" + CR; hcodeBegin += "private:" + CR; @@ -259,30 +258,30 @@ public class MappedSystemCTask { if (task.isRequested()) { int params = task.getRequest().getNbOfParams(); - firstCommand="_waitOnRequest"; - hcode+="TMLWaitCommand " + firstCommand + SCCR; - initCommand+= "," + firstCommand + "(" + task.getActivityDiagram().getFirst().getID() + ",this,requestChannel,"; - if (params==0){ - initCommand+= "0,"+ getFormattedLiveVarStr(_startAnaNode) + ")" + CR; - }else{ - initCommand+= "(ParamFuncPointer)&" + reference + "::" + "waitOnRequest_func," + getFormattedLiveVarStr(_startAnaNode) + ")" + CR; + firstCommand = "_waitOnRequest"; + hcode += "TMLWaitCommand " + firstCommand + SCCR; + initCommand += "," + firstCommand + "(" + task.getActivityDiagram().getFirst().getID() + ",this,requestChannel,"; + if (params == 0) { + initCommand += "0," + getFormattedLiveVarStr(_startAnaNode) + ")" + CR; + } else { + initCommand += "(ParamFuncPointer)&" + reference + "::" + "waitOnRequest_func," + getFormattedLiveVarStr(_startAnaNode) + ")" + CR; //functionSig+="Parameter<ParamType>* waitOnRequest_func(Parameter<ParamType>* ioParam)" + SCCR; //functions+="Parameter<ParamType>* " + reference + "::waitOnRequest_func(Parameter<ParamType>* ioParam){" + CR; - functionSig+="Parameter* waitOnRequest_func(Parameter* ioParam)" + SCCR; - functions+="Parameter* " + reference + "::waitOnRequest_func(Parameter* ioParam){" + CR; - functions+= "ioParam->getP(&arg1__req"; - for (int i=1; i<params; i++){ - functions+= ", &arg" + (i+1) + "__req"; + functionSig += "Parameter* waitOnRequest_func(Parameter* ioParam)" + SCCR; + functions += "Parameter* " + reference + "::waitOnRequest_func(Parameter* ioParam){" + CR; + functions += "ioParam->getP(&arg1__req"; + for (int i = 1; i < params; i++) { + functions += ", &arg" + (i + 1) + "__req"; } - functions+=")" + SCCR + "return 0" + SCCR; - functions+="}\n\n"; + functions += ")" + SCCR + "return 0" + SCCR; + functions += "}\n\n"; } - String xx = firstCommand + ".setNextCommand(array(1,(TMLCommand*)" + makeCommands(task.getActivityDiagram().getFirst(),false,"&"+firstCommand,null) + "))"+ SCCR; - firstCommand="&"+firstCommand; - chaining+=xx; - }else{ - firstCommand=makeCommands(task.getActivityDiagram().getFirst(),false,"0",null); + String xx = firstCommand + ".setNextCommand(array(1,(TMLCommand*)" + makeCommands(task.getActivityDiagram().getFirst(), false, "&" + firstCommand, null) + "))" + SCCR; + firstCommand = "&" + firstCommand; + chaining += xx; + } else { + firstCommand = makeCommands(task.getActivityDiagram().getFirst(), false, "0", null); } hcode = basicHCode() + hcodeBegin + makeAttributesDeclaration() + CR + hcode; @@ -295,69 +294,73 @@ public class MappedSystemCTask { makeSerializableFuncs(); } - private void makeSerializableFuncs(){ + private void makeSerializableFuncs() { hcode += "std::istream& readObject(std::istream& i_stream_var)" + SCCR; hcode += "std::ostream& writeObject(std::ostream& i_stream_var)" + SCCR; //hcode += "unsigned long getStateHash() const" + SCCR; - functions+= "std::istream& " + reference + "::readObject(std::istream& i_stream_var){\n"; - for (TMLAttribute att:task.getAttributes()){ + functions += "std::istream& " + reference + "::readObject(std::istream& i_stream_var){\n"; + for (TMLAttribute att : task.getAttributes()) { //att = (TMLAttribute)(iterator.next()); functions += "READ_STREAM(i_stream_var," + att.name + ")" + SCCR; functions += "#ifdef DEBUG_SERIALIZE\n"; - functions += "std::cout << \"Read: Variable " + att.name + " \" << " + att.name + " << std::endl" + SCCR; + functions += "std::cout << \"Read: Variable " + att.name + " \" << " + att.name + " << std::endl" + SCCR; functions += "#endif\n"; } - functions+= "TMLTask::readObject(i_stream_var);\nreturn i_stream_var;\n}\n\n"; - functions+= "std::ostream& " + reference + "::writeObject(std::ostream& i_stream_var){\n"; - for (TMLAttribute att:task.getAttributes()){ + functions += "TMLTask::readObject(i_stream_var);\nreturn i_stream_var;\n}\n\n"; + functions += "std::ostream& " + reference + "::writeObject(std::ostream& i_stream_var){\n"; + for (TMLAttribute att : task.getAttributes()) { functions += "WRITE_STREAM(i_stream_var," + att.name + ")" + SCCR; functions += "#ifdef DEBUG_SERIALIZE\n"; - functions += "std::cout << \"Write: Variable " + att.name + " \" << " + att.name + " << std::endl" + SCCR; + functions += "std::cout << \"Write: Variable " + att.name + " \" << " + att.name + " << std::endl" + SCCR; functions += "#endif\n"; } - functions+= "TMLTask::writeObject(i_stream_var);\nreturn i_stream_var;\n}\n\n"; + functions += "TMLTask::writeObject(i_stream_var);\nreturn i_stream_var;\n}\n\n"; hcode += "void reset()" + SCCR; - functions+= "void "+reference + "::reset(){\nTMLTask::reset();\n"; - for (TMLAttribute att:task.getAttributes()){ + functions += "void " + reference + "::reset(){\nTMLTask::reset();\n"; + for (TMLAttribute att : task.getAttributes()) { functions += att.name + "="; if (att.hasInitialValue()) functions += att.initialValue + SCCR; else functions += "0" + SCCR; } - functions+= "}\n\n"; + functions += "}\n\n"; /*hcode += "void refreshStateHash(const char* iLiveVarList);\n"; functions+= "void " + reference + "::refreshStateHash(const char* iLiveVarList){\n"; int aSeq=0; functions += "_stateHash.init((HashValueType)_ID,30);\nif(iLiveVarList!=0){\n";*/ hcode += "HashValueType getStateHash();\n"; - functions+= "HashValueType " + reference + "::getStateHash(){\n"; - int aSeq=0; + functions += "HashValueType " + reference + "::getStateHash(){\n"; + int aSeq = 0; //functions += "if(_liveVarList!=0 && _hashInvalidated){\n"; functions += "if(_hashInvalidated){\n"; functions += "_hashInvalidated=false;\n_stateHash.init((HashValueType)_ID,30);\n"; functions += "if(_liveVarList!=0){\n"; - for(TMLAttribute att: task.getAttributes()) { + for (TMLAttribute att : task.getAttributes()) { functions += "if ((_liveVarList[" + (aSeq >>> 3) + "] & " + (1 << (aSeq & 0x7)) + ")!=0) _stateHash.addValue(" + att.getName() + ");\n"; //functions += "_stateHash.addValue(" + att.getName() + ");\n"; aSeq++; } - int i=0; + int i = 0; //for channels: include hash only if performed action is blocking //for events: include filling level for senders (notified possible), include parameters for readers (if parameters set) - for(TMLChannel ch: channels) { - if (ch.getType()==TMLChannel.BRBW || (ch.getType()==TMLChannel.BRNBW && ch.getDestinationTask()==task)) functions += "_channels[" + i +"]->setSignificance(this, " + "((_liveVarList[" + (aSeq >>> 3) + "] & " + (1 << (aSeq & 0x7)) + ")!=0));\n"; + for (TMLChannel ch : channels) { + if (ch.getType() == TMLChannel.BRBW || (ch.getType() == TMLChannel.BRNBW && ch.getDestinationTask() == task)) + functions += "_channels[" + i + "]->setSignificance(this, " + "((_liveVarList[" + (aSeq >>> 3) + "] & " + (1 << (aSeq & 0x7)) + ")!=0));\n"; //if (ch.getType()==TMLChannel.BRBW || (ch.getType()==TMLChannel.BRNBW && ch.getDestinationTask()==task)) functions += "_channels[" + i +"]->setSignificance(this, true);\n"; - aSeq++; i++; + aSeq++; + i++; } - for(TMLEvent evt: events) { - if (evt.isBlocking() || evt.getDestinationTask()==task) functions += " _channels[" + i +"]->setSignificance(this, " + "((_liveVarList[" + (aSeq >>> 3) + "] & " + (1 << (aSeq & 0x7)) + ")!=0));\n"; + for (TMLEvent evt : events) { + if (evt.isBlocking() || evt.getDestinationTask() == task) + functions += " _channels[" + i + "]->setSignificance(this, " + "((_liveVarList[" + (aSeq >>> 3) + "] & " + (1 << (aSeq & 0x7)) + ")!=0));\n"; //if (evt.isBlocking() || evt.getDestinationTask()==task) functions += " _channels[" + i +"]->setSignificance(this, true);\n"; - aSeq++; i++; + aSeq++; + i++; } - if (task.isRequested()){ - functions += " _channels[" + i +"]->setSignificance(this, " + "((_liveVarList[" + (aSeq >>> 3) + "] & " + (1 << (aSeq & 0x7)) + ")!=0));\n"; + if (task.isRequested()) { + functions += " _channels[" + i + "]->setSignificance(this, " + "((_liveVarList[" + (aSeq >>> 3) + "] & " + (1 << (aSeq & 0x7)) + ")!=0));\n"; //functions += " _channels[" + i +"]->setSignificance(this, true);\n"; } /*for(i=0; i< channels.size() + events.size() + (task.isRequested()? 1:0) ; i++){ @@ -368,165 +371,172 @@ public class MappedSystemCTask { functions += "}\n}\nreturn _stateHash.getHash();\n}\n\n"; } - private String getFormattedLiveVarStr(TMLActivityElement currElem){ + private String getFormattedLiveVarStr(TMLActivityElement currElem) { return getFormattedLiveVarStr(_analysis.getLiveVarNodeByCommand(currElem)); //return getFormattedLiveVarStr((LiveVariableNode)null); } - private String getFormattedLiveVarStr(LiveVariableNode currNode){ - if (currNode==null){ + private String getFormattedLiveVarStr(LiveVariableNode currNode) { + if (currNode == null) { return "0, false"; - }else{ - String checkpoint = (currNode.isCheckpoint())? "true":"false"; + } else { + String checkpoint = (currNode.isCheckpoint()) ? "true" : "false"; //String checkpoint = "true"; return currNode.getLiveVariableString() + "," + checkpoint; } } + private String makeCommands(TMLActivityElement currElem, boolean skip, String retElement, String retElseElement) { + String nextCommand = "", cmdName = ""; - private String makeCommands(TMLActivityElement currElem, boolean skip, String retElement, String retElseElement){ - String nextCommand="",cmdName=""; - - if (skip) return makeCommands(currElem.getNextElement(0), false,retElement,null); + if (skip) return makeCommands(currElem.getNextElement(0), false, retElement, null); - if (currElem==null){ - if (debug) TraceManager.addDev("Checking null\n"); + if (currElem == null) { + if (debug) { + //TraceManager.addDev("Checking null\n"); + } return retElement; } - if (debug) TraceManager.addDev("Checking " + currElem.getName() + CR); + if (debug) { + //TraceManager.addDev("Checking " + currElem.getName() + CR); + } if (currElem instanceof TMLStartState) { if (debug) TraceManager.addDev("Checking Start\n"); - return makeCommands(currElem.getNextElement(0), false,retElement,null); + return makeCommands(currElem.getNextElement(0), false, retElement, null); - } else if (currElem instanceof TMLStopState){ + } else if (currElem instanceof TMLStopState) { //add stop state if (retElement.equals("0")) - if (debug) TraceManager.addDev("Checking Stop\n"); - if (retElement.equals("0")){ - cmdName= "_stop" + currElem.getID(); - hcode+="TMLStopCommand " + cmdName + SCCR; - initCommand+= "," + cmdName + "(" + currElem.getID() + ",this)" + CR; - }else + if (debug) { + //TraceManager.addDev("Checking Stop\n"); + } + if (retElement.equals("0")) { + cmdName = "_stop" + currElem.getID(); + hcode += "TMLStopCommand " + cmdName + SCCR; + initCommand += "," + cmdName + "(" + currElem.getID() + ",this)" + CR; + } else return retElement; - }else if (currElem instanceof TMLRandom){ - if (debug) TraceManager.addDev("Checking Random\n"); - cmdName= "_random" + currElem.getID(); - TMLRandom random = (TMLRandom)currElem; - hcode+="TMLRandomCommand " + cmdName + SCCR; - initCommand+= "," + cmdName + "("+ currElem.getID() + ",this," + makeCommandRangeFunc(cmdName, random.getMinValue(), random.getMaxValue()) + ",&" + random.getVariable() + "," + getFormattedLiveVarStr(currElem) + ")"+CR; - nextCommand= cmdName + ".setNextCommand(array(1,(TMLCommand*)" + makeCommands(currElem.getNextElement(0),false,retElement,null) + "));\n"; + } else if (currElem instanceof TMLRandom) { + if (debug) { + //TraceManager.addDev("Checking Random\n"); + } + cmdName = "_random" + currElem.getID(); + TMLRandom random = (TMLRandom) currElem; + hcode += "TMLRandomCommand " + cmdName + SCCR; + initCommand += "," + cmdName + "(" + currElem.getID() + ",this," + makeCommandRangeFunc(cmdName, random.getMinValue(), random.getMaxValue()) + ",&" + random.getVariable() + "," + getFormattedLiveVarStr(currElem) + ")" + CR; + nextCommand = cmdName + ".setNextCommand(array(1,(TMLCommand*)" + makeCommands(currElem.getNextElement(0), false, retElement, null) + "));\n"; //functions+="void "+ reference + "::" + cmdName + "_func(ParamType& oMin, ParamType& oMax){\n oMin=" + modifyString(random.getMinValue()) + ";\noMax=" + modifyString(random.getMaxValue()) + SCCR; //functions+= "}" + CR2; //functionSig+="void " + cmdName + "_func(ParamType & oMin, ParamType& oMax)" + SCCR; - } else if (currElem instanceof TMLActionState || currElem instanceof TMLDelay){ - String action,comment; - if (currElem instanceof TMLActionState){ - if (debug) TraceManager.addDev("Checking Action\n"); - action = formatAction(((TMLActionState)currElem).getAction()); - comment=action; - }else{ - if (debug) TraceManager.addDev("Checking Delay\n"); + } else if (currElem instanceof TMLActionState || currElem instanceof TMLDelay) { + String action, comment; + if (currElem instanceof TMLActionState) { + //if (debug) TraceManager.addDev("Checking Action\n"); + action = formatAction(((TMLActionState) currElem).getAction()); + comment = action; + } else { + //if (debug) TraceManager.addDev("Checking Delay\n"); int masterClockFreq = tmlmapping.getTMLArchitecture().getMasterClockFrequency(); - TMLDelay delay=(TMLDelay)currElem; + TMLDelay delay = (TMLDelay) currElem; action = "TMLTime tmpDelayxy = " + delay.getMaxDelay() + "*" + masterClockFreq + delay.getMasterClockFactor() + ";"; - comment=action; - action+= "\nif (tmpDelayxy==0) tmpDelayxy=1;\n"; - if (delay.getMinDelay().equals(delay.getMaxDelay())){ + comment = action; + action += "\nif (tmpDelayxy==0) tmpDelayxy=1;\n"; + if (delay.getMinDelay().equals(delay.getMaxDelay())) { action += "_endLastTransaction+=tmpDelayxy"; - }else{ + } else { action += "TMLTime tmpDelayxx = " + delay.getMinDelay() + "*" + masterClockFreq + delay.getMasterClockFactor() + ";\nif (tmpDelayxx==0) tmpDelayxx=1;\n"; action += "_endLastTransaction+=myrand(tmpDelayxx,tmpDelayxy)"; } } //cmdName= "_action" + currElem.getID(); - String elemName=currElem.getName(), idString; - if (elemName.charAt(0)=='#'){ - int pos=elemName.indexOf('\\'); - idString=elemName.substring(1,pos); + String elemName = currElem.getName(), idString; + if (elemName.charAt(0) == '#') { + int pos = elemName.indexOf('\\'); + idString = elemName.substring(1, pos); //TraceManager.addDev(elemName + "***" + pos + "***" + idString + "***"+ elemName.length()); - cmdName="_" + elemName.substring(pos+1) + idString; - }else{ - cmdName= "_action" + currElem.getID(); - idString=String.valueOf(currElem.getID()); + cmdName = "_" + elemName.substring(pos + 1) + idString; + } else { + cmdName = "_action" + currElem.getID(); + idString = String.valueOf(currElem.getID()); } - hcode+="TMLActionCommand " + cmdName + SCCR; - initCommand+= "," + cmdName + "("+ idString + ",this,(ActionFuncPointer)&" + reference + "::" + cmdName + "_func, " + getFormattedLiveVarStr(currElem) + ")"+CR; - nextCommand= cmdName + ".setNextCommand(array(1,(TMLCommand*)" + makeCommands(currElem.getNextElement(0),false,retElement,null) + "));\n"; - functions+="void "+ reference + "::" + cmdName + "_func(){\n#ifdef ADD_COMMENTS\naddComment(new Comment(_endLastTransaction,0," + commentNum + "));\n#endif\n" + modifyString(addSemicolonIfNecessary(action)) + CR; + hcode += "TMLActionCommand " + cmdName + SCCR; + initCommand += "," + cmdName + "(" + idString + ",this,(ActionFuncPointer)&" + reference + "::" + cmdName + "_func, " + getFormattedLiveVarStr(currElem) + ")" + CR; + nextCommand = cmdName + ".setNextCommand(array(1,(TMLCommand*)" + makeCommands(currElem.getNextElement(0), false, retElement, null) + "));\n"; + functions += "void " + reference + "::" + cmdName + "_func(){\n#ifdef ADD_COMMENTS\naddComment(new Comment(_endLastTransaction,0," + commentNum + "));\n#endif\n" + modifyString(addSemicolonIfNecessary(action)) + CR; //functions+="return 0"+ SCCR; - functions+= "}" + CR2; - commentText+="_comment[" + commentNum + "]=std::string(\"Action " + comment + "\");\n"; + functions += "}" + CR2; + commentText += "_comment[" + commentNum + "]=std::string(\"Action " + comment + "\");\n"; commentNum++; - functionSig+="void " + cmdName + "_func()" + SCCR; + functionSig += "void " + cmdName + "_func()" + SCCR; - } else if (currElem instanceof TMLExecI){ - if (debug) TraceManager.addDev("Checking Execi\n"); - cmdName= "_execi" + currElem.getID(); - hcode+="TMLExeciCommand " + cmdName + SCCR; + } else if (currElem instanceof TMLExecI) { + //if (debug) TraceManager.addDev("Checking Execi\n"); + cmdName = "_execi" + currElem.getID(); + hcode += "TMLExeciCommand " + cmdName + SCCR; //initCommand+= "," + cmdName + "(this,"+ ((TMLExecI)currElem).getAction() + ",0,0)"+CR; - if (isIntValue(((TMLExecI)currElem).getAction())) - initCommand+= "," + cmdName + "(" + currElem.getID() + ",this,0,0," + ((TMLExecI)currElem).getAction() + "," + getFormattedLiveVarStr(currElem) + ")" + CR; + if (isIntValue(((TMLExecI) currElem).getAction())) + initCommand += "," + cmdName + "(" + currElem.getID() + ",this,0,0," + ((TMLExecI) currElem).getAction() + "," + getFormattedLiveVarStr(currElem) + ")" + CR; else - initCommand+= "," + cmdName + "(" + currElem.getID() + ",this," + makeCommandLenFunc(cmdName, ((TMLExecI)currElem).getAction(), null) + ",0,1," + getFormattedLiveVarStr(currElem) + ")" + CR; - nextCommand= cmdName + ".setNextCommand(array(1,(TMLCommand*)" + makeCommands(currElem.getNextElement(0),false,retElement,null) + "))"+ SCCR; - - } else if (currElem instanceof TMLExecC){ - if (debug) TraceManager.addDev("Checking ExecC\n"); - cmdName= "_execc" + currElem.getID(); - hcode+="TMLExeciCommand " + cmdName + SCCR; - if (isIntValue(((TMLExecC)currElem).getAction())) - initCommand+= "," + cmdName + "(" + currElem.getID() + ",this,0,1," + ((TMLExecC)currElem).getAction() + "," + getFormattedLiveVarStr(currElem) + ")" + CR; + initCommand += "," + cmdName + "(" + currElem.getID() + ",this," + makeCommandLenFunc(cmdName, ((TMLExecI) currElem).getAction(), null) + ",0,1," + getFormattedLiveVarStr(currElem) + ")" + CR; + nextCommand = cmdName + ".setNextCommand(array(1,(TMLCommand*)" + makeCommands(currElem.getNextElement(0), false, retElement, null) + "))" + SCCR; + + } else if (currElem instanceof TMLExecC) { + //if (debug) TraceManager.addDev("Checking ExecC\n"); + cmdName = "_execc" + currElem.getID(); + hcode += "TMLExeciCommand " + cmdName + SCCR; + if (isIntValue(((TMLExecC) currElem).getAction())) + initCommand += "," + cmdName + "(" + currElem.getID() + ",this,0,1," + ((TMLExecC) currElem).getAction() + "," + getFormattedLiveVarStr(currElem) + ")" + CR; else - initCommand+= "," + cmdName + "("+ currElem.getID() + ",this,"+ makeCommandLenFunc(cmdName, ((TMLExecC)currElem).getAction(), null) + ",1,1," + getFormattedLiveVarStr(currElem) + ")"+CR; + initCommand += "," + cmdName + "(" + currElem.getID() + ",this," + makeCommandLenFunc(cmdName, ((TMLExecC) currElem).getAction(), null) + ",1,1," + getFormattedLiveVarStr(currElem) + ")" + CR; - nextCommand= cmdName + ".setNextCommand(array(1,(TMLCommand*)" + makeCommands(currElem.getNextElement(0),false,retElement,null) + "))"+ SCCR; + nextCommand = cmdName + ".setNextCommand(array(1,(TMLCommand*)" + makeCommands(currElem.getNextElement(0), false, retElement, null) + "))" + SCCR; - } else if (currElem instanceof TMLExecIInterval){ + } else if (currElem instanceof TMLExecIInterval) { /*if (debug) TraceManager.addDev("Checking ExeciInterv\n"); cmdName= "_execi" + currElem.getID(); hcode+="TMLExeciCommand " + cmdName + SCCR; //initCommand+= "," + cmdName + "(this,"+ ((TMLExecIInterval)currElem).getMinDelay()+ "," + ((TMLExecIInterval)currElem).getMaxDelay() + ",0)"+CR; initCommand+= "," + cmdName + "("+currElem.getID()+",this,"+ makeCommandLenFunc(cmdName, ((TMLExecIInterval)currElem).getMinDelay(), ((TMLExecIInterval)currElem).getMaxDelay()) + ",0,1," + getFormattedLiveVarStr(currElem) + ")" +CR; nextCommand= cmdName + ".setNextCommand(array(1,(TMLCommand*)" + makeCommands(currElem.getNextElement(0),false,retElement,null) + "))"+ SCCR;*/ - if (debug) TraceManager.addDev("Checking ExeciInterv\n"); - cmdName= "_execi" + currElem.getID(); - hcode+="TMLExeciRangeCommand " + cmdName + SCCR; - initCommand+= "," + cmdName + "("+currElem.getID()+",this,"+ makeCommandRangeFunc(cmdName, ((TMLExecIInterval)currElem).getMinDelay(), ((TMLExecIInterval)currElem).getMaxDelay()) + ",0," + getFormattedLiveVarStr(currElem) + ")" +CR; - nextCommand= cmdName + ".setNextCommand(array(1,(TMLCommand*)" + makeCommands(currElem.getNextElement(0),false,retElement,null) + "))"+ SCCR; - - } else if (currElem instanceof TMLExecCInterval){ - if (debug) TraceManager.addDev("Checking ExecCInterv\n"); - cmdName= "_execc" + currElem.getID(); - hcode+="TMLExeciCommand " + cmdName + SCCR; + //if (debug) TraceManager.addDev("Checking ExeciInterv\n"); + cmdName = "_execi" + currElem.getID(); + hcode += "TMLExeciRangeCommand " + cmdName + SCCR; + initCommand += "," + cmdName + "(" + currElem.getID() + ",this," + makeCommandRangeFunc(cmdName, ((TMLExecIInterval) currElem).getMinDelay(), ((TMLExecIInterval) currElem).getMaxDelay()) + ",0," + getFormattedLiveVarStr(currElem) + ")" + CR; + nextCommand = cmdName + ".setNextCommand(array(1,(TMLCommand*)" + makeCommands(currElem.getNextElement(0), false, retElement, null) + "))" + SCCR; + + } else if (currElem instanceof TMLExecCInterval) { + //if (debug) TraceManager.addDev("Checking ExecCInterv\n"); + cmdName = "_execc" + currElem.getID(); + hcode += "TMLExeciCommand " + cmdName + SCCR; //initCommand+= "," + cmdName + "(this,"+ ((TMLExecIInterval)currElem).getMinDelay()+ "," + ((TMLExecIInterval)currElem).getMaxDelay() + ",1)"+CR; - initCommand+= "," + cmdName + "("+currElem.getID()+",this,"+ makeCommandLenFunc(cmdName, ((TMLExecCInterval)currElem).getMinDelay(), ((TMLExecCInterval)currElem).getMaxDelay()) + ",1,1," + getFormattedLiveVarStr(currElem) + ")"+CR; - nextCommand= cmdName + ".setNextCommand(array(1,(TMLCommand*)" + makeCommands(currElem.getNextElement(0),false,retElement,null) + "))"+ SCCR; + initCommand += "," + cmdName + "(" + currElem.getID() + ",this," + makeCommandLenFunc(cmdName, ((TMLExecCInterval) currElem).getMinDelay(), ((TMLExecCInterval) currElem).getMaxDelay()) + ",1,1," + getFormattedLiveVarStr(currElem) + ")" + CR; + nextCommand = cmdName + ".setNextCommand(array(1,(TMLCommand*)" + makeCommands(currElem.getNextElement(0), false, retElement, null) + "))" + SCCR; - } else if (currElem instanceof TMLForLoop){ + } else if (currElem instanceof TMLForLoop) { //makeCommands(TMLActivityElement currElem, boolean skip, String retElement, MergedCmdStr nextCommandCont, String retElseElement) - if (debug) TraceManager.addDev("Checking Loop\n"); - TMLForLoop fl = (TMLForLoop)currElem; - if (fl.getCondition().isEmpty() || fl.getCondition().trim().toUpperCase().equals("TRUE")){ + //if (debug) TraceManager.addDev("Checking Loop\n"); + TMLForLoop fl = (TMLForLoop) currElem; + if (fl.getCondition().isEmpty() || fl.getCondition().trim().toUpperCase().equals("TRUE")) { //initAction.addNext(fl.getNextElement(0)); //inside loop - TMLActionState incAction=new TMLActionState("#"+ fl.getID() + "\\lpIncAc",null); + TMLActionState incAction = new TMLActionState("#" + fl.getID() + "\\lpIncAc", null); incAction.setAction(fl.getIncrement()); - String firstCmdInLoop= makeCommands(fl.getNextElement(0), false, "&_lpIncAc" + fl.getID(), null); + String firstCmdInLoop = makeCommands(fl.getNextElement(0), false, "&_lpIncAc" + fl.getID(), null); makeCommands(incAction, false, firstCmdInLoop, null); - if (fl.getInit().isEmpty()){ + if (fl.getInit().isEmpty()) { return firstCmdInLoop; - }else{ - TMLActionState initAction=new TMLActionState("lpInitAc",null); + } else { + TMLActionState initAction = new TMLActionState("lpInitAc", null); initAction.setAction(fl.getInit()); - return makeCommands(initAction, false, firstCmdInLoop,null); + return makeCommands(initAction, false, firstCmdInLoop, null); } - }else{ - TMLChoice lpChoice=new TMLChoice("#"+ fl.getID() + "\\lpChoice",null); + } else { + TMLChoice lpChoice = new TMLChoice("#" + fl.getID() + "\\lpChoice", null); //if (fl.getCondition().isEmpty()) // lpChoice.addGuard("[ true ]"); //else @@ -534,163 +544,163 @@ public class MappedSystemCTask { lpChoice.addGuard("[ else ]"); lpChoice.addNext(fl.getNextElement(0)); //inside loop lpChoice.addNext(fl.getNextElement(1)); //after loop cmdName= "_choice" + currElem.getID(); - if (fl.getIncrement().isEmpty()){ + if (fl.getIncrement().isEmpty()) { makeCommands(lpChoice, false, "&_lpChoice" + fl.getID(), retElement); - }else{ - TMLActionState incAction=new TMLActionState("#"+ fl.getID() + "\\lpIncAc",null); + } else { + TMLActionState incAction = new TMLActionState("#" + fl.getID() + "\\lpIncAc", null); incAction.setAction(fl.getIncrement()); makeCommands(incAction, false, "&_lpChoice" + fl.getID(), null); makeCommands(lpChoice, false, "&_lpIncAc" + fl.getID(), retElement); } - if (fl.getInit().isEmpty()){ + if (fl.getInit().isEmpty()) { return "&_lpChoice" + fl.getID(); - }else{ - TMLActionState initAction=new TMLActionState("lpInitAc",null); + } else { + TMLActionState initAction = new TMLActionState("lpInitAc", null); initAction.setAction(fl.getInit()); return makeCommands(initAction, false, "&_lpChoice" + fl.getID(), null); } } - } else if (currElem instanceof TMLReadChannel){ - if (debug) TraceManager.addDev("Checking Read\n"); - cmdName= "_read" + currElem.getID(); - hcode+="TMLReadCommand " + cmdName + SCCR; - TMLReadChannel rCommand=(TMLReadChannel)currElem; + } else if (currElem instanceof TMLReadChannel) { + //if (debug) TraceManager.addDev("Checking Read\n"); + cmdName = "_read" + currElem.getID(); + hcode += "TMLReadCommand " + cmdName + SCCR; + TMLReadChannel rCommand = (TMLReadChannel) currElem; if (isIntValue(rCommand.getNbOfSamples())) //initCommand+= "," + cmdName + "("+currElem.getID()+",this,0," + rCommand.getChannel(0).getExtendedName() + "," + rCommand.getChannel(0).getSize() + "*" + rCommand.getNbOfSamples() + ")"+CR; - initCommand+= "," + cmdName + "("+currElem.getID()+",this,0," + rCommand.getChannel(0).getExtendedName() + "," + getFormattedLiveVarStr(currElem) + "," + rCommand.getNbOfSamples() + ")"+CR; + initCommand += "," + cmdName + "(" + currElem.getID() + ",this,0," + rCommand.getChannel(0).getExtendedName() + "," + getFormattedLiveVarStr(currElem) + "," + rCommand.getNbOfSamples() + ")" + CR; else //initCommand+= "," + cmdName + "("+currElem.getID()+",this," + makeCommandLenFunc(cmdName, rCommand.getChannel(0).getSize() + "*(" + rCommand.getNbOfSamples()+")",null) + "," + rCommand.getChannel(0).getExtendedName() + ")"+CR; - initCommand+= "," + cmdName + "("+currElem.getID()+",this," + makeCommandLenFunc(cmdName, rCommand.getNbOfSamples(),null) + "," + rCommand.getChannel(0).getExtendedName() + "," + getFormattedLiveVarStr(currElem) + ")"+CR; - nextCommand= cmdName + ".setNextCommand(array(1,(TMLCommand*)" + makeCommands(currElem.getNextElement(0),false,retElement,null) + "))"+ SCCR; + initCommand += "," + cmdName + "(" + currElem.getID() + ",this," + makeCommandLenFunc(cmdName, rCommand.getNbOfSamples(), null) + "," + rCommand.getChannel(0).getExtendedName() + "," + getFormattedLiveVarStr(currElem) + ")" + CR; + nextCommand = cmdName + ".setNextCommand(array(1,(TMLCommand*)" + makeCommands(currElem.getNextElement(0), false, retElement, null) + "))" + SCCR; - } else if (currElem instanceof TMLWriteChannel){ + } else if (currElem instanceof TMLWriteChannel) { String channels; - TMLWriteChannel wCommand=(TMLWriteChannel)currElem; - if (wCommand.getNbOfChannels()>1){ - if (ChannelMappedOnSameHW(wCommand)){ + TMLWriteChannel wCommand = (TMLWriteChannel) currElem; + if (wCommand.getNbOfChannels() > 1) { + if (ChannelMappedOnSameHW(wCommand)) { if (debug) TraceManager.addDev("Checking WriteMult with multicast\n"); - cmdName= "_mwrite" + currElem.getID(); - hcode+="TMLWriteMultCommand " + cmdName + SCCR; - channels="array("+wCommand.getNbOfChannels(); - for(int i=0; i<wCommand.getNbOfChannels(); i++){ - channels+="," + wCommand.getChannel(i).getExtendedName(); + cmdName = "_mwrite" + currElem.getID(); + hcode += "TMLWriteMultCommand " + cmdName + SCCR; + channels = "array(" + wCommand.getNbOfChannels(); + for (int i = 0; i < wCommand.getNbOfChannels(); i++) { + channels += "," + wCommand.getChannel(i).getExtendedName(); } - channels+=")," + wCommand.getNbOfChannels(); - }else{ + channels += ")," + wCommand.getNbOfChannels(); + } else { if (debug) TraceManager.addDev("Checking WriteMult with unicast\n"); - TMLWriteChannel prevWrite = null, firstWrite=null; - for(int i=0; i<wCommand.getNbOfChannels(); i++){ - TMLWriteChannel newWrite = new TMLWriteChannel("WriteMult",null); - if(i==0) firstWrite=newWrite; + TMLWriteChannel prevWrite = null, firstWrite = null; + for (int i = 0; i < wCommand.getNbOfChannels(); i++) { + TMLWriteChannel newWrite = new TMLWriteChannel("WriteMult", null); + if (i == 0) firstWrite = newWrite; newWrite.addChannel(wCommand.getChannel(i)); newWrite.setNbOfSamples(wCommand.getNbOfSamples()); - if (prevWrite!=null) prevWrite.addNext(newWrite); - prevWrite=newWrite; + if (prevWrite != null) prevWrite.addNext(newWrite); + prevWrite = newWrite; } prevWrite.addNext(wCommand.getNextElement(0)); - return makeCommands(firstWrite, false, retElement,null); + return makeCommands(firstWrite, false, retElement, null); } - }else{ - cmdName= "_write" + currElem.getID(); - hcode+="TMLWriteCommand " + cmdName + SCCR; - channels=wCommand.getChannel(0).getExtendedName(); + } else { + cmdName = "_write" + currElem.getID(); + hcode += "TMLWriteCommand " + cmdName + SCCR; + channels = wCommand.getChannel(0).getExtendedName(); } if (isIntValue(wCommand.getNbOfSamples())) - initCommand+= "," + cmdName + "("+currElem.getID()+",this,0," + channels + "," + getFormattedLiveVarStr(currElem) + "," + wCommand.getNbOfSamples() + ")" +CR; + initCommand += "," + cmdName + "(" + currElem.getID() + ",this,0," + channels + "," + getFormattedLiveVarStr(currElem) + "," + wCommand.getNbOfSamples() + ")" + CR; else - initCommand+= "," + cmdName + "("+currElem.getID()+",this," + makeCommandLenFunc(cmdName, wCommand.getNbOfSamples(), null) + "," + channels + "," + getFormattedLiveVarStr(currElem) + ")"+CR; - nextCommand= cmdName + ".setNextCommand(array(1,(TMLCommand*)" + makeCommands(currElem.getNextElement(0),false,retElement,null) + "))"+ SCCR; + initCommand += "," + cmdName + "(" + currElem.getID() + ",this," + makeCommandLenFunc(cmdName, wCommand.getNbOfSamples(), null) + "," + channels + "," + getFormattedLiveVarStr(currElem) + ")" + CR; + nextCommand = cmdName + ".setNextCommand(array(1,(TMLCommand*)" + makeCommands(currElem.getNextElement(0), false, retElement, null) + "))" + SCCR; - } else if (currElem instanceof TMLSendEvent){ + } else if (currElem instanceof TMLSendEvent) { if (debug) TraceManager.addDev("Checking Send\n"); - // TMLSendEvent sendEvt=(TMLSendEvent)currElem; - cmdName= "_send" + currElem.getID(); - hcode+="TMLSendCommand " + cmdName + SCCR; + // TMLSendEvent sendEvt=(TMLSendEvent)currElem; + cmdName = "_send" + currElem.getID(); + hcode += "TMLSendCommand " + cmdName + SCCR; handleParameters(currElem, cmdName, false, getFormattedLiveVarStr(currElem)); - nextCommand= cmdName + ".setNextCommand(array(1,(TMLCommand*)" + makeCommands(currElem.getNextElement(0),false,retElement,null) + "))"+ SCCR; + nextCommand = cmdName + ".setNextCommand(array(1,(TMLCommand*)" + makeCommands(currElem.getNextElement(0), false, retElement, null) + "))" + SCCR; - } else if (currElem instanceof TMLSendRequest){ + } else if (currElem instanceof TMLSendRequest) { if (debug) TraceManager.addDev("Checking Request\n"); //TMLSendRequest sendReq=(TMLSendRequest)currElem; - cmdName= "_request" + currElem.getID(); - hcode+="TMLRequestCommand " + cmdName + SCCR; + cmdName = "_request" + currElem.getID(); + hcode += "TMLRequestCommand " + cmdName + SCCR; handleParameters(currElem, cmdName, false, getFormattedLiveVarStr(currElem)); - nextCommand= cmdName + ".setNextCommand(array(1,(TMLCommand*)" + makeCommands(currElem.getNextElement(0),false,retElement,null) + "))"+ SCCR; + nextCommand = cmdName + ".setNextCommand(array(1,(TMLCommand*)" + makeCommands(currElem.getNextElement(0), false, retElement, null) + "))" + SCCR; - } else if (currElem instanceof TMLWaitEvent){ + } else if (currElem instanceof TMLWaitEvent) { if (debug) TraceManager.addDev("Checking Wait\n"); - // TMLWaitEvent waitEvt = (TMLWaitEvent)currElem; - cmdName= "_wait" + currElem.getID(); - hcode+="TMLWaitCommand " + cmdName + SCCR; + // TMLWaitEvent waitEvt = (TMLWaitEvent)currElem; + cmdName = "_wait" + currElem.getID(); + hcode += "TMLWaitCommand " + cmdName + SCCR; handleParameters(currElem, cmdName, true, getFormattedLiveVarStr(currElem)); - nextCommand= cmdName + ".setNextCommand(array(1,(TMLCommand*)" + makeCommands(currElem.getNextElement(0),false,retElement,null) + "))"+ SCCR; + nextCommand = cmdName + ".setNextCommand(array(1,(TMLCommand*)" + makeCommands(currElem.getNextElement(0), false, retElement, null) + "))" + SCCR; - } else if (currElem instanceof TMLNotifiedEvent){ + } else if (currElem instanceof TMLNotifiedEvent) { if (debug) TraceManager.addDev("Checking Notified\n"); - cmdName= "_notified" + currElem.getID(); - hcode+="TMLNotifiedCommand " + cmdName + SCCR; - initCommand+= "," + cmdName + "("+currElem.getID()+",this," + ((TMLNotifiedEvent)currElem).getEvent().getExtendedName() + ",&" + ((TMLNotifiedEvent)currElem).getVariable() +",\"" + ((TMLNotifiedEvent)currElem).getVariable() + "\"," + getFormattedLiveVarStr(currElem) + ")" + CR; - nextCommand= cmdName + ".setNextCommand(array(1,(TMLCommand*)" + makeCommands(currElem.getNextElement(0),false,retElement,null) + "))"+ SCCR; - - } else if (currElem instanceof TMLSequence){ - TMLSequence tmlseq = (TMLSequence)currElem; - if (debug) TraceManager.addDev("Checking Sequence with "+ tmlseq.getNbNext()+ " elements."); + cmdName = "_notified" + currElem.getID(); + hcode += "TMLNotifiedCommand " + cmdName + SCCR; + initCommand += "," + cmdName + "(" + currElem.getID() + ",this," + ((TMLNotifiedEvent) currElem).getEvent().getExtendedName() + ",&" + ((TMLNotifiedEvent) currElem).getVariable() + ",\"" + ((TMLNotifiedEvent) currElem).getVariable() + "\"," + getFormattedLiveVarStr(currElem) + ")" + CR; + nextCommand = cmdName + ".setNextCommand(array(1,(TMLCommand*)" + makeCommands(currElem.getNextElement(0), false, retElement, null) + "))" + SCCR; + + } else if (currElem instanceof TMLSequence) { + TMLSequence tmlseq = (TMLSequence) currElem; + //if (debug) TraceManager.addDev("Checking Sequence with " + tmlseq.getNbNext() + " elements."); if (tmlseq.getNbNext() == 0) { return retElement; } else { if (tmlseq.getNbNext() == 1) { - return makeCommands(currElem.getNextElement(0), false,retElement,null); + return makeCommands(currElem.getNextElement(0), false, retElement, null); } else { String nextBranch; tmlseq.sortNexts(); - if (debug) TraceManager.addDev("Checking Sequence branch "+ (tmlseq.getNbNext()-1)); - nextBranch= makeCommands(currElem.getNextElement(currElem.getNbNext() - 1),false,retElement,null); - for(int i=currElem.getNbNext() - 2; i>=0; i--) { - if (debug) TraceManager.addDev("Checking Sequence branch "+ i); - nextBranch=makeCommands(currElem.getNextElement(i),false,nextBranch,null); + //if (debug) TraceManager.addDev("Checking Sequence branch " + (tmlseq.getNbNext() - 1)); + nextBranch = makeCommands(currElem.getNextElement(currElem.getNbNext() - 1), false, retElement, null); + for (int i = currElem.getNbNext() - 2; i >= 0; i--) { + //if (debug) TraceManager.addDev("Checking Sequence branch " + i); + nextBranch = makeCommands(currElem.getNextElement(i), false, nextBranch, null); } return nextBranch; } } - } else if (currElem instanceof TMLChoice){ - String elemName=currElem.getName(), idString; - if (elemName.charAt(0)=='#'){ - int pos=elemName.indexOf('\\'); - idString=elemName.substring(1,pos); + } else if (currElem instanceof TMLChoice) { + String elemName = currElem.getName(), idString; + if (elemName.charAt(0) == '#') { + int pos = elemName.indexOf('\\'); + idString = elemName.substring(1, pos); //TraceManager.addDev(elemName + "***" + pos + "***" + idString + "***"+ elemName.length()); - cmdName="_" + elemName.substring(pos+1) + idString; - }else{ - cmdName= "_choice" + currElem.getID(); - idString=String.valueOf(currElem.getID()); + cmdName = "_" + elemName.substring(pos + 1) + idString; + } else { + cmdName = "_choice" + currElem.getID(); + idString = String.valueOf(currElem.getID()); } - TMLChoice choice = (TMLChoice)currElem; - String code = "", nextCommandTemp="", stopCmdToAdd=""; - int noOfGuards=0; - if (debug) TraceManager.addDev("Checking Choice\n"); - if (choice.getNbGuard() !=0 ) { + TMLChoice choice = (TMLChoice) currElem; + String code = "", nextCommandTemp = "", stopCmdToAdd = ""; + int noOfGuards = 0; + //if (debug) TraceManager.addDev("Checking Choice\n"); + if (choice.getNbGuard() != 0) { //int indexElseG = choice.getElseGuard(), indexAfterG = choice.getAfterGuard(); int noNonDetGuards = choice.nbOfNonDeterministicGuard(); int noStochGuards = choice.nbOfStochasticGuard(); - if (noNonDetGuards>0){ //Non-Deterministic choice - code+= "oMin=0;\n"; - code+= "oMax=" + (noNonDetGuards-1) + SCCR; + if (noNonDetGuards > 0) { //Non-Deterministic choice + code += "oMin=0;\n"; + code += "oMax=" + (noNonDetGuards - 1) + SCCR; //code += "rnd__0 = myrand(0, "+ noNonDetGuards + ")" + SCCR; - code += "return myrand(0, "+ (noNonDetGuards-1) + ")" + SCCR; - for(int i=0; i<noNonDetGuards; i++) { + code += "return myrand(0, " + (noNonDetGuards - 1) + ")" + SCCR; + for (int i = 0; i < noNonDetGuards; i++) { //code += "if (rnd__0 < " + Math.floor(100/noNonDetGuards)*(i+1) + ") return " + i + SCCR; - nextCommandTemp+= ",(TMLCommand*)" + makeCommands(choice.getNextElement(i), false, retElement,null); + nextCommandTemp += ",(TMLCommand*)" + makeCommands(choice.getNextElement(i), false, retElement, null); } noOfGuards = noNonDetGuards; //code+= "return " + (noNonDetGuards-1) + SCCR; - }else if(noStochGuards>0){ //Stochastic choice - code+= "oMin=0;\n"; - code+= "oMax=" + (noStochGuards-1) + SCCR; + } else if (noStochGuards > 0) { //Stochastic choice + code += "oMin=0;\n"; + code += "oMax=" + (noStochGuards - 1) + SCCR; code += "rnd__0 = myrand(0, 99)" + SCCR; - String composedGuard=""; - for(int i=0; i<choice.getNbGuard(); i++) { + String composedGuard = ""; + for (int i = 0; i < choice.getNbGuard(); i++) { if (choice.isStochasticGuard(i)) { if (composedGuard.isEmpty()) { composedGuard = formatGuard(choice.getStochasticGuard(i)); @@ -698,40 +708,40 @@ public class MappedSystemCTask { composedGuard = composedGuard + "+" + formatGuard(choice.getStochasticGuard(i)); } code += "if (rnd__0 < (" + composedGuard + ")) return " + noOfGuards + SCCR; - nextCommandTemp+= ",(TMLCommand*)" + makeCommands(choice.getNextElement(i), false, retElement,null); + nextCommandTemp += ",(TMLCommand*)" + makeCommands(choice.getNextElement(i), false, retElement, null); noOfGuards++; } } - }else{ - int indElseGuard = choice.getElseGuard(), newIndElseGuard=-1; - code+= "unsigned int oC=0;\n"; - code+= "oMin=-1;\n"; - code+= "oMax=0;\n"; - for(int i=0; i<choice.getNbGuard(); i++) { - if (!(choice.isNonDeterministicGuard(i) || choice.isStochasticGuard(i))){ - if (i==indElseGuard){ - newIndElseGuard=noOfGuards; - if (retElseElement!=null) - nextCommandTemp+= ",(TMLCommand*)" +makeCommands(choice.getNextElement(indElseGuard), false, retElseElement,null); + } else { + int indElseGuard = choice.getElseGuard(), newIndElseGuard = -1; + code += "unsigned int oC=0;\n"; + code += "oMin=-1;\n"; + code += "oMax=0;\n"; + for (int i = 0; i < choice.getNbGuard(); i++) { + if (!(choice.isNonDeterministicGuard(i) || choice.isStochasticGuard(i))) { + if (i == indElseGuard) { + newIndElseGuard = noOfGuards; + if (retElseElement != null) + nextCommandTemp += ",(TMLCommand*)" + makeCommands(choice.getNextElement(indElseGuard), false, retElseElement, null); else - nextCommandTemp+= ",(TMLCommand*)" + makeCommands(choice.getNextElement(indElseGuard), false, retElement,null); + nextCommandTemp += ",(TMLCommand*)" + makeCommands(choice.getNextElement(indElseGuard), false, retElement, null); - }else{ - code += "if "+ formatAction(formatGuard(choice.getGuard(i))) + "{\noC++;\n"; + } else { + code += "if " + formatAction(formatGuard(choice.getGuard(i))) + "{\noC++;\n"; code += "oMax += " + (1 << noOfGuards) + SCCR + "\n}\n"; - nextCommandTemp += ",(TMLCommand*)" + makeCommands(choice.getNextElement(i), false, retElement,null); + nextCommandTemp += ",(TMLCommand*)" + makeCommands(choice.getNextElement(i), false, retElement, null); } noOfGuards++; } } //if (newIndElseGuard!=-1){ - if (newIndElseGuard==-1){ - newIndElseGuard= noOfGuards; + if (newIndElseGuard == -1) { + newIndElseGuard = noOfGuards; stopCmdToAdd = ",(TMLCommand*)&_stop" + idString; noOfGuards++; - hcode+="TMLStopCommand " + "_stop" + idString + SCCR; - initCommand+= ", _stop" + idString + "(" + idString + ",this)" + CR; + hcode += "TMLStopCommand " + "_stop" + idString + SCCR; + initCommand += ", _stop" + idString + "(" + idString + ",this)" + CR; } code += "if (oMax==0){\n oMax=" + (1 << newIndElseGuard) + SCCR; //code += "oC=1;\n}\n"; @@ -740,167 +750,167 @@ public class MappedSystemCTask { code += "return getEnabledBranchNo(myrand(1,oC), oMax);\n"; } //nextCommand= cmdName + ".setNextCommand(array(" + noOfGuards + nextCommandTemp + "))" + SCCR; - nextCommand= cmdName + ".setNextCommand(array(" + noOfGuards + nextCommandTemp + stopCmdToAdd+ "))" + SCCR; + nextCommand = cmdName + ".setNextCommand(array(" + noOfGuards + nextCommandTemp + stopCmdToAdd + "))" + SCCR; } //if (choice.nbOfNonDeterministicGuard()==0 && choice.nbOfStochasticGuard()==0) // hcode+="TMLChoiceCommand " + cmdName + SCCR; //else - hcode+="TMLRandomChoiceCommand " + cmdName + SCCR; - initCommand+= "," + cmdName + "("+ idString +",this,(RangeFuncPointer)&" + reference + "::" + cmdName + "_func," + noOfGuards + "," + getFormattedLiveVarStr(currElem) + ")"+CR; - functions+="unsigned int "+ reference + "::" + cmdName + "_func(ParamType& oMin, ParamType& oMax){" + CR + code +CR+ "}" + CR2; - functionSig+="unsigned int " + cmdName + "_func(ParamType& oMin, ParamType& oMax)" + SCCR; + hcode += "TMLRandomChoiceCommand " + cmdName + SCCR; + initCommand += "," + cmdName + "(" + idString + ",this,(RangeFuncPointer)&" + reference + "::" + cmdName + "_func," + noOfGuards + "," + getFormattedLiveVarStr(currElem) + ")" + CR; + functions += "unsigned int " + reference + "::" + cmdName + "_func(ParamType& oMin, ParamType& oMax){" + CR + code + CR + "}" + CR2; + functionSig += "unsigned int " + cmdName + "_func(ParamType& oMin, ParamType& oMax)" + SCCR; - } else if (currElem instanceof TMLSelectEvt){ + } else if (currElem instanceof TMLSelectEvt) { TMLEvent evt; //Integer nbevt=0; - int nbevt=0; - String evtList="",paramList=""; - if (debug) TraceManager.addDev("Checking SelectEvt\n"); - cmdName= "_select" + currElem.getID(); - for(int i=0; i<currElem.getNbNext(); i++) { - evt=((TMLSelectEvt)currElem).getEvent(i); - if (evt!=null){ + int nbevt = 0; + String evtList = "", paramList = ""; + //if (debug) TraceManager.addDev("Checking SelectEvt\n"); + cmdName = "_select" + currElem.getID(); + for (int i = 0; i < currElem.getNbNext(); i++) { + evt = ((TMLSelectEvt) currElem).getEvent(i); + if (evt != null) { nbevt++; - evtList += ",(TMLEventChannel*)"+ evt.getExtendedName(); - if (evt.getNbOfParams()==0) { - paramList+=",(ParamFuncPointer)0"; - }else{ + evtList += ",(TMLEventChannel*)" + evt.getExtendedName(); + if (evt.getNbOfParams() == 0) { + paramList += ",(ParamFuncPointer)0"; + } else { //functionSig+="Parameter<ParamType>* " + cmdName + "_func_" + i + "(Parameter<ParamType>* ioParam)" + SCCR; //functions+="Parameter<ParamType>* " + reference + "::" + cmdName + "_func_" + i + "(Parameter<ParamType>* ioParam){" + CR; - functionSig+="Parameter* " + cmdName + "_func_" + i + "(Parameter* ioParam)" + SCCR; - functions+="Parameter* " + reference + "::" + cmdName + "_func_" + i + "(Parameter* ioParam){" + CR; + functionSig += "Parameter* " + cmdName + "_func_" + i + "(Parameter* ioParam)" + SCCR; + functions += "Parameter* " + reference + "::" + cmdName + "_func_" + i + "(Parameter* ioParam){" + CR; - paramList+=",(ParamFuncPointer)&" + reference + "::" + cmdName + "_func_" + i + CR; - functions += "ioParam->getP(&" + ((TMLSelectEvt)currElem).getParam(i,0); - for(int j=1; j<evt.getNbOfParams(); j++) { - functions+= ", &" + ((TMLSelectEvt)currElem).getParam(i,j); + paramList += ",(ParamFuncPointer)&" + reference + "::" + cmdName + "_func_" + i + CR; + functions += "ioParam->getP(&" + ((TMLSelectEvt) currElem).getParam(i, 0); + for (int j = 1; j < evt.getNbOfParams(); j++) { + functions += ", &" + ((TMLSelectEvt) currElem).getParam(i, j); } - functions+=");\nreturn 0;\n}\n\n"; + functions += ");\nreturn 0;\n}\n\n"; } - nextCommand+= ",(TMLCommand*)" + makeCommands(currElem.getNextElement(i), true, retElement,null); + nextCommand += ",(TMLCommand*)" + makeCommands(currElem.getNextElement(i), true, retElement, null); } } - hcode+="TMLSelectCommand " + cmdName + SCCR; - initCommand+= "," + cmdName + "("+currElem.getID()+",this,array("+ nbevt + evtList + "),"+ nbevt + "," + getFormattedLiveVarStr(currElem) + ",array("+ nbevt + paramList + "))"+CR; - nextCommand=cmdName + ".setNextCommand(array(" + nbevt + nextCommand + "))" + SCCR; + hcode += "TMLSelectCommand " + cmdName + SCCR; + initCommand += "," + cmdName + "(" + currElem.getID() + ",this,array(" + nbevt + evtList + ")," + nbevt + "," + getFormattedLiveVarStr(currElem) + ",array(" + nbevt + paramList + "))" + CR; + nextCommand = cmdName + ".setNextCommand(array(" + nbevt + nextCommand + "))" + SCCR; } else { - TraceManager.addDev("Operator: " + currElem + " of class " + currElem.getClass().getName() + " is not managed in the current version of this C++ code generator."); + TraceManager.addDev("Operator: " + currElem + " of class " + currElem.getClass().getName() + " is not managed in the current version of this C++ code generator."); } - chaining+=nextCommand; - return (cmdName.equals("0") || cmdName.charAt(0)=='&')? cmdName : "&"+cmdName; + chaining += nextCommand; + return (cmdName.equals("0") || cmdName.charAt(0) == '&') ? cmdName : "&" + cmdName; } - private String formatGuard(String guard){ + private String formatGuard(String guard) { guard = Conversion.replaceAllChar(guard, '[', "("); guard = Conversion.replaceAllChar(guard, ']', ")"); return guard; } - public static String formatAction(String action){ - action = action.replaceAll("not\\s","!"); - action = action.replaceAll("not\\(","!("); - action = action.replaceAll("\\sand\\s","&&"); - action = action.replaceAll("\\sand\\(","&&("); - action = action.replaceAll("\\)and\\s",")&&"); - action = action.replaceAll("\\)and\\(",")&&("); - action = action.replaceAll("\\sor\\s","||"); - action = action.replaceAll("\\sor\\(","||("); - action = action.replaceAll("\\)or\\s",")||"); - action = action.replaceAll("\\)or\\(",")||("); + public static String formatAction(String action) { + action = action.replaceAll("not\\s", "!"); + action = action.replaceAll("not\\(", "!("); + action = action.replaceAll("\\sand\\s", "&&"); + action = action.replaceAll("\\sand\\(", "&&("); + action = action.replaceAll("\\)and\\s", ")&&"); + action = action.replaceAll("\\)and\\(", ")&&("); + action = action.replaceAll("\\sor\\s", "||"); + action = action.replaceAll("\\sor\\(", "||("); + action = action.replaceAll("\\)or\\s", ")||"); + action = action.replaceAll("\\)or\\(", ")||("); //action = action.replaceAll("[\\s(]or[\\s)]","||"); return action; } - private boolean ChannelMappedOnSameHW(TMLWriteChannel writeCmd){ + private boolean ChannelMappedOnSameHW(TMLWriteChannel writeCmd) { LinkedList<HwCommunicationNode> commNodeRefList = tmlmapping.findNodesForElement(writeCmd.getChannel(0)); - for(int i=1; i<writeCmd.getNbOfChannels(); i++){ + for (int i = 1; i < writeCmd.getNbOfChannels(); i++) { LinkedList<HwCommunicationNode> commNodeCmpList = tmlmapping.findNodesForElement(writeCmd.getChannel(i)); - - if (commNodeCmpList.size()!=commNodeRefList.size()) return false; - + + if (commNodeCmpList.size() != commNodeRefList.size()) return false; + Iterator<HwCommunicationNode> it = commNodeCmpList.iterator(); - - for(HwCommunicationNode cmnode: commNodeRefList) { - if (it.next()!=cmnode) return false; + + for (HwCommunicationNode cmnode : commNodeRefList) { + if (it.next() != cmnode) return false; } } return true; } - private String makeCommandLenFunc(String cmdName, String lowerLimit, String upperLimit){ - if (upperLimit==null) - functions+="TMLLength "+ reference + "::" + cmdName + "_func(){\nreturn (TMLLength)(" + modifyString(lowerLimit) + ");\n}" + CR2; + private String makeCommandLenFunc(String cmdName, String lowerLimit, String upperLimit) { + if (upperLimit == null) + functions += "TMLLength " + reference + "::" + cmdName + "_func(){\nreturn (TMLLength)(" + modifyString(lowerLimit) + ");\n}" + CR2; else - functions+="TMLLength "+ reference + "::" + cmdName + "_func(){\nreturn (TMLLength)myrand(" + lowerLimit + "," + modifyString(upperLimit) + ");\n}" + CR2; - functionSig+="TMLLength " + cmdName + "_func()" + SCCR; + functions += "TMLLength " + reference + "::" + cmdName + "_func(){\nreturn (TMLLength)myrand(" + lowerLimit + "," + modifyString(upperLimit) + ");\n}" + CR2; + functionSig += "TMLLength " + cmdName + "_func()" + SCCR; return "(LengthFuncPointer)&" + reference + "::" + cmdName + "_func"; } - private String makeCommandRangeFunc(String cmdName, String lowerLimit, String upperLimit){ - functions+="unsigned int "+ reference + "::" + cmdName + "_func(ParamType& oMin, ParamType& oMax){\n oMin=" + modifyString(lowerLimit) + ";\noMax=" + modifyString(upperLimit) + SCCR + "return myrand(oMin, oMax)" + SCCR; - functions+= "}" + CR2; - functionSig+="unsigned int " + cmdName + "_func(ParamType & oMin, ParamType& oMax)" + SCCR; + private String makeCommandRangeFunc(String cmdName, String lowerLimit, String upperLimit) { + functions += "unsigned int " + reference + "::" + cmdName + "_func(ParamType& oMin, ParamType& oMax){\n oMin=" + modifyString(lowerLimit) + ";\noMax=" + modifyString(upperLimit) + SCCR + "return myrand(oMin, oMax)" + SCCR; + functions += "}" + CR2; + functionSig += "unsigned int " + cmdName + "_func(ParamType & oMin, ParamType& oMax)" + SCCR; return "(RangeFuncPointer)&" + reference + "::" + cmdName + "_func"; } - private boolean isIntValue(String input){ - try{ + private boolean isIntValue(String input) { + try { Integer.parseInt(input); return true; - }catch(Exception e){ + } catch (Exception e) { return false; } } - private void handleParameters(TMLActivityElement currElem, String cmdName, boolean wait, String liveVarString){ - String concatParams="", channelName=""; - String[] paramArray=null; + private void handleParameters(TMLActivityElement currElem, String cmdName, boolean wait, String liveVarString) { + String concatParams = "", channelName = ""; + String[] paramArray = null; //boolean areStatic=true; - int nbOfParams=0; - String address=(wait)? "&":""; - if (currElem instanceof TMLActivityElementEvent){ - nbOfParams=((TMLActivityElementEvent)currElem).getNbOfParams(); + int nbOfParams = 0; + String address = (wait) ? "&" : ""; + if (currElem instanceof TMLActivityElementEvent) { + nbOfParams = ((TMLActivityElementEvent) currElem).getNbOfParams(); paramArray = new String[nbOfParams]; - for (int i=0; i< nbOfParams; i++){ - paramArray[i]=((TMLActivityElementEvent)currElem).getParam(i); + for (int i = 0; i < nbOfParams; i++) { + paramArray[i] = ((TMLActivityElementEvent) currElem).getParam(i); } - channelName = ((TMLActivityElementEvent)currElem).getEvent().getExtendedName(); - } - else if (currElem instanceof TMLSendRequest){ - nbOfParams=((TMLSendRequest)currElem).getNbOfParams(); + channelName = ((TMLActivityElementEvent) currElem).getEvent().getExtendedName(); + } else if (currElem instanceof TMLSendRequest) { + nbOfParams = ((TMLSendRequest) currElem).getNbOfParams(); paramArray = new String[nbOfParams]; - for (int i=0; i< nbOfParams; i++){ - paramArray[i]=((TMLSendRequest)currElem).getParam(i); + for (int i = 0; i < nbOfParams; i++) { + paramArray[i] = ((TMLSendRequest) currElem).getParam(i); } - channelName = ((TMLSendRequest)currElem).getRequest().getExtendedName(); + channelName = ((TMLSendRequest) currElem).getRequest().getExtendedName(); } - if (nbOfParams==0){ - initCommand+= "," + cmdName + "("+ currElem.getID() +",this," + channelName + ",0," + liveVarString +")"+CR; - }else{ - for(int i=0; i<nbOfParams; i++){ + if (nbOfParams == 0) { + initCommand += "," + cmdName + "(" + currElem.getID() + ",this," + channelName + ",0," + liveVarString + ")" + CR; + } else { + for (int i = 0; i < nbOfParams; i++) { //if(areStatic && !isIntValue(paramArray[i])) areStatic=false; - if (i>0) concatParams+=","; + if (i > 0) concatParams += ","; //concatParams+=","; - if (paramArray[i]==null || paramArray[i].isEmpty()) concatParams+="0"; else concatParams+= address + paramArray[i]; + if (paramArray[i] == null || paramArray[i].isEmpty()) concatParams += "0"; + else concatParams += address + paramArray[i]; } //if (areStatic){ //initCommand+= "," + cmdName + "("+ currElem.getID() +",this," + channelName + ",0," + liveVarString + ",Parameter<ParamType>(" + nbOfParams + "," + concatParams + "))"+CR; //initCommand+= "," + cmdName + "("+ currElem.getID() +",this," + channelName + ",0," + liveVarString + ",new SizedParameter<ParamType," + nbOfParams + ">(" + concatParams + "))"+CR; //}else{ - initCommand+= "," + cmdName + "("+ currElem.getID() +",this," + channelName + ",(ParamFuncPointer)&" + reference + "::" + cmdName + "_func,"+ liveVarString + ")" + CR; + initCommand += "," + cmdName + "(" + currElem.getID() + ",this," + channelName + ",(ParamFuncPointer)&" + reference + "::" + cmdName + "_func," + liveVarString + ")" + CR; //functionSig+="Parameter<ParamType>* " + cmdName + "_func(Parameter<ParamType>* ioParam)" + SCCR; //functions+="Parameter<ParamType>* " + reference + "::" + cmdName + "_func(Parameter<ParamType>* ioParam){" + CR; - functionSig+="Parameter* " + cmdName + "_func(Parameter* ioParam)" + SCCR; - functions+="Parameter* " + reference + "::" + cmdName + "_func(Parameter* ioParam){" + CR; + functionSig += "Parameter* " + cmdName + "_func(Parameter* ioParam)" + SCCR; + functions += "Parameter* " + reference + "::" + cmdName + "_func(Parameter* ioParam){" + CR; if (wait) functions += "ioParam->getP(" + concatParams + ")" + SCCR + "return 0" + SCCR; else //functions += "return new Parameter<ParamType>(" + nbOfParams + "," + concatParams + ")" + SCCR; functions += "return new SizedParameter<ParamType," + nbOfParams + ">(" + concatParams + ")" + SCCR; - functions+="}\n\n"; + functions += "}\n\n"; //} } } @@ -912,13 +922,13 @@ public class MappedSystemCTask { private String makeAttributesCode() { String code = ""; - // int i; - for(TMLAttribute att: task.getAttributes()) { + // int i; + for (TMLAttribute att : task.getAttributes()) { //if (!att.name.endsWith("__req")){ //NEW if (att.hasInitialValue()) - code += ","+ att.name + "(" + att.initialValue + ")"+CR; + code += "," + att.name + "(" + att.initialValue + ")" + CR; else - code += ","+ att.name + "(0)"+CR; + code += "," + att.name + "(0)" + CR; //} } //code += ",arg1__req(0)"+CR; @@ -929,8 +939,8 @@ public class MappedSystemCTask { private String makeAttributesDeclaration() { String code = ""; - // int i; - for(TMLAttribute att: task.getAttributes()) { + // int i; + for (TMLAttribute att : task.getAttributes()) { //if (!att.name.endsWith("__req")){ //NEW code += "ParamType " + att.name; code += ";\n"; @@ -940,7 +950,7 @@ public class MappedSystemCTask { //code += "ParamType arg2__req" + SCCR; //code += "ParamType arg3__req" + SCCR; code += "ParamType rnd__0" + SCCR; - code += "TMLChannel* _channels[" + (channels.size() + events.size() + (task.isRequested()? 1:0)) + "]" + SCCR; + code += "TMLChannel* _channels[" + (channels.size() + events.size() + (task.isRequested() ? 1 : 0)) + "]" + SCCR; return code; } @@ -959,35 +969,35 @@ public class MappedSystemCTask { return _input; } - public String getIdentifierNameByID(int id){ + public String getIdentifierNameByID(int id) { //Channels, Events, Requests, Variables, Choice, Random - id=Math.abs(id); - for (TMLChannel channel: channels){ - if (channel.getID()==id) return channel.getName(); + id = Math.abs(id); + for (TMLChannel channel : channels) { + if (channel.getID() == id) return channel.getName(); } - for (TMLEvent event: events){ - if (event.getID()==id) return event.getName(); + for (TMLEvent event : events) { + if (event.getID() == id) return event.getName(); /*int param = Integer.MAX_VALUE - 3 * event.getID() - id + 1; if (param>0 && param<4) return event.getName() + "_param" + param;*/ } - for (TMLRequest request: requests){ - if (request.getID()==id) return request.getName(); + for (TMLRequest request : requests) { + if (request.getID() == id) return request.getName(); /*int param = Integer.MAX_VALUE - 3 * request.getID() - id +1; if (param>0 && param<4) return request.getName() + "_param!" + param;*/ } - for(TMLAttribute att: task.getAttributes()){ - if (att.getID()==id) return reference + ":" + att.getName(); + for (TMLAttribute att : task.getAttributes()) { + if (att.getID() == id) return reference + ":" + att.getName(); } - for(int i=0; i<task.getActivityDiagram().nElements();i++) - if (task.getActivityDiagram().get(i).getID()==id) return reference + ":Command " + id; + for (int i = 0; i < task.getActivityDiagram().nElements(); i++) + if (task.getActivityDiagram().get(i).getID() == id) return reference + ":Command " + id; return null; } - public void determineCheckpoints(int[] aStatistics){ + public void determineCheckpoints(int[] aStatistics) { _analysis.determineCheckpoints(aStatistics); } - public StaticAnalysis getAnalysis(){ + public StaticAnalysis getAnalysis() { return _analysis; } } diff --git a/src/main/java/tmltranslator/tomappingsystemc2/TML2MappingSystemC.java b/src/main/java/tmltranslator/tomappingsystemc2/TML2MappingSystemC.java index dad6681a601b2ede4e945e67273212f21bcb9f35..5d24b911b680dda1aed45a0d788561526337990c 100644 --- a/src/main/java/tmltranslator/tomappingsystemc2/TML2MappingSystemC.java +++ b/src/main/java/tmltranslator/tomappingsystemc2/TML2MappingSystemC.java @@ -193,7 +193,7 @@ public class TML2MappingSystemC implements IDiploSimulatorCodeGenerator { //tmlmapping.getTMLArchitecture().getMasterClockFrequency() * exNode.sliceTime //declaration += "RRScheduler* " + exNode.getName() + "_scheduler = new RRScheduler(\"" + exNode.getName() + "_RRSched\", 0, 5, " + (int) Math.ceil(((float)exNode.execiTime)*(1+((float)exNode.branchingPredictionPenalty)/100)) + " ) " + SCCR; declaration += "RRScheduler* " + exNode.getName() + "_scheduler = new RRScheduler(\"" + exNode.getName() + "_RRSched\", 0, " + (tmlmapping.getTMLArchitecture().getMasterClockFrequency() * exNode.sliceTime) + ", " + (int) Math.ceil((float) (exNode.clockRatio * Math.max(exNode.execiTime, exNode.execcTime) * (exNode.branchingPredictionPenalty * exNode.pipelineSize + 100 - exNode.branchingPredictionPenalty)) / 100) + " ) " + SCCR; - TraceManager.addDev("cores " + exNode.nbOfCores); + //TraceManager.addDev("cores " + exNode.nbOfCores); for (int cores = 0; cores < exNode.nbOfCores; cores++) { //for(int cores=0; cores<1; cores++){ //if (tmlmapping.isAUsedHwNode(node)) { @@ -344,7 +344,7 @@ public class TML2MappingSystemC implements IDiploSimulatorCodeGenerator { } //param += "," + evt.getNbOfParams(); if (tmlmapping.isCommNodeMappedOn(evt, null)) { - TraceManager.addDev("Evt: " + evt.getName()); + //TraceManager.addDev("Evt: " + evt.getName()); declaration += tmp + "* " + evt.getExtendedName() + " = new " + tmp + "(" + evt.getID() + ",\"" + evt.getName() + "\"," + determineRouting(tmlmapping.getHwNodeOf(evt.getOriginTask()), tmlmapping.getHwNodeOf(evt.getDestinationTask()), evt) + param; } else { @@ -363,7 +363,7 @@ public class TML2MappingSystemC implements IDiploSimulatorCodeGenerator { TMLRequest req = task.getRequest(); if (tmlmapping.isCommNodeMappedOn(req, null)) { //declaration += "TMLEventBChannel* reqChannel_"+ task.getName() + " = new TMLEventBChannel(" + - TraceManager.addDev("Request: " + req.getName()); + //TraceManager.addDev("Request: " + req.getName()); declaration += "TMLEventBChannel<ParamType," + req.getNbOfParams() + ">* reqChannel_" + task.getName() + " = new TMLEventBChannel<ParamType," + req.getNbOfParams() + ">(" + req.getID() + ",\"reqChannel" + task.getName() + "\"," + determineRouting(tmlmapping.getHwNodeOf(req.getOriginTasks().get(0)), //tmlmapping.getHwNodeOf(req.getDestinationTask()), req) + ",0," + req.getNbOfParams() + ",true)" + SCCR; @@ -497,12 +497,12 @@ public class TML2MappingSystemC implements IDiploSimulatorCodeGenerator { declaration += "}\n};\n\n" + tepeTranslator.getEqFuncs(); declaration += "#include <main.h>\n"; - if (aStatistics[0] != 0) TraceManager.addDev("Global gain variables " + 100 * aStatistics[1] / aStatistics[0]); - if (aStatistics[2] != 0) TraceManager.addDev("Global gain Channels " + 100 * aStatistics[3] / aStatistics[2]); - if (aStatistics[4] != 0) TraceManager.addDev("Global gain events " + 100 * aStatistics[5] / aStatistics[4]); - if (aStatistics[6] != 0) + //if (aStatistics[0] != 0) TraceManager.addDev("Global gain variables " + 100 * aStatistics[1] / aStatistics[0]); + //if (aStatistics[2] != 0) TraceManager.addDev("Global gain Channels " + 100 * aStatistics[3] / aStatistics[2]); + //if (aStatistics[4] != 0) TraceManager.addDev("Global gain events " + 100 * aStatistics[5] / aStatistics[4]); + /*if (aStatistics[6] != 0) TraceManager.addDev("Global gain checkpoints " + 100 * aStatistics[7] / aStatistics[6]); - + */ //Declaration of EBRDDs /*declaration += "//Declaration of EBRDDs" + CR; for(EBRDD ebrdd: ebrdds){ @@ -605,38 +605,38 @@ public class TML2MappingSystemC implements IDiploSimulatorCodeGenerator { if ((hopNum = extractPath(path, masters, slaves, startNode, destNode, false)) < 0) { hopNum = extractPath(path, masters, slaves, destNode, destNode, true) - hopNum; } - TraceManager.addDev(commElemToRoute.getName() + " is mapped on:"); + //TraceManager.addDev(commElemToRoute.getName() + " is mapped on:"); for (HwCommunicationNode commElem : path) { TraceManager.addDev(commElem.getName()); } - TraceManager.addDev("number of elements: " + hopNum); - TraceManager.addDev("masters: " + masters.str); - TraceManager.addDev("slaves: " + slaves.str); + //TraceManager.addDev("number of elements: " + hopNum); + //TraceManager.addDev("masters: " + masters.str); + //TraceManager.addDev("slaves: " + slaves.str); return hopNum + ",array(" + hopNum + masters.str + "),array(" + hopNum + slaves.str + ")"; } private boolean exploreBuses(int depth, LinkedList<HwCommunicationNode> commNodes, LinkedList<HwCommunicationNode> path, HwNode startNode, HwNode destNode, TMLElement commElemToRoute) { //first called with Maping:getCommunicationNodes LinkedList<HwCommunicationNode> nodesToExplore; - TraceManager.addDev("No of comm nodes " + commNodes.size()); - TraceManager.addDev("startNode=" + startNode); + //TraceManager.addDev("No of comm nodes " + commNodes.size()); + //TraceManager.addDev("startNode=" + startNode); boolean busExploreMode = ((depth & 1) == 0); //if (depth % 2 == 0){ if (busExploreMode) { - TraceManager.addDev("search for buses connected to " + startNode.getName()); + //TraceManager.addDev("search for buses connected to " + startNode.getName()); nodesToExplore = getBusesConnectedToNode(commNodes, startNode); } else { - TraceManager.addDev("search for bridges connected to: " + startNode.getName()); + //TraceManager.addDev("search for bridges connected to: " + startNode.getName()); nodesToExplore = getBridgesConnectedToBus(commNodes, (HwBus) startNode); } //HwMemory memory = null; - TraceManager.addDev("no of elements found: " + nodesToExplore.size()); + //TraceManager.addDev("no of elements found: " + nodesToExplore.size()); for (HwCommunicationNode currNode : nodesToExplore) { //memory = null; if (busExploreMode) { //memory = getMemConnectedToBusChannelMapped(commNodes, (HwBus)currNode, commElemToRoute); if (isBusConnectedToNode(currNode, destNode)) { - TraceManager.addDev(currNode.getName() + " is last node"); + //TraceManager.addDev(currNode.getName() + " is last node"); path.add(currNode); //if (memory!=null) path.add(memory); commNodes.remove(currNode); @@ -644,7 +644,7 @@ public class TML2MappingSystemC implements IDiploSimulatorCodeGenerator { } } if (tmlmapping.isCommNodeMappedOn(commElemToRoute, currNode)) { - TraceManager.addDev(currNode.getName() + " mapping found for " + commElemToRoute.getName()); + //TraceManager.addDev(currNode.getName() + " mapping found for " + commElemToRoute.getName()); path.add(currNode); //if (memory!=null) path.add(memory); commNodes.remove(currNode); @@ -660,7 +660,7 @@ public class TML2MappingSystemC implements IDiploSimulatorCodeGenerator { //if (memory!=null) path.add(memory); commNodes.remove(currNode); //for (int i=0; i<path.size(); i++) System.out.print(" "); - TraceManager.addDev(currNode.getName()); + //TraceManager.addDev(currNode.getName()); if (exploreBuses(depth + 1, commNodes, path, currNode, destNode, commElemToRoute)) return true; path.remove(currNode); //if (memory!=null) path.remove(memory); @@ -672,9 +672,10 @@ public class TML2MappingSystemC implements IDiploSimulatorCodeGenerator { private HwMemory getMemConnectedToBusChannelMapped(LinkedList<HwCommunicationNode> _commNodes, HwBus _bus, TMLElement _channel) { for (HwCommunicationNode commNode : _commNodes) { if (commNode instanceof HwMemory) { - if (_bus != null) - TraceManager.addDev(commNode.getName() + " connected to bus " + _bus.getName() + ": " + tmlmapping.getTMLArchitecture().isNodeConnectedToBus(commNode, _bus)); - TraceManager.addDev(_channel.getName() + " is mapped onto " + commNode.getName() + ": " + tmlmapping.isCommNodeMappedOn(_channel, commNode)); + if (_bus != null) { + //TraceManager.addDev(commNode.getName() + " connected to bus " + _bus.getName() + ": " + tmlmapping.getTMLArchitecture().isNodeConnectedToBus(commNode, _bus)); + } + //TraceManager.addDev(_channel.getName() + " is mapped onto " + commNode.getName() + ": " + tmlmapping.isCommNodeMappedOn(_channel, commNode)); if ((_bus == null || tmlmapping.getTMLArchitecture().isNodeConnectedToBus(commNode, _bus)) && tmlmapping.isCommNodeMappedOn(_channel, commNode)) { return (HwMemory) commNode; diff --git a/src/main/java/ui/window/JDialogSystemCGeneration.java b/src/main/java/ui/window/JDialogSystemCGeneration.java index 24a5f84738b6c79afc20264a30bb0f62355250f9..d8ef40e942f42b6dacc58bc83f6e8cec21bf9973 100755 --- a/src/main/java/ui/window/JDialogSystemCGeneration.java +++ b/src/main/java/ui/window/JDialogSystemCGeneration.java @@ -61,12 +61,11 @@ import javax.swing.event.ListSelectionListener; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.io.File; import java.util.ArrayList; import java.util.List; import java.util.Vector; -import java.io.File; - /** * Class JDialogSystemCGeneration * Dialog for managing the generation and compilation of SystemC code @@ -194,7 +193,6 @@ public class JDialogSystemCGeneration extends JDialog implements ActionListener, } - simulatorHost = _simulatorHost; automatic = _automatic; @@ -672,8 +670,7 @@ public class JDialogSystemCGeneration extends JDialog implements ActionListener, setButtons(); } - private void generateCode() - throws InterruptedException { + private void generateCode() throws InterruptedException { String list; jta.append("Generating simulator C++ code\n"); @@ -768,8 +765,8 @@ public class JDialogSystemCGeneration extends JDialog implements ActionListener, testGo(); jta.append("Simulator code generation done\n"); - for (final TEPE tep: alTepe) { - TraceManager.addDev(tep.toString()); + for (final TEPE tep : alTepe) { + //TraceManager.addDev(tep.toString()); } jta.append("Saving C++ files...\n");