diff --git a/svd-encoder/CHANGELOG.md b/svd-encoder/CHANGELOG.md index f07d822f..02e08706 100644 --- a/svd-encoder/CHANGELOG.md +++ b/svd-encoder/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## Unreleased +- Revert the `riscv` element, as well as the `unstable-riscv` feature. + ## [v0.14.5] - 2023-08-20 - Adapt the `riscv` element to handle `riscv::Exception`. diff --git a/svd-encoder/Cargo.toml b/svd-encoder/Cargo.toml index 7d07e49d..52486ab8 100644 --- a/svd-encoder/Cargo.toml +++ b/svd-encoder/Cargo.toml @@ -11,9 +11,6 @@ rust-version = "1.65.0" version = "0.14.5" readme = "README.md" -[features] -unstable-riscv = ["svd-rs/unstable-riscv"] - [dependencies] convert_case = "0.6.0" svd-rs = { version = "0.14.9", path = "../svd-rs" } diff --git a/svd-encoder/src/device.rs b/svd-encoder/src/device.rs index 8341f446..378e6536 100644 --- a/svd-encoder/src/device.rs +++ b/svd-encoder/src/device.rs @@ -34,12 +34,6 @@ impl Encode for Device { elem.children.push(new_node("licenseText", v.clone())); } - #[cfg(feature = "unstable-riscv")] - if let Some(v) = &self.riscv { - elem.children - .push(XMLNode::Element(v.encode_with_config(config)?)); - } - if let Some(v) = &self.cpu { elem.children .push(XMLNode::Element(v.encode_with_config(config)?)); diff --git a/svd-encoder/src/lib.rs b/svd-encoder/src/lib.rs index 88d750e3..7f531426 100644 --- a/svd-encoder/src/lib.rs +++ b/svd-encoder/src/lib.rs @@ -103,7 +103,5 @@ mod readaction; mod register; mod registercluster; mod registerproperties; -#[cfg(feature = "unstable-riscv")] -mod riscv; mod usage; mod writeconstraint; diff --git a/svd-encoder/src/riscv.rs b/svd-encoder/src/riscv.rs deleted file mode 100644 index 0047a9fe..00000000 --- a/svd-encoder/src/riscv.rs +++ /dev/null @@ -1,95 +0,0 @@ -use super::{new_node, Config, Element, Encode, EncodeError, XMLNode}; -use crate::svd::riscv::{Exception, Hart, Priority, Riscv}; - -impl Encode for Riscv { - type Error = EncodeError; - - fn encode_with_config(&self, config: &Config) -> Result { - let mut elem = Element::new("riscv"); - - if !self.core_interrupts.is_empty() { - let mut interrupts = Element::new("coreInterrupts"); - for interrupt in &self.core_interrupts { - interrupts - .children - .push(interrupt.encode_node_with_config(config)?); - } - elem.children.push(XMLNode::Element(interrupts)); - } - if !self.exceptions.is_empty() { - let mut exceptions = Element::new("exceptions"); - for exception in &self.exceptions { - exceptions - .children - .push(exception.encode_node_with_config(config)?); - } - elem.children.push(XMLNode::Element(exceptions)); - } - if !self.priorities.is_empty() { - let mut priorities = Element::new("priorities"); - for priority in &self.priorities { - priorities - .children - .push(priority.encode_node_with_config(config)?); - } - elem.children.push(XMLNode::Element(priorities)); - } - if !self.harts.is_empty() { - let mut harts = Element::new("harts"); - for hart in &self.harts { - harts.children.push(hart.encode_node_with_config(config)?); - } - elem.children.push(XMLNode::Element(harts)); - } - - Ok(elem) - } -} - -impl Encode for Exception { - type Error = EncodeError; - - fn encode_with_config(&self, _config: &Config) -> Result { - let mut children = vec![new_node("name", self.name.clone())]; - if let Some(desc) = &self.description { - children.push(new_node("description", desc.clone())); - } - children.push(new_node("value", format!("{}", self.value))); - - let mut elem = Element::new("exception"); - elem.children = children; - Ok(elem) - } -} - -impl Encode for Priority { - type Error = EncodeError; - - fn encode_with_config(&self, _config: &Config) -> Result { - let mut children = vec![new_node("name", self.name.clone())]; - if let Some(desc) = &self.description { - children.push(new_node("description", desc.clone())); - } - children.push(new_node("value", format!("{}", self.value))); - - let mut elem = Element::new("priority"); - elem.children = children; - Ok(elem) - } -} - -impl Encode for Hart { - type Error = EncodeError; - - fn encode_with_config(&self, _config: &Config) -> Result { - let mut children = vec![new_node("name", self.name.clone())]; - if let Some(desc) = &self.description { - children.push(new_node("description", desc.clone())); - } - children.push(new_node("value", format!("{}", self.value))); - - let mut elem = Element::new("hart"); - elem.children = children; - Ok(elem) - } -} diff --git a/svd-parser/CHANGELOG.md b/svd-parser/CHANGELOG.md index a2773dfd..572d79cd 100644 --- a/svd-parser/CHANGELOG.md +++ b/svd-parser/CHANGELOG.md @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## Unreleased + +- Revert the `riscv` element, as well as the `unstable-riscv` feature. + ## [v0.14.7] - 2024-10-03 - Bump svd-rs to 0.14.9 diff --git a/svd-parser/Cargo.toml b/svd-parser/Cargo.toml index aed85fb7..3531c188 100644 --- a/svd-parser/Cargo.toml +++ b/svd-parser/Cargo.toml @@ -17,7 +17,6 @@ readme = "README.md" [features] derive-from = ["svd-rs/derive-from"] expand = ["derive-from"] -unstable-riscv = ["svd-rs/unstable-riscv"] [dependencies] svd-rs = { version = "0.14.9", path = "../svd-rs" } diff --git a/svd-parser/src/device.rs b/svd-parser/src/device.rs index 701055fc..32ec8d07 100644 --- a/svd-parser/src/device.rs +++ b/svd-parser/src/device.rs @@ -1,6 +1,4 @@ use super::*; -#[cfg(feature = "unstable-riscv")] -use crate::svd::riscv::Riscv; use crate::svd::{cpu::Cpu, peripheral::Peripheral, registerproperties::RegisterProperties}; /// Parses a SVD file @@ -33,10 +31,6 @@ impl Parse for Device { .collect(); ps? }); - #[cfg(feature = "unstable-riscv")] - if let Some(riscv) = optional::("riscv", tree, config)? { - device = device.riscv(riscv); - } if let Some(version) = tree.get_child_text_opt("version")? { device = device.version(version) } diff --git a/svd-parser/src/lib.rs b/svd-parser/src/lib.rs index e3718ed6..b3d22c6d 100644 --- a/svd-parser/src/lib.rs +++ b/svd-parser/src/lib.rs @@ -211,8 +211,6 @@ mod readaction; mod register; mod registercluster; mod registerproperties; -#[cfg(feature = "unstable-riscv")] -mod riscv; mod usage; mod writeconstraint; diff --git a/svd-parser/src/riscv.rs b/svd-parser/src/riscv.rs deleted file mode 100644 index b04457f1..00000000 --- a/svd-parser/src/riscv.rs +++ /dev/null @@ -1,113 +0,0 @@ -use super::*; -use crate::svd::riscv::{Exception, Hart, Interrupt, Priority, Riscv}; - -impl Parse for Riscv { - type Object = Self; - type Error = SVDErrorAt; - type Config = Config; - - fn parse(tree: &Node, config: &Config) -> Result { - if !tree.has_tag_name("riscv") { - return Err(SVDError::NotExpectedTag("riscv".to_string()).at(tree.id())); - } - - let mut builder = Riscv::builder(); - - if let Some(interrupts) = tree.get_child("coreInterrupts") { - let interrupts: Result, _> = interrupts - .children() - .filter(|t| t.is_element() && t.has_tag_name("interrupt")) - .map(|i| Interrupt::parse(&i, config)) - .collect(); - builder = builder.core_interrupts(interrupts?); - } - - if let Some(exceptions) = tree.get_child("exceptions") { - let exceptions: Result, _> = exceptions - .children() - .filter(|t| t.is_element() && t.has_tag_name("exception")) - .map(|i| Exception::parse(&i, config)) - .collect(); - builder = builder.exceptions(exceptions?); - } - - if let Some(priorities) = tree.get_child("priorities") { - let priorities: Result, _> = priorities - .children() - .filter(|t| t.is_element() && t.has_tag_name("priority")) - .map(|i| Priority::parse(&i, config)) - .collect(); - builder = builder.priorities(priorities?); - } - - if let Some(harts) = tree.get_child("harts") { - let harts: Result, _> = harts - .children() - .filter(|t| t.is_element() && t.has_tag_name("hart")) - .map(|i| Hart::parse(&i, config)) - .collect(); - builder = builder.harts(harts?); - } - - builder - .build(config.validate_level) - .map_err(|e| SVDError::from(e).at(tree.id())) - } -} - -impl Parse for Exception { - type Object = Self; - type Error = SVDErrorAt; - type Config = Config; - - fn parse(tree: &Node, config: &Config) -> Result { - if !tree.has_tag_name("exception") { - return Err(SVDError::NotExpectedTag("exception".to_string()).at(tree.id())); - } - - Exception::builder() - .name(tree.get_child_text("name")?) - .description(tree.get_child_text_opt("description")?) - .value(tree.get_child_u32("value")?) - .build(config.validate_level) - .map_err(|e| SVDError::from(e).at(tree.id())) - } -} - -impl Parse for Priority { - type Object = Self; - type Error = SVDErrorAt; - type Config = Config; - - fn parse(tree: &Node, config: &Config) -> Result { - if !tree.has_tag_name("priority") { - return Err(SVDError::NotExpectedTag("priority".to_string()).at(tree.id())); - } - - Priority::builder() - .name(tree.get_child_text("name")?) - .description(tree.get_child_text_opt("description")?) - .value(tree.get_child_u32("value")?) - .build(config.validate_level) - .map_err(|e| SVDError::from(e).at(tree.id())) - } -} - -impl Parse for Hart { - type Object = Self; - type Error = SVDErrorAt; - type Config = Config; - - fn parse(tree: &Node, config: &Config) -> Result { - if !tree.has_tag_name("hart") { - return Err(SVDError::NotExpectedTag("hart".to_string()).at(tree.id())); - } - - Hart::builder() - .name(tree.get_child_text("name")?) - .description(tree.get_child_text_opt("description")?) - .value(tree.get_child_u32("value")?) - .build(config.validate_level) - .map_err(|e| SVDError::from(e).at(tree.id())) - } -} diff --git a/svd-rs/CHANGELOG.md b/svd-rs/CHANGELOG.md index ad181880..c8af63fd 100644 --- a/svd-rs/CHANGELOG.md +++ b/svd-rs/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## Unreleased +- Revert the `riscv` elements, as well as the `unstable-riscv` feature. + ## [v0.14.9] - 2024-08-20 - Add `riscv::Exception` for custom exception source enumerations. diff --git a/svd-rs/Cargo.toml b/svd-rs/Cargo.toml index 9c0248ae..88b2362d 100644 --- a/svd-rs/Cargo.toml +++ b/svd-rs/Cargo.toml @@ -15,7 +15,6 @@ readme = "README.md" [features] derive-from = [] -unstable-riscv = [] [dependencies] thiserror = "1.0.31" diff --git a/svd-rs/src/device.rs b/svd-rs/src/device.rs index d7f9b0a8..aa9d4439 100644 --- a/svd-rs/src/device.rs +++ b/svd-rs/src/device.rs @@ -1,5 +1,3 @@ -#[cfg(feature = "unstable-riscv")] -use super::Riscv; use super::{ BuildError, Cpu, Description, EmptyToNone, Name, Peripheral, RegisterProperties, SvdError, ValidateLevel, @@ -107,14 +105,6 @@ pub struct Device { /// Specify the compliant CMSIS-SVD schema version #[cfg_attr(feature = "serde", serde(skip, default = "default_schema_version"))] pub schema_version: String, - - /// Describe the processor included in the device - #[cfg_attr( - feature = "serde", - serde(default, skip_serializing_if = "Option::is_none") - )] - #[cfg(feature = "unstable-riscv")] - pub riscv: Option, } fn default_xmlns_xs() -> String { @@ -140,8 +130,6 @@ pub struct DeviceBuilder { version: Option, description: Option, license_text: Option, - #[cfg(feature = "unstable-riscv")] - riscv: Option, cpu: Option, header_system_filename: Option, header_definitions_prefix: Option, @@ -164,8 +152,6 @@ impl From for DeviceBuilder { version: Some(d.version), description: Some(d.description), license_text: d.license_text, - #[cfg(feature = "unstable-riscv")] - riscv: d.riscv, cpu: d.cpu, header_system_filename: d.header_system_filename, header_definitions_prefix: d.header_definitions_prefix, @@ -216,12 +202,6 @@ impl DeviceBuilder { self.license_text = value; self } - /// Set the riscv of the device. - #[cfg(feature = "unstable-riscv")] - pub fn riscv(mut self, value: Riscv) -> Self { - self.riscv = Some(value); - self - } /// Set the cpu of the device. pub fn cpu(mut self, value: Option) -> Self { self.cpu = value; @@ -303,8 +283,6 @@ impl DeviceBuilder { }) .ok_or_else(|| BuildError::Uninitialized("description".to_string()))?, license_text: self.license_text, - #[cfg(feature = "unstable-riscv")] - riscv: self.riscv, cpu: self.cpu, header_system_filename: self.header_system_filename, header_definitions_prefix: self.header_definitions_prefix, @@ -363,10 +341,6 @@ impl Device { if builder.license_text.is_some() { self.license_text = builder.license_text.empty_to_none(); } - #[cfg(feature = "unstable-riscv")] - if builder.riscv.is_some() { - self.riscv = builder.riscv; - } if builder.cpu.is_some() { self.cpu = builder.cpu; } diff --git a/svd-rs/src/lib.rs b/svd-rs/src/lib.rs index ceaf9e54..fe895426 100644 --- a/svd-rs/src/lib.rs +++ b/svd-rs/src/lib.rs @@ -94,12 +94,6 @@ pub use self::protection::Protection; pub mod datatype; pub use self::datatype::DataType; -/// Custom objects for the RISC-V ecosystem -#[cfg(feature = "unstable-riscv")] -pub mod riscv; -#[cfg(feature = "unstable-riscv")] -pub use self::riscv::Riscv; - /// Level of validation #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum ValidateLevel { diff --git a/svd-rs/src/riscv.rs b/svd-rs/src/riscv.rs deleted file mode 100644 index a78589ad..00000000 --- a/svd-rs/src/riscv.rs +++ /dev/null @@ -1,173 +0,0 @@ -pub use super::Interrupt; -use super::{BuildError, SvdError, ValidateLevel}; - -/// Description of the custom exceptions in the device. -pub mod exception; -pub use exception::Exception; - -/// Description of HARTs in the device. -pub mod hart; -pub use hart::Hart; - -/// Description of interrupt priority levels in the device. -pub mod priority; -pub use priority::Priority; - -/// RISC-V specific descriptions. -#[cfg_attr( - feature = "serde", - derive(serde::Deserialize, serde::Serialize), - serde(rename_all = "camelCase") -)] -#[derive(Clone, Debug, PartialEq, Eq)] -#[non_exhaustive] -pub struct Riscv { - /// Core interrupt enumeration values - #[cfg_attr( - feature = "serde", - serde(default, skip_serializing_if = "Vec::is_empty") - )] - pub core_interrupts: Vec, - - /// Exception enumeration values - #[cfg_attr( - feature = "serde", - serde(default, skip_serializing_if = "Vec::is_empty") - )] - pub exceptions: Vec, - - /// Priority level enumeration values - #[cfg_attr( - feature = "serde", - serde(default, skip_serializing_if = "Vec::is_empty") - )] - pub priorities: Vec, - - /// HART enumeration values - #[cfg_attr( - feature = "serde", - serde(default, skip_serializing_if = "Vec::is_empty") - )] - pub harts: Vec, -} - -/// Builder for [`Riscv`] -#[derive(Clone, Debug, Default, PartialEq, Eq)] -pub struct RiscvBuilder { - core_interrupts: Option>, - exceptions: Option>, - priorities: Option>, - harts: Option>, -} - -impl From for RiscvBuilder { - fn from(riscv: Riscv) -> Self { - Self { - core_interrupts: Some(riscv.core_interrupts), - exceptions: Some(riscv.exceptions), - priorities: Some(riscv.priorities), - harts: Some(riscv.harts), - } - } -} - -impl RiscvBuilder { - /// Set the core interrupt enumeration values - pub fn core_interrupts(mut self, core_interrupts: Vec) -> Self { - self.core_interrupts = Some(core_interrupts); - self - } - - /// Set the exception enumeration values - pub fn exceptions(mut self, exceptions: Vec) -> Self { - self.exceptions = Some(exceptions); - self - } - - /// Set the priority level enumeration values - pub fn priorities(mut self, priorities: Vec) -> Self { - self.priorities = Some(priorities); - self - } - - /// Set the HART enumeration values - pub fn harts(mut self, harts: Vec) -> Self { - self.harts = Some(harts); - self - } - - /// Validate and build a [`Riscv`]. - pub fn build(self, lvl: ValidateLevel) -> Result { - let riscv = Riscv { - 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()))?, - }; - riscv.validate(lvl)?; - Ok(riscv) - } -} - -impl Riscv { - /// Make a builder for [`Riscv`] - pub fn builder() -> RiscvBuilder { - RiscvBuilder::default() - } - - /// Modify an existing [`Riscv`] based on a [builder](RiscvBuilder). - pub fn modify_from( - &mut self, - builder: RiscvBuilder, - lvl: ValidateLevel, - ) -> Result<(), SvdError> { - if let Some(core_interrupts) = builder.core_interrupts { - self.core_interrupts = core_interrupts; - } - if let Some(exceptions) = builder.exceptions { - self.exceptions = exceptions; - } - if let Some(priorities) = builder.priorities { - self.priorities = priorities; - } - if let Some(harts) = builder.harts { - self.harts = harts; - } - self.validate(lvl) - } - - /// Validate the [`Riscv`]. - /// - /// # Errors - /// - /// - If any of the core interrupt enumeration values are invalid - /// - If any of the exception enumeration values are invalid - /// - If any of the priority level enumeration values are invalid - /// - If any of the HART enumeration values are invalid - pub fn validate(&self, lvl: ValidateLevel) -> Result<(), SvdError> { - for ci in &self.core_interrupts { - ci.validate(lvl)?; - } - for e in &self.exceptions { - e.validate(lvl)?; - } - for p in &self.priorities { - p.validate(lvl)?; - } - for h in &self.harts { - h.validate(lvl)?; - } - Ok(()) - } -} diff --git a/svd-rs/src/riscv/exception.rs b/svd-rs/src/riscv/exception.rs deleted file mode 100644 index 24fcde70..00000000 --- a/svd-rs/src/riscv/exception.rs +++ /dev/null @@ -1,114 +0,0 @@ -use crate::{BuildError, Description, Name, SvdError, ValidateLevel}; - -/// Describes a exception source in the device -#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] -#[derive(Clone, Debug, PartialEq, Eq)] -#[non_exhaustive] -pub struct Exception { - /// The string represents the exception source name - pub name: String, - - /// The string describes the exception source - #[cfg_attr( - feature = "serde", - serde(default, skip_serializing_if = "Option::is_none") - )] - pub description: Option, - - /// Represents the enumeration index value associated to the exception source - pub value: u32, -} - -/// Builder for [`Exception`] -#[derive(Clone, Debug, Default, PartialEq, Eq)] -pub struct ExceptionBuilder { - name: Option, - description: Option, - value: Option, -} - -impl From for ExceptionBuilder { - fn from(d: Exception) -> Self { - Self { - name: Some(d.name), - description: d.description, - value: Some(d.value), - } - } -} - -impl ExceptionBuilder { - /// Set the name of the exception source - pub fn name(mut self, value: String) -> Self { - self.name = Some(value); - self - } - /// Set the description of the exception source - pub fn description(mut self, value: Option) -> Self { - self.description = value; - self - } - /// Set the value of the exception source - pub fn value(mut self, value: u32) -> Self { - self.value = Some(value); - self - } - /// Validate and build an [`Exception`]. - pub fn build(self, lvl: ValidateLevel) -> Result { - let de = Exception { - name: self - .name - .ok_or_else(|| BuildError::Uninitialized("name".to_string()))?, - description: self.description, - value: self - .value - .ok_or_else(|| BuildError::Uninitialized("value".to_string()))?, - }; - de.validate(lvl)?; - Ok(de) - } -} - -impl Exception { - /// Make a builder for [`Exception`] - pub fn builder() -> ExceptionBuilder { - ExceptionBuilder::default() - } - /// Modify an existing [`Exception`] based on a [builder](ExceptionBuilder). - pub fn modify_from( - &mut self, - builder: ExceptionBuilder, - lvl: ValidateLevel, - ) -> Result<(), SvdError> { - if let Some(name) = builder.name { - self.name = name; - } - if builder.description.is_some() { - self.description = builder.description; - } - if let Some(value) = builder.value { - self.value = value; - } - self.validate(lvl) - } - /// Validate the [`Exception`]. - /// - /// # Notes - /// - /// This doesn't do anything. - pub fn validate(&self, _lvl: ValidateLevel) -> Result<(), SvdError> { - Ok(()) - } -} - -impl Name for Exception { - fn name(&self) -> &str { - &self.name - } -} - -impl Description for Exception { - fn description(&self) -> Option<&str> { - self.description.as_deref() - } -} diff --git a/svd-rs/src/riscv/hart.rs b/svd-rs/src/riscv/hart.rs deleted file mode 100644 index 27e7ad09..00000000 --- a/svd-rs/src/riscv/hart.rs +++ /dev/null @@ -1,114 +0,0 @@ -use crate::{BuildError, Description, Name, SvdError, ValidateLevel}; - -/// Describes a HART ID in the device -#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] -#[derive(Clone, Debug, PartialEq, Eq)] -#[non_exhaustive] -pub struct Hart { - /// The string represents the HART ID - pub name: String, - - /// The string describes the HART ID - #[cfg_attr( - feature = "serde", - serde(default, skip_serializing_if = "Option::is_none") - )] - pub description: Option, - - /// Represents the enumeration index value associated to the HART ID - pub value: u32, -} - -/// Builder for [`Hart`] -#[derive(Clone, Debug, Default, PartialEq, Eq)] -pub struct HartBuilder { - name: Option, - description: Option, - value: Option, -} - -impl From for HartBuilder { - fn from(d: Hart) -> Self { - Self { - name: Some(d.name), - description: d.description, - value: Some(d.value), - } - } -} - -impl HartBuilder { - /// Set the name of the HART - pub fn name(mut self, value: String) -> Self { - self.name = Some(value); - self - } - /// Set the description of the HART - pub fn description(mut self, value: Option) -> Self { - self.description = value; - self - } - /// Set the value of the HART - pub fn value(mut self, value: u32) -> Self { - self.value = Some(value); - self - } - /// Validate and build a [`Hart`]. - pub fn build(self, lvl: ValidateLevel) -> Result { - let de = Hart { - name: self - .name - .ok_or_else(|| BuildError::Uninitialized("name".to_string()))?, - description: self.description, - value: self - .value - .ok_or_else(|| BuildError::Uninitialized("value".to_string()))?, - }; - de.validate(lvl)?; - Ok(de) - } -} - -impl Hart { - /// Make a builder for [`Hart`] - pub fn builder() -> HartBuilder { - HartBuilder::default() - } - /// Modify an existing [`Hart`] based on a [builder](HartBuilder). - pub fn modify_from( - &mut self, - builder: HartBuilder, - lvl: ValidateLevel, - ) -> Result<(), SvdError> { - if let Some(name) = builder.name { - self.name = name; - } - if builder.description.is_some() { - self.description = builder.description; - } - if let Some(value) = builder.value { - self.value = value; - } - self.validate(lvl) - } - /// Validate the [`Hart`]. - /// - /// # Notes - /// - /// This doesn't do anything. - pub fn validate(&self, _lvl: ValidateLevel) -> Result<(), SvdError> { - Ok(()) - } -} - -impl Name for Hart { - fn name(&self) -> &str { - &self.name - } -} - -impl Description for Hart { - fn description(&self) -> Option<&str> { - self.description.as_deref() - } -} diff --git a/svd-rs/src/riscv/priority.rs b/svd-rs/src/riscv/priority.rs deleted file mode 100644 index 80ab85ac..00000000 --- a/svd-rs/src/riscv/priority.rs +++ /dev/null @@ -1,114 +0,0 @@ -use crate::{BuildError, Description, Name, SvdError, ValidateLevel}; - -/// Describes a priority level in the device -#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] -#[derive(Clone, Debug, PartialEq, Eq)] -#[non_exhaustive] -pub struct Priority { - /// The string represents the priority level - pub name: String, - - /// The string describes the priority level - #[cfg_attr( - feature = "serde", - serde(default, skip_serializing_if = "Option::is_none") - )] - pub description: Option, - - /// Represents the enumeration index value associated to the priority level - pub value: u32, -} - -/// Builder for [`Priority`] -#[derive(Clone, Debug, Default, PartialEq, Eq)] -pub struct PriorityBuilder { - name: Option, - description: Option, - value: Option, -} - -impl From for PriorityBuilder { - fn from(d: Priority) -> Self { - Self { - name: Some(d.name), - description: d.description, - value: Some(d.value), - } - } -} - -impl PriorityBuilder { - /// Set the name of the priority level - pub fn name(mut self, value: String) -> Self { - self.name = Some(value); - self - } - /// Set the description of the priority level - pub fn description(mut self, value: Option) -> Self { - self.description = value; - self - } - /// Set the value of the priority level - pub fn value(mut self, value: u32) -> Self { - self.value = Some(value); - self - } - /// Validate and build a [`Priority`]. - pub fn build(self, lvl: ValidateLevel) -> Result { - let de = Priority { - name: self - .name - .ok_or_else(|| BuildError::Uninitialized("name".to_string()))?, - description: self.description, - value: self - .value - .ok_or_else(|| BuildError::Uninitialized("value".to_string()))?, - }; - de.validate(lvl)?; - Ok(de) - } -} - -impl Priority { - /// Make a builder for [`Priority`] - pub fn builder() -> PriorityBuilder { - PriorityBuilder::default() - } - /// Modify an existing [`Priority`] based on a [builder](PriorityBuilder). - pub fn modify_from( - &mut self, - builder: PriorityBuilder, - lvl: ValidateLevel, - ) -> Result<(), SvdError> { - if let Some(name) = builder.name { - self.name = name; - } - if builder.description.is_some() { - self.description = builder.description; - } - if let Some(value) = builder.value { - self.value = value; - } - self.validate(lvl) - } - /// Validate the [`Priority`]. - /// - /// # Notes - /// - /// This doesn't do anything. - pub fn validate(&self, _lvl: ValidateLevel) -> Result<(), SvdError> { - Ok(()) - } -} - -impl Name for Priority { - fn name(&self) -> &str { - &self.name - } -} - -impl Description for Priority { - fn description(&self) -> Option<&str> { - self.description.as_deref() - } -} diff --git a/tests/Cargo.toml b/tests/Cargo.toml index d45bbb57..c3d40fa8 100644 --- a/tests/Cargo.toml +++ b/tests/Cargo.toml @@ -7,9 +7,6 @@ edition = "2021" version = "0.12.0" publish = false -[features] -unstable-riscv = ["svd-rs/unstable-riscv", "svd-parser/unstable-riscv", "svd-encoder/unstable-riscv"] - [dependencies] svd-rs = { path = "../svd-rs"} svd-parser = { path = "../svd-parser"} diff --git a/tests/src/lib.rs b/tests/src/lib.rs index 7e0ed121..68f4a9dd 100644 --- a/tests/src/lib.rs +++ b/tests/src/lib.rs @@ -61,6 +61,3 @@ mod register; //mod registerproperties; mod usage; mod writeconstraint; - -#[cfg(feature = "unstable-riscv")] -mod riscv; diff --git a/tests/src/riscv.rs b/tests/src/riscv.rs deleted file mode 100644 index 8726b19f..00000000 --- a/tests/src/riscv.rs +++ /dev/null @@ -1,278 +0,0 @@ -use super::run_test; -use crate::svd::{ - riscv::{Exception, Hart, Priority, Riscv}, - Interrupt, ValidateLevel, -}; - -#[test] -fn decode_encode() { - let interrupts = vec![ - Interrupt::builder() - .name("MachineSoft".to_string()) - .description(Some("Machine Software Interrupt".to_string())) - .value(3) - .build(ValidateLevel::Strict) - .unwrap(), - Interrupt::builder() - .name("MachineTimer".to_string()) - .description(Some("Machine Timer Interrupt".to_string())) - .value(7) - .build(ValidateLevel::Strict) - .unwrap(), - Interrupt::builder() - .name("MachineExternal".to_string()) - .description(Some("Machine External Interrupt".to_string())) - .value(11) - .build(ValidateLevel::Strict) - .unwrap(), - ]; - - let exceptions = vec![ - Exception::builder() - .name("InstructionAddressMisaligned".to_string()) - .description(Some("Instruction Address Misaligned".to_string())) - .value(0) - .build(ValidateLevel::Strict) - .unwrap(), - Exception::builder() - .name("InstructionAccessFault".to_string()) - .description(Some("Instruction Access Fault".to_string())) - .value(1) - .build(ValidateLevel::Strict) - .unwrap(), - ]; - - let priorities = vec![ - Priority::builder() - .name("P0".to_string()) - .description(Some("Priority level 0".to_string())) - .value(0) - .build(ValidateLevel::Strict) - .unwrap(), - Priority::builder() - .name("P1".to_string()) - .description(Some("Priority level 1".to_string())) - .value(1) - .build(ValidateLevel::Strict) - .unwrap(), - Priority::builder() - .name("P2".to_string()) - .description(Some("Priority level 2".to_string())) - .value(2) - .build(ValidateLevel::Strict) - .unwrap(), - Priority::builder() - .name("P3".to_string()) - .description(Some("Priority level 3".to_string())) - .value(3) - .build(ValidateLevel::Strict) - .unwrap(), - Priority::builder() - .name("P4".to_string()) - .description(Some("Priority level 4".to_string())) - .value(4) - .build(ValidateLevel::Strict) - .unwrap(), - Priority::builder() - .name("P5".to_string()) - .description(Some("Priority level 5".to_string())) - .value(5) - .build(ValidateLevel::Strict) - .unwrap(), - Priority::builder() - .name("P6".to_string()) - .description(Some("Priority level 6".to_string())) - .value(6) - .build(ValidateLevel::Strict) - .unwrap(), - Priority::builder() - .name("P7".to_string()) - .description(Some("Priority level 7".to_string())) - .value(7) - .build(ValidateLevel::Strict) - .unwrap(), - ]; - - let harts = vec![Hart::builder() - .name("H0".to_string()) - .description(Some("Hart 0".to_string())) - .value(0) - .build(ValidateLevel::Strict) - .unwrap()]; - - let tests = vec![( - Riscv::builder() - .core_interrupts(interrupts) - .exceptions(exceptions) - .priorities(priorities) - .harts(harts) - .build(ValidateLevel::Strict) - .unwrap(), - " - - - - MachineSoft - Machine Software Interrupt - 3 - - - MachineTimer - Machine Timer Interrupt - 7 - - - MachineExternal - Machine External Interrupt - 11 - - - - - InstructionAddressMisaligned - Instruction Address Misaligned - 0 - - - InstructionAccessFault - Instruction Access Fault - 1 - - - - - P0 - Priority level 0 - 0 - - - P1 - Priority level 1 - 1 - - - P2 - Priority level 2 - 2 - - - P3 - Priority level 3 - 3 - - - P4 - Priority level 4 - 4 - - - P5 - Priority level 5 - 5 - - - P6 - Priority level 6 - 6 - - - P7 - Priority level 7 - 7 - - - - - H0 - Hart 0 - 0 - - - - ", - " - - - - MachineSoft - Machine Software Interrupt - 3 - - - MachineTimer - Machine Timer Interrupt - 7 - - - MachineExternal - Machine External Interrupt - 11 - - - - - InstructionAddressMisaligned - Instruction Address Misaligned - 0 - - - InstructionAccessFault - Instruction Access Fault - 1 - - - - - P0 - Priority level 0 - 0 - - - P1 - Priority level 1 - 1 - - - P2 - Priority level 2 - 2 - - - P3 - Priority level 3 - 3 - - - P4 - Priority level 4 - 4 - - - P5 - Priority level 5 - 5 - - - P6 - Priority level 6 - 6 - - - P7 - Priority level 7 - 7 - - - - - H0 - Hart 0 - 0 - - - - ", - )]; - - run_test::(&tests[..], None, None); -}