@@ -223,6 +223,26 @@ pub fn fields(
223
223
r_impl_items : & mut Vec < TokenStream > ,
224
224
w_impl_items : & mut Vec < TokenStream > ,
225
225
) -> Result < ( ) > {
226
+ struct F < ' a > {
227
+ _pc_w : Ident ,
228
+ _sc : Ident ,
229
+ access : Option < Access > ,
230
+ description : String ,
231
+ description_with_bits : String ,
232
+ evs : & ' a [ EnumeratedValues ] ,
233
+ mask : u64 ,
234
+ name : & ' a str ,
235
+ offset : u64 ,
236
+ pc_r : Ident ,
237
+ _pc_r : Ident ,
238
+ pc_w : Ident ,
239
+ sc : Ident ,
240
+ bits : Ident ,
241
+ ty : Ident ,
242
+ width : u32 ,
243
+ write_constraint : Option < & ' a WriteConstraint > ,
244
+ }
245
+
226
246
impl < ' a > F < ' a > {
227
247
fn from ( f : & ' a Field ) -> Result < Self > {
228
248
// TODO(AJM) - do we need to do anything with this range type?
@@ -235,7 +255,7 @@ pub fn fields(
235
255
let pc_w = Ident :: new ( & format ! ( "{}_AW" , pc) , span) ;
236
256
let _pc_w = Ident :: new ( & format ! ( "{}_W" , pc) , span) ;
237
257
let _sc = Ident :: new ( & format ! ( "_{}" , sc) , span) ;
238
- let bits = Ident :: new ( if width == 1 { "bit" } else { "bits" } , Span :: call_site ( ) ) ;
258
+ let bits = Ident :: new ( if width == 1 { "bit" } else { "bits" } , span ) ;
239
259
let mut description_with_bits = if width == 1 {
240
260
format ! ( "Bit {}" , offset)
241
261
} else {
@@ -263,7 +283,7 @@ pub fn fields(
263
283
width,
264
284
access : f. access ,
265
285
evs : & f. enumerated_values ,
266
- sc : Ident :: new ( & sc, Span :: call_site ( ) ) ,
286
+ sc : Ident :: new ( & sc, span ) ,
267
287
mask : 1u64 . wrapping_neg ( ) >> ( 64 - width) ,
268
288
name : & f. name ,
269
289
offset : u64:: from ( offset) ,
@@ -273,10 +293,10 @@ pub fn fields(
273
293
}
274
294
}
275
295
276
- let fs = fields. iter ( ) . map ( F :: from) . collect :: < Result < Vec < _ > > > ( ) ?;
277
-
278
296
// TODO enumeratedValues
279
- for f in & fs {
297
+ for f in fields. iter ( ) . map ( F :: from) {
298
+ let f = f?;
299
+
280
300
let can_read = [ Access :: ReadOnly , Access :: ReadWriteOnce , Access :: ReadWrite ]
281
301
. contains ( & access)
282
302
&& ( f. access != Some ( Access :: WriteOnly ) )
@@ -357,7 +377,7 @@ pub fn fields(
357
377
let has_reserved_variant = evs. values . len ( ) != ( 1 << f. width ) ;
358
378
let variants = Variant :: from_enumerated_values ( evs) ?;
359
379
360
- add_from_variants ( mod_items, & variants, pc_r, & f , description, rv) ;
380
+ add_from_variants ( mod_items, & variants, pc_r, fty , description, rv) ;
361
381
362
382
let mut enum_items = vec ! [ ] ;
363
383
@@ -481,7 +501,7 @@ pub fn fields(
481
501
} ) ;
482
502
483
503
if base. is_none ( ) {
484
- add_from_variants ( mod_items, & variants, pc_w, & f , description, rv) ;
504
+ add_from_variants ( mod_items, & variants, pc_w, fty , description, rv) ;
485
505
}
486
506
}
487
507
@@ -641,13 +661,11 @@ fn add_from_variants(
641
661
mod_items : & mut Vec < TokenStream > ,
642
662
variants : & [ Variant ] ,
643
663
pc : & Ident ,
644
- f : & F ,
664
+ fty : & Ident ,
645
665
desc : & str ,
646
666
reset_value : Option < u64 > ,
647
667
) {
648
- let fty = & f. ty ;
649
-
650
- let ( repr, cast) = if f. ty == "bool" {
668
+ let ( repr, cast) = if fty == "bool" {
651
669
( quote ! { } , quote ! { variant as u8 != 0 } )
652
670
} else {
653
671
( quote ! { #[ repr( #fty) ] } , quote ! { variant as _ } )
@@ -736,26 +754,6 @@ fn derive_from_base(
736
754
}
737
755
}
738
756
739
- struct F < ' a > {
740
- _pc_w : Ident ,
741
- _sc : Ident ,
742
- access : Option < Access > ,
743
- description : String ,
744
- description_with_bits : String ,
745
- evs : & ' a [ EnumeratedValues ] ,
746
- mask : u64 ,
747
- name : & ' a str ,
748
- offset : u64 ,
749
- pc_r : Ident ,
750
- _pc_r : Ident ,
751
- pc_w : Ident ,
752
- sc : Ident ,
753
- bits : Ident ,
754
- ty : Ident ,
755
- width : u32 ,
756
- write_constraint : Option < & ' a WriteConstraint > ,
757
- }
758
-
759
757
#[ derive( Clone , Debug ) ]
760
758
pub struct Base < ' a > {
761
759
pub peripheral : Option < & ' a str > ,
0 commit comments