Skip to content

Commit

Permalink
Merge pull request #2414 from lf-lang/zephyr-npe
Browse files Browse the repository at this point in the history
Informative error message for platforms that do not support federated
  • Loading branch information
lhstrh committed Sep 29, 2024
2 parents 4b2b3c9 + 805f95b commit 163051f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.lflang.federated.generator;

import static org.lflang.generator.docker.DockerGenerator.dockerGeneratorFactory;
import static org.lflang.target.property.type.PlatformType.Platform.supportsFederated;

import com.google.inject.Injector;
import java.io.IOException;
Expand Down Expand Up @@ -63,6 +64,7 @@
import org.lflang.target.property.DockerProperty.DockerOptions;
import org.lflang.target.property.KeepaliveProperty;
import org.lflang.target.property.NoCompileProperty;
import org.lflang.target.property.PlatformProperty;
import org.lflang.target.property.type.CoordinationModeType.CoordinationMode;
import org.lflang.util.Averager;
import org.lflang.util.FileUtil;
Expand Down Expand Up @@ -121,7 +123,7 @@ public FedGenerator(LFGeneratorContext context) {
* @return False if no errors have occurred, true otherwise.
*/
public boolean doGenerate(Resource resource, LFGeneratorContext context) throws IOException {
if (!federatedExecutionIsSupported(resource)) return true;
if (!federatedExecutionIsSupported(resource, context)) return true;
cleanIfNeeded(context);

// In a federated execution, we need keepalive to be true,
Expand Down Expand Up @@ -300,7 +302,7 @@ private void cleanIfNeeded(LFGeneratorContext context) {
}

/** Return whether federated execution is supported for {@code resource}. */
private boolean federatedExecutionIsSupported(Resource resource) {
private boolean federatedExecutionIsSupported(Resource resource, LFGeneratorContext context) {
TargetDecl targetDecl = GeneratorUtils.findTargetDecl(resource);
var target = Target.fromDecl(targetDecl);
var targetOK =
Expand All @@ -316,6 +318,17 @@ private boolean federatedExecutionIsSupported(Resource resource) {
.error("Federated LF programs with a C target are currently not supported on Windows.");
targetOK = false;
}
if (target.equals(Target.C) || target.equals(Target.CCPP)) {
// Currently, only the C runtime has a platform abstraction.
var platform = context.getTargetConfig().get(PlatformProperty.INSTANCE).platform();
if (!supportsFederated(platform)) {
messageReporter
.at(targetDecl)
.error(
"Federations are not supported by the " + platform.getcMakeName() + " platform.");
targetOK = false;
}
}

return targetOK;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ private void validateFlexPRET(TargetConfig config, MessageReporter reporter) {
private void validateZephyr(TargetConfig config, MessageReporter reporter) {
var platform = config.get(PlatformProperty.INSTANCE);
var singleThreaded = config.get(SingleThreadedProperty.INSTANCE);

if (singleThreaded) {
if (platform.userThreads().value() > 0) {
reporter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,23 @@ protected Class<Platform> enumClass() {

public enum Platform {
AUTO,
ARDUINO, // FIXME: not multithreaded
NRF52("nRF52", false),
RP2040("Rp2040", true),
LINUX("Linux", true),
MAC("Darwin", true),
ZEPHYR("Zephyr", true),
FLEXPRET("FlexPRET", true),
WINDOWS("Windows", true);
ARDUINO,
NRF52("nRF52"),
RP2040("Rp2040"),
LINUX("Linux"),
MAC("Darwin"),
ZEPHYR("Zephyr"),
FLEXPRET("FlexPRET"),
WINDOWS("Windows");

final String cMakeName;

private final boolean multiThreaded;

Platform() {
this.cMakeName = this.toString();
this.multiThreaded = true;
}

Platform(String cMakeName, boolean isMultiThreaded) {
Platform(String cMakeName) {
this.cMakeName = cMakeName;
this.multiThreaded = isMultiThreaded;
}

/** Return the name in lower case. */
Expand All @@ -46,12 +42,16 @@ public String getcMakeName() {
return this.cMakeName;
}

public boolean isMultiThreaded() {
return this.multiThreaded;
}

public Platform getDefault() {
return Platform.AUTO;
}

/** Return {@code true} if the given platform supports federated. */
public static boolean supportsFederated(Platform platform) {
return switch (platform) {
case AUTO, LINUX, MAC -> true;
default -> false;
};
}
}
}

0 comments on commit 163051f

Please sign in to comment.