public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [nvptx] mkoffload cleanup
@ 2015-07-10 22:53 Nathan Sidwell
  2015-07-10 23:38 ` Bernd Schmidt
  0 siblings, 1 reply; 2+ messages in thread
From: Nathan Sidwell @ 2015-07-10 22:53 UTC (permalink / raw)
  To: Bernd Schmidt; +Cc: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 281 bytes --]

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

[-- Attachment #2: mkoff.diff --]
[-- Type: text/plain, Size: 2966 bytes --]

2015-07-10  Nathan Sidwell  <nathan@codesourcery.com>

	* 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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [nvptx] mkoffload cleanup
  2015-07-10 22:53 [nvptx] mkoffload cleanup Nathan Sidwell
@ 2015-07-10 23:38 ` Bernd Schmidt
  0 siblings, 0 replies; 2+ messages in thread
From: Bernd Schmidt @ 2015-07-10 23:38 UTC (permalink / raw)
  To: Nathan Sidwell; +Cc: GCC Patches

On 07/11/2015 12:53 AM, Nathan Sidwell wrote:
> 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)

The quoting is fairly standard and used throughout gcc, and I guess I'm 
kind of used to seeing it - the patch would make things inconsistent 
with everything else. It's also nonobvious and probably unintentional 
that indentation and linebreaks get lost in some places in the output 
when the patch is applied - the following is emitted as a single line:

extern void *__OFFLOAD_TABLE__[]; static __attribute__((constructor)) 
void init (void) { GOMP_offload_register (__OFFLOAD_TABLE__, 5, 
&target_data); }

So, I'm sorry - not a fan of this.


Bernd

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-07-10 23:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-10 22:53 [nvptx] mkoffload cleanup Nathan Sidwell
2015-07-10 23:38 ` Bernd Schmidt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).