本文整理汇总了Python中llvm.ee.EngineBuilder类的典型用法代码示例。如果您正苦于以下问题:Python EngineBuilder类的具体用法?Python EngineBuilder怎么用?Python EngineBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了EngineBuilder类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_multi_module_linking
def test_multi_module_linking(self):
# generate external library module
m = Module.new('external-library-module')
fnty = Type.function(Type.int(), [Type.int(), Type.int()])
libfname = 'myadd'
func = m.add_function(fnty, libfname)
bb = func.append_basic_block('')
bldr = Builder.new(bb)
bldr.ret(bldr.add(*func.args))
func.verify()
# JIT the lib module and bind dynamic symbol
libengine = EngineBuilder.new(m).mcjit(True).create()
myadd_ptr = libengine.get_pointer_to_function(func)
le.dylib_add_symbol(libfname, myadd_ptr)
# reference external library
m = Module.new('user')
fnty = Type.function(Type.int(), [Type.int(), Type.int()])
func = m.add_function(fnty, 'foo')
bb = func.append_basic_block('')
bldr = Builder.new(bb)
extadd = m.get_or_insert_function(fnty, name=libfname)
bldr.ret(bldr.call(extadd, func.args))
func.verify()
# JIT the user module
engine = EngineBuilder.new(m).mcjit(True).create()
ptr = engine.get_pointer_to_function(func)
self.assertEqual(myadd_ptr,
engine.get_pointer_to_named_function(libfname))
from ctypes import c_int, CFUNCTYPE
callee = CFUNCTYPE(c_int, c_int, c_int)(ptr)
self.assertEqual(321 + 123, callee(321, 123))
示例2: test_enginebuilder_with_tm
def test_enginebuilder_with_tm(self):
tm = le.TargetMachine.new()
module = self.make_test_module()
self.assertTrue(llvmpy.capsule.has_ownership(module._ptr._ptr))
ee = EngineBuilder.new(module).create(tm)
self.assertFalse(llvmpy.capsule.has_ownership(module._ptr._ptr))
self.run_foo(ee, module)
示例3: test_enginebuilder_basic
def test_enginebuilder_basic(self):
module = self.make_test_module()
ee = EngineBuilder.new(module).create()
with self.assertRaises(llvm.LLVMException):
# Ensure the module is owned.
llvm._util.check_is_unowned(module)
self.run_foo(ee, module)
示例4: test_enginebuilder_with_tm
def test_enginebuilder_with_tm(self):
tm = le.TargetMachine.new()
module = self.make_test_module()
ee = EngineBuilder.new(module).create(tm)
with self.assertRaises(llvm.LLVMException):
# Ensure the targetmachine is owned.
llvm._util.check_is_unowned(tm)
with self.assertRaises(llvm.LLVMException):
# Ensure the module is owned.
llvm._util.check_is_unowned(module)
self.run_foo(ee, module)
示例5: test_mcjit
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))
示例6: get_callable
def get_callable(self, entry_point_name, entry_point_typesig):
"""
Returns a python callable that dispatches to the requested C function.
"""
# get llvm represetation of function
ll_function = self.ll_module.get_function_named(entry_point_name)
# run jit compiler
from llvm.ee import EngineBuilder
self.exec_engine = \
EngineBuilder.new(self.ll_module).mcjit(True).opt(3).create()
c_func_ptr = self.exec_engine.get_pointer_to_function(ll_function)
# cast c_func_ptr to python callable using ctypes
return entry_point_typesig(c_func_ptr)
示例7: func_template
def func_template(self, ty, op):
m = Module.new('dofjaa')
fnty = Type.function(ty, [ty, ty])
fn = m.add_function(fnty, 'foo')
bldr = Builder.new(fn.append_basic_block(''))
bldr.ret(getattr(bldr, op)(*fn.args))
engine = EngineBuilder.new(m).mcjit(True).create()
ptr = engine.get_pointer_to_function(fn)
from ctypes import c_uint32, c_uint64, c_float, c_double, CFUNCTYPE
maptypes = {
Type.int(32): c_uint32,
Type.int(64): c_uint64,
Type.float(): c_float,
Type.double(): c_double,
}
cty = maptypes[ty]
prototype = CFUNCTYPE(*[cty] * 3)
callee = prototype(ptr)
callee(12, 23)
示例8:
import sys
import platform
import llvm
from llvm.core import Module
from llvm.ee import EngineBuilder
m = Module.new("fjoidajfa")
eb = EngineBuilder.new(m)
target = eb.select_target()
print("target.triple=%r" % target.triple)
if sys.platform == "darwin":
s = {"64bit": "x86_64", "32bit": "x86"}[platform.architecture()[0]]
assert target.triple.startswith(s + "-apple-darwin")
assert llvm.test(verbosity=2) == 0
print("llvm.__version__: %s" % llvm.__version__)
# assert llvm.__version__ == '0.12.0'
示例9: _build_engine
def _build_engine(self, mod, mattrs):
if mattrs:
return EngineBuilder.new(mod).mattrs(mattrs).create()
else:
return EngineBuilder.new(mod).create()
示例10: test_enginebuilder_opt
def test_enginebuilder_opt(self):
module = self.make_test_module()
ee = EngineBuilder.new(module).opt(3).create()
self.run_foo(ee, module)
示例11: test_enginebuilder_force_jit
def test_enginebuilder_force_jit(self):
module = self.make_test_module()
ee = EngineBuilder.new(module).force_jit().create()
self.run_foo(ee, module)
示例12: test_enginebuilder_basic
def test_enginebuilder_basic(self):
module = self.make_test_module()
self.assertTrue(llvmpy.capsule.has_ownership(module._ptr._ptr))
ee = EngineBuilder.new(module).create()
self.assertFalse(llvmpy.capsule.has_ownership(module._ptr._ptr))
self.run_foo(ee, module)
示例13: __init__
def __init__(self, opt=OPT_NORMAL):
self.__opt = opt
self.__fatmod = Module.new('mlvm.jit.%X' % id(self))
self.__engine = EngineBuilder.new(self.__fatmod).opt(opt).create()
self.__symlib = {} # stores (name, argtys) -> (wrapper, callable)