From patchwork Fri Dec 6 08:24:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1204955 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-515321-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="NdGvSMN8"; dkim-atps=neutral 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 47Tlxj249qz9sPW for ; Fri, 6 Dec 2019 19:24:38 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=XXRUr2+ZB1v8XEWO4SkKessQ+fjTNg8BNB4i37q26Whm4SqNvvzuo hZ2+fYeOpl6+oL09CPJdpy17O1eyh84KeGexIvAy0LS+S8qm4YHJYUK8q24oSJpI 6S3YXgjDkBF5X5ZBYghvt2ycSNw8cf12/h4vD7c8mnT5nM475/+eR0= 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:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=UIBQ2s0/3ZbKPyp1g5elYd2XFV0=; b=NdGvSMN87R177jeWFX3e AgMi2IowG5ts63cJTZA3yS+aFa3M4lQ16xyKAFoWo2GbPqWHu0FB3lxiqWVZmmF4 d33YBDdhOB19xpNyHKMgfwzl/3+ZG6mLCen3DNbCxRZ1T8jBg26oW+yWiGoa0UWX lPSLU4S6syVaJJnnOSI8Cw4= Received: (qmail 45541 invoked by alias); 6 Dec 2019 08:24:29 -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 45463 invoked by uid 89); 6 Dec 2019 08:24:21 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: mx1.suse.de Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 06 Dec 2019 08:24:10 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 25D6AB027 for ; Fri, 6 Dec 2019 08:24:07 +0000 (UTC) Date: Fri, 6 Dec 2019 09:24:06 +0100 (CET) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] Improve *-match.c debugging Message-ID: User-Agent: Alpine 2.21 (LSU 202 2017-01-01) MIME-Version: 1.0 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 * genmatch.c (c_expr::gen_transform): Emit newlines from line number changes rather than after every semicolon. 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. */