From patchwork Tue Feb 24 13:09:22 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Georg-Johann Lay X-Patchwork-Id: 442959 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 81D1C140119 for ; Wed, 25 Feb 2015 00:09:36 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:content-type; q=dns; s=default; b=CwSCt9xUS2cv+bGolXTqV5hocfS9mYI7fSA7UXIJv9d sIm85uLyHubgZ2lJw+3UpLRt3j2L/AJ0ongHcYwyDjbi9b906+rigtmYEMtd8ArP tbTEj39/OvCgC3tr/jiDReivC++9PEzx6AKlWGY/mQSIGe7ssqlp/x+oZKxzTaMw = DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:content-type; s=default; bh=DrJQQQh7XoJoPD3hxx7cKRV/zak=; b=rUPqBI067t5aSHgeA u4gjiitDqk6Q4Y2KYWzQQ5HOrVzHo1QGMuUCp0M2NcFX/5YBlI/t+nq7VjjImsVJ ITxEErgu8JzCKY79iPuGDqRkUwEFVcXirlSTTHqLgHkQa5J5oS9+IDh8O67vCjhn E1FQcI/hNGdj5DDhewvjS9IrYQ= Received: (qmail 122296 invoked by alias); 24 Feb 2015 13:09:28 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 122285 invoked by uid 89); 24 Feb 2015 13:09:28 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 X-HELO: mo4-p00-ob.smtp.rzone.de Received: from mo4-p00-ob.smtp.rzone.de (HELO mo4-p00-ob.smtp.rzone.de) (81.169.146.217) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Tue, 24 Feb 2015 13:09:26 +0000 X-RZG-AUTH: :LXoWVUeid/7A29J/hMvvT3ol15ykJcYwTPbBBR62PQx1xqvTHw== X-RZG-CLASS-ID: mo00 Received: from [192.168.0.22] (ip5b43a95f.dynamic.kabel-deutschland.de [91.67.169.95]) by smtp.strato.de (RZmta 37.3 DYNA|AUTH) with ESMTPSA id w075e5r1OD9NOEF (using TLSv1.2 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate); Tue, 24 Feb 2015 14:09:23 +0100 (CET) Message-ID: <54EC7802.9030701@gjlay.de> Date: Tue, 24 Feb 2015 14:09:22 +0100 From: Georg-Johann Lay User-Agent: Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: GCC Patches CC: Denis Chertykov Subject: [patch, avr] Tidy up avr-log.c X-IsSubscribed: yes avr-log.c and respective macros in avr-protos.h still assume that the implementation language is C90, i.e. no variadic macros are available. This patch cleans up the code from the cumbersome old approach and uses variadic macros for avr_dump, avr_edump and avr_fdump. Ok for trunk? Johann 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. Index: config/avr/avr-log.c =================================================================== --- config/avr/avr-log.c (revision 220854) +++ config/avr/avr-log.c (working copy) @@ -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 @@ macros avr_edump or avr_fdump from avr-p /* 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 * 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 * /* FALLTHRU */ case '?': - avr_log_fdump_f (file, "%F[%f:%P]"); + avr_vdump (file, caller, "%F[%f:%P]"); break; case 'P': Index: config/avr/avr-protos.h =================================================================== --- config/avr/avr-protos.h (revision 220854) +++ config/avr/avr-protos.h (working copy) @@ -155,12 +155,11 @@ extern bool avr_have_dimode; /* 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