Skip to content

atomics features in generated code #729

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

Merged
merged 1 commit into from
Jun 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
- Fix escaping <> and & characters in doc attributes
- Add `interrupt_link_section` config parameter for controlling the `#[link_section = "..."]` attribute of `__INTERRUPTS`
- Add option to implement Debug for readable registers (#716)
- Add `atomics-feature`

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

Expand Down
6 changes: 6 additions & 0 deletions src/generate/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ pub fn render(d: &Device, config: &Config, device_x: &mut String) -> Result<Toke
let mut file = File::create(config.output_dir.join("generic.rs"))?;
writeln!(file, "{generic_file}")?;
if config.atomics {
if let Some(atomics_feature) = config.atomics_feature.as_ref() {
writeln!(file, "#[cfg(feature = \"{atomics_feature}\")]")?;
}
writeln!(file, "\n{generic_atomic_file}")?;
}
if config.const_generic {
Expand All @@ -170,6 +173,9 @@ pub fn render(d: &Device, config: &Config, device_x: &mut String) -> Result<Toke
} else {
let mut tokens = syn::parse_file(generic_file)?.into_token_stream();
if config.atomics {
if let Some(atomics_feature) = config.atomics_feature.as_ref() {
quote!(#[cfg(feature = #atomics_feature)]).to_tokens(&mut tokens);
}
syn::parse_file(generic_atomic_file)?.to_tokens(&mut tokens);
}
if config.const_generic {
Expand Down
5 changes: 4 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,9 @@
//! concurrently called on different bits in the same register without data races. This flag won't
//! work for RISCV chips without the atomic extension.
//!
//! The `--atomics_feature` flag can also be specified to include atomics implementations conditionally
//! behind the supplied feature name.
//!
//! `portable-atomic` v0.3.16 must be added to the dependencies, with default features off to
//! disable the `fallback` feature.
//!
Expand All @@ -503,7 +506,7 @@
//! register that has read actions will not be read and printed as `(not read/has read action!)`.
//! Registers that are not readable will have `(write only register)` printed as the value.
//!
//! The `--impl_debug_feature` flad can also be specified to include debug implementations conditionally
//! The `--impl_debug_feature` flag can also be specified to include debug implementations conditionally
//! behind the supplied feature name.
//!
//! Usage examples:
Expand Down
7 changes: 7 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ fn run() -> Result<()> {
.action(ArgAction::SetTrue)
.help("Generate atomic register modification API"),
)
.arg(
Arg::new("atomics_feature")
.long("atomics_feature")
.help("add feature gating for atomic register modification API")
.action(ArgAction::Set)
.value_name("FEATURE"),
)
.arg(
Arg::new("const_generic")
.long("const_generic")
Expand Down
3 changes: 3 additions & 0 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ pub struct Config {
#[cfg_attr(feature = "serde", serde(default))]
pub atomics: bool,
#[cfg_attr(feature = "serde", serde(default))]
pub atomics_feature: Option<String>,
#[cfg_attr(feature = "serde", serde(default))]
pub generic_mod: bool,
#[cfg_attr(feature = "serde", serde(default))]
pub make_mod: bool,
Expand Down Expand Up @@ -111,6 +113,7 @@ impl Default for Config {
Self {
target: Target::default(),
atomics: false,
atomics_feature: None,
generic_mod: false,
make_mod: false,
const_generic: false,
Expand Down