summaryrefslogtreecommitdiffstats
path: root/src/compiler/glsl/glsl_lexer.ll
diff options
context:
space:
mode:
authorDave Airlie <[email protected]>2016-06-09 09:39:48 +1000
committerIan Romanick <[email protected]>2017-01-20 15:41:23 -0800
commitbbce1c538dc0cb8bf3769510283d11847dc07540 (patch)
tree54c9174e9a8ee7cd9c882e3de110d2ec248a1983 /src/compiler/glsl/glsl_lexer.ll
parent249007d13cf10cdc1359a15939b50f947f1cae6a (diff)
glsl/ast/ir: Add 64-bit integer constant support
This adds support for 64-bit integer constants to the parser, ast and ir. v2: fix a few issues found in testing. v3: Add missing ir_constant copy contructor support. v4: Use PRIu64 and PRId64 in printfs in glsl_parser_extras.cpp. Suggested by Nicolai. Rebase on Marek's linalloc changes. Signed-off-by: Dave Airlie <[email protected]> Reviewed-by: Ian Romanick <[email protected]> [v2] Reviewed-by: Matt Turner <[email protected]> [v3] Reviewed-by: Nicolai Hähnle <[email protected]>
Diffstat (limited to 'src/compiler/glsl/glsl_lexer.ll')
-rw-r--r--src/compiler/glsl/glsl_lexer.ll27
1 files changed, 21 insertions, 6 deletions
diff --git a/src/compiler/glsl/glsl_lexer.ll b/src/compiler/glsl/glsl_lexer.ll
index 4c0980fc248..039eb43038d 100644
--- a/src/compiler/glsl/glsl_lexer.ll
+++ b/src/compiler/glsl/glsl_lexer.ll
@@ -107,17 +107,29 @@ literal_integer(char *text, int len, struct _mesa_glsl_parse_state *state,
{
bool is_uint = (text[len - 1] == 'u' ||
text[len - 1] == 'U');
+ bool is_long = (text[len - 1] == 'l' || text[len - 1] == 'L');
const char *digits = text;
+ if (is_long)
+ is_uint = (text[len - 2] == 'u' && text[len - 1] == 'l') ||
+ (text[len - 2] == 'U' && text[len - 1] == 'L');
/* Skip "0x" */
if (base == 16)
digits += 2;
unsigned long long value = strtoull(digits, NULL, base);
- lval->n = (int)value;
+ if (is_long)
+ lval->n64 = (int64_t)value;
+ else
+ lval->n = (int)value;
- if (value > UINT_MAX) {
+ if (is_long && !is_uint && base == 10 && value > (uint64_t)LLONG_MAX + 1) {
+ /* Tries to catch unintentionally providing a negative value. */
+ _mesa_glsl_warning(lloc, state,
+ "signed literal value `%s' is interpreted as %lld",
+ text, lval->n64);
+ } else if (!is_long && value > UINT_MAX) {
/* Note that signed 0xffffffff is valid, not out of range! */
if (state->is_version(130, 300)) {
_mesa_glsl_error(lloc, state,
@@ -135,7 +147,10 @@ literal_integer(char *text, int len, struct _mesa_glsl_parse_state *state,
"signed literal value `%s' is interpreted as %d",
text, lval->n);
}
- return is_uint ? UINTCONSTANT : INTCONSTANT;
+ if (is_long)
+ return is_uint ? UINT64CONSTANT : INT64CONSTANT;
+ else
+ return is_uint ? UINTCONSTANT : INTCONSTANT;
}
#define LITERAL_INTEGER(base) \
@@ -462,13 +477,13 @@ layout {
\|= return OR_ASSIGN;
-= return SUB_ASSIGN;
-[1-9][0-9]*[uU]? {
+[1-9][0-9]*([uU]|[lL]|ul|UL)? {
return LITERAL_INTEGER(10);
}
-0[xX][0-9a-fA-F]+[uU]? {
+0[xX][0-9a-fA-F]+([uU]|[lL]|ul|UL)? {
return LITERAL_INTEGER(16);
}
-0[0-7]*[uU]? {
+0[0-7]*([uU]|[lL]|ul|UL)? {
return LITERAL_INTEGER(8);
}