File tree Expand file tree Collapse file tree 2 files changed +34
-7
lines changed Expand file tree Collapse file tree 2 files changed +34
-7
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
31
31
- Bumped ` xtensa-lx ` and add ` xtensa_lx::interrupt::InterruptNumber ` implementation.
32
32
- Don't use a mask when the width of the mask is the same as the width of the parent register.
33
33
- Improved error handling
34
+ - Registers with single fields that span the entire register now generate safe ` bits ` writers.
34
35
35
36
## [ v0.19.0] - 2021-05-26
36
37
Original file line number Diff line number Diff line change @@ -168,14 +168,40 @@ pub fn render(
168
168
169
169
mod_items. extend ( w_impl_items) ;
170
170
171
- mod_items. extend ( quote ! {
172
- #[ doc = "Writes raw bits to the register." ]
173
- #[ inline( always) ]
174
- pub unsafe fn bits( & mut self , bits: #rty) -> & mut Self {
175
- self . 0 . bits( bits) ;
176
- self
171
+ // the writer can be safe if:
172
+ // * there is a single field that covers the entire register
173
+ // * that field can represent all values
174
+ let can_write_safe = match register
175
+ . fields
176
+ . as_ref ( )
177
+ . and_then ( |fields| fields. iter ( ) . next ( ) )
178
+ . and_then ( |field| field. write_constraint )
179
+ {
180
+ Some ( WriteConstraint :: Range ( range) ) => {
181
+ range. min == 0 && range. max == u64:: MAX >> ( 64 - rsize)
177
182
}
178
- } ) ;
183
+ _ => false ,
184
+ } ;
185
+
186
+ if can_write_safe {
187
+ mod_items. extend ( quote ! {
188
+ #[ doc = "Writes raw bits to the register." ]
189
+ #[ inline( always) ]
190
+ pub fn bits( & mut self , bits: #rty) -> & mut Self {
191
+ unsafe { self . 0 . bits( bits) } ;
192
+ self
193
+ }
194
+ } ) ;
195
+ } else {
196
+ mod_items. extend ( quote ! {
197
+ #[ doc = "Writes raw bits to the register." ]
198
+ #[ inline( always) ]
199
+ pub unsafe fn bits( & mut self , bits: #rty) -> & mut Self {
200
+ self . 0 . bits( bits) ;
201
+ self
202
+ }
203
+ } ) ;
204
+ }
179
205
180
206
close. to_tokens ( & mut mod_items) ;
181
207
}
You can’t perform that action at this time.
0 commit comments