Skip to content

Commit

Permalink
derive array
Browse files Browse the repository at this point in the history
  • Loading branch information
burrbull committed Jan 2, 2025
1 parent 569e544 commit dcaf59e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 13 deletions.
21 changes: 15 additions & 6 deletions src/patch/peripheral.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,10 @@ pub(crate) trait RegisterBlockExt: Name {
/// Update all derivedFrom referencing rname
fn derive_register(&mut self, rspec: &str, rderive: &Yaml, bpath: &BlockPath) -> PatchResult {
let (rspec, ignore) = rspec.spec();
let (rderive, info) = if let Some(rderive) = rderive.as_str() {
let (rderive, dim, info) = if let Some(rderive) = rderive.as_str() {
(
rderive,
None,
RegisterInfo::builder().derived_from(Some(rderive.into())),
)
} else if let Some(hash) = rderive.as_hash() {
Expand All @@ -259,6 +260,7 @@ pub(crate) trait RegisterBlockExt: Name {
})?;
(
rderive,
make_dim_element(hash)?,
make_register(hash, Some(bpath))?.derived_from(Some(rderive.into())),
)
} else {
Expand All @@ -281,14 +283,21 @@ pub(crate) trait RegisterBlockExt: Name {
let rtags = self.iter_registers(rspec).collect::<Vec<_>>();
let mut found = Vec::new();
if !rtags.is_empty() {
for register in rtags {
found.push(register.name.to_string());
register.modify_from(info.clone(), VAL_LVL)?;
for rtag in rtags {
found.push(rtag.name.to_string());
modify_dim_element(rtag, &dim)?;
rtag.modify_from(info.clone(), VAL_LVL)?;
}
} else if !ignore {
super::check_dimable_name(rspec)?;
let register = info.name(rspec.into()).build(VAL_LVL)?.single();
self.add_child(RegisterCluster::Register(register));
let reg = info.name(rspec.into()).build(VAL_LVL)?;
self.add_child(RegisterCluster::Register({
if let Some(dim) = dim {
reg.array(dim.build(VAL_LVL)?)
} else {
reg.single()
}
}));
}
for rname in found {
for r in self
Expand Down
27 changes: 20 additions & 7 deletions src/patch/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,25 +369,38 @@ impl RegisterExt for Register {
}
}
let (fspec, ignore) = fspec.spec();
let info = if let Some(dpath) = fderive.as_str() {
FieldInfo::builder().derived_from(Some(make_path(dpath, rpath)))
let (dim, info) = if let Some(dpath) = fderive.as_str() {
(
None,
FieldInfo::builder().derived_from(Some(make_path(dpath, rpath))),
)
} else if let Some(hash) = fderive.as_hash() {
let dpath = hash.get_str("_from")?.ok_or_else(|| {
anyhow!("derive: source field not given, please add a _from field to {fspec}")
})?;
make_field(hash, Some(rpath))?.derived_from(Some(make_path(dpath, rpath)))
(
make_dim_element(hash)?,
make_field(hash, Some(rpath))?.derived_from(Some(make_path(dpath, rpath))),
)
} else {
return Err(anyhow!("derive: incorrect syntax for {fspec}"));
};
let ftags = self.iter_fields(fspec).collect::<Vec<_>>();
if !ftags.is_empty() {
for field in ftags {
field.modify_from(info.clone(), VAL_LVL)?;
for ftag in ftags {
modify_dim_element(ftag, &dim)?;
ftag.modify_from(info.clone(), VAL_LVL)?;
}
} else if !ignore {
super::check_dimable_name(fspec)?;
let field = info.name(fspec.into()).build(VAL_LVL)?.single();
self.fields.get_or_insert(Vec::new()).push(field);
let field = info.name(fspec.into()).build(VAL_LVL)?;
self.fields.get_or_insert(Vec::new()).push({
if let Some(dim) = dim {
field.array(dim.build(VAL_LVL)?)
} else {
field.single()
}
});
}
Ok(())
}
Expand Down

0 comments on commit dcaf59e

Please sign in to comment.