From patchwork Tue Feb 4 02:26:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Schmidt X-Patchwork-Id: 1233107 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=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-518834-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha1 header.s=default header.b=de2QFEa9; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48BTBB0DSmz9sX3 for ; Tue, 4 Feb 2020 13:27:45 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; q=dns; s=default; b=oYDLFSey9vgpHtuPfN7 YKe5LdYHmdm/NCnRV0pLNNsKyq7tXdNQHu5ktwzspXPBjJMnzNYefgYTO4n+aNVs 1MinKCfJp/idQZmLFN8AzRQPexiSjYmBykPhXn+aHCMPGoh4AZKfcmegiq3K0g/b 95uar4mZ+z9Fzak3o3Fpuj34= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; s=default; bh=HpqGBjnFKzQvLLY4ROzjg58cU oQ=; b=de2QFEa96iR+f6dIh/JzoqIIjMVdxmzXnS0GMfTNBn/bZkAUsdZeMEQ7/ 3QEImrDrjjO72GRyk8XWfH9M7o6oF2ddHCZH2kUAqsdKdzdRGW9drHTzRLVnYFOP lWec8g1O75hdWFrjUiFNyFHTCR5Npt+nwP7wvjrfAwTeW28o+I= Received: (qmail 66219 invoked by alias); 4 Feb 2020 02:27:18 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 66116 invoked by uid 89); 4 Feb 2020 02:27:17 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: mx0a-001b2d01.pphosted.com Received: from mx0a-001b2d01.pphosted.com (HELO mx0a-001b2d01.pphosted.com) (148.163.156.1) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 04 Feb 2020 02:27:14 +0000 Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0142NlRs053303; Mon, 3 Feb 2020 21:27:13 -0500 Received: from ppma03dal.us.ibm.com (b.bd.3ea9.ip4.static.sl-reverse.com [169.62.189.11]) by mx0a-001b2d01.pphosted.com with ESMTP id 2xxy9hgsba-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 03 Feb 2020 21:27:13 -0500 Received: from pps.filterd (ppma03dal.us.ibm.com [127.0.0.1]) by ppma03dal.us.ibm.com (8.16.0.27/8.16.0.27) with SMTP id 0142QutS019105; Tue, 4 Feb 2020 02:27:12 GMT Received: from b03cxnp08027.gho.boulder.ibm.com (b03cxnp08027.gho.boulder.ibm.com [9.17.130.19]) by ppma03dal.us.ibm.com with ESMTP id 2xw0y7b8j9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 04 Feb 2020 02:27:12 +0000 Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp08027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 0142RAu750987284 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 4 Feb 2020 02:27:11 GMT Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D4402C605B; Tue, 4 Feb 2020 02:27:10 +0000 (GMT) Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B6102C6059; Tue, 4 Feb 2020 02:27:10 +0000 (GMT) Received: from localhost (unknown [9.40.194.84]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTP; Tue, 4 Feb 2020 02:27:10 +0000 (GMT) From: Bill Schmidt To: gcc-patches@gcc.gnu.org Cc: segher@kernel.crashing.org Subject: [PATCH 05/14] Add support functions for matching types. Date: Mon, 3 Feb 2020 20:26:06 -0600 Message-Id: In-Reply-To: References: In-Reply-To: References: 2020-02-03 Bill Schmidt * config/rs6000/rs6000-genbif.c (void_status): New enum. (basetype): Likewise. (restriction): Likewise. (typeinfo): New struct. (match_basetype): New function. (match_const_restriction): New function. (match_type): New function. --- gcc/config/rs6000/rs6000-genbif.c | 453 ++++++++++++++++++++++++++++++ 1 file changed, 453 insertions(+) diff --git a/gcc/config/rs6000/rs6000-genbif.c b/gcc/config/rs6000/rs6000-genbif.c index 197059cc2d2..7c1082fbe8f 100644 --- a/gcc/config/rs6000/rs6000-genbif.c +++ b/gcc/config/rs6000/rs6000-genbif.c @@ -149,6 +149,53 @@ static char linebuf[LINELEN]; static int line; static int pos; +/* Used to determine whether a type can be void (only return types). */ +enum void_status { + VOID_NOTOK, + VOID_OK +}; + +/* Legal base types for an argument or return type. */ +enum basetype { + BT_CHAR, + BT_SHORT, + BT_INT, + BT_LONGLONG, + BT_FLOAT, + BT_DOUBLE, + BT_INT128, + BT_FLOAT128 +}; + +/* Ways in which a const int value can be restricted. RES_BITS indicates + that the integer is restricted to val1 bits, interpreted as signed or + unsigned depending on whether the type is signed or unsigned. RES_RANGE + indicates that the integer is restricted to values between val1 and val2, + inclusive. RES_VALUES indicates that the integer must have one of the + values val1 or val2. */ +enum restriction { + RES_NONE, + RES_BITS, + RES_RANGE, + RES_VALUES +}; + +/* Type modifiers for an argument or return type. */ +struct typeinfo { + char isvoid; + char isconst; + char isvector; + char issigned; + char isunsigned; + char isbool; + char ispixel; + char ispointer; + basetype base; + restriction restr; + int val1; + int val2; +}; + /* Exit codes for the shell. */ enum exit_codes { EC_INTERR @@ -268,3 +315,409 @@ match_integer () sscanf (buf, "%d", &x); return x; } + +/* Match one of the allowable base types. Consumes one token unless the + token is "long", which must be paired with a second "long". Return 1 + for success, 0 for failure. */ +static int +match_basetype (typeinfo *typedata) +{ + consume_whitespace (); + int oldpos = pos; + char *token = match_identifier (); + if (!token) + { + (*diag) ("missing base type in return type at column %d\n", pos + 1); + return 0; + } + + if (!strcmp (token, "char")) + typedata->base = BT_CHAR; + else if (!strcmp (token, "short")) + typedata->base = BT_SHORT; + else if (!strcmp (token, "int")) + typedata->base = BT_INT; + else if (!strcmp (token, "long")) + { + consume_whitespace (); + char *mustbelong = match_identifier (); + if (!mustbelong || strcmp (mustbelong, "long")) + { + (*diag) ("incomplete 'long long' at column %d\n", oldpos + 1); + return 0; + } + typedata->base = BT_LONGLONG; + } + else if (!strcmp (token, "float")) + typedata->base = BT_FLOAT; + else if (!strcmp (token, "double")) + typedata->base = BT_DOUBLE; + else if (!strcmp (token, "__int128")) + typedata->base = BT_INT128; + else if (!strcmp (token, "_Float128")) + typedata->base = BT_FLOAT128; + else + { + (*diag) ("unrecognized base type at column %d\n", oldpos + 1); + return 0; + } + + return 1; +} + +/* A const int argument may be restricted to certain values. This is + indicated by one of the following occurring after the "int' token: + + restricts the constant to x bits, interpreted as signed or + unsigned according to the argument type + restricts the constant to the inclusive range [x,y] + {x,y} restricts the constant to one of two values, x or y. + + Here x and y are integer tokens. Return 1 for success, else 0. */ +static int +match_const_restriction (typeinfo *typedata) +{ + int oldpos = pos; + if (linebuf[pos] == '<') + { + safe_inc_pos (); + oldpos = pos; + int x = match_integer (); + if (x == MININT) + { + (*diag) ("malformed integer at column %d.\n", oldpos + 1); + return 0; + } + consume_whitespace (); + if (linebuf[pos] == '>') + { + typedata->restr = RES_BITS; + typedata->val1 = x; + safe_inc_pos (); + return 1; + } + else if (linebuf[pos] != ',') + { + (*diag) ("malformed restriction at column %d.\n", pos + 1); + return 0; + } + safe_inc_pos (); + oldpos = pos; + int y = match_integer (); + if (y == MININT) + { + (*diag) ("malformed integer at column %d.\n", oldpos + 1); + return 0; + } + typedata->restr = RES_RANGE; + typedata->val1 = x; + typedata->val2 = y; + + consume_whitespace (); + if (linebuf[pos] != '>') + { + (*diag) ("malformed restriction at column %d.\n", pos + 1); + return 0; + } + safe_inc_pos (); + } + else + { + assert (linebuf[pos] == '{'); + safe_inc_pos (); + oldpos = pos; + int x = match_integer (); + if (x == MININT) + { + (*diag) ("malformed integer at column %d.\n", oldpos + 1); + return 0; + } + consume_whitespace (); + if (linebuf[pos] != ',') + { + (*diag) ("missing comma at column %d.\n", pos + 1); + return 0; + } + consume_whitespace (); + oldpos = pos; + int y = match_integer (); + if (y == MININT) + { + (*diag) ("malformed integer at column %d.\n", oldpos + 1); + return 0; + } + typedata->restr = RES_VALUES; + typedata->val1 = x; + typedata->val2 = y; + + consume_whitespace (); + if (linebuf[pos] != '}') + { + (*diag) ("malformed restriction at column %d.\n", pos + 1); + return 0; + } + safe_inc_pos (); + } + + return 1; +} + +/* Look for a type, which can be terminated by a token that is not part of + a type, a comma, or a closing parenthesis. Place information about the + type in TYPEDATA. Return 1 for success, 0 for failure. */ +static int +match_type (typeinfo *typedata, int voidok) +{ + /* A legal type is of the form: + + [const] [[signed|unsigned] | ] [*] + + where "const" applies only to a of "int". Legal values + of are (for now): + + char + short + int + long long + float + double + __int128 + _Float128 + + Legal values of are as follows, and are shorthand for + the associated meaning: + + vsc vector signed char + vuc vector unsigned char + vbc vector bool char + vss vector signed short + vus vector unsigned short + vbs vector bool short + vsi vector signed int + vui vector unsigned int + vbi vector bool int + vsll vector signed long long + vull vector unsigned long long + vbll vector bool long long + vsq vector signed __int128 + vuq vector unsigned __int128 + vbq vector bool __int128 + vp vector pixel + vf vector float + vd vector double + + For simplicity, We don't support "short int" and "long long int". + We don't support a of "bool", "long double", or "_Float16", + but will add these if builtins require it. "signed" and "unsigned" + only apply to integral base types. The optional * indicates a pointer + type, and can currently only be used with void. */ + + consume_whitespace (); + memset (typedata, 0, sizeof(*typedata)); + int oldpos = pos; + + char *token = match_identifier (); + if (!token) + return 0; + + if (!strcmp (token, "void")) + typedata->isvoid = 1; + if (!strcmp (token, "const")) + typedata->isconst = 1; + else if (!strcmp (token, "vsc")) + { + typedata->isvector = 1; + typedata->issigned = 1; + typedata->base = BT_CHAR; + return 1; + } + else if (!strcmp (token, "vuc")) + { + typedata->isvector = 1; + typedata->isunsigned = 1; + typedata->base = BT_CHAR; + return 1; + } + else if (!strcmp (token, "vbc")) + { + typedata->isvector = 1; + typedata->isbool = 1; + typedata->base = BT_CHAR; + return 1; + } + else if (!strcmp (token, "vss")) + { + typedata->isvector = 1; + typedata->issigned = 1; + typedata->base = BT_SHORT; + return 1; + } + else if (!strcmp (token, "vus")) + { + typedata->isvector = 1; + typedata->isunsigned = 1; + typedata->base = BT_SHORT; + return 1; + } + else if (!strcmp (token, "vbs")) + { + typedata->isvector = 1; + typedata->isbool = 1; + typedata->base = BT_SHORT; + return 1; + } + else if (!strcmp (token, "vsi")) + { + typedata->isvector = 1; + typedata->issigned = 1; + typedata->base = BT_INT; + return 1; + } + else if (!strcmp (token, "vui")) + { + typedata->isvector = 1; + typedata->isunsigned = 1; + typedata->base = BT_INT; + return 1; + } + else if (!strcmp (token, "vbi")) + { + typedata->isvector = 1; + typedata->isbool = 1; + typedata->base = BT_INT; + return 1; + } + else if (!strcmp (token, "vsll")) + { + typedata->isvector = 1; + typedata->issigned = 1; + typedata->base = BT_LONGLONG; + return 1; + } + else if (!strcmp (token, "vull")) + { + typedata->isvector = 1; + typedata->isunsigned = 1; + typedata->base = BT_LONGLONG; + return 1; + } + else if (!strcmp (token, "vbll")) + { + typedata->isvector = 1; + typedata->isbool = 1; + typedata->base = BT_LONGLONG; + return 1; + } + else if (!strcmp (token, "vsq")) + { + typedata->isvector = 1; + typedata->issigned = 1; + typedata->base = BT_INT128; + return 1; + } + else if (!strcmp (token, "vuq")) + { + typedata->isvector = 1; + typedata->isunsigned = 1; + typedata->base = BT_INT128; + return 1; + } + else if (!strcmp (token, "vbq")) + { + typedata->isvector = 1; + typedata->isbool = 1; + typedata->base = BT_INT128; + return 1; + } + else if (!strcmp (token, "vp")) + { + typedata->isvector = 1; + typedata->ispixel = 1; + typedata->base = BT_SHORT; + return 1; + } + else if (!strcmp (token, "vf")) + { + typedata->isvector = 1; + typedata->base = BT_FLOAT; + return 1; + } + else if (!strcmp (token, "vd")) + { + typedata->isvector = 1; + typedata->base = BT_DOUBLE; + return 1; + } + else if (!strcmp (token, "signed")) + typedata->issigned = 1; + else if (!strcmp (token, "unsigned")) + typedata->isunsigned = 1; + else if (!typedata->isvoid) + { + pos = oldpos; + return match_basetype (typedata); + } + + if (typedata->isvoid) + { + consume_whitespace (); + if (linebuf[pos] == '*') + { + typedata->ispointer = 1; + safe_inc_pos (); + } + else if (!voidok) + return 0; + return 1; + } + + if (typedata->isconst) + { + consume_whitespace (); + oldpos = pos; + token = match_identifier (); + if (!strcmp (token, "signed")) + { + typedata->issigned = 1; + consume_whitespace (); + oldpos = pos; + token = match_identifier (); + if (strcmp (token, "int")) + { + (*diag) ("'signed' not followed by 'int' at column %d.\n", + oldpos + 1); + return 0; + } + } + else if (!strcmp (token, "unsigned")) + { + typedata->isunsigned = 1; + consume_whitespace (); + oldpos = pos; + token = match_identifier (); + if (strcmp (token, "int")) + { + (*diag) ("'unsigned' not followed by 'int' at column %d.\n", + oldpos + 1); + return 0; + } + } + else if (strcmp (token, "int")) + { + (*diag) ("'const' not followed by 'int' at column %d.\n", + oldpos + 1); + return 0; + } + + typedata->base = BT_INT; + + consume_whitespace (); + if (linebuf[pos] == '<' || linebuf[pos] == '{') + return match_const_restriction (typedata); + + return 1; + } + + consume_whitespace (); + return match_basetype (typedata); +}