本文整理汇总了Python中pykit.ir.Builder类的典型用法代码示例。如果您正苦于以下问题:Python Builder类的具体用法?Python Builder怎么用?Python Builder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Builder类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: rewrite_setattr
def rewrite_setattr(func, env):
"""
Resolve missing attributes through __setattr__
"""
context = env['flypy.typing.context']
b = Builder(func)
for op in func.ops:
if op.opcode == 'setfield':
obj, attr, value = op.args
obj_type = context[obj]
attr_type = types.String[()]
if attr not in obj_type.fields and attr not in obj_type.layout:
assert SETATTR in obj_type.fields, attr
b.position_after(op)
# Construct attribute string
attr_string = OConst(attr)
# call(getfield(obj, '__setattr__'), ['attr', value])
method_type = make_method(obj_type, SETATTR)
method = b.getfield(ptypes.Opaque, obj, SETATTR)
call = b.call(ptypes.Opaque, method, [attr_string, value])
op.delete()
# Update context
del context[op]
context[method] = method_type
context[call] = types.Void[()]
context[attr_string] = attr_type
示例2: explicit_coercions
def explicit_coercions(func, env=None):
"""
Turn implicit coercions into explicit conversion operations.
"""
conversions = {}
b = Builder(func)
for op in func.ops:
if op.opcode != 'kernel':
continue
overload = op.metadata['overload']
signature = overload.resolved_sig
parameters = signature.parameters[:-1]
assert len(op.args) - 1 == len(parameters)
# -------------------------------------------------
# Identify conversion points
replacements = {} # { arg : replacement_conversion }
for arg, param_type in zip(op.args[1:], parameters):
if arg.type != param_type:
conversion = conversions.get((arg, param_type))
if not conversion:
conversion = Op('convert', param_type, [arg])
b.position_after(arg)
b.emit(conversion)
conversions[arg, param_type] = conversion
replacements[arg] = conversion
# -------------------------------------------------
op.replace_args(replacements)
示例3: split_critical_edges
def split_critical_edges(func, cfg, phis):
"""
Split critical edges to correctly handle cycles in phis. See 2) above.
"""
b = Builder(func)
for block in cfg.node:
successors = cfg.neighbors(block)
if len(successors) > 1:
# More than one successor, we need to split
# (Alternatively, we could move our copies into the successor block
# if we were the only predecessor, but this seems simpler)
# Split successors with phis
new_succs = {} # old_successor -> new_successor
for succ in successors:
if phis[succ]:
label = func.temp("split_critical")
new_succ = func.new_block(label, after=block)
new_succs[succ] = new_succ
b.position_at_end(new_succ)
b.jump(succ)
# Patch our basic-block terminator to point to new blocks
if new_succs:
terminator = block.terminator
assert terminator.opcode == 'cbranch', terminator
test, truebb, falsebb = terminator.args
terminator.set_args([test,
new_succs.get(truebb, truebb),
new_succs.get(falsebb, falsebb)])