diff --git a/executablecode/Makefile b/executablecode/Makefile index d861ff0349fef4b5c2d8ebbaf04d6bcdfeb08a06..a56336953daeaab017eb0a03d38167eab248328e 100755 --- a/executablecode/Makefile +++ b/executablecode/Makefile @@ -20,7 +20,7 @@ OBJDIR = lib MODULE = run SRCS_generated_DIR = generated_src/ include Makefile.src -SRCS_base = src/request.c src/message.c src/myerrors.c src/debug.c src/syncchannel.c src/asyncchannel.c src/request_manager.c src/random.c src/mytimelib.c +SRCS_base = src/request.c src/message.c src/myerrors.c src/debug.c src/syncchannel.c src/asyncchannel.c src/request_manager.c src/random.c src/mytimelib.c src/tracemanager.c SRCS_base_DIR = . SRCS_base_DIRSRC = src/ OBJS_executor = $(SRCS_base:%.c=lib/%.o) diff --git a/executablecode/src/request.h b/executablecode/src/request.h index 1ab2fa2fcc7d2edf7894a004b851178d7b80804b..926e59fb18c4819c12092725e1f2fe8653a4df7e 100644 --- a/executablecode/src/request.h +++ b/executablecode/src/request.h @@ -14,7 +14,6 @@ struct request; #define SEND_ASYNC_REQUEST 4 #define RECEIVE_ASYNC_REQUEST 6 #define DELAY 8 - #define IMMEDIATE 10 typedef struct timespec timespec; diff --git a/src/avatartranslator/toexecutable/AVATAR2CPOSIX.java b/src/avatartranslator/toexecutable/AVATAR2CPOSIX.java index 3cbde843a733e8df17a5b97a80fb498ccbf1d0b1..5aad67967e1cccc21c5698ea5b462dc2d2b228b5 100755 --- a/src/avatartranslator/toexecutable/AVATAR2CPOSIX.java +++ b/src/avatartranslator/toexecutable/AVATAR2CPOSIX.java @@ -74,6 +74,7 @@ public class AVATAR2CPOSIX { private int timeUnit; private boolean debug; + private boolean tracing; public AVATAR2CPOSIX(AvatarSpecification _avspec) { @@ -115,8 +116,9 @@ public class AVATAR2CPOSIX { - public void generateCPOSIX(boolean _debug) { + public void generateCPOSIX(boolean _debug, boolean _tracing) { debug = _debug; + tracing = _tracing; mainFile = new MainFile("main"); taskFiles = new Vector<TaskFile>(); @@ -214,7 +216,7 @@ public class AVATAR2CPOSIX { } else { ret += getCTypeOf(list.get(0)); } - ret += " " + _block.getName() + "__" + am.getName() + "("; + ret += " " + _block.getName() + "__" +am.getName() + "("; list = am.getListOfAttributes(); int cpt = 0; for(AvatarAttribute aa: list) { @@ -225,13 +227,22 @@ public class AVATAR2CPOSIX { cpt ++; } - ret += ") {" + CR + "debugMsg(\"-> ....() Executing method " + am.getName() + "\");" + CR; + ret += ") {" + CR; - list = am.getListOfAttributes(); - cpt = 0; - for(AvatarAttribute aa: list) { - ret += "debugInt(\"Attribute " + aa.getName() + " = \"," + aa.getName() + ");" + CR; + if (tracing) { + ret += traceFunctionCall(_block.getName(), am.getName()); + } + + if (debug) { + ret += "debugMsg(\"-> ....() Executing method " + am.getName() + "\");" + CR; + + list = am.getListOfAttributes(); + cpt = 0; + for(AvatarAttribute aa: list) { + ret += "debugInt(\"Attribute " + aa.getName() + " = \"," + aa.getName() + ");" + CR; + } } + ret += "}" + CR + CR; } _taskFile.addToMainCode(ret + CR); @@ -259,7 +270,7 @@ public class AVATAR2CPOSIX { s+= CR + "int __currentState = STATE__START__STATE;" + CR; int nbOfMaxParams = _block.getMaxNbOfParams(); - s+= "request *__req;" + CR; + //s+= "request *__req;" + CR; for(i=0; i<_block.getMaxNbOfMultipleBranches(); i++) { s+= "request __req" + i + ";" + CR; s+= "int *__params" + i + "[" + nbOfMaxParams + "];" + CR; @@ -282,13 +293,17 @@ public class AVATAR2CPOSIX { // Making start state AvatarStateMachine asm = _block.getStateMachine(); - s += "case STATE__START__STATE: " + CR + makeBehaviourFromElement(_block, asm.getStartState(), true); + s += "case STATE__START__STATE: " + CR; + s += traceStateEntering("__myname", "start state"); + s += makeBehaviourFromElement(_block, asm.getStartState(), true); s += "break;" + CR + CR; // Making other states for(AvatarStateMachineElement asme: asm.getListOfElements()) { if (asme instanceof AvatarState) { - s += "case STATE__" + asme.getName() + ": " + CR + makeBehaviourFromElement(_block, asme, true); + s += "case STATE__" + asme.getName() + ": " + CR; + s += traceStateEntering("__myname", asme.getName()); + s += makeBehaviourFromElement(_block, asme, true); s += "break;" + CR + CR; } } @@ -326,7 +341,9 @@ public class AVATAR2CPOSIX { String g = modifyGuard(at.getGuard()); ret += "if (!" + g + ") {" + CR; - ret += "debug2Msg(__myname, \"Guard failed: " + g + "\");" + CR; + if (debug) { + ret += "debug2Msg(__myname, \"Guard failed: " + g + "\");" + CR; + } ret += "__currentState = STATE__STOP__STATE;" + CR; ret += "break;" + CR; ret += "}" + CR; @@ -351,7 +368,9 @@ public class AVATAR2CPOSIX { if (_asme instanceof AvatarState) { if (!firstCall) { - ret += "debug2Msg(__myname, \"-> (=====) Entering state + " + _asme.getName() + "\");" + CR; + if (debug) { + ret += "debug2Msg(__myname, \"-> (=====) Entering state + " + _asme.getName() + "\");" + CR; + } return ret + "__currentState = STATE__" + _asme.getName() + ";" + CR; } else { if (_asme.nbOfNexts() == 0) { @@ -392,8 +411,9 @@ public class AVATAR2CPOSIX { ret += "break;" + CR; ret += "}" + CR; - ret += "__req = executeListOfRequests(&__list);" + CR; + ret += "__returnRequest = executeListOfRequests(&__list);" + CR; ret += "clearListOfRequests(&__list);" + CR ; + ret += traceRequest(); // Resulting requests for(i=0; i<_asme.nbOfNexts(); i++) { @@ -402,17 +422,17 @@ public class AVATAR2CPOSIX { } AvatarTransition at = (AvatarTransition)(_asme.getNext(i)); if (at.hasActions()) { - ret += " if (__req == &__req" + i + ") {" + CR; + ret += " if (__returnRequest == &__req" + i + ") {" + CR; for(int j=0; j<at.getNbOfAction(); j++) { ret += at.getAction(j) + ";" + CR; } ret += makeBehaviourFromElement(_block, at.getNext(0), false) + CR + "}"; } else { if (at.getNext(0) instanceof AvatarActionOnSignal) { - ret += " if (__req == &__req" + i + ") {" + CR + makeBehaviourFromElement(_block, at.getNext(0).getNext(0), false) + CR + "}"; + ret += " if (__returnRequest == &__req" + i + ") {" + CR + makeBehaviourFromElement(_block, at.getNext(0).getNext(0), false) + CR + "}"; } else { // nothing special to do : immediate choice - ret += " if (__req == &__req" + i + ") {" + CR + makeBehaviourFromElement(_block, at.getNext(0), false) + CR + "}"; + ret += " if (__returnRequest == &__req" + i + ") {" + CR + makeBehaviourFromElement(_block, at.getNext(0), false) + CR + "}"; } } ret += CR; @@ -438,6 +458,7 @@ public class AVATAR2CPOSIX { AvatarSignal as = aaos.getSignal(); AvatarRelation ar = avspec.getAvatarRelationWithSignal(as); ret += executeOneRequest("__req0"); + ret += traceRequest(); } // Default @@ -569,6 +590,11 @@ public class AVATAR2CPOSIX { mainFile.appendToMainCode("activeDebug();" + CR); } + if (tracing) { + mainFile.appendToMainCode("/* Activating tracing */" + CR); + mainFile.appendToMainCode("activeTracingInFile(\"trace.txt\");" + CR); + } + mainFile.appendToMainCode("/* Activating randomness */" + CR); mainFile.appendToMainCode("initRandom();" + CR); @@ -652,6 +678,27 @@ public class AVATAR2CPOSIX { return ret0 + _ab.getName() + "__" + _call.trim(); } + private String traceRequest() { + if (!tracing) { + return ""; + } + return "traceRequest(__myname, __returnRequest);" + CR; + } + + private String traceFunctionCall(String blockName, String functionName) { + if (!tracing) { + return ""; + } + return "traceFunctionCall(\"" + blockName + "\", \"" + functionName + "\");" + CR; + } + + private String traceStateEntering(String name, String stateName) { + if (!tracing) { + return ""; + } + return "traceStateEntering(\"" + name + "\", \"" + stateName + "\");" + CR; + } + private String mainDebugMsg(String s) { if (!debug) { return ""; diff --git a/src/avatartranslator/toexecutable/MainFile.java b/src/avatartranslator/toexecutable/MainFile.java index a294474feb0a80bedceac5bd951666cf88879e70..c1878aa0c1cc91ff45ba930f53d54f5a358ab636 100755 --- a/src/avatartranslator/toexecutable/MainFile.java +++ b/src/avatartranslator/toexecutable/MainFile.java @@ -57,7 +57,7 @@ public class MainFile { private final static String H_END_DEF = "#endif\n"; private final static String INCLUDE_HEADER = "#include <stdio.h>\n#include <pthread.h>\n#include <unistd.h>\n#include <stdlib.h>\n"; - private final static String LOCAL_INCLUDE_HEADER = "#include \"request.h\"\n#include \"syncchannel.h\"\n#include \"request_manager.h\"\n#include \"debug.h\"\n#include \"random.h\""; + private final static String LOCAL_INCLUDE_HEADER = "#include \"request.h\"\n#include \"syncchannel.h\"\n#include \"request_manager.h\"\n#include \"debug.h\"\n#include \"random.h\"\n#include \"tracemanager.h\""; private final static String MAIN_DEC = "int main(int argc, char *argv[]) {\n"; private final static String CR = "\n"; diff --git a/src/avatartranslator/toexecutable/TaskFile.java b/src/avatartranslator/toexecutable/TaskFile.java index c2ba1c58d9433af772c2d84e7d3871d9a56f55b9..b09103820b7485599ae1f72c71a11f4f698ed6bf 100755 --- a/src/avatartranslator/toexecutable/TaskFile.java +++ b/src/avatartranslator/toexecutable/TaskFile.java @@ -54,7 +54,7 @@ import avatartranslator.*; public class TaskFile { private final static String INCLUDE_HEADER = "#include <stdio.h>\n#include <pthread.h>\n#include <unistd.h>\n#include <stdlib.h>\n"; - private final static String LOCAL_INCLUDE_HEADER = "#include \"request.h\"\n#include \"syncchannel.h\"\n#include \"request_manager.h\"\n#include \"debug.h\"\n#include \"defs.h\"\n#include \"mytimelib.h\"\n#include \"random.h\"\n#include \"main.h\""; + private final static String LOCAL_INCLUDE_HEADER = "#include \"request.h\"\n#include \"syncchannel.h\"\n#include \"request_manager.h\"\n#include \"debug.h\"\n#include \"defs.h\"\n#include \"mytimelib.h\"\n#include \"random.h\"\n#include \"tracemanager.h\"\n#include \"main.h\""; private final static String CR = "\n"; diff --git a/src/ui/window/JDialogAvatarExecutableCodeGeneration.java b/src/ui/window/JDialogAvatarExecutableCodeGeneration.java index 659fbe0e0e5c63c753a11d589bf3c9023c73256d..aafd6994ea00bbfc9c700f298e3f8c4e04de1aec 100644 --- a/src/ui/window/JDialogAvatarExecutableCodeGeneration.java +++ b/src/ui/window/JDialogAvatarExecutableCodeGeneration.java @@ -102,7 +102,7 @@ public class JDialogAvatarExecutableCodeGeneration extends javax.swing.JDialog i protected JTextField code1, code2, compiler1, exe1, exe2, exe3, exe2int; protected JTabbedPane jp1; protected JScrollPane jsp; - protected JCheckBox removeCFiles, removeXFiles, debugmode, optimizemode; + protected JCheckBox removeCFiles, removeXFiles, debugmode, tracemode, optimizemode; protected JComboBox versionCodeGenerator, units; private static int selectedUnit = 2; @@ -209,6 +209,10 @@ public class JDialogAvatarExecutableCodeGeneration extends javax.swing.JDialog i debugmode.setSelected(true); jp01.add(debugmode, c01); + tracemode = new JCheckBox("Put tracing capabilities in generated code"); + tracemode.setSelected(true); + jp01.add(tracemode, c01); + optimizemode = new JCheckBox("Optimize code"); optimizemode.setSelected(optimizeModeSelected); jp01.add(optimizemode, c01); @@ -430,7 +434,7 @@ public class JDialogAvatarExecutableCodeGeneration extends javax.swing.JDialog i } else { AVATAR2CPOSIX avatartocposix = new AVATAR2CPOSIX(avspec); avatartocposix.setTimeUnit(selectedUnit); - avatartocposix.generateCPOSIX(debugmode.isSelected()); + avatartocposix.generateCPOSIX(debugmode.isSelected(), tracemode.isSelected()); testGo(); jta.append("Generation of C-POSIX executable code: done\n"); //t2j.printJavaClasses();