diff --git a/src/tmltranslator/tomappingsystemc2/MappedSystemCTask.java b/src/tmltranslator/tomappingsystemc2/MappedSystemCTask.java index bc70559d31dc5025e0656d9b99cc2f38359062df..bed60199897c24bf1f46d5c89705afb573c88759 100755 --- a/src/tmltranslator/tomappingsystemc2/MappedSystemCTask.java +++ b/src/tmltranslator/tomappingsystemc2/MappedSystemCTask.java @@ -161,7 +161,7 @@ public class MappedSystemCTask { makeHeaderClassH(); makeEndClassH(); - cppcode+=reference+ "::" + makeConstructorSignature()+":TMLTask(iID, iPriority,iName,iCPU)"+ CR + makeAttributesCode(); + cppcode+=reference+ "::" + makeConstructorSignature()+":TMLTask(iID, iPriority,iName,iCPUs)"+ 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; @@ -205,7 +205,7 @@ public class MappedSystemCTask { } private String makeConstructorSignature(){ - String constSig=reference+ "(ID iID, Priority iPriority, std::string iName, CPU* iCPU"+CR; + String constSig=reference+ "(ID iID, Priority iPriority, std::string iName, CPU* iCPUs"+CR; for(TMLChannel ch: channels) { constSig+=", TMLChannel* "+ ch.getExtendedName() + CR; } @@ -460,20 +460,64 @@ public class MappedSystemCTask { } else if (currElem instanceof TMLForLoop){ + //makeCommands(TMLActivityElement currElem, boolean skip, String retElement, MergedCmdStr nextCommandCont, String retElseElement) if (debug) System.out.println("Checking Loop\n"); TMLForLoop fl = (TMLForLoop)currElem; - TMLActionState initAction=new TMLActionState("lpInitAc",null); - initAction.setAction(fl.getInit()); - TMLActionState incAction=new TMLActionState("#"+ fl.getID() + "\\lpIncAc",null); - incAction.setAction(fl.getIncrement()); - TMLChoice lpChoice=new TMLChoice("#"+ fl.getID() + "\\lpChoice",null); - lpChoice.addGuard("[ " + fl.getCondition() + " ]"); - lpChoice.addGuard("[ else ]"); - lpChoice.addNext(fl.getNextElement(0)); //inside loop - lpChoice.addNext(fl.getNextElement(1)); //after loop cmdName= "_choice" + currElem.getID(); - makeCommands(incAction, false, "&_lpChoice" + fl.getID(), null, null); - makeCommands(lpChoice, false, "&_lpIncAc" + fl.getID(), null, retElement); - return makeCommands(initAction, false, "&_lpChoice" + fl.getID(), nextCommandCont, null); + 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); + incAction.setAction(fl.getIncrement()); + String firstCmdInLoop= makeCommands(fl.getNextElement(0), false, "&_lpIncAc" + fl.getID(), null, null); + makeCommands(incAction, false, firstCmdInLoop, null, null); + if (fl.getInit().isEmpty()){ + return firstCmdInLoop; + }else{ + TMLActionState initAction=new TMLActionState("lpInitAc",null); + initAction.setAction(fl.getInit()); + return makeCommands(initAction, false, firstCmdInLoop, nextCommandCont, null); + } + + }else{ + /*TMLActionState initAction=new TMLActionState("lpInitAc",null); + initAction.setAction(fl.getInit()); + TMLActionState incAction=new TMLActionState("#"+ fl.getID() + "\\lpIncAc",null); + incAction.setAction(fl.getIncrement()); + TMLChoice lpChoice=new TMLChoice("#"+ fl.getID() + "\\lpChoice",null); + if (fl.getCondition().isEmpty()) + lpChoice.addGuard("[ true ]"); + else + lpChoice.addGuard("[ " + fl.getCondition() + " ]"); + lpChoice.addGuard("[ else ]"); + lpChoice.addNext(fl.getNextElement(0)); //inside loop + lpChoice.addNext(fl.getNextElement(1)); //after loop cmdName= "_choice" + currElem.getID(); + makeCommands(incAction, false, "&_lpChoice" + fl.getID(), null, null); + makeCommands(lpChoice, false, "&_lpIncAc" + fl.getID(), null, retElement); + return makeCommands(initAction, false, "&_lpChoice" + fl.getID(), nextCommandCont, null);*/ + + TMLChoice lpChoice=new TMLChoice("#"+ fl.getID() + "\\lpChoice",null); + //if (fl.getCondition().isEmpty()) + // lpChoice.addGuard("[ true ]"); + //else + lpChoice.addGuard("[ " + fl.getCondition() + " ]"); + 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()){ + makeCommands(lpChoice, false, "&_lpChoice" + fl.getID(), null, retElement); + }else{ + TMLActionState incAction=new TMLActionState("#"+ fl.getID() + "\\lpIncAc",null); + incAction.setAction(fl.getIncrement()); + makeCommands(incAction, false, "&_lpChoice" + fl.getID(), null, null); + makeCommands(lpChoice, false, "&_lpIncAc" + fl.getID(), null, retElement); + } + if (fl.getInit().isEmpty()){ + return "&_lpChoice" + fl.getID(); + }else{ + TMLActionState initAction=new TMLActionState("lpInitAc",null); + initAction.setAction(fl.getInit()); + return makeCommands(initAction, false, "&_lpChoice" + fl.getID(), nextCommandCont, null); + } + } } else if (currElem instanceof TMLReadChannel){ if (debug) System.out.println("Checking Read\n"); @@ -594,6 +638,7 @@ public class MappedSystemCTask { } TMLChoice choice = (TMLChoice)currElem; String code = "", nextCommandTemp="", MCResult=""; + boolean moreThanTwoGuards=false; if (debug) System.out.println("Checking Choice\n"); if (choice.getNbGuard() !=0 ) { String guardS = "",code2; @@ -602,6 +647,17 @@ public class MappedSystemCTask { int nbS = choice.nbOfStochasticGuard(); if ((nb > 0) || (nbS > 0)){ code += "rnd__0 = myrand(0, 99)" + SCCR; + }else{ + if (choice.getNbGuard()>1 && !(choice.getNbGuard()==2 && choice.getElseGuard()!=-1)){ + moreThanTwoGuards=true; + code+="rnd__0 = 0" + SCCR; + for(int i=0; i<choice.getNbGuard(); i++) { + if (i!=index1 && i!=index2) + code+="if (" + choice.getGuard(i) + ") rnd__0++" + SCCR; + } + code = Conversion.replaceAllChar(code, '[', "("); + code = Conversion.replaceAllChar(code, ']', ")"); + } } nb = 0; for(int i=0; i<choice.getNbGuard(); i++) { @@ -621,6 +677,10 @@ public class MappedSystemCTask { nbS ++; } else { code2 = choice.getGuard(i); + if (!moreThanTwoGuards || i+1==choice.getNbGuard() || i==index1) + code2 = choice.getGuard(i); + else + code2 = "(" + choice.getGuard(i) + "&& myrand(1,rnd__0)==1)"; code2 = Conversion.replaceAllChar(code2, '[', "("); code2 = Conversion.replaceAllChar(code2, ']', ")"); } diff --git a/src/tmltranslator/tomappingsystemc2/TML2MappingSystemC.java b/src/tmltranslator/tomappingsystemc2/TML2MappingSystemC.java index 1eddbce37f79690d915b3bf272859caadc093504..22e36f864f816b73a212de31d04d33f65011959c 100755 --- a/src/tmltranslator/tomappingsystemc2/TML2MappingSystemC.java +++ b/src/tmltranslator/tomappingsystemc2/TML2MappingSystemC.java @@ -111,6 +111,7 @@ public class TML2MappingSystemC { public void generateSystemC(boolean _debug, boolean _optimize) { debug = _debug; optimize = _optimize; + tmlmapping.removeAllRandomSequences(); dependencies.clear(); tmlmodeling = tmlmapping.getTMLModeling(); tasks = new ArrayList<MappedSystemCTask>(); @@ -169,7 +170,7 @@ public class TML2MappingSystemC { if (node instanceof HwCPU) { //if (tmlmapping.isAUsedHwNode(node)) { HwCPU exNode = (HwCPU)node; - declaration += "CPU* " + exNode.getName() + " = new CPU(" + exNode.getID() + ", \"" + exNode.getName() + "\", "; + declaration += "CPU* " + exNode.getName() + " = new SingleCoreCPU(" + exNode.getID() + ", \"" + exNode.getName() + "\", "; if (exNode.getType().equals("CPURRPB")) declaration += "new PrioScheduler(\"" + exNode.getName() + "_PrioSched\",0), "; else @@ -189,9 +190,12 @@ public class TML2MappingSystemC { for(HwNode node: tmlmapping.getTMLArchitecture().getHwNodes()) { if (node instanceof HwBus) { //if (tmlmapping.isAUsedHwNode(node)) { - declaration += "Bus* " + node.getName() + " = new Bus("+ node.getID() + ",\"" + node.getName() + "\",0, 100, "+ ((HwBus)node).byteDataSize + ", " + node.clockRatio + ","; - if(((HwBus)node).arbitration==HwBus.CAN) declaration +="true"; else declaration +="false"; - declaration += ");\naddBus("+ node.getName() +")"+ SCCR; + HwBus thisBus = (HwBus)node; + for(int i=0; i< thisBus.pipelineSize; i++){ + declaration += "Bus* " + node.getName() + "_" + i + " = new Bus("+ node.getID() + ",\"" + node.getName() + "_" + i + "\",0, 100, "+ thisBus.byteDataSize + ", " + node.clockRatio + ","; + if(thisBus.arbitration==HwBus.CAN) declaration +="true"; else declaration +="false"; + declaration += ");\naddBus("+ node.getName() + "_" + i + ")"+ SCCR; + } //} } } @@ -228,8 +232,11 @@ public class TML2MappingSystemC { //declaration+= "BusMaster* " + node.getName() + "2defaultBus = new BusMaster(\"" + node.getName() + "2defaultBus\", 0, defaultBus)" + SCCR; //else{ for(HwLink link: nodeLinks){ - declaration+= "BusMaster* " + node.getName() + "_" + link.bus.getName() + "_Master = new BusMaster(\"" + node.getName() + "_" + link.bus.getName() + "_Master\", " + link.getPriority() + ", 1, array(1, (SchedulableCommDevice*)" + link.bus.getName() + "))" + SCCR; - //declaration+= "BusMaster* " + node.getName() + "_" + link.bus.getName() + "_Master = new BusMaster(\"" + node.getName() + "_" + link.bus.getName() + "_Master\", " + link.getPriority() + ", " + link.bus.getName() + ")" + SCCR; + //declaration+= "BusMaster* " + node.getName() + "_" + link.bus.getName() + "_Master = new BusMaster(\"" + node.getName() + "_" + link.bus.getName() + "_Master\", " + link.getPriority() + ", 1, array(1, (SchedulableCommDevice*)" + link.bus.getName() + "))" + SCCR; + declaration+= "BusMaster* " + node.getName() + "_" + link.bus.getName() + "_Master = new BusMaster(\"" + node.getName() + "_" + link.bus.getName() + "_Master\", " + link.getPriority() + ", " + link.bus.pipelineSize + ", array(" + link.bus.pipelineSize; + for(int i=0; i< link.bus.pipelineSize; i++) + declaration+= ", (SchedulableCommDevice*)" + link.bus.getName() + "_" + i; + declaration+= "))" + SCCR; declaration+= node.getName() + "->addBusMaster(" + node.getName() + "_" + link.bus.getName() + "_Master)" + SCCR; } } @@ -295,7 +302,11 @@ public class TML2MappingSystemC { declaration += "//Declaration of requests" + CR; for(TMLTask task: tmlmodeling.getTasks()) { if (task.isRequested()){ - declaration += "TMLEventBChannel* reqChannel_"+ task.getName() + " = new TMLEventBChannel(" + task.getID() + ",\"reqChannel"+ task.getName() + "\",0,0,0,0,true)" + SCCR; + if (tmlmapping.isCommNodeMappedOn(task.getRequest(),null)){ + declaration += "TMLEventBChannel* reqChannel_"+ task.getName() + " = new TMLEventBChannel(" + task.getRequest().getID() + ",\"reqChannel"+ task.getName() + "\"," + determineRouting(tmlmapping.getHwNodeOf(task.getRequest().getOriginTasks().get(0)), tmlmapping.getHwNodeOf(task.getRequest().getDestinationTask()), task.getRequest()) + ",0,true)" + SCCR; + }else{ + declaration += "TMLEventBChannel* reqChannel_"+ task.getName() + " = new TMLEventBChannel(" + task.getRequest().getID() + ",\"reqChannel"+ task.getName() + "\",0,0,0,0,true)" + SCCR; + } declaration += "addRequest(reqChannel_"+ task.getName() +")"+ SCCR; } } @@ -315,14 +326,15 @@ public class TML2MappingSystemC { numDevices++; } } - declaration += node.getName() + "->setScheduler((WorkloadSource*) new "; + declaration += node.getName() + "_0->setScheduler((WorkloadSource*) new "; if (((HwBus)node).arbitration==HwBus.BASIC_ROUND_ROBIN) declaration+="RRScheduler(\"" + node.getName() + "_RRSched\", 0, 5, " + (int) Math.ceil(((float)node.clockRatio)/((float)((HwBus)node).byteDataSize)) + ", array("; else declaration+="PrioScheduler(\"" + node.getName() + "_PrioSched\", 0, array("; declaration+= numDevices + devices + "), " + numDevices + "))" + SCCR; } - + for(int i=1; i< ((HwBus)node).pipelineSize; i++) + declaration+=node.getName() + "_" + i + "->setScheduler(" + node.getName() + "_0->getScheduler(),false)" +SCCR; } } declaration += CR; @@ -391,7 +403,13 @@ public class TML2MappingSystemC { slaves.str+=",static_cast<Slave*>(0)"; else firstPart=startNode.getName(); + System.out.println("------------------------------------------------------"); + for(HwCommunicationNode commElem:path){ + System.out.println("CommELem to process: " + commElem.getName()); + } + System.out.println("------------------------------------------------------"); for(HwCommunicationNode commElem:path){ + System.out.println("CommELem to process: " + commElem.getName()); if (commElem instanceof HwMemory){ reverse=true; slaves.str+= ",static_cast<Slave*>(" + commElem.getName() + "),static_cast<Slave*>(" + commElem.getName() + ")";