summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRebecca N. Palmer <rebecca_palmer@zoho.com>2015-04-29 11:26:41 +0100
committerZhigang Gong <zhigang.gong@intel.com>2015-04-30 10:30:50 +0800
commit2b0208daa72e271a7b6c7374a6ae744075259d13 (patch)
tree3d96529bf2889b546263d06279ce164ccd633900
parentd2a47648d8d28665dafbe7e78172492a8c94e949 (diff)
Allow building with Python 3
Make the build scripts work in both Python 2 and Python 3. (CMake prefers Python 2 if both are available, but will use Python 3 if only it is installed.) Signed-off-by: Rebecca Palmer <rebecca_palmer@zoho.com> Reviewed-by: Zhigang Gong <zhigang.gong@linux.intel.com>
-rwxr-xr-xbackend/src/libocl/script/gen_vector.py23
-rw-r--r--utests/utest_generator.py3
2 files changed, 14 insertions, 12 deletions
diff --git a/backend/src/libocl/script/gen_vector.py b/backend/src/libocl/script/gen_vector.py
index ffc573aa..92582f55 100755
--- a/backend/src/libocl/script/gen_vector.py
+++ b/backend/src/libocl/script/gen_vector.py
@@ -20,13 +20,14 @@
# This file is to generate inline code to lower down those builtin
# vector functions to scalar functions.
+from __future__ import print_function
import re
import sys
import os
if len(sys.argv) != 4:
- print "Invalid argument {0}".format(sys.argv)
- print "use {0} spec_file_name output_file_name just_proto".format(sys.argv[0])
+ print("Invalid argument {0}".format(sys.argv))
+ print("use {0} spec_file_name output_file_name just_proto".format(sys.argv[0]))
raise
all_vector = 1,2,3,4,8,16
@@ -61,8 +62,8 @@ all_type = all_int_type + all_float_type
# all vector/scalar types
for t in all_type:
- exec "{0}n = [\"{0}n\", gen_vector_type([\"{0}\"])]".format(t)
- exec "s{0} = [\"{0}\", gen_vector_type([\"{0}\"], [1])]".format(t)
+ exec("{0}n = [\"{0}n\", gen_vector_type([\"{0}\"])]".format(t))
+ exec("s{0} = [\"{0}\", gen_vector_type([\"{0}\"], [1])]".format(t))
# Predefined type sets according to the Open CL spec.
math_gentype = ["math_gentype", gen_vector_type(all_float_type)]
@@ -124,8 +125,8 @@ def check_type(types):
for t in types:
memspace, t = stripMemSpace(t)
if not t in type_dict:
- print t
- raise "found invalid type."
+ print(t)
+ raise TypeError("found invalid type.")
def match_unsigned(dtype):
if dtype[0] == 'float':
@@ -187,8 +188,8 @@ def fixup_type(dstType, srcType, n):
if (len(dstType) == len(srcType)):
return dstType[n]
- print dstType, srcType
- raise "type mispatch"
+ print(dstType, srcType)
+ raise TypeError("type mispatch")
class builtinProto():
valueTypeStr = ""
@@ -226,7 +227,7 @@ class builtinProto():
def init_from_line(self, t):
self.append('//{0}'.format(t))
- line = filter(None, re.split(',| |\(', t.rstrip(')\n')))
+ line = [_f for _f in re.split(',| |\(', t.rstrip(')\n')) if _f]
self.paramCount = 0
stripped = 0
memSpace = ''
@@ -310,7 +311,7 @@ class builtinProto():
vtype = fixup_type(vtypeSeq, ptypeSeqs[n], i)
if vtype[1] != ptype[1]:
if ptype[1] != 1:
- raise "parameter is not a scalar but has different width with result value."
+ raise TypeError("parameter is not a scalar but has different width with result value.")
if isPointer(ptype):
formatStr += '&'
formatStr += 'param{0}'.format(n)
@@ -333,7 +334,7 @@ class builtinProto():
def output(self):
for line in self.outputStr:
- print line
+ print(line)
def output(self, outFile):
for line in self.outputStr:
diff --git a/utests/utest_generator.py b/utests/utest_generator.py
index 510c41a8..7d2d3a06 100644
--- a/utests/utest_generator.py
+++ b/utests/utest_generator.py
@@ -1,4 +1,5 @@
#!/usr/bin/python
+from __future__ import print_function
import os,sys,re
FLT_MAX_POSI='0x1.fffffep127f'
@@ -326,7 +327,7 @@ which can print more values and information to assist debuging the issue.
file_object.close()
def nameForCmake(self,content,namesuffix):
- print("generated/%s_%s.cpp"%(self.fileName,namesuffix)),
+ print("generated/%s_%s.cpp"%(self.fileName,namesuffix),end=" ")
def utestFunc(self,index):
funcLines=[]