Fix for python 3
This commit is contained in:
parent
740d2595ee
commit
93cd20e933
8 changed files with 41 additions and 28 deletions
25
llvm/core.py
25
llvm/core.py
|
|
@ -29,6 +29,14 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
from io import BytesIO
|
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 contextlib, weakref
|
||||||
|
|
||||||
import llvm
|
import llvm
|
||||||
|
|
@ -468,7 +476,7 @@ class Module(llvm.Wrapper):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def global_variables(self):
|
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):
|
def add_function(self, ty, name):
|
||||||
"""Add a function of given type with given name."""
|
"""Add a function of given type with given name."""
|
||||||
|
|
@ -501,7 +509,7 @@ class Module(llvm.Wrapper):
|
||||||
@property
|
@property
|
||||||
def functions(self):
|
def functions(self):
|
||||||
"""All functions in this module."""
|
"""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):
|
def verify(self):
|
||||||
"""Verify module.
|
"""Verify module.
|
||||||
|
|
@ -585,10 +593,11 @@ class Module(llvm.Wrapper):
|
||||||
ret = False
|
ret = False
|
||||||
if fileobj is None:
|
if fileobj is None:
|
||||||
ret = True
|
ret = True
|
||||||
fileobj = BytesIO()
|
fileobj = StringIO()
|
||||||
from llvm.ee import TargetMachine
|
from llvm.ee import TargetMachine
|
||||||
tm = TargetMachine.new()
|
tm = TargetMachine.new()
|
||||||
fileobj.write(tm.emit_assembly(self))
|
asm = tm.emit_assembly(self)
|
||||||
|
fileobj.write(asm)
|
||||||
if ret:
|
if ret:
|
||||||
return fileobj.getvalue()
|
return fileobj.getvalue()
|
||||||
|
|
||||||
|
|
@ -983,7 +992,7 @@ class Value(llvm.Wrapper):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def uses(self):
|
def uses(self):
|
||||||
return map(_make_value, self._ptr.list_use())
|
return list(map(_make_value, self._ptr.list_use()))
|
||||||
|
|
||||||
class User(Value):
|
class User(Value):
|
||||||
_type_ = api.llvm.User
|
_type_ = api.llvm.User
|
||||||
|
|
@ -1458,7 +1467,7 @@ class Function(GlobalValue):
|
||||||
@property
|
@property
|
||||||
def args(self):
|
def args(self):
|
||||||
args = self._ptr.getArgumentList()
|
args = self._ptr.getArgumentList()
|
||||||
return map(_make_value, args)
|
return list(map(_make_value, args))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def basic_block_count(self):
|
def basic_block_count(self):
|
||||||
|
|
@ -1480,7 +1489,7 @@ class Function(GlobalValue):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def basic_blocks(self):
|
def basic_blocks(self):
|
||||||
return map(_make_value, self._ptr.getBasicBlockList())
|
return list(map(_make_value, self._ptr.getBasicBlockList()))
|
||||||
|
|
||||||
def viewCFG(self):
|
def viewCFG(self):
|
||||||
return self._ptr.viewCFG()
|
return self._ptr.viewCFG()
|
||||||
|
|
@ -1782,7 +1791,7 @@ class BasicBlock(Value):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def instructions(self):
|
def instructions(self):
|
||||||
return map(_make_value, self._ptr.getInstList())
|
return list(map(_make_value, self._ptr.getInstList()))
|
||||||
|
|
||||||
#===----------------------------------------------------------------------===
|
#===----------------------------------------------------------------------===
|
||||||
# Value factory method
|
# Value factory method
|
||||||
|
|
|
||||||
|
|
@ -179,7 +179,7 @@ class ExecutionEngine(llvm.Wrapper):
|
||||||
self._ptr.DisableLazyCompilation(disabled)
|
self._ptr.DisableLazyCompilation(disabled)
|
||||||
|
|
||||||
def run_function(self, fn, args):
|
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)
|
return GenericValue(ptr)
|
||||||
|
|
||||||
def get_pointer_to_function(self, fn):
|
def get_pointer_to_function(self, fn):
|
||||||
|
|
|
||||||
|
|
@ -147,7 +147,6 @@ class PassManager(llvm.Wrapper):
|
||||||
if not a_pass:
|
if not a_pass:
|
||||||
assert pass_name not in PASSES, "Registered but not found?"
|
assert pass_name not in PASSES, "Registered but not found?"
|
||||||
raise llvm.LLVMException('Invalid pass name "%s"' % pass_name)
|
raise llvm.LLVMException('Invalid pass name "%s"' % pass_name)
|
||||||
print a_pass
|
|
||||||
self._ptr.add(a_pass)
|
self._ptr.add(a_pass)
|
||||||
|
|
||||||
def run(self, module):
|
def run(self, module):
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,11 @@ import tempfile
|
||||||
import contextlib
|
import contextlib
|
||||||
|
|
||||||
BITS = tuple.__itemsize__ * 8
|
BITS = tuple.__itemsize__ * 8
|
||||||
from io import BytesIO
|
|
||||||
|
try:
|
||||||
|
from StringIO import StringIO
|
||||||
|
except ImportError:
|
||||||
|
from io import StringIO
|
||||||
|
|
||||||
|
|
||||||
import llvm
|
import llvm
|
||||||
|
|
@ -118,7 +122,8 @@ class TestAttr(TestCase):
|
||||||
ret void
|
ret void
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
return Module.from_assembly(BytesIO(test_module))
|
buf = StringIO(test_module)
|
||||||
|
return Module.from_assembly(buf)
|
||||||
|
|
||||||
def test_align(self):
|
def test_align(self):
|
||||||
m = self.make_module()
|
m = self.make_module()
|
||||||
|
|
@ -250,7 +255,7 @@ entry:
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
def test_operands(self):
|
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")
|
test_func = m.get_function_named("test_func")
|
||||||
prod = m.get_function_named("prod")
|
prod = m.get_function_named("prod")
|
||||||
|
|
@ -312,7 +317,7 @@ entry:
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
def test_passes(self):
|
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_test1 = m.get_function_named('test1')
|
||||||
fn_test2 = m.get_function_named('test2')
|
fn_test2 = m.get_function_named('test2')
|
||||||
|
|
@ -360,7 +365,7 @@ entry:
|
||||||
self.assertNotEqual(str(fn_test1).strip(), original_test1.strip())
|
self.assertNotEqual(str(fn_test1).strip(), original_test1.strip())
|
||||||
|
|
||||||
def test_passes_with_pmb(self):
|
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_test1 = m.get_function_named('test1')
|
||||||
fn_test2 = m.get_function_named('test2')
|
fn_test2 = m.get_function_named('test2')
|
||||||
|
|
@ -626,7 +631,7 @@ class TestTargetMachines(TestCase):
|
||||||
self.assertTrue(tm.target_data)
|
self.assertTrue(tm.target_data)
|
||||||
self.assertTrue(tm.target_short_description)
|
self.assertTrue(tm.target_short_description)
|
||||||
self.assertTrue(tm.triple)
|
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())
|
self.assertTrue(le.get_host_cpu_name())
|
||||||
|
|
||||||
def test_ptx(self):
|
def test_ptx(self):
|
||||||
|
|
@ -636,13 +641,13 @@ class TestTargetMachines(TestCase):
|
||||||
arch = 'nvptx64'
|
arch = 'nvptx64'
|
||||||
else:
|
else:
|
||||||
return # skip this test
|
return # skip this test
|
||||||
print arch
|
print(arch)
|
||||||
m, func = self._build_module()
|
m, func = self._build_module()
|
||||||
func.calling_convention = lc.CC_PTX_KERNEL # set calling conv
|
func.calling_convention = lc.CC_PTX_KERNEL # set calling conv
|
||||||
ptxtm = le.TargetMachine.lookup(arch=arch, cpu='sm_20')
|
ptxtm = le.TargetMachine.lookup(arch=arch, cpu='sm_20')
|
||||||
self.assertTrue(ptxtm.triple)
|
self.assertTrue(ptxtm.triple)
|
||||||
self.assertTrue(ptxtm.cpu)
|
self.assertTrue(ptxtm.cpu)
|
||||||
ptxasm = ptxtm.emit_assembly(m).decode('utf-8')
|
ptxasm = ptxtm.emit_assembly(m)
|
||||||
self.assertIn('foo', ptxasm)
|
self.assertIn('foo', ptxasm)
|
||||||
if lc.HAS_NVPTX:
|
if lc.HAS_NVPTX:
|
||||||
self.assertIn('.address_size 64', ptxasm)
|
self.assertIn('.address_size 64', ptxasm)
|
||||||
|
|
@ -936,31 +941,31 @@ class TestCPUSupport(TestCase):
|
||||||
def test_cpu_support2(self):
|
def test_cpu_support2(self):
|
||||||
features = 'sse3', 'sse41', 'sse42', 'avx'
|
features = 'sse3', 'sse41', 'sse42', 'avx'
|
||||||
mattrs = ','.join(map(lambda s: '-%s' % s, features))
|
mattrs = ','.join(map(lambda s: '-%s' % s, features))
|
||||||
print 'disable mattrs', mattrs
|
print('disable mattrs', mattrs)
|
||||||
self._template(mattrs)
|
self._template(mattrs)
|
||||||
|
|
||||||
def test_cpu_support3(self):
|
def test_cpu_support3(self):
|
||||||
features = 'sse41', 'sse42', 'avx'
|
features = 'sse41', 'sse42', 'avx'
|
||||||
mattrs = ','.join(map(lambda s: '-%s' % s, features))
|
mattrs = ','.join(map(lambda s: '-%s' % s, features))
|
||||||
print 'disable mattrs', mattrs
|
print('disable mattrs', mattrs)
|
||||||
self._template(mattrs)
|
self._template(mattrs)
|
||||||
|
|
||||||
def test_cpu_support4(self):
|
def test_cpu_support4(self):
|
||||||
features = 'sse42', 'avx'
|
features = 'sse42', 'avx'
|
||||||
mattrs = ','.join(map(lambda s: '-%s' % s, features))
|
mattrs = ','.join(map(lambda s: '-%s' % s, features))
|
||||||
print 'disable mattrs', mattrs
|
print('disable mattrs', mattrs)
|
||||||
self._template(mattrs)
|
self._template(mattrs)
|
||||||
|
|
||||||
def test_cpu_support5(self):
|
def test_cpu_support5(self):
|
||||||
features = 'avx',
|
features = 'avx',
|
||||||
mattrs = ','.join(map(lambda s: '-%s' % s, features))
|
mattrs = ','.join(map(lambda s: '-%s' % s, features))
|
||||||
print 'disable mattrs', mattrs
|
print('disable mattrs', mattrs)
|
||||||
self._template(mattrs)
|
self._template(mattrs)
|
||||||
|
|
||||||
def test_cpu_support6(self):
|
def test_cpu_support6(self):
|
||||||
features = []
|
features = []
|
||||||
mattrs = ','.join(map(lambda s: '-%s' % s, features))
|
mattrs = ','.join(map(lambda s: '-%s' % s, features))
|
||||||
print 'disable mattrs', mattrs
|
print('disable mattrs', mattrs)
|
||||||
self._template(mattrs)
|
self._template(mattrs)
|
||||||
|
|
||||||
tests.append(TestCPUSupport)
|
tests.append(TestCPUSupport)
|
||||||
|
|
@ -1235,4 +1240,4 @@ def run(verbosity=1):
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
run()
|
unittest.main()
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ class TestInlineAsm(TestCase):
|
||||||
inlineasm = InlineAsm.get(iaty, "bswap $0", "=r,r")
|
inlineasm = InlineAsm.get(iaty, "bswap $0", "=r,r")
|
||||||
self.assertIn('asm "bswap $0", "=r,r"', str(inlineasm))
|
self.assertIn('asm "bswap $0", "=r,r"', str(inlineasm))
|
||||||
builder.ret(builder.call(inlineasm, [fn.args[0]]))
|
builder.ret(builder.call(inlineasm, [fn.args[0]]))
|
||||||
print fn
|
print(fn)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ def test():
|
||||||
alloc = b.malloc_array(Type.int(), Constant.int(Type.int(), 10), 'hee')
|
alloc = b.malloc_array(Type.int(), Constant.int(Type.int(), 10), 'hee')
|
||||||
inst = b.free(alloc)
|
inst = b.free(alloc)
|
||||||
b.ret_void()
|
b.ret_void()
|
||||||
print m
|
print(m)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
test()
|
test()
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ class TestTBAABuilder(TestCase):
|
||||||
|
|
||||||
|
|
||||||
bldr.ret_void()
|
bldr.ret_void()
|
||||||
print mod
|
print(mod)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
||||||
|
|
@ -122,7 +122,7 @@ def debug_in_gdb(lfunc):
|
||||||
|
|
||||||
# Now let's compile and run!
|
# Now let's compile and run!
|
||||||
retval = ee.run_function(lfunc, [arg1])
|
retval = ee.run_function(lfunc, [arg1])
|
||||||
print retval.as_real(float_type)
|
print(retval.as_real(float_type))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue