Skip to content

Commit 026d423

Browse files
committed
spec, mod, then path
1 parent 3eab47f commit 026d423

File tree

2 files changed

+32
-33
lines changed

2 files changed

+32
-33
lines changed

src/patch/peripheral.rs

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ pub(crate) trait RegisterBlockExt: Name {
198198

199199
/// Remove fields from rname and mark it as derivedFrom rderive.
200200
/// Update all derivedFrom referencing rname
201-
fn derive_register(&mut self, rname: &str, rderive: &Yaml) -> PatchResult {
201+
fn derive_register(&mut self, rname: &str, rderive: &Yaml, bpath: &BlockPath) -> PatchResult {
202202
let (rderive, info) = if let Some(rderive) = rderive.as_str() {
203203
(
204204
rderive,
@@ -217,10 +217,8 @@ pub(crate) trait RegisterBlockExt: Name {
217217
};
218218

219219
self.get_reg(rderive).ok_or_else(|| {
220-
anyhow!(
221-
"register {rderive} not found. Present registers: {}.`",
222-
self.present_registers()
223-
)
220+
let present = self.present_registers();
221+
anyhow!("Could not find `{bpath}:{rderive}. Present registers: {present}.")
224222
})?;
225223

226224
match self.get_mut_reg(rname) {
@@ -241,7 +239,7 @@ pub(crate) trait RegisterBlockExt: Name {
241239

242240
/// Remove fields from rname and mark it as derivedFrom rderive.
243241
/// Update all derivedFrom referencing rname
244-
fn derive_cluster(&mut self, _cname: &str, _cderive: &Yaml) -> PatchResult {
242+
fn derive_cluster(&mut self, _cname: &str, _cderive: &Yaml, _bpath: &BlockPath) -> PatchResult {
245243
todo!()
246244
}
247245

@@ -255,10 +253,10 @@ pub(crate) trait RegisterBlockExt: Name {
255253
.regs()
256254
.find(|r| r.name == srcname)
257255
.ok_or_else(|| {
256+
let present = self.present_registers();
258257
anyhow!(
259-
"{} {bpath} does not have register {srcname}. Present registers: {}.`",
258+
"{} {bpath} does not have register {srcname}. Present registers: {present}.`",
260259
Self::RB_TYPE,
261-
self.present_registers()
262260
)
263261
})?
264262
.clone();
@@ -277,7 +275,7 @@ pub(crate) trait RegisterBlockExt: Name {
277275
}
278276

279277
/// Add cname given by deriving from ccopy to ptag
280-
fn copy_cluster(&mut self, _rname: &str, _ccopy: &Hash) -> PatchResult {
278+
fn copy_cluster(&mut self, _rname: &str, _ccopy: &Hash, _bpath: &BlockPath) -> PatchResult {
281279
todo!()
282280
}
283281

@@ -326,7 +324,6 @@ pub(crate) trait RegisterBlockExt: Name {
326324
/// Work through a register, handling all fields
327325
fn process_register(
328326
&mut self,
329-
330327
rspec: &str,
331328
rmod: &Hash,
332329
bpath: &BlockPath,
@@ -656,7 +653,7 @@ impl PeripheralExt for Peripheral {
656653
for (cname, val) in rcopy.hash()? {
657654
let cname = cname.str()?;
658655
let ccopy = val.hash()?;
659-
self.copy_cluster(rname, ccopy)
656+
self.copy_cluster(rname, ccopy, &ppath)
660657
.with_context(|| format!("Copying cluster `{cname}` from `{val:?}`"))?;
661658
}
662659
}
@@ -754,23 +751,24 @@ impl PeripheralExt for Peripheral {
754751
"_registers" => {
755752
for (rname, val) in rderive.hash()? {
756753
let rname = rname.str()?;
757-
self.derive_register(rname, val).with_context(|| {
754+
self.derive_register(rname, val, &ppath).with_context(|| {
758755
format!("Deriving register `{rname}` from `{val:?}`")
759756
})?;
760757
}
761758
}
762759
"_clusters" => {
763760
for (cname, val) in rderive.hash()? {
764761
let cname = cname.str()?;
765-
self.derive_cluster(rname, val).with_context(|| {
762+
self.derive_cluster(rname, val, &ppath).with_context(|| {
766763
format!("Deriving cluster `{cname}` from `{val:?}`")
767764
})?;
768765
}
769766
}
770767
_ => {
771-
self.derive_register(rname, rderive).with_context(|| {
772-
format!("Deriving register `{rname}` from `{rderive:?}`")
773-
})?;
768+
self.derive_register(rname, rderive, &ppath)
769+
.with_context(|| {
770+
format!("Deriving register `{rname}` from `{rderive:?}`")
771+
})?;
774772
}
775773
}
776774
}
@@ -911,7 +909,7 @@ impl ClusterExt for Cluster {
911909
for (cname, val) in rcopy.hash()? {
912910
let cname = cname.str()?;
913911
let ccopy = val.hash()?;
914-
self.copy_cluster(rname, ccopy)
912+
self.copy_cluster(rname, ccopy, &cpath)
915913
.with_context(|| format!("Copying cluster `{cname}` from `{val:?}`"))?;
916914
}
917915
}
@@ -994,23 +992,24 @@ impl ClusterExt for Cluster {
994992
"_registers" => {
995993
for (rname, val) in rderive.hash()? {
996994
let rname = rname.str()?;
997-
self.derive_register(rname, val).with_context(|| {
995+
self.derive_register(rname, val, &cpath).with_context(|| {
998996
format!("Deriving register `{rname}` from `{val:?}`")
999997
})?;
1000998
}
1001999
}
10021000
"_clusters" => {
10031001
for (cname, val) in rderive.hash()? {
10041002
let cname = cname.str()?;
1005-
self.derive_cluster(rname, val).with_context(|| {
1003+
self.derive_cluster(rname, val, &cpath).with_context(|| {
10061004
format!("Deriving cluster `{cname}` from `{val:?}`")
10071005
})?;
10081006
}
10091007
}
10101008
_ => {
1011-
self.derive_register(rname, rderive).with_context(|| {
1012-
format!("Deriving register `{rname}` from `{rderive:?}`")
1013-
})?;
1009+
self.derive_register(rname, rderive, &cpath)
1010+
.with_context(|| {
1011+
format!("Deriving register `{rname}` from `{rderive:?}`")
1012+
})?;
10141013
}
10151014
}
10161015
}

src/patch/register.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,18 @@ pub trait RegisterExt {
5656
/// Work through a field, handling either an enum or a range
5757
fn process_field(
5858
&mut self,
59-
rpath: &RegisterPath,
6059
fspec: &str,
6160
fmod: &Yaml,
61+
rpath: &RegisterPath,
6262
config: &Config,
6363
) -> PatchResult;
6464

6565
/// Add an enumeratedValues given by field to all fspec in rtag
6666
fn process_field_enum(
6767
&mut self,
68-
rpath: &RegisterPath,
6968
fspec: &str,
7069
fmod: &Hash,
70+
rpath: &RegisterPath,
7171
usage: Option<Usage>,
7272
config: &Config,
7373
) -> PatchResult;
@@ -81,9 +81,9 @@ pub trait RegisterExt {
8181
/// Add a writeConstraint range given by field to all fspec in rtag
8282
fn process_field_range(
8383
&mut self,
84-
rpath: &RegisterPath,
8584
fspec: &str,
8685
fmod: &[Yaml],
86+
rpath: &RegisterPath,
8787
) -> PatchResult;
8888

8989
/// Delete substring from the beginning bitfield names inside rtag
@@ -203,7 +203,7 @@ impl RegisterExt for Register {
203203
for (fspec, field) in rmod {
204204
let fspec = fspec.str()?;
205205
if !fspec.starts_with('_') {
206-
self.process_field(&rpath, fspec, field, config)
206+
self.process_field(fspec, field, &rpath, config)
207207
.with_context(|| format!("Processing field matched to `{fspec}`"))?;
208208
}
209209
}
@@ -527,9 +527,9 @@ impl RegisterExt for Register {
527527

528528
fn process_field(
529529
&mut self,
530-
rpath: &RegisterPath,
531530
fspec: &str,
532531
fmod: &Yaml,
532+
rpath: &RegisterPath,
533533
config: &Config,
534534
) -> PatchResult {
535535
const READ: phf::Map<&'static str, Option<ReadAction>> = phf::phf_map! {
@@ -557,17 +557,17 @@ impl RegisterExt for Register {
557557
let is_read = READ.keys().any(|key| fmod.contains_key(&key.to_yaml()));
558558
let is_write = WRITE.keys().any(|key| fmod.contains_key(&key.to_yaml()));
559559
if !is_read && !is_write {
560-
self.process_field_enum(rpath, fspec, fmod, None, config)
560+
self.process_field_enum(fspec, fmod, rpath, None, config)
561561
.with_context(|| "Adding read-write enumeratedValues")?;
562562
} else {
563563
if is_read {
564564
for (key, action) in &READ {
565565
if let Some(fmod) = fmod.get_hash(key)? {
566566
if !fmod.is_empty() {
567567
self.process_field_enum(
568-
rpath,
569568
fspec,
570569
fmod,
570+
rpath,
571571
Some(Usage::Read),
572572
config,
573573
)
@@ -585,9 +585,9 @@ impl RegisterExt for Register {
585585
if let Some(fmod) = fmod.get_hash(key)? {
586586
if !fmod.is_empty() {
587587
self.process_field_enum(
588-
rpath,
589588
fspec,
590589
fmod,
590+
rpath,
591591
Some(Usage::Write),
592592
config,
593593
)
@@ -602,7 +602,7 @@ impl RegisterExt for Register {
602602
}
603603
}
604604
Yaml::Array(fmod) if fmod.len() == 2 => {
605-
self.process_field_range(rpath, fspec, fmod)
605+
self.process_field_range(fspec, fmod, rpath)
606606
.with_context(|| "Adding writeConstraint range")?;
607607
}
608608
_ => {}
@@ -628,9 +628,9 @@ impl RegisterExt for Register {
628628

629629
fn process_field_enum(
630630
&mut self,
631-
rpath: &RegisterPath,
632631
fspec: &str,
633632
mut fmod: &Hash,
633+
rpath: &RegisterPath,
634634
usage: Option<Usage>,
635635
config: &Config,
636636
) -> PatchResult {
@@ -807,9 +807,9 @@ impl RegisterExt for Register {
807807

808808
fn process_field_range(
809809
&mut self,
810-
rpath: &RegisterPath,
811810
fspec: &str,
812811
fmod: &[Yaml],
812+
rpath: &RegisterPath,
813813
) -> PatchResult {
814814
let mut set_any = false;
815815
let (fspec, ignore) = fspec.spec();

0 commit comments

Comments
 (0)