Skip to content

Commit bbb0b6f

Browse files
authored
Merge pull request #28 from lf-lang/clem.par-build
Rewrite of the backend interfaces
2 parents 81a168f + 8085b2c commit bbb0b6f

File tree

18 files changed

+779
-339
lines changed

18 files changed

+779
-339
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ result
1313
# These are backup files generated by rustfmt
1414
**/*.rs.bk
1515
.direnv
16+
sandbox/
1617

1718
.vscode/
1819
build/

Cargo.lock

Lines changed: 39 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ serde_derive = "*"
1414
which = "*"
1515
regex = "1.8.4"
1616
lazy_static = "1.4.0"
17+
rayon = "1.7"
1718

1819
toml = {version = "0"}
1920
crossbeam = "*"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ tarfetcher = {version = "0.4.2"}
6464
# replacement for target properties
6565
[[app.properties]]
6666
cmake-include = "./my-cmake.cmake"
67-
logging = true
67+
logging = "info"
6868

6969
# second binary
7070
[[app]]

sandbox/Lingo.toml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
[package]
2+
name = "example_project"
3+
version = "0.1.0"
4+
authors = ["[email protected]"]
5+
homepage = "https://lf-lang.org"
6+
license = "Weird Stallman License"
7+
description = "A little Lingo.toml for people"
8+
9+
# shared properties of all binaries
10+
[properties]
11+
fast = true
12+
13+
# first binary in the project
14+
[[app]]
15+
name = "git-hook"
16+
target = "Cpp"
17+
main_reactor = "src/Main.lf"
18+
dependencies = {}
19+
# main_reactor defaults to src/Main.lf
20+
21+
# dependencies
22+
#[[app.dependencies]]
23+
#git = {version = "0.3.2"}
24+
#tarfetcher = {version = "0.4.2"}
25+
26+
# replacement for target properties
27+
[app.properties]
28+
logging = "info"
29+
#cmake-include = "./my-cmake.cmake"
30+
31+
# second binary
32+
[[app]]
33+
name = "embedded"
34+
main_reactor = "src/Main2.lf"
35+
dependencies = {}
36+
target = "Cpp"
37+
38+
#[[app.dependencies]]
39+
#blink = {version = "0.1.2"}
40+
41+
[app.properties]
42+
no-compile = true

sandbox/src/Main.lf

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// This example illustrates local deadline handling. Even numbers are sent by the Source
2+
// immediately, whereas odd numbers are sent after a big enough delay to violate the deadline.
3+
target Cpp {
4+
timeout: 4 sec
5+
}
6+
7+
reactor Source(period: time = 2 sec) {
8+
private preamble {=
9+
#include <thread>
10+
=}
11+
output y: int
12+
timer t(0, period)
13+
state count: int = 0
14+
15+
reaction(t) -> y {=
16+
if (count % 2 == 1) {
17+
// The count variable is odd.
18+
// Take time to cause a deadline violation.
19+
std::this_thread::sleep_for(400ms);
20+
}
21+
std::cout << "Source sends: " << count << std::endl;
22+
y.set(count);
23+
count++;
24+
=}
25+
}
26+
27+
reactor Destination(timeout: time = 1 sec) {
28+
input x: int
29+
state count: int = 0
30+
31+
reaction(x) {=
32+
std::cout << "Destination receives: " << *x.get() << std::endl;
33+
if (count % 2 == 1) {
34+
// The count variable is odd, so the deadline should have been
35+
// violated
36+
std::cerr << "ERROR: Failed to detect deadline." << std::endl;
37+
exit(1);
38+
}
39+
count++;
40+
=} deadline(timeout) {=
41+
std::cout << "Destination deadline handler receives: "
42+
<< *x.get() << std::endl;
43+
if (count % 2 == 0) {
44+
// The count variable is even, so the deadline should not have
45+
// been violated.
46+
std::cerr << "ERROR: Deadline handler invoked without deadline "
47+
<< "violation." << std::endl;
48+
exit(2);
49+
}
50+
count++;
51+
=}
52+
}
53+
54+
main reactor Main {
55+
s = new Source()
56+
d = new Destination(timeout = 200 msec)
57+
s.y -> d.x
58+
}

sandbox/src/Main2.lf

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// This example illustrates local deadline handling. Even numbers are sent by the Source
2+
// immediately, whereas odd numbers are sent after a big enough delay to violate the deadline.
3+
target Cpp {
4+
timeout: 4 sec
5+
}
6+
7+
reactor Source(period: time = 2 sec) {
8+
private preamble {=
9+
#include <thread>
10+
=}
11+
output y: int
12+
timer t(0, period)
13+
state count: int = 0
14+
15+
reaction(t) -> y {=
16+
if (count % 2 == 1) {
17+
// The count variable is odd.
18+
// Take time to cause a deadline violation.
19+
std::this_thread::sleep_for(400ms);
20+
}
21+
std::cout << "Source sends: " << count << std::endl;
22+
y.set(count);
23+
count++;
24+
=}
25+
}
26+
27+
reactor Destination(timeout: time = 1 sec) {
28+
input x: int
29+
state count: int = 0
30+
31+
reaction(x) {=
32+
std::cout << "Destination receives: " << *x.get() << std::endl;
33+
if (count % 2 == 1) {
34+
// The count variable is odd, so the deadline should have been
35+
// violated
36+
std::cerr << "ERROR: Failed to detect deadline." << std::endl;
37+
exit(1);
38+
}
39+
count++;
40+
=} deadline(timeout) {=
41+
std::cout << "Destination deadline handler receives: "
42+
<< *x.get() << std::endl;
43+
if (count % 2 == 0) {
44+
// The count variable is even, so the deadline should not have
45+
// been violated.
46+
std::cerr << "ERROR: Deadline handler invoked without deadline "
47+
<< "violation." << std::endl;
48+
exit(2);
49+
}
50+
count++;
51+
=}
52+
}
53+
54+
main reactor Main2 {
55+
s = new Source()
56+
d = new Destination(timeout = 200 msec)
57+
s.y -> d.x
58+
}

src/args.rs

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::backends::BuildProfile;
12
use clap::{Args, Parser, Subcommand};
23
use serde_derive::{Deserialize, Serialize};
34
use std::path::PathBuf;
@@ -17,46 +18,61 @@ pub enum Platform {
1718
Zephyr,
1819
}
1920

20-
#[derive(clap::ValueEnum, Clone, Copy, Debug, Deserialize, Serialize)]
21+
#[derive(clap::ValueEnum, Clone, Copy, Debug, Deserialize, Serialize, Eq, PartialEq, Hash)]
2122
pub enum BuildSystem {
2223
LFC,
2324
CMake,
25+
Cargo,
2426
}
2527

2628
#[derive(Args, Debug)]
2729
pub struct BuildArgs {
28-
/// which build system to use
30+
/// Which build system to use
2931
/// TODO: discuss this
3032
#[clap(short, long)]
3133
pub build_system: Option<BuildSystem>,
3234

33-
/// which target to build
35+
/// Which target to build
3436
#[clap(short, long)]
3537
pub language: Option<TargetLanguage>,
3638

37-
/// overwrites any possible board definition in Lingo.toml
39+
/// Overwrites any possible board definition in Lingo.toml
3840
#[clap(long)]
3941
pub platform: Option<Platform>,
4042

41-
/// tell lingo where the lfc toolchain can be found
43+
/// Tell lingo where the lfc toolchain can be found
4244
#[clap(long)]
4345
pub lfc: Option<PathBuf>,
4446

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

49-
/// if one of the apps fails to build dont interrupt the build process
51+
/// If one of the apps fails to build dont interrupt the build process
5052
#[clap(short, long, action)]
5153
pub keep_going: bool,
5254

53-
/// compiles the binaries with optimizations turned on and strips debug symbols
55+
/// Compiles the binaries with optimizations turned on and strips debug symbols
5456
#[clap(short, long, action)]
5557
pub release: bool,
5658

57-
/// list of apps to build if left empty all apps are built
59+
/// List of apps to build if left empty all apps are built
5860
#[clap(short, long, value_delimiter = ',')]
5961
pub apps: Vec<String>,
62+
63+
/// Number of threads to use for parallel builds. Zero means it will be determined automatically.
64+
#[clap(short, long, default_value_t = 0)]
65+
pub threads: usize,
66+
}
67+
68+
impl BuildArgs {
69+
pub fn build_profile(&self) -> BuildProfile {
70+
if self.release {
71+
BuildProfile::Release
72+
} else {
73+
BuildProfile::Debug
74+
}
75+
}
6076
}
6177

6278
impl ToString for TargetLanguage {
@@ -75,7 +91,7 @@ pub struct InitArgs {
7591
}
7692
impl InitArgs {
7793
pub fn get_target_language(&self) -> TargetLanguage {
78-
self.language.unwrap_or_else(|| {
94+
self.language.unwrap_or({
7995
// Target language for Zephyr is C, else Cpp.
8096
match self.platform {
8197
Some(Platform::Zephyr) => TargetLanguage::C,

0 commit comments

Comments
 (0)