From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id eV/6I5X7mmrw5CgAWB0awg (envelope-from ) for ; Fri, 04 Sep 2026 13:10:45 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=polymtl.ca header.i=@polymtl.ca header.a=rsa-sha256 header.s=oct2025 header.b=D9nvGU0C; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 856761E033; Fri, 04 Sep 2026 13:10:45 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [IPv6:2620:52:6:3111::32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 703311E033 for ; Fri, 04 Sep 2026 13:10:44 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1D82D4BB3BB5 for ; Fri, 4 Sep 2026 17:10:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1D82D4BB3BB5 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=polymtl.ca header.i=@polymtl.ca header.a=rsa-sha256 header.s=oct2025 header.b=D9nvGU0C Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id A2DEC4BA2E0E for ; Fri, 4 Sep 2026 17:09:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A2DEC4BA2E0E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=polymtl.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=polymtl.ca ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A2DEC4BA2E0E Authentication-Results: sourceware.org; arc=none smtp.remote-ip=132.207.4.11 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1788541763; cv=none; b=CusgYq9LAQkTL71ZjvB8IEen5zoE1ftVTt+ibGzDT2ZANxFltV+iUUZ87lqgLSrxkWjLM7UO9c8MIxjEqqeemNKI27SjF+fPrlLeHl5AZUQjqzBKae/LycZNU0B6B+ZDc/+6hehDJkPUtZbicy/3tmsfz1doiN3cLwn5BUjQGbk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1788541763; c=relaxed/simple; bh=yxdYkABNu1b1HdJpxKdd/e510ZoRDBIhLtc1G9IPHIA=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=nndKkprov3X5bimcql/N6Zj8WhQ24CSMeqFf74y9wr8HLO3rfGQTptgWlUXLCsjd6+8D3EkQAUVdeXhsxpEGTn/WrJDG8zDIiRTlV9FD/NNJcDaoY6RW6QYAnGgh8hFT+L9yy6pHL++g6YCntCNN7eo1mNPQYjwpX7xE6pB+SwM= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=polymtl.ca header.i=@polymtl.ca header.a=rsa-sha256 header.s=oct2025 header.b=D9nvGU0C DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A2DEC4BA2E0E Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 684H9Go4143742 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 4 Sep 2026 13:09:21 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 684H9Go4143742 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=polymtl.ca; s=oct2025; t=1788541762; bh=0xfk5CX9rGosBgNgluNjUYWptVGxEdQ1xEZsZxrjP7s=; h=From:To:Cc:Subject:Date:In-Reply-To:From; b=D9nvGU0CjR/8LNQjYnxtP5LYV/1jxIrKpRzpRyY4dgVXlCo7/GGNRAJRRw9DVVkSL sErOmJaWvcFu/OBFKPDgnvjMxMopxdkac4fsA4jyccDxDz5b2ynuGAseEKKDp0w9h7 5uWrsYNuNEc9qOFtTMGbph1qVNab3yX9wbbuxpCJ8+9zVdUGy4znl4YdUxcy3A0D7D tKoz5MvAqSEp6doAT6yGuNT51j2ZK3hlAVgIJGWrWdUtgiNogo/4VkaVEhX9Pa/5/O tlcivYbB6+nxRA7r18GqpKkneSRlsZTq9fRFxf7e4jiFz8cMriKgxqrY860ipUSTAa NcdjGs24kJfJQ== Received: by simark.ca (Postfix) id 691181E168; Fri, 04 Sep 2026 13:03:47 -0400 (EDT) From: simon.marchi@polymtl.ca To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 04/17] gdb: move parser output post-processing to a script Date: Fri, 4 Sep 2026 12:56:36 -0400 Message-ID: <20260904170338.1643894-5-simon.marchi@polymtl.ca> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260904170338.1643894-1-simon.marchi@polymtl.ca> References: <20260904170338.1643894-1-simon.marchi@polymtl.ca> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Fri, 4 Sep 2026 17:09:17 +0000 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org From: Simon Marchi The output of bison and flex needs some post-processing before being compiled. It is currently done by a sed invocation inlined in each of the two pattern rules, which is kind of hard to read and modify. Additionally, a following patch adds the generation of header files for parsers, and those will need the same post processing. Moving the code to a dedicated script makes re-use easier. Move the code to post-process-parser-output.sh, which takes the name of the parser generator (flex or bison), just to know which substitutions to do, as well as the name of the parser file. Make the Makefile rules depend on the script, so that the parsers are regenerated when it changes. Change-Id: I15f43184034aff33d242052db79586980ec2dac0 --- gdb/Makefile.in | 39 +++++------------- gdb/post-process-parser-output.sh | 67 +++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 28 deletions(-) create mode 100755 gdb/post-process-parser-output.sh diff --git a/gdb/Makefile.in b/gdb/Makefile.in index aeafb9394d7b..80b2f8573294 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -2693,39 +2693,22 @@ po/$(PACKAGE).pot: force %.c: %.y %.c: %.l -%-gen.c: %.y +# Post-process a file produced by a parser generator, see the script +# for details. +POST_PROCESS_PARSER_OUTPUT_SH = $(srcdir)/post-process-parser-output.sh +POST_PROCESS_PARSER_OUTPUT = $(SHELL) $(POST_PROCESS_PARSER_OUTPUT_SH) + +%-gen.c: %.y $(POST_PROCESS_PARSER_OUTPUT_SH) $(ECHO_YACC) $(SHELL) $(YLWRAP) $< y.tab.c $@.tmp -- \ $(YACC) $(YFLAGS) || (rm -f $@.tmp; false) - @sed -e '/extern.*malloc/d' \ - -e '/extern.*realloc/d' \ - -e '/extern.*free/d' \ - -e '/include.*malloc.h/d' \ - -e 's/\([^x]\)malloc/\1xmalloc/g' \ - -e 's/\([^x]\)realloc/\1xrealloc/g' \ - -e 's/\([ \t;,(]\)free\([ \t]*[&(),]\)/\1xfree\2/g' \ - -e 's/\([ \t;,(]\)free$$/\1xfree/g' \ - -e '/^#line.*y.tab.c/d' \ - -e 's/YY_NULL/YY_NULLPTR/g' \ - -e "s/YYSTYPE/$(subst -,_,$*)_YYSTYPE/g" \ - -e "s/yyalloc/$(subst -,_,$*)_yyalloc/g" \ - -e "s/yysymbol_kind_t/$(subst -,_,$*)_yysymbol_kind_t/g" \ - < $@.tmp > $@.new && \ + @$(POST_PROCESS_PARSER_OUTPUT) bison $* < $@.tmp > $@.new && \ rm -f $@.tmp && \ mv $@.new $@ -%-gen.c: %.l +%-gen.c: %.l $(POST_PROCESS_PARSER_OUTPUT_SH) $(ECHO_LEX) $(FLEX) -t $< > $@.tmp || (rm -f $@.tmp; false) - @sed -e '/extern.*malloc/d' \ - -e '/extern.*realloc/d' \ - -e '/extern.*free/d' \ - -e '/include.*malloc.h/d' \ - -e 's/\([^x]\)malloc/\1xmalloc/g' \ - -e 's/\([^x]\)realloc/\1xrealloc/g' \ - -e 's/\([ \t;,(]\)free\([ \t]*[&(),]\)/\1xfree\2/g' \ - -e 's/\([ \t;,(]\)free$$/\1xfree/g' \ - -e 's/yy_flex_xrealloc/yyxrealloc/g' \ - < $@.tmp > $@.new && \ - rm -f $@.tmp && \ - mv $@.new $@ + @$(POST_PROCESS_PARSER_OUTPUT) flex $* < $@.tmp > $@.new && \ + rm -f $@.tmp && \ + mv $@.new $@ # XML rules diff --git a/gdb/post-process-parser-output.sh b/gdb/post-process-parser-output.sh new file mode 100755 index 000000000000..b246e63ddff1 --- /dev/null +++ b/gdb/post-process-parser-output.sh @@ -0,0 +1,67 @@ +#!/bin/sh + +# Copyright (C) 2026 Free Software Foundation, Inc. +# +# This file is part of GDB. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Post-process a file produced by flex or bison/byacc, reading it from +# standard input and writing the result to standard output. +# +# Usage: +# +# ./post-process-parser-output.sh GENERATOR NAME < INPUT > OUTPUT +# +# Where GENERATOR is "bison" (regardless of whether we're using the actual +# bison or byacc) or "flex", and NAME is the name of the parser (e.g. +# "cp-name-parser"), used to make the global symbols names bison produces +# unique. + +set -e + +generator="$1" + +# Convert e.g. "cp-name-parser" to "cp_name_parser". +name=$(echo "$2" | sed -e 's/-/_/g') + +common=' +/extern.*malloc/d +/extern.*realloc/d +/extern.*free/d +/include.*malloc.h/d +s/\([^x]\)malloc/\1xmalloc/g +s/\([^x]\)realloc/\1xrealloc/g +s/\([ \t;,(]\)free\([ \t]*[&(),]\)/\1xfree\2/g +s/\([ \t;,(]\)free$/\1xfree/g +' + +case "$generator" in + bison) + sed -e "$common" \ + -e '/^#line.*y.tab.c/d' \ + -e 's/YY_NULL/YY_NULLPTR/g' \ + -e "s/YYSTYPE/${name}_YYSTYPE/g" \ + -e "s/yyalloc/${name}_yyalloc/g" \ + -e "s/yysymbol_kind_t/${name}_yysymbol_kind_t/g" + ;; + flex) + sed -e "$common" \ + -e 's/yy_flex_xrealloc/yyxrealloc/g' + ;; + *) + echo "$0: unknown parser generator \"$generator\"" >&2 + exit 1 + ;; +esac -- 2.55.0