diff --git a/src/arm_semihosting/src/macros.rs b/src/arm_semihosting/src/macros.rs index c3d7f87308..bf0f45e8c5 100644 --- a/src/arm_semihosting/src/macros.rs +++ b/src/arm_semihosting/src/macros.rs @@ -35,7 +35,13 @@ macro_rules! syscall1 { #[macro_export] macro_rules! hprint { ($($tt:tt)*) => { - $crate::export::hstdout_fmt(format_args!($($tt)*)) + match ::core::format_args!($($tt)*) { + args => if let ::core::option::Option::Some(s) = args.as_str() { + $crate::export::hstdout_str(s) + } else { + $crate::export::hstdout_fmt(args) + }, + } }; } @@ -45,7 +51,7 @@ macro_rules! hprint { #[macro_export] macro_rules! hprintln { ($($tt:tt)*) => { - match $crate::export::hstdout_fmt(format_args!($($tt)*)) { + match $crate::hprint!($($tt)*) { Ok(()) => $crate::export::hstdout_str("\n"), Err(()) => Err(()), } @@ -58,7 +64,13 @@ macro_rules! hprintln { #[macro_export] macro_rules! heprint { ($($tt:tt)*) => { - $crate::export::hstderr_fmt(format_args!($($tt)*)) + match ::core::format_args!($($tt)*) { + args => if let ::core::option::Option::Some(s) = args.as_str() { + $crate::export::hstderr_str(s) + } else { + $crate::export::hstderr_fmt(args) + }, + } }; } @@ -68,7 +80,7 @@ macro_rules! heprint { #[macro_export] macro_rules! heprintln { ($($tt:tt)*) => { - match $crate::export::hstderr_fmt(format_args!($($tt)*)) { + match $crate::heprint!($($tt)*) { Ok(()) => $crate::export::hstderr_str("\n"), Err(()) => Err(()), } diff --git a/src/r3_support_rp2040/src/stdout.rs b/src/r3_support_rp2040/src/stdout.rs index 71ffb9af03..440661d3f2 100644 --- a/src/r3_support_rp2040/src/stdout.rs +++ b/src/r3_support_rp2040/src/stdout.rs @@ -106,7 +106,13 @@ pub fn write_fmt(args: fmt::Arguments<'_>) { #[macro_export] macro_rules! sprint { ($($tt:tt)*) => { - $crate::stdout::write_fmt(format_args!($($tt)*)) + match ::core::format_args!($($tt)*) { + args => if let ::core::option::Option::Some(s) = args.as_str() { + $crate::stdout::write_str(s) + } else { + $crate::stdout::write_fmt(args) + }, + } }; } @@ -114,7 +120,7 @@ macro_rules! sprint { #[macro_export] macro_rules! sprintln { ($($tt:tt)*) => {{ - $crate::stdout::write_fmt(format_args!($($tt)*)); + $crate::sprint!($($tt)*); $crate::stdout::write_str("\n"); }}; } diff --git a/src/r3_support_rza1/src/stdout.rs b/src/r3_support_rza1/src/stdout.rs index ffe6800b72..4656e0b8d0 100644 --- a/src/r3_support_rza1/src/stdout.rs +++ b/src/r3_support_rza1/src/stdout.rs @@ -102,7 +102,13 @@ pub fn write_fmt(args: fmt::Arguments<'_>) { #[macro_export] macro_rules! sprint { ($($tt:tt)*) => { - $crate::stdout::write_fmt(format_args!($($tt)*)) + match ::core::format_args!($($tt)*) { + args => if let ::core::option::Option::Some(s) = args.as_str() { + $crate::stdout::write_str(s) + } else { + $crate::stdout::write_fmt(args) + }, + } }; } @@ -110,7 +116,7 @@ macro_rules! sprint { #[macro_export] macro_rules! sprintln { ($($tt:tt)*) => {{ - $crate::stdout::write_fmt(format_args!($($tt)*)); + $crate::sprint!($($tt)*); $crate::stdout::write_str("\n"); }}; }