本文整理匯總了Python中pykit.ir.Builder.replace_predecessor方法的典型用法代碼示例。如果您正苦於以下問題:Python Builder.replace_predecessor方法的具體用法?Python Builder.replace_predecessor怎麽用?Python Builder.replace_predecessor使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pykit.ir.Builder
的用法示例。
在下文中一共展示了Builder.replace_predecessor方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: consume_yields
# 需要導入模塊: from pykit.ir import Builder [as 別名]
# 或者: from pykit.ir.Builder import replace_predecessor [as 別名]
def consume_yields(func, consumer, generator_func, valuemap):
b = Builder(func)
copier = lambda x : x
loop = consumer.loop
inlined_values = set(valuemap.values())
for block in func.blocks:
if block in inlined_values:
for op in block.ops:
if op.opcode == 'yield':
# -- Replace 'yield' by the loop body -- #
b.position_after(op)
_, resume = b.splitblock()
# Copy blocks
blocks = [copier(block) for block in loop.blocks]
# Insert blocks
prev = op.block
for block in blocks:
func.add_block(block, after=prev)
prev = block
# Fix wiring
b.jump(blocks[0])
b.position_at_end(blocks[-1])
b.jump(resume)
# We just introduced a bunch of copied blocks
func.reset_uses()
# Update phis with new predecessor
b.replace_predecessor(loop.tail, op.block, loop.head)
b.replace_predecessor(loop.tail, op.block, loop.head)
# Replace next() by value produced by yield
value = op.args[0]
consumer.next.replace_uses(value)
op.delete()
# We don't need these anymore
consumer.next.delete()