Skip to content

Commit 6d38138

Browse files
felipebalbiDirbaio
authored andcommitted
Make fpu-present optional
fpuPresent is an optional parameter in the CPU section. Encode it as such in order to parse more SVD files. Signed-off-by: Felipe Balbi <[email protected]>
1 parent cb49fd6 commit 6d38138

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

svd-encoder/src/cpu.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ impl Encode for Cpu {
1010
new_node("revision", self.revision.clone()),
1111
self.endian.encode_node()?,
1212
new_node("mpuPresent", format!("{}", self.mpu_present)),
13-
new_node("fpuPresent", format!("{}", self.fpu_present)),
1413
];
14+
if let Some(v) = &self.fpu_present {
15+
children.push(new_node("fpuPresent", format!("{}", v)));
16+
}
1517
if let Some(v) = &self.fpu_double_precision {
1618
children.push(new_node("fpuDP", format!("{}", v)));
1719
}

svd-parser/src/cpu.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ impl Parse for Cpu {
1717
.revision(tree.get_child_text("revision")?)
1818
.endian(Endian::parse(&tree.get_child_elem("endian")?, config)?)
1919
.mpu_present(tree.get_child_bool("mpuPresent")?)
20-
.fpu_present(tree.get_child_bool("fpuPresent")?)
20+
.fpu_present(optional::<BoolParse>("fpuPresent", tree, &())?)
2121
.fpu_double_precision(optional::<BoolParse>("fpuDP", tree, &())?)
2222
.dsp_present(optional::<BoolParse>("dspPresent", tree, &())?)
2323
.icache_present(optional::<BoolParse>("icachePresent", tree, &())?)

svd-rs/src/cpu.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,15 @@ pub struct Cpu {
2121
pub mpu_present: bool,
2222

2323
/// Indicate whether the processor is equipped with a hardware floating point unit (FPU)
24-
pub fpu_present: bool,
24+
#[cfg_attr(
25+
feature = "serde",
26+
serde(
27+
default,
28+
skip_serializing_if = "Option::is_none",
29+
rename = "fpuPresent"
30+
)
31+
)]
32+
pub fpu_present: Option<bool>,
2533

2634
/// Indicate whether the processor is equipped with a double precision floating point unit.
2735
/// This element is valid only when `fpu_present` is set to `true`
@@ -126,7 +134,7 @@ impl From<Cpu> for CpuBuilder {
126134
revision: Some(c.revision),
127135
endian: Some(c.endian),
128136
mpu_present: Some(c.mpu_present),
129-
fpu_present: Some(c.fpu_present),
137+
fpu_present: c.fpu_present,
130138
fpu_double_precision: c.fpu_double_precision,
131139
dsp_present: c.dsp_present,
132140
icache_present: c.icache_present,
@@ -164,8 +172,8 @@ impl CpuBuilder {
164172
self
165173
}
166174
/// Set the fpu_present of the cpu.
167-
pub fn fpu_present(mut self, value: bool) -> Self {
168-
self.fpu_present = Some(value);
175+
pub fn fpu_present(mut self, value: Option<bool>) -> Self {
176+
self.fpu_present = value;
169177
self
170178
}
171179
/// Set the fpu_double_precision of the cpu.
@@ -238,9 +246,7 @@ impl CpuBuilder {
238246
mpu_present: self
239247
.mpu_present
240248
.ok_or_else(|| BuildError::Uninitialized("mpu_present".to_string()))?,
241-
fpu_present: self
242-
.fpu_present
243-
.ok_or_else(|| BuildError::Uninitialized("fpu_present".to_string()))?,
249+
fpu_present: self.fpu_present,
244250
fpu_double_precision: self.fpu_double_precision,
245251
dsp_present: self.dsp_present,
246252
icache_present: self.icache_present,
@@ -281,8 +287,8 @@ impl Cpu {
281287
if let Some(mpu_present) = builder.mpu_present {
282288
self.mpu_present = mpu_present;
283289
}
284-
if let Some(fpu_present) = builder.fpu_present {
285-
self.fpu_present = fpu_present;
290+
if builder.fpu_present.is_some() {
291+
self.fpu_present = builder.fpu_present;
286292
}
287293
if builder.fpu_double_precision.is_some() {
288294
self.fpu_double_precision = builder.fpu_double_precision;

0 commit comments

Comments
 (0)