Fix for python 3

This commit is contained in:
Siu Kwan Lam 2013-02-27 13:48:08 -06:00
commit 93cd20e933
8 changed files with 41 additions and 28 deletions

View file

@ -29,6 +29,14 @@
#
from io import BytesIO
try:
from StringIO import StringIO
except ImportError:
try:
from cStringIO import StringIO
except ImportError:
from io import StringIO
import contextlib, weakref
import llvm
@ -468,7 +476,7 @@ class Module(llvm.Wrapper):
@property
def global_variables(self):
return map(_make_value, self._ptr.list_globals())
return list(map(_make_value, self._ptr.list_globals()))
def add_function(self, ty, name):
"""Add a function of given type with given name."""
@ -501,7 +509,7 @@ class Module(llvm.Wrapper):
@property
def functions(self):
"""All functions in this module."""
return map(_make_value, self._ptr.list_functions())
return list(map(_make_value, self._ptr.list_functions()))
def verify(self):
"""Verify module.
@ -585,10 +593,11 @@ class Module(llvm.Wrapper):
ret = False
if fileobj is None:
ret = True
fileobj = BytesIO()
fileobj = StringIO()
from llvm.ee import TargetMachine
tm = TargetMachine.new()
fileobj.write(tm.emit_assembly(self))
asm = tm.emit_assembly(self)
fileobj.write(asm)
if ret:
return fileobj.getvalue()
@ -983,7 +992,7 @@ class Value(llvm.Wrapper):
@property
def uses(self):
return map(_make_value, self._ptr.list_use())
return list(map(_make_value, self._ptr.list_use()))
class User(Value):
_type_ = api.llvm.User
@ -1458,7 +1467,7 @@ class Function(GlobalValue):
@property
def args(self):
args = self._ptr.getArgumentList()
return map(_make_value, args)
return list(map(_make_value, args))
@property
def basic_block_count(self):
@ -1480,7 +1489,7 @@ class Function(GlobalValue):
@property
def basic_blocks(self):
return map(_make_value, self._ptr.getBasicBlockList())
return list(map(_make_value, self._ptr.getBasicBlockList()))
def viewCFG(self):
return self._ptr.viewCFG()
@ -1782,7 +1791,7 @@ class BasicBlock(Value):
@property
def instructions(self):
return map(_make_value, self._ptr.getInstList())
return list(map(_make_value, self._ptr.getInstList()))
#===----------------------------------------------------------------------===
# Value factory method

View file

@ -179,7 +179,7 @@ class ExecutionEngine(llvm.Wrapper):
self._ptr.DisableLazyCompilation(disabled)
def run_function(self, fn, args):
ptr = self._ptr.runFunction(fn._ptr, map(lambda x: x._ptr, args))
ptr = self._ptr.runFunction(fn._ptr, list(map(lambda x: x._ptr, args)))
return GenericValue(ptr)
def get_pointer_to_function(self, fn):

View file

@ -147,7 +147,6 @@ class PassManager(llvm.Wrapper):
if not a_pass:
assert pass_name not in PASSES, "Registered but not found?"
raise llvm.LLVMException('Invalid pass name "%s"' % pass_name)
print a_pass
self._ptr.add(a_pass)
def run(self, module):

View file

@ -11,7 +11,11 @@ import tempfile
import contextlib
BITS = tuple.__itemsize__ * 8
from io import BytesIO
try:
from StringIO import StringIO
except ImportError:
from io import StringIO
import llvm
@ -118,7 +122,8 @@ class TestAttr(TestCase):
ret void
}
"""
return Module.from_assembly(BytesIO(test_module))
buf = StringIO(test_module)
return Module.from_assembly(buf)
def test_align(self):
m = self.make_module()
@ -250,7 +255,7 @@ entry:
}
"""
def test_operands(self):
m = Module.from_assembly(BytesIO(self.test_module))
m = Module.from_assembly(StringIO(self.test_module))
test_func = m.get_function_named("test_func")
prod = m.get_function_named("prod")
@ -312,7 +317,7 @@ entry:
}
"""
def test_passes(self):
m = Module.from_assembly(BytesIO(self.asm))
m = Module.from_assembly(StringIO(self.asm))
fn_test1 = m.get_function_named('test1')
fn_test2 = m.get_function_named('test2')
@ -360,7 +365,7 @@ entry:
self.assertNotEqual(str(fn_test1).strip(), original_test1.strip())
def test_passes_with_pmb(self):
m = Module.from_assembly(BytesIO(self.asm))
m = Module.from_assembly(StringIO(self.asm))
fn_test1 = m.get_function_named('test1')
fn_test2 = m.get_function_named('test2')
@ -626,7 +631,7 @@ class TestTargetMachines(TestCase):
self.assertTrue(tm.target_data)
self.assertTrue(tm.target_short_description)
self.assertTrue(tm.triple)
self.assertIn('foo', tm.emit_assembly(m).decode('utf-8'))
self.assertIn('foo', tm.emit_assembly(m))
self.assertTrue(le.get_host_cpu_name())
def test_ptx(self):
@ -636,13 +641,13 @@ class TestTargetMachines(TestCase):
arch = 'nvptx64'
else:
return # skip this test
print arch
print(arch)
m, func = self._build_module()
func.calling_convention = lc.CC_PTX_KERNEL # set calling conv
ptxtm = le.TargetMachine.lookup(arch=arch, cpu='sm_20')
self.assertTrue(ptxtm.triple)
self.assertTrue(ptxtm.cpu)
ptxasm = ptxtm.emit_assembly(m).decode('utf-8')
ptxasm = ptxtm.emit_assembly(m)
self.assertIn('foo', ptxasm)
if lc.HAS_NVPTX:
self.assertIn('.address_size 64', ptxasm)
@ -936,31 +941,31 @@ class TestCPUSupport(TestCase):
def test_cpu_support2(self):
features = 'sse3', 'sse41', 'sse42', 'avx'
mattrs = ','.join(map(lambda s: '-%s' % s, features))
print 'disable mattrs', mattrs
print('disable mattrs', mattrs)
self._template(mattrs)
def test_cpu_support3(self):
features = 'sse41', 'sse42', 'avx'
mattrs = ','.join(map(lambda s: '-%s' % s, features))
print 'disable mattrs', mattrs
print('disable mattrs', mattrs)
self._template(mattrs)
def test_cpu_support4(self):
features = 'sse42', 'avx'
mattrs = ','.join(map(lambda s: '-%s' % s, features))
print 'disable mattrs', mattrs
print('disable mattrs', mattrs)
self._template(mattrs)
def test_cpu_support5(self):
features = 'avx',
mattrs = ','.join(map(lambda s: '-%s' % s, features))
print 'disable mattrs', mattrs
print('disable mattrs', mattrs)
self._template(mattrs)
def test_cpu_support6(self):
features = []
mattrs = ','.join(map(lambda s: '-%s' % s, features))
print 'disable mattrs', mattrs
print('disable mattrs', mattrs)
self._template(mattrs)
tests.append(TestCPUSupport)
@ -1235,4 +1240,4 @@ def run(verbosity=1):
if __name__ == '__main__':
run()
unittest.main()

View file

@ -20,7 +20,7 @@ class TestInlineAsm(TestCase):
inlineasm = InlineAsm.get(iaty, "bswap $0", "=r,r")
self.assertIn('asm "bswap $0", "=r,r"', str(inlineasm))
builder.ret(builder.call(inlineasm, [fn.args[0]]))
print fn
print(fn)
if __name__ == '__main__':
unittest.main()

View file

@ -10,7 +10,7 @@ def test():
alloc = b.malloc_array(Type.int(), Constant.int(Type.int(), 10), 'hee')
inst = b.free(alloc)
b.ret_void()
print m
print(m)
if __name__ == '__main__':
test()

View file

@ -29,7 +29,7 @@ class TestTBAABuilder(TestCase):
bldr.ret_void()
print mod
print(mod)
if __name__ == '__main__':
unittest.main()

View file

@ -122,7 +122,7 @@ def debug_in_gdb(lfunc):
# Now let's compile and run!
retval = ee.run_function(lfunc, [arg1])
print retval.as_real(float_type)
print(retval.as_real(float_type))
if __name__ == '__main__':