From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1725) id 254743848024; Tue, 15 Jun 2021 17:16:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 254743848024 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: William Schmidt To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/users/wschmidt/heads/builtins10)] rs6000: Add functions for matching types, part 3 of 3 X-Act-Checkin: gcc X-Git-Author: Bill Schmidt X-Git-Refname: refs/users/wschmidt/heads/builtins10 X-Git-Oldrev: d1be2a9c59ebd8b453ec111271ecc3a65d166054 X-Git-Newrev: 071f491c883d3effbd3eb0ae49783ccec3fc6921 Message-Id: <20210615171645.254743848024@sourceware.org> Date: Tue, 15 Jun 2021 17:16:45 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Jun 2021 17:16:45 -0000 https://gcc.gnu.org/g:071f491c883d3effbd3eb0ae49783ccec3fc6921 commit 071f491c883d3effbd3eb0ae49783ccec3fc6921 Author: Bill Schmidt Date: Mon Jun 7 12:03:49 2021 -0500 rs6000: Add functions for matching types, part 3 of 3 2021-06-07 Bill Schmidt gcc/ * config/rs6000/rs6000-gen-builtins.c (restriction): New enum. (typeinfo): Add restr field. (match_bracketed_pair): New function. (match_const_restriction): Implement. Diff: --- gcc/config/rs6000/rs6000-gen-builtins.c | 115 +++++++++++++++++++++++++++++++- 1 file changed, 114 insertions(+), 1 deletion(-) diff --git a/gcc/config/rs6000/rs6000-gen-builtins.c b/gcc/config/rs6000/rs6000-gen-builtins.c index f850ea86a39..b964dc2298f 100644 --- a/gcc/config/rs6000/rs6000-gen-builtins.c +++ b/gcc/config/rs6000/rs6000-gen-builtins.c @@ -216,6 +216,22 @@ enum basetype BT_VQUAD }; +/* Ways in which a const int value can be restricted. RES_BITS indicates + that the integer is restricted to val1 bits, interpreted as an unsigned + number. RES_RANGE indicates that the integer is restricted to values + between val1 and val2, inclusive. RES_VAR_RANGE is like RES_RANGE, but + the argument may be variable, so it can only be checked if it is constant. + RES_VALUES indicates that the integer must have one of the values val1 + or val2. */ +enum restriction +{ + RES_NONE, + RES_BITS, + RES_RANGE, + RES_VAR_RANGE, + RES_VALUES +}; + /* Type modifiers for an argument or return type. */ struct typeinfo { @@ -228,6 +244,7 @@ struct typeinfo char ispixel; char ispointer; basetype base; + restriction restr; char *val1; char *val2; }; @@ -453,6 +470,53 @@ match_basetype (typeinfo *typedata) return 1; } +/* Helper routine for match_const_restriction. */ +static int +match_bracketed_pair (typeinfo *typedata, char open, char close, + restriction restr) +{ + if (linebuf[pos] == open) + { + safe_inc_pos (); + int oldpos = pos; + char *x = match_integer (); + if (x == NULL) + { + (*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; + } + safe_inc_pos (); + consume_whitespace (); + oldpos = pos; + char *y = match_integer (); + if (y == NULL) + { + (*diag) ("malformed integer at column %d.\n", oldpos + 1); + return 0; + } + typedata->restr = restr; + typedata->val1 = x; + typedata->val2 = y; + + consume_whitespace (); + if (linebuf[pos] != close) + { + (*diag) ("malformed restriction at column %d.\n", pos + 1); + return 0; + } + safe_inc_pos (); + return 1; + } + + return 0; +} + /* A const int argument may be restricted to certain values. This is indicated by one of the following occurring after the "int' token: @@ -470,7 +534,56 @@ match_basetype (typeinfo *typedata) static int match_const_restriction (typeinfo *typedata) { - return 1; + int oldpos = pos; + if (linebuf[pos] == '<') + { + safe_inc_pos (); + oldpos = pos; + char *x = match_integer (); + if (x == NULL) + { + (*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; + char *y = match_integer (); + if (y == NULL) + { + (*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 (); + return 1; + } + else if (match_bracketed_pair (typedata, '{', '}', RES_VALUES) + || match_bracketed_pair (typedata, '[', ']', RES_VAR_RANGE)) + return 1; + + return 0; } /* Look for a type, which can be terminated by a token that is not part of