public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/wschmidt/heads/builtins10)] rs6000: Add functions for matching types, part 1 of 3
@ 2021-06-15 17:16 William Schmidt
0 siblings, 0 replies; 6+ messages in thread
From: William Schmidt @ 2021-06-15 17:16 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:324d188c7d302ec0149e5f586a35ee3468a2a8e3
commit 324d188c7d302ec0149e5f586a35ee3468a2a8e3
Author: Bill Schmidt <wschmidt@linux.ibm.com>
Date: Mon Jun 7 11:49:56 2021 -0500
rs6000: Add functions for matching types, part 1 of 3
2021-06-07 Bill Schmidt <wschmidt@linux.ibm.com>
gcc/
* config/rs6000/rs6000-gen-builtins.c (void_status): New enum.
(basetype): Likewise.
(typeinfo): Likewise.
(handle_pointer): New function.
(match_basetype): New stub function.
(match_const_restriction): Likewise.
(match_type): New function.
Diff:
---
gcc/config/rs6000/rs6000-gen-builtins.c | 367 ++++++++++++++++++++++++++++++++
1 file changed, 367 insertions(+)
diff --git a/gcc/config/rs6000/rs6000-gen-builtins.c b/gcc/config/rs6000/rs6000-gen-builtins.c
index c5d5590e865..38363f034d3 100644
--- a/gcc/config/rs6000/rs6000-gen-builtins.c
+++ b/gcc/config/rs6000/rs6000-gen-builtins.c
@@ -186,6 +186,52 @@ 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_LONG,
+ BT_LONGLONG,
+ BT_FLOAT,
+ BT_DOUBLE,
+ BT_LONGDOUBLE,
+ BT_INT128,
+ BT_FLOAT128,
+ BT_BOOL,
+ BT_STRING,
+ BT_DECIMAL32,
+ BT_DECIMAL64,
+ BT_DECIMAL128,
+ BT_IBM128,
+ BT_VPAIR,
+ BT_VQUAD
+};
+
+/* 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;
+ char *val1;
+ char *val2;
+};
+
/* Pointer to a diagnostic function. */
static void (*diag) (const char *, ...)
__attribute__ ((format (printf, 1, 2)));
@@ -321,3 +367,324 @@ match_to_right_bracket (void)
pos = lastpos + 1;
return buf;
}
+
+static inline void
+handle_pointer (typeinfo *typedata)
+{
+ consume_whitespace ();
+ if (linebuf[pos] == '*')
+ {
+ typedata->ispointer = 1;
+ safe_inc_pos ();
+ }
+}
+
+/* Match one of the allowable base types. Consumes one token unless the
+ token is "long", which must be paired with a second "long". Optionally
+ consumes a following '*' token for pointers. Return 1 for success,
+ 0 for failure. */
+static int
+match_basetype (typeinfo *typedata)
+{
+ 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:
+
+ <x> restricts the constant to x bits, interpreted as unsigned
+ <x,y> restricts the constant to the inclusive range [x,y]
+ [x,y] restricts the constant to the inclusive range [x,y],
+ but only applies if the argument is constant.
+ {x,y} restricts the constant to one of two values, x or y.
+
+ Here x and y are integer tokens. Note that the "const" token is a
+ lie when the restriction is [x,y], but this simplifies the parsing
+ significantly and is hopefully forgivable.
+
+ Return 1 for success, else 0. */
+static int
+match_const_restriction (typeinfo *typedata)
+{
+ 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] <basetype> | <vectype>] [*]
+
+ Legal values of <basetype> are (for now):
+
+ char
+ short
+ int
+ long
+ long double
+ long long
+ float
+ double
+ __int128
+ _Float128
+ bool
+ string
+ _Decimal32
+ _Decimal64
+ _Decimal128
+ __ibm128
+
+ Legal values of <vectype> 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
+ v256 __vector_pair
+ v512 __vector_quad
+
+ For simplicity, We don't support "short int" and "long long int".
+ We don't currently support a <basetype> of "_Float16". "signed"
+ and "unsigned" only apply to integral base types. The optional *
+ indicates a pointer type. */
+
+ consume_whitespace ();
+ memset (typedata, 0, sizeof *typedata);
+ int oldpos = pos;
+
+ char *token = match_identifier ();
+ if (!token)
+ return 0;
+
+ if (!strcmp (token, "const"))
+ {
+ typedata->isconst = 1;
+ consume_whitespace ();
+ oldpos = pos;
+ token = match_identifier ();
+ }
+
+ if (!strcmp (token, "void"))
+ typedata->isvoid = 1;
+
+ if (!strcmp (token, "vsc"))
+ {
+ typedata->isvector = 1;
+ typedata->issigned = 1;
+ typedata->base = BT_CHAR;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vuc"))
+ {
+ typedata->isvector = 1;
+ typedata->isunsigned = 1;
+ typedata->base = BT_CHAR;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vbc"))
+ {
+ typedata->isvector = 1;
+ typedata->isbool = 1;
+ typedata->base = BT_CHAR;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vss"))
+ {
+ typedata->isvector = 1;
+ typedata->issigned = 1;
+ typedata->base = BT_SHORT;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vus"))
+ {
+ typedata->isvector = 1;
+ typedata->isunsigned = 1;
+ typedata->base = BT_SHORT;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vbs"))
+ {
+ typedata->isvector = 1;
+ typedata->isbool = 1;
+ typedata->base = BT_SHORT;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vsi"))
+ {
+ typedata->isvector = 1;
+ typedata->issigned = 1;
+ typedata->base = BT_INT;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vui"))
+ {
+ typedata->isvector = 1;
+ typedata->isunsigned = 1;
+ typedata->base = BT_INT;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vbi"))
+ {
+ typedata->isvector = 1;
+ typedata->isbool = 1;
+ typedata->base = BT_INT;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vsll"))
+ {
+ typedata->isvector = 1;
+ typedata->issigned = 1;
+ typedata->base = BT_LONGLONG;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vull"))
+ {
+ typedata->isvector = 1;
+ typedata->isunsigned = 1;
+ typedata->base = BT_LONGLONG;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vbll"))
+ {
+ typedata->isvector = 1;
+ typedata->isbool = 1;
+ typedata->base = BT_LONGLONG;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vsq"))
+ {
+ typedata->isvector = 1;
+ typedata->issigned = 1;
+ typedata->base = BT_INT128;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vuq"))
+ {
+ typedata->isvector = 1;
+ typedata->isunsigned = 1;
+ typedata->base = BT_INT128;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vbq"))
+ {
+ typedata->isvector = 1;
+ typedata->isbool = 1;
+ typedata->base = BT_INT128;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vp"))
+ {
+ typedata->isvector = 1;
+ typedata->ispixel = 1;
+ typedata->base = BT_SHORT;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vf"))
+ {
+ typedata->isvector = 1;
+ typedata->base = BT_FLOAT;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vd"))
+ {
+ typedata->isvector = 1;
+ typedata->base = BT_DOUBLE;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "v256"))
+ {
+ typedata->isvector = 1;
+ typedata->base = BT_VPAIR;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "v512"))
+ {
+ typedata->isvector = 1;
+ typedata->base = BT_VQUAD;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "signed"))
+ typedata->issigned = 1;
+ else if (!strcmp (token, "unsigned"))
+ typedata->isunsigned = 1;
+ else if (!typedata->isvoid && !typedata->isconst)
+ {
+ /* Push back token. */
+ 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->issigned && !typedata->isunsigned)
+ pos = oldpos;
+ if (!match_basetype (typedata))
+ return 0;
+
+ if (typedata->isconst)
+ {
+ if (typedata->ispointer)
+ return 1;
+ if (typedata->base != BT_INT)
+ {
+ (*diag)("'const' at %d requires pointer or integer type",
+ oldpos + 1);
+ return 0;
+ }
+ consume_whitespace ();
+ if (linebuf[pos] == '<' || linebuf[pos] == '{' || linebuf[pos] == '[')
+ return match_const_restriction (typedata);
+ }
+
+ return 1;
+}
^ permalink raw reply [flat|nested] 6+ messages in thread
* [gcc(refs/users/wschmidt/heads/builtins10)] rs6000: Add functions for matching types, part 1 of 3
@ 2021-06-25 16:15 William Schmidt
0 siblings, 0 replies; 6+ messages in thread
From: William Schmidt @ 2021-06-25 16:15 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:c4d5d38e2992320479dce33aff187bdd05280eb1
commit c4d5d38e2992320479dce33aff187bdd05280eb1
Author: Bill Schmidt <wschmidt@linux.ibm.com>
Date: Mon Jun 7 11:49:56 2021 -0500
rs6000: Add functions for matching types, part 1 of 3
2021-06-07 Bill Schmidt <wschmidt@linux.ibm.com>
gcc/
* config/rs6000/rs6000-gen-builtins.c (void_status): New enum.
(basetype): Likewise.
(typeinfo): Likewise.
(handle_pointer): New function.
(match_basetype): New stub function.
(match_const_restriction): Likewise.
(match_type): New function.
Diff:
---
gcc/config/rs6000/rs6000-gen-builtins.c | 367 ++++++++++++++++++++++++++++++++
1 file changed, 367 insertions(+)
diff --git a/gcc/config/rs6000/rs6000-gen-builtins.c b/gcc/config/rs6000/rs6000-gen-builtins.c
index c5d5590e865..38363f034d3 100644
--- a/gcc/config/rs6000/rs6000-gen-builtins.c
+++ b/gcc/config/rs6000/rs6000-gen-builtins.c
@@ -186,6 +186,52 @@ 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_LONG,
+ BT_LONGLONG,
+ BT_FLOAT,
+ BT_DOUBLE,
+ BT_LONGDOUBLE,
+ BT_INT128,
+ BT_FLOAT128,
+ BT_BOOL,
+ BT_STRING,
+ BT_DECIMAL32,
+ BT_DECIMAL64,
+ BT_DECIMAL128,
+ BT_IBM128,
+ BT_VPAIR,
+ BT_VQUAD
+};
+
+/* 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;
+ char *val1;
+ char *val2;
+};
+
/* Pointer to a diagnostic function. */
static void (*diag) (const char *, ...)
__attribute__ ((format (printf, 1, 2)));
@@ -321,3 +367,324 @@ match_to_right_bracket (void)
pos = lastpos + 1;
return buf;
}
+
+static inline void
+handle_pointer (typeinfo *typedata)
+{
+ consume_whitespace ();
+ if (linebuf[pos] == '*')
+ {
+ typedata->ispointer = 1;
+ safe_inc_pos ();
+ }
+}
+
+/* Match one of the allowable base types. Consumes one token unless the
+ token is "long", which must be paired with a second "long". Optionally
+ consumes a following '*' token for pointers. Return 1 for success,
+ 0 for failure. */
+static int
+match_basetype (typeinfo *typedata)
+{
+ 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:
+
+ <x> restricts the constant to x bits, interpreted as unsigned
+ <x,y> restricts the constant to the inclusive range [x,y]
+ [x,y] restricts the constant to the inclusive range [x,y],
+ but only applies if the argument is constant.
+ {x,y} restricts the constant to one of two values, x or y.
+
+ Here x and y are integer tokens. Note that the "const" token is a
+ lie when the restriction is [x,y], but this simplifies the parsing
+ significantly and is hopefully forgivable.
+
+ Return 1 for success, else 0. */
+static int
+match_const_restriction (typeinfo *typedata)
+{
+ 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] <basetype> | <vectype>] [*]
+
+ Legal values of <basetype> are (for now):
+
+ char
+ short
+ int
+ long
+ long double
+ long long
+ float
+ double
+ __int128
+ _Float128
+ bool
+ string
+ _Decimal32
+ _Decimal64
+ _Decimal128
+ __ibm128
+
+ Legal values of <vectype> 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
+ v256 __vector_pair
+ v512 __vector_quad
+
+ For simplicity, We don't support "short int" and "long long int".
+ We don't currently support a <basetype> of "_Float16". "signed"
+ and "unsigned" only apply to integral base types. The optional *
+ indicates a pointer type. */
+
+ consume_whitespace ();
+ memset (typedata, 0, sizeof *typedata);
+ int oldpos = pos;
+
+ char *token = match_identifier ();
+ if (!token)
+ return 0;
+
+ if (!strcmp (token, "const"))
+ {
+ typedata->isconst = 1;
+ consume_whitespace ();
+ oldpos = pos;
+ token = match_identifier ();
+ }
+
+ if (!strcmp (token, "void"))
+ typedata->isvoid = 1;
+
+ if (!strcmp (token, "vsc"))
+ {
+ typedata->isvector = 1;
+ typedata->issigned = 1;
+ typedata->base = BT_CHAR;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vuc"))
+ {
+ typedata->isvector = 1;
+ typedata->isunsigned = 1;
+ typedata->base = BT_CHAR;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vbc"))
+ {
+ typedata->isvector = 1;
+ typedata->isbool = 1;
+ typedata->base = BT_CHAR;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vss"))
+ {
+ typedata->isvector = 1;
+ typedata->issigned = 1;
+ typedata->base = BT_SHORT;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vus"))
+ {
+ typedata->isvector = 1;
+ typedata->isunsigned = 1;
+ typedata->base = BT_SHORT;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vbs"))
+ {
+ typedata->isvector = 1;
+ typedata->isbool = 1;
+ typedata->base = BT_SHORT;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vsi"))
+ {
+ typedata->isvector = 1;
+ typedata->issigned = 1;
+ typedata->base = BT_INT;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vui"))
+ {
+ typedata->isvector = 1;
+ typedata->isunsigned = 1;
+ typedata->base = BT_INT;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vbi"))
+ {
+ typedata->isvector = 1;
+ typedata->isbool = 1;
+ typedata->base = BT_INT;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vsll"))
+ {
+ typedata->isvector = 1;
+ typedata->issigned = 1;
+ typedata->base = BT_LONGLONG;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vull"))
+ {
+ typedata->isvector = 1;
+ typedata->isunsigned = 1;
+ typedata->base = BT_LONGLONG;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vbll"))
+ {
+ typedata->isvector = 1;
+ typedata->isbool = 1;
+ typedata->base = BT_LONGLONG;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vsq"))
+ {
+ typedata->isvector = 1;
+ typedata->issigned = 1;
+ typedata->base = BT_INT128;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vuq"))
+ {
+ typedata->isvector = 1;
+ typedata->isunsigned = 1;
+ typedata->base = BT_INT128;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vbq"))
+ {
+ typedata->isvector = 1;
+ typedata->isbool = 1;
+ typedata->base = BT_INT128;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vp"))
+ {
+ typedata->isvector = 1;
+ typedata->ispixel = 1;
+ typedata->base = BT_SHORT;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vf"))
+ {
+ typedata->isvector = 1;
+ typedata->base = BT_FLOAT;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vd"))
+ {
+ typedata->isvector = 1;
+ typedata->base = BT_DOUBLE;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "v256"))
+ {
+ typedata->isvector = 1;
+ typedata->base = BT_VPAIR;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "v512"))
+ {
+ typedata->isvector = 1;
+ typedata->base = BT_VQUAD;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "signed"))
+ typedata->issigned = 1;
+ else if (!strcmp (token, "unsigned"))
+ typedata->isunsigned = 1;
+ else if (!typedata->isvoid && !typedata->isconst)
+ {
+ /* Push back token. */
+ 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->issigned && !typedata->isunsigned)
+ pos = oldpos;
+ if (!match_basetype (typedata))
+ return 0;
+
+ if (typedata->isconst)
+ {
+ if (typedata->ispointer)
+ return 1;
+ if (typedata->base != BT_INT)
+ {
+ (*diag)("'const' at %d requires pointer or integer type",
+ oldpos + 1);
+ return 0;
+ }
+ consume_whitespace ();
+ if (linebuf[pos] == '<' || linebuf[pos] == '{' || linebuf[pos] == '[')
+ return match_const_restriction (typedata);
+ }
+
+ return 1;
+}
^ permalink raw reply [flat|nested] 6+ messages in thread
* [gcc(refs/users/wschmidt/heads/builtins10)] rs6000: Add functions for matching types, part 1 of 3
@ 2021-04-26 20:48 William Schmidt
0 siblings, 0 replies; 6+ messages in thread
From: William Schmidt @ 2021-04-26 20:48 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:7d8e91f0bb4a8677dad1570e1adbcfe6e469e2bf
commit 7d8e91f0bb4a8677dad1570e1adbcfe6e469e2bf
Author: Bill Schmidt <wschmidt@linux.ibm.com>
Date: Fri Apr 2 16:27:13 2021 -0500
rs6000: Add functions for matching types, part 1 of 3
2021-04-02 Bill Schmidt <wschmidt@linux.ibm.com>
gcc/
* config/rs6000/rs6000-gen-builtins.c (void_status): New enum.
(basetype): Likewise.
(typeinfo): New struct.
(handle_pointer): New function.
(match_basetype): New stub function.
(match_const_restriction): Likewise.
(match_type): New function.
Diff:
---
gcc/config/rs6000/rs6000-gen-builtins.c | 364 ++++++++++++++++++++++++++++++++
1 file changed, 364 insertions(+)
diff --git a/gcc/config/rs6000/rs6000-gen-builtins.c b/gcc/config/rs6000/rs6000-gen-builtins.c
index f3e1d31c225..ac061d092e7 100644
--- a/gcc/config/rs6000/rs6000-gen-builtins.c
+++ b/gcc/config/rs6000/rs6000-gen-builtins.c
@@ -190,6 +190,49 @@ 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_LONG,
+ BT_LONGLONG,
+ BT_FLOAT,
+ BT_DOUBLE,
+ BT_LONGDOUBLE,
+ BT_INT128,
+ BT_FLOAT128,
+ BT_BOOL,
+ BT_STRING,
+ BT_DECIMAL32,
+ BT_DECIMAL64,
+ BT_DECIMAL128,
+ BT_IBM128,
+ BT_VPAIR,
+ BT_VQUAD
+};
+
+/* 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;
+ int val1;
+ int val2;
+};
+
/* Exit codes for the shell. */
enum exit_codes {
EC_INTERR
@@ -331,3 +374,324 @@ match_to_right_bracket ()
pos = lastpos + 1;
return buf;
}
+
+static inline void
+handle_pointer (typeinfo *typedata)
+{
+ consume_whitespace ();
+ if (linebuf[pos] == '*')
+ {
+ typedata->ispointer = 1;
+ safe_inc_pos ();
+ }
+}
+
+/* Match one of the allowable base types. Consumes one token unless the
+ token is "long", which must be paired with a second "long". Optionally
+ consumes a following '*' token for pointers. Return 1 for success,
+ 0 for failure. */
+static int
+match_basetype (typeinfo *typedata)
+{
+ 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:
+
+ <x> restricts the constant to x bits, interpreted as unsigned
+ <x,y> restricts the constant to the inclusive range [x,y]
+ [x,y] restricts the constant to the inclusive range [x,y],
+ but only applies if the argument is constant.
+ {x,y} restricts the constant to one of two values, x or y.
+
+ Here x and y are integer tokens. Note that the "const" token is a
+ lie when the restriction is [x,y], but this simplifies the parsing
+ significantly and is hopefully forgivable.
+
+ Return 1 for success, else 0. */
+static int
+match_const_restriction (typeinfo *typedata)
+{
+ 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] <basetype> | <vectype>] [*]
+
+ Legal values of <basetype> are (for now):
+
+ char
+ short
+ int
+ long
+ long double
+ long long
+ float
+ double
+ __int128
+ _Float128
+ bool
+ string
+ _Decimal32
+ _Decimal64
+ _Decimal128
+ __ibm128
+
+ Legal values of <vectype> 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
+ v256 __vector_pair
+ v512 __vector_quad
+
+ For simplicity, We don't support "short int" and "long long int".
+ We don't currently support a <basetype> of "_Float16". "signed"
+ and "unsigned" only apply to integral base types. The optional *
+ indicates a pointer type. */
+
+ consume_whitespace ();
+ memset (typedata, 0, sizeof(*typedata));
+ int oldpos = pos;
+
+ char *token = match_identifier ();
+ if (!token)
+ return 0;
+
+ if (!strcmp (token, "const"))
+ {
+ typedata->isconst = 1;
+ consume_whitespace ();
+ oldpos = pos;
+ token = match_identifier ();
+ }
+
+ if (!strcmp (token, "void"))
+ typedata->isvoid = 1;
+
+ if (!strcmp (token, "vsc"))
+ {
+ typedata->isvector = 1;
+ typedata->issigned = 1;
+ typedata->base = BT_CHAR;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vuc"))
+ {
+ typedata->isvector = 1;
+ typedata->isunsigned = 1;
+ typedata->base = BT_CHAR;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vbc"))
+ {
+ typedata->isvector = 1;
+ typedata->isbool = 1;
+ typedata->base = BT_CHAR;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vss"))
+ {
+ typedata->isvector = 1;
+ typedata->issigned = 1;
+ typedata->base = BT_SHORT;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vus"))
+ {
+ typedata->isvector = 1;
+ typedata->isunsigned = 1;
+ typedata->base = BT_SHORT;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vbs"))
+ {
+ typedata->isvector = 1;
+ typedata->isbool = 1;
+ typedata->base = BT_SHORT;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vsi"))
+ {
+ typedata->isvector = 1;
+ typedata->issigned = 1;
+ typedata->base = BT_INT;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vui"))
+ {
+ typedata->isvector = 1;
+ typedata->isunsigned = 1;
+ typedata->base = BT_INT;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vbi"))
+ {
+ typedata->isvector = 1;
+ typedata->isbool = 1;
+ typedata->base = BT_INT;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vsll"))
+ {
+ typedata->isvector = 1;
+ typedata->issigned = 1;
+ typedata->base = BT_LONGLONG;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vull"))
+ {
+ typedata->isvector = 1;
+ typedata->isunsigned = 1;
+ typedata->base = BT_LONGLONG;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vbll"))
+ {
+ typedata->isvector = 1;
+ typedata->isbool = 1;
+ typedata->base = BT_LONGLONG;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vsq"))
+ {
+ typedata->isvector = 1;
+ typedata->issigned = 1;
+ typedata->base = BT_INT128;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vuq"))
+ {
+ typedata->isvector = 1;
+ typedata->isunsigned = 1;
+ typedata->base = BT_INT128;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vbq"))
+ {
+ typedata->isvector = 1;
+ typedata->isbool = 1;
+ typedata->base = BT_INT128;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vp"))
+ {
+ typedata->isvector = 1;
+ typedata->ispixel = 1;
+ typedata->base = BT_SHORT;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vf"))
+ {
+ typedata->isvector = 1;
+ typedata->base = BT_FLOAT;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vd"))
+ {
+ typedata->isvector = 1;
+ typedata->base = BT_DOUBLE;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "v256"))
+ {
+ typedata->isvector = 1;
+ typedata->base = BT_VPAIR;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "v512"))
+ {
+ typedata->isvector = 1;
+ typedata->base = BT_VQUAD;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "signed"))
+ typedata->issigned = 1;
+ else if (!strcmp (token, "unsigned"))
+ typedata->isunsigned = 1;
+ else if (!typedata->isvoid && !typedata->isconst)
+ {
+ /* Push back token. */
+ 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->issigned && !typedata->isunsigned)
+ pos = oldpos;
+ if (!match_basetype (typedata))
+ return 0;
+
+ if (typedata->isconst)
+ {
+ if (typedata->ispointer)
+ return 1;
+ if (typedata->base != BT_INT)
+ {
+ (*diag)("'const' at %d requires pointer or integer type",
+ oldpos + 1);
+ return 0;
+ }
+ consume_whitespace ();
+ if (linebuf[pos] == '<' || linebuf[pos] == '{' || linebuf[pos] == '[')
+ return match_const_restriction (typedata);
+ }
+
+ return 1;
+}
^ permalink raw reply [flat|nested] 6+ messages in thread
* [gcc(refs/users/wschmidt/heads/builtins10)] rs6000: Add functions for matching types, part 1 of 3
@ 2021-04-02 22:09 William Schmidt
0 siblings, 0 replies; 6+ messages in thread
From: William Schmidt @ 2021-04-02 22:09 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:bf5128e8a3eca3213aa85069db9d7116436c0f08
commit bf5128e8a3eca3213aa85069db9d7116436c0f08
Author: Bill Schmidt <wschmidt@linux.ibm.com>
Date: Fri Apr 2 16:27:13 2021 -0500
rs6000: Add functions for matching types, part 1 of 3
2021-04-02 Bill Schmidt <wschmidt@linux.ibm.com>
gcc/
* config/rs6000/rs6000-gen-builtins.c (void_status): New enum.
(basetype): Likewise.
(typeinfo): New struct.
(handle_pointer): New function.
(match_basetype): New stub function.
(match_const_restriction): Likewise.
(match_type): New function.
Diff:
---
gcc/config/rs6000/rs6000-gen-builtins.c | 364 ++++++++++++++++++++++++++++++++
1 file changed, 364 insertions(+)
diff --git a/gcc/config/rs6000/rs6000-gen-builtins.c b/gcc/config/rs6000/rs6000-gen-builtins.c
index f3e1d31c225..ac061d092e7 100644
--- a/gcc/config/rs6000/rs6000-gen-builtins.c
+++ b/gcc/config/rs6000/rs6000-gen-builtins.c
@@ -190,6 +190,49 @@ 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_LONG,
+ BT_LONGLONG,
+ BT_FLOAT,
+ BT_DOUBLE,
+ BT_LONGDOUBLE,
+ BT_INT128,
+ BT_FLOAT128,
+ BT_BOOL,
+ BT_STRING,
+ BT_DECIMAL32,
+ BT_DECIMAL64,
+ BT_DECIMAL128,
+ BT_IBM128,
+ BT_VPAIR,
+ BT_VQUAD
+};
+
+/* 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;
+ int val1;
+ int val2;
+};
+
/* Exit codes for the shell. */
enum exit_codes {
EC_INTERR
@@ -331,3 +374,324 @@ match_to_right_bracket ()
pos = lastpos + 1;
return buf;
}
+
+static inline void
+handle_pointer (typeinfo *typedata)
+{
+ consume_whitespace ();
+ if (linebuf[pos] == '*')
+ {
+ typedata->ispointer = 1;
+ safe_inc_pos ();
+ }
+}
+
+/* Match one of the allowable base types. Consumes one token unless the
+ token is "long", which must be paired with a second "long". Optionally
+ consumes a following '*' token for pointers. Return 1 for success,
+ 0 for failure. */
+static int
+match_basetype (typeinfo *typedata)
+{
+ 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:
+
+ <x> restricts the constant to x bits, interpreted as unsigned
+ <x,y> restricts the constant to the inclusive range [x,y]
+ [x,y] restricts the constant to the inclusive range [x,y],
+ but only applies if the argument is constant.
+ {x,y} restricts the constant to one of two values, x or y.
+
+ Here x and y are integer tokens. Note that the "const" token is a
+ lie when the restriction is [x,y], but this simplifies the parsing
+ significantly and is hopefully forgivable.
+
+ Return 1 for success, else 0. */
+static int
+match_const_restriction (typeinfo *typedata)
+{
+ 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] <basetype> | <vectype>] [*]
+
+ Legal values of <basetype> are (for now):
+
+ char
+ short
+ int
+ long
+ long double
+ long long
+ float
+ double
+ __int128
+ _Float128
+ bool
+ string
+ _Decimal32
+ _Decimal64
+ _Decimal128
+ __ibm128
+
+ Legal values of <vectype> 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
+ v256 __vector_pair
+ v512 __vector_quad
+
+ For simplicity, We don't support "short int" and "long long int".
+ We don't currently support a <basetype> of "_Float16". "signed"
+ and "unsigned" only apply to integral base types. The optional *
+ indicates a pointer type. */
+
+ consume_whitespace ();
+ memset (typedata, 0, sizeof(*typedata));
+ int oldpos = pos;
+
+ char *token = match_identifier ();
+ if (!token)
+ return 0;
+
+ if (!strcmp (token, "const"))
+ {
+ typedata->isconst = 1;
+ consume_whitespace ();
+ oldpos = pos;
+ token = match_identifier ();
+ }
+
+ if (!strcmp (token, "void"))
+ typedata->isvoid = 1;
+
+ if (!strcmp (token, "vsc"))
+ {
+ typedata->isvector = 1;
+ typedata->issigned = 1;
+ typedata->base = BT_CHAR;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vuc"))
+ {
+ typedata->isvector = 1;
+ typedata->isunsigned = 1;
+ typedata->base = BT_CHAR;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vbc"))
+ {
+ typedata->isvector = 1;
+ typedata->isbool = 1;
+ typedata->base = BT_CHAR;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vss"))
+ {
+ typedata->isvector = 1;
+ typedata->issigned = 1;
+ typedata->base = BT_SHORT;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vus"))
+ {
+ typedata->isvector = 1;
+ typedata->isunsigned = 1;
+ typedata->base = BT_SHORT;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vbs"))
+ {
+ typedata->isvector = 1;
+ typedata->isbool = 1;
+ typedata->base = BT_SHORT;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vsi"))
+ {
+ typedata->isvector = 1;
+ typedata->issigned = 1;
+ typedata->base = BT_INT;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vui"))
+ {
+ typedata->isvector = 1;
+ typedata->isunsigned = 1;
+ typedata->base = BT_INT;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vbi"))
+ {
+ typedata->isvector = 1;
+ typedata->isbool = 1;
+ typedata->base = BT_INT;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vsll"))
+ {
+ typedata->isvector = 1;
+ typedata->issigned = 1;
+ typedata->base = BT_LONGLONG;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vull"))
+ {
+ typedata->isvector = 1;
+ typedata->isunsigned = 1;
+ typedata->base = BT_LONGLONG;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vbll"))
+ {
+ typedata->isvector = 1;
+ typedata->isbool = 1;
+ typedata->base = BT_LONGLONG;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vsq"))
+ {
+ typedata->isvector = 1;
+ typedata->issigned = 1;
+ typedata->base = BT_INT128;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vuq"))
+ {
+ typedata->isvector = 1;
+ typedata->isunsigned = 1;
+ typedata->base = BT_INT128;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vbq"))
+ {
+ typedata->isvector = 1;
+ typedata->isbool = 1;
+ typedata->base = BT_INT128;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vp"))
+ {
+ typedata->isvector = 1;
+ typedata->ispixel = 1;
+ typedata->base = BT_SHORT;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vf"))
+ {
+ typedata->isvector = 1;
+ typedata->base = BT_FLOAT;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vd"))
+ {
+ typedata->isvector = 1;
+ typedata->base = BT_DOUBLE;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "v256"))
+ {
+ typedata->isvector = 1;
+ typedata->base = BT_VPAIR;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "v512"))
+ {
+ typedata->isvector = 1;
+ typedata->base = BT_VQUAD;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "signed"))
+ typedata->issigned = 1;
+ else if (!strcmp (token, "unsigned"))
+ typedata->isunsigned = 1;
+ else if (!typedata->isvoid && !typedata->isconst)
+ {
+ /* Push back token. */
+ 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->issigned && !typedata->isunsigned)
+ pos = oldpos;
+ if (!match_basetype (typedata))
+ return 0;
+
+ if (typedata->isconst)
+ {
+ if (typedata->ispointer)
+ return 1;
+ if (typedata->base != BT_INT)
+ {
+ (*diag)("'const' at %d requires pointer or integer type",
+ oldpos + 1);
+ return 0;
+ }
+ consume_whitespace ();
+ if (linebuf[pos] == '<' || linebuf[pos] == '{' || linebuf[pos] == '[')
+ return match_const_restriction (typedata);
+ }
+
+ return 1;
+}
^ permalink raw reply [flat|nested] 6+ messages in thread
* [gcc(refs/users/wschmidt/heads/builtins10)] rs6000: Add functions for matching types, part 1 of 3
@ 2021-04-01 19:47 William Schmidt
0 siblings, 0 replies; 6+ messages in thread
From: William Schmidt @ 2021-04-01 19:47 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:fcc6f3e112dc25690d092dbaef49bf64087f2fce
commit fcc6f3e112dc25690d092dbaef49bf64087f2fce
Author: Bill Schmidt <wschmidt@linux.ibm.com>
Date: Wed Mar 24 11:57:49 2021 -0500
rs6000: Add functions for matching types, part 1 of 3
2021-03-24 Bill Schmidt <wschmidt@linux.ibm.com>
gcc/
* config/rs6000/rs6000-gen-builtins.c (void_status): New enum.
(basetype): Likewise.
(typeinfo): New struct.
(handle_pointer): New function.
(match_basetype): New stub function.
(match_const_restriction): Likewise.
(match_type): New function.
Diff:
---
gcc/config/rs6000/rs6000-gen-builtins.c | 360 ++++++++++++++++++++++++++++++++
1 file changed, 360 insertions(+)
diff --git a/gcc/config/rs6000/rs6000-gen-builtins.c b/gcc/config/rs6000/rs6000-gen-builtins.c
index 136d6911760..5ce1707d84e 100644
--- a/gcc/config/rs6000/rs6000-gen-builtins.c
+++ b/gcc/config/rs6000/rs6000-gen-builtins.c
@@ -189,6 +189,49 @@ 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_LONG,
+ BT_LONGLONG,
+ BT_FLOAT,
+ BT_DOUBLE,
+ BT_LONGDOUBLE,
+ BT_INT128,
+ BT_FLOAT128,
+ BT_BOOL,
+ BT_STRING,
+ BT_DECIMAL32,
+ BT_DECIMAL64,
+ BT_DECIMAL128,
+ BT_IBM128,
+ BT_VPAIR,
+ BT_VQUAD
+};
+
+/* 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;
+ int val1;
+ int val2;
+};
+
/* Exit codes for the shell. */
enum exit_codes {
EC_INTERR
@@ -330,3 +373,320 @@ match_to_right_bracket ()
pos = lastpos + 1;
return buf;
}
+
+static inline void
+handle_pointer (typeinfo *typedata)
+{
+ consume_whitespace ();
+ if (linebuf[pos] == '*')
+ {
+ typedata->ispointer = 1;
+ safe_inc_pos ();
+ }
+}
+
+/* Match one of the allowable base types. Consumes one token unless the
+ token is "long", which must be paired with a second "long". Optionally
+ consumes a following '*' token for pointers. Return 1 for success,
+ 0 for failure. */
+static int
+match_basetype (typeinfo *typedata)
+{
+ 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:
+
+ <x> restricts the constant to x bits, interpreted as unsigned
+ <x,y> restricts the constant to the inclusive range [x,y]
+ [x,y] restricts the constant to the inclusive range [x,y],
+ but only applies if the argument is constant.
+ {x,y} restricts the constant to one of two values, x or y.
+
+ Here x and y are integer tokens. Note that the "const" token is a
+ lie when the restriction is [x,y], but this simplifies the parsing
+ significantly and is hopefully forgivable.
+
+ Return 1 for success, else 0. */
+static int
+match_const_restriction (typeinfo *typedata)
+{
+ 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] <basetype> | <vectype>] [*]
+
+ Legal values of <basetype> are (for now):
+
+ char
+ short
+ int
+ long long
+ float
+ double
+ __int128
+ _Float128
+ _Decimal32
+ _Decimal64
+ _Decimal128
+ __ibm128
+
+ Legal values of <vectype> 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
+ v256 __vector_pair
+ v512 __vector_quad
+
+ For simplicity, We don't support "short int" and "long long int".
+ We don't currently support a <basetype> of "_Float16". "signed"
+ and "unsigned" only apply to integral base types. The optional *
+ indicates a pointer type. */
+
+ consume_whitespace ();
+ memset (typedata, 0, sizeof(*typedata));
+ int oldpos = pos;
+
+ char *token = match_identifier ();
+ if (!token)
+ return 0;
+
+ if (!strcmp (token, "const"))
+ {
+ typedata->isconst = 1;
+ consume_whitespace ();
+ oldpos = pos;
+ token = match_identifier ();
+ }
+
+ if (!strcmp (token, "void"))
+ typedata->isvoid = 1;
+
+ if (!strcmp (token, "vsc"))
+ {
+ typedata->isvector = 1;
+ typedata->issigned = 1;
+ typedata->base = BT_CHAR;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vuc"))
+ {
+ typedata->isvector = 1;
+ typedata->isunsigned = 1;
+ typedata->base = BT_CHAR;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vbc"))
+ {
+ typedata->isvector = 1;
+ typedata->isbool = 1;
+ typedata->base = BT_CHAR;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vss"))
+ {
+ typedata->isvector = 1;
+ typedata->issigned = 1;
+ typedata->base = BT_SHORT;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vus"))
+ {
+ typedata->isvector = 1;
+ typedata->isunsigned = 1;
+ typedata->base = BT_SHORT;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vbs"))
+ {
+ typedata->isvector = 1;
+ typedata->isbool = 1;
+ typedata->base = BT_SHORT;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vsi"))
+ {
+ typedata->isvector = 1;
+ typedata->issigned = 1;
+ typedata->base = BT_INT;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vui"))
+ {
+ typedata->isvector = 1;
+ typedata->isunsigned = 1;
+ typedata->base = BT_INT;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vbi"))
+ {
+ typedata->isvector = 1;
+ typedata->isbool = 1;
+ typedata->base = BT_INT;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vsll"))
+ {
+ typedata->isvector = 1;
+ typedata->issigned = 1;
+ typedata->base = BT_LONGLONG;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vull"))
+ {
+ typedata->isvector = 1;
+ typedata->isunsigned = 1;
+ typedata->base = BT_LONGLONG;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vbll"))
+ {
+ typedata->isvector = 1;
+ typedata->isbool = 1;
+ typedata->base = BT_LONGLONG;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vsq"))
+ {
+ typedata->isvector = 1;
+ typedata->issigned = 1;
+ typedata->base = BT_INT128;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vuq"))
+ {
+ typedata->isvector = 1;
+ typedata->isunsigned = 1;
+ typedata->base = BT_INT128;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vbq"))
+ {
+ typedata->isvector = 1;
+ typedata->isbool = 1;
+ typedata->base = BT_INT128;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vp"))
+ {
+ typedata->isvector = 1;
+ typedata->ispixel = 1;
+ typedata->base = BT_SHORT;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vf"))
+ {
+ typedata->isvector = 1;
+ typedata->base = BT_FLOAT;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vd"))
+ {
+ typedata->isvector = 1;
+ typedata->base = BT_DOUBLE;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "v256"))
+ {
+ typedata->isvector = 1;
+ typedata->base = BT_VPAIR;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "v512"))
+ {
+ typedata->isvector = 1;
+ typedata->base = BT_VQUAD;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "signed"))
+ typedata->issigned = 1;
+ else if (!strcmp (token, "unsigned"))
+ typedata->isunsigned = 1;
+ else if (!typedata->isvoid && !typedata->isconst)
+ {
+ /* Push back token. */
+ 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->issigned && !typedata->isunsigned)
+ pos = oldpos;
+ if (!match_basetype (typedata))
+ return 0;
+
+ if (typedata->isconst)
+ {
+ if (typedata->ispointer)
+ return 1;
+ if (typedata->base != BT_INT)
+ {
+ (*diag)("'const' at %d requires pointer or integer type",
+ oldpos + 1);
+ return 0;
+ }
+ consume_whitespace ();
+ if (linebuf[pos] == '<' || linebuf[pos] == '{' || linebuf[pos] == '[')
+ return match_const_restriction (typedata);
+ }
+
+ return 1;
+}
^ permalink raw reply [flat|nested] 6+ messages in thread
* [gcc(refs/users/wschmidt/heads/builtins10)] rs6000: Add functions for matching types, part 1 of 3
@ 2021-03-25 15:44 William Schmidt
0 siblings, 0 replies; 6+ messages in thread
From: William Schmidt @ 2021-03-25 15:44 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:e894bbea3b8cc38b24bf9c5680e9d4772199fa11
commit e894bbea3b8cc38b24bf9c5680e9d4772199fa11
Author: Bill Schmidt <wschmidt@linux.ibm.com>
Date: Wed Mar 24 11:57:49 2021 -0500
rs6000: Add functions for matching types, part 1 of 3
2021-03-24 Bill Schmidt <wschmidt@linux.ibm.com>
gcc/
* config/rs6000/rs6000-gen-builtins.c (void_status): New enum.
(basetype): Likewise.
(typeinfo): New struct.
(handle_pointer): New function.
(match_basetype): New stub function.
(match_const_restriction): Likewise.
(match_type): New function.
Diff:
---
gcc/config/rs6000/rs6000-gen-builtins.c | 360 ++++++++++++++++++++++++++++++++
1 file changed, 360 insertions(+)
diff --git a/gcc/config/rs6000/rs6000-gen-builtins.c b/gcc/config/rs6000/rs6000-gen-builtins.c
index 136d6911760..5ce1707d84e 100644
--- a/gcc/config/rs6000/rs6000-gen-builtins.c
+++ b/gcc/config/rs6000/rs6000-gen-builtins.c
@@ -189,6 +189,49 @@ 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_LONG,
+ BT_LONGLONG,
+ BT_FLOAT,
+ BT_DOUBLE,
+ BT_LONGDOUBLE,
+ BT_INT128,
+ BT_FLOAT128,
+ BT_BOOL,
+ BT_STRING,
+ BT_DECIMAL32,
+ BT_DECIMAL64,
+ BT_DECIMAL128,
+ BT_IBM128,
+ BT_VPAIR,
+ BT_VQUAD
+};
+
+/* 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;
+ int val1;
+ int val2;
+};
+
/* Exit codes for the shell. */
enum exit_codes {
EC_INTERR
@@ -330,3 +373,320 @@ match_to_right_bracket ()
pos = lastpos + 1;
return buf;
}
+
+static inline void
+handle_pointer (typeinfo *typedata)
+{
+ consume_whitespace ();
+ if (linebuf[pos] == '*')
+ {
+ typedata->ispointer = 1;
+ safe_inc_pos ();
+ }
+}
+
+/* Match one of the allowable base types. Consumes one token unless the
+ token is "long", which must be paired with a second "long". Optionally
+ consumes a following '*' token for pointers. Return 1 for success,
+ 0 for failure. */
+static int
+match_basetype (typeinfo *typedata)
+{
+ 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:
+
+ <x> restricts the constant to x bits, interpreted as unsigned
+ <x,y> restricts the constant to the inclusive range [x,y]
+ [x,y] restricts the constant to the inclusive range [x,y],
+ but only applies if the argument is constant.
+ {x,y} restricts the constant to one of two values, x or y.
+
+ Here x and y are integer tokens. Note that the "const" token is a
+ lie when the restriction is [x,y], but this simplifies the parsing
+ significantly and is hopefully forgivable.
+
+ Return 1 for success, else 0. */
+static int
+match_const_restriction (typeinfo *typedata)
+{
+ 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] <basetype> | <vectype>] [*]
+
+ Legal values of <basetype> are (for now):
+
+ char
+ short
+ int
+ long long
+ float
+ double
+ __int128
+ _Float128
+ _Decimal32
+ _Decimal64
+ _Decimal128
+ __ibm128
+
+ Legal values of <vectype> 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
+ v256 __vector_pair
+ v512 __vector_quad
+
+ For simplicity, We don't support "short int" and "long long int".
+ We don't currently support a <basetype> of "_Float16". "signed"
+ and "unsigned" only apply to integral base types. The optional *
+ indicates a pointer type. */
+
+ consume_whitespace ();
+ memset (typedata, 0, sizeof(*typedata));
+ int oldpos = pos;
+
+ char *token = match_identifier ();
+ if (!token)
+ return 0;
+
+ if (!strcmp (token, "const"))
+ {
+ typedata->isconst = 1;
+ consume_whitespace ();
+ oldpos = pos;
+ token = match_identifier ();
+ }
+
+ if (!strcmp (token, "void"))
+ typedata->isvoid = 1;
+
+ if (!strcmp (token, "vsc"))
+ {
+ typedata->isvector = 1;
+ typedata->issigned = 1;
+ typedata->base = BT_CHAR;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vuc"))
+ {
+ typedata->isvector = 1;
+ typedata->isunsigned = 1;
+ typedata->base = BT_CHAR;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vbc"))
+ {
+ typedata->isvector = 1;
+ typedata->isbool = 1;
+ typedata->base = BT_CHAR;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vss"))
+ {
+ typedata->isvector = 1;
+ typedata->issigned = 1;
+ typedata->base = BT_SHORT;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vus"))
+ {
+ typedata->isvector = 1;
+ typedata->isunsigned = 1;
+ typedata->base = BT_SHORT;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vbs"))
+ {
+ typedata->isvector = 1;
+ typedata->isbool = 1;
+ typedata->base = BT_SHORT;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vsi"))
+ {
+ typedata->isvector = 1;
+ typedata->issigned = 1;
+ typedata->base = BT_INT;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vui"))
+ {
+ typedata->isvector = 1;
+ typedata->isunsigned = 1;
+ typedata->base = BT_INT;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vbi"))
+ {
+ typedata->isvector = 1;
+ typedata->isbool = 1;
+ typedata->base = BT_INT;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vsll"))
+ {
+ typedata->isvector = 1;
+ typedata->issigned = 1;
+ typedata->base = BT_LONGLONG;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vull"))
+ {
+ typedata->isvector = 1;
+ typedata->isunsigned = 1;
+ typedata->base = BT_LONGLONG;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vbll"))
+ {
+ typedata->isvector = 1;
+ typedata->isbool = 1;
+ typedata->base = BT_LONGLONG;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vsq"))
+ {
+ typedata->isvector = 1;
+ typedata->issigned = 1;
+ typedata->base = BT_INT128;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vuq"))
+ {
+ typedata->isvector = 1;
+ typedata->isunsigned = 1;
+ typedata->base = BT_INT128;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vbq"))
+ {
+ typedata->isvector = 1;
+ typedata->isbool = 1;
+ typedata->base = BT_INT128;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vp"))
+ {
+ typedata->isvector = 1;
+ typedata->ispixel = 1;
+ typedata->base = BT_SHORT;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vf"))
+ {
+ typedata->isvector = 1;
+ typedata->base = BT_FLOAT;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "vd"))
+ {
+ typedata->isvector = 1;
+ typedata->base = BT_DOUBLE;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "v256"))
+ {
+ typedata->isvector = 1;
+ typedata->base = BT_VPAIR;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "v512"))
+ {
+ typedata->isvector = 1;
+ typedata->base = BT_VQUAD;
+ handle_pointer (typedata);
+ return 1;
+ }
+ else if (!strcmp (token, "signed"))
+ typedata->issigned = 1;
+ else if (!strcmp (token, "unsigned"))
+ typedata->isunsigned = 1;
+ else if (!typedata->isvoid && !typedata->isconst)
+ {
+ /* Push back token. */
+ 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->issigned && !typedata->isunsigned)
+ pos = oldpos;
+ if (!match_basetype (typedata))
+ return 0;
+
+ if (typedata->isconst)
+ {
+ if (typedata->ispointer)
+ return 1;
+ if (typedata->base != BT_INT)
+ {
+ (*diag)("'const' at %d requires pointer or integer type",
+ oldpos + 1);
+ return 0;
+ }
+ consume_whitespace ();
+ if (linebuf[pos] == '<' || linebuf[pos] == '{' || linebuf[pos] == '[')
+ return match_const_restriction (typedata);
+ }
+
+ return 1;
+}
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-06-25 16:15 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-15 17:16 [gcc(refs/users/wschmidt/heads/builtins10)] rs6000: Add functions for matching types, part 1 of 3 William Schmidt
-- strict thread matches above, loose matches on Subject: below --
2021-06-25 16:15 William Schmidt
2021-04-26 20:48 William Schmidt
2021-04-02 22:09 William Schmidt
2021-04-01 19:47 William Schmidt
2021-03-25 15:44 William Schmidt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).