add MCJIT test
This commit is contained in:
parent
56a511854a
commit
319984f0e0
3 changed files with 36 additions and 2 deletions
|
|
@ -2454,4 +2454,8 @@ if api.llvm.InitializeNativeTargetAsmPrinter():
|
||||||
# should this be an optional feature?
|
# should this be an optional feature?
|
||||||
# should user trigger the initialization?
|
# should user trigger the initialization?
|
||||||
raise llvm.LLVMException("No native asm printer!?")
|
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!?")
|
||||||
|
|
|
||||||
|
|
@ -152,7 +152,9 @@ class EngineBuilder(llvm.Wrapper):
|
||||||
engine = self._ptr.create(tm._ptr)
|
engine = self._ptr.create(tm._ptr)
|
||||||
else:
|
else:
|
||||||
engine = self._ptr.create()
|
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):
|
def select_target(self, *args):
|
||||||
'''get the corresponding target machine
|
'''get the corresponding target machine
|
||||||
|
|
@ -218,6 +220,9 @@ class ExecutionEngine(llvm.Wrapper):
|
||||||
def remove_module(self, module):
|
def remove_module(self, module):
|
||||||
return self._ptr.removeModule(module._ptr)
|
return self._ptr.removeModule(module._ptr)
|
||||||
|
|
||||||
|
def finalize_object(self):
|
||||||
|
return self._ptr.finalizeObject()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def target_data(self):
|
def target_data(self):
|
||||||
ptr = self._ptr.getDataLayout()
|
ptr = self._ptr.getDataLayout()
|
||||||
|
|
|
||||||
|
|
@ -1353,6 +1353,31 @@ class TestCmp(TestCase):
|
||||||
tests.append(TestCmp)
|
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):
|
def run(verbosity=1):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue