aboutsummaryrefslogtreecommitdiffstats
path: root/src/compiler/nir/nir_algebraic.py
diff options
context:
space:
mode:
authorMathieu Bridon <[email protected]>2018-08-09 10:27:22 +0200
committerDylan Baker <[email protected]>2018-08-09 16:49:19 -0700
commit1e668ca111563b122b16be5506638983b31205b5 (patch)
tree0654f232c600cae9278cdf77437c7fceed94559e /src/compiler/nir/nir_algebraic.py
parent14f1ab998fcdcd8fec43c3da8ef03af4af2d3966 (diff)
python: Better check for integer types
Python 3 lost the long type: now everything is an int, with the right size. This commit makes the script compatible with Python 2 (where we check for both int and long) and Python 3 (where we only check for int). Signed-off-by: Mathieu Bridon <[email protected]> Reviewed-by: Eric Engestrom <[email protected]> Reviewed-by: Dylan Baker <[email protected]>
Diffstat (limited to 'src/compiler/nir/nir_algebraic.py')
-rw-r--r--src/compiler/nir/nir_algebraic.py8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/compiler/nir/nir_algebraic.py b/src/compiler/nir/nir_algebraic.py
index 5baeea88afe..3055937029c 100644
--- a/src/compiler/nir/nir_algebraic.py
+++ b/src/compiler/nir/nir_algebraic.py
@@ -36,9 +36,11 @@ import traceback
from nir_opcodes import opcodes
if sys.version_info < (3, 0):
+ integer_types = (int, long)
string_type = unicode
else:
+ integer_types = (int, )
string_type = str
_type_re = re.compile(r"(?P<type>int|uint|bool|float)?(?P<bits>\d+)?")
@@ -81,7 +83,7 @@ class Value(object):
return val
elif isinstance(val, string_type):
return Variable(val, name_base, varset)
- elif isinstance(val, (bool, int, long, float)):
+ elif isinstance(val, (bool, float) + integer_types):
return Constant(val, name_base)
__template = mako.template.Template("""
@@ -145,7 +147,7 @@ class Constant(Value):
def hex(self):
if isinstance(self.value, (bool)):
return 'NIR_TRUE' if self.value else 'NIR_FALSE'
- if isinstance(self.value, (int, long)):
+ if isinstance(self.value, integer_types):
return hex(self.value)
elif isinstance(self.value, float):
i = struct.unpack('Q', struct.pack('d', self.value))[0]
@@ -164,7 +166,7 @@ class Constant(Value):
def type(self):
if isinstance(self.value, (bool)):
return "nir_type_bool32"
- elif isinstance(self.value, (int, long)):
+ elif isinstance(self.value, integer_types):
return "nir_type_int"
elif isinstance(self.value, float):
return "nir_type_float"