Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Watchdog support for the C target #1730

Merged
merged 139 commits into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from 137 commits
Commits
Show all changes
139 commits
Select commit Hold shift + click to select a range
718eaab
added func for watchdog name, created watchdog instance class
Dec 26, 2022
43bb491
made some progress on code generation
Jan 5, 2023
20531f0
more functions added for code generation
Jan 5, 2023
371385e
saving progress before pushing
Jan 8, 2023
86c369d
fixed grammar(added watchdog to 'varreformodetransition', removed wat…
Jan 8, 2023
15fc495
added watchdog grammar to reactor
Jan 8, 2023
6124cae
making sure updated before push
Jan 12, 2023
3798f3a
code generation steps (excluding mutex initialization) should be done…
Jan 18, 2023
bf4fd4c
generatewatchdogstruct in generateselfstruct
Jan 18, 2023
b87327f
save changes to watchdog
Feb 1, 2023
4f2fbb1
merge conflicts resolved
Feb 1, 2023
c8c569c
Added a few missing imports, but plenty compile errors remain
lhstrh Feb 8, 2023
10cf741
saving before merging
Feb 8, 2023
63c624f
think fixed merge conflicts?
Feb 8, 2023
90d002f
at least it compiles now
Feb 8, 2023
45f0f9f
Merge remote-tracking branch 'origin/master' into watchdogs
Feb 10, 2023
4db9e0f
fixed build problems
Feb 13, 2023
f7b177e
tried, unsuccessfully, to fix variable grammar error
Feb 13, 2023
0487e8e
watchdog example test
Feb 17, 2023
ca78125
saving reactorc and changes to scopeprovider
Feb 17, 2023
c36cc80
saving changes to scope provider
Feb 17, 2023
94185e7
Fixed the scope provider
lhstrh Feb 18, 2023
41e9487
Merge branch 'watchdogs' of github.com:lf-lang/lingua-franca into wat…
Feb 18, 2023
1726124
fixed trigger table
Feb 20, 2023
6994d46
saved?
Feb 26, 2023
29b7890
merged from main
Feb 26, 2023
43f8999
Merge master into watchdogs
lhstrh Mar 2, 2023
3393c58
fixed compile issues
Mar 3, 2023
78405a3
fixing before merge
Mar 3, 2023
976b102
added casewatchdogs, still not fixed
Mar 9, 2023
0d31103
Also produce code for watchdogs in reactor definition
lhstrh Mar 9, 2023
59b3737
Apply formatter to test
lhstrh Mar 9, 2023
ccb0b6a
Merge remote-tracking branch 'origin/master' into watchdogs
Mar 9, 2023
9d83f55
Fix submodule issues and remove files that should not be checked in
lhstrh Mar 9, 2023
ec8afa7
Remove spurious file
lhstrh Mar 9, 2023
da5b43a
Change order of submodules
lhstrh Mar 9, 2023
9460c1a
Let version of reactor-cpp be the same as in master
lhstrh Mar 9, 2023
f1ae73f
Merge branch 'master' into watchdogs
lhstrh Mar 9, 2023
043cfbc
Make submodule entries uniform
lhstrh Mar 9, 2023
bacf3af
Merge branch 'master' into watchdogs
lhstrh Mar 9, 2023
774411b
Merge branch 'watchdogs' of github.com:lf-lang/lingua-franca into wat…
Mar 9, 2023
41c5430
Update org.lflang/src/org/lflang/ast/ToLf.java
Benichiwa Mar 9, 2023
89abf74
Update org.lflang/src/org/lflang/ast/IsEqual.java
Benichiwa Mar 9, 2023
e4be4d5
Update org.lflang/src/org/lflang/ast/IsEqual.java
Benichiwa Mar 9, 2023
a81d25b
removed fixmes, updated grammar
Mar 9, 2023
f453bc4
Merge branch 'watchdogs' of github.com:lf-lang/lingua-franca into wat…
Mar 9, 2023
88dbef7
fixed ccpp test issue?
Mar 9, 2023
06b338e
Merge branch 'master' into watchdogs
lhstrh Mar 10, 2023
5670e27
saving before pull again
Mar 13, 2023
0b27dd0
save before second pull
Mar 13, 2023
8df2efa
Merge branch 'watchdogs' of github.com:lf-lang/lingua-franca into wat…
Mar 13, 2023
c0ecf59
fixed
Mar 13, 2023
945bffe
added error reporting for unthreaded w watchdog
Mar 15, 2023
8228827
saving before checkout out klighd-workaround
Mar 20, 2023
2af0fa7
saving before klighd workaround
Mar 20, 2023
78b7fb5
merged reacotr-c
Mar 20, 2023
be2a4c9
some changes to code review
Mar 20, 2023
d87274f
Align lingua-franca/watchdogs with reactor-c/watchdogs
edwardalee Mar 25, 2023
aaa7368
Merged master in watchdogs
edwardalee Mar 25, 2023
e8a1b05
Deleted spurious empty files
edwardalee Mar 25, 2023
f9e9853
Merge remote-tracking branch 'origin/master' into watchdogs
edwardalee Mar 25, 2023
998787a
Merge remote-tracking branch 'origin/watchdogs' into watchdogs-eal
edwardalee Mar 25, 2023
534a003
Removed unused imports
edwardalee Mar 25, 2023
cb06dff
Group watchdog with action
edwardalee Mar 25, 2023
302f690
Removed unused imports
edwardalee Mar 25, 2023
7b05cd6
Removed non-substantive change
edwardalee Mar 25, 2023
673a7fc
Removed unused or redundant imports
edwardalee Mar 25, 2023
91086ad
Made this a real test
edwardalee Mar 25, 2023
c20e711
Made fields private and rearranged
edwardalee Mar 25, 2023
bb2a21d
Fixed hasWatchdogs, which was always returning true
edwardalee Mar 25, 2023
6d33efc
Regularized function pointer
edwardalee Mar 25, 2023
5e31d32
Align reactor-c
edwardalee Mar 25, 2023
60cf911
merged changes, fixed inconsistencies, implemented watchdog stop
Mar 31, 2023
7fb877b
threading error working
Mar 31, 2023
58da147
merged master
Mar 31, 2023
8b3b3e3
saving before pull again
Mar 31, 2023
e1c7046
Merge branch 'watchdogs' of github.com:lf-lang/lingua-franca into wat…
Mar 31, 2023
6c22729
fixed generator issue
Mar 31, 2023
7b6ea7a
got everything to merge from watchdogs-eal branch
Mar 31, 2023
a4740c3
saving before continuing changes
Apr 3, 2023
1af9922
added watchdog to body of itself, started making changes to treat wat…
Apr 3, 2023
b5d6d58
create triggers save progress
Benichiwa Apr 5, 2023
34f96e5
fixed watchdog test inconsistency? define watchdog trigger
Apr 5, 2023
f91883e
Merge branch 'master' of github.com:lf-lang/lingua-franca into watchdogs
Apr 10, 2023
a35208f
tried removing boolean from self-base_t struct, failed, everything wo…
Apr 10, 2023
5773b89
created check for runtime, and removed local one for each class
Apr 14, 2023
9e9aac7
saving changes before merging
Apr 14, 2023
755ff09
save before reattempting the merge
Apr 18, 2023
918c49a
hopefully succesfully resolved merge conflicts
Apr 20, 2023
b95830e
issues fixed w watchdog test, seems to be working as expected, not su…
Apr 20, 2023
3b8e0f7
removed fake python test
Apr 20, 2023
1f86008
updating reactor-c
Apr 21, 2023
1493800
fixed invocation of watchdog_stop in watchdog test
Apr 21, 2023
2e986dc
Aligned to reactor-c/watchdogs
edwardalee Apr 27, 2023
fb6a4af
Merge branch 'master' into watchdogs
edwardalee Apr 27, 2023
e32c9ff
First pass a refactoring
edwardalee Apr 27, 2023
6f98739
Align reactor-c-py to main
edwardalee Apr 27, 2023
b6ef20d
Aligned reactor-c
edwardalee Apr 27, 2023
88e7b59
Merge branch 'master' into watchdogs-eal2
edwardalee Apr 28, 2023
5c3114e
Continued refactoring
edwardalee Apr 28, 2023
af103df
Attempt to exclude FilePkgReader
edwardalee Apr 28, 2023
97e53b6
Another attempt to exclude FileReader
edwardalee Apr 29, 2023
49d3ba9
Watcher cannot watch its own reactions
edwardalee Apr 29, 2023
661df88
Continued refactoring and docs
edwardalee Apr 29, 2023
95a7116
Aligned reactor-c
edwardalee Apr 30, 2023
4a55825
Manually reverted formatting changes.
edwardalee Apr 30, 2023
c25c8b7
Removed unused imports
edwardalee Apr 30, 2023
592e2c0
Revert formatting changes
edwardalee Apr 30, 2023
b7e902b
Merge master changes in
edwardalee Apr 30, 2023
5159e0a
Undo formatting changes
edwardalee Apr 30, 2023
6463813
Undid formatting
edwardalee May 1, 2023
e3d967b
Merge single file with master
edwardalee May 1, 2023
eae9ebd
Merge single file with master
edwardalee May 1, 2023
92ce015
Merge single file with master
edwardalee May 1, 2023
a4365c8
Remove use of Google Objects class
edwardalee May 1, 2023
e71ffdf
Restored accidentally removed watchdog line
edwardalee May 1, 2023
45f7286
Merge single file with master
edwardalee May 1, 2023
442f808
Restored file to unformatted version
edwardalee May 1, 2023
17f5071
Added file docs
edwardalee May 1, 2023
0867ec8
Revert formatting
edwardalee May 1, 2023
e6a0ed0
Revert to master version (reverse formatting)
edwardalee May 1, 2023
e52a3bc
Revert formatting
edwardalee May 1, 2023
dcf79e2
Merge branch 'master' into watchdogs-eal2
edwardalee May 1, 2023
a42a6f0
Formatted test
edwardalee May 1, 2023
47e99f7
Placeholder for when there are no watchdogs
edwardalee May 1, 2023
2687e42
Align reactor-c
edwardalee May 1, 2023
ddca01e
Merge branch 'master' into watchdogs-eal2
lhstrh May 5, 2023
7547acf
Move watchdog test into concurrent
edwardalee May 5, 2023
c54def7
More lenient test
edwardalee May 5, 2023
54fa3d0
Aligned reactor-c
edwardalee May 6, 2023
8cf85f4
Merge branch 'master' into watchdogs-eal2
edwardalee May 6, 2023
836bb3e
Made test timing lenient.
edwardalee May 6, 2023
2244285
Merge branch 'master' into watchdogs-eal2
lhstrh May 12, 2023
f8d38f0
Align to watchdogs-eal2 of reactor-c
edwardalee May 15, 2023
3a5d403
Merge branch 'master' into watchdogs-eal2
edwardalee May 15, 2023
a84070a
In response to review, renamed variables
edwardalee May 16, 2023
235ec78
Merge branch 'master' into watchdogs-eal2
lhstrh May 18, 2023
68afbc2
Address remaining FIXME to include errorReporter
edwardalee May 18, 2023
31d4b4d
Align to reactor-c main
edwardalee May 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion org.lflang/src/lib/py/reactor-c-py
46 changes: 25 additions & 21 deletions org.lflang/src/org/lflang/ASTUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.function.Predicate;
import java.util.regex.Matcher;
Expand Down Expand Up @@ -61,8 +60,6 @@
import org.lflang.generator.ReactorInstance;
import org.lflang.lf.Action;
import org.lflang.lf.Assignment;
import org.lflang.lf.AttrParm;
import org.lflang.lf.Attribute;
import org.lflang.lf.Code;
import org.lflang.lf.Connection;
import org.lflang.lf.Element;
Expand Down Expand Up @@ -92,6 +89,7 @@
import org.lflang.lf.Type;
import org.lflang.lf.VarRef;
import org.lflang.lf.Variable;
import org.lflang.lf.Watchdog;
import org.lflang.lf.WidthSpec;
import org.lflang.lf.WidthTerm;
import org.lflang.util.StringUtil;
Expand Down Expand Up @@ -263,7 +261,6 @@ public static Target getTarget(EObject object) {

/**
* Add a new target property to the given resource.
*
* This also creates a config object if the resource does not yey have one.
*
* @param resource The resource to modify
Expand Down Expand Up @@ -292,11 +289,11 @@ public static boolean hasMultipleConnections(Connection connection) {
if (connection.getLeftPorts().size() > 1 || connection.getRightPorts().size() > 1) {
return true;
}
VarRef leftPort = connection.getLeftPorts().get(0);
VarRef leftPort = connection.getLeftPorts().get(0);
VarRef rightPort = connection.getRightPorts().get(0);
Instantiation leftContainer = leftPort.getContainer();
Instantiation leftContainer = leftPort.getContainer();
Instantiation rightContainer = rightPort.getContainer();
Port leftPortAsPort = (Port) leftPort.getVariable();
Port leftPortAsPort = (Port) leftPort.getVariable();
Port rightPortAsPort = (Port) rightPort.getVariable();
return leftPortAsPort.getWidthSpec() != null
|| leftContainer != null && leftContainer.getWidthSpec() != null
Expand Down Expand Up @@ -450,6 +447,16 @@ public static List<Reaction> allReactions(Reactor definition) {
return ASTUtils.collectElements(definition, featurePackage.getReactor_Reactions());
}

/**
* Given a reactor class, return a list of all its watchdogs.
*
* @param definition Reactor class definition
* @return List<Watchdog>
*/
public static List<Watchdog> allWatchdogs(Reactor definition) {
return ASTUtils.collectElements(definition, featurePackage.getReactor_Watchdogs());
}

/**
* Given a reactor class, return a list of all its state variables,
* which includes state variables of base classes that it extends.
Expand Down Expand Up @@ -485,7 +492,7 @@ public static List<Mode> allModes(Reactor definition) {
public static List<Reactor> recursiveChildren(ReactorInstance r) {
List<Reactor> ret = new ArrayList<>();
ret.add(r.reactorDefinition);
for (var child: r.children) {
for (var child : r.children) {
ret.addAll(recursiveChildren(child));
}
return ret;
Expand Down Expand Up @@ -790,7 +797,6 @@ private static Element toElement(String str, boolean addQuotes) {
Element e = LfFactory.eINSTANCE.createElement();
e.setLiteral(strToReturn);
return e;

}

/**
Expand Down Expand Up @@ -937,12 +943,12 @@ public static boolean isFloat(String literal) {
return true;
}

/**
/**
* Report whether the given code is an integer number or not.
* @param code AST node to inspect.
* @return True if the given code is an integer, false otherwise.
*/
public static boolean isInteger(Code code) {
public static boolean isInteger(Code code) {
return isInteger(toText(code));
}

Expand All @@ -966,13 +972,13 @@ public static boolean isInteger(Expression expr) {
* @return True if the argument denotes a valid time, false otherwise.
*/
public static boolean isValidTime(Expression expr) {
if (expr instanceof ParameterReference) {
return isOfTimeType(((ParameterReference)expr).getParameter());
} else if (expr instanceof Time) {
return isValidTime((Time) expr);
} else if (expr instanceof Literal) {
return isZero(((Literal) expr).getLiteral());
}
if (expr instanceof ParameterReference) {
return isOfTimeType(((ParameterReference) expr).getParameter());
} else if (expr instanceof Time) {
return isValidTime((Time) expr);
} else if (expr instanceof Literal) {
return isZero(((Literal) expr).getLiteral());
}
return false;
}

Expand Down Expand Up @@ -1021,7 +1027,7 @@ public static boolean isListInitializer(Initializer init) {
* can be inferred: "time" and "timeList". Return the
* "undefined" type if neither can be inferred.
*
* @param type Explicit type declared on the declaration
* @param type Explicit type declared on the declaration
* @param init The initializer expression
* @return The inferred type, or "undefined" if none could be inferred.
*/
Expand Down Expand Up @@ -1114,8 +1120,6 @@ public static InferredType getInferredType(Port p) {
return getInferredType(p.getType(), null);
}



/**
* If the given string can be recognized as a floating-point number that has a leading decimal point,
* prepend the string with a zero and return it. Otherwise, return the original string.
Expand Down
14 changes: 11 additions & 3 deletions org.lflang/src/org/lflang/LinguaFranca.xtext
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ Reactor:
| (outputs+=Output)
| (timers+=Timer)
| (actions+=Action)
| (watchdogs+=Watchdog)
| (instantiations+=Instantiation)
| (connections+=Connection)
| (reactions+=Reaction)
Expand Down Expand Up @@ -174,6 +175,7 @@ Mode:
(stateVars+=StateVar) |
(timers+=Timer) |
(actions+=Action) |
(watchdogs+=Watchdog) |
(instantiations+=Instantiation) |
(connections+=Connection) |
(reactions+=Reaction)
Expand Down Expand Up @@ -213,6 +215,11 @@ BuiltinTriggerRef:
Deadline:
'deadline' '(' delay=Expression ')' code=Code;

Watchdog:
'watchdog' name=ID '(' timeout=Expression ')'
('->' effects+=VarRefOrModeTransition (',' effects+=VarRefOrModeTransition)*)?
code=Code;

STP:
'STP' '(' value=Expression ')' code=Code;

Expand Down Expand Up @@ -273,7 +280,7 @@ TypedVariable:
;

Variable:
TypedVariable | Timer | Mode;
TypedVariable | Timer | Mode | Watchdog;

VarRef:
(variable=[Variable] | container=[Instantiation] '.' variable=[Variable]
Expand Down Expand Up @@ -457,7 +464,7 @@ SignedFloat:
// Just escaping with \ is not a good idea because then every \ has to be escaped \\.
// Perhaps the string EQUALS_BRACE could become '=}'?
Code:
//{Code} '{=' (tokens+=Token)* '=}'
// {Code} '{=' (tokens+=Token)* '=}'
{Code} '{=' body=Body '=}'
;

Expand Down Expand Up @@ -504,7 +511,8 @@ Token:
'mutable' | 'input' | 'output' | 'timer' | 'action' | 'reaction' |
'startup' | 'shutdown' | 'after' | 'deadline' | 'mutation' | 'preamble' |
'new' | 'federated' | 'at' | 'as' | 'from' | 'widthof' | 'const' | 'method' |
'interleaved' | 'mode' | 'initial' | 'reset' | 'history' | 'named' |
'interleaved' | 'mode' | 'initial' | 'reset' | 'history' | 'watchdog' | 'named' |

// Other terminals
NEGINT | TRUE | FALSE |
// Action origins
Expand Down
12 changes: 11 additions & 1 deletion org.lflang/src/org/lflang/ast/IsEqual.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import org.lflang.lf.TypedVariable;
import org.lflang.lf.VarRef;
import org.lflang.lf.Variable;
import org.lflang.lf.Watchdog;
import org.lflang.lf.WidthSpec;
import org.lflang.lf.WidthTerm;
import org.lflang.lf.util.LfSwitch;
Expand Down Expand Up @@ -319,7 +320,6 @@ public Boolean caseSTP(STP object) {
.conclusion;
}


@Override
public Boolean casePreamble(Preamble object) {
return new ComparisonMachine<>(object, Preamble.class)
Expand Down Expand Up @@ -496,6 +496,16 @@ public Boolean caseArraySpec(ArraySpec object) {
.conclusion;
}

@Override
public Boolean caseWatchdog(Watchdog object) {
return new ComparisonMachine<>(object, Watchdog.class)
.equalAsObjects(Watchdog::getName)
.equivalent(Watchdog::getTimeout)
.listsEquivalent(Watchdog::getEffects)
.equivalent(Watchdog::getCode)
.conclusion;
}

@Override
public Boolean caseWidthSpec(WidthSpec object) {
return new ComparisonMachine<>(object, WidthSpec.class)
Expand Down
43 changes: 39 additions & 4 deletions org.lflang/src/org/lflang/ast/ToLf.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
import org.lflang.lf.VarRef;
import org.lflang.lf.Variable;
import org.lflang.lf.Visibility;
import org.lflang.lf.Watchdog;
import org.lflang.lf.WidthSpec;
import org.lflang.lf.WidthTerm;
import org.lflang.lf.util.LfSwitch;
Expand Down Expand Up @@ -393,6 +394,7 @@ public MalleableString caseReactor(Reactor object) {
// | (outputs+=Output)
// | (timers+=Timer)
// | (actions+=Action)
// | (watchdogs+=Watchdog)
// | (instantiations+=Instantiation)
// | (connections+=Connection)
// | (reactions+=Reaction)
Expand All @@ -410,6 +412,7 @@ public MalleableString caseReactor(Reactor object) {
object.getOutputs(),
object.getTimers(),
object.getActions(),
object.getWatchdogs(),
object.getInstantiations(),
object.getConnections(),
object.getStateVars()),
Expand Down Expand Up @@ -656,6 +659,40 @@ public MalleableString caseDeadline(Deadline object) {
return handler(object, "deadline", Deadline::getDelay, Deadline::getCode);
}

@Override
public MalleableString caseWatchdog(Watchdog object) {
// 'watchdog' name=ID '(' timeout=Expression ')'
// ('->' effects+=VarRefOrModeTransition (',' effects+=VarRefOrModeTransition)*)?
// code=Code;

Builder msb = new Builder();
msb.append("watchdog ");
msb.append(object.getName());
msb.append(list(true, object.getTimeout()));

if (!object.getEffects().isEmpty()) {
List<Mode> allModes = ASTUtils.allModes(ASTUtils.getEnclosingReactor(object));
msb.append(" -> ", " ->\n")
.append(
object.getEffects().stream()
.map(
varRef ->
(allModes.stream()
.anyMatch(
m -> m.getName().equals(varRef.getVariable().getName())))
? new Builder()
.append(varRef.getTransition())
.append("(")
.append(doSwitch(varRef))
.append(")")
.get()
: doSwitch(varRef))
.collect(new Joiner(", ")));
}
msb.append(" ").append(doSwitch(object.getCode()));
return msb.get();
}

@Override
public MalleableString caseSTP(STP object) {
// 'STP' '(' value=Expression ')' code=Code
Expand Down Expand Up @@ -844,9 +881,8 @@ public MalleableString caseInitializer(Initializer object) {
}

/**
* Return true if the initializer should be output with an equals initializer.
* Old-style assignments with parentheses are also output that
* way to help with the transition.
* Return true if the initializer should be output with an equals initializer. Old-style
* assignments with parentheses are also output that way to help with the transition.
*/
private boolean shouldOutputAsAssignment(Initializer init) {
return init.isAssign()
Expand Down Expand Up @@ -882,7 +918,6 @@ private MalleableString initializer(Initializer init) {
return list(", ", prefix, suffix, false, false, init.getExprs());
}


@Override
public MalleableString caseParameter(Parameter object) {
// name=ID (':' (type=Type))?
Expand Down
Loading