-
Notifications
You must be signed in to change notification settings - Fork 59
Add riscv
section for RISC-V targets
#265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,79 @@ | ||
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 let Some(clic) = &self.clic { | ||
elem.children.push(new_node("clic", clic.clone())); | ||
} | ||
if let Some(clint) = &self.clint { | ||
elem.children.push(new_node("clint", clint.clone())); | ||
} | ||
if let Some(plic) = &self.plic { | ||
elem.children.push(new_node("plic", plic.clone())); | ||
} | ||
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,88 @@ | ||
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() | ||
.clic(tree.get_child_text("clic").ok()) | ||
.clint(tree.get_child_text("clint").ok()) | ||
.plic(tree.get_child_text("plic").ok()); | ||
|
||
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 hidden or 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 hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.