当前位置: 首页>>代码示例>>Python>>正文


Python ee.EngineBuilder类代码示例

本文整理汇总了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))
开发者ID:B-Rich,项目名称:llvmpy,代码行数:35,代码来源:test_mcjit.py

示例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)
开发者ID:meteogrid,项目名称:llvmpy,代码行数:7,代码来源:test_llvmpy.py

示例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)
开发者ID:bfroehle,项目名称:llvmpy,代码行数:9,代码来源:test_llvmpy.py

示例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)
开发者ID:bfroehle,项目名称:llvmpy,代码行数:15,代码来源:test_llvmpy.py

示例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))
开发者ID:B-Rich,项目名称:llvmpy,代码行数:16,代码来源:test_mcjit.py

示例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)
开发者ID:pyprogrammer,项目名称:ctree,代码行数:18,代码来源:jit.py

示例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)
开发者ID:alendit,项目名称:llvmpy,代码行数:22,代码来源:test_arith.py

示例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'
开发者ID:pombredanne,项目名称:llvmpy,代码行数:20,代码来源:run_test.py

示例9: _build_engine

 def _build_engine(self, mod, mattrs):
     if mattrs:
         return EngineBuilder.new(mod).mattrs(mattrs).create()
     else:
         return EngineBuilder.new(mod).create()
开发者ID:meteogrid,项目名称:llvmpy,代码行数:5,代码来源:test_llvmpy.py

示例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)
开发者ID:meteogrid,项目名称:llvmpy,代码行数:5,代码来源:test_llvmpy.py

示例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)
开发者ID:meteogrid,项目名称:llvmpy,代码行数:5,代码来源:test_llvmpy.py

示例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)
开发者ID:meteogrid,项目名称:llvmpy,代码行数:6,代码来源:test_llvmpy.py

示例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)
开发者ID:sklam,项目名称:mlvm,代码行数:5,代码来源:jit.py


注:本文中的llvm.ee.EngineBuilder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。