Skip to content

Commit

Permalink
Merge #587
Browse files Browse the repository at this point in the history
587: tweak inline attributes to remove machine code duplication r=jonas-schievink a=japaric

fixes #586 and saves 140 bytes of Flash in the example (repro case) given therein

Co-authored-by: Jorge Aparicio <[email protected]>
  • Loading branch information
bors[bot] and japaric authored Sep 23, 2021
2 parents 96a3043 + 4bb54b9 commit e240ba9
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
4 changes: 4 additions & 0 deletions macros/src/attributes/global_logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,25 @@ fn codegen(strukt: &ItemStruct) -> TokenStream {
#(#attrs)*
#vis struct #ident;

#[inline(never)]
#[no_mangle]
unsafe fn _defmt_acquire() {
<#ident as defmt::Logger>::acquire()
}

#[inline(never)]
#[no_mangle]
unsafe fn _defmt_flush() {
<#ident as defmt::Logger>::flush()
}

#[inline(never)]
#[no_mangle]
unsafe fn _defmt_release() {
<#ident as defmt::Logger>::release()
}

#[inline(never)]
#[no_mangle]
unsafe fn _defmt_write(bytes: &[u8]) {
<#ident as defmt::Logger>::write(bytes)
Expand Down
1 change: 1 addition & 0 deletions macros/src/attributes/panic_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ fn codegen(fun: &ItemFn) -> TokenStream {
quote!(
#(#attrs)*
#[export_name = "_defmt_panic"]
#[inline(never)]
fn #ident() -> ! {
#block
}
Expand Down
1 change: 1 addition & 0 deletions macros/src/items/timestamp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub(crate) fn expand(args: TokenStream) -> TokenStream {
quote!(
const _: () = {
#[export_name = "_defmt_timestamp"]
#[inline(never)]
fn defmt_timestamp(fmt: ::defmt::Formatter<'_>) {
match (#(&(#formatting_exprs)),*) {
(#(#patterns),*) => {
Expand Down
8 changes: 5 additions & 3 deletions src/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub fn fetch_bytes() -> Vec<u8> {
pub fn acquire() {}

#[cfg(not(feature = "unstable-test"))]
#[inline(never)]
#[inline(always)]
pub fn acquire() {
extern "Rust" {
fn _defmt_acquire();
Expand All @@ -51,7 +51,7 @@ pub fn acquire() {
pub fn release() {}

#[cfg(not(feature = "unstable-test"))]
#[inline(never)]
#[inline(always)]
pub fn release() {
extern "Rust" {
fn _defmt_release();
Expand All @@ -65,7 +65,7 @@ pub fn write(bytes: &[u8]) {
}

#[cfg(not(feature = "unstable-test"))]
#[inline(never)]
#[inline(always)]
pub fn write(bytes: &[u8]) {
extern "Rust" {
fn _defmt_write(bytes: &[u8]);
Expand All @@ -78,6 +78,7 @@ pub fn write(bytes: &[u8]) {
pub fn timestamp(_fmt: crate::Formatter<'_>) {}

#[cfg(not(feature = "unstable-test"))]
#[inline(always)]
pub fn timestamp(fmt: crate::Formatter<'_>) {
extern "Rust" {
fn _defmt_timestamp(_: crate::Formatter<'_>);
Expand Down Expand Up @@ -257,6 +258,7 @@ pub fn panic() -> ! {
}

#[cfg(not(feature = "unstable-test"))]
#[inline(always)]
pub fn panic() -> ! {
extern "Rust" {
fn _defmt_panic() -> !;
Expand Down

0 comments on commit e240ba9

Please sign in to comment.