From patchwork Tue Apr 27 15:32:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Schmidt X-Patchwork-Id: 1470739 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=fEdI/4+r; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FV5RV4Zp4z9t14 for ; Wed, 28 Apr 2021 01:34:46 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 77696399C023; Tue, 27 Apr 2021 15:34:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 77696399C023 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1619537663; bh=hRDBYi6pxXUJHYjmu3Tp+OmKosX2o6h80GkDiK/+afs=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=fEdI/4+rFFjJO8Q5IlQhGQueHUhqbnTicF5k6dCkPjivE/SnME77PUMn6r7ryghLF 8OgZgktR/ObA6HkF3JS4bA0hS1UEH+ge3zyGNMFRgAE3m1fkq7Q/K0Nit2rl0CCyBy vT6iOZfyAESVUgesO8UCZpvUOF9XyLtiQeY3b3g8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id C8872398EC08 for ; Tue, 27 Apr 2021 15:34:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org C8872398EC08 Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 13RFWrO9156805; Tue, 27 Apr 2021 11:34:17 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 386muqs603-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 27 Apr 2021 11:34:17 -0400 Received: from m0098413.ppops.net (m0098413.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 13RFWvZT156900; Tue, 27 Apr 2021 11:34:16 -0400 Received: from ppma03wdc.us.ibm.com (ba.79.3fa9.ip4.static.sl-reverse.com [169.63.121.186]) by mx0b-001b2d01.pphosted.com with ESMTP id 386muqs5yr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 27 Apr 2021 11:34:16 -0400 Received: from pps.filterd (ppma03wdc.us.ibm.com [127.0.0.1]) by ppma03wdc.us.ibm.com (8.16.0.43/8.16.0.43) with SMTP id 13RFH25s015517; Tue, 27 Apr 2021 15:34:16 GMT Received: from b03cxnp08025.gho.boulder.ibm.com (b03cxnp08025.gho.boulder.ibm.com [9.17.130.17]) by ppma03wdc.us.ibm.com with ESMTP id 384ay8xddy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 27 Apr 2021 15:34:16 +0000 Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp08025.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 13RFYFaf19661308 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 27 Apr 2021 15:34:15 GMT Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2EB41C6059; Tue, 27 Apr 2021 15:34:15 +0000 (GMT) Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 10B57C6057; Tue, 27 Apr 2021 15:34:15 +0000 (GMT) Received: from ltcden2-lp1.aus.stglabs.ibm.com (unknown [9.53.174.68]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTPS; Tue, 27 Apr 2021 15:34:15 +0000 (GMT) Received: by ltcden2-lp1.aus.stglabs.ibm.com (Postfix, from userid 1006) id AF10141397AD; Tue, 27 Apr 2021 10:34:14 -0500 (CDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH 11/57] rs6000: Main function with stubs for parsing and output Date: Tue, 27 Apr 2021 10:32:46 -0500 Message-Id: <8458b798d908dba0074d70fdf50bdfdef736814f.1619537141.git.wschmidt@linux.ibm.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: gzNMMxWCPsgM7dTCKrSt5LeTNdFgjTTb X-Proofpoint-ORIG-GUID: IXddSqcNSy-xEj59A3GqeKsQlRP9Fere X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.761 definitions=2021-04-27_08:2021-04-27, 2021-04-27 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 malwarescore=0 adultscore=0 mlxlogscore=999 bulkscore=0 phishscore=0 impostorscore=0 mlxscore=0 suspectscore=0 priorityscore=1501 clxscore=1015 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104270108 X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Bill Schmidt via Gcc-patches From: Bill Schmidt Reply-To: Bill Schmidt Cc: jakub@redhat.com, Bill Schmidt , jlaw@tachyum.com, dje.gcc@gmail.com, segher@kernel.crashing.org Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" 2021-03-03 Bill Schmidt gcc/ * config/rs6000/rs6000-gen-builtins.c (rbtree.h): New #include. (num_bifs): New filescope variable. (num_ovld_stanzas): Likewise. (num_ovlds): Likewise. (exit_codes): Add more enum values. (parse_codes): New enum. (bif_rbt): New filescope variable. (ovld_rbt): Likewise. (fntype_rbt): Likewise. (bifo_rbt): Likewise. (parse_bif): New stub function. (create_bif_order): Likewise. (parse_ovld): Likewise. (write_header_file): Likewise. (write_init_file): Likewise. (write_defines_file): Likewise. (delete_output_files): New function. (main): Likewise. --- gcc/config/rs6000/rs6000-gen-builtins.c | 232 ++++++++++++++++++++++++ 1 file changed, 232 insertions(+) diff --git a/gcc/config/rs6000/rs6000-gen-builtins.c b/gcc/config/rs6000/rs6000-gen-builtins.c index 1c4bf20bf3b..3a6aea85847 100644 --- a/gcc/config/rs6000/rs6000-gen-builtins.c +++ b/gcc/config/rs6000/rs6000-gen-builtins.c @@ -163,6 +163,7 @@ along with GCC; see the file COPYING3. If not see #include #include #include +#include "rbtree.h" /* Used as a sentinel for range constraints on integer fields. No field can be 32 bits wide, so this is a safe sentinel value. */ @@ -249,11 +250,45 @@ struct typeinfo { int val2; }; +static int num_bifs; +static int num_ovld_stanzas; +static int num_ovlds; + /* Exit codes for the shell. */ enum exit_codes { + EC_OK, + EC_BADARGS, + EC_NOBIF, + EC_NOOVLD, + EC_NOHDR, + EC_NOINIT, + EC_NODEFINES, + EC_PARSEBIF, + EC_PARSEOVLD, + EC_WRITEHDR, + EC_WRITEINIT, + EC_WRITEDEFINES, EC_INTERR }; +/* Return codes for parsing routines. */ +enum parse_codes { + PC_OK, + PC_EOFILE, + PC_EOSTANZA, + PC_PARSEFAIL +}; + +/* The red-black trees for built-in function identifiers, built-in + overload identifiers, and function type descriptors. */ +static rbt_strings bif_rbt; +static rbt_strings ovld_rbt; +static rbt_strings fntype_rbt; + +/* Another red-black tree containing a mapping from built-in function + identifiers to the order in which they were encountered. */ +static rbt_strings bifo_rbt; + /* Pointer to a diagnostic function. */ void (*diag) (const char *, ...) __attribute__ ((format (printf, 1, 2))) = NULL; @@ -895,3 +930,200 @@ match_type (typeinfo *typedata, int voidok) return 1; } + +/* Parse the built-in file. */ +static parse_codes +parse_bif () +{ + return PC_OK; +} + +/* Create a mapping from function IDs in their final order to the order + they appear in the built-in function file. */ +static void +create_bif_order () +{ +} + +/* Parse the overload file. */ +static parse_codes +parse_ovld () +{ + return PC_OK; +} + +/* Write everything to the header file (rs6000-builtins.h). */ +static int +write_header_file () +{ + return 1; +} + +/* Write everything to the initialization file (rs6000-builtins.c). */ +static int +write_init_file () +{ + return 1; +} + +/* Write everything to the include file (rs6000-vecdefines.h). */ +static int +write_defines_file () +{ + return 1; +} + +/* Close and delete output files after any failure, so that subsequent + build dependencies will fail. */ +static void +delete_output_files () +{ + /* Depending on whence we're called, some of these may already be + closed. Don't check for errors. */ + fclose (header_file); + fclose (init_file); + fclose (defines_file); + + unlink (header_path); + unlink (init_path); + unlink (defines_path); +} + +/* Main program to convert flat files into built-in initialization code. */ +int +main (int argc, const char **argv) +{ + if (argc != 6) + { + fprintf (stderr, + "Five arguments required: two input file and three output " + "files.\n"); + exit (EC_BADARGS); + } + + pgm_path = argv[0]; + bif_path = argv[1]; + ovld_path = argv[2]; + header_path = argv[3]; + init_path = argv[4]; + defines_path = argv[5]; + + bif_file = fopen (bif_path, "r"); + if (!bif_file) + { + fprintf (stderr, "Cannot find input built-in file '%s'.\n", bif_path); + exit (EC_NOBIF); + } + ovld_file = fopen (ovld_path, "r"); + if (!ovld_file) + { + fprintf (stderr, "Cannot find input overload file '%s'.\n", ovld_path); + exit (EC_NOOVLD); + } + header_file = fopen (header_path, "w"); + if (!header_file) + { + fprintf (stderr, "Cannot open header file '%s' for output.\n", + header_path); + exit (EC_NOHDR); + } + init_file = fopen (init_path, "w"); + if (!init_file) + { + fprintf (stderr, "Cannot open init file '%s' for output.\n", init_path); + exit (EC_NOINIT); + } + defines_file = fopen (defines_path, "w"); + if (!defines_file) + { + fprintf (stderr, "Cannot open defines file '%s' for output.\n", + defines_path); + exit (EC_NODEFINES); + } + + /* Initialize the balanced trees containing built-in function ids, + overload function ids, and function type declaration ids. */ + bif_rbt.rbt_nil = (rbt_string_node *) malloc (sizeof (rbt_string_node)); + bif_rbt.rbt_nil->color = RBT_BLACK; + bif_rbt.rbt_root = bif_rbt.rbt_nil; + + ovld_rbt.rbt_nil = (rbt_string_node *) malloc (sizeof (rbt_string_node)); + ovld_rbt.rbt_nil->color = RBT_BLACK; + ovld_rbt.rbt_root = ovld_rbt.rbt_nil; + + fntype_rbt.rbt_nil = (rbt_string_node *) malloc (sizeof (rbt_string_node)); + fntype_rbt.rbt_nil->color = RBT_BLACK; + fntype_rbt.rbt_root = fntype_rbt.rbt_nil; + + /* Initialize another balanced three that contains a map from built-in + function ids to the order they were encountered. */ + bifo_rbt.rbt_nil = (rbt_string_node *) malloc (sizeof (rbt_string_node)); + bifo_rbt.rbt_nil->color = RBT_BLACK; + bifo_rbt.rbt_root = bifo_rbt.rbt_nil; + + /* Parse the built-in function file. */ + num_bifs = 0; + line = 0; + if (parse_bif () == PC_PARSEFAIL) + { + fprintf (stderr, "Parsing of '%s' failed, aborting.\n", bif_path); + delete_output_files (); + exit (EC_PARSEBIF); + } + fclose (bif_file); + + /* Create a mapping from function IDs in their final order to + the order they appear in the built-in function file. */ + create_bif_order (); + +#ifdef DEBUG + fprintf (stderr, "\nFunction ID list:\n"); + rbt_dump (&bif_rbt, bif_rbt.rbt_root); + fprintf (stderr, "\n"); +#endif + + /* Parse the overload file. */ + num_ovld_stanzas = 0; + num_ovlds = 0; + line = 0; + if (parse_ovld () == PC_PARSEFAIL) + { + fprintf (stderr, "Parsing of '%s' failed, aborting.\n", ovld_path); + delete_output_files (); + exit (EC_PARSEOVLD); + } + fclose (ovld_file); + +#ifdef DEBUG + fprintf (stderr, "\nFunction type decl list:\n"); + rbt_dump (&fntype_rbt, fntype_rbt.rbt_root); + fprintf (stderr, "\n"); +#endif + + /* Write the header file and the file containing initialization code. */ + if (!write_header_file ()) + { + fprintf (stderr, "Output to '%s' failed, aborting.\n", header_path); + delete_output_files (); + exit (EC_WRITEHDR); + } + fclose (header_file); + if (!write_init_file ()) + { + fprintf (stderr, "Output to '%s' failed, aborting.\n", init_path); + delete_output_files (); + exit (EC_WRITEINIT); + } + fclose (init_file); + + /* Write the defines file to be included into altivec.h. */ + if (!write_defines_file ()) + { + fprintf (stderr, "Output to '%s' failed, aborting.\n", defines_path); + delete_output_files (); + exit (EC_WRITEDEFINES); + } + fclose (defines_file); + + return EC_OK; +}