+2015-02-25 Georg-Johann Lay <avr@gjlay.de>
+
+ 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.
+
2015-02-25 Jakub Jelinek <jakub@redhat.com>
PR lto/64374
* config/xtensa/xtensa.md (zero_cost_loop_start): Reverse numbering
of operand 0 and operand 2.
(zero_cost_loop_end, loop_end): Similarly.
-
+
2015-02-24 Aldy Hernandez <aldyh@redhat.com>
* gimple.h (gimple_build_assign): Rename CXX_MEM_STAT_DECL to
/* 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 ==
/* 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++)
break;
case 'F':
- fputs (avr_log_caller, file);
+ fputs (caller, file);
break;
case 'H':
/* FALLTHRU */
case '?':
- avr_log_fdump_f (file, "%F[%f:%P]");
+ avr_vdump (file, caller, "%F[%f:%P]");
break;
case 'P':
/* From avr-log.c */
-#define avr_edump (avr_log_set_caller_e (__FUNCTION__))
-#define avr_fdump (avr_log_set_caller_f (__FUNCTION__))
-
-extern int (*avr_log_set_caller_e (const char*))(const char*, ...);
-extern int (*avr_log_set_caller_f (const char*))(FILE*, const char*, ...);
+#define avr_dump(...) avr_vdump (NULL, __FUNCTION__, __VA_ARGS__)
+#define avr_edump(...) avr_vdump (stderr, __FUNCTION__, __VA_ARGS__)
+#define avr_fdump(FIL, ...) avr_vdump (FIL, __FUNCTION__, __VA_ARGS__)
+extern int avr_vdump (FILE*, const char*, ...);
extern void avr_log_set_avr_log (void);
typedef struct