@@ -33,14 +33,14 @@ pub trait DeviceExt {
33
33
fn modify_cpu ( & mut self , cmod : & Hash ) -> PatchResult ;
34
34
35
35
/// Modify pspec inside device according to pmod
36
- fn modify_peripheral ( & mut self , pspec : & str , pmod : & Hash ) -> PatchResult ;
36
+ fn modify_peripheral ( & mut self , pspec : & str , pmod : & Hash , env : & Env ) -> PatchResult ;
37
37
38
38
/// Add pname given by padd to device
39
- fn add_peripheral ( & mut self , pname : & str , padd : & Hash ) -> PatchResult ;
39
+ fn add_peripheral ( & mut self , pname : & str , padd : & Hash , env : & Env ) -> PatchResult ;
40
40
41
41
/// Remove registers from pname and mark it as derivedFrom pderive.
42
42
/// Update all derivedFrom referencing pname
43
- fn derive_peripheral ( & mut self , pname : & str , pderive : & Yaml ) -> PatchResult ;
43
+ fn derive_peripheral ( & mut self , pname : & str , pderive : & Yaml , env : & Env ) -> PatchResult ;
44
44
45
45
/// Move registers from pold to pnew.
46
46
/// Update all derivedFrom referencing pold
@@ -95,7 +95,7 @@ impl DeviceExt for Device {
95
95
"_peripherals" => {
96
96
for ( pspec, pmod) in val. hash ( ) ? {
97
97
let pspec = pspec. str ( ) ?;
98
- self . modify_peripheral ( pspec, pmod. hash ( ) ?)
98
+ self . modify_peripheral ( pspec, pmod. hash ( ) ?, & env )
99
99
. with_context ( || {
100
100
format ! ( "Modifying peripherals matched to `{pspec}`" )
101
101
} ) ?;
@@ -119,7 +119,7 @@ impl DeviceExt for Device {
119
119
}
120
120
121
121
_ => self
122
- . modify_peripheral ( key, val. hash ( ) ?)
122
+ . modify_peripheral ( key, val. hash ( ) ?, & env )
123
123
. with_context ( || format ! ( "Modifying peripherals matched to `{key}`" ) ) ?,
124
124
}
125
125
}
@@ -134,14 +134,14 @@ impl DeviceExt for Device {
134
134
// Handle any new peripherals (!)
135
135
for ( pname, padd) in device. hash_iter ( "_add" ) {
136
136
let pname = pname. str ( ) ?;
137
- self . add_peripheral ( pname, padd. hash ( ) ?)
137
+ self . add_peripheral ( pname, padd. hash ( ) ?, & env )
138
138
. with_context ( || format ! ( "Adding peripheral `{pname}`" ) ) ?;
139
139
}
140
140
141
141
// Handle any derived peripherals
142
142
for ( pname, pderive) in device. hash_iter ( "_derive" ) {
143
143
let pname = pname. str ( ) ?;
144
- self . derive_peripheral ( pname, pderive)
144
+ self . derive_peripheral ( pname, pderive, & env )
145
145
. with_context ( || format ! ( "Deriving peripheral `{pname}` from `{pderive:?}`" ) ) ?;
146
146
}
147
147
@@ -222,11 +222,11 @@ impl DeviceExt for Device {
222
222
Ok ( ( ) )
223
223
}
224
224
225
- fn modify_peripheral ( & mut self , pspec : & str , pmod : & Hash ) -> PatchResult {
225
+ fn modify_peripheral ( & mut self , pspec : & str , pmod : & Hash , env : & Env ) -> PatchResult {
226
226
let mut modified = HashSet :: new ( ) ;
227
227
let ptags = self . iter_peripherals ( pspec) . collect :: < Vec < _ > > ( ) ;
228
228
if !ptags. is_empty ( ) {
229
- let peripheral_builder = make_peripheral ( pmod, true ) ?;
229
+ let peripheral_builder = make_peripheral ( pmod, true , env ) ?;
230
230
let dim = make_dim_element ( pmod) ?;
231
231
for ptag in ptags {
232
232
modified. insert ( ptag. name . clone ( ) ) ;
@@ -271,12 +271,12 @@ impl DeviceExt for Device {
271
271
Ok ( ( ) )
272
272
}
273
273
274
- fn add_peripheral ( & mut self , pname : & str , padd : & Hash ) -> PatchResult {
274
+ fn add_peripheral ( & mut self , pname : & str , padd : & Hash , env : & Env ) -> PatchResult {
275
275
if self . get_peripheral ( pname) . is_some ( ) {
276
276
return Err ( anyhow ! ( "device already has a peripheral {pname}" ) ) ;
277
277
}
278
278
279
- let pnew = make_peripheral ( padd, false ) ?
279
+ let pnew = make_peripheral ( padd, false , env ) ?
280
280
. name ( pname. to_string ( ) )
281
281
. build ( VAL_LVL ) ?;
282
282
let pnew = if let Some ( dim) = make_dim_element ( padd) ? {
@@ -289,7 +289,7 @@ impl DeviceExt for Device {
289
289
Ok ( ( ) )
290
290
}
291
291
292
- fn derive_peripheral ( & mut self , pname : & str , pderive : & Yaml ) -> PatchResult {
292
+ fn derive_peripheral ( & mut self , pname : & str , pderive : & Yaml , env : & Env ) -> PatchResult {
293
293
let ( pderive, info) = if let Some ( pderive) = pderive. as_str ( ) {
294
294
(
295
295
pderive,
@@ -304,7 +304,7 @@ impl DeviceExt for Device {
304
304
} ) ?;
305
305
(
306
306
pderive,
307
- make_peripheral ( hash, true ) ?. derived_from ( Some ( pderive. into ( ) ) ) ,
307
+ make_peripheral ( hash, true , env ) ?. derived_from ( Some ( pderive. into ( ) ) ) ,
308
308
)
309
309
} else {
310
310
return Err ( anyhow ! ( "derive: incorrect syntax for {pname}" ) ) ;
0 commit comments