aboutsummaryrefslogtreecommitdiff
path: root/gcc/config/avr/avr-log.c
diff options
context:
space:
mode:
authorGeorg-Johann Lay <avr@gjlay.de>2015-02-25 12:08:57 +0000
committerGeorg-Johann Lay <gjl@gcc.gnu.org>2015-02-25 12:08:57 +0000
commit10fbfd1bd1b5fc1942457a6fd67903367cb5f876 (patch)
tree51ac589ee4d7a23f013ea6acd79f79d0eafc0692 /gcc/config/avr/avr-log.c
parent1d3d9afaff77287cdcbf6af5b4a4f54d0dc39119 (diff)
downloadgcc-10fbfd1bd1b5fc1942457a6fd67903367cb5f876.zip
gcc-10fbfd1bd1b5fc1942457a6fd67903367cb5f876.tar.gz
gcc-10fbfd1bd1b5fc1942457a6fd67903367cb5f876.tar.bz2
Use variadic macros with avr-log.c.
* config/avr/avr-protos.h (avr_vdump): New prototype. (avr_log_set_caller_e, avr_log_set_caller_f): Remove protos. (avr_edump, avr_fdump, avr_dump): (Re)define to use avr_vdump. * config/avr/avr-log.c: Adjust comments. (avr_vdump): New function. (avr_vadump): Pass caller as 2nd argument instead of format string. (avr_log_caller, avr_log_fdump_e, avr_log_fdump_f) (avr_log_set_caller_e, avr_log_set_caller_f): Remove. From-SVN: r220962
Diffstat (limited to 'gcc/config/avr/avr-log.c')
-rw-r--r--gcc/config/avr/avr-log.c75
1 files changed, 19 insertions, 56 deletions
diff --git a/gcc/config/avr/avr-log.c b/gcc/config/avr/avr-log.c
index 8a19101..e84d579 100644
--- a/gcc/config/avr/avr-log.c
+++ b/gcc/config/avr/avr-log.c
@@ -43,13 +43,11 @@
/* This file supplies some functions for AVR back-end developers
with a printf-like interface. The functions are called through
- macros avr_edump or avr_fdump from avr-protos.h:
-
- avr_edump (const char *fmt, ...);
-
- avr_fdump (FILE *stream, const char *fmt, ...);
+ macros `avr_dump', `avr_edump' or `avr_fdump' from avr-protos.h:
+ avr_fdump (FILE *stream, const char *fmt, ...);
avr_edump (fmt, ...) is a shortcut for avr_fdump (stderr, fmt, ...)
+ avr_dump (fmt, ...) is a shortcut for avr_fdump (dump_file, fmt, ...)
== known %-codes ==
@@ -85,76 +83,41 @@
/* Set according to -mlog= option. */
avr_log_t avr_log;
-/* The caller as of __FUNCTION__ */
-static const char *avr_log_caller = "?";
-
/* The worker function implementing the %-codes */
static void avr_log_vadump (FILE*, const char*, va_list);
-/* As we have no variadic macros, avr_edump maps to a call to
- avr_log_set_caller_e which saves __FUNCTION__ to avr_log_caller and
- returns a function pointer to avr_log_fdump_e. avr_log_fdump_e
- gets the printf-like arguments and calls avr_log_vadump, the
- worker function. avr_fdump works the same way. */
-
-/* Provide avr_log_fdump_e/f so that avr_log_set_caller_e/_f can return
- their address. */
-
-static int
-avr_log_fdump_e (const char *fmt, ...)
-{
- va_list ap;
-
- va_start (ap, fmt);
- avr_log_vadump (stderr, fmt, ap);
- va_end (ap);
-
- return 1;
-}
+/* Wrapper for avr_log_vadump. If STREAM is NULL we are called by avr_dump,
+ i.e. output to dump_file if available. The 2nd argument is __FUNCTION__.
+ The 3rd argument is the format string. */
-static int
-avr_log_fdump_f (FILE *stream, const char *fmt, ...)
+int
+avr_vdump (FILE *stream, const char *caller, ...)
{
va_list ap;
+
+ if (NULL == stream && dump_file)
+ stream = dump_file;
- va_start (ap, fmt);
+ va_start (ap, caller);
if (stream)
- avr_log_vadump (stream, fmt, ap);
+ avr_log_vadump (stream, caller, ap);
va_end (ap);
return 1;
}
-/* Macros avr_edump/avr_fdump map to calls of the following two functions,
- respectively. You don't need to call them directly. */
-
-int (*
-avr_log_set_caller_e (const char *caller)
- )(const char*, ...)
-{
- avr_log_caller = caller;
-
- return avr_log_fdump_e;
-}
-
-int (*
-avr_log_set_caller_f (const char *caller)
- )(FILE*, const char*, ...)
-{
- avr_log_caller = caller;
-
- return avr_log_fdump_f;
-}
-
/* Worker function implementing the %-codes and forwarding to
respective print/dump function. */
static void
-avr_log_vadump (FILE *file, const char *fmt, va_list ap)
+avr_log_vadump (FILE *file, const char *caller, va_list ap)
{
char bs[3] = {'\\', '?', '\0'};
+ /* 3rd proper argument is always the format string. */
+ const char *fmt = va_arg (ap, const char*);
+
while (*fmt)
{
switch (*fmt++)
@@ -256,7 +219,7 @@ avr_log_vadump (FILE *file, const char *fmt, va_list ap)
break;
case 'F':
- fputs (avr_log_caller, file);
+ fputs (caller, file);
break;
case 'H':
@@ -280,7 +243,7 @@ avr_log_vadump (FILE *file, const char *fmt, va_list ap)
/* FALLTHRU */
case '?':
- avr_log_fdump_f (file, "%F[%f:%P]");
+ avr_vdump (file, caller, "%F[%f:%P]");
break;
case 'P':