diff mbox

[nvptx] mkoffload cleanup

Message ID 55A04CE9.3000301@acm.org
State New
Headers show

Commit Message

Nathan Sidwell July 10, 2015, 10:53 p.m. UTC
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  <nathan@codesourcery.com>

	* config/nvptx/mkoffload.c (Q): New macro.
	(proacess): Use it for emitting code.

Comments

Bernd Schmidt July 10, 2015, 11:37 p.m. UTC | #1
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
diff mbox

Patch

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