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); } From patchwork Mon May 8 18:13:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Monakov X-Patchwork-Id: 91221 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2340469vqo; Mon, 8 May 2023 11:14:52 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5nrksYCabKRig3YJPbuTqsHTVbvYQhjbkhv5DIHIsut9HX6CLP2Nbpg9WrufV8Qvd//U9q X-Received: by 2002:a17:907:701:b0:94a:82ca:12e5 with SMTP id xb1-20020a170907070100b0094a82ca12e5mr9038375ejb.45.1683569692657; Mon, 08 May 2023 11:14:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683569692; cv=none; d=google.com; s=arc-20160816; b=Z5Gf9Gw5pSfgkrhR4Ohc7WDhGoQ+2DqFNHW+iqbFZjm7Abyi9BLceviuj6adMmDnZ/ cIzl7IVX29+xCfFOUdtIARdPeM6P9aXe2BmUvF6SB4Q9vX6rOSSUNy4ci8KQuAql80WI GUHrwEqbsqmmSGo2BkuPsLDOn1AeZaoeJBURqde1Cjy3P/Nm8wFIqInfh6Li7nLHtMUH SHOznrHlr5X/gOCbs9UoNhLObftdsnk9oel1s94SA1cmPSZcyO74JB6hpP0jdVRdA3Dy XC6M/d9BEpilMAQnQ+fUbZ1SFVVmFh295T0m8oRRnvIn9x91T4wQ1cvRo2Mi9nzXpWkf uBaA== 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=sXu4vDlY5p6Y+pInEQVP1msog0eEzqoG2Vs9eFvlbdE=; b=rQGum+WzaJEZPPneTDgBAQXnzavAnm319WcKOtPxEgUy5tNHa71gRKC6WYGIvf3yBm GtflVc3+OlBg9NwRFyuG2xxaqOJS7oeuh6+CuK4/gsrl/Vaui9cC/LDoTWBbcE7M9kHe yDX2azDAi62KJzEpsIlcgnf2hEX2Bd5sNj/8jS0LLmRJnOCRJd84zxGO50QzKAx/mKp2 6whjiiWOICztCL73LKTiG4H+FMLDF7LC9p8U+fv5B2QotQMlWUxO5a+rAOTl5JsVi7AW hlROa/JYwCpqhwCSo6bi5M46P8fZ95Nxt84Ml3nQtYq/KMpX0/Ce+5n0ZNVTIz+Wuv/v JBrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=xHDJkQud; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id rl18-20020a170907217200b0094edbf6c509si328152ejb.455.2023.05.08.11.14.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 May 2023 11:14:52 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=xHDJkQud; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 3ECC23856DD2 for ; Mon, 8 May 2023 18:14:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3ECC23856DD2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1683569652; bh=sXu4vDlY5p6Y+pInEQVP1msog0eEzqoG2Vs9eFvlbdE=; 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=xHDJkQudKSOimnfTLNZYQ9WR5acqN9X+xxDfceO4JOqyEP1Km+wODnLX7BfsUCXf7 K6Mr++1wlwm0NZLr9iSyEAsCKZ4YNGfj4wD7ecb4wPZOmKi7MSZk9CEhkI5PFD6IHA 8fyBsi+wCGICZx/E3j2wuiXP8EeufaZ1O+k/jsgQ= 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 ABB8E3858D3C for ; Mon, 8 May 2023 18:13:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ABB8E3858D3C Received: from localhost.intra.ispras.ru (unknown [10.10.3.121]) by mail.ispras.ru (Postfix) with ESMTP id 2411C44C1013; Mon, 8 May 2023 18:13:19 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru 2411C44C1013 To: gcc-patches@gcc.gnu.org Cc: Alexander Monakov Subject: [PATCH 2/3] genmatch: clean up showUsage Date: Mon, 8 May 2023 21:13:10 +0300 Message-Id: <20230508181311.25961-3-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?1765350773870572753?= X-GMAIL-MSGID: =?utf-8?q?1765350773870572753?= Display usage more consistently and get rid of camelCase. gcc/ChangeLog: * genmatch.cc (showUsage): Reimplement as ... (usage): ...this. Adjust all uses. (main): Print usage when no arguments. Add missing 'return 1'. --- gcc/genmatch.cc | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/gcc/genmatch.cc b/gcc/genmatch.cc index d5e56e2d68..baf93855a6 100644 --- a/gcc/genmatch.cc +++ b/gcc/genmatch.cc @@ -5301,13 +5301,12 @@ round_alloc_size (size_t s) /* Construct and display the help menu. */ static void -showUsage () +usage () { - fprintf (stderr, "Usage: genmatch [--gimple] [--generic] " - "[--header=] [--include=] [-v[v]] input " - "[...]\n"); - fprintf (stderr, "\nWhen more then one outputfile is specified --header " - "is required.\n"); + const char *usage = "Usage:\n" + " %s [--gimple|--generic] [-v[v]] \n" + " %s [options] [--include=FILE] --header=FILE ...\n"; + fprintf (stderr, usage, progname, progname); } /* Write out the correct include to the match-head fle containing the helper @@ -5332,9 +5331,6 @@ main (int argc, char **argv) progname = "genmatch"; - if (argc < 2) - return 1; - bool gimple = true; char *s_header_file = NULL; char *s_include_file = NULL; @@ -5359,14 +5355,17 @@ main (int argc, char **argv) files.safe_push (argv[i]); else { - showUsage (); + usage (); return 1; } } /* Validate if the combinations are valid. */ if ((files.length () > 1 && !s_header_file) || files.is_empty ()) - showUsage (); + { + usage (); + return 1; + } if (!s_include_file) s_include_file = s_header_file; From patchwork Mon May 8 18:13:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Monakov X-Patchwork-Id: 91220 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2340409vqo; Mon, 8 May 2023 11:14:48 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4+2y5kO2+e+DxHWAImkOvhshQ6gC337GrmROcl7yV3wGLHbt56H6UJWwHr5cqXayEW+SU/ X-Received: by 2002:a17:907:3f18:b0:966:31a1:8d6e with SMTP id hq24-20020a1709073f1800b0096631a18d6emr5510849ejc.57.1683569687746; Mon, 08 May 2023 11:14:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683569687; cv=none; d=google.com; s=arc-20160816; b=aTx1oKyiqQWz90i7nEaTKJxYpWfOeZRmLSkoAyelaGLlgZqeCzrc9/Puv3AGeCP03g JqnaOKrNFjOkUn8wv0/ZxEUnejz8azmF47RuD7RJfEAs7gSRVFkhj5hgCpvRT9wPJv3o Sz9kbRVu7mIJcMtlsHGDR+TE0F5b2JPd5tH4H0YBypiqQOAAdiv2Qh7MMLSvUgAue52M +sn5nZ4o/1rsM/aM0XeK8n1+L1B3aKLth5mBPT4dCT8GfA5h2FMUKLWT1d4V7Ajf08FE 5w4M+js6edccfa0IBEzJLakABwjH4WgcTN0JvskpKL6AM5DUI75kbxShn9Azsw1MrueD Nn7A== 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=t2i/YmdO+2kv6OEpvtuOxTFRzNyBRSJz1kmBaj184NY=; b=foa9MGf7MVnbLlBfMsriSL+wH/3sVhVmio8N7/zyBfAtOEBHC+4QT1eeJcnhyLxmGb 6iQAj7Cai8qUePd0d0g2XrQI7xqI0kyZlL8KxtVr9WGywJUhztM54HIeWB+nX+3feI5P 9cGm9KLhI81zSgjc8G3Wi7LpmmotMWndlSvmcJyWhT+FV4Apsoop1i7dSXwwkksoXDjc AJt+BqecV8BWqbUrUDKVY5SsiZsG48wJA59/nmWUibd549UGhfof9/vFY1WWQIgjJUnZ jY0skDY3UXXhX2ottioeT/EadyxZVsM7p6fugZ8wRrsSUTQdj34t8ILoL+4H0uIrdOBo C/9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=BJvtPtOv; 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 t12-20020a170906948c00b0096628c30c8esi334143ejx.230.2023.05.08.11.14.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 May 2023 11:14:47 -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=BJvtPtOv; 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 88E91385357A for ; Mon, 8 May 2023 18:14:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 88E91385357A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1683569650; bh=t2i/YmdO+2kv6OEpvtuOxTFRzNyBRSJz1kmBaj184NY=; 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=BJvtPtOvhkkjxTW0uJauUDWEg9TZb1VFszbndYGJQVZZMiOVhCW+s00UNdMZsii+1 ACOl6lr9i0bGMltB42m5JPG1KkHRh1waoBN09vT3wX0p8FQu/goTWnu2UCmXmU3p/f qr1HMEaK99QABDquE5cpWpQgqXrIPRcPs84hpHlg= 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 A91363858D35 for ; Mon, 8 May 2023 18:13:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A91363858D35 Received: from localhost.intra.ispras.ru (unknown [10.10.3.121]) by mail.ispras.ru (Postfix) with ESMTP id 42C5144C1028; Mon, 8 May 2023 18:13:19 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru 42C5144C1028 To: gcc-patches@gcc.gnu.org Cc: Alexander Monakov Subject: [PATCH 3/3] genmatch: fixup get_out_file Date: Mon, 8 May 2023 21:13:11 +0300 Message-Id: <20230508181311.25961-4-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?1765350768710748461?= X-GMAIL-MSGID: =?utf-8?q?1765350768710748461?= get_out_file did not follow the coding conventions (mixing three-space and two-space indentation, missing linebreak before function name). Take that as an excuse to reimplement it in a more terse manner and rename as 'choose_output', which is hopefully more descriptive. gcc/ChangeLog: * genmatch.cc (get_out_file): Make static and rename to ... (choose_output): ... this. Reimplement. Update all uses ... (decision_tree::gen): ... here and ... (main): ... here. --- gcc/genmatch.cc | 41 +++++++++++++++++------------------------ 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/gcc/genmatch.cc b/gcc/genmatch.cc index baf93855a6..177c13d87c 100644 --- a/gcc/genmatch.cc +++ b/gcc/genmatch.cc @@ -255,28 +255,21 @@ output_line_directive (FILE *f, location_t location, #define SIZED_BASED_CHUNKS 1 -int current_file = 0; -FILE *get_out_file (vec &parts) +static FILE * +choose_output (const vec &parts) { #ifdef SIZED_BASED_CHUNKS - if (parts.length () == 1) - return parts[0]; - - FILE *f = NULL; - long min = 0; - /* We've started writing all the files at pos 0, so ftell is equivalent - to the size and should be much faster. */ - for (unsigned i = 0; i < parts.length (); i++) - { - long res = ftell (parts[i]); - if (!f || res < min) - { - min = res; - f = parts[i]; - } - } - return f; + FILE *shortest = NULL; + long min = 0; + for (FILE *part : parts) + { + long len = ftell (part); + if (!shortest || min > len) + shortest = part, min = len; + } + return shortest; #else + static int current_file; return parts[current_file++ % parts.length ()]; #endif } @@ -3924,7 +3917,7 @@ decision_tree::gen (vec &files, bool gimple) } /* Cycle the file buffers. */ - FILE *f = get_out_file (files); + FILE *f = choose_output (files); /* Generate a split out function with the leaf transform code. */ s->fname = xasprintf ("%s_simplify_%u", gimple ? "gimple" : "generic", @@ -3991,7 +3984,7 @@ decision_tree::gen (vec &files, bool gimple) /* Cycle the file buffers. */ - FILE *f = get_out_file (files); + FILE *f = choose_output (files); if (gimple) fp_decl (f, "\nbool\n" @@ -4028,7 +4021,7 @@ decision_tree::gen (vec &files, bool gimple) { /* Cycle the file buffers. */ - FILE *f = get_out_file (files); + FILE *f = choose_output (files); if (gimple) fp_decl (f, "\nbool\n" @@ -4053,7 +4046,7 @@ decision_tree::gen (vec &files, bool gimple) /* Cycle the file buffers. */ - FILE *f = get_out_file (files); + FILE *f = choose_output (files); /* Then generate the main entry with the outermost switch and tail-calls to the split-out functions. */ @@ -5461,7 +5454,7 @@ main (int argc, char **argv) dt.print (stderr); /* Cycle the file buffers. */ - FILE *f = get_out_file (parts); + FILE *f = choose_output (parts); write_predicate (f, pred, dt, gimple); }