From patchwork Mon May 8 18:13:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Monakov X-Patchwork-Id: 91222 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2340970vqo; Mon, 8 May 2023 11:15:44 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5xijXNInTuJP7Ba66hiL6vGRmeC9Js5efI0TcdDg1/toTPLZqASys2W0oQ/3Y5DmfvBRmt X-Received: by 2002:a17:907:7e8e:b0:965:b38f:490d with SMTP id qb14-20020a1709077e8e00b00965b38f490dmr10346678ejc.63.1683569744108; Mon, 08 May 2023 11:15:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683569744; cv=none; d=google.com; s=arc-20160816; b=r40J3mz+0W4Y14cCkD9TaBu8XlYR2aTlImADrurZ99Aa2qCAGCbPHP6I5/1qflBGcf jC6xE09ulzLWlp5tujKMmUaiRfXbZeTM2lEVbm5LsQxG6O3v1Cg3GfoM/KhN0oDWTiSi Oos3iLZ8XT8XAO8tVb8MBBkt2vTq5k8XkJaVPrWkXJgzAoO8KY/qpv2jgcEA2z3gTIC2 bzvtWUBBCvjc9n2xyB1dNQQ/j6kcvHF9eGN+XXNCH0rXgXr+D69VbTnBXMFQzb/F0DV0 B0OyL9eIoBTn/r7KRS1S8Xnd8OpAoVSogZGXEbRaN5HVVNncuqTvbc5zCOIpAOCmGpNm bYGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dkim-filter:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=Xbm3j+Lc8oUX4o52PXBAZwUIbQPcAnjMUu3kiIhW4q8=; b=eAfMEEZ4fGE2IKUTR4jyqJluDyg1LrtDkhvHqCnRHHeHSDUXlvKMTe5+IFMuTD0kzs li7DqbxHmUMgeADbNH+d+rLCP/+LBZmkimBOubFfh3Nknrkr3JgmJiLgf2pmItRGlCrh Ic36GNRaU89yCqZnXg0/zdSYAgRS5/9kz/GCFg+A9/R0K17PiWfKPRewZSjuf24bzo2A B8tXHGaUKlwjYfc5yE8DOkE6H7W8lrHl40V6dIj9EpPX3kEdKj5/qEEh2Tgo0D+InR5J e868SuHTIa00kdvyWy+yWWtgEgxJXfoWGndc5FTn1Mh4BVOOYl+1hG3OWn90oUFoaxBY tTLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=vQFM9y+o; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id h25-20020a17090634d900b009537f634c45si291626ejb.585.2023.05.08.11.15.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 May 2023 11:15:44 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=vQFM9y+o; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 07865385E45B for ; Mon, 8 May 2023 18:15:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 07865385E45B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1683569706; bh=Xbm3j+Lc8oUX4o52PXBAZwUIbQPcAnjMUu3kiIhW4q8=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=vQFM9y+omOxwcIqxElPTsRpjI9k4kZVRlMDuNclYkYnxN5SBSuIA+0k9//5Hl0A0B Q7VUwN+lQbON5B38agp0XSZTQFSbJi3owl2aOMDG24I44MZcfSFPtlCPs3wgGqaMou ZysC5jtptGUFshnZCmm/WVPbTSWrV2kV21OVWr3g= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by sourceware.org (Postfix) with ESMTPS id A31753858D32 for ; Mon, 8 May 2023 18:13:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A31753858D32 Received: from localhost.intra.ispras.ru (unknown [10.10.3.121]) by mail.ispras.ru (Postfix) with ESMTP id 05BC144C1012; Mon, 8 May 2023 18:13:19 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru 05BC144C1012 To: gcc-patches@gcc.gnu.org Cc: Alexander Monakov Subject: [PATCH 1/3] genmatch: clean up emit_func Date: Mon, 8 May 2023 21:13:09 +0300 Message-Id: <20230508181311.25961-2-amonakov@ispras.ru> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20230508181311.25961-1-amonakov@ispras.ru> References: <20230508181311.25961-1-amonakov@ispras.ru> MIME-Version: 1.0 X-Spam-Status: No, score=-9.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Alexander Monakov via Gcc-patches From: Alexander Monakov Reply-To: Alexander Monakov Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765350828055670894?= X-GMAIL-MSGID: =?utf-8?q?1765350828055670894?= Eliminate boolean parameters of emit_func. The first ('open') just prints 'extern' to generated header, which is unnecessary. Introduce a separate function to use when finishing a declaration in place of the second ('close'). Rename emit_func to 'fp_decl' (matching 'fprintf' in length) to unbreak indentation in several places. Reshuffle emitted line breaks in a few places to make generated declarations less ugly. gcc/ChangeLog: * genmatch.cc (header_file): Make static. (emit_func): Rename to... (fp_decl): ... this. Adjust all uses. (fp_decl_done): New function. Use it... (decision_tree::gen): ... here and... (write_predicate): ... here. (main): Adjust. --- gcc/genmatch.cc | 97 ++++++++++++++++++++++++++----------------------- 1 file changed, 52 insertions(+), 45 deletions(-) diff --git a/gcc/genmatch.cc b/gcc/genmatch.cc index c593814871..d5e56e2d68 100644 --- a/gcc/genmatch.cc +++ b/gcc/genmatch.cc @@ -183,31 +183,37 @@ fprintf_indent (FILE *f, unsigned int indent, const char *format, ...) va_end (ap); } -/* Like fprintf, but print to two files, one header one C implementation. */ -FILE *header_file = NULL; +/* Secondary stream for fp_decl. */ +static FILE *header_file; +/* Start or continue emitting a declaration in fprintf-like manner, + printing both to F and global header_file, if non-null. */ static void #if GCC_VERSION >= 4001 -__attribute__((format (printf, 4, 5))) +__attribute__((format (printf, 2, 3))) #endif -emit_func (FILE *f, bool open, bool close, const char *format, ...) +fp_decl (FILE *f, const char *format, ...) { - va_list ap1, ap2; - if (header_file != NULL) - { - if (open) - fprintf (header_file, "extern "); - va_start (ap2, format); - vfprintf (header_file, format, ap2); - va_end (ap2); - if (close) - fprintf (header_file, ";\n"); - } + va_list ap; + va_start (ap, format); + vfprintf (f, format, ap); + va_end (ap); - va_start (ap1, format); - vfprintf (f, format, ap1); - va_end (ap1); - fputc ('\n', f); + if (!header_file) + return; + + va_start (ap, format); + vfprintf (header_file, format, ap); + va_end (ap); +} + +/* Finish a declaration being emitted by fp_decl. */ +static void +fp_decl_done (FILE *f, const char *trailer) +{ + fprintf (f, "%s\n", trailer); + if (header_file) + fprintf (header_file, "%s;", trailer); } static void @@ -3924,35 +3930,35 @@ decision_tree::gen (vec &files, bool gimple) s->fname = xasprintf ("%s_simplify_%u", gimple ? "gimple" : "generic", fcnt++); if (gimple) - emit_func (f, true, false, "\nbool\n" + fp_decl (f, "\nbool\n" "%s (gimple_match_op *res_op, gimple_seq *seq,\n" " tree (*valueize)(tree) ATTRIBUTE_UNUSED,\n" " const tree ARG_UNUSED (type), tree *ARG_UNUSED " - "(captures)\n", + "(captures)", s->fname); else { - emit_func (f, true, false, "\ntree\n" + fp_decl (f, "\ntree\n" "%s (location_t ARG_UNUSED (loc), const tree ARG_UNUSED (type),\n", (*iter).second->fname); for (unsigned i = 0; i < as_a (s->s->s->match)->ops.length (); ++i) - emit_func (f, false, false, " tree ARG_UNUSED (_p%d),", i); - emit_func (f, false, false, " tree *captures\n"); + fp_decl (f, " tree ARG_UNUSED (_p%d),", i); + fp_decl (f, " tree *captures"); } for (unsigned i = 0; i < s->s->s->for_subst_vec.length (); ++i) { if (! s->s->s->for_subst_vec[i].first->used) continue; if (is_a (s->s->s->for_subst_vec[i].second)) - emit_func (f, false, false, ", const enum tree_code ARG_UNUSED (%s)", + fp_decl (f, ",\n const enum tree_code ARG_UNUSED (%s)", s->s->s->for_subst_vec[i].first->id); else if (is_a (s->s->s->for_subst_vec[i].second)) - emit_func (f, false, false, ", const combined_fn ARG_UNUSED (%s)", + fp_decl (f, ",\n const combined_fn ARG_UNUSED (%s)", s->s->s->for_subst_vec[i].first->id); } - emit_func (f, false, true, ")"); + fp_decl_done (f, ")"); fprintf (f, "{\n"); fprintf_indent (f, 2, "const bool debug_dump = " "dump_file && (dump_flags & TDF_FOLDING);\n"); @@ -3988,22 +3994,22 @@ decision_tree::gen (vec &files, bool gimple) FILE *f = get_out_file (files); if (gimple) - emit_func (f, true, false,"\nbool\n" + fp_decl (f, "\nbool\n" "gimple_simplify_%s (gimple_match_op *res_op," " gimple_seq *seq,\n" " tree (*valueize)(tree) " "ATTRIBUTE_UNUSED,\n" " code_helper ARG_UNUSED (code), tree " - "ARG_UNUSED (type)\n", + "ARG_UNUSED (type)", e->operation->id); else - emit_func (f, true, false, "\ntree\n" + fp_decl (f, "\ntree\n" "generic_simplify_%s (location_t ARG_UNUSED (loc), enum " "tree_code ARG_UNUSED (code), const tree ARG_UNUSED (type)", e->operation->id); for (unsigned i = 0; i < n; ++i) - emit_func (f, false, false,", tree _p%d", i); - emit_func (f, false, true, ")"); + fp_decl (f, ", tree _p%d", i); + fp_decl_done (f, ")"); fprintf (f, "{\n"); fprintf_indent (f, 2, "const bool debug_dump = " "dump_file && (dump_flags & TDF_FOLDING);\n"); @@ -4025,17 +4031,17 @@ decision_tree::gen (vec &files, bool gimple) FILE *f = get_out_file (files); if (gimple) - emit_func (f, true, false, "\nbool\n" + fp_decl (f, "\nbool\n" "gimple_simplify (gimple_match_op*, gimple_seq*,\n" " tree (*)(tree), code_helper,\n" " const tree"); else - emit_func (f, true, false,"\ntree\n" + fp_decl (f, "\ntree\n" "generic_simplify (location_t, enum tree_code,\n" " const tree"); for (unsigned i = 0; i < n; ++i) - emit_func (f, false, false, ", tree"); - emit_func (f, false, true, ")"); + fp_decl (f, ", tree"); + fp_decl_done (f, ")"); fprintf (f, "{\n"); if (gimple) fprintf (f, " return false;\n"); @@ -4052,17 +4058,17 @@ decision_tree::gen (vec &files, bool gimple) /* Then generate the main entry with the outermost switch and tail-calls to the split-out functions. */ if (gimple) - emit_func (f, true, false, "\nbool\n" + fp_decl (f, "\nbool\n" "gimple_simplify (gimple_match_op *res_op, gimple_seq *seq,\n" " tree (*valueize)(tree) ATTRIBUTE_UNUSED,\n" " code_helper code, const tree type"); else - emit_func (f, true, false, "\ntree\n" + fp_decl (f, "\ntree\n" "generic_simplify (location_t loc, enum tree_code code, " "const tree type ATTRIBUTE_UNUSED"); for (unsigned i = 0; i < n; ++i) - emit_func (f, false, false, ", tree _p%d", i); - emit_func (f, false, true, ")"); + fp_decl (f, ", tree _p%d", i); + fp_decl_done (f, ")"); fprintf (f, "{\n"); if (gimple) @@ -4117,10 +4123,11 @@ decision_tree::gen (vec &files, bool gimple) void write_predicate (FILE *f, predicate_id *p, decision_tree &dt, bool gimple) { - emit_func (f, true, true, "\nbool\n%s%s (tree t%s%s)", - gimple ? "gimple_" : "tree_", p->id, - p->nargs > 0 ? ", tree *res_ops" : "", - gimple ? ", tree (*valueize)(tree) ATTRIBUTE_UNUSED" : ""); + fp_decl (f, "\nbool\n%s%s (tree t%s%s)", + gimple ? "gimple_" : "tree_", p->id, + p->nargs > 0 ? ", tree *res_ops" : "", + gimple ? ", tree (*valueize)(tree) ATTRIBUTE_UNUSED" : ""); + fp_decl_done (f, ""); fprintf (f, "{\n"); /* Conveniently make 'type' available. */ fprintf_indent (f, 2, "const tree type = TREE_TYPE (t);\n"); @@ -5484,7 +5491,7 @@ main (int argc, char **argv) if (header_file) { - fprintf (header_file, "#endif /* GCC_GIMPLE_MATCH_AUTO_H. */\n"); + fprintf (header_file, "\n#endif /* GCC_GIMPLE_MATCH_AUTO_H. */\n"); fclose (header_file); }