From 76a2f6c2a2f0064ba694f2ffb165ba26eb6437bc Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 17 Feb 2019 12:04:02 -0600 Subject: [PATCH] libs/libc/stdio: This commits makes the nano-printf the defualt logic for the printf family. The legacy printf is still available via CONFIG_LIBC_PRINT_LEGACY. This commit also modifies the nano-prinf configure: The PRINT_LEVEL is not long selectable. Instead, a not CONFIG_LIBC_PRINT_MINIMAL boolean setting was added and the PRINT_LEVEL is derived from a combination of CONFIG_LIBC_PRINT_MINIMAL, CONFIG_LIBC_FLOATINGPOINT, and CONFIG_LIBC_LONG_LONG. --- libs/libc/stdio/Kconfig | 57 +++++++++++++----------------- libs/libc/stdio/Make.defs | 20 +++++------ libs/libc/stdio/nano_libvsprintf.c | 19 +++------- 3 files changed, 38 insertions(+), 58 deletions(-) diff --git a/libs/libc/stdio/Kconfig b/libs/libc/stdio/Kconfig index a63bf8e165..43023d231c 100644 --- a/libs/libc/stdio/Kconfig +++ b/libs/libc/stdio/Kconfig @@ -48,7 +48,17 @@ config NUNGET_CHARS int "Number unget() characters" default 2 ---help--- - Number of characters that can be buffered by ungetc() (Only if NFILE_STREAMS > 0) + Number of characters that can be buffered by ungetc() (Only if + NFILE_STREAMS > 0) + +config LIBC_PRINT_LEGACY + bool "Enable legacy printf logic" + default n + ---help--- + By default, printf (and friends) are implemented using a port from + newlib-nano. That port can be signifcantly smaller, especially if + floating support is enabled. This option may is avaiable, however, + to revert to the legacy printf version is so desired. config LIBC_FLOATINGPOINT bool "Enable floating point in printf" @@ -57,12 +67,6 @@ config LIBC_FLOATINGPOINT By default, floating point support in printf, sscanf, etc. is disabled. This option will enable floating point support. - if CONFIG_NANO_PRINTF is enabled, tnen this option works a - little differently. You still have to select - CONFIG_NANO_PRINTLEVEL=3 to get floating point support. In - case, this option extends the range of acceptable - values that will permit selection of CONFIG_NANO_PRINTLEVEL=3. - config LIBC_LONG_LONG bool "Enable long long support in printf" default y if !DEFAULT_SMALL @@ -76,6 +80,20 @@ config LIBC_LONG_LONG libraries that will be drawn into the build if long long support is enabled. +config LIBC_PRINT_MINIMAL + bool "Minimal formatting support in printf" + default y if DEFAULT_SMALL + default n if !DEFAULT_SMALL + depends on !LIBC_FLOATINGPOINT && !LIBC_LONG_LONG && !LIBC_PRINT_LEGACY + ---help--- + Enables support for long long formats in printf, sscanf, etc. is + enabled. This is enabled by default but if you are trying to + reduce the FLASH footprint, then disabling this feature is one + option. The FLASH saves comes not from disabling the long long + formats, but rather from omitting the large long long arithmetic + libraries that will be drawn into the build if long long support + is enabled. + config LIBC_SCANSET bool "Scanset support" default n @@ -114,29 +132,4 @@ config MEMCPY_VIK Select this option for improved performance at the expense of increased size. See licensing information in the top-level COPYING file. -config NANO_PRINTF - bool "Use nano printf code" - default y if DEFAULT_SMALL - default n if !DEFAULT_SMALL - ---help--- - Replace printf code with version from newlib-nano. Can be - signifcantly smaller, especially if floating support is enabled. - However, it does not include 'long long' support. - -config NANO_PRINTLEVEL - int "Nano printf support level" - default 2 if !LIBC_FLOATINGPOINT - default 3 if LIBC_FLOATINGPOINT - range 1 2 if !LIBC_FLOATINGPOINT && !LIBC_LONG_LONG - range 1 3 if LIBC_FLOATINGPOINT && !LIBC_LONG_LONG - range 2 2 if !LIBC_FLOATINGPOINT && LIBC_LONG_LONG - range 2 3 if LIBC_FLOATINGPOINT && LIBC_LONG_LONG - depends on NANO_PRINTF - ---help--- - Nano printf can be built into more than one support level. The - default is to offer the usual modifiers and integer formatting - support (level 2). Level 1 maintains a minimal version that just - offers integer formatting, but no modifier support whatsoever. - Level 3 is intented for floating point support. - endmenu #Standard C I/O diff --git a/libs/libc/stdio/Make.defs b/libs/libc/stdio/Make.defs index e1463c3694..5c0ead76ec 100644 --- a/libs/libc/stdio/Make.defs +++ b/libs/libc/stdio/Make.defs @@ -45,24 +45,20 @@ CSRCS += lib_zeroinstream.c lib_nullinstream.c lib_nulloutstream.c CSRCS += lib_sscanf.c lib_vsscanf.c lib_libvscanf.c lib_libnoflush.c CSRCS += lib_libsnoflush.c -ifeq ($(CONFIG_NANO_PRINTF),y) - -CSRCS += nano_libvsprintf.c nano_ultoa_invert.c - -ifeq ($(CONFIG_NANO_PRINTLEVEL),3) - -CSRCS += nano_dtoa_engine.c nano_dtoa_data.c - -endif - -else +ifeq ($(CONFIG_LIBC_PRINT_LEGACY),y) CSRCS += lib_libvsprintf.c - ifeq ($(CONFIG_LIBC_FLOATINGPOINT),y) CSRCS += lib_dtoa.c endif +#else + +CSRCS += nano_libvsprintf.c nano_ultoa_invert.c +ifeq ($(CONFIG_LIBC_FLOATINGPOINT),y) +CSRCS += nano_dtoa_engine.c nano_dtoa_data.c +endif + endif # The remaining sources files depend upon C streams diff --git a/libs/libc/stdio/nano_libvsprintf.c b/libs/libc/stdio/nano_libvsprintf.c index 2885b94e97..cbff2eaa96 100644 --- a/libs/libc/stdio/nano_libvsprintf.c +++ b/libs/libc/stdio/nano_libvsprintf.c @@ -66,24 +66,15 @@ * is to offer the usual modifiers and integer formatting support * (level 2). Level 1 maintains a minimal version that just offers * integer formatting, but no modifier support whatsoever. Level 3 is - * intented for floating point support. + * intended for floating point support. */ -#if defined(CONFIG_NANO_PRINTLEVEL) -# define PRINTF_LEVEL CONFIG_NANO_PRINTLEVEL -#elif defined(CONFIG_LIBC_FLOATINGPOINT) +#if defined(CONFIG_LIBC_FLOATINGPOINT) # define PRINTF_LEVEL PRINTF_FLT +#elif defined(CONFIG_LIB_LONG_LONG) || !defined(CONFIG_LIBC_PRINT_MINIMAL) +# define PRINT_LEVEL PRINTF_STD #else -# define PRINTF_LEVEL PRINTF_STD -#endif - -#if PRINTF_LEVEL == PRINTF_MIN || PRINTF_LEVEL == PRINTF_STD || \ - PRINTF_LEVEL == PRINTF_FLT - -/* OK */ - -#else -# error "Not a known printf level." +# define PRINT_LEVEL PRINTF_MIN #endif #ifdef putc