summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorSerge Guelton <sguelton@quarkslab.com>2018-12-18 16:04:21 +0000
committerSerge Guelton <sguelton@quarkslab.com>2018-12-18 16:04:21 +0000
commitbd8d3419e1b6a1c7ec82e1ceb1f22b407a38dac9 (patch)
tree560bc893dd4d59a78b0bc277418faeb97299917c /utils
parent38ed7e5d7917d18c9c7af9c49c5d83a112c6222a (diff)
downloadclang-bd8d3419e1b6a1c7ec82e1ceb1f22b407a38dac9.tar.gz
Portable Python script across Python version
In Python3, dict.items, dict.keys, dict.values, zip, map and filter no longer return lists, they create generator instead. The portability patch consists in forcing an extra `list` call if the result is actually used as a list. `map` are replaced by list comprehension and `filter` by filtered list comprehension. Differential Revision: https://reviews.llvm.org/D55197 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349501 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils')
-rwxr-xr-xutils/ABITest/ABITestGen.py6
-rw-r--r--utils/ABITest/TypeGen.py6
-rwxr-xr-xutils/analyzer/CmpRuns.py4
-rwxr-xr-xutils/analyzer/SATestBuild.py3
-rwxr-xr-xutils/check_cfc/check_cfc.py4
-rwxr-xr-xutils/check_cfc/obj_diff.py4
-rw-r--r--utils/perf-training/perf-helper.py6
7 files changed, 16 insertions, 17 deletions
diff --git a/utils/ABITest/ABITestGen.py b/utils/ABITest/ABITestGen.py
index d42e08e123..a829f925df 100755
--- a/utils/ABITest/ABITestGen.py
+++ b/utils/ABITest/ABITestGen.py
@@ -148,7 +148,7 @@ class TypePrinter(object):
retvalTests = None
else:
retvalTests = self.getTestValuesArray(FT.returnType)
- tests = map(self.getTestValuesArray, FT.argTypes)
+ tests = [self.getTestValuesArray(ty) for ty in FT.argTypes]
print('void test_%s(void) {'%(fnName,), file=self.outputTests)
if retvalTests is not None:
@@ -231,10 +231,10 @@ class TypePrinter(object):
yield '{ %s }' % v
return
- fieldValues = map(list, map(self.getTestValues, nonPadding))
+ fieldValues = [list(v) for v in map(self.getTestValues, nonPadding)]
for i,values in enumerate(fieldValues):
for v in values:
- elements = map(random.choice,fieldValues)
+ elements = [random.choice(fv) for fv in fieldValues]
elements[i] = v
yield '{ %s }'%(', '.join(elements))
diff --git a/utils/ABITest/TypeGen.py b/utils/ABITest/TypeGen.py
index 698e358829..8561baea61 100644
--- a/utils/ABITest/TypeGen.py
+++ b/utils/ABITest/TypeGen.py
@@ -110,7 +110,7 @@ class RecordType(Type):
t.getBitFieldSize())
else:
return '%s field%d;'%(printer.getTypeName(t),i)
- fields = map(getField, enumerate(self.fields))
+ fields = [getField(f) for f in enumerate(self.fields)]
# Name the struct for more readable LLVM IR.
return 'typedef %s %s { %s } %s;'%(('struct','union')[self.isUnion],
name, ' '.join(fields), name)
@@ -372,7 +372,7 @@ class RecordTypeGenerator(TypeGenerator):
isUnion,I = False,N
if self.useUnion:
isUnion,I = (I&1),I>>1
- fields = map(self.typeGen.get,getNthTuple(I,self.maxSize,self.typeGen.cardinality))
+ fields = [self.typeGen.get(f) for f in getNthTuple(I,self.maxSize,self.typeGen.cardinality)]
return RecordType(N, isUnion, fields)
class FunctionTypeGenerator(TypeGenerator):
@@ -405,7 +405,7 @@ class FunctionTypeGenerator(TypeGenerator):
else:
retTy = None
argIndices = getNthTuple(N, self.maxSize, self.typeGen.cardinality)
- args = map(self.typeGen.get, argIndices)
+ args = [self.typeGen.get(i) for i in argIndices]
return FunctionType(N, retTy, args)
class AnyTypeGenerator(TypeGenerator):
diff --git a/utils/analyzer/CmpRuns.py b/utils/analyzer/CmpRuns.py
index 87d5eda7a1..be50349962 100755
--- a/utils/analyzer/CmpRuns.py
+++ b/utils/analyzer/CmpRuns.py
@@ -298,10 +298,10 @@ def deriveStats(results):
combined_data['PathsLength'].append(diagnostic.getPathLength())
for stat in results.stats:
- for key, value in stat.iteritems():
+ for key, value in stat.items():
combined_data[key].append(value)
combined_stats = {}
- for key, values in combined_data.iteritems():
+ for key, values in combined_data.items():
combined_stats[str(key)] = {
"max": max(values),
"min": min(values),
diff --git a/utils/analyzer/SATestBuild.py b/utils/analyzer/SATestBuild.py
index 70c425d38e..1c96cd8838 100755
--- a/utils/analyzer/SATestBuild.py
+++ b/utils/analyzer/SATestBuild.py
@@ -583,8 +583,7 @@ def runCmpResults(Dir, Strictness=0):
# Iterate and find the differences.
NumDiffs = 0
- PairList = zip(RefList, NewList)
- for P in PairList:
+ for P in zip(RefList, NewList):
RefDir = P[0]
NewDir = P[1]
diff --git a/utils/check_cfc/check_cfc.py b/utils/check_cfc/check_cfc.py
index 0228f1d625..aea9bdd638 100755
--- a/utils/check_cfc/check_cfc.py
+++ b/utils/check_cfc/check_cfc.py
@@ -98,8 +98,8 @@ def remove_dir_from_path(path_var, directory):
PATH"""
pathlist = path_var.split(os.pathsep)
norm_directory = os.path.normpath(os.path.normcase(directory))
- pathlist = filter(lambda x: os.path.normpath(
- os.path.normcase(x)) != norm_directory, pathlist)
+ pathlist = [x for x in pathlist if os.path.normpath(
+ os.path.normcase(x)) != norm_directory]
return os.pathsep.join(pathlist)
def path_without_wrapper():
diff --git a/utils/check_cfc/obj_diff.py b/utils/check_cfc/obj_diff.py
index cc4c2a97d5..61b9118df8 100755
--- a/utils/check_cfc/obj_diff.py
+++ b/utils/check_cfc/obj_diff.py
@@ -25,7 +25,7 @@ def disassemble(objfile):
if p.returncode or err:
print("Disassemble failed: {}".format(objfile))
sys.exit(1)
- return filter(keep_line, out.split(os.linesep))
+ return [line for line in out.split(os.linesep) if keep_line(line)]
def dump_debug(objfile):
"""Dump all of the debug info from a file."""
@@ -34,7 +34,7 @@ def dump_debug(objfile):
if p.returncode or err:
print("Dump debug failed: {}".format(objfile))
sys.exit(1)
- return filter(keep_line, out.split(os.linesep))
+ return [line for line in out.split(os.linesep) if keep_line(line)]
def first_diff(a, b, fromfile, tofile):
"""Returns the first few lines of a difference, if there is one. Python
diff --git a/utils/perf-training/perf-helper.py b/utils/perf-training/perf-helper.py
index 30b9caeffd..6337a9b19a 100644
--- a/utils/perf-training/perf-helper.py
+++ b/utils/perf-training/perf-helper.py
@@ -295,8 +295,8 @@ def form_by_frequency(symbol_lists):
for a in symbols:
counts[a] = counts.get(a,0) + 1
- by_count = counts.items()
- by_count.sort(key = lambda (_,n): -n)
+ by_count = list(counts.items())
+ by_count.sort(key = lambda __n: -__n[1])
return [s for s,n in by_count]
def form_by_random(symbol_lists):
@@ -333,7 +333,7 @@ def genOrderFile(args):
help="write a list of the unordered symbols to PATH (requires --binary)",
default=None, metavar="PATH")
parser.add_argument("--method", dest="method",
- help="order file generation method to use", choices=methods.keys(),
+ help="order file generation method to use", choices=list(methods.keys()),
default='call_order')
opts = parser.parse_args(args)