-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #265 from romancardenas/master
Add `riscv` section for RISC-V targets
- Loading branch information
Showing
20 changed files
with
827 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
use super::{new_node, Config, Element, Encode, EncodeError, XMLNode}; | ||
use crate::svd::riscv::{Hart, Priority, Riscv}; | ||
|
||
impl Encode for Riscv { | ||
type Error = EncodeError; | ||
|
||
fn encode_with_config(&self, config: &Config) -> Result<Element, EncodeError> { | ||
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.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 Priority { | ||
type Error = EncodeError; | ||
|
||
fn encode_with_config(&self, _config: &Config) -> Result<Element, EncodeError> { | ||
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<Element, EncodeError> { | ||
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
use super::*; | ||
use crate::svd::riscv::{Hart, Interrupt, Priority, Riscv}; | ||
|
||
impl Parse for Riscv { | ||
type Object = Self; | ||
type Error = SVDErrorAt; | ||
type Config = Config; | ||
|
||
fn parse(tree: &Node, config: &Config) -> Result<Self, Self::Error> { | ||
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<Vec<_>, _> = 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(priorities) = tree.get_child("priorities") { | ||
let priorities: Result<Vec<_>, _> = 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<Vec<_>, _> = 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 Priority { | ||
type Object = Self; | ||
type Error = SVDErrorAt; | ||
type Config = Config; | ||
|
||
fn parse(tree: &Node, config: &Config) -> Result<Self, Self::Error> { | ||
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<Self, Self::Error> { | ||
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())) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.