File tree Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Expand file tree Collapse file tree 2 files changed +20
-1
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,10 +168,28 @@ pub fn render(
168
168
169
169
mod_items. extend ( w_impl_items) ;
170
170
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 unsafefn: Option < Ident > = register
175
+ . fields
176
+ . as_ref ( )
177
+ . and_then ( |fields| fields. iter ( ) . next ( ) )
178
+ . and_then ( |field| field. write_constraint )
179
+ . and_then ( |constraint| match constraint {
180
+ WriteConstraint :: Range ( range)
181
+ if range. min == 0 && range. max == 2_u64 . pow ( rsize) - 1 =>
182
+ {
183
+ None
184
+ }
185
+ _ => Some ( ( ) ) ,
186
+ } )
187
+ . map ( |_| Ident :: new ( "unsafe" , span) ) ;
188
+
171
189
mod_items. extend ( quote ! {
172
190
#[ doc = "Writes raw bits to the register." ]
173
191
#[ inline( always) ]
174
- pub unsafe fn bits( & mut self , bits: #rty) -> & mut Self {
192
+ pub #unsafefn fn bits( & mut self , bits: #rty) -> & mut Self {
175
193
self . 0 . bits( bits) ;
176
194
self
177
195
}
You can’t perform that action at this time.
0 commit comments