From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 8TymJ2X7mmrw5CgAWB0awg (envelope-from ) for ; Fri, 04 Sep 2026 13:09:57 -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=v9M7s5MD; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 9B2ED1E033; Fri, 04 Sep 2026 13:09:57 -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 4F1011E033 for ; Fri, 04 Sep 2026 13:09:56 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6F4C94BB3BF5 for ; Fri, 4 Sep 2026 17:09:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6F4C94BB3BF5 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=v9M7s5MD Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id 9B4154BA2E0B for ; Fri, 4 Sep 2026 17:09:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9B4154BA2E0B 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 9B4154BA2E0B 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=EooM5MDD0+6s2DkkDRgwfqJDBi2rhfBvpiPgcdFJuu7VBhhcJWkph48rGcgU+U9HM3lIl6lBquK+L5h256IqG6mq06gvUE6eBEfEV0JQvuWjB7QuQzCEHavoq5NfLPXr8xv2WiSQ1IWN5kPI/umnQNcgPjZmotlXkOfy+1BzEyc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1788541763; c=relaxed/simple; bh=1OzafMihlJlRTd3GLDcnVBEIHqIQA1v1hM6ouoKgAO0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=wnl5rfXZt/7u9MWzAIqKqZVkUFjljjWilHHsbWsSLatmPk33H/Oc7QkGHKrULYoBC0sooAzY0ygkg2Cbknoxj1KGJXNU7UxhfnNyWpIWRJLT6SAc5fHB4DNchHttK6ilOsJ9I+a/UDlbq4O5ffrhWE+5McqrWsDJR80FgaaBwms= 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=v9M7s5MD DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9B4154BA2E0B 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 684H9G8F143744 (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 684H9G8F143744 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=polymtl.ca; s=oct2025; t=1788541762; bh=c+PBw5YSOltwVztlJf4zp8SOVT0eHlCLYUbjoHyGKyg=; h=From:To:Cc:Subject:Date:In-Reply-To:From; b=v9M7s5MD9im7OOksYHBCQ9ZsD67jFzE7VmGE+loy1k9oKFyq/DjvfrPH9xqbmNQ4B GfTZ41m2yNzQmaJm6O9sCog2NFMxfbTnU3MGS+tTxEdDgGX4kBr9LZ9Sp4Lb8iY1Vw OQjAIgMOFrynkUPftHQNlzmOQqvFAh2w22jPQ8fVh3pf4dzIeAe9qz8DYYoYIWLbwh fMtdibxud+hJMlLuAlE6UskOJHa1or+/b5vS6v8B2hoH6ipu43PipfgsQOSURa5Q1n sycX64TjaDUJFB7RyB/P1A/riTZxqwLNI+Azy562yactI75lw8xjTb+enKrKXWmD56 imHy4xYTcYUSA== Received: by simark.ca (Postfix) id F22C41E173; Fri, 04 Sep 2026 13:03:47 -0400 (EDT) From: simon.marchi@polymtl.ca To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 07/17] gdb: make $(YACC) and $(FLEX) generate headers Date: Fri, 4 Sep 2026 12:56:39 -0400 Message-ID: <20260904170338.1643894-8-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 I'd like to move the hand-written support code of parsers out of the .y files, because I find it very impractical to read and edit. C++ tooling also typically doesn't work for the C++ code inside .y files. To help with this, pass -d to $(YACC), so that it also produces header files exposing the generated parsers, allowing to call them from other files. I checked that the following yacc implementations support it: - bison - AIX (https://www.ibm.com/docs/en/aix/7.2.0?topic=y-yacc-command) - Solaris (https://docs.oracle.com/cd/E88353_01/html/E37839/yacc-1.html) - NetBSD (https://man.netbsd.org/yacc.1) - FreeBSD (https://man.freebsd.org/cgi/man.cgi?query=yacc&apropos=0&sektion=1&manpath=FreeBSD+15.1-RELEASE&arch=default&format=html) - OpenBSD (https://man.openbsd.org/yacc) Also pass `--header-file` to $(FLEX) to have it generate a header file. This is a flex-specific option, but a previous patch in this series (to use -P) already effectively required the use of flex. The post-processing must be applied to the header files exactly as it is applied to the source files (it contains declarations of things that get renamed by that post-processing), so call the post processing script for the headers too. Add the generated headers to generated_files, so they are created before anything that could include them is compiled. Change-Id: I7153f85c69e989b5a1e4318288b85ba4b456a319 --- gdb/.gitignore | 9 +++++++++ gdb/Makefile.in | 38 +++++++++++++++++++++++++------------- 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/gdb/.gitignore b/gdb/.gitignore index c4d0f0595448..6b5600dd695e 100644 --- a/gdb/.gitignore +++ b/gdb/.gitignore @@ -6,15 +6,24 @@ /xml-builtin.c /ada-exp-gen.c +/ada-exp-gen.h /ada-lex-gen.c +/ada-lex-gen.h /c-exp-gen.c +/c-exp-gen.h /cp-name-parser-gen.c +/cp-name-parser-gen.h /d-exp-gen.c +/d-exp-gen.h /f-exp-gen.c +/f-exp-gen.h /gdb /gcore /go-exp-gen.c +/go-exp-gen.h /init.c /jit-reader.h /m2-exp-gen.c +/m2-exp-gen.h /p-exp-gen.c +/p-exp-gen.h diff --git a/gdb/Makefile.in b/gdb/Makefile.in index daf5cf2baee1..e6c1587f4767 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -2071,9 +2071,12 @@ YYFILES = \ # a .o itself. YYOBJ = $(filter-out ada-lex-gen.o,$(patsubst %.c,%.o,$(YYFILES))) +# The headers bison/byacc and flex generate alongside the files above. +YYHFILES = $(patsubst %-gen.c,%-gen.h,$(YYFILES)) + # Things which need to be built when making a distribution. -DISTSTUFF = $(YYFILES) +DISTSTUFF = $(YYFILES) $(YYHFILES) # All generated files which can be included by another file. @@ -2081,6 +2084,7 @@ generated_files = \ ada-lex-gen.c \ config.h \ jit-reader.h \ + $(YYHFILES) \ $(NAT_GENERATED_FILES) \ $(NM_H) @@ -2437,7 +2441,7 @@ local-maintainer-clean: @echo "This command is intended for maintainers to use;" @echo "it deletes files that may require special tools to rebuild." rm -f TAGS - rm -f $(YYFILES) + rm -f $(YYFILES) $(YYHFILES) rm -f nm.h config.status do-maintainer-clean: @@ -2710,17 +2714,25 @@ YY_PREFIX_go-exp = go_yy YY_PREFIX_m2-exp = m2_yy YY_PREFIX_p-exp = pascal_yy -%-gen.c: %.y $(POST_PROCESS_PARSER_OUTPUT_SH) - $(ECHO_YACC) $(SHELL) $(YLWRAP) $< y.tab.c $@.tmp -- \ - $(YACC) $(YFLAGS) -p $(YY_PREFIX_$*) -t || (rm -f $@.tmp; false) - @$(POST_PROCESS_PARSER_OUTPUT) bison $* < $@.tmp > $@.new && \ - rm -f $@.tmp && \ - mv $@.new $@ -%-gen.c: %.l $(POST_PROCESS_PARSER_OUTPUT_SH) - $(ECHO_LEX) $(FLEX) -t -P $(YY_PREFIX_$*) $< > $@.tmp || (rm -f $@.tmp; false) - @$(POST_PROCESS_PARSER_OUTPUT) flex $* < $@.tmp > $@.new && \ - rm -f $@.tmp && \ - mv $@.new $@ +%-gen.c %-gen.h: %.y $(POST_PROCESS_PARSER_OUTPUT_SH) + $(ECHO_YACC) $(SHELL) $(YLWRAP) $< \ + y.tab.c $*-gen.c.tmp \ + y.tab.h $*-gen.h.tmp -- \ + $(YACC) $(YFLAGS) -p $(YY_PREFIX_$*) -t -d \ + || (rm -f $*-gen.c.tmp $*-gen.h.tmp; false) + @$(POST_PROCESS_PARSER_OUTPUT) bison $* < $*-gen.c.tmp > $*-gen.c.new \ + && rm -f $*-gen.c.tmp && mv $*-gen.c.new $*-gen.c + @$(POST_PROCESS_PARSER_OUTPUT) bison $* < $*-gen.h.tmp > $*-gen.h.new \ + && rm -f $*-gen.h.tmp && mv $*-gen.h.new $*-gen.h + +%-gen.c %-gen.h: %.l $(POST_PROCESS_PARSER_OUTPUT_SH) + $(ECHO_LEX) $(FLEX) -t -P $(YY_PREFIX_$*) \ + --header-file=$*-gen.h.tmp $< > $*-gen.c.tmp \ + || (rm -f $*-gen.c.tmp $*-gen.h.tmp; false) + @$(POST_PROCESS_PARSER_OUTPUT) flex $* < $*-gen.c.tmp > $*-gen.c.new \ + && rm -f $*-gen.c.tmp && mv $*-gen.c.new $*-gen.c + @$(POST_PROCESS_PARSER_OUTPUT) flex $* < $*-gen.h.tmp > $*-gen.h.new \ + && rm -f $*-gen.h.tmp && mv $*-gen.h.new $*-gen.h # XML rules -- 2.55.0