Skip to content

Commit

Permalink
Ma2jsim log mode changes
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannesLeurs authored and schmalzing committed Sep 11, 2024
1 parent 1bc28ab commit a842b89
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 4 deletions.
4 changes: 4 additions & 0 deletions generators/ma2jsim/main/java/montiarc/util/LogAspects.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public String changeState() {
return Aspects.ENTER_STATE;
}

public String modeChange() {
return Aspects.MODE_CHANGE;
}

public String receiveEvent() {
return Aspects.RECEIVE_EVENT;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protected ${ast.getName()}${suffixes.component()}<#if isTop>${suffixes.top()}</#
this.${prefixes.feature()}${feature.getName()} = ${prefixes.feature()}${feature.getName()};
</#list>
<#if helper.getModeAutomaton(ast).isPresent()>
this.modeAutomaton = new ${ast.getName()}${suffixes.modeAutomaton()}(this);
this.modeAutomaton = new ${ast.getName()}${suffixes.modeAutomaton()}(this, name);
</#if>

<#if !(hasOnlyOneVariant && prettyPrinter.prettyprintCondition(helper.getVariants(ast)[0]) == "true")>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<#-- ASTComponentType ast -->
<#import "/montiarc/generator/ma2jsim/util/Util.ftl" as Util>
<#import "/montiarc/generator/ma2jsim/util/MethodNames.ftl" as MethodNames>
<#import "/montiarc/generator/ma2jsim/logging/CompLogging.ftl" as Log>

<#assign modeAutomaton = helper.getModeAutomaton(ast).get()>
<#assign modeAutomatonClass>${ast.getName()}${suffixes.modeAutomaton()}<#if isTop>${suffixes.top()}</#if></#assign>
Expand All @@ -18,8 +19,11 @@

protected Mode currentMode;

${modeAutomatonClass}(${modeContextType} context) {
protected String compName;

${modeAutomatonClass}(${modeContextType} context, String compName) {
this.context = context;
this.compName = compName;
}

${tc.include("montiarc.generator.ma2jsim.component.modes.ModeEnum.ftl")}
Expand All @@ -28,6 +32,7 @@
void setup() {
// set initial state
this.currentMode = Mode.${initMode.getName()};
<@Log.info log_aspects.modeChange() "this.compName"> "->" + Mode.${initMode.getName()} </@Log.info>

// instantiate sub components
this.context.<@MethodNames.modeSetup initMode.getSymbol()/>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<#-- (c) https://github.com/MontiCore/monticore -->
<#import "/montiarc/generator/ma2jsim/util/MethodNames.ftl" as MethodNames>
<#import "/montiarc/generator/ma2jsim/logging/CompLogging.ftl" as Log>

<#-- Calculates the java expression to get the port object of the port access -->
<#-- ASTPortAccess portAccess, ASTArcMode enclosingMode, ASTComponentType enclosingComp -->
Expand Down Expand Up @@ -33,6 +34,10 @@
<#assign guardPrinted><#if guardExpre.isPresent()>${prettyPrinter.prettyprint(guardExpre.get())} <#else>true</#if></#assign>

if (${guardPrinted}) {
<@Log.info log_aspects.modeChange() "this.compName">
Mode.${transition.getSourceName()} + "->" + Mode.${transition.getTargetName()}
</@Log.info>

this.currentMode = Mode.${transition.getTargetName()};
this.context.<@MethodNames.modeTeardown transition.getSourceNameSymbol()/>();
this.context.<@MethodNames.modeSetup transition.getTargetNameSymbol()/>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
-->

<#-- For explication about how this macro works, see the beginning of the file -->
<#macro info aspect qualCompInstanceNameSupplier throwable=""> <#-- TODO: communicate supplier -->
<#macro info aspect qualCompInstanceNameSupplier throwable="">
<@log "info" throwable "${qualCompInstanceNameSupplier} + \"#${aspect}\"">
<#-- When <@info...>content</@info...> is called, the content will be placed into #nested,
which by itself is the argument fro the <#nested> tag of the <@log> macro -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ private Aspects() {}

public static final String ENTER_STATE = "enter_state";

public static final String MODE_CHANGE = "mode_change";

public static final String RECEIVE_EVENT = "event";
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ protected void processReceivedData(NoMsgType data) {
}

public TickPort(Component owner, Scheduler scheduler) {
super(".#tick", owner, scheduler);
super(owner.getName() + ".>tick", owner, scheduler);
}
}

0 comments on commit a842b89

Please sign in to comment.