add MCJIT test

This commit is contained in:
Siu Kwan Lam 2013-07-31 16:57:29 -05:00
commit 319984f0e0
3 changed files with 36 additions and 2 deletions

View file

@ -2454,4 +2454,8 @@ if api.llvm.InitializeNativeTargetAsmPrinter():
# should this be an optional feature?
# should user trigger the initialization?
raise llvm.LLVMException("No native asm printer!?")
if api.llvm.InitializeNativeTargetAsmParser():
# required by MCJIT?
# should this be an optional feature?
# should user trigger the initialization?
raise llvm.LLVMException("No native asm parser!?")

View file

@ -152,7 +152,9 @@ class EngineBuilder(llvm.Wrapper):
engine = self._ptr.create(tm._ptr)
else:
engine = self._ptr.create()
return ExecutionEngine(engine)
ee = ExecutionEngine(engine)
ee.finalize_object() # no effect for legacy JIT
return ee
def select_target(self, *args):
'''get the corresponding target machine
@ -218,6 +220,9 @@ class ExecutionEngine(llvm.Wrapper):
def remove_module(self, module):
return self._ptr.removeModule(module._ptr)
def finalize_object(self):
return self._ptr.finalizeObject()
@property
def target_data(self):
ptr = self._ptr.getDataLayout()

View file

@ -1353,6 +1353,31 @@ class TestCmp(TestCase):
tests.append(TestCmp)
# ---------------------------------------------------------------------------
class TestMCJIT(TestCase):
def test_mcjit(self):
m = Module.new('oidfjs')
fnty = Type.function(Type.int(), [Type.int(), Type.int()])
func = m.add_function(fnty, 'foo')
bb = func.append_basic_block('')
bldr = Builder.new(bb)
bldr.ret(bldr.add(*func.args))
func.verify()
engine = EngineBuilder.new(m).mcjit(True).create()
ptr = engine.get_pointer_to_function(func)
from ctypes import c_int, CFUNCTYPE
callee = CFUNCTYPE(c_int, c_int, c_int)(ptr)
self.assertEqual(321 + 123, callee(321, 123))
if llvm.version >= (3, 3):
# MCJIT broken in 3.2
# The test will segfault in OSX?
tests.append(TestMCJIT)
# ---------------------------------------------------------------------------
def run(verbosity=1):