Skip to content
Snippets Groups Projects
Commit f8fe83b3 authored by Ludovic Apvrille's avatar Ludovic Apvrille
Browse files

AVATAR code generator: first tracing system

parent afcf5159
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......
......@@ -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;
......
......@@ -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 "";
......
......@@ -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";
......
......@@ -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";
......
......@@ -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();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment