Skip to content

Commit

Permalink
Merge pull request #30 from us-irs/inline-generated-functions
Browse files Browse the repository at this point in the history
inline some generated functions
  • Loading branch information
jonathanpallant authored Mar 5, 2025
2 parents f5e9ad4 + b6d4a70 commit 3f0e440
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ pub fn derive_mmio(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
#[doc = "If you create multiple instances of this handle at the same time,"]
#[doc = "you are responsible for ensuring that there are no read-modify-write"]
#[doc = "races on any of the registers."]
#[inline]
pub const unsafe fn new_mmio(ptr: *mut #ident) -> #wrapper_ident<'static> {
#wrapper_ident {
ptr,
Expand Down Expand Up @@ -243,6 +244,7 @@ impl FieldParser {
#[doc = ""]
#[doc = "The lifetime of the returned inner MMIO block is tied to the "]
#[doc = "lifetime of this structure"]
#[inline]
pub fn #field_ident(&mut self) -> #inner_mmio_path<'_> {
unsafe {
self.#steal_func_name()
Expand All @@ -260,6 +262,7 @@ impl FieldParser {
#[doc = "If you create multiple instances of this handle at the same time,"]
#[doc = "you are responsible for ensuring that there are no read-modify-write"]
#[doc = "races on any of the registers."]
#[inline]
pub unsafe fn #steal_func_name(&mut self) -> #inner_mmio_path<'static> {
let ptr = unsafe { core::ptr::addr_of_mut!((*self.ptr).#field_ident) };
unsafe {
Expand Down Expand Up @@ -294,13 +297,15 @@ impl FieldParser {
#[doc = "` register."]
#[doc = ""]
#[doc = "Never create a reference from this pointer - only use read/write/read_volatile/write_volatile methods on it."]
#[inline(always)]
pub fn #pointer_fn_name(&mut self) -> *mut #type_path{
unsafe { core::ptr::addr_of_mut!((*self.ptr).#field_ident) }
}

#[doc = "Read the `"]
#[doc = stringify!(#field_ident)]
#[doc = "` register."]
#[inline(always)]
pub fn #read_fn_name(&mut self) -> #type_path {
let addr = self.#pointer_fn_name();
unsafe {
Expand All @@ -314,6 +319,7 @@ impl FieldParser {
#[doc = "Write the `"]
#[doc = stringify!(#field_ident)]
#[doc = "` register."]
#[inline(always)]
pub fn #write_fn_name(&mut self, value: #type_path) {
let addr = self.#pointer_fn_name();
unsafe {
Expand All @@ -324,6 +330,7 @@ impl FieldParser {
#[doc = "Read-Modify-Write the `"]
#[doc = stringify!(#field_ident)]
#[doc = "` register."]
#[inline]
pub fn #modify_fn_name<F>(&mut self, f: F) where F: FnOnce(#type_path) -> #type_path {
let value = self. #read_fn_name();
let new_value = f(value);
Expand Down

0 comments on commit 3f0e440

Please sign in to comment.