Skip to content

Commit

Permalink
Merge pull request #28 from lf-lang/clem.par-build
Browse files Browse the repository at this point in the history
Rewrite of the backend interfaces
  • Loading branch information
tanneberger authored Jul 13, 2023
2 parents 81a168f + 8085b2c commit bbb0b6f
Show file tree
Hide file tree
Showing 18 changed files with 779 additions and 339 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ result
# These are backup files generated by rustfmt
**/*.rs.bk
.direnv
sandbox/

.vscode/
build/
Expand Down
45 changes: 39 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ serde_derive = "*"
which = "*"
regex = "1.8.4"
lazy_static = "1.4.0"
rayon = "1.7"

toml = {version = "0"}
crossbeam = "*"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ tarfetcher = {version = "0.4.2"}
# replacement for target properties
[[app.properties]]
cmake-include = "./my-cmake.cmake"
logging = true
logging = "info"

# second binary
[[app]]
Expand Down
42 changes: 42 additions & 0 deletions sandbox/Lingo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[package]
name = "example_project"
version = "0.1.0"
authors = ["tassilo.tannerber@tu-dresden.de"]
homepage = "https://lf-lang.org"
license = "Weird Stallman License"
description = "A little Lingo.toml for people"

# shared properties of all binaries
[properties]
fast = true

# first binary in the project
[[app]]
name = "git-hook"
target = "Cpp"
main_reactor = "src/Main.lf"
dependencies = {}
# main_reactor defaults to src/Main.lf

# dependencies
#[[app.dependencies]]
#git = {version = "0.3.2"}
#tarfetcher = {version = "0.4.2"}

# replacement for target properties
[app.properties]
logging = "info"
#cmake-include = "./my-cmake.cmake"

# second binary
[[app]]
name = "embedded"
main_reactor = "src/Main2.lf"
dependencies = {}
target = "Cpp"

#[[app.dependencies]]
#blink = {version = "0.1.2"}

[app.properties]
no-compile = true
58 changes: 58 additions & 0 deletions sandbox/src/Main.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// This example illustrates local deadline handling. Even numbers are sent by the Source
// immediately, whereas odd numbers are sent after a big enough delay to violate the deadline.
target Cpp {
timeout: 4 sec
}

reactor Source(period: time = 2 sec) {
private preamble {=
#include <thread>
=}
output y: int
timer t(0, period)
state count: int = 0

reaction(t) -> y {=
if (count % 2 == 1) {
// The count variable is odd.
// Take time to cause a deadline violation.
std::this_thread::sleep_for(400ms);
}
std::cout << "Source sends: " << count << std::endl;
y.set(count);
count++;
=}
}

reactor Destination(timeout: time = 1 sec) {
input x: int
state count: int = 0

reaction(x) {=
std::cout << "Destination receives: " << *x.get() << std::endl;
if (count % 2 == 1) {
// The count variable is odd, so the deadline should have been
// violated
std::cerr << "ERROR: Failed to detect deadline." << std::endl;
exit(1);
}
count++;
=} deadline(timeout) {=
std::cout << "Destination deadline handler receives: "
<< *x.get() << std::endl;
if (count % 2 == 0) {
// The count variable is even, so the deadline should not have
// been violated.
std::cerr << "ERROR: Deadline handler invoked without deadline "
<< "violation." << std::endl;
exit(2);
}
count++;
=}
}

main reactor Main {
s = new Source()
d = new Destination(timeout = 200 msec)
s.y -> d.x
}
58 changes: 58 additions & 0 deletions sandbox/src/Main2.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// This example illustrates local deadline handling. Even numbers are sent by the Source
// immediately, whereas odd numbers are sent after a big enough delay to violate the deadline.
target Cpp {
timeout: 4 sec
}

reactor Source(period: time = 2 sec) {
private preamble {=
#include <thread>
=}
output y: int
timer t(0, period)
state count: int = 0

reaction(t) -> y {=
if (count % 2 == 1) {
// The count variable is odd.
// Take time to cause a deadline violation.
std::this_thread::sleep_for(400ms);
}
std::cout << "Source sends: " << count << std::endl;
y.set(count);
count++;
=}
}

reactor Destination(timeout: time = 1 sec) {
input x: int
state count: int = 0

reaction(x) {=
std::cout << "Destination receives: " << *x.get() << std::endl;
if (count % 2 == 1) {
// The count variable is odd, so the deadline should have been
// violated
std::cerr << "ERROR: Failed to detect deadline." << std::endl;
exit(1);
}
count++;
=} deadline(timeout) {=
std::cout << "Destination deadline handler receives: "
<< *x.get() << std::endl;
if (count % 2 == 0) {
// The count variable is even, so the deadline should not have
// been violated.
std::cerr << "ERROR: Deadline handler invoked without deadline "
<< "violation." << std::endl;
exit(2);
}
count++;
=}
}

main reactor Main2 {
s = new Source()
d = new Destination(timeout = 200 msec)
s.y -> d.x
}
36 changes: 26 additions & 10 deletions src/args.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::backends::BuildProfile;
use clap::{Args, Parser, Subcommand};
use serde_derive::{Deserialize, Serialize};
use std::path::PathBuf;
Expand All @@ -17,46 +18,61 @@ pub enum Platform {
Zephyr,
}

#[derive(clap::ValueEnum, Clone, Copy, Debug, Deserialize, Serialize)]
#[derive(clap::ValueEnum, Clone, Copy, Debug, Deserialize, Serialize, Eq, PartialEq, Hash)]
pub enum BuildSystem {
LFC,
CMake,
Cargo,
}

#[derive(Args, Debug)]
pub struct BuildArgs {
/// which build system to use
/// Which build system to use
/// TODO: discuss this
#[clap(short, long)]
pub build_system: Option<BuildSystem>,

/// which target to build
/// Which target to build
#[clap(short, long)]
pub language: Option<TargetLanguage>,

/// overwrites any possible board definition in Lingo.toml
/// Overwrites any possible board definition in Lingo.toml
#[clap(long)]
pub platform: Option<Platform>,

/// tell lingo where the lfc toolchain can be found
/// Tell lingo where the lfc toolchain can be found
#[clap(long)]
pub lfc: Option<PathBuf>,

/// skips building aka invoking the build system so it only generates code
/// Skips building aka invoking the build system so it only generates code
#[clap(short, long, action)]
pub no_compile: bool,

/// if one of the apps fails to build dont interrupt the build process
/// If one of the apps fails to build dont interrupt the build process
#[clap(short, long, action)]
pub keep_going: bool,

/// compiles the binaries with optimizations turned on and strips debug symbols
/// Compiles the binaries with optimizations turned on and strips debug symbols
#[clap(short, long, action)]
pub release: bool,

/// list of apps to build if left empty all apps are built
/// List of apps to build if left empty all apps are built
#[clap(short, long, value_delimiter = ',')]
pub apps: Vec<String>,

/// Number of threads to use for parallel builds. Zero means it will be determined automatically.
#[clap(short, long, default_value_t = 0)]
pub threads: usize,
}

impl BuildArgs {
pub fn build_profile(&self) -> BuildProfile {
if self.release {
BuildProfile::Release
} else {
BuildProfile::Debug
}
}
}

impl ToString for TargetLanguage {
Expand All @@ -75,7 +91,7 @@ pub struct InitArgs {
}
impl InitArgs {
pub fn get_target_language(&self) -> TargetLanguage {
self.language.unwrap_or_else(|| {
self.language.unwrap_or({
// Target language for Zephyr is C, else Cpp.
match self.platform {
Some(Platform::Zephyr) => TargetLanguage::C,
Expand Down
Loading

0 comments on commit bbb0b6f

Please sign in to comment.