|
| 1 | +use super::*; |
| 2 | +use crate::svd::riscv::{Hart, Interrupt, Priority, Riscv}; |
| 3 | + |
| 4 | +impl Parse for Riscv { |
| 5 | + type Object = Self; |
| 6 | + type Error = SVDErrorAt; |
| 7 | + type Config = Config; |
| 8 | + |
| 9 | + fn parse(tree: &Node, config: &Config) -> Result<Self, Self::Error> { |
| 10 | + if !tree.has_tag_name("riscv") { |
| 11 | + return Err(SVDError::NotExpectedTag("riscv".to_string()).at(tree.id())); |
| 12 | + } |
| 13 | + |
| 14 | + let mut builder = Riscv::builder(); |
| 15 | + |
| 16 | + if let Some(interrupts) = tree.get_child("coreInterrupts") { |
| 17 | + let interrupts: Result<Vec<_>, _> = interrupts |
| 18 | + .children() |
| 19 | + .filter(|t| t.is_element() && t.has_tag_name("interrupt")) |
| 20 | + .map(|i| Interrupt::parse(&i, config)) |
| 21 | + .collect(); |
| 22 | + builder = builder.core_interrupts(interrupts?); |
| 23 | + } |
| 24 | + |
| 25 | + if let Some(priorities) = tree.get_child("priorities") { |
| 26 | + let priorities: Result<Vec<_>, _> = priorities |
| 27 | + .children() |
| 28 | + .filter(|t| t.is_element() && t.has_tag_name("priority")) |
| 29 | + .map(|i| Priority::parse(&i, config)) |
| 30 | + .collect(); |
| 31 | + builder = builder.priorities(priorities?); |
| 32 | + }; |
| 33 | + |
| 34 | + if let Some(harts) = tree.get_child("harts") { |
| 35 | + let harts: Result<Vec<_>, _> = harts |
| 36 | + .children() |
| 37 | + .filter(|t| t.is_element() && t.has_tag_name("hart")) |
| 38 | + .map(|i| Hart::parse(&i, config)) |
| 39 | + .collect(); |
| 40 | + builder = builder.harts(harts?); |
| 41 | + }; |
| 42 | + |
| 43 | + builder |
| 44 | + .build(config.validate_level) |
| 45 | + .map_err(|e| SVDError::from(e).at(tree.id())) |
| 46 | + } |
| 47 | +} |
| 48 | + |
| 49 | +impl Parse for Priority { |
| 50 | + type Object = Self; |
| 51 | + type Error = SVDErrorAt; |
| 52 | + type Config = Config; |
| 53 | + |
| 54 | + fn parse(tree: &Node, config: &Config) -> Result<Self, Self::Error> { |
| 55 | + if !tree.has_tag_name("priority") { |
| 56 | + return Err(SVDError::NotExpectedTag("priority".to_string()).at(tree.id())); |
| 57 | + } |
| 58 | + |
| 59 | + Priority::builder() |
| 60 | + .name(tree.get_child_text("name")?) |
| 61 | + .description(tree.get_child_text_opt("description")?) |
| 62 | + .value(tree.get_child_u32("value")?) |
| 63 | + .build(config.validate_level) |
| 64 | + .map_err(|e| SVDError::from(e).at(tree.id())) |
| 65 | + } |
| 66 | +} |
| 67 | + |
| 68 | +impl Parse for Hart { |
| 69 | + type Object = Self; |
| 70 | + type Error = SVDErrorAt; |
| 71 | + type Config = Config; |
| 72 | + |
| 73 | + fn parse(tree: &Node, config: &Config) -> Result<Self, Self::Error> { |
| 74 | + if !tree.has_tag_name("hart") { |
| 75 | + return Err(SVDError::NotExpectedTag("hart".to_string()).at(tree.id())); |
| 76 | + } |
| 77 | + |
| 78 | + Hart::builder() |
| 79 | + .name(tree.get_child_text("name")?) |
| 80 | + .description(tree.get_child_text_opt("description")?) |
| 81 | + .value(tree.get_child_u32("value")?) |
| 82 | + .build(config.validate_level) |
| 83 | + .map_err(|e| SVDError::from(e).at(tree.id())) |
| 84 | + } |
| 85 | +} |
0 commit comments