Skip to content

Commit 4a27478

Browse files
Python compat - print statement
Make sure all print statements are compatible with Python 2 and Python3 using the `from __future__ import print_function` statement. Differential Revision: https://reviews.llvm.org/D56249 llvm-svn: 350307
1 parent 41f98c8 commit 4a27478

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+592
-487
lines changed

llvm/bindings/python/llvm/core.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# License. See LICENSE.TXT for details.
77
#
88
#===------------------------------------------------------------------------===#
9+
from __future__ import print_function
910

1011
from .common import LLVMObject
1112
from .common import c_object_p
@@ -605,7 +606,7 @@ def register_enumerations():
605606
]
606607
for enum_class, enum_spec in enums:
607608
for name, value in enum_spec:
608-
print name, value
609+
print(name, value)
609610
enum_class.register(name, value)
610611
return enums
611612

llvm/bindings/python/llvm/tests/test_bitreader.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import print_function
2+
13
from .base import TestBase
24
from ..core import OpCode
35
from ..core import MemoryBuffer
@@ -11,5 +13,5 @@ class TestBitReader(TestBase):
1113
def test_parse_bitcode(self):
1214
source = self.get_test_bc()
1315
m = parse_bitcode(MemoryBuffer(filename=source))
14-
print m.target
15-
print m.datalayout
16+
print(m.target)
17+
print(m.datalayout)

llvm/bindings/python/llvm/tests/test_core.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import print_function
2+
13
from .base import TestBase
24
from ..core import MemoryBuffer
35
from ..core import PassRegistry
@@ -127,7 +129,7 @@ def test_basicblock_instruction_iteration(self):
127129
self.assertEqual(inst.opcode, inst_list[i][1])
128130
for op in range(len(inst)):
129131
o = inst.get_operand(op)
130-
print o.name
132+
print(o.name)
131133
o.dump()
132134
inst.dump()
133135
i += 1

llvm/bindings/python/llvm/tests/test_disassembler.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import print_function
2+
13
from .base import TestBase
24

35
from ..disassembler import Disassembler, Option_UseMarkup
@@ -38,6 +40,6 @@ def test_set_options(self):
3840
disassembler = Disassembler(triple)
3941
disassembler.set_options(Option_UseMarkup)
4042
count, s = disassembler.get_instruction(sequence)
41-
print s
43+
print(s)
4244
self.assertEqual(count, 4)
4345
self.assertEqual(s, '\tpush\t{<reg:r4>, <reg:lr>}')

llvm/docs/conf.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#
1010
# All configuration values have a default; values that are commented out
1111
# serve to show the default.
12+
from __future__ import print_function
1213

1314
import sys, os
1415
from datetime import date
@@ -234,14 +235,14 @@
234235
header = f.readline().rstrip('\n')
235236

236237
if len(header) != len(title):
237-
print >>sys.stderr, (
238+
print((
238239
"error: invalid header in %r (does not match title)" % (
239-
file_subpath,))
240+
file_subpath,)), file=sys.stderr)
240241
if ' - ' not in title:
241-
print >>sys.stderr, (
242+
print((
242243
("error: invalid title in %r "
243244
"(expected '<name> - <description>')") % (
244-
file_subpath,))
245+
file_subpath,)), file=sys.stderr)
245246

246247
# Split the name out of the title.
247248
name,description = title.split(' - ', 1)

llvm/examples/Kaleidoscope/MCJIT/cached/genk-timing.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env python
22

3+
from __future__ import print_function
4+
35
import sys
46
import random
57

@@ -173,7 +175,7 @@ def writeFinalFunctionCounts(self):
173175

174176
def generateKScript(filename, numFuncs, elementsPerFunc, funcsBetweenExec, callWeighting, timingScript):
175177
""" Generate a random Kaleidoscope script based on the given parameters """
176-
print "Generating " + filename
178+
print("Generating " + filename)
177179
print(" %d functions, %d elements per function, %d functions between execution" %
178180
(numFuncs, elementsPerFunc, funcsBetweenExec))
179181
print(" Call weighting = %f" % callWeighting)
@@ -200,7 +202,7 @@ def generateKScript(filename, numFuncs, elementsPerFunc, funcsBetweenExec, callW
200202
script.writeEmptyLine()
201203
script.writeFinalFunctionCounts()
202204
funcsCalled = len(script.calledFunctions)
203-
print " Called %d of %d functions, %d total" % (funcsCalled, numFuncs, script.totalCallsExecuted)
205+
print(" Called %d of %d functions, %d total" % (funcsCalled, numFuncs, script.totalCallsExecuted))
204206
timingScript.writeTimingCall(filename, numFuncs, funcsCalled, script.totalCallsExecuted)
205207

206208
# Execution begins here
@@ -216,4 +218,4 @@ def generateKScript(filename, numFuncs, elementsPerFunc, funcsBetweenExec, callW
216218
for (numFuncs, elementsPerFunc, funcsBetweenExec, callWeighting) in dataSets:
217219
filename = "test-%d-%d-%d-%d.k" % (numFuncs, elementsPerFunc, funcsBetweenExec, int(callWeighting * 100))
218220
generateKScript(filename, numFuncs, elementsPerFunc, funcsBetweenExec, callWeighting, timingScript)
219-
print "All done!"
221+
print("All done!")

llvm/examples/Kaleidoscope/MCJIT/cached/split-lib.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env python
22

3+
from __future__ import print_function
4+
35
class TimingScriptGenerator:
46
"""Used to generate a bash script which will invoke the toy and time it"""
57
def __init__(self, scriptname, outputname):
@@ -47,7 +49,7 @@ def splitScript(inputname, libGenScript, timingScript):
4749
infile = open(inputname, "r")
4850
libfile = open(libname, "w")
4951
callfile = open(callname, "w")
50-
print "Splitting %s into %s and %s" % (inputname, callname, libname)
52+
print("Splitting %s into %s and %s" % (inputname, callname, libname))
5153
for line in infile:
5254
if not line.startswith("#"):
5355
if line.startswith("print"):
@@ -67,4 +69,4 @@ def splitScript(inputname, libGenScript, timingScript):
6769

6870
for script in script_list:
6971
splitScript(script, libGenScript, timingScript)
70-
print "All done!"
72+
print("All done!")

llvm/examples/Kaleidoscope/MCJIT/complete/genk-timing.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env python
22

3+
from __future__ import print_function
4+
35
import sys
46
import random
57

@@ -178,7 +180,7 @@ def writeFinalFunctionCounts(self):
178180

179181
def generateKScript(filename, numFuncs, elementsPerFunc, funcsBetweenExec, callWeighting, timingScript):
180182
""" Generate a random Kaleidoscope script based on the given parameters """
181-
print "Generating " + filename
183+
print("Generating " + filename)
182184
print(" %d functions, %d elements per function, %d functions between execution" %
183185
(numFuncs, elementsPerFunc, funcsBetweenExec))
184186
print(" Call weighting = %f" % callWeighting)
@@ -205,7 +207,7 @@ def generateKScript(filename, numFuncs, elementsPerFunc, funcsBetweenExec, callW
205207
script.writeEmptyLine()
206208
script.writeFinalFunctionCounts()
207209
funcsCalled = len(script.calledFunctions)
208-
print " Called %d of %d functions, %d total" % (funcsCalled, numFuncs, script.totalCallsExecuted)
210+
print(" Called %d of %d functions, %d total" % (funcsCalled, numFuncs, script.totalCallsExecuted))
209211
timingScript.writeTimingCall(filename, numFuncs, funcsCalled, script.totalCallsExecuted)
210212

211213
# Execution begins here
@@ -221,4 +223,4 @@ def generateKScript(filename, numFuncs, elementsPerFunc, funcsBetweenExec, callW
221223
for (numFuncs, elementsPerFunc, funcsBetweenExec, callWeighting) in dataSets:
222224
filename = "test-%d-%d-%d-%d.k" % (numFuncs, elementsPerFunc, funcsBetweenExec, int(callWeighting * 100))
223225
generateKScript(filename, numFuncs, elementsPerFunc, funcsBetweenExec, callWeighting, timingScript)
224-
print "All done!"
226+
print("All done!")

llvm/examples/Kaleidoscope/MCJIT/complete/split-lib.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env python
22

3+
from __future__ import print_function
4+
35
class TimingScriptGenerator:
46
"""Used to generate a bash script which will invoke the toy and time it"""
57
def __init__(self, scriptname, outputname):
@@ -47,7 +49,7 @@ def splitScript(inputname, libGenScript, timingScript):
4749
infile = open(inputname, "r")
4850
libfile = open(libname, "w")
4951
callfile = open(callname, "w")
50-
print "Splitting %s into %s and %s" % (inputname, callname, libname)
52+
print("Splitting %s into %s and %s" % (inputname, callname, libname))
5153
for line in infile:
5254
if not line.startswith("#"):
5355
if line.startswith("print"):
@@ -67,4 +69,4 @@ def splitScript(inputname, libGenScript, timingScript):
6769

6870
for script in script_list:
6971
splitScript(script, libGenScript, timingScript)
70-
print "All done!"
72+
print("All done!")

llvm/examples/Kaleidoscope/MCJIT/lazy/genk-timing.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env python
22

3+
from __future__ import print_function
4+
35
import sys
46
import random
57

@@ -173,7 +175,7 @@ def writeFinalFunctionCounts(self):
173175

174176
def generateKScript(filename, numFuncs, elementsPerFunc, funcsBetweenExec, callWeighting, timingScript):
175177
""" Generate a random Kaleidoscope script based on the given parameters """
176-
print "Generating " + filename
178+
print("Generating " + filename)
177179
print(" %d functions, %d elements per function, %d functions between execution" %
178180
(numFuncs, elementsPerFunc, funcsBetweenExec))
179181
print(" Call weighting = %f" % callWeighting)
@@ -200,7 +202,7 @@ def generateKScript(filename, numFuncs, elementsPerFunc, funcsBetweenExec, callW
200202
script.writeEmptyLine()
201203
script.writeFinalFunctionCounts()
202204
funcsCalled = len(script.calledFunctions)
203-
print " Called %d of %d functions, %d total" % (funcsCalled, numFuncs, script.totalCallsExecuted)
205+
print(" Called %d of %d functions, %d total" % (funcsCalled, numFuncs, script.totalCallsExecuted))
204206
timingScript.writeTimingCall(filename, numFuncs, funcsCalled, script.totalCallsExecuted)
205207

206208
# Execution begins here
@@ -216,4 +218,4 @@ def generateKScript(filename, numFuncs, elementsPerFunc, funcsBetweenExec, callW
216218
for (numFuncs, elementsPerFunc, funcsBetweenExec, callWeighting) in dataSets:
217219
filename = "test-%d-%d-%d-%d.k" % (numFuncs, elementsPerFunc, funcsBetweenExec, int(callWeighting * 100))
218220
generateKScript(filename, numFuncs, elementsPerFunc, funcsBetweenExec, callWeighting, timingScript)
219-
print "All done!"
221+
print("All done!")

llvm/test/BugPoint/compile-custom.ll.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env python
22

3+
from __future__ import print_function
4+
35
import sys
46

57
# Currently any print-out from the custom tool is interpreted as a crash

llvm/test/CodeGen/NVPTX/ld-st-addrrspace.py

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
# RUN: llc < %t.ll -march=nvptx64 -mcpu=sm_30 | FileCheck -check-prefixes=CHECK,CHECK_P64 %t.ll
66
# RUN: llc < %t.ll -march=nvptx -mcpu=sm_30 | FileCheck -check-prefixes=CHECK,CHECK_P32 %t.ll
77

8+
from __future__ import print_function
9+
810
from itertools import product
911
from string import Template
1012

llvm/test/CodeGen/NVPTX/wmma.py

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
# RUN: python %s > %t.ll
55
# RUN: llc < %t.ll -march=nvptx64 -mcpu=sm_70 -mattr=+ptx61 | FileCheck %t.ll
66

7+
from __future__ import print_function
8+
79
from itertools import product
810
from string import Template
911

llvm/test/CodeGen/SystemZ/Large/branch-range-01.py

+25-23
Original file line numberDiff line numberDiff line change
@@ -67,42 +67,44 @@
6767
# CHECK: c %r4, 136(%r3)
6868
# CHECK: jge [[LABEL]]
6969

70+
from __future__ import print_function
71+
7072
branch_blocks = 10
7173
main_size = 0xffd8
7274

73-
print '@global = global i32 0'
75+
print('@global = global i32 0')
7476

75-
print 'define void @f1(i8 *%base, i32 *%stop, i32 %limit) {'
76-
print 'entry:'
77-
print ' br label %before0'
78-
print ''
77+
print('define void @f1(i8 *%base, i32 *%stop, i32 %limit) {')
78+
print('entry:')
79+
print(' br label %before0')
80+
print('')
7981

8082
for i in xrange(branch_blocks):
8183
next = 'before%d' % (i + 1) if i + 1 < branch_blocks else 'main'
82-
print 'before%d:' % i
83-
print ' %%bstop%d = getelementptr i32, i32 *%%stop, i64 %d' % (i, i)
84-
print ' %%bcur%d = load i32 , i32 *%%bstop%d' % (i, i)
85-
print ' %%btest%d = icmp eq i32 %%limit, %%bcur%d' % (i, i)
86-
print ' br i1 %%btest%d, label %%after0, label %%%s' % (i, next)
87-
print ''
84+
print('before%d:' % i)
85+
print(' %%bstop%d = getelementptr i32, i32 *%%stop, i64 %d' % (i, i))
86+
print(' %%bcur%d = load i32 , i32 *%%bstop%d' % (i, i))
87+
print(' %%btest%d = icmp eq i32 %%limit, %%bcur%d' % (i, i))
88+
print(' br i1 %%btest%d, label %%after0, label %%%s' % (i, next))
89+
print('')
8890

89-
print '%s:' % next
91+
print('%s:' % next)
9092
a, b = 1, 1
9193
for i in xrange(0, main_size, 6):
9294
a, b = b, a + b
9395
offset = 4096 + b % 500000
9496
value = a % 256
95-
print ' %%ptr%d = getelementptr i8, i8 *%%base, i64 %d' % (i, offset)
96-
print ' store volatile i8 %d, i8 *%%ptr%d' % (value, i)
97+
print(' %%ptr%d = getelementptr i8, i8 *%%base, i64 %d' % (i, offset))
98+
print(' store volatile i8 %d, i8 *%%ptr%d' % (value, i))
9799

98100
for i in xrange(branch_blocks):
99-
print ' %%astop%d = getelementptr i32, i32 *%%stop, i64 %d' % (i, i + 25)
100-
print ' %%acur%d = load i32 , i32 *%%astop%d' % (i, i)
101-
print ' %%atest%d = icmp eq i32 %%limit, %%acur%d' % (i, i)
102-
print ' br i1 %%atest%d, label %%main, label %%after%d' % (i, i)
103-
print ''
104-
print 'after%d:' % i
101+
print(' %%astop%d = getelementptr i32, i32 *%%stop, i64 %d' % (i, i + 25))
102+
print(' %%acur%d = load i32 , i32 *%%astop%d' % (i, i))
103+
print(' %%atest%d = icmp eq i32 %%limit, %%acur%d' % (i, i))
104+
print(' br i1 %%atest%d, label %%main, label %%after%d' % (i, i))
105+
print('')
106+
print('after%d:' % i)
105107

106-
print ' %dummy = load volatile i32, i32 *@global'
107-
print ' ret void'
108-
print '}'
108+
print(' %dummy = load volatile i32, i32 *@global')
109+
print(' ret void')
110+
print('}')

llvm/test/CodeGen/SystemZ/Large/branch-range-02.py

+16-14
Original file line numberDiff line numberDiff line change
@@ -56,27 +56,29 @@
5656
# CHECK: c %r4, 1036(%r3)
5757
# CHECK: jge [[LABEL]]
5858

59+
from __future__ import print_function
60+
5961
blocks = 256 + 4
6062

61-
print 'define void @f1(i8 *%base, i32 *%stop, i32 %limit) {'
62-
print 'entry:'
63-
print ' br label %b0'
64-
print ''
63+
print('define void @f1(i8 *%base, i32 *%stop, i32 %limit) {')
64+
print('entry:')
65+
print(' br label %b0')
66+
print('')
6567

6668
a, b = 1, 1
6769
for i in xrange(blocks):
6870
a, b = b, a + b
6971
value = a % 256
7072
next = 'b%d' % (i + 1) if i + 1 < blocks else 'end'
7173
other = 'end' if 2 * i < blocks else 'b0'
72-
print 'b%d:' % i
73-
print ' store volatile i8 %d, i8 *%%base' % value
74-
print ' %%astop%d = getelementptr i32, i32 *%%stop, i64 %d' % (i, i)
75-
print ' %%acur%d = load i32 , i32 *%%astop%d' % (i, i)
76-
print ' %%atest%d = icmp eq i32 %%limit, %%acur%d' % (i, i)
77-
print ' br i1 %%atest%d, label %%%s, label %%%s' % (i, other, next)
74+
print('b%d:' % i)
75+
print(' store volatile i8 %d, i8 *%%base' % value)
76+
print(' %%astop%d = getelementptr i32, i32 *%%stop, i64 %d' % (i, i))
77+
print(' %%acur%d = load i32 , i32 *%%astop%d' % (i, i))
78+
print(' %%atest%d = icmp eq i32 %%limit, %%acur%d' % (i, i))
79+
print(' br i1 %%atest%d, label %%%s, label %%%s' % (i, other, next))
7880

79-
print ''
80-
print '%s:' % next
81-
print ' ret void'
82-
print '}'
81+
print('')
82+
print('%s:' % next)
83+
print(' ret void')
84+
print('}')

0 commit comments

Comments
 (0)