From 38d82357747a50715f998e0cda3852ca83871f79 Mon Sep 17 00:00:00 2001 From: Jon Nordby Date: Thu, 6 Feb 2014 19:50:59 +0100 Subject: [PATCH] Make build compatible with Python 2.6 Implicit numbers for format specifiers "{}" can only be used on Py2.7+, and Py2.6 is still in use on for instance CentOS 6.5 and similar. Reviewed-by: Zhigang Gong --- backend/src/gen_builtin_vector.py | 28 ++++++++++++++-------------- backend/src/update_blob_ocl_header.py | 8 ++++---- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/backend/src/gen_builtin_vector.py b/backend/src/gen_builtin_vector.py index d7336af..b100bbf 100755 --- a/backend/src/gen_builtin_vector.py +++ b/backend/src/gen_builtin_vector.py @@ -25,8 +25,8 @@ import sys import os if len(sys.argv) != 3: - print "Invalid argument {}".format(sys.argv) - print "use {} spec_file_name output_file_name".format(sys.argv[0]) + print "Invalid argument {0}".format(sys.argv) + print "use {0} spec_file_name output_file_name".format(sys.argv[0]) raise all_vector = 1,2,3,4,8,16 @@ -223,7 +223,7 @@ class builtinProto(): return ret def init_from_line(self, t): - self.append('//{}'.format(t)) + self.append('//{0}'.format(t)) line = filter(None, re.split(',| |\(', t.rstrip(')\n'))) self.paramCount = 0 stripped = 0 @@ -264,7 +264,7 @@ class builtinProto(): return if (n == 0): - formatStr = 'INLINE_OVERLOADABLE {}{} {} ('.format(vtype[0], vtype[1], self.functionName) + formatStr = 'INLINE_OVERLOADABLE {0}{1} {2} ('.format(vtype[0], vtype[1], self.functionName) else: formatStr += ', ' @@ -278,12 +278,12 @@ class builtinProto(): pointerStr = '' if ptype[1] != 1: - formatStr += '{}{} {}param{}'.format(ptype[0], ptype[1], pointerStr, n) + formatStr += '{0}{1} {2}param{3}'.format(ptype[0], ptype[1], pointerStr, n) else: - formatStr += '{} {}param{}'.format(ptype[0], pointerStr, n) + formatStr += '{0} {1}param{2}'.format(ptype[0], pointerStr, n) formatStr += ')' - formatStr = self.append(formatStr, '{{return ({}{})('.format(vtype[0], vtype[1])) + formatStr = self.append(formatStr, '{{return ({0}{1})('.format(vtype[0], vtype[1])) self.indent = len(formatStr) for j in range(0, vtype[1]): if (j != 0): @@ -295,7 +295,7 @@ class builtinProto(): if self.prefix == 'relational' and self.functionName != 'bitselect' and self.functionName != 'select': formatStr += '-' - formatStr += '{}('.format(self.functionName) + formatStr += '{0}('.format(self.functionName) for n in range(0, self.paramCount): if n != 0: formatStr += ', ' @@ -307,16 +307,16 @@ class builtinProto(): raise "parameter is not a scalar but has different width with result value." if isPointer(ptype): formatStr += '&' - formatStr += 'param{}'.format(n) + formatStr += 'param{0}'.format(n) continue if (isPointer(ptype)): - formatStr += '({} {} *)param{} + {:2d}'.format(ptype[2], ptype[0], n, j) + formatStr += '({0} {1} *)param{2} + {3:2d}'.format(ptype[2], ptype[0], n, j) else: if (self.functionName == 'select' and n == 2): formatStr += '({0})(param{1}.s{2:x} & (({0})1 << (sizeof({0})*8 - 1)))'.format(ptype[0], n, j) else: - formatStr += 'param{}.s{:x}'.format(n, j) + formatStr += 'param{0}.s{1:x}'.format(n, j) formatStr += ')' @@ -331,7 +331,7 @@ class builtinProto(): def output(self, outFile): for line in self.outputStr: - outFile.write('{}\n'.format(line)) + outFile.write('{0}\n'.format(line)) def gen_proto_str(self): check_type([self.valueTypeStr] + self.paramTypeStrs) @@ -361,7 +361,7 @@ tempHeaderFileName = sys.argv[2] + '.tmp' safeUnlink(headerFileName) tempHeader = open(tempHeaderFileName, 'w') -tempHeader.write("//This file is autogenerated by {}.\n".format(sys.argv[0])) +tempHeader.write("//This file is autogenerated by {0}.\n".format(sys.argv[0])) tempHeader.write("//Don't modify it manually.\n") functionProto = builtinProto() @@ -370,7 +370,7 @@ for line in specFile: continue if line[0] == '#': if line[1] == '#': - sectionHeader = "//{} builtin functions".format(line[2:].rstrip()) + sectionHeader = "//{0} builtin functions".format(line[2:].rstrip()) sectionPrefix=(line[2:].split())[0] continue functionProto.init(sectionHeader, sectionPrefix) diff --git a/backend/src/update_blob_ocl_header.py b/backend/src/update_blob_ocl_header.py index 197f16c..7d6907a 100755 --- a/backend/src/update_blob_ocl_header.py +++ b/backend/src/update_blob_ocl_header.py @@ -21,8 +21,8 @@ import sys import os if len(sys.argv) != 3: - print "Invalid argument {}".format(sys.argv) - print "use {} tmpl_file_name output_file_name".format(sys.argv[0]) + print "Invalid argument {0}".format(sys.argv) + print "use {0} tmpl_file_name output_file_name".format(sys.argv[0]) raise def safeUnlink(filename): @@ -46,7 +46,7 @@ for tline in tmplFile: if matched_header == "": blob.write(tline) for header in header_segments: - if tline.strip() == '// ##BEGIN_{}##'.format(header.upper()) : + if tline.strip() == '// ##BEGIN_{0}##'.format(header.upper()) : hFile = open(path + '/ocl_' + header + '.h', 'r') lineNr = 0 for hline in hFile: @@ -56,7 +56,7 @@ for tline in tmplFile: hFile.close() matched_header = header else: - if tline.strip() == '// ##END_{}##'.format(matched_header.upper()) : + if tline.strip() == '// ##END_{0}##'.format(matched_header.upper()) : blob.write(tline) matched_header = ""; -- 2.7.4