本文整理汇总了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")
示例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
)
示例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)
示例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
示例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]
示例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()
示例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
示例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
示例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
示例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()
示例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()
示例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
示例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
示例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
示例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