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


Python Function.new方法代码示例

本文整理汇总了Python中llvm.core.Function.new方法的典型用法代码示例。如果您正苦于以下问题:Python Function.new方法的具体用法?Python Function.new怎么用?Python Function.new使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在llvm.core.Function的用法示例。


在下文中一共展示了Function.new方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: declare_runtime_library

# 需要导入模块: from llvm.core import Function [as 别名]
# 或者: from llvm.core.Function import new [as 别名]
    def declare_runtime_library(self):
        self.runtime = {}

        self.runtime['_print_int'] = Function.new(self.module,
                                                  Type.function(Type.void(), [int_type], False),
                                                  "_print_int")
        self.runtime['_print_float'] = Function.new(self.module,
                                                    Type.function(Type.void(), [float_type], False),
                                                    "_print_float")
        self.runtime['_print_bool'] = Function.new(self.module,
                                                   Type.function(Type.void(), [bool_type], False),
                                                   "_print_bool")
开发者ID:emmett9001,项目名称:gone-compiler,代码行数:14,代码来源:gonellvm.py

示例2: add_prelude

# 需要导入模块: from llvm.core import Function [as 别名]
# 或者: from llvm.core.Function import new [as 别名]
 def add_prelude(self):
     for name, function in prelude.iteritems():
         self.intrinsics[name] = Function.new(
             self.module,
             function,
             name
         )
开发者ID:rfaulkner,项目名称:blaze-core,代码行数:9,代码来源:codegen.py

示例3: __init__

# 需要导入模块: from llvm.core import Function [as 别名]
# 或者: from llvm.core.Function import new [as 别名]
 def __init__(self, env, node, restype, argtypes):
     self.env = env
     self.node = node
     self.restype = ctypes[restype]
     self.argtypes = [ctypes[t] for t in argtypes]
     self.fntype = Type.function(self.restype, self.argtypes)
     self.fn = Function.new(env.options['module'], self.fntype, node.value)
开发者ID:cheery,项目名称:0137-compiler,代码行数:9,代码来源:cffi.py

示例4: CodeGen

# 需要导入模块: from llvm.core import Function [as 别名]
# 或者: from llvm.core.Function import new [as 别名]
 def CodeGen(self):
     # Make the function type, eg. double(double,double).
     funct_type = Type.function(Type.double(), [Type.double()] * len(self.args), False)
                                                 
     function = Function.new(g_llvm_module, funct_type, self.name)
                                                     
     # If the name conflicted, there was already something with the same name.
     # If it has a body, don't allow redefinition or reextern.
     if function.name != self.name:
         function.delete()
         function = g_llvm_module.get_function_named(self.name)
                                                                 
         # If the function already has a body, reject this.
         if not function.is_declaration:
             raise RuntimeError('Redefinition of function.')
                                                                         
         # If the function took a different number of args, reject.
         if len(function.args) != len(self.args):
             raise RuntimeError('Redeclaration of a function with different number of args.')
                                                                                 
     # Set names for all arguments and add them to the variables symbol table.
     for arg, arg_name in zip(function.args, self.args):
         arg.name = arg_name
                                                                                         
     return function
开发者ID:dongchen-coder,项目名称:dongchen-coder.github.io,代码行数:27,代码来源:kaleidoscope.py

示例5: emit_extern_func

# 需要导入模块: from llvm.core import Function [as 别名]
# 或者: from llvm.core.Function import new [as 别名]
 def emit_extern_func(self, extnode):
     assert extnode.name not in self.functions
     fntype = Type.function(self.type_map[extnode.rettype],
                            [self.type_map[t] for _, t in funcnode],
                            extnode.varargs)
     self.functions[extnode.name] = Function.new(self.module, fntype,
                                                 extnode.name)
     return self.funcnode[extnode.name]
开发者ID:bryant,项目名称:gravel,代码行数:10,代码来源:gravel.py

示例6: init_llvm

# 需要导入模块: from llvm.core import Function [as 别名]
# 或者: from llvm.core.Function import new [as 别名]
    def init_llvm(self):
        mod = Module.new("exprllvm")
        self.engine = ExecutionEngine.new(mod)

        # functions
        self.llvm_functions = {}
        func = Function.new(mod, Type.function(
            Type.void(), [], False), "main")
        self.llvm_functions['main'] = func
        block = func.append_basic_block("entry")

        # builder
        builder = Builder.new(block)
        self.builder = builder

        # add some pre-defined functions
        print_int = Function.new(mod, Type.function(
            Type.void(), [Type.int()], False), "print_int")
        self.llvm_functions['print_int'] = print_int

        self.builder.call(print_int, [Constant.int(Type.int(),3)])
        self.builder.ret_void()
开发者ID:DrOriam,项目名称:pycompile12,代码行数:24,代码来源:exprllvm.py

示例7: declare_function

# 需要导入模块: from llvm.core import Function [as 别名]
# 或者: from llvm.core.Function import new [as 别名]
 def declare_function(self, func_block):
     """Declare a Function and add it to self.vars"""
     _, name, ret_type, *args = func_block.instructions[0]
     args = [] if args == [[]] else args
     if not ret_type:
         ret_type = args[0]
         arg_types = []
     else:
         arg_types = [typemap[t] for t in args[1::2]]
     ret_type = typemap[ret_type]
     function = Function.new(
         self.module, Type.function(ret_type, arg_types, False), name
     )
     for i, argname in enumerate(args[0::2]):
         function.args[i].name = argname
     self.vars[name] = function
开发者ID:geraldstanje,项目名称:gone,代码行数:18,代码来源:gonellvm.py

示例8: codegen_proto

# 需要导入模块: from llvm.core import Function [as 别名]
# 或者: from llvm.core.Function import new [as 别名]
def codegen_proto(proto):
    name, args = proto[1], proto[2]
    double_types = [double_type] * len(args)
    func_type = Type.function(double_type, double_types)
    try:
        func = Function.get(the_module, name)
        if func.basic_block_count:
            raise CodegenError("redefinition of function")
        if len(func.args) != len(args):
            raise CodegenError("redefinition of function with different # args")
    except LLVMException:
        func = Function.new(the_module, func_type, name)
    for arg, name in zip(func.args, args):
        arg.name = name
        named_values[name] = arg
    return func
开发者ID:simudream,项目名称:kaleidoscope,代码行数:18,代码来源:kaleidoscope.py

示例9: start_function

# 需要导入模块: from llvm.core import Function [as 别名]
# 或者: from llvm.core.Function import new [as 别名]
    def start_function(self, name, retty, argtys):
        rettype = arg_typemap(retty)
        argtypes = [arg_typemap(arg) for arg in argtys]
        func_type = Type.function(rettype, argtypes, False)

        self.function = Function.new(self.module, func_type, name)

        self.block = self.function.append_basic_block("entry")
        self.builder = Builder.new(self.block)
        self.exit_block = self.function.append_basic_block("exit")

        self.locals = {}
        self.stack = {}

        if rettype is not void_type:
            self.locals['retval'] = self.builder.alloca(rettype, "retval")

        self.globals[name] = self.function
开发者ID:rfaulkner,项目名称:blaze-core,代码行数:20,代码来源:codegen.py

示例10: buildLoad

# 需要导入模块: from llvm.core import Function [as 别名]
# 或者: from llvm.core.Function import new [as 别名]
def buildLoad(module, memory):
    '''Build function load value from memory at address'''

    # Declare load
    loadType = Type.function(Type.int(), [Type.int()], False)
    load = Function.new(module, loadType, 'load')

    # Build body
    body = load.append_basic_block('body')
    builder = Builder.new(body)

    # Get pointer to memory at address
    addr = builder.sext(load.args[0], Type.int(bits=64))
    value = builder.load(builder.gep(memory, [num(0), addr]))

    # Return value
    builder.ret(value)
    load.verify()
开发者ID:cdparks,项目名称:hugo,代码行数:20,代码来源:genllvm.py

示例11: buildSave

# 需要导入模块: from llvm.core import Function [as 别名]
# 或者: from llvm.core.Function import new [as 别名]
def buildSave(module, memory):
    '''Build function to save value to memory at address'''

    # Declare save
    saveType = Type.function(Type.void(), [Type.int(), Type.int()], False)
    save = Function.new(module, saveType, 'save')

    # Build body
    body = save.append_basic_block('body')
    builder = Builder.new(body)

    # Get pointer to memory at address
    value, addr = save.args
    addr64 = builder.sext(addr, Type.int(bits=64))
    builder.store(value, builder.gep(memory, [num(0), addr64]))

    # Exit function
    builder.ret_void()
    save.verify()
开发者ID:cdparks,项目名称:hugo,代码行数:21,代码来源:genllvm.py

示例12: emit_func

# 需要导入模块: from llvm.core import Function [as 别名]
# 或者: from llvm.core.Function import new [as 别名]
    def emit_func(self, funcnode):
        assert funcnode.name not in self.functions
        fntype = Type.function(self.type_map[funcnode.rettype],
                               [self.type_map[t] for _, t in funcnode.args],
                               False)
        fn = Function.new(self.module, fntype, funcnode.name)
        s = Scope("", fn)

        for arg, (name, ty) in zip(fn.args, funcnode.args):
            arg.name = name
            var = s.locals[name] = s.builder.alloca(self.type_map[ty], name)
            s.builder.store(arg, var)

        self.scopes.append(s)
        self.functions[funcnode.name] = self.current_func = f
        self.emit_block(funcnode.body)
        self.scopes.pop()
        fn.verify()
        return f
开发者ID:bryant,项目名称:gravel,代码行数:21,代码来源:gravel.py

示例13: gen_code

# 需要导入模块: from llvm.core import Function [as 别名]
# 或者: from llvm.core.Function import new [as 别名]
    def gen_code(self, module, builder, variables):
        funct_type = Type.function(Type.double(), [Type.double()] * len(self.args), False)
        function = Function.new(module, funct_type, self.name)

        variables = {}
        for arg, arg_name in zip(function.args, self.args):
            arg.name = arg_name
            variables[arg_name] = arg

        block = function.append_basic_block('entry')

        builder = Builder.new(block)

        return_value = self.body.gen_code(module, builder, variables)
        builder.ret(return_value)

        function.verify()

        return function
开发者ID:rigtorp,项目名称:sfpl,代码行数:21,代码来源:sfpl.py

示例14: code_gen

# 需要导入模块: from llvm.core import Function [as 别名]
# 或者: from llvm.core.Function import new [as 别名]
    def code_gen(self):
        funct_type = Type.function(
            Type.double(), [Type.double()] * len(self.args), False)

        function = Function.new(g_llvm_module, funct_type, self.name)

        if function.name != self.name:
            function.delete()
            function = g_llvm_module.get_function_named(self.name)

            if not function.is_declaration:
                raise RuntimeError('Redefinition of a function.')

            if len(self.callee.args) != self.args):
                raise RuntimeError('Redeclaration of a function with different number of args.')

        for arg, arg_name in zip(function.args, self.args):
            arg.name = arg_name
            g_named_values[arg_name] = arg

        return function
开发者ID:jplesperance,项目名称:jpl-compiler-python,代码行数:23,代码来源:ast.py

示例15: buildMain

# 需要导入模块: from llvm.core import Function [as 别名]
# 或者: from llvm.core.Function import new [as 别名]
def buildMain(module, source):
    '''Build main function'''

    # Declare main function
    mainType = Type.function(Type.int(), [], False)
    main = Function.new(module, mainType, 'main')

    # Build entry block
    entry = main.append_basic_block('entry')
    builder = Builder.new(entry)
    next = builder.alloca(Type.int(), 'next')
    builder.store(num(0), next)

    # Build exit block
    exit = main.append_basic_block('exit')
    builder = Builder.new(exit)
    builder.ret(num(0))

    # Build block for switch-case
    loop = main.append_basic_block('loop')
    builder = Builder.new(loop)
    jump = builder.load(next, 'jump')
    switch = builder.switch(jump, exit)
    builder = Builder.new(entry)
    builder.branch(loop)

    # For each expression build a block that jumps back up to switch
    # and add label-block pair to switch block
    for label, expression in sorted(source.items()):
        stack = []
        case = main.append_basic_block('case-{}'.format(label))
        builder = Builder.new(case)
        for instruction in expression:
            instruction.gen(module, builder, stack)
        builder.store(stack.pop(), next)
        builder.branch(loop)
        switch.add_case(num(label), case)
    return main
开发者ID:cdparks,项目名称:hugo,代码行数:40,代码来源:genllvm.py


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