From 948c655985dcbe6f8abcc7da850b91e8caa73080 Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Wed, 15 Dec 2010 00:24:38 +0100 Subject: digital/avr/common: add preprocessor tools --- digital/avr/modules/trace/trace.h | 21 +++------------------ digital/avr/modules/uart/uart_common.h | 9 +++------ 2 files changed, 6 insertions(+), 24 deletions(-) (limited to 'digital/avr/modules') diff --git a/digital/avr/modules/trace/trace.h b/digital/avr/modules/trace/trace.h index 68894059..a8e1e9fc 100644 --- a/digital/avr/modules/trace/trace.h +++ b/digital/avr/modules/trace/trace.h @@ -24,33 +24,18 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * }}} */ -/** - * You can find the example on the website : - * http://gcc.gnu.org/ml/gcc-patches/2000-11/msg00016.html - */ -#define PASTE_EXPAND(a, b) PASTE(a, b) - -#define PASTE(a, b) a ## b - -#define TRACE_ARGS_COUNT(...) \ - _TRACE_ARGS_COUNT1 ( , ##__VA_ARGS__) - -#define _TRACE_ARGS_COUNT1(...) \ - _TRACE_ARGS_COUNT2 (__VA_ARGS__, 10,9,8,7,6,5,4,3,2,1,0) - -#define _TRACE_ARGS_COUNT2(_ ,_0,_1,_2,_3,_4,_5,_6,_7,_8,_9, n,...) n +#include "preproc.h" #ifndef HOST #define TRACE(args...) \ - PASTE_EXPAND(TRACE_PRINT, TRACE_ARGS_COUNT(args...)) (args) + PREPROC_NARG_CALL(TRACE_PRINT, ## args) #else /* HOST */ #include extern char *trace_table[]; #define TRACE(id, args...) \ do {\ fprintf (stderr, trace_table[id], ## args);\ - PASTE_EXPAND(TRACE_PRINT, TRACE_ARGS_COUNT(id, ## args...))\ - (id, ## args);\ + PREPROC_NARG_CALL(TRACE_PRINT, id, ## args);\ } while (0) #endif /* HOST */ diff --git a/digital/avr/modules/uart/uart_common.h b/digital/avr/modules/uart/uart_common.h index 8f5a3af4..4704f59c 100644 --- a/digital/avr/modules/uart/uart_common.h +++ b/digital/avr/modules/uart/uart_common.h @@ -24,19 +24,16 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * }}} */ +#include "preproc.h" /* This symbol should be 0 or 1. */ #ifndef UART_N # error "uart: UART_N missing" #endif -/* Utility macros. */ -#define PASTE4_SUB(a, b, c, d) a ## b ## c ## d -#define PASTE4(a, b, c, d) PASTE4_SUB (a, b, c, d) - /* Port selection macros. */ -#define AC_UART(x) PASTE4(AC_UART, UART_N, _, x) -#define uart(x) PASTE4(uart, UART_N, _, x) +#define AC_UART(x) PREPROC_PASTE(AC_UART, UART_N, _, x) +#define uart(x) PREPROC_PASTE(uart, UART_N, _, x) /* Define uart symbols. */ #define uart_error uart (error) -- cgit v1.2.3