From patchwork Fri Jul 10 22:53:29 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 493886 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 8E8751402B6 for ; Sat, 11 Jul 2015 08:53:44 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=WXac3DWi; dkim-atps=neutral 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=tnaNcCqOmI9TIN1J6BeSlI3NalBQv76YWRhEsJpujhy u07Hx+fpzevput3L2hupdGLGJQ1bBrTllatNVyVlVRad+CAUBYV7D/E7i0rFCO9R wxubhJY8lC5CvIKtbo9GEsvuuhUpirq7el1pWw1PPb6nYEK/1607j2gK1UyYpt5s = 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=+8zj7HV1DIJ/4TgtHBrWeNIsZog=; b=WXac3DWi52GQj9wnG GVASfNefoyjfQ3Z6O4sj+5XDJpvGSgDqEcSaTWSMuvLg+8Splpumh2CnwV6ocCgK 5MqoMYVgfV/DJucpKzCYe/3zQdmr/oAsO8TKj665xb0OSFDQIndGD2CqhoMCwdj2 iESowAO2gx4tBTBqWhX7Nj1y88= Received: (qmail 99447 invoked by alias); 10 Jul 2015 22:53:36 -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 99437 invoked by uid 89); 10 Jul 2015 22:53:35 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-qk0-f174.google.com Received: from mail-qk0-f174.google.com (HELO mail-qk0-f174.google.com) (209.85.220.174) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Fri, 10 Jul 2015 22:53:33 +0000 Received: by qkhu186 with SMTP id u186so216844077qkh.0 for ; Fri, 10 Jul 2015 15:53:31 -0700 (PDT) X-Received: by 10.140.149.76 with SMTP id 73mr39005530qhv.94.1436568811673; Fri, 10 Jul 2015 15:53:31 -0700 (PDT) Received: from ?IPv6:2601:19b:400:a983:a2a8:cdff:fe3e:b48? ([2601:19b:400:a983:a2a8:cdff:fe3e:b48]) by smtp.googlemail.com with ESMTPSA id 25sm6361365qkw.13.2015.07.10.15.53.30 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 Jul 2015 15:53:31 -0700 (PDT) Message-ID: <55A04CE9.3000301@acm.org> Date: Fri, 10 Jul 2015 18:53:29 -0400 From: Nathan Sidwell User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: Bernd Schmidt CC: GCC Patches Subject: [nvptx] mkoffload cleanup Bernd, I'mm working through the mkoffload machinery. mkoffload.c emits a C file, and the quoting in the source is quite confusing. This patch introduces a quoting macro 'Q' that allows one to write raw C to be stringized and written out. ok? (more cleanups to follow) nathan 2015-07-10 Nathan Sidwell * config/nvptx/mkoffload.c (Q): New macro. (proacess): Use it for emitting code. Index: config/nvptx/mkoffload.c =================================================================== --- config/nvptx/mkoffload.c (revision 225703) +++ config/nvptx/mkoffload.c (working copy) @@ -37,6 +37,10 @@ #include "collect-utils.h" #include "gomp-constants.h" +/* Quoter macro so that one can write unquoted 'C' for printfs. + Sadly all white space is collapsed. */ +#define Q(...) #__VA_ARGS__ "\n" + const char tool_name[] = "nvptx mkoffload"; #define COMMENT_PREFIX "#" @@ -269,37 +273,41 @@ process (FILE *in, FILE *out) unsigned int nvars = 0, nfuncs = 0; - fprintf (out, "static const char *var_mappings[] = {\n"); + fprintf (out, + Q (static const char *const var_mappings[] = {)); for (id_map *id = var_ids; id; id = id->next, nvars++) fprintf (out, "\t\"%s\"%s\n", id->ptx_name, id->next ? "," : ""); - fprintf (out, "};\n\n"); - fprintf (out, "static const char *func_mappings[] = {\n"); + fprintf (out, Q (};)); + + fprintf (out, Q (static const char *const func_mappings[] = {)); for (id_map *id = func_ids; id; id = id->next, nfuncs++) fprintf (out, "\t\"%s\"%s\n", id->ptx_name, id->next ? "," : ""); - fprintf (out, "};\n\n"); + fprintf (out, Q(};)); - fprintf (out, "static const void *target_data[] = {\n"); - fprintf (out, " ptx_code, (void *)(__UINTPTR_TYPE__)sizeof (ptx_code),\n"); - fprintf (out, " (void *) %u, var_mappings, (void *) %u, func_mappings\n", + fprintf (out, + Q (static const void *target_data[] = { + ptx_code, (void *)(__UINTPTR_TYPE__)sizeof (ptx_code), + (void *) %u, var_mappings, (void *) %u, func_mappings};), nvars, nfuncs); - fprintf (out, "};\n\n"); - - fprintf (out, "#ifdef __cplusplus\n"); - fprintf (out, "extern \"C\" {\n"); - fprintf (out, "#endif\n"); - - fprintf (out, "extern void GOMP_offload_register (const void *, int, void *);\n"); - - fprintf (out, "#ifdef __cplusplus\n"); - fprintf (out, "}\n"); - fprintf (out, "#endif\n"); - fprintf (out, "extern void *__OFFLOAD_TABLE__[];\n\n"); - fprintf (out, "static __attribute__((constructor)) void init (void)\n{\n"); - fprintf (out, " GOMP_offload_register (__OFFLOAD_TABLE__, %d,\n", + fprintf (out, Q (#ifdef __cplusplus)); + fprintf (out, Q (extern "C" {)); + fprintf (out, Q (#endif)); + + fprintf (out, + Q (extern void GOMP_offload_register (const void *, int, void *);)); + + fprintf (out, Q (#ifdef __cplusplus)); + fprintf (out, Q (})); + fprintf (out, Q (#endif)); + + fprintf (out, + Q (extern void *__OFFLOAD_TABLE__[]; + static __attribute__((constructor)) void init (void) + { + GOMP_offload_register (__OFFLOAD_TABLE__, %d, &target_data); + }), GOMP_DEVICE_NVIDIA_PTX); - fprintf (out, " &target_data);\n"); - fprintf (out, "};\n"); } static void