Skip to content

Commit a1c72a8

Browse files
committed
atomics features in generated code
1 parent 535aac3 commit a1c72a8

File tree

5 files changed

+21
-1
lines changed

5 files changed

+21
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
1717
- Fix escaping <> and & characters in doc attributes
1818
- Add `interrupt_link_section` config parameter for controlling the `#[link_section = "..."]` attribute of `__INTERRUPTS`
1919
- Add option to implement Debug for readable registers (#716)
20+
- Add `atomics-feature`
2021

2122
## [v0.28.0] - 2022-12-25
2223

src/generate/device.rs

+6
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ pub fn render(d: &Device, config: &Config, device_x: &mut String) -> Result<Toke
153153
let mut file = File::create(config.output_dir.join("generic.rs"))?;
154154
writeln!(file, "{generic_file}")?;
155155
if config.atomics {
156+
if let Some(atomics_feature) = config.atomics_feature.as_ref() {
157+
writeln!(file, "#[cfg(feature = \"{atomics_feature}\")]")?;
158+
}
156159
writeln!(file, "\n{generic_atomic_file}")?;
157160
}
158161
if config.const_generic {
@@ -170,6 +173,9 @@ pub fn render(d: &Device, config: &Config, device_x: &mut String) -> Result<Toke
170173
} else {
171174
let mut tokens = syn::parse_file(generic_file)?.into_token_stream();
172175
if config.atomics {
176+
if let Some(atomics_feature) = config.atomics_feature.as_ref() {
177+
quote!(#[cfg(feature = #atomics_feature)]).to_tokens(&mut tokens);
178+
}
173179
syn::parse_file(generic_atomic_file)?.to_tokens(&mut tokens);
174180
}
175181
if config.const_generic {

src/lib.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,9 @@
492492
//! concurrently called on different bits in the same register without data races. This flag won't
493493
//! work for RISCV chips without the atomic extension.
494494
//!
495+
//! The `--atomics_feature` flag can also be specified to include atomics implementations conditionally
496+
//! behind the supplied feature name.
497+
//!
495498
//! `portable-atomic` v0.3.16 must be added to the dependencies, with default features off to
496499
//! disable the `fallback` feature.
497500
//!
@@ -503,7 +506,7 @@
503506
//! register that has read actions will not be read and printed as `(not read/has read action!)`.
504507
//! Registers that are not readable will have `(write only register)` printed as the value.
505508
//!
506-
//! The `--impl_debug_feature` flad can also be specified to include debug implementations conditionally
509+
//! The `--impl_debug_feature` flag can also be specified to include debug implementations conditionally
507510
//! behind the supplied feature name.
508511
//!
509512
//! Usage examples:

src/main.rs

+7
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ fn run() -> Result<()> {
7272
.action(ArgAction::SetTrue)
7373
.help("Generate atomic register modification API"),
7474
)
75+
.arg(
76+
Arg::new("atomics_feature")
77+
.long("atomics_feature")
78+
.help("add feature gating for atomic register modification API")
79+
.action(ArgAction::Set)
80+
.value_name("FEATURE"),
81+
)
7582
.arg(
7683
Arg::new("const_generic")
7784
.long("const_generic")

src/util.rs

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ pub struct Config {
3030
#[cfg_attr(feature = "serde", serde(default))]
3131
pub atomics: bool,
3232
#[cfg_attr(feature = "serde", serde(default))]
33+
pub atomics_feature: Option<String>,
34+
#[cfg_attr(feature = "serde", serde(default))]
3335
pub generic_mod: bool,
3436
#[cfg_attr(feature = "serde", serde(default))]
3537
pub make_mod: bool,
@@ -111,6 +113,7 @@ impl Default for Config {
111113
Self {
112114
target: Target::default(),
113115
atomics: false,
116+
atomics_feature: None,
114117
generic_mod: false,
115118
make_mod: false,
116119
const_generic: false,

0 commit comments

Comments
 (0)