Skip to content

Commit dfa4286

Browse files
committed
add void ports
1 parent d071a37 commit dfa4286

21 files changed

Lines changed: 325 additions & 57 deletions

include/reactor-uc/macros_api.h

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,21 @@
88
#ifndef REACTOR_UC_MACROS_API_H
99
#define REACTOR_UC_MACROS_API_H
1010

11-
/**
12-
* @brief Sets the value of an output port and triggers all downstream reactions.
13-
*
14-
* This macro copies the value to the output port and consequently triggers all downstream reactions.
15-
16-
* @param port The output port.
17-
* @param val The value to set.
18-
*/
19-
#define lf_set(port, val) \
11+
/// @private
12+
#define lf_set_with_val(port, val) \
2013
do { \
2114
__typeof__((port)->value) __val = (val); \
2215
Port* _port = (Port*)(port); \
2316
_port->set(_port, &__val); \
2417
} while (0)
2518

19+
/// @private
20+
#define lf_set_without_val(port) \
21+
do { \
22+
Port* _port = (Port*)(port); \
23+
_port->set(_port, NULL); \
24+
} while (0)
25+
2626
/**
2727
* @brief Sets the value of an output port with an array,
2828
*
@@ -74,9 +74,15 @@ lf_ret_t lf_schedule_with_value(Action* action, interval_t offset, const void* v
7474
/// @private
7575
#define GET_ARG4(arg1, arg2, arg3, arg4, ...) arg4
7676

77+
/// @private
78+
#define GET_ARG3(arg1, arg2, arg3, ...) arg3
79+
7780
/// @private
7881
#define LF_SCHEDULE_CHOOSER(...) GET_ARG4(__VA_ARGS__, lf_schedule_with_val, lf_schedule_without_val)
7982

83+
/// @private
84+
#define LF_SET_CHOOSER(...) GET_ARG3(__VA_ARGS__, lf_set_with_val, lf_set_without_val)
85+
8086
/**
8187
* @brief Schedule an action to occur at a future logical tag.
8288
*
@@ -106,4 +112,14 @@ lf_ret_t lf_schedule_with_value(Action* action, interval_t offset, const void* v
106112
lf_ret_t __ret = __a->schedule(__a, (offset), (const void*)array); \
107113
})
108114

115+
/**
116+
* @brief Sets the value of an output port and triggers all downstream reactions.
117+
*
118+
* This macro copies the value to the output port and consequently triggers all downstream reactions.
119+
120+
* @param port The output port.
121+
* @param val (optional) The value to set.
122+
*/
123+
#define lf_set(...) LF_SET_CHOOSER(__VA_ARGS__)(__VA_ARGS__)
124+
109125
#endif

include/reactor-uc/macros_internal.h

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@
136136
BufferType value[(ArrayLen)]; \
137137
} ReactorName##_##PortName;
138138

139+
#define LF_DEFINE_OUTPUT_VOID_STRUCT(ReactorName, PortName, SourceSize) \
140+
typedef struct { \
141+
Port super; \
142+
Reaction* sources[(SourceSize)]; \
143+
} ReactorName##_##PortName;
144+
139145
#define LF_DEFINE_OUTPUT_CTOR(ReactorName, PortName, SourceSize) \
140146
void ReactorName##_##PortName##_ctor(ReactorName##_##PortName* self, Reactor* parent, \
141147
OutputExternalCtorArgs external) { \
@@ -144,6 +150,14 @@
144150
external.parent_observers_size, external.conns_out, external.conns_out_size); \
145151
}
146152

153+
#define LF_DEFINE_OUTPUT_VOID_CTOR(ReactorName, PortName, SourceSize) \
154+
void ReactorName##_##PortName##_ctor(ReactorName##_##PortName* self, Reactor* parent, \
155+
OutputExternalCtorArgs external) { \
156+
Port_ctor(&self->super, TRIG_OUTPUT, parent, NULL, 0, external.parent_effects, external.parent_effects_size, \
157+
self->sources, SourceSize, external.parent_observers, external.parent_observers_size, \
158+
external.conns_out, external.conns_out_size); \
159+
}
160+
147161
#define LF_PORT_INSTANCE(ReactorName, PortName, PortWidth) ReactorName##_##PortName PortName[PortWidth];
148162
#define LF_PORT_PTR_INSTANCE(ReactorName, PortName) ReactorName##_##PortName* PortName;
149163
#define LF_MULTIPORT_PTR_INSTANCE(ReactorName, PortName, PortWidth) \
@@ -181,6 +195,14 @@
181195
Connection* conns_out[(NumConnsOut)]; \
182196
} ReactorName##_##PortName;
183197

198+
#define LF_DEFINE_INPUT_VOID_STRUCT(ReactorName, PortName, EffectSize, ObserversSize, NumConnsOut) \
199+
typedef struct { \
200+
Port super; \
201+
Reaction* effects[(EffectSize)]; \
202+
Reaction* observers[(ObserversSize)]; \
203+
Connection* conns_out[(NumConnsOut)]; \
204+
} ReactorName##_##PortName;
205+
184206
#define LF_DEFINE_INPUT_CTOR(ReactorName, PortName, EffectSize, ObserverSize, BufferType, NumConnsOut) \
185207
void ReactorName##_##PortName##_ctor(ReactorName##_##PortName* self, Reactor* parent, \
186208
InputExternalCtorArgs external) { \
@@ -189,6 +211,14 @@
189211
(Connection**)&self->conns_out, NumConnsOut); \
190212
}
191213

214+
#define LF_DEFINE_INPUT_VOID_CTOR(ReactorName, PortName, EffectSize, ObserverSize, NumConnsOut) \
215+
void ReactorName##_##PortName##_ctor(ReactorName##_##PortName* self, Reactor* parent, \
216+
InputExternalCtorArgs external) { \
217+
Port_ctor(&self->super, TRIG_INPUT, parent, NULL, 0, self->effects, (EffectSize), external.parent_sources, \
218+
external.parent_sources_size, self->observers, ObserverSize, (Connection**)&self->conns_out, \
219+
NumConnsOut); \
220+
}
221+
192222
#define LF_DEFINE_TIMER_STRUCT(ReactorName, TimerName, EffectSize, ObserversSize) \
193223
typedef struct { \
194224
Timer super; \
@@ -438,7 +468,7 @@
438468
DelayedConnection super; \
439469
BufferType payload_buf[(BufferSize)]; \
440470
bool payload_used_buf[(BufferSize)]; \
441-
Port* downstreams[(BufferSize)]; \
471+
Port* downstreams[(DownstreamSize)]; \
442472
} ParentName##_##ConnName;
443473

444474
#define LF_DEFINE_DELAYED_CONNECTION_STRUCT_ARRAY(ParentName, ConnName, DownstreamSize, BufferType, BufferSize, \
@@ -447,7 +477,13 @@
447477
DelayedConnection super; \
448478
BufferType payload_buf[(BufferSize)][(ArrayLength)]; \
449479
bool payload_used_buf[(BufferSize)]; \
450-
Port* downstreams[(BufferSize)]; \
480+
Port* downstreams[(DownstreamSize)]; \
481+
} ParentName##_##ConnName;
482+
483+
#define LF_DEFINE_DELAYED_CONNECTION_STRUCT_VOID(ParentName, ConnName, DownstreamSize) \
484+
typedef struct { \
485+
DelayedConnection super; \
486+
Port* downstreams[(DownstreamSize)]; \
451487
} ParentName##_##ConnName;
452488

453489
#define LF_DEFINE_DELAYED_CONNECTION_CTOR(ParentName, ConnName, DownstreamSize, BufferSize, IsPhysical) \
@@ -456,6 +492,13 @@
456492
sizeof(self->payload_buf[0]), (void*)self->payload_buf, self->payload_used_buf, \
457493
BufferSize); \
458494
}
495+
496+
#define LF_DEFINE_DELAYED_CONNECTION_VOID_CTOR(ParentName, ConnName, DownstreamSize, IsPhysical) \
497+
void ParentName##_##ConnName##_ctor(ParentName##_##ConnName* self, Reactor* parent, interval_t delay) { \
498+
DelayedConnection_ctor(&self->super, parent, self->downstreams, DownstreamSize, delay, IsPhysical, 0, NULL, NULL, \
499+
0); \
500+
}
501+
459502
// FIXME: Duplicated
460503
#define LF_DELAYED_CONNECTION_INSTANCE(ParentName, ConnName, BankWidth, PortWidth) \
461504
ParentName##_##ConnName ConnName[BankWidth][PortWidth];
@@ -481,12 +524,22 @@ typedef struct FederatedOutputConnection FederatedOutputConnection;
481524
BufferType payload_buf[1][(ArrayLength)]; \
482525
} ReactorName##_##OutputName##_conn;
483526

527+
#define LF_DEFINE_FEDERATED_OUTPUT_CONNECTION_STRUCT_VOID(ReactorName, OutputName) \
528+
typedef struct { \
529+
FederatedOutputConnection super; \
530+
} ReactorName##_##OutputName##_conn;
531+
484532
#define LF_DEFINE_FEDERATED_OUTPUT_CONNECTION_CTOR(ReactorName, OutputName, BufferType, DestinationConnId) \
485533
void ReactorName##_##OutputName##_conn_ctor(ReactorName##_##OutputName##_conn* self, Reactor* parent, \
486534
FederatedConnectionBundle* bundle) { \
487535
FederatedOutputConnection_ctor(&self->super, parent, bundle, DestinationConnId, (void*)&self->payload_buf, \
488536
sizeof(self->payload_buf[0])); \
489537
}
538+
#define LF_DEFINE_FEDERATED_OUTPUT_CONNECTION_VOID_CTOR(ReactorName, OutputName, DestinationConnId) \
539+
void ReactorName##_##OutputName##_conn_ctor(ReactorName##_##OutputName##_conn* self, Reactor* parent, \
540+
FederatedConnectionBundle* bundle) { \
541+
FederatedOutputConnection_ctor(&self->super, parent, bundle, DestinationConnId, NULL, 0); \
542+
}
490543

491544
#define LF_FEDERATED_OUTPUT_CONNECTION_INSTANCE(ReactorName, OutputName) ReactorName##_##OutputName##_conn OutputName
492545

@@ -544,6 +597,12 @@ typedef struct FederatedInputConnection FederatedInputConnection;
544597
Port* downstreams[1]; \
545598
} ReactorName##_##InputName##_conn;
546599

600+
#define LF_DEFINE_FEDERATED_INPUT_CONNECTION_STRUCT_VOID(ReactorName, InputName) \
601+
typedef struct { \
602+
FederatedInputConnection super; \
603+
Port* downstreams[1]; \
604+
} ReactorName##_##InputName##_conn;
605+
547606
#define LF_DEFINE_FEDERATED_INPUT_CONNECTION_CTOR(ReactorName, InputName, BufferType, BufferSize, Delay, IsPhysical, \
548607
MaxWait) \
549608
void ReactorName##_##InputName##_conn_ctor(ReactorName##_##InputName##_conn* self, Reactor* parent) { \
@@ -552,6 +611,12 @@ typedef struct FederatedInputConnection FederatedInputConnection;
552611
sizeof(self->payload_buf[0]), BufferSize); \
553612
}
554613

614+
#define LF_DEFINE_FEDERATED_INPUT_CONNECTION_VOID_CTOR(ReactorName, InputName, Delay, IsPhysical, MaxWait) \
615+
void ReactorName##_##InputName##_conn_ctor(ReactorName##_##InputName##_conn* self, Reactor* parent) { \
616+
FederatedInputConnection_ctor(&self->super, parent, Delay, IsPhysical, MaxWait, (Port**)&self->downstreams, 1, \
617+
NULL, NULL, 0, 0); \
618+
}
619+
555620
#define LF_FEDERATED_INPUT_CONNECTION_INSTANCE(ReactorName, InputName) ReactorName##_##InputName##_conn InputName
556621

557622
#define LF_DEFINE_STARTUP_COORDINATOR_STRUCT(ReactorName, NumNeighbors, NumEvents) \

lfc/core/src/main/java/org/lflang/AttributeUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,6 @@ public static PlatformType.Platform getPlatform(EObject node) {
310310
return PlatformType.Platform.ESPIDF;
311311
case "FREERTOS":
312312
return PlatformType.Platform.FREERTOS;
313-
case "ARDUINO":
314-
return PlatformType.Platform.ARDUINO;
315313
default:
316314
return PlatformType.Platform.AUTO;
317315
}
@@ -342,8 +340,10 @@ public static String getClockSyncAttrValue(Reactor node) {
342340
public static String getLoggingAttrValue(Reactor node) {
343341
Attribute attr = findAttributeByName(node, "logging");
344342
if (attr != null) {
343+
System.out.println("attr is not null" + attr.getAttrParms().get(0).getValue());
345344
return StringUtil.removeQuotes(attr.getAttrParms().get(0).getValue());
346345
} else {
346+
System.out.println("attr is null");
347347
return "";
348348
}
349349
}

lfc/core/src/main/kotlin/org/lflang/generator/uc/UcActionGenerator.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,11 @@ class UcActionGenerator(private val reactor: Reactor) {
3131
private val Action.actionPolicy
3232
get(): String = policy?.let { policy.toString() } ?: "defer"
3333

34+
private val Action.isVoid
35+
get(): Boolean = this.type == null || this.type.id == "void"
36+
3437
private fun generateSelfStruct(action: Action): String {
35-
if (action.type == null) {
38+
if (action.isVoid) {
3639
return "LF_DEFINE_ACTION_STRUCT_VOID(${reactor.codeType}, ${action.name}, ${action.actionType}, ${reactor.getEffects(action).size}, ${reactor.getSources(action).size}, ${reactor.getObservers(action).size}, ${action.maxNumPendingEvents});"
3740
} else if (action.type.isArray) {
3841
return "LF_DEFINE_ACTION_STRUCT_ARRAY(${reactor.codeType}, ${action.name}, ${action.actionType}, ${reactor.getEffects(action).size}, ${reactor.getSources(action).size}, ${reactor.getObservers(action).size}, ${action.maxNumPendingEvents}, ${action.type.id}, ${action.type.arrayLength});"
@@ -44,7 +47,7 @@ class UcActionGenerator(private val reactor: Reactor) {
4447
private fun generateCtor(action: Action) =
4548
with(PrependOperator) {
4649
"""
47-
|LF_DEFINE_ACTION_CTOR${if (action.type == null) "_VOID" else ""}(${reactor.codeType}, ${action.name}, ${action.actionType}, ACTION_POLICY_${action.actionPolicy.uppercase()}, ${reactor.getEffects(action).size}, ${reactor.getSources(action).size}, ${reactor.getObservers(action).size}, ${action.maxNumPendingEvents} ${if (action.type != null) ", ${action.type.toText()}" else ""});
50+
|LF_DEFINE_ACTION_CTOR${if (action.isVoid) "_VOID" else ""}(${reactor.codeType}, ${action.name}, ${action.actionType}, ACTION_POLICY_${action.actionPolicy.uppercase()}, ${reactor.getEffects(action).size}, ${reactor.getSources(action).size}, ${reactor.getObservers(action).size}, ${action.maxNumPendingEvents} ${if (!action.isVoid) ", ${action.type.toText()}" else ""});
4851
|
4952
"""
5053
.trimMargin()

lfc/core/src/main/kotlin/org/lflang/generator/uc/UcCmakeGenerator.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,9 @@ abstract class UcCmakeGenerator(
7070

7171
open class UcCmakeGeneratorNonFederated(
7272
private val mainDef: Instantiation,
73+
buildType: BuildTypeType.BuildType,
7374
fileConfig: UcFileConfig,
74-
) :
75-
UcCmakeGenerator(
76-
UcLoggingLevelAttribute(mainDef.reactor),
77-
BuildTypeType.BuildType.RELEASE,
78-
fileConfig) { // FIXME:
75+
) : UcCmakeGenerator(UcLoggingLevelAttribute(mainDef.reactor), buildType, fileConfig) {
7976
override val mainTarget = fileConfig.name
8077

8178
override fun generateIncludeCmake(sources: List<Path>) =
@@ -84,11 +81,12 @@ open class UcCmakeGeneratorNonFederated(
8481

8582
class UcCmakeGeneratorFederated(
8683
private val federate: UcFederate,
84+
buildType: BuildTypeType.BuildType,
8785
fileConfig: UcFileConfig,
8886
) :
8987
UcCmakeGenerator(
9088
UcLoggingLevelAttribute(federate.inst.eContainer() as Reactor),
91-
BuildTypeType.BuildType.RELEASE,
89+
buildType,
9290
fileConfig,
9391
) {
9492
override val mainTarget = federate.codeType

0 commit comments

Comments
 (0)