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

CCpp target #513

Merged
merged 63 commits into from
Sep 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
44e2b67
Removed the old CCppGenerator
Soroosh129 Sep 18, 2021
3b54e97
Updated tests and added new tests for CCpp
Soroosh129 Sep 18, 2021
c81cf3b
Updated federated tests to test the CCpp target
Soroosh129 Sep 18, 2021
334e33c
Added a new CCpp target. Fixed a bug where compile errors were not be…
Soroosh129 Sep 18, 2021
8e08f12
Moved target-specific tests to target. Updated tests
Soroosh129 Sep 18, 2021
7a96461
Various improvements in error handling
Soroosh129 Sep 18, 2021
ed2084a
Updated comments on the tests
Soroosh129 Sep 18, 2021
c98cb61
Updated the validator to treat the C and the CCpp target the same
Soroosh129 Sep 18, 2021
60d2970
Added a special C test that uses the CCpp target
Soroosh129 Sep 18, 2021
53e4d86
Fixed conversion issue in test
Soroosh129 Sep 18, 2021
8e3729d
Typo in test description
Soroosh129 Sep 18, 2021
6e87733
Added compatiblity for C++ to _LF_SET_NEW
Soroosh129 Sep 18, 2021
5092f6e
Tweaked error reporting in IDE a bit to prevent displaying incorrect …
Soroosh129 Sep 18, 2021
7ff8cf0
Remove unnecessary check for -l libraries in CMake. A warning will be…
Soroosh129 Sep 18, 2021
5c3f9ba
Updated tests for C++ compatiblity
Soroosh129 Sep 18, 2021
e20e3b1
Updated clock sync infrastructure to be compatible with g++
Soroosh129 Sep 19, 2021
4a07316
Fixed C++ error for test
Soroosh129 Sep 19, 2021
da58de2
Treat .c supporting files as C
Soroosh129 Sep 19, 2021
f368af6
Code cleanup and comment
Soroosh129 Sep 19, 2021
0e13698
Revert "Treat .c supporting files as C"
Soroosh129 Sep 19, 2021
1bad76c
Updated comment to explain why we can't just treat .c supporting file…
Soroosh129 Sep 19, 2021
ea1beda
Don't recompile examples using CCpp
Soroosh129 Sep 19, 2021
5810393
Merge remote-tracking branch 'origin/master' into ROS-serialization
Soroosh129 Sep 19, 2021
4017149
Fixed issues caused by merge
Soroosh129 Sep 19, 2021
efb606c
Updated ROS serialization examples to use the new CCpp target
Soroosh129 Sep 19, 2021
bae6c05
Added cast to suppress C++-related error
Soroosh129 Sep 19, 2021
036ab9f
Merge remote-tracking branch 'origin/ROS-serialization' into ccpp-target
Soroosh129 Sep 19, 2021
499e372
Updated search procedure of cmake-include to match the files target p…
Soroosh129 Sep 11, 2021
70aed12
Fixed merge conflicts from ROS-serialization
Soroosh129 Sep 12, 2021
20ce46b
Fixed the logic when an exception occurs
Soroosh129 Sep 12, 2021
5bc3fc8
Aesthetic consistency update to comments and functions
Soroosh129 Sep 14, 2021
25335d4
Updated tests to check that separate compile works for federates
Soroosh129 Sep 15, 2021
9f7459f
Added an updater to TargetConfig to remove redundancy
Soroosh129 Sep 15, 2021
27b91c3
Updated comment for test
Soroosh129 Sep 15, 2021
babc7b0
Made test federated. The test will still fail since separate compile …
Soroosh129 Sep 15, 2021
aba6182
Made test federated
Soroosh129 Sep 15, 2021
afe522f
Removed unused imports
Soroosh129 Sep 17, 2021
5d416e3
Updated examples to use definitions that match their reactor names
Soroosh129 Sep 19, 2021
23ac2fa
Changed file names to match the previous format
Soroosh129 Sep 19, 2021
402dac4
Updated error message to be more informative
Soroosh129 Sep 19, 2021
8892e1f
Moved target-specific tests to target
Soroosh129 Sep 19, 2021
233019c
Updated path
Soroosh129 Sep 19, 2021
c6c908e
Fixed target separation by resetting cmake-include for each federate …
Soroosh129 Sep 19, 2021
bdcbaa7
Moved back addPlatformFiles to avoid adding duplicate platform files
Soroosh129 Sep 19, 2021
e38dac0
Ignore compiler if it is blank
Soroosh129 Sep 20, 2021
315a904
Add cmake predicates that enable functionalities related to CppMode r…
Soroosh129 Sep 20, 2021
3ad0f5f
Update org.lflang/src/org/lflang/validation/LFValidatorImpl.xtend
Soroosh129 Sep 20, 2021
e9ff67c
Added LFResource to keep track of all imported .lf resources along wi…
Soroosh129 Sep 20, 2021
7b845b6
Addressed @cmnrd's comment
Soroosh129 Sep 20, 2021
f871e0f
Addressed lhstrh's comment
Soroosh129 Sep 20, 2021
f75531b
Added isCBasedTarget
Soroosh129 Sep 20, 2021
a0bdd76
Fixed mistakenly left out CCppMode check
Soroosh129 Sep 20, 2021
bdeaac4
Added a check for CMake when ROS Serialization is requested
Soroosh129 Sep 20, 2021
e27ce41
Added error for fast:true for all federated programs
Soroosh129 Sep 20, 2021
c8efedd
Use the name instead of pairs to avoid illegal argument exception
Soroosh129 Sep 21, 2021
b54bf70
Added a validator check for target properties
Soroosh129 Sep 21, 2021
a7756ad
Reverted accidental changes to unrelated files
Soroosh129 Sep 21, 2021
21a68aa
Added an updater for the files target property
Soroosh129 Sep 21, 2021
a18b559
Update org.lflang/src/org/lflang/TargetConfig.xtend
Soroosh129 Sep 21, 2021
b5bd149
Added FIXME about the updater
Soroosh129 Sep 21, 2021
818cabe
Added fixme about the role of GeneratorBase in pulling in files from …
Soroosh129 Sep 21, 2021
e8e0586
Updated comment
Soroosh129 Sep 21, 2021
615d0e0
Merge pull request #498 from lf-lang/cmake-include-improvements
Soroosh129 Sep 22, 2021
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
7 changes: 3 additions & 4 deletions example/C/src/ROS/ROSBuiltInSerialization.lf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* This example showcases the infrastructure that is built into LF
* C runtime that can automatically serialize and deserialize ROS2
* This example showcases the infrastructure that is built into the
* CCpp target that can automatically serialize and deserialize ROS2
* messages in federated programs.
*
* This example contains a sender-receiver federated program in which
Expand All @@ -21,11 +21,10 @@
*
* @author Soroush Bateni <[email protected]>
*/
target C {
target CCpp {
cmake: true, // Only CMake is supported
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it this exampke or the CCpp target that only supports cmake? In the latter case, do we need this line and should we even allow the cmake property in this target?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the target CCpp works without CMake. We have tests for that in this branch.

ROS Serialization on the other hand only works with CMake. That's a great point. I will add a check.

cmake-include: "include/CMakeListsExtension.txt",
threads: 1,
compiler: "g++"
};

preamble {=
Expand Down
3 changes: 1 addition & 2 deletions example/C/src/ROS/ROSSerialization.lf
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@
* There is a variant of this example called ROSBuiltInSerialization.lf that uses
* the built-in ROS 2 serialization feature that is provided in LF.
*/
target C {
target CCpp {
coordination: decentralized,
timeout: 10 sec,
cmake-include: "include/CMakeListsExtension.txt",
files: ["include/ament_target_dependencies.cmake"],
compiler: "g++",
};

preamble {=
Expand Down
4 changes: 3 additions & 1 deletion example/C/src/Rhythm/PlayWaveform.lf
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ target C {
"/lib/C/util/audio_loop_linux.c",
"sounds/Bass-Drum-1.wav", "sounds/Hi-Bongo.wav", "sounds/Claves.wav", "sounds/High-Conga-1.wav",
"sounds/Cowbell-1.wav", "sounds/Cuica-1.wav", "sounds/Guiro.wav",
"sounds/Ensoniq-ESQ-1-Snare.wav", "sounds/Floor-Tom-1.wav"]
"sounds/Ensoniq-ESQ-1-Snare.wav", "sounds/Floor-Tom-1.wav"],
// Include the cmake support for the audio loop
cmake-include: ["/lib/C/util/audio_loop.cmake"]
}
preamble {=
#include "wave_file_reader.c"
Expand Down
20 changes: 8 additions & 12 deletions example/C/src/Rhythm/Rhythm.lf
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,20 @@
*/
target C {
threads: 2,
cmake-include: [
"sound-extension.cmake",
"audio_loop.cmake",
"sensor_simulator.cmake",
"ncurses-extension.cmake",
"mlib-extension.cmake"],
tracing: true,
files: [
"/lib/C/util/sensor_simulator.c", "/lib/C/util/sensor_simulator.h", "/lib/C/util/sensor_simulator.cmake",
"/lib/C/util/sensor_simulator.c", "/lib/C/util/sensor_simulator.h",
"/lib/C/util/wave_file_reader.c", "/lib/C/util/wave_file_reader.h",
"/lib/C/util/audio_loop_mac.c", "/lib/C/util/audio_loop.h", "/lib/C/util/audio_loop.cmake",
"/lib/C/util/audio_loop_mac.c", "/lib/C/util/audio_loop.h",
"/lib/C/util/audio_loop_linux.c",
"sounds/Bass-Drum-1.wav", "sounds/Hi-Bongo.wav", "sounds/Claves.wav", "sounds/High-Conga-1.wav",
"sounds/Cowbell-1.wav", "sounds/Cuica-1.wav", "sounds/Guiro.wav",
"sounds/Ensoniq-ESQ-1-Snare.wav", "sounds/Floor-Tom-1.wav",
"include/ncurses-extension.cmake",
"include/sound-extension.cmake",
"include/mlib-extension.cmake"]
"sounds/Ensoniq-ESQ-1-Snare.wav", "sounds/Floor-Tom-1.wav"],
// Include cmake support for some needed functionality
cmake-include: [
"/lib/C/util/sensor_simulator.cmake", // Enable support for the sensor simulator
"include/ncurses-extension.cmake", // Enable support for ncurses
"include/mlib-extension.cmake"] // Enable support for the math lib
};

import PlayWaveform from "PlayWaveform.lf"
Expand Down
15 changes: 3 additions & 12 deletions example/C/src/Rhythm/RhythmDistributed.lf
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,14 @@
*/
target C {
coordination: centralized,
cmake-include: [
"sound-extension.cmake",
"audio_loop.cmake",
"sensor_simulator.cmake",
"ncurses-extension.cmake",
"mlib-extension.cmake"],
files: [
"/lib/C/util/sensor_simulator.c", "/lib/C/util/sensor_simulator.h", "/lib/C/util/sensor_simulator.cmake",
"/lib/C/util/sensor_simulator.c", "/lib/C/util/sensor_simulator.h",
"/lib/C/util/wave_file_reader.c", "/lib/C/util/wave_file_reader.h",
"/lib/C/util/audio_loop_mac.c", "/lib/C/util/audio_loop.h", "/lib/C/util/audio_loop.cmake",
"/lib/C/util/audio_loop_mac.c", "/lib/C/util/audio_loop.h",
"/lib/C/util/audio_loop_linux.c",
"sounds/Bass-Drum-1.wav", "sounds/Hi-Bongo.wav", "sounds/Claves.wav", "sounds/High-Conga-1.wav",
"sounds/Cowbell-1.wav", "sounds/Cuica-1.wav", "sounds/Guiro.wav",
"sounds/Ensoniq-ESQ-1-Snare.wav", "sounds/Floor-Tom-1.wav",
"include/ncurses-extension.cmake",
"include/sound-extension.cmake",
"include/mlib-extension.cmake"]
"sounds/Ensoniq-ESQ-1-Snare.wav", "sounds/Floor-Tom-1.wav"]
};

import RhythmSource from "Rhythm.lf"
Expand Down
12 changes: 2 additions & 10 deletions example/C/src/Rhythm/RhythmDistributedNoUI.lf
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@
* @author Edward A. Lee
*/
target C {
cmake-include: [
"sound-extension.cmake",
"audio_loop.cmake",
"ncurses-extension.cmake",
"mlib-extension.cmake"],
coordination: decentralized,
timeout: 10 sec,
clock-sync: on,
Expand All @@ -47,14 +42,11 @@ target C {
},
files: [
"/lib/C/util/wave_file_reader.c", "/lib/C/util/wave_file_reader.h",
"/lib/C/util/audio_loop_mac.c", "/lib/C/util/audio_loop.h", "/lib/C/util/audio_loop.cmake",
"/lib/C/util/audio_loop_mac.c", "/lib/C/util/audio_loop.h",
"/lib/C/util/audio_loop_linux.c",
"sounds/Bass-Drum-1.wav", "sounds/Hi-Bongo.wav", "sounds/Claves.wav", "sounds/High-Conga-1.wav",
"sounds/Cowbell-1.wav", "sounds/Cuica-1.wav", "sounds/Guiro.wav",
"sounds/Ensoniq-ESQ-1-Snare.wav", "sounds/Floor-Tom-1.wav",
"include/ncurses-extension.cmake",
"include/sound-extension.cmake",
"include/mlib-extension.cmake"]
"sounds/Ensoniq-ESQ-1-Snare.wav", "sounds/Floor-Tom-1.wav"]
};
import PlayWaveform from "PlayWaveform.lf"

Expand Down
7 changes: 4 additions & 3 deletions example/C/src/Rhythm/SensorSimulator.lf
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
*/
target C {
threads: 2,
cmake-include: ["ncurses-extension.cmake", "sensor_simulator.cmake"], // Adds support for ncurses
files: [
"/lib/C/util/sensor_simulator.c",
"/lib/C/util/sensor_simulator.h",
"/lib/C/util/sensor_simulator.cmake",
],
cmake-include: [
"/lib/C/util/sensor_simulator.cmake",
"include/ncurses-extension.cmake"
]
]
};
preamble {=
#include "sensor_simulator.h"
Expand Down
13 changes: 0 additions & 13 deletions example/C/src/Rhythm/include/sound-extension.cmake

This file was deleted.

2 changes: 1 addition & 1 deletion example/ReflexGame/ReflexGameTest.lf
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ main reactor {
// control-z) is received.
void* read_char(void* a) {
while(1) {
char* c = malloc(sizeof(char));
char* c = (char*)malloc(sizeof(char));
*c = getchar();
schedule_value(a, 0, c, 1);
if (*c == EOF) break;
Expand Down
30 changes: 29 additions & 1 deletion org.lflang.tests/src/org/lflang/tests/runtime/CTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@
***************/
package org.lflang.tests.runtime;

import java.util.EnumSet;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import org.lflang.ASTUtils;
import org.lflang.Target;
import org.lflang.tests.TestRegistry.TestCategory;

/**
* Collection of tests for the C target.
Expand Down Expand Up @@ -101,4 +104,29 @@ public void runConcurrentTests() {
public void runFederatedTests() {
super.runFederatedTests();
}

/** Static description of test that runs C tests as CCpp. */
public static final String RUN_AS_CCPP_DESC = "Description: Running C tests as CCpp.";

/**
* Run C tests with the target CCpp.
*/
@Test
public void runAsCCpp() {
printTestHeader(RUN_AS_CCPP_DESC);

EnumSet<TestCategory> categories = EnumSet.allOf(TestCategory.class);

categories.removeAll(EnumSet.of(
// Don't need to test examples.
// If any of them uses CCpp, it will
// be tested when compileExamples is
// run.
TestCategory.EXAMPLE));

runTestsAndPrintResults(target,
categories::contains,
it -> ASTUtils.changeTargetName(it.fileConfig.resource, "CCpp"),
true);
}
}
11 changes: 9 additions & 2 deletions org.lflang/src/lib/C/util/audio_loop.cmake
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
target_sources(${LF_MAIN_TARGET} PRIVATE audio_loop_linux.c)
find_package( ALSA REQUIRED)
if (ALSA_FOUND)
include_directories( ${ALSA_INCLUDE_DIRS} )
target_link_libraries( ${LF_MAIN_TARGET} ${ALSA_LIBRARIES} )
endif(ALSA_FOUND)
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
target_sources(${LF_MAIN_TARGET} PRIVATE audio_loop_mac.c)
target_link_libraries( ${LF_MAIN_TARGET} "-framework AudioToolbox" )
target_link_libraries( ${LF_MAIN_TARGET} "-framework CoreFoundation" )
else()
message(FATAL_ERROR "Your platform is not supported!"
" The C target supports Linux, MacOS and Windows.")
endif()
" Sound is only currently supported on Linux and MacOS.")
endif()
5 changes: 3 additions & 2 deletions org.lflang/src/lib/core/federated/clock-sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,9 @@ ushort setup_clock_synchronization_with_rti() {

port_to_return = ntohs(federate_UDP_addr.sin_port);

// Set the option for this socket to reuse the same address
if (setsockopt(_lf_rti_socket_UDP, SOL_SOCKET, SO_REUSEADDR, &(int){1}, sizeof(int)) < 0) {
// Set the option for this socket to reuse the same address
int option_value = 1;
if (setsockopt(_lf_rti_socket_UDP, SOL_SOCKET, SO_REUSEADDR, &option_value, sizeof(int)) < 0) {
error_print("Failed to set SO_REUSEADDR option on the socket: %s.", strerror(errno));
}
// Set the timeout on the UDP socket so that read and write operations don't block for too long
Expand Down
10 changes: 10 additions & 0 deletions org.lflang/src/lib/core/reactor.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,23 @@ do { \
* struct to true (which causes the object message to be sent),
* @param out The output port (by name).
*/
#ifndef __cplusplus
#define _LF_SET_NEW(out) \
do { \
out->is_present = true; \
lf_token_t* token = __set_new_array_impl(out->token, 1, out->num_destinations); \
out->value = token->value; \
out->token = token; \
} while(0)
#else
#define _LF_SET_NEW(out) \
do { \
out->is_present = true; \
lf_token_t* token = __set_new_array_impl(out->token, 1, out->num_destinations); \
out->value = static_cast<decltype(out->value)>(token->value); \
out->token = token; \
} while(0)
#endif // __cplusplus

/**
* Version of set() for output types given as 'type[]'.
Expand Down
10 changes: 10 additions & 0 deletions org.lflang/src/org/lflang/ASTUtils.xtend
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,16 @@ class ASTUtils {
return true
}

/**
* Change the target name to 'newTargetName'.
* For example, change C to CCpp.
*/
static def boolean changeTargetName(Resource resource, String newTargetName) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems dangerous. I assume it is needed by the test that compile C tests as CCpp? I wouldn't expose this function here if we don't have a use-case for it. Maybe it would be better placed in the test package.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume it is needed by the test that compile C tests as CCpp?

Correct.

Maybe it would be better placed in the test package.

I think semantically, it belongs to ASTUtils because it is an AST transformation after all.
I think in terms of being dangerous, there will be validation and compiler errors if a target name is changed to an incompatible language, so it might be relatively safe perhaps.

val r = resource.targetDecl
r.name = newTargetName
return true
}

/**
* Return true if any port on the left or right of the connection involves
* a bank of reactors or a multiport.
Expand Down
Loading