Subject: Re: bug#41615: [feature/native-comp] Dump prettier C code.

From: Andrea Corallo <[email-masked]>
Date: Sun, 31 May 2020 11:37:50 +0000

Nicolas Bértolo <[email-masked]> writes:

> I have reformatted the patches.
>
> Sorry for the inconveniences.
>
>
> From 0720ec7eb3dc552b018273cd68a5f7d6bb2fdb72 Mon Sep 17 00:00:00 2001
> From: =?UTF-8?q?Nicol=C3=A1s=20B=C3=A9rtolo?= <[email-masked]>
> Date: Wed, 20 May 2020 00:34:32 -0300
> Subject: [PATCH 1/2] Define static data using string literals.
>
> The purpose of this change is to dump prettier C files.
> This does not affect compilation times in my tests.
>
> * src/comp.c (emit_static_object): Define static objects using string
> literals, memcpy and bzero.
> ---
>  src/comp.c | 295 +++++++++++++++++++++++++++++++++++++++++++++++++----
>  1 file changed, 277 insertions(+), 18 deletions(-)

I like this considerably less :)

It introduces quite some complexity and the same advantage in
debuggability can be achieved with something like the attached 8 line
patch (untested).

Generally speaking I want to try to keep our back-end as simple as we
manage to.

On the subject of 'emit_static_object' the current situation is not
ideal.  But rather that working around the workaround I believe the right
thing to do is to improve GCC with a new entry point and keep the
current arrangement as a simple fallback.

I've already an half cooked GCC patch to allow for directly injecting
blobs, this should have more then one advantage.  Hopefully I manage to
start testing it today, I'm rather curious.

Andrea

-- 
[email-masked]
>From 2154060e21c6d74d46cf274abaa716bec8fd2ac5 Mon Sep 17 00:00:00 2001
From: Andrea Corallo <[email-masked]>
Date: Sun, 31 May 2020 12:22:46 +0100
Subject: [PATCH] * Emit better debug comments in emit_static_object

	* src/comp.c (emit_static_object): Do not truncate debug
	comments at the first NULL character.
---
 src/comp.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/comp.c b/src/comp.c
index d3bff1e4cf..179e97a551 100644
--- a/src/comp.c
+++ b/src/comp.c
@@ -2392,8 +2392,12 @@ emit_static_object (const char *name, Lisp_Object obj)
 				  0, NULL, 0);
   DECL_BLOCK (block, f);
 
-  /* NOTE this truncates if the data has some zero byte before termination.  */
-  gcc_jit_block_add_comment (block, NULL, p);
+  char *comment = memcpy (xmalloc (len), p, len);
+  for (ptrdiff_t i = 0; i < len - 1; i++)
+    if (!comment[i])
+      comment[i] = '\n';
+  gcc_jit_block_add_comment (block, NULL, comment);
+  xfree (comment);
 
   gcc_jit_lvalue *arr =
       gcc_jit_lvalue_access_field (data_struct, NULL, fields[1]);
-- 
2.17.1