diff --git a/src/TMLTranslator.java b/src/TMLTranslator.java index 5c593d04c4976f05e7e561f72fa10d8e06afdc61..2473eaf76178cb3296019c24fce1c1e934e351ae 100755 --- a/src/TMLTranslator.java +++ b/src/TMLTranslator.java @@ -57,6 +57,8 @@ import tmltranslator.TMLMappingTextSpecification; import tmltranslator.TMLModeling; import tmltranslator.TMLSyntaxChecking; import tmltranslator.TMLTextSpecification; +import tmltranslator.tomappingsystemc2.IDiploSimulatorCodeGenerator; +import tmltranslator.tomappingsystemc2.DiploSimulatorFactory; import tmltranslator.toturtle.Mapping2TIF; import tmltranslator.toturtle.TML2TURTLE; import tmltranslator.touppaal.TML2UPPAAL; @@ -348,13 +350,17 @@ public class TMLTranslator { public static boolean convertToSystemC2() { //System.out.println("Converting to SystemC2 ... yo!"); - tmltranslator.tomappingsystemc2.TML2MappingSystemC map; + final IDiploSimulatorCodeGenerator map; +// tmltranslator.tomappingsystemc2.TML2MappingSystemC map; if (tmap == null) { - map = new tmltranslator.tomappingsystemc2.TML2MappingSystemC(tmlm); - } else { - map = new tmltranslator.tomappingsystemc2.TML2MappingSystemC(tmap); + map = DiploSimulatorFactory.INSTANCE.createTranslator( tmlm ); + } + else { + map = DiploSimulatorFactory.INSTANCE.createTranslator( tmap ); } + map.generateSystemC(debug, true); + try { map.saveFile(outputFileName, "appmodel"); } catch (Exception e) { diff --git a/src/dseengine/DSEConfiguration.java b/src/dseengine/DSEConfiguration.java index 9ac35bc9dec030a792da53cdb512fa38613cd4b1..e962e3440220cb144a79f5cfb28a2582908b695e 100755 --- a/src/dseengine/DSEConfiguration.java +++ b/src/dseengine/DSEConfiguration.java @@ -55,10 +55,6 @@ import tmltranslator.*; import tmltranslator.tomappingsystemc2.*; //import tmltranslator.toturtle.*; -import translator.*; - -import dseengine.*; - import myutil.*; import ui.*; @@ -73,7 +69,7 @@ public class DSEConfiguration implements Runnable { private final String PATH_TO_CODE = "No directory selected for putting the generated code"; private final String PATH_TO_RESULTS = "No directory selected for putting the results"; private final String PATH_TO_SOURCE = "No source model selected"; - private final String NO_OUTPUT_SELECTED = "No format for the output has been selected"; + private final String NO_OUTPUT_SELECTED = "No format ofr the output has been selected"; private final String LOAD_MAPPING_FAILED = "Loading of the mapping failed"; private final String LOAD_TASKMODEL_FAILED = "Loading of the task model failed"; private final String SIMULATION_COMPILATION_COMMAND_NOT_SET = "Compilation command missing"; @@ -675,7 +671,9 @@ public class DSEConfiguration implements Runnable { // Generating code TraceManager.addDev("\n\n\n**** Generating simulation code..."); - TML2MappingSystemC map = new TML2MappingSystemC(tmap); + final IDiploSimulatorCodeGenerator map = DiploSimulatorFactory.INSTANCE.createTranslator( tmap ); +// TML2MappingSystemC map = new TML2MappingSystemC(tmap); + try { map.generateSystemC(_debug, _optimize); map.saveFile(pathToSimulator, "appmodel"); @@ -711,7 +709,8 @@ public class DSEConfiguration implements Runnable { // Generating code TraceManager.addDev("\n\n\n**** Generating simulation code from mapping..."); - TML2MappingSystemC map = new TML2MappingSystemC(_tmlmap); + final IDiploSimulatorCodeGenerator map = DiploSimulatorFactory.INSTANCE.createTranslator( _tmlmap ); + try { map.generateSystemC(_debug, _optimize); map.saveFile(pathToSimulator, "appmodel"); @@ -1157,6 +1156,7 @@ public class DSEConfiguration implements Runnable { return 0; } else { + if (results == null) { TraceManager.addDev("No results"); return -1; @@ -1164,7 +1164,7 @@ public class DSEConfiguration implements Runnable { // Must compute results results.computeResults(); - overallResults = results.getExplanationHeader() + "\n" + results.getAllComments() + "\n" + results.getWholeResults(); + TraceManager.addDev("Results: #" + resultsID + "\n" + results.getWholeResults()); // Saving to file @@ -1247,7 +1247,8 @@ public class DSEConfiguration implements Runnable { TraceManager.addDev("\n\n\n**** Generating simulation code..."); - TML2MappingSystemC map = new TML2MappingSystemC(tmap); + final IDiploSimulatorCodeGenerator map = DiploSimulatorFactory.INSTANCE.createTranslator( tmap ); +// TML2MappingSystemC map = new TML2MappingSystemC(tmap); try { map.generateSystemC(_debug, _optimize); map.saveFile(pathToSimulator, "appmodel"); diff --git a/src/tmltranslator/CPPCodeGenerationHelper.java b/src/tmltranslator/CPPCodeGenerationHelper.java new file mode 100644 index 0000000000000000000000000000000000000000..d36c063f3223feee225e71d803def5a000b14b47 --- /dev/null +++ b/src/tmltranslator/CPPCodeGenerationHelper.java @@ -0,0 +1,124 @@ +package tmltranslator; + +import java.util.Arrays; +import java.util.Collection; + +public class CPPCodeGenerationHelper { + + public static final String NORMALIZATION_SUFFIX = "_Norm"; + + private static final String DOT_REPLACEMENT = "_DOT_"; + + private static final String PATH_REPLACEMENT = "_PATH_"; + + private static final String[] CPP_KEYWORDS = { + "alignas", // (depuis C++11) + "alignof", // (depuis C++11) + "and", + "and_eq", + "asm", + "auto", + "bitand", + "bitor", + "bool", + "break", + "case", + "catch", + "char", + "char16_t", //(depuis C++11) + "char32_t", // (depuis C++11) + "class", + "compl", + "const", + "constexpr", // (depuis C++11) + "const_cast", + "continue", + "decltype", //(depuis C++11) + "default", + "delete", + "do", + "double", + "dynamic_cast", + "else", + "enum", + "explicit", + "export", + "extern", + "false", + "float", + "for", + "friend", + "goto", + "if", + "inline", + "int", + "long", + "mutable", + "namespace", + "new", + "noexcept", //(depuis C++11) + "not", + "not_eq", + "nullptr", // (depuis C++11) + "operator", + "or", + "or_eq", + "private", + "protected", + "public", + "register", + "reinterpret_cast", + "return", + "short", + "signed", + "sizeof", + "static", + "static_assert", // (depuis C++11) + "static_cast", + "struct", + "switch", + "template", + "this", + "thread_local", // (depuis C++11) + "throw", + "true", + "try", + "typedef", + "typeid", + "typename", + "union", + "unsigned", + "using", + "virtual", + "void", + "volatile", + "wchar_t", + "while", + "xor", + "xor_eq" }; + + private static final Collection<String> CPP_KEYWORDS_LIST = Arrays.asList( CPP_KEYWORDS ); + + private CPPCodeGenerationHelper() { + } + + public static String normalize( final String name ) { + return removeCKeywords( name ).replaceAll( "\\.", DOT_REPLACEMENT ).replaceAll( "::", PATH_REPLACEMENT ); + } + + public static String headerFileName( final String name ) { + return name + ".h"; + } + + public static String cppFileName( final String name ) { + return name + ".cpp"; + } + + public static String removeCKeywords( final String name ) { + if ( CPP_KEYWORDS_LIST.contains( name ) ) { + return name + NORMALIZATION_SUFFIX; + } + + return name; + } +} diff --git a/src/tmltranslator/HwBus.java b/src/tmltranslator/HwBus.java index 3051faf6bcad9b4828684df2946c2cb60144e5b2..8ed166aa7b9d3a183e245965a8c3297181c9313c 100755 --- a/src/tmltranslator/HwBus.java +++ b/src/tmltranslator/HwBus.java @@ -45,9 +45,6 @@ knowledge of the CeCILL license and that you accept its terms. package tmltranslator; -import java.util.*; - - public class HwBus extends HwCommunicationNode { public static final int BASIC_ROUND_ROBIN = 0; diff --git a/src/tmltranslator/HwCommunicationNode.java b/src/tmltranslator/HwCommunicationNode.java index 9282c1ba90d0408a205e4ae309345f8ef59462d3..f0149555aac26d6f62f167166f06863cb6a8aff0 100755 --- a/src/tmltranslator/HwCommunicationNode.java +++ b/src/tmltranslator/HwCommunicationNode.java @@ -45,8 +45,6 @@ knowledge of the CeCILL license and that you accept its terms. package tmltranslator; -import java.util.*; - public abstract class HwCommunicationNode extends HwNode { diff --git a/src/tmltranslator/HwMemory.java b/src/tmltranslator/HwMemory.java index d5525fa0f32a2fab910e06f475b62705bec93936..48c77376429bec6d4e1ce9738999bd341b6d210f 100755 --- a/src/tmltranslator/HwMemory.java +++ b/src/tmltranslator/HwMemory.java @@ -45,10 +45,6 @@ knowledge of the CeCILL license and that you accept its terms. package tmltranslator; -import java.util.*; -import tmltranslator.modelcompiler.*; - - public class HwMemory extends HwCommunicationNode { public static final int DEFAULT_BYTE_DATA_SIZE = 4; diff --git a/src/tmltranslator/tomappingsystemc2/DiploSimulatorCodeGenerator.java b/src/tmltranslator/tomappingsystemc2/DiploSimulatorCodeGenerator.java new file mode 100644 index 0000000000000000000000000000000000000000..43729448599c90bce58f910a2333159e56fbae6d --- /dev/null +++ b/src/tmltranslator/tomappingsystemc2/DiploSimulatorCodeGenerator.java @@ -0,0 +1,850 @@ +/**Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + + ludovic.apvrille AT enst.fr + + This software is a computer program whose purpose is to allow the + edition of TURTLE analysis, design and deployment diagrams, to + allow the generation of RT-LOTOS or Java code from this diagram, + and at last to allow the analysis of formal validation traces + obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + from INRIA Rhone-Alpes. + + This software is governed by the CeCILL license under French law and + abiding by the rules of distribution of free software. You can use, + modify and/ or redistribute the software under the terms of the CeCILL + license as circulated by CEA, CNRS and INRIA at the following URL + "http://www.cecill.info". + + As a counterpart to the access to the source code and rights to copy, + modify and redistribute granted by the license, users are provided only + with a limited warranty and the software's author, the holder of the + economic rights, and the successive licensors have only limited + liability. + + In this respect, the user's attention is drawn to the risks associated + with loading, using, modifying and/or developing or reproducing the + software by the user in light of its specific status of free software, + that may mean that it is complicated to manipulate, and that also + therefore means that it is reserved for developers and experienced + professionals having in-depth computer knowledge. Users are therefore + encouraged to load and test the software's suitability as regards their + requirements in conditions enabling the security of their systems and/or + data to be ensured and, more generally, to use and operate it in the + same conditions as regards security. + + The fact that you are presently reading this means that you have had + knowledge of the CeCILL license and that you accept its terms. + + /** + * Class TML2MappingSystemC + * Creation: 03/09/2007 + * @version 1.0 03/09/2007 + * @author Daniel Knorreck + * @see + */ + +package tmltranslator.tomappingsystemc2; + +import java.util.*; + +import tmltranslator.*; +import myutil.*; +import req.ebrdd.*; +import tepe.*; + + +public class DiploSimulatorCodeGenerator implements IDiploSimulatorCodeGenerator { + + private final static String CR = "\n"; + // private final static String CR2 = "\n\n"; + private final static String SCCR = ";\n"; + // private final static String EFCR = "}\n"; + // private final static String EFCR2 = "}\n\n"; + // private final static String EF = "}"; + //private final static int MAX_EVENT = 1024; + + private static final String SPACE = " "; + + private TMLModeling tmlmodeling; + private TMLMapping tmlmapping; + + private boolean debug; + private boolean optimize; + private String header, declaration, mainFile, src; + private ArrayList<MappedSystemCTask> tasks; + + //private ArrayList<EBRDD> ebrdds; + //private ArrayList<TEPE> tepes; + SystemCTEPE tepeTranslator; + //private ArrayList<SystemCEBRDD> systemCebrdds = new ArrayList<SystemCEBRDD>(); + + private final NamesGenerationHelper namesGen; + + DiploSimulatorCodeGenerator(TMLModeling _tmlm) { + this( _tmlm.getDefaultMapping() ); + + tmlmodeling = _tmlm; + tmlmodeling.removeForksAndJoins(); +// tmlmapping = tmlmodeling.getDefaultMapping(); +// tepeTranslator = new SystemCTEPE(new ArrayList<TEPE>(), this); + } + + DiploSimulatorCodeGenerator(TMLMapping _tmlmapping) { +// tmlmapping = _tmlmapping; +// tmlmapping.handleCPs(); +// tmlmapping.removeForksAndJoins(); +// tmlmapping.makeMinimumMapping(); +// tepeTranslator = new SystemCTEPE(new ArrayList<TEPE>(), this); + this( _tmlmapping, null, new ArrayList<TEPE>() ); + } + + DiploSimulatorCodeGenerator(TMLModeling _tmlm, List<EBRDD> _ebrdds, List<TEPE> _tepes) { + this( _tmlm.getDefaultMapping(), _ebrdds, _tepes ); + + tmlmodeling = _tmlm; +// tmlmapping = tmlmodeling.getDefaultMapping(); +// tepeTranslator = new SystemCTEPE(_tepes, this); + } + + DiploSimulatorCodeGenerator(TMLMapping _tmlmapping, List<EBRDD> _ebrdds, List<TEPE> _tepes) { + tmlmapping = _tmlmapping; + tmlmapping.handleCPs(); + tmlmapping.removeForksAndJoins(); + tmlmapping.makeMinimumMapping(); + tepeTranslator = new SystemCTEPE(_tepes, this ); + namesGen = NamesGenerationHelper.INSTANCE; + } + + public void saveFile(String path, String filename) throws FileException { + generateTaskFiles(path); + FileUtils.saveFile(path + filename + ".cpp", getFullCode()); + src += filename + ".cpp"; + FileUtils.saveFile(path + "Makefile.src", src); + //tepeTranslator.saveFile(path + "src_simulator/TEPE/test.h"); + } + + public String getFullCode() { + return mainFile; + } + + public void generateSystemC(boolean _debug, boolean _optimize) { + debug = _debug; + optimize = _optimize; + tmlmapping.removeAllRandomSequences(); + tmlmapping.handleCPs(); + tmlmodeling = tmlmapping.getTMLModeling(); + tasks = new ArrayList<MappedSystemCTask>(); + //generateSystemCTasks(); + //generateEBRDDs(); + generateMainFile(); + generateMakefileSrc(); + } + + private void generateMainFile() { + makeHeader(); + makeDeclarations(); + header += tepeTranslator.getEqFuncDeclaration() + "\n"; + mainFile = header + declaration; + mainFile = Conversion.indentString(mainFile, 4); + } + + private void generateMakefileSrc() { + src = "SRCS = "; + for(TMLTask mst: tmlmapping.getMappedTasks()) { + src += namesGen.cppFileName( mst.getName() ) + SPACE; + } + //for(EBRDD ebrdd: ebrdds){ + // src += ebrdd.getName() + ".cpp "; + //} + } + + private void makeHeader() { + // System headers + header = "#include <Simulator.h>" + CR; + header += "#include <AliasConstraint.h>\n#include <EqConstraint.h>\n#include <LogConstraint.h>\n#include <PropLabConstraint.h>\n"; + header += "#include <PropRelConstraint.h>\n#include <SeqConstraint.h>\n#include <SignalConstraint.h>\n#include <TimeMMConstraint.h>\n"; + header += "#include <TimeTConstraint.h>\n"; + header += "#include <CPU.h>\n#include <SingleCoreCPU.h>\n#include <RRScheduler.h>\n#include <RRPrioScheduler.h>\n#include <PrioScheduler.h>\n#include <Bus.h>\n"; + header += "#include <Bridge.h>\n#include <Memory.h>\n#include <TMLbrbwChannel.h>\n#include <TMLnbrnbwChannel.h>\n"; + header += "#include <TMLbrnbwChannel.h>\n#include <TMLEventBChannel.h>\n#include <TMLEventFChannel.h>\n#include <TMLEventFBChannel.h>\n"; + header += "#include <TMLTransaction.h>\n#include <TMLCommand.h>\n#include <TMLTask.h>\n"; + 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()) { + //header += "#include <" + mst.getReference() + ".h>" + 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; + //} + header += CR; + } + + private void makeDeclarations() { + declaration = "class CurrentComponents: public SimComponents{\npublic:\nCurrentComponents():SimComponents(" + tmlmapping.getHashCode() + "){\n"; + + // Declaration of HW nodes + declaration += "//Declaration of CPUs" + CR; + for(HwNode node: tmlmapping.getTMLArchitecture().getHwNodes()) { + if (node instanceof HwCPU) { + 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 { + //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; + } + + 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; + + if ( cores != 0 ) { + declaration += cpuInstName + "->setScheduler(" + schedulerInstName + ",false)" + SCCR; + } + + declaration += "addCPU(" + cpuInstName + ")"+ SCCR; + } + } + + if ( node instanceof HwA ) { + 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; + + // 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 + ", "; + + 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 += CR; + + // Declaration of Buses + declaration += "//Declaration of Buses" + CR; + + 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 + ","; + + if ( thisBus.arbitration==HwBus.CAN ) { + declaration += Boolean.TRUE.toString(); + } + else { + declaration += Boolean.FALSE.toString(); + } + + declaration += ");\naddBus(" + busInstName + ")"+ SCCR; + } + } + } + + declaration += CR; + + // Declaration of Bridges + declaration += "//Declaration of Bridges" + CR; + + 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; + } + } + + declaration += CR; + + // Declaration of Memories + declaration += "//Declaration of Memories" + CR; + + 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; + } + } + + declaration += CR; + + //Declaration of Bus masters + declaration += "//Declaration of Bus masters" + CR; + 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 ) { + final int noOfCores; + + if ( node instanceof HwCPU ) { + noOfCores = ((HwCPU)node).nbOfCores; + } + else { + noOfCores = 1; + } + + 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 ); + } + + 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; + + for(int i=0; i< link.bus.pipelineSize; i++) { + declaration+= ", (SchedulableCommDevice*) " + namesGen.schedComDeviceInstanceName( link.bus, i ); + } + + declaration+= "))" + SCCR; + + declaration+= nodeInstanceName + "->addBusMaster(" + busMasterInstName + ")" + SCCR; + } + } + } + } + + declaration += CR; + + // Declaration of channels + declaration += "//Declaration of channels" + CR; + + for ( final TMLElement elem : tmlmodeling.getChannels() ) { + if (elem instanceof TMLChannel) { + final TMLChannel channel = (TMLChannel)elem; + + final String channelTypeName = namesGen.channelTypeName( channel ); + final String channelInstName = namesGen.channelInstanceName( channel ); + + 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= ""; + } + + declaration += determineRouting(tmlmapping.getHwNodeOf(channel.getOriginTask()), tmlmapping.getHwNodeOf(channel.getDestinationTask()), elem) + param + "," + channel.getPriority(); + + if (channel.isLossy() && channel.getType()!=TMLChannel.NBRNBW) { + declaration += "," + channel.getLossPercentage() + "," + channel.getMaxNbOfLoss(); + } + + declaration += ")"+ SCCR; + declaration += "addChannel("+ channelInstName +")"+ SCCR; + } + } + + declaration += CR; + + // Declaration of events + declaration += "//Declaration of events" + CR; + + for( final TMLEvent evt : tmlmodeling.getEvents() ) { + final String eventTypeName = namesGen.eventTypeName( evt ); + + final String param; + + if (evt.isInfinite()) { + param= ",0,false,false"; + } + else { + if (evt.isBlocking()) { + param= "," + evt.getMaxSize() + ",0"; + } + else { + param= "," + evt.getMaxSize() + ",0"; + } + } + + final String eventInstName = namesGen.eventInstanceName( evt ); + final String eventName = namesGen.eventName( evt ); + + 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{ + declaration += eventTypeName + "* " + eventInstName + " = new " + eventTypeName + "(" + evt.getID() + ",\"" + eventName + "\",0,0,0" + param; ///old command + } + + if (evt.isLossy()) { + declaration += "," + evt.getLossPercentage() + "," + evt.getMaxNbOfLoss(); + } + + declaration += ")" + SCCR; + declaration += "addEvent("+ eventInstName +")"+ SCCR; + } + + declaration += CR; + + // Declaration of requests + declaration += "//Declaration of requests" + CR; + + for(TMLTask task: tmlmodeling.getTasks()) { + if (task.isRequested()) { + final String reqChannelInstName = namesGen.requestChannelInstanceName( task ); + TMLRequest req = task.getRequest(); + + 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 { + 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"; + } + + if ( req.isLossy() ) { + declaration += "," + req.getLossPercentage() + "," + req.getMaxNbOfLoss(); + } + + declaration += ")" + SCCR; + + declaration += "addRequest( " + reqChannelInstName +")"+ SCCR; + } + } + + declaration += CR; + + //Set bus schedulers + declaration += "//Set bus schedulers" + CR; + + 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; + + 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)){ + final HwCPU cpu = (HwCPU) link.hwnode; + + 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 ); + numDevices++; + } + } + } + + 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("; + } + + 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; + } + } + } + + declaration += CR; + + //Declaration of Tasks + ListIterator<HwExecutionNode> iterator = tmlmapping.getNodes().listIterator(); + declaration += "//Declaration of tasks" + CR; + HwExecutionNode node; + //for(TMLTask task: tmlmodeling.getTasks()) { + List<TMLChannel> channels; + List<TMLEvent> events; + List<TMLRequest> requests; + int[] aStatistics = new int[8]; + Set<Integer> mappedChannels = new HashSet<Integer>(); + + for(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("; + + 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 ); + } + + declaration+= "),1" + CR; + } + else if ( node instanceof HwA ) { + throw new UnsupportedOperationException( "Not implemented for HWA!" ); + + // DB: TODO copy paste error?? This will cause class cast exception +// declaration+= ((HwCPU)node).nbOfCores; +// +// for (int cores=0; cores< ((HwCPU)node).nbOfCores; cores++){ +// declaration+= "," + node.getName()+cores; +// } +// +// declaration+= ")," + ((HwCPU)node).nbOfCores + CR; + } + else { + throw new UnsupportedOperationException( "Not implemented for " + node.getClass().getSimpleName() + "!" ); + // DB: TODO what other type could this be? Only HwA and HwCPU extends the abstract class HwExecutionNode + //declaration += "1," + node.getName() + "),1" + CR; + } + + MappedSystemCTask mst; + channels = new ArrayList<TMLChannel>(tmlmodeling.getChannels(task)); + events = new ArrayList<TMLEvent>(tmlmodeling.getEvents(task)); + requests = new ArrayList<TMLRequest>(tmlmodeling.getRequests(task)); + + mst = new MappedSystemCTask(task, channels, events, requests, tmlmapping, mappedChannels); + tasks.add(mst); + + for( final TMLChannel channelb : channels ) { + declaration += "," + namesGen.channelInstanceName( channelb ) + 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; + } + } + + if (task.isRequested()) { + declaration += "," + namesGen.requestChannelInstanceName( task ) + CR; + } + + declaration += ")" + SCCR; + declaration += "addTask(" + namesGen.taskInstanceName( task ) +")"+ SCCR; + } + + declaration += "}\n\n"; + + //Declaration of TEPEs + declaration += "void generateTEPEs(){" + CR; + declaration += "//Declaration of TEPEs" + CR; + tepeTranslator.generateTEPEs(); + declaration += tepeTranslator.getCode(); + + //Generation of tasks + for(MappedSystemCTask task: tasks){ + task.determineCheckpoints(aStatistics); + task.generateSystemC(debug, optimize); + } + + //Declaration of TEPEs continued + declaration += CR; + 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) TraceManager.addDev("Global gain checkpoints " + 100 * aStatistics[7] / aStatistics[6]); + + //Declaration of EBRDDs + /*declaration += "//Declaration of EBRDDs" + CR; + for(EBRDD ebrdd: ebrdds){ + declaration += ebrdd.getName() + "* ebrdd__" + ebrdd.getName() + " = new " + ebrdd.getName() + "(0, \""+ ebrdd.getName() + "\");\n"; + declaration += "addEBRDD(ebrdd__"+ ebrdd.getName() +")"+ SCCR; + }*/ + } + + 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; + boolean reverse = reverseIn; + + if (reverseIn) { + slaves.str += ",static_cast<Slave*>(0)"; + } + else { + //firstPart=startNode.getName() + "0"; + firstNode = startNode; + } + + for( final HwCommunicationNode commElem : path ) { + if ( commElem instanceof HwMemory ) { + reverse = true; + 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 ) { +// if ( firstPart.length()==0 ){ + firstNode = commElem; +// firstPart=commElem.getName(); + } + 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 ) + ")"; + firstNode = null; + //firstPart=""; + } + } + else { + if ( firstNode == null ) { +// if ( firstPart.length()==0 ){ + firstNode = commElem; + 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); +// masters.str+= "," + firstPart + "_" + commElem.getName() + "_Master"; + masterCount++; + firstNode = null; +// firstPart=""; + } + } + } + } + + if ( reverse ) { + masters.str += "," + namesGen.busMasterInstanceName( destNode, 0, (HwBus) firstNode ); +// masters.str+= "," + destNode.getName() + "0_" + firstPart + "_Master"; + + return masterCount + 1 ; + } + + slaves.str += ",static_cast<Slave*>(0)"; + + return - masterCount; + } + + private String determineRouting( HwNode startNode, HwNode destNode, TMLElement commElemToRoute ){ + + //TraceManager.addDev( "Determine routing from " + startNode.getName() + " to " + destNode.getName() ); + StrWrap masters = new StrWrap(); + StrWrap slaves = new StrWrap(); + + List<HwCommunicationNode> path = new LinkedList<HwCommunicationNode>(); + List<HwCommunicationNode> commNodes = new LinkedList<HwCommunicationNode>(); + + for( HwNode node: tmlmapping.getTMLArchitecture().getHwNodes() ) { + if( node instanceof HwCommunicationNode ) { + commNodes.add((HwCommunicationNode) node); + } + } +// if( startNode == null ) { +// TraceManager.addDev( "NULL REFERENCE" ); +// } +// else { +// //TraceManager.addDev( "startNode: " + startNode.getName() ); +// } + + HwMemory memory = getMemConnectedToBusChannelMapped( commNodes, null, commElemToRoute ); + + 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!!!!!!!!!!!!!!!!!!!!!!!!!!"); + } + + path.add( memory ); + + exploreBuses( 0, commNodes2, path, memory, destNode, commElemToRoute ); + } + + int hopNum = extractPath( path, masters, slaves, startNode, destNode, false ); + + if ( hopNum < 0 ) { + hopNum = extractPath( path, masters, slaves, destNode, destNode, true ) - hopNum; + } + + 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); + + return hopNum + ",array(" + hopNum + masters.str + "),array(" + hopNum + slaves.str + ")"; + } + + private boolean exploreBuses(int depth, List<HwCommunicationNode> commNodes, List<HwCommunicationNode> path, HwNode startNode, HwNode destNode, TMLElement commElemToRoute){ + //first called with Maping:getCommunicationNodes + List<HwCommunicationNode> nodesToExplore; + 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()); + nodesToExplore=getBusesConnectedToNode(commNodes, startNode); + }else{ + 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()); + 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"); + 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()); + path.add(currNode); + //if (memory!=null) path.add(memory); + commNodes.remove(currNode); + 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){ + //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; + path.remove(currNode); + //if (memory!=null) path.remove(memory); + commNodes.add(currNode); + } + 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; + } + } + } + return null; + } + + 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((HwBus)commNode); + } + } + return resultList; + } + + private List<HwCommunicationNode> getBridgesConnectedToBus( List<HwCommunicationNode> _commNodes, HwBus _bus){ + List<HwCommunicationNode> resultList = new LinkedList<HwCommunicationNode>(); + for(HwCommunicationNode commNode: _commNodes){ + if (commNode instanceof HwBridge){ + if (tmlmapping.getTMLArchitecture().isNodeConnectedToBus(commNode, _bus)) resultList.add((HwBridge)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; + } + return false; + } + + private void generateTaskFiles(String path) throws FileException { + for(MappedSystemCTask mst: tasks) { + mst.saveInFiles(path); + } + } + + public MappedSystemCTask getMappedTaskByName(String iName){ + for(MappedSystemCTask task: tasks){ + if (task.getTMLTask().getName().equals(iName)) return task; + } + return null; + } +} diff --git a/src/tmltranslator/tomappingsystemc2/DiploSimulatorFactory.java b/src/tmltranslator/tomappingsystemc2/DiploSimulatorFactory.java new file mode 100644 index 0000000000000000000000000000000000000000..651d5702e98696630fc1940c057fd4f6b652ace9 --- /dev/null +++ b/src/tmltranslator/tomappingsystemc2/DiploSimulatorFactory.java @@ -0,0 +1,36 @@ +package tmltranslator.tomappingsystemc2; + +import java.util.List; + +import req.ebrdd.EBRDD; +import tepe.TEPE; +import tmltranslator.TMLMapping; +import tmltranslator.TMLModeling; + +public class DiploSimulatorFactory { + + public static final DiploSimulatorFactory INSTANCE = new DiploSimulatorFactory(); + + private DiploSimulatorFactory() { + } + + public IDiploSimulatorCodeGenerator createTranslator( final TMLModeling tmlModeling ) { + return new DiploSimulatorCodeGenerator( tmlModeling ); + } + + public IDiploSimulatorCodeGenerator createTranslator( final TMLMapping tmlMapping ) { + return new DiploSimulatorCodeGenerator( tmlMapping ); + } + + public IDiploSimulatorCodeGenerator createTranslator( final TMLModeling tmlModeling, + final List<EBRDD> ebrdds, + final List<TEPE> tepes ) { + return new DiploSimulatorCodeGenerator( tmlModeling, ebrdds, tepes ); + } + + public IDiploSimulatorCodeGenerator createTranslator( final TMLMapping tmlMapping, + final List<EBRDD> ebrdds, + final List<TEPE> tepes ) { + return new DiploSimulatorCodeGenerator( tmlMapping, ebrdds, tepes ); + } +} diff --git a/src/tmltranslator/tomappingsystemc2/IDiploSimulatorCodeGenerator.java b/src/tmltranslator/tomappingsystemc2/IDiploSimulatorCodeGenerator.java new file mode 100644 index 0000000000000000000000000000000000000000..c9abd65af89c20c89a8e992c7c6727b6f1fa9a89 --- /dev/null +++ b/src/tmltranslator/tomappingsystemc2/IDiploSimulatorCodeGenerator.java @@ -0,0 +1,15 @@ +package tmltranslator.tomappingsystemc2; + +import myutil.FileException; + +public interface IDiploSimulatorCodeGenerator { + + MappedSystemCTask getMappedTaskByName( String iName ); + + void generateSystemC( boolean _debug, + boolean _optimize ); + + void saveFile( String path, + String filename ) + throws FileException; +} diff --git a/src/tmltranslator/tomappingsystemc2/MappedSystemCTask.java b/src/tmltranslator/tomappingsystemc2/MappedSystemCTask.java index 1867c6d6b193cddaab73677237ffa1e73c4ef3b9..a87dee6454d5a001acfd042a554d53f0279a0200 100755 --- a/src/tmltranslator/tomappingsystemc2/MappedSystemCTask.java +++ b/src/tmltranslator/tomappingsystemc2/MappedSystemCTask.java @@ -54,9 +54,9 @@ public class MappedSystemCTask { //private TMLModeling tmlm; private TMLTask task; private String reference, cppcode, hcode, initCommand, functions, functionSig, chaining, firstCommand, commentText; - private ArrayList<TMLChannel> channels; - private ArrayList<TMLEvent> events; - private ArrayList<TMLRequest> requests; + private List<TMLChannel> channels; + private List<TMLEvent> events; + private List<TMLRequest> requests; private TMLMapping tmlmapping; private int commentNum; private boolean debug; @@ -66,16 +66,16 @@ public class MappedSystemCTask { 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"; - private final static String EFCR = "}\n"; - private final static String EFCR2 = "}\n\n"; - private final static String EF = "}"; +// private final static String EFCR = "}\n"; +// private final static String EFCR2 = "}\n\n"; +// private final static String EF = "}"; - public MappedSystemCTask(TMLTask _task, ArrayList<TMLChannel> _channels, ArrayList<TMLEvent> _events, ArrayList<TMLRequest> _requests, TMLMapping _tmlmapping, Set<Integer> _depChannels) { + public MappedSystemCTask(TMLTask _task, List<TMLChannel> _channels, List<TMLEvent> _events, List<TMLRequest> _requests, TMLMapping _tmlmapping, Set<Integer> _depChannels) { task = _task; channels = _channels; events = _events; @@ -93,10 +93,6 @@ public class MappedSystemCTask { commentNum=0; optimize=false; - //for(TMLAttribute att: task.getAttributes()) { - // TraceManager.addDev ("************ Attribute: " + att.name); - //} - _analysis = new StaticAnalysis(_task, _channels, _events, _requests, _depChannels); _startAnaNode = _analysis.startAnalysis(); } @@ -152,9 +148,9 @@ public class MappedSystemCTask { code += "extern \"C\" bool condFunc(TMLTask* _ioTask_);\n"; return code; } - - private void classHCode() { - } +// +// private void classHCode() { +// } // CPP Code private void basicCPPCode() { diff --git a/src/tmltranslator/tomappingsystemc2/NamesGenerationHelper.java b/src/tmltranslator/tomappingsystemc2/NamesGenerationHelper.java new file mode 100644 index 0000000000000000000000000000000000000000..9d96d4b8a4378d280850019d05f439115d173bc1 --- /dev/null +++ b/src/tmltranslator/tomappingsystemc2/NamesGenerationHelper.java @@ -0,0 +1,436 @@ +package tmltranslator.tomappingsystemc2; + +import java.util.Arrays; +import java.util.Collection; + +import tmltranslator.CPPCodeGenerationHelper; +import tmltranslator.HwA; +import tmltranslator.HwBridge; +import tmltranslator.HwBus; +import tmltranslator.HwCPU; +import tmltranslator.HwCommunicationNode; +import tmltranslator.HwExecutionNode; +import tmltranslator.HwMemory; +import tmltranslator.HwNode; +import tmltranslator.TMLChannel; +import tmltranslator.TMLEvent; +import tmltranslator.TMLTask; + +public class NamesGenerationHelper { + + private static final String[] RESERVED_WORDS = { + "IndeterminismSource", + "Parameter", + "TMLActionCommand", + "TMLbrbwChannel", + "TMLChannel", + "TMLChoiceCommand", + "TMLCommand", + "TMLEventBChannel", + "TMLEventFChannel", + "TMLEventSizedChannel", + "TMLExeciCommand", + "TMLExeciRangeCommand", + "TMLnbrnbwChannel", + "TMLNotifiedCommand", + "TMLRandomChoiceCommand", + "TMLRandomCommand", + "TMLReadCommand", + "TMLRequestCommand", + "TMLSelectCommand", + "TMLSendCommand", + "TMLStateChannel", + "TMLStopCommand", + "TMLTask", + "TMLWaitCommand", + "TMLWriteCommand", + "TMLWriteMultCommand", + + "GeneralListener", + "SimComponents", + "RunXTransactions", + "Breakpoint", + "CondBreakpoint", + "RunTillNextRandomChoice", + "RunXCommands", + "RunXTimeUnits", + "RunTillTransOnDevice", + "RunTillTransOnTask", + "RunTillTransOnChannel", + "TEPESigListener", + "TEPEFloatingSigListener", + "TEPEEquationListener", + "TEPESettingListener", + "ListenerSubject", + + "Server", + "ServerExplore", + "ServerIF", + "ServerLocal", + "SimComponents", + "SimServSyncInfo", + "Simulator", + + "AliasConstraint", + "EqConstraint", + "FSMConstraint", + "LogConstraint", + "PropertyConstraint", + "PropertyStateConstraint", + "PropLabConstraint", + "PropRelConstraint", + "SeqConstraint", + "SignalConstraint", + "ThreeSigConstraint", + "TimeMMConstraint", + "TimeTConstraint", + "TwoSigConstraint", + + "Comment", + "SignalChangeData", + "MemPool", + "MemPoolNoDel", + "Serializable", + "TMLTransaction", + + "WAIT_SEND_VLEN", + "CLOCK_INC", + "BLOCK_SIZE_TRANS", + "BLOCK_SIZE_PARAM", + "BLOCK_SIZE_COMMENT", + "PARAMETER_BLOCK_SIZE", + "NO_EVENTS_TO_LOAD", + "PORT", + "BACKLOG", + "UNKNOWN", + "TERMINATED", + "RUNNING", + "RUNNABLE", + "SUSPENDED", + "INT_MSB", + "TAG_HEADER", + "TAG_STARTo", + "TAG_STARTc", + "TAG_ERRNOo", + "TAG_ERRNOc", + "TAG_MSGo", + "TAG_MSGc", + "TAG_TIMEo", + "TAG_TIMEc", + "TAG_SIMDURo", + "TAG_SIMDURc", + "TAG_CYCLESo", + "TAG_CYCLESc", + "TAG_TASKo", + "TAG_TASKc", + "TAG_TSKSTATEo", + "TAG_TSKSTATEc", + "TAG_VARo", + "TAG_VARc", + "TAG_STATUSo", + "TAG_STATUSc", + "TAG_REASONo", + "TAG_REASONc", + "TAG_GLOBALo", + "TAG_GLOBALc", + "TAG_CURRCMDo", + "TAG_CURRCMDc", + "TAG_CMDo", + "TAG_CMDc", + "TAG_EXECTIMESo", + "TAG_EXECTIMESc", + "TAG_STARTTIMEo", + "TAG_STARTTIMEc", + "TAG_FINISHTIMEo", + "TAG_FINISHTIMEc", + "TAG_STARTTIMETRANSo", + "TAG_STARTTIMETRANSc", + "TAG_FINISHTIMETRANSo", + "TAG_FINISHTIMETRANSc", + "TAG_BREAKCMDo", + "TAG_BREAKCMDc", + "TAG_NEXTCMDo", + "TAG_NEXTCMDc", + "TAG_HASHo", + "TAG_HASHc", + "TAG_BRANCHo", + "TAG_BRANCHc", + "TAG_REPLYo", + "TAG_REPLYc", + "TAG_EXTIMEo", + "TAG_EXTIMEc", + "TAG_CONTDELo", + "TAG_CONTDELc", + "TAG_TRANSo", + "TAG_TRANSc", + "TAG_TRANSACTION_NBo", + "TAG_TRANSACTION_NBc", + "TAG_BUSo", + "TAG_BUSc", + "TAG_CHANNELo", + "TAG_CHANNELc", + "TAG_TOWRITEo", + "TAG_TOWRITEc", + "TAG_TOREADo", + "TAG_TOREADc", + "TAG_CONTENTo", + "TAG_CONTENTc", + "TAG_PARAMo", + "TAG_PARAMc", + "TAG_Pxo", + "TAG_Pxc", + "TAG_UTILo", + "TAG_UTILc", + "TAG_CPUo", + "TAG_CPUc", + "TAG_PROGRESSo", + "TAG_PROGRESSc", + "TAG_CURRTASKo", + "TAG_CURRTASKc", + "TAG_ENERGYo", + "TAG_ENERGYc", + + "Bridge", + "Bus", + "CPU", + "Memory", + "PrioScheduler", + "RRPrioScheduler", + "RRScheduler", + "SchedulableCommDevice", + "SchedulableDevice", + "SingleCoreCPU", + "Slave", + "TraceableDevice", + "WorkloadSource", + }; + + private static final Collection<String> RESERVED_WORDS_LIST = Arrays.asList( RESERVED_WORDS ); + + + public static final String LEFT_ANGLE_RACKET = "<"; + public static final String RIGHT_ANGLE_RACKET = ">"; + + public static final NamesGenerationHelper INSTANCE = new NamesGenerationHelper(); + + private NamesGenerationHelper() { + } + + String cppFileName( final String name ) { + return CPPCodeGenerationHelper.cppFileName( name ); + } + + String headerFileName( final String name ) { + return CPPCodeGenerationHelper.headerFileName( name ); + } + + String hardwareNodeInstanceName( final HwNode element, + final int index ) { + if ( element instanceof HwCommunicationNode ) { + return communicationNodeInstanceName( (HwCommunicationNode) element, index ); + } + + if ( element instanceof HwExecutionNode ) { + return executionNodeInstanceName( (HwExecutionNode) element, index ); + } + + throw new UnsupportedOperationException(); + } + + String communicationNodeInstanceName( final HwCommunicationNode element, + final int index ) { + if ( element instanceof HwMemory ) { + return memoryInstanceName( (HwMemory) element ); + } + + if ( element instanceof HwBus ) { + return busInstanceName( (HwBus) element, index ); + } + + if ( element instanceof HwBridge ) { + return bridgeInstanceName( (HwBridge) element ); + } + + throw new UnsupportedOperationException(); + } + + String prioSchedulerInstanceName( final HwCPU element ) { + return normalize( element.getName() + "_scheduler" ); + } + + String prioSchedulerName( final HwBus element ) { + return element.getName() + "_PrioSched"; + } + + String prioSchedulerName( final HwCPU element ) { + return element.getName() + "_PrioSched"; + } + + String rrSchedulerInstanceName( final HwExecutionNode element ) { + return normalize( element.getName() + "_scheduler" ); + } + + String rrSchedulerName( final HwBus element ) { + return element.getName() + "_RRSched"; + } + + String rrSchedulerName( final HwExecutionNode element ) { + return element.getName() + "_RRSched"; + } + + String executionNodeInstanceName( final HwExecutionNode element, + final int index ) { + if ( element instanceof HwCPU ) { + return cpuInstanceName( (HwCPU) element, index ); + } + + if ( element instanceof HwA ) { + return hwAccInstanceName( (HwA) element ); + } + + throw new UnsupportedOperationException( "Unknown execution node type: " + String.valueOf( element ) ); + } + + String cpuInstanceName( final HwCPU element, + final int indexCore ) { + return normalize( cpuName( element, indexCore ) ); + } + + String cpuName( final HwCPU element, + final int indexCore ) { + return element.getName() + indexSuffix( indexCore ); + } + + String hwAccInstanceName( final HwA element ) { + return normalize( hwAccName( element ) ); + } + + String hwAccName( final HwA element ) { + return element.getName(); + } + + String busInstanceName( final HwBus element, + final int pipelineIndex ) { + return normalize( busName( element, pipelineIndex ) ); + } + + String busName( final HwBus element, + final int pipelineIndex ) { + return element.getName() + indexSuffix( pipelineIndex ); + } + + String bridgeInstanceName( final HwBridge element ) { + return normalize( bridgeName( element ) + "brd" ); + } + + String bridgeName( final HwBridge element ) { + return element.getName(); + } + + String memoryInstanceName( final HwMemory element ) { + return normalize( memoryName( element ) ); + } + + String memoryName( final HwMemory element ) { + return element.getName(); + } + + String busMasterInstanceName( final HwNode element, + final int indexCore, + final HwBus linkBus ) { + return normalize( busMasterName( element, indexCore, linkBus ) ); + } + + String busMasterName( final HwNode element, + final int indexCore, + final HwBus linkBus ) { + return element.getName() + indexSuffix( indexCore ) + "_" + linkBus.getName() + "_Master"; + } + + String channelTypeName( final TMLChannel element ) { + switch( element.getType() ) { + case TMLChannel.BRBW: + return "TMLbrbwChannel"; + case TMLChannel.BRNBW: + return "TMLbrnbwChannel"; + case TMLChannel.NBRNBW: + default: + return "TMLnbrnbwChannel"; + } + } + + String channelInstanceName( final TMLChannel element ) { + return CPPCodeGenerationHelper.normalize( element.getExtendedName() ); + } + + String channelName( final TMLChannel element ) { + return element.getName(); + } + + String eventTypeName( final TMLEvent evt ) { + final String typeName; + + if ( evt.isInfinite() ) { + typeName = "TMLEventBChannel"; + } + else if ( evt.isBlocking() ) { + typeName = "TMLEventFBChannel"; + } + else { + typeName = "TMLEventFChannel"; + } + + return typeName + LEFT_ANGLE_RACKET + "ParamType," + evt.getNbOfParams() + RIGHT_ANGLE_RACKET; + } + + String eventInstanceName( final TMLEvent element ) { + return normalize( element.getExtendedName() ); + } + + String eventName( final TMLEvent element ) { + return element.getName(); + } + + String requestChannelInstanceName( final TMLTask element ) { + return normalize( "reqChannel_" + element.getName() ); + } + + String schedComDeviceInstanceName( final HwBus element, + final int index ) { + return normalize( element.getName() + indexSuffix( index ) ); + } + + String taskTypeName( final TMLTask element ) { + return normalize( element.getName() ); + } + + String taskInstanceName( final TMLTask element ) { + return normalize( "task__" + taskName( element ) ); + } + + String taskName( final TMLTask element ) { + return element.getName(); + } + + String workloadSourceInstanceName( final HwNode linkedHwNode, + final int indexCore, + final HwBus bus ) { + return busMasterInstanceName( linkedHwNode, indexCore, bus ); + } + + private String indexSuffix( final int index ) { + return index >= 0 ? "_" + index : ""; + } + + public static String normalize( final String name ) { + return CPPCodeGenerationHelper.normalize( removeReservedWords( name ) ); + } + + public static String removeReservedWords( final String name ) { + if ( RESERVED_WORDS_LIST.contains( name ) ) { + return normalize( name + CPPCodeGenerationHelper.NORMALIZATION_SUFFIX ); + } + + return name; + } +} diff --git a/src/tmltranslator/tomappingsystemc2/StaticAnalysis.java b/src/tmltranslator/tomappingsystemc2/StaticAnalysis.java index 3f712d53f529bd461ef4504743535e3104491eeb..77ecbd05cc15f7b2717377b1757786784ac673d9 100644 --- a/src/tmltranslator/tomappingsystemc2/StaticAnalysis.java +++ b/src/tmltranslator/tomappingsystemc2/StaticAnalysis.java @@ -8,12 +8,12 @@ import myutil.*; //import java.util.HashSet; public class StaticAnalysis{ - private ArrayList<LiveVariableNode> liveNodes= new ArrayList<LiveVariableNode>(); + private List<LiveVariableNode> liveNodes= new ArrayList<LiveVariableNode>(); private final static Pattern _varPattern = Pattern.compile("[\\w&&\\D]+[\\w]*"); private TMLTask _task; - private ArrayList<TMLChannel> _channels; - private ArrayList<TMLEvent> _events; - private ArrayList<TMLRequest> _requests; + private List<TMLChannel> _channels; + private List<TMLEvent> _events; + private List<TMLRequest> _requests; private int _nextDefID=0; private int[][] _varToDefs=null; @@ -22,7 +22,7 @@ public class StaticAnalysis{ private LiveVariableNode[] _defLookup=null; private Set<Integer> _depChannels; - public StaticAnalysis(TMLTask iTask, ArrayList<TMLChannel>iChannels, ArrayList<TMLEvent> iEvents, ArrayList<TMLRequest> iRequests, Set<Integer> iDepChannels){ + public StaticAnalysis(TMLTask iTask, List<TMLChannel>iChannels, List<TMLEvent> iEvents, List<TMLRequest> iRequests, Set<Integer> iDepChannels){ _task = iTask; _channels=iChannels; _events=iEvents; @@ -135,27 +135,27 @@ public class StaticAnalysis{ //anEvalFunc += "}\n\n"; return anEvalFunc; }*/ - - private void printLiveVarNode(LiveVariableNode iNode){ - int aSeq=0; - for(TMLAttribute att: _task.getAttributes()) { - if ((iNode.getOutVars()[aSeq >>> 5] & (1 << (aSeq & 0x1F)))!=0) - TraceManager.addDev(att.getName() + ": significant"); - aSeq++; - } - for(TMLChannel ch: _channels) { - if ((iNode.getOutVars()[aSeq >>> 5] & (1 << (aSeq & 0x1F)))!=0) - TraceManager.addDev(ch.getName() + ": significant"); - aSeq++; - } - for(TMLEvent evt: _events) { - if ((iNode.getOutVars()[aSeq >>> 5] & (1 << (aSeq & 0x1F)))!=0) - TraceManager.addDev(evt.getName() + ": significant"); - aSeq++; - } - if (_task.isRequested() && (iNode.getOutVars()[aSeq >>> 5] & (1 << (aSeq & 0x1F)))!=0) - TraceManager.addDev("reqChannel: significant"); - } +// +// private void printLiveVarNode(LiveVariableNode iNode){ +// int aSeq=0; +// for(TMLAttribute att: _task.getAttributes()) { +// if ((iNode.getOutVars()[aSeq >>> 5] & (1 << (aSeq & 0x1F)))!=0) +// TraceManager.addDev(att.getName() + ": significant"); +// aSeq++; +// } +// for(TMLChannel ch: _channels) { +// if ((iNode.getOutVars()[aSeq >>> 5] & (1 << (aSeq & 0x1F)))!=0) +// TraceManager.addDev(ch.getName() + ": significant"); +// aSeq++; +// } +// for(TMLEvent evt: _events) { +// if ((iNode.getOutVars()[aSeq >>> 5] & (1 << (aSeq & 0x1F)))!=0) +// TraceManager.addDev(evt.getName() + ": significant"); +// aSeq++; +// } +// if (_task.isRequested() && (iNode.getOutVars()[aSeq >>> 5] & (1 << (aSeq & 0x1F)))!=0) +// TraceManager.addDev("reqChannel: significant"); +// } public String printVariables(int[] iVariables){ String aResult=""; @@ -299,7 +299,7 @@ public class StaticAnalysis{ TraceManager.addDev("No checkpoint candidates"); else{ TraceManager.addDev("a: " + _task.getAttributes().size() + " c: " + _channels.size() + " e: " + _events.size()); - int aNbOfLiveElements = _task.getAttributes().size() + _channels.size() + _events.size(); + //int aNbOfLiveElements = _task.getAttributes().size() + _channels.size() + _events.size(); int nbOfVars=0, nbOfChannels=0, nbOfEvents=0; for(int i=0; i<_task.getAttributes().size(); i++) nbOfVars += aStatistics[i]; diff --git a/src/tmltranslator/tomappingsystemc2/strwrap.java b/src/tmltranslator/tomappingsystemc2/StrWrap.java similarity index 59% rename from src/tmltranslator/tomappingsystemc2/strwrap.java rename to src/tmltranslator/tomappingsystemc2/StrWrap.java index 53ffcdc61f2bdd06366680d4b77fab7a0b047f32..b68dad96564d8cfc13ad1c84e33e5183d95a73df 100755 --- a/src/tmltranslator/tomappingsystemc2/strwrap.java +++ b/src/tmltranslator/tomappingsystemc2/StrWrap.java @@ -1,11 +1,11 @@ package tmltranslator.tomappingsystemc2; -public class strwrap{ +public class StrWrap{ String str; - strwrap(String iStr){ + StrWrap(String iStr){ str=iStr; } - strwrap(){ + StrWrap(){ str=""; } } \ No newline at end of file diff --git a/src/tmltranslator/tomappingsystemc2/SystemCEBRDD.java b/src/tmltranslator/tomappingsystemc2/SystemCEBRDD.java index 2d8a7383d8dba9669794f044b6e2195020caf0cb..98b20593e514e28f0c8926b40ebce5741b91f4bb 100644 --- a/src/tmltranslator/tomappingsystemc2/SystemCEBRDD.java +++ b/src/tmltranslator/tomappingsystemc2/SystemCEBRDD.java @@ -322,7 +322,7 @@ public class SystemCEBRDD { } } else if(currElem instanceof EBRDDERC){ cmdName= "_erc" + currElem.getID(); - strwrap ETDeclare=new strwrap(), ETInit=new strwrap(); + StrWrap ETDeclare=new StrWrap(), ETInit=new StrWrap(); LinkedList<String> erbFuncs = new LinkedList<String>(); hcode+= cmdName + "_class " + cmdName + SCCR; //ERC declaration!!! @@ -447,7 +447,7 @@ public class SystemCEBRDD { hcode += "};" + CR + "#endif" + CR; } - private int buildET(ERCElement currElem, String ancestor, int newID, strwrap ETDeclare, strwrap ETInit, LinkedList<String> erbFuncs){ + private int buildET(ERCElement currElem, String ancestor, int newID, StrWrap ETDeclare, StrWrap ETInit, LinkedList<String> erbFuncs){ if (currElem==null) return newID; String negated = (currElem.isNegated())? "true":"false"; newID++; diff --git a/src/tmltranslator/tomappingsystemc2/SystemCTEPE.java b/src/tmltranslator/tomappingsystemc2/SystemCTEPE.java index 01c9c29af80b4e655d86e8133c1d924a81d76f41..5f02acc621433fe44220d4778fb457a39e54c150 100644 --- a/src/tmltranslator/tomappingsystemc2/SystemCTEPE.java +++ b/src/tmltranslator/tomappingsystemc2/SystemCTEPE.java @@ -46,7 +46,6 @@ knowledge of the CeCILL license and that you accept its terms. package tmltranslator.tomappingsystemc2; import java.util.*; -import tmltranslator.*; import myutil.*; import tepe.*; import java.util.regex.*; @@ -54,26 +53,26 @@ import java.util.regex.*; public class SystemCTEPE { - private final static String CR = "\n"; - private final static String CR2 = "\n\n"; +// private final static String CR = "\n"; +// private final static String CR2 = "\n\n"; private final static String SCCR = ";\n"; - private final static String EFCR = "}\n"; - private final static String EFCR2 = "}\n\n"; - private final static String EF = "}"; +// private final static String EFCR = "}\n"; +// private final static String EFCR2 = "}\n\n"; +// private final static String EF = "}"; private final static Pattern _varPattern = Pattern.compile("[\\w&&\\D]+[\\w]*"); - private ArrayList<TEPE> _tepes; + private List<TEPE> _tepes; private int _nbOfFloatingSig=0,_nbOfStartNodes=0; - private String _floatingSigProc="", _floatingSigComp="", _floatingEnaComp="", _connect="", _declare="", _evtRegister="", _code="", _listeners="", _eqFuncs="", _eqFuncDecl=""; - TML2MappingSystemC _tmltranslator; + private String _floatingSigProc="", _floatingSigComp="", _floatingEnaComp="", _connect="", _declare="", /*_evtRegister="", */_code="", _listeners="", _eqFuncs="", _eqFuncDecl=""; + IDiploSimulatorCodeGenerator _tmltranslator; - public SystemCTEPE(ArrayList<TEPE> tepes, TML2MappingSystemC tmltranslator){ + public SystemCTEPE( List<TEPE> tepes, IDiploSimulatorCodeGenerator tmltranslator){ _tepes=tepes; _tmltranslator=tmltranslator; } public void generateTEPEs(){ _nbOfFloatingSig=0; _nbOfStartNodes=0; - _floatingSigProc=""; _floatingSigComp=""; _floatingEnaComp=""; _connect=""; _declare=""; _evtRegister=""; _listeners=""; _eqFuncs=""; _eqFuncDecl=""; + _floatingSigProc=""; _floatingSigComp=""; _floatingEnaComp=""; _connect=""; _declare=""; /*_evtRegister="";*/ _listeners=""; _eqFuncs=""; _eqFuncDecl=""; if (!_tepes.isEmpty()){ TraceManager.addDev("And the TEPEs are..............."); for(TEPE tepe: _tepes) { diff --git a/src/tmltranslator/tomappingsystemc2/TML2MappingSystemC.java b/src/tmltranslator/tomappingsystemc2/TML2MappingSystemC.java index 72dc435b08ebb3ce6bc4f92043f681ed58ecb33a..30a7718d95629e657cc7ba3ce46ba0ec6eff8f74 100755 --- a/src/tmltranslator/tomappingsystemc2/TML2MappingSystemC.java +++ b/src/tmltranslator/tomappingsystemc2/TML2MappingSystemC.java @@ -53,7 +53,7 @@ import req.ebrdd.*; import tepe.*; -public class TML2MappingSystemC { +public class TML2MappingSystemC implements IDiploSimulatorCodeGenerator { private final static String CR = "\n"; // private final static String CR2 = "\n\n"; @@ -91,7 +91,7 @@ public class TML2MappingSystemC { tepeTranslator = new SystemCTEPE(new ArrayList<TEPE>(), this); } - public TML2MappingSystemC(TMLModeling _tmlm, ArrayList<EBRDD> _ebrdds, ArrayList<TEPE> _tepes) { + public TML2MappingSystemC(TMLModeling _tmlm, List<EBRDD> _ebrdds, List<TEPE> _tepes) { tmlmodeling = _tmlm; //ebrdds = _ebrdds; tmlmapping = tmlmodeling.getDefaultMapping(); @@ -99,7 +99,7 @@ public class TML2MappingSystemC { //tepeTranslator.generateTEPEs(); } - public TML2MappingSystemC(TMLMapping _tmlmapping, ArrayList<EBRDD> _ebrdds, ArrayList<TEPE> _tepes) { + public TML2MappingSystemC(TMLMapping _tmlmapping, List<EBRDD> _ebrdds, List<TEPE> _tepes) { tmlmapping = _tmlmapping; tmlmapping.handleCPs(); tmlmapping.removeForksAndJoins(); @@ -502,7 +502,7 @@ public class TML2MappingSystemC { } - private int extractPath(LinkedList<HwCommunicationNode> path, strwrap masters, strwrap slaves, HwNode startNode, HwNode destNode, boolean reverseIn){ + private int extractPath(LinkedList<HwCommunicationNode> path, StrWrap masters, StrWrap slaves, HwNode startNode, HwNode destNode, boolean reverseIn){ String firstPart=""; //lastBus=""; int masterCount=0; boolean reverse=reverseIn; @@ -563,7 +563,7 @@ public class TML2MappingSystemC { private String determineRouting( HwNode startNode, HwNode destNode, TMLElement commElemToRoute ){ //TraceManager.addDev( "Determine routing from " + startNode.getName() + " to " + destNode.getName() ); - strwrap masters=new strwrap(), slaves=new strwrap(); + StrWrap masters=new StrWrap(), slaves=new StrWrap(); LinkedList<HwCommunicationNode> path = new LinkedList<HwCommunicationNode>(); LinkedList<HwCommunicationNode> commNodes = new LinkedList<HwCommunicationNode>(); diff --git a/src/ui/TGComponentManager.java b/src/ui/TGComponentManager.java index c755fe5c2ea98670af83b14988ef46edc970fb95..cdac62bbe059b7fd27688a81c9dbb429889e359d 100755 --- a/src/ui/TGComponentManager.java +++ b/src/ui/TGComponentManager.java @@ -828,9 +828,9 @@ public class TGComponentManager { case SAFETY_PRAGMA: tgc = new AvatarBDSafetyPragma(x, y, tdp.getMinX(), tdp.getMaxX(), tdp.getMinY(), tdp.getMaxY(), false, null, tdp); break; - case AVATAR_FIREWALL: - tgc = new AvatarBDFirewall(x, y, tdp.getMinX(), tdp.getMaxX(), tdp.getMinY(), tdp.getMaxY(), false, null, tdp); - break; +// case AVATAR_FIREWALL: +// tgc = new AvatarBDFirewall(x, y, tdp.getMinX(), tdp.getMaxX(), tdp.getMinY(), tdp.getMaxY(), false, null, tdp); +// break; case IOD_CHOICE: tgc = new IODChoice(x, y, tdp.getMinX(), tdp.getMaxX(), tdp.getMinY(), tdp.getMaxY(), false, null, tdp); break; @@ -1781,8 +1781,8 @@ public class TGComponentManager { return TMLARCHI_BRIDGENODE; } else if (tgc instanceof TMLArchiFirewallNode) { return TMLARCHI_FIREWALL; - } else if (tgc instanceof AvatarBDFirewall) { - return AVATAR_FIREWALL; +// } else if (tgc instanceof AvatarBDFirewall) { +// return AVATAR_FIREWALL; } else if (tgc instanceof TMLArchiHWANode) { return TMLARCHI_HWANODE; } else if (tgc instanceof TMLArchiMemoryNode) { diff --git a/src/ui/window/JDialogSystemCGeneration.java b/src/ui/window/JDialogSystemCGeneration.java index 3d3a5788fa1f3ea475f2003138223acb8781636d..29da53423b24187fb62ea18a142d690a861951ae 100755 --- a/src/ui/window/JDialogSystemCGeneration.java +++ b/src/ui/window/JDialogSystemCGeneration.java @@ -87,6 +87,8 @@ import myutil.TraceManager; //import ui.ebrdd.*; import req.ebrdd.EBRDD; import tepe.TEPE; +import tmltranslator.tomappingsystemc2.IDiploSimulatorCodeGenerator; +import tmltranslator.tomappingsystemc2.DiploSimulatorFactory; import ui.AvatarRequirementPanelTranslator; import ui.IconManager; import ui.MainGUI; @@ -788,7 +790,6 @@ public class JDialogSystemCGeneration extends javax.swing.JDialog implements Act break; }*/ case 0: { //Simulator without CPs (Daniel's version) - tmltranslator.tomappingsystemc2.TML2MappingSystemC tml2systc; // Making EBRDDs ArrayList<EBRDD> al = new ArrayList<EBRDD>(); ArrayList<TEPE> alTepe = new ArrayList<TEPE>(); @@ -822,16 +823,23 @@ public class JDialogSystemCGeneration extends javax.swing.JDialog implements Act } }*/ + final IDiploSimulatorCodeGenerator tml2systc; + // Generating code if (mgui.gtm.getTMLMapping() == null) { if (mgui.gtm.getArtificialTMLMapping() == null) { - tml2systc = new tmltranslator.tomappingsystemc2.TML2MappingSystemC(mgui.gtm.getTMLModeling(), al, alTepe); - } else { + tml2systc = DiploSimulatorFactory.INSTANCE.createTranslator( mgui.gtm.getTMLModeling(), al, alTepe ); + //tml2systc = new tmltranslator.tomappingsystemc2.TML2MappingSystemC(mgui.gtm.getTMLModeling(), al, alTepe); + } + else { TraceManager.addDev("Using artifical mapping"); - tml2systc = new tmltranslator.tomappingsystemc2.TML2MappingSystemC(mgui.gtm.getArtificialTMLMapping(), al, alTepe); + tml2systc = DiploSimulatorFactory.INSTANCE.createTranslator( mgui.gtm.getArtificialTMLMapping(), al, alTepe ); + //tml2systc = new tmltranslator.tomappingsystemc2.TML2MappingSystemC(mgui.gtm.getArtificialTMLMapping(), al, alTepe); } - } else { - tml2systc = new tmltranslator.tomappingsystemc2.TML2MappingSystemC(mgui.gtm.getTMLMapping(), al, alTepe); + } + else { + tml2systc = DiploSimulatorFactory.INSTANCE.createTranslator( mgui.gtm.getTMLMapping(), al, alTepe ); +// tml2systc = new tmltranslator.tomappingsystemc2.TML2MappingSystemC(mgui.gtm.getTMLMapping(), al, alTepe); } tml2systc.generateSystemC(debugmode.isSelected(), optimizemode.isSelected());