Skip to content

Commit ddc3d99

Browse files
committed
unstable-riscv feature
1 parent 71b33bf commit ddc3d99

18 files changed

+37
-87
lines changed

svd-encoder/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
88
## Unreleased
99

1010
- Add `riscv` element for configuration parameters related to RISC-V targets.
11+
You must use the `unstable-riscv` feature to enable this exeperimental element.
1112
- Bump MSRV to 1.65.0
1213

1314
## [v0.14.3] - 2023-11-15

svd-encoder/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ rust-version = "1.65.0"
1111
version = "0.14.4"
1212
readme = "README.md"
1313

14+
[features]
15+
unstable-riscv = ["svd-rs/unstable-riscv"]
16+
1417
[dependencies]
1518
convert_case = "0.6.0"
1619
svd-rs = { version = "0.14.7", path = "../svd-rs" }

svd-encoder/src/device.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl Encode for Device {
3434
elem.children.push(new_node("licenseText", v.clone()));
3535
}
3636

37-
// TODO not sure if this is the correct position
37+
#[cfg(feature = "unstable-riscv")]
3838
if let Some(v) = &self.riscv {
3939
elem.children
4040
.push(XMLNode::Element(v.encode_with_config(config)?));

svd-encoder/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ mod readaction;
103103
mod register;
104104
mod registercluster;
105105
mod registerproperties;
106+
#[cfg(feature = "unstable-riscv")]
106107
mod riscv;
107108
mod usage;
108109
mod writeconstraint;

svd-encoder/src/riscv.rs

-9
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,6 @@ impl Encode for Riscv {
77
fn encode_with_config(&self, config: &Config) -> Result<Element, EncodeError> {
88
let mut elem = Element::new("riscv");
99

10-
if let Some(clic) = &self.clic {
11-
elem.children.push(new_node("clic", clic.clone()));
12-
}
13-
if let Some(clint) = &self.clint {
14-
elem.children.push(new_node("clint", clint.clone()));
15-
}
16-
if let Some(plic) = &self.plic {
17-
elem.children.push(new_node("plic", plic.clone()));
18-
}
1910
if !self.core_interrupts.is_empty() {
2011
let mut interrupts = Element::new("coreInterrupts");
2112
for interrupt in &self.core_interrupts {

svd-parser/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
88
## Unreleased
99

1010
- Add `riscv` element for configuration parameters related to RISC-V targets.
11+
You must use the `unstable-riscv` feature to enable this exeperimental element.
1112
- Bump MSRV to 1.65.0
1213

1314
## [v0.14.5] - 2024-01-03

svd-parser/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ readme = "README.md"
1717
[features]
1818
derive-from = ["svd-rs/derive-from"]
1919
expand = ["derive-from"]
20+
unstable-riscv = ["svd-rs/unstable-riscv"]
2021

2122
[dependencies]
2223
svd-rs = { version = "0.14.7", path = "../svd-rs" }

svd-parser/src/device.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use super::*;
2-
use crate::svd::{
3-
cpu::Cpu, peripheral::Peripheral, registerproperties::RegisterProperties, riscv::Riscv,
4-
};
2+
#[cfg(feature = "unstable-riscv")]
3+
use crate::svd::riscv::Riscv;
4+
use crate::svd::{cpu::Cpu, peripheral::Peripheral, registerproperties::RegisterProperties};
55

66
/// Parses a SVD file
77
impl Parse for Device {
@@ -20,7 +20,6 @@ impl Parse for Device {
2020
.name(tree.get_child_text("name")?)
2121
.series(tree.get_child_text_opt("series")?)
2222
.license_text(tree.get_child_text_opt("licenseText")?)
23-
.riscv(optional::<Riscv>("riscv", tree, config)?)
2423
.cpu(optional::<Cpu>("cpu", tree, config)?)
2524
.header_system_filename(tree.get_child_text_opt("headerSystemFilename")?)
2625
.header_definitions_prefix(tree.get_child_text_opt("headerDefinitionsPrefix")?)
@@ -34,6 +33,10 @@ impl Parse for Device {
3433
.collect();
3534
ps?
3635
});
36+
#[cfg(feature = "unstable-riscv")]
37+
if let Some(riscv) = optional::<Riscv>("riscv", tree, config)? {
38+
device = device.riscv(riscv);
39+
}
3740
if let Some(version) = tree.get_child_text_opt("version")? {
3841
device = device.version(version)
3942
}

svd-parser/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ mod readaction;
211211
mod register;
212212
mod registercluster;
213213
mod registerproperties;
214+
#[cfg(feature = "unstable-riscv")]
214215
mod riscv;
215216
mod usage;
216217
mod writeconstraint;

svd-parser/src/riscv.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@ impl Parse for Riscv {
1111
return Err(SVDError::NotExpectedTag("riscv".to_string()).at(tree.id()));
1212
}
1313

14-
let mut builder = Riscv::builder()
15-
.clic(tree.get_child_text("clic").ok())
16-
.clint(tree.get_child_text("clint").ok())
17-
.plic(tree.get_child_text("plic").ok());
14+
let mut builder = Riscv::builder();
1815

1916
if let Some(interrupts) = tree.get_child("coreInterrupts") {
2017
let interrupts: Result<Vec<_>, _> = interrupts

svd-rs/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
88
## Unreleased
99

1010
- Add `riscv` element for configuration parameters related to RISC-V targets.
11+
You must use the `unstable-riscv` feature to enable this exeperimental element.
1112
- Add `DataType`
1213

1314
## [v0.14.8] - 2024-02-13

svd-rs/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ readme = "README.md"
1515

1616
[features]
1717
derive-from = []
18+
unstable-riscv = []
1819

1920
[dependencies]
2021
thiserror = "1.0.31"

svd-rs/src/device.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
#[cfg(feature = "unstable-riscv")]
2+
use super::Riscv;
13
use super::{
2-
BuildError, Cpu, Description, EmptyToNone, Name, Peripheral, RegisterProperties, Riscv,
3-
SvdError, ValidateLevel,
4+
BuildError, Cpu, Description, EmptyToNone, Name, Peripheral, RegisterProperties, SvdError,
5+
ValidateLevel,
46
};
57

68
/// Errors for [`Device::validate`]
@@ -111,6 +113,7 @@ pub struct Device {
111113
feature = "serde",
112114
serde(default, skip_serializing_if = "Option::is_none")
113115
)]
116+
#[cfg(feature = "unstable-riscv")]
114117
pub riscv: Option<Riscv>,
115118
}
116119

@@ -137,6 +140,7 @@ pub struct DeviceBuilder {
137140
version: Option<String>,
138141
description: Option<String>,
139142
license_text: Option<String>,
143+
#[cfg(feature = "unstable-riscv")]
140144
riscv: Option<Riscv>,
141145
cpu: Option<Cpu>,
142146
header_system_filename: Option<String>,
@@ -160,6 +164,7 @@ impl From<Device> for DeviceBuilder {
160164
version: Some(d.version),
161165
description: Some(d.description),
162166
license_text: d.license_text,
167+
#[cfg(feature = "unstable-riscv")]
163168
riscv: d.riscv,
164169
cpu: d.cpu,
165170
header_system_filename: d.header_system_filename,
@@ -212,8 +217,9 @@ impl DeviceBuilder {
212217
self
213218
}
214219
/// Set the riscv of the device.
215-
pub fn riscv(mut self, value: Option<Riscv>) -> Self {
216-
self.riscv = value;
220+
#[cfg(feature = "unstable-riscv")]
221+
pub fn riscv(mut self, value: Riscv) -> Self {
222+
self.riscv = Some(value);
217223
self
218224
}
219225
/// Set the cpu of the device.
@@ -297,6 +303,7 @@ impl DeviceBuilder {
297303
})
298304
.ok_or_else(|| BuildError::Uninitialized("description".to_string()))?,
299305
license_text: self.license_text,
306+
#[cfg(feature = "unstable-riscv")]
300307
riscv: self.riscv,
301308
cpu: self.cpu,
302309
header_system_filename: self.header_system_filename,
@@ -356,6 +363,7 @@ impl Device {
356363
if builder.license_text.is_some() {
357364
self.license_text = builder.license_text.empty_to_none();
358365
}
366+
#[cfg(feature = "unstable-riscv")]
359367
if builder.riscv.is_some() {
360368
self.riscv = builder.riscv;
361369
}

svd-rs/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ pub mod datatype;
9595
pub use self::datatype::DataType;
9696

9797
/// Custom objects for the RISC-V ecosystem
98+
#[cfg(feature = "unstable-riscv")]
9899
pub mod riscv;
100+
#[cfg(feature = "unstable-riscv")]
99101
pub use self::riscv::Riscv;
100102

101103
/// Level of validation

svd-rs/src/riscv.rs

-57
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,6 @@ pub use priority::Priority;
1818
#[derive(Clone, Debug, PartialEq, Eq)]
1919
#[non_exhaustive]
2020
pub struct Riscv {
21-
/// Indicate the ID of the CLIC peripheral (if present).
22-
#[cfg_attr(
23-
feature = "serde",
24-
serde(default, skip_serializing_if = "Option::is_none")
25-
)]
26-
pub clic: Option<String>,
27-
28-
/// Indicate the ID of the CLINT peripheral (if present).
29-
#[cfg_attr(
30-
feature = "serde",
31-
serde(default, skip_serializing_if = "Option::is_none")
32-
)]
33-
pub clint: Option<String>,
34-
35-
/// Indicate the ID of the PLIC peripheral (if present).
36-
#[cfg_attr(
37-
feature = "serde",
38-
serde(default, skip_serializing_if = "Option::is_none")
39-
)]
40-
pub plic: Option<String>,
41-
4221
/// Core interrupt enumeration values
4322
#[cfg_attr(
4423
feature = "serde",
@@ -64,9 +43,6 @@ pub struct Riscv {
6443
/// Builder for [`Riscv`]
6544
#[derive(Clone, Debug, Default, PartialEq, Eq)]
6645
pub struct RiscvBuilder {
67-
clic: Option<String>,
68-
clint: Option<String>,
69-
plic: Option<String>,
7046
core_interrupts: Option<Vec<Interrupt>>,
7147
priorities: Option<Vec<Priority>>,
7248
harts: Option<Vec<Hart>>,
@@ -75,9 +51,6 @@ pub struct RiscvBuilder {
7551
impl From<Riscv> for RiscvBuilder {
7652
fn from(riscv: Riscv) -> Self {
7753
Self {
78-
clic: riscv.clic,
79-
clint: riscv.clint,
80-
plic: riscv.plic,
8154
core_interrupts: Some(riscv.core_interrupts),
8255
priorities: Some(riscv.priorities),
8356
harts: Some(riscv.harts),
@@ -86,24 +59,6 @@ impl From<Riscv> for RiscvBuilder {
8659
}
8760

8861
impl RiscvBuilder {
89-
/// Set the ID of the CLIC peripheral
90-
pub fn clic(mut self, clic: Option<String>) -> Self {
91-
self.clic = clic;
92-
self
93-
}
94-
95-
/// Set the ID of the CLINT peripheral
96-
pub fn clint(mut self, clint: Option<String>) -> Self {
97-
self.clint = clint;
98-
self
99-
}
100-
101-
/// Set the ID of the PLIC peripheral
102-
pub fn plic(mut self, plic: Option<String>) -> Self {
103-
self.plic = plic;
104-
self
105-
}
106-
10762
/// Set the core interrupt enumeration values
10863
pub fn core_interrupts(mut self, core_interrupts: Vec<Interrupt>) -> Self {
10964
self.core_interrupts = Some(core_interrupts);
@@ -125,9 +80,6 @@ impl RiscvBuilder {
12580
/// Validate and build a [`Riscv`].
12681
pub fn build(self, lvl: ValidateLevel) -> Result<Riscv, SvdError> {
12782
let riscv = Riscv {
128-
clic: self.clic,
129-
clint: self.clint,
130-
plic: self.plic,
13183
core_interrupts: self
13284
.core_interrupts
13385
.ok_or_else(|| BuildError::Uninitialized("core_interrupts".to_string()))?,
@@ -155,15 +107,6 @@ impl Riscv {
155107
builder: RiscvBuilder,
156108
lvl: ValidateLevel,
157109
) -> Result<(), SvdError> {
158-
if builder.clic.is_some() {
159-
self.clic = builder.clic;
160-
}
161-
if builder.clint.is_some() {
162-
self.clint = builder.clint;
163-
}
164-
if builder.plic.is_some() {
165-
self.plic = builder.plic;
166-
}
167110
if let Some(core_interrupts) = builder.core_interrupts {
168111
self.core_interrupts = core_interrupts;
169112
}

tests/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ edition = "2021"
77
version = "0.12.0"
88
publish = false
99

10+
[features]
11+
unstable-riscv = ["svd-rs/unstable-riscv", "svd-parser/unstable-riscv", "svd-encoder/unstable-riscv"]
12+
1013
[dependencies]
1114
svd-rs = { path = "../svd-rs"}
1215
svd-parser = { path = "../svd-parser"}

tests/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,5 @@ mod register;
6262
mod usage;
6363
mod writeconstraint;
6464

65+
#[cfg(feature = "unstable-riscv")]
6566
mod riscv;

tests/src/riscv.rs

-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::vec;
2-
31
use super::run_test;
42
use crate::svd::{
53
riscv::{Hart, Priority, Riscv},
@@ -89,17 +87,13 @@ fn decode_encode() {
8987

9088
let tests = vec![(
9189
Riscv::builder()
92-
.clint(Some("CLINT".to_string()))
93-
.plic(Some("PLIC".to_string()))
9490
.core_interrupts(interrupts)
9591
.priorities(priorities)
9692
.harts(harts)
9793
.build(ValidateLevel::Strict)
9894
.unwrap(),
9995
"
10096
<riscv>
101-
<clint>CLINT</clint>
102-
<plic>PLIC</plic>
10397
<coreInterrupts>
10498
<interrupt>
10599
<name>MachineSoft</name>
@@ -170,8 +164,6 @@ fn decode_encode() {
170164
",
171165
"
172166
<riscv>
173-
<clint>CLINT</clint>
174-
<plic>PLIC</plic>
175167
<coreInterrupts>
176168
<interrupt>
177169
<name>MachineSoft</name>

0 commit comments

Comments
 (0)