From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id Gf7JAf+Zm2pT4SsAWB0awg (envelope-from ) for ; Sat, 05 Sep 2026 00:26:39 -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=bttWh+ky; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 036B01E09E; Sat, 05 Sep 2026 00:26:39 -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 1919B1E091 for ; Sat, 05 Sep 2026 00:26:38 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AEA104BB5918 for ; Sat, 5 Sep 2026 04:26:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AEA104BB5918 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=bttWh+ky Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id 9F7F64BA2E1B for ; Sat, 5 Sep 2026 04:26:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9F7F64BA2E1B 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 9F7F64BA2E1B 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=1788582367; cv=none; b=TeS62HqM6YPMd7hSigCgkZq0MZkEHLDLVJf3AlUJCYJnJDESpOe7j3ipyUUXAleZzh6x/TeRxoULZ8PWDdyxrgitS21OOnWNvRqch8J6lGb8X01GHF7rHmi7ySKzTwMiXVGY4hoI8IsGE+c+m91ueVnzqU1gdpu2f6yEfPuPLxo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1788582367; c=relaxed/simple; bh=1OzafMihlJlRTd3GLDcnVBEIHqIQA1v1hM6ouoKgAO0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=TcImVLTxG9fm/cSk7Gcn8YYcdHJNxCld4LDuNwE9SIbVRjZDjFK6qTJZSjyXL+GJyjCUoSXLJq0rli+hR6HP+Z3DUeCrA1OsvFd1KxpecJ7hXApJP5lx8DhzT+lkHkfeTtk+Mhnf7bvBZj5OOebelNKNtqMyF45cG8Q6kRwSsB8= 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=bttWh+ky DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9F7F64BA2E1B 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 6854Q15Y081798 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 5 Sep 2026 00:26:06 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 6854Q15Y081798 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=polymtl.ca; s=oct2025; t=1788582366; bh=c+PBw5YSOltwVztlJf4zp8SOVT0eHlCLYUbjoHyGKyg=; h=From:To:Cc:Subject:Date:In-Reply-To:From; b=bttWh+ky6AHf6wQIVYt2lIF2mhx/uVpA5k4fY+hsvR6BFS64XVxjSXJJW8BUqPe3N He/q0gHPVMrV5Xpwayus7wNI/9v/NmY9z8goazOPeZQktQyf+3SgoeZ8vVKF89PFXB CdusVsWxl8T8Lm0pLFywegw/dk785iLfPT3LgAFeQKkGeXG76Cjbc6tTv0ySx9U4MN LnTQqYAH3vbo8HlVKjidt4LwC83JAybp8elYZjyfIPidmfSYKAJcF4pPN0hcwZSqOu y7T7OiNzVHfUt1euS5vwfh46SXNYRIY76fUlryO7evYhqCKhXroUXnP1U/+bCsBIDA FVJ1ByoOlH2lA== Received: by simark.ca (Postfix) id CF27E1E091; Sat, 05 Sep 2026 00:26:00 -0400 (EDT) From: simon.marchi@polymtl.ca To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH v2 08/19] gdb: make $(YACC) and $(FLEX) generate headers Date: Sat, 5 Sep 2026 00:23:11 -0400 Message-ID: <20260905042353.1702204-9-simon.marchi@polymtl.ca> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260905042353.1702204-1-simon.marchi@polymtl.ca> References: <20260905042353.1702204-1-simon.marchi@polymtl.ca> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Sat, 5 Sep 2026 04:26:01 +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