svd_parser/
register.rs

1use super::*;
2use crate::svd::{
3    DataType, Field, ModifiedWriteValues, ReadAction, Register, RegisterInfo, RegisterProperties,
4    WriteConstraint,
5};
6
7impl Parse for Register {
8    type Object = Self;
9    type Error = SVDErrorAt;
10    type Config = Config;
11
12    fn parse(tree: &Node, config: &Self::Config) -> Result<Self, Self::Error> {
13        parse_array("register", tree, config)
14    }
15}
16
17impl Parse for RegisterInfo {
18    type Object = Self;
19    type Error = SVDErrorAt;
20    type Config = Config;
21
22    fn parse(tree: &Node, config: &Self::Config) -> Result<Self, Self::Error> {
23        RegisterInfo::builder()
24            .name(tree.get_child_text("name")?)
25            .display_name(tree.get_child_text_opt("displayName")?)
26            .description(tree.get_child_text_opt("description")?)
27            .alternate_group(tree.get_child_text_opt("alternateGroup")?)
28            .alternate_register(tree.get_child_text_opt("alternateRegister")?)
29            .address_offset(tree.get_child_u32("addressOffset")?)
30            .properties(RegisterProperties::parse(tree, config)?)
31            .datatype(optional::<DataType>("dataType", tree, config)?)
32            .modified_write_values(optional::<ModifiedWriteValues>(
33                "modifiedWriteValues",
34                tree,
35                config,
36            )?)
37            .write_constraint(optional::<WriteConstraint>(
38                "writeConstraint",
39                tree,
40                config,
41            )?)
42            .read_action(optional::<ReadAction>("readAction", tree, config)?)
43            .fields({
44                if let Some(fields) = tree.get_child("fields") {
45                    let fs: Result<Vec<_>, _> = fields
46                        .children()
47                        .filter(Node::is_element)
48                        .map(|t| Field::parse(&t, config))
49                        .collect();
50                    Some(fs?)
51                } else {
52                    None
53                }
54            })
55            .derived_from(tree.attribute("derivedFrom").map(|s| s.to_owned()))
56            .build(config.validate_level)
57            .map_err(|e| SVDError::from(e).at(tree.id()))
58    }
59}