Updating to python 3 with 2to3. Check llvm/py3k_update.diff and llvm/py3k_update.out for the output from this.

This commit is contained in:
AndrewBC 2011-06-11 20:39:16 -05:00
commit 6d50a337ad
29 changed files with 3455 additions and 143 deletions

View file

@ -28,4 +28,4 @@ tmp_2 = bldr.add (tmp_1, z, "tmp_2")
bldr.ret (tmp_2)
print module
print(module)

View file

@ -47,4 +47,4 @@ x_sub_y = bldr.sub (x, y, "x_sub_y")
recur_2 = bldr.call (gcd, (x_sub_y, y,), "tmp")
bldr.ret (recur_2)
print module
print(module)

View file

@ -9,9 +9,9 @@ m.add_global_variable(Type.int(), 'i')
# write it's assembly representation to a file
asm = str(m)
print >> file("/tmp/testasm.ll", "w"), asm
print(asm, file=file("/tmp/testasm.ll", "w"))
# read it back into a module
m2 = Module.from_assembly(file("/tmp/testasm.ll"))
print m2
print(m2)

View file

@ -42,7 +42,7 @@ def test_jit_ctypes():
if 0:
# print the created module
print my_module
print(my_module)
# compile the function
ee = ExecutionEngine.new(my_module)

View file

@ -29,5 +29,5 @@ arg2 = GenericValue.int(ty_int, 42)
retval = ee.run_function(f_sum, [arg1, arg2])
# The return value is also GenericValue. Let's print it.
print "returned", retval.as_int()
print("returned", retval.as_int())

View file

@ -41,5 +41,5 @@ builder.ret(tmp)
# We've completed the definition now! Let's see the LLVM assembly
# language representation of what we've created:
print my_module
print(my_module)

View file

@ -16,7 +16,7 @@ b = Builder.new(block)
val = Constant.int(Type.int(), 42)
bswap = Function.intrinsic(mod, INTR_BSWAP, [Type.int()])
b.call(bswap, [val])
print mod
print(mod)
# the output is:
#
@ -50,7 +50,7 @@ cos2 = b.call(pow, [cosx, Constant.int(Type.int(), 2)], "cos2")
onemc2 = b.sub(one, cos2, "onemc2")
sin = b.call(sqrt, [onemc2], "sin")
b.ret(sin)
print mod
print(mod)
#
# ; ModuleID = 'test'

View file

@ -4,17 +4,17 @@ from llvm.core import *
def check(a, b):
if a is b:
print "OK"
print("OK")
else:
print "FAIL"
print("FAIL")
def check_isnot(a, b):
if not (a is b):
print "OK"
print("OK")
else:
print "FAIL"
print("FAIL")
print "Testing module aliasing ..",
print("Testing module aliasing ..", end=' ')
m1 = Module.new('a')
t = Type.int()
ft = Type.function(t, [t])
@ -22,75 +22,75 @@ f1 = m1.add_function(ft, "func")
m2 = f1.module
check(m1, m2)
print "Testing global vairable aliasing 1 .. ",
print("Testing global vairable aliasing 1 .. ", end=' ')
gv1 = GlobalVariable.new(m1, t, "gv")
gv2 = GlobalVariable.get(m1, "gv")
check(gv1, gv2)
print "Testing global vairable aliasing 2 .. ",
print("Testing global vairable aliasing 2 .. ", end=' ')
gv3 = m1.global_variables[0]
check(gv1, gv3)
print "Testing global vairable aliasing 3 .. ",
print("Testing global vairable aliasing 3 .. ", end=' ')
gv2 = None
gv3 = None
gv1.delete()
gv4 = GlobalVariable.new(m1, t, "gv")
check_isnot(gv1, gv4)
print "Testing function aliasing 1 ..",
print("Testing function aliasing 1 ..", end=' ')
b1 = f1.append_basic_block('entry')
f2 = b1.function
check(f1, f2)
print "Testing function aliasing 2 ..",
print("Testing function aliasing 2 ..", end=' ')
f3 = m1.get_function_named("func")
check(f1, f3)
print "Testing function aliasing 3 ..",
print("Testing function aliasing 3 ..", end=' ')
f4 = Function.get_or_insert(m1, ft, "func")
check(f1, f4)
print "Testing function aliasing 4 ..",
print("Testing function aliasing 4 ..", end=' ')
f5 = Function.get(m1, "func")
check(f1, f5)
print "Testing function aliasing 5 ..",
print("Testing function aliasing 5 ..", end=' ')
f6 = m1.get_or_insert_function(ft, "func")
check(f1, f6)
print "Testing function aliasing 6 ..",
print("Testing function aliasing 6 ..", end=' ')
f7 = m1.functions[0]
check(f1, f7)
print "Testing argument aliasing .. ",
print("Testing argument aliasing .. ", end=' ')
a1 = f1.args[0]
a2 = f1.args[0]
check(a1, a2)
print "Testing basic block aliasing 1 .. ",
print("Testing basic block aliasing 1 .. ", end=' ')
b2 = f1.basic_blocks[0]
check(b1, b2)
print "Testing basic block aliasing 2 .. ",
print("Testing basic block aliasing 2 .. ", end=' ')
b3 = f1.get_entry_basic_block()
check(b1, b3)
print "Testing basic block aliasing 3 .. ",
print("Testing basic block aliasing 3 .. ", end=' ')
b31 = f1.entry_basic_block
check(b1, b31)
print "Testing basic block aliasing 4 .. ",
print("Testing basic block aliasing 4 .. ", end=' ')
bldr = Builder.new(b1)
b4 = bldr.basic_block
check(b1, b4)
print "Testing basic block aliasing 5 .. ",
print("Testing basic block aliasing 5 .. ", end=' ')
i1 = bldr.ret_void()
b5 = i1.basic_block
check(b1, b5)
print "Testing instruction aliasing 1 .. ",
print("Testing instruction aliasing 1 .. ", end=' ')
i2 = b5.instructions[0]
check(i1, i2)
@ -100,9 +100,9 @@ phi.add_incoming(f1.args[0], b1)
v2 = phi.get_incoming_value(0)
b6 = phi.get_incoming_block(0)
print "Testing PHI / basic block aliasing 5 .. ",
print("Testing PHI / basic block aliasing 5 .. ", end=' ')
check(b1, b6)
print "Testing PHI / value aliasing .. ",
print("Testing PHI / value aliasing .. ", end=' ')
check(f1.args[0], v2)

View file

@ -28,9 +28,9 @@ class strstream(object):
def __init__(self): pass
def read(self): return test_module
m = Module.from_assembly(strstream())
print "-"*60
print m
print "-"*60
print("-"*60)
print(m)
print("-"*60)
test_func = m.get_function_named("test_func")
prod = m.get_function_named("prod")
@ -38,16 +38,16 @@ prod = m.get_function_named("prod")
#===----------------------------------------------------------------------===
# test operands
print
print()
i1 = test_func.basic_blocks[0].instructions[0]
i2 = test_func.basic_blocks[0].instructions[1]
print "Testing User.operand_count ..",
print("Testing User.operand_count ..", end=' ')
if i1.operand_count == 3 and i2.operand_count == 2:
print "OK"
print("OK")
else:
print "FAIL"
print("FAIL")
print "Testing User.operands ..",
print("Testing User.operands ..", end=' ')
c1 = i1.operands[0] is prod
c2 = i1.operands[1] is test_func.args[0]
c3 = i1.operands[2] is test_func.args[1]
@ -56,22 +56,22 @@ c5 = i2.operands[1] is test_func.args[2]
c6 = len(i1.operands) == 3
c7 = len(i2.operands) == 2
if c1 and c2 and c3 and c5 and c6 and c7:
print "OK"
print("OK")
else:
print "FAIL"
print
print("FAIL")
print()
#===----------------------------------------------------------------------===
# show test_function
print "Examining test_function `test_test_func':"
print("Examining test_function `test_test_func':")
idx = 1
for inst in test_func.basic_blocks[0].instructions:
print "Instruction #%d:" % (idx,)
print " operand_count =", inst.operand_count
print " operands:"
print("Instruction #%d:" % (idx,))
print(" operand_count =", inst.operand_count)
print(" operands:")
oidx = 1
for op in inst.operands:
print " %d: %s" % (oidx, repr(op))
print(" %d: %s" % (oidx, repr(op)))
oidx += 1
idx += 1

View file

@ -36,8 +36,8 @@ entry:
}
"""
m = Module.from_assembly(strstream(asm))
print "-"*72
print m
print("-"*72)
print(m)
# Let's run a module-level inlining pass. First, create a pass manager.
pm = PassManager.new()
@ -55,8 +55,8 @@ pm.run(m)
del pm
# Print the result. Note the change in @test2.
print "-"*72
print m
print("-"*72)
print(m)
# Let's run a DCE pass on the the function 'test1' now. First create a
@ -73,5 +73,5 @@ fpm.add( PASS_AGGRESSIVE_DCE )
fpm.run( m.get_function_named('test1') )
# Print the result. Note the change in @test1.
print "-"*72
print m
print("-"*72)
print(m)

View file

@ -69,7 +69,7 @@ def main():
# done
if gc.garbage:
print "garbage = ", gc.garbage
print("garbage = ", gc.garbage)
main()

View file

@ -15,12 +15,12 @@ ti = Type.int()
def do_llvmexception():
print " Testing class LLVMException"
print(" Testing class LLVMException")
e = LLVMException()
def do_ownable():
print " Testing class Ownable"
print(" Testing class Ownable")
o = Ownable(None, lambda x: None)
try:
o._own(None)
@ -30,7 +30,7 @@ def do_ownable():
def do_misc():
print " Testing miscellaneous functions"
print(" Testing miscellaneous functions")
try:
load_library_permanently("/usr/lib/libm.so")
except LLVMException:
@ -42,14 +42,14 @@ def do_misc():
def do_llvm():
print " Testing module llvm"
print(" Testing module llvm")
do_llvmexception()
do_ownable()
do_misc()
def do_module():
print " Testing class Module"
print(" Testing class Module")
m = Module.new('test')
m.target = 'a'
a = m.target
@ -101,7 +101,7 @@ def do_module():
def do_type():
print " Testing class Type"
print(" Testing class Type")
for i in range(1,100):
Type.int(i)
Type.float()
@ -151,14 +151,14 @@ def do_type():
def do_typehandle():
print " Testing class TypeHandle"
print(" Testing class TypeHandle")
th = TypeHandle.new(Type.opaque())
ts = Type.struct([ Type.int(), Type.pointer(th.type) ])
th.type.refine(ts)
def do_value():
print " Testing class Value"
print(" Testing class Value")
k = Constant.int(ti, 42)
k.name = 'a'
s = k.name
@ -186,7 +186,7 @@ def do_user():
def do_constant():
print " Testing class Constant"
print(" Testing class Constant")
Constant.null(ti)
Constant.all_ones(ti)
Constant.undef(ti)
@ -231,7 +231,7 @@ def do_constant():
def do_global_value():
print " Testing class GlobalValue"
print(" Testing class GlobalValue")
m = Module.new('a')
gv = GlobalVariable.new(m, Type.int(), 'b')
s = gv.is_declaration
@ -247,7 +247,7 @@ def do_global_value():
def do_global_variable():
print " Testing class GlobalVariable"
print(" Testing class GlobalVariable")
m = Module.new('a')
gv = GlobalVariable.new(m, Type.int(), 'b')
gv = GlobalVariable.get(m, 'b')
@ -260,7 +260,7 @@ def do_global_variable():
def do_argument():
print " Testing class Argument"
print(" Testing class Argument")
m = Module.new('a')
ft = Type.function(ti, [ti])
f = Function.new(m, ft, 'func')
@ -272,7 +272,7 @@ def do_argument():
def do_function():
print " Testing class Function"
print(" Testing class Function")
ft = Type.function(ti, [ti]*20)
zz = Function.new(Module.new('z'), ft, 'foobar')
del zz
@ -307,7 +307,7 @@ def do_function():
def do_instruction():
print " Testing class Instruction"
print(" Testing class Instruction")
m = Module.new('a')
ft = Type.function(ti, [ti]*20)
f = Function.new(m, ft, 'func')
@ -320,7 +320,7 @@ def do_instruction():
def do_callorinvokeinstruction():
print " Testing class CallOrInvokeInstruction"
print(" Testing class CallOrInvokeInstruction")
m = Module.new('a')
ft = Type.function(ti, [ti])
f = Function.new(m, ft, 'func')
@ -337,7 +337,7 @@ def do_callorinvokeinstruction():
def do_phinode():
print " Testing class PhiNode"
print(" Testing class PhiNode")
m = Module.new('a')
ft = Type.function(ti, [ti])
f = Function.new(m, ft, 'func')
@ -354,7 +354,7 @@ def do_phinode():
def do_switchinstruction():
print " Testing class SwitchInstruction"
print(" Testing class SwitchInstruction")
m = Module.new('a')
ft = Type.function(ti, [ti])
f = Function.new(m, ft, 'func')
@ -365,7 +365,7 @@ def do_switchinstruction():
def do_basicblock():
print " Testing class BasicBlock"
print(" Testing class BasicBlock")
m = Module.new('a')
ft = Type.function(ti, [ti])
f = Function.new(m, ft, 'func')
@ -395,7 +395,7 @@ def _do_builder_mrv():
def do_builder():
print " Testing class Builder"
print(" Testing class Builder")
m = Module.new('a')
ft = Type.function(ti, [ti])
f = Function.new(m, ft, 'func')
@ -488,7 +488,7 @@ def do_builder():
def do_llvm_core():
print " Testing module llvm.core"
print(" Testing module llvm.core")
do_module()
do_type()
do_typehandle()
@ -508,7 +508,7 @@ def do_llvm_core():
def do_targetdata():
print " Testing class TargetData"
print(" Testing class TargetData")
t = TargetData.new('')
v = str(t)
v = t.byte_order
@ -530,7 +530,7 @@ def do_targetdata():
def do_genericvalue():
print " Testing class GenericValue"
print(" Testing class GenericValue")
v = GenericValue.int(ti, 1)
v = GenericValue.int_signed(ti, 1)
v = GenericValue.real(Type.float(), 3.14)
@ -540,7 +540,7 @@ def do_genericvalue():
def do_executionengine():
print " Testing class ExecutionEngine"
print(" Testing class ExecutionEngine")
m = Module.new('a')
ee = ExecutionEngine.new(m, True)
ft = Type.function(ti, [])
@ -567,14 +567,14 @@ def do_executionengine():
def do_llvm_ee():
print " Testing module llvm.ee"
print(" Testing module llvm.ee")
do_targetdata()
do_genericvalue()
do_executionengine()
def do_passmanager():
print " Testing class PassManager"
print(" Testing class PassManager")
pm = PassManager.new()
pm.add(TargetData.new(''))
for i in [getattr(llvm.passes, x) for x in \
@ -586,7 +586,7 @@ def do_passmanager():
def do_functionpassmanager():
print " Testing class FunctionPassManager"
print(" Testing class FunctionPassManager")
m = Module.new('a')
ft = Type.function(ti, [])
f = m.add_function(ft, 'func')
@ -602,13 +602,13 @@ def do_functionpassmanager():
def do_llvm_passes():
print " Testing module llvm.passes"
print(" Testing module llvm.passes")
do_passmanager()
do_functionpassmanager()
def main():
print "Testing package llvm"
print("Testing package llvm")
do_llvm()
do_llvm_core()
do_llvm_ee()

View file

@ -1,7 +1,7 @@
#!/usr/bin/env python
from llvm.core import *
from cStringIO import StringIO
from io import StringIO
def make_module():

View file

@ -16,4 +16,4 @@ m = Module.new('mod1')
m.add_type_name("struct.node", th.type)
# show what we created
print m
print(m)

View file

@ -13,11 +13,11 @@ tmp2 = bld.add(tmp1, f.args[1], "tmp2")
tmp3 = bld.add(tmp1, f.args[2], "tmp3")
bld.ret(tmp3)
print "-"*60
print m
print "-"*60
print("-"*60)
print(m)
print("-"*60)
print "Testing use count ..",
print("Testing use count ..", end=' ')
c1 = f.args[0].use_count == 1
c2 = f.args[1].use_count == 1
c3 = f.args[2].use_count == 1
@ -25,11 +25,11 @@ c4 = tmp1.use_count == 2
c5 = tmp2.use_count == 0
c6 = tmp3.use_count == 1
if c1 and c2 and c3 and c4 and c5 and c6:
print "OK"
print("OK")
else:
print "FAIL"
print("FAIL")
print "Testing uses ..",
print("Testing uses ..", end=' ')
c1 = f.args[0].uses[0] is tmp1
c2 = len(f.args[0].uses) == 1
c3 = f.args[1].uses[0] is tmp2
@ -40,6 +40,6 @@ c7 = len(tmp1.uses) == 2
c8 = len(tmp2.uses) == 0
c9 = len(tmp3.uses) == 1
if c1 and c2 and c3 and c4 and c5 and c6 and c7 and c8 and c9:
print "OK"
print("OK")
else:
print "FAIL"
print("FAIL")