Skip to content

Commit

Permalink
core_interrupts, exceptions, and priorities are optional
Browse files Browse the repository at this point in the history
  • Loading branch information
romancardenas committed Aug 20, 2024
1 parent a95c627 commit fcce3e5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
6 changes: 3 additions & 3 deletions svd-parser/src/riscv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl Parse for Riscv {
.map(|i| Exception::parse(&i, config))
.collect();
builder = builder.exceptions(exceptions?);
};
}

if let Some(priorities) = tree.get_child("priorities") {
let priorities: Result<Vec<_>, _> = priorities
Expand All @@ -38,7 +38,7 @@ impl Parse for Riscv {
.map(|i| Priority::parse(&i, config))
.collect();
builder = builder.priorities(priorities?);
};
}

if let Some(harts) = tree.get_child("harts") {
let harts: Result<Vec<_>, _> = harts
Expand All @@ -47,7 +47,7 @@ impl Parse for Riscv {
.map(|i| Hart::parse(&i, config))
.collect();
builder = builder.harts(harts?);
};
}

builder
.build(config.validate_level)
Expand Down
21 changes: 12 additions & 9 deletions svd-rs/src/riscv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,18 @@ impl RiscvBuilder {
/// Validate and build a [`Riscv`].
pub fn build(self, lvl: ValidateLevel) -> Result<Riscv, SvdError> {
let riscv = Riscv {
core_interrupts: self
.core_interrupts
.ok_or_else(|| BuildError::Uninitialized("core_interrupts".to_string()))?,
exceptions: self
.exceptions
.ok_or_else(|| BuildError::Uninitialized("exceptions".to_string()))?,
priorities: self
.priorities
.ok_or_else(|| BuildError::Uninitialized("priorities".to_string()))?,
core_interrupts: match self.core_interrupts {
Some(core_interrupts) => core_interrupts,
None => Vec::new(),
},
exceptions: match self.exceptions {
Some(exceptions) => exceptions,
None => Vec::new(),
},
priorities: match self.priorities {
Some(priorities) => priorities,
None => Vec::new(),
},
harts: self
.harts
.ok_or_else(|| BuildError::Uninitialized("harts".to_string()))?,
Expand Down

0 comments on commit fcce3e5

Please sign in to comment.