diff mbox series

Improve *-match.c debugging

Message ID nycvar.YFH.7.76.1912060922240.5566@zhemvz.fhfr.qr
State New
Headers show
Series Improve *-match.c debugging | expand

Commit Message

Richard Biener Dec. 6, 2019, 8:24 a.m. UTC
The following more closely re-emits C expressions by emitting line
breaks whenever the source line location changes rather than only
after ;

This makes 'n' debugging easier.

I've only briefly tried to reconstruct the original source but
failed.  I guess the pp tokens do not contain enough information here.

Bootstrapped on x86_64-unknown-linux-gnu, applied.

Richard.

2019-12-06  Richard Biener  <rguenther@suse.de>

	* genmatch.c (c_expr::gen_transform): Emit newlines from line
	number changes rather than after every semicolon.
diff mbox series

Patch

Index: gcc/genmatch.c
===================================================================
--- gcc/genmatch.c	(revision 279033)
+++ gcc/genmatch.c	(working copy)
@@ -2599,10 +2599,22 @@  c_expr::gen_transform (FILE *f, int inde
     fprintf_indent (f, indent, "%s = ", dest);
 
   unsigned stmt_nr = 1;
+  int prev_line = -1;
   for (unsigned i = 0; i < code.length (); ++i)
     {
       const cpp_token *token = &code[i];
 
+      /* We can't recover from all lexing losses but we can roughly restore line
+         breaks from location info.  */
+      const line_map_ordinary *map;
+      linemap_resolve_location (line_table, token->src_loc,
+				LRK_SPELLING_LOCATION, &map);
+      expanded_location loc = linemap_expand_location (line_table, map,
+						       token->src_loc);
+      if (prev_line != -1 && loc.line != prev_line)
+	fputc ('\n', f);
+      prev_line = loc.line;
+
       /* Replace captures for code-gen.  */
       if (token->type == CPP_ATSIGN)
 	{
@@ -2653,11 +2665,11 @@  c_expr::gen_transform (FILE *f, int inde
       if (token->type == CPP_SEMICOLON)
 	{
 	  stmt_nr++;
-	  fputc ('\n', f);
 	  if (dest && stmt_nr == nr_stmts)
 	    fprintf_indent (f, indent, "%s = ", dest);
 	}
     }
+  fputc ('\n', f);
 }
 
 /* Generate transform code for a capture.  */