本文整理汇总了Python中pykit.ir.Builder.exc_setup方法的典型用法代码示例。如果您正苦于以下问题:Python Builder.exc_setup方法的具体用法?Python Builder.exc_setup怎么用?Python Builder.exc_setup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pykit.ir.Builder
的用法示例。
在下文中一共展示了Builder.exc_setup方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: preserve_exceptions
# 需要导入模块: from pykit.ir import Builder [as 别名]
# 或者: from pykit.ir.Builder import exc_setup [as 别名]
def preserve_exceptions(oldblock, newblock):
"""
Preserve exc_setup instructions for block splits.
"""
from pykit.ir import Builder
func = oldblock.parent
b = Builder(func)
b.position_at_beginning(newblock)
for op in oldblock.leaders:
if op.opcode == 'exc_setup':
b.exc_setup(op.args[0], **op.metadata)
示例2: test_exc_rewrite
# 需要导入模块: from pykit.ir import Builder [as 别名]
# 或者: from pykit.ir.Builder import exc_setup [as 别名]
def test_exc_rewrite(self):
func = Function("foo", [], types.Function(types.Void, ()))
entry = func.new_block("entry")
catch_block = func.new_block("catch")
b = Builder(func)
with b.at_front(entry):
b.exc_setup([catch_block])
b.exc_throw(Const(StopIteration, types.Exception))
with b.at_front(catch_block):
b.exc_catch([Const(Exception, types.Exception)])
local_exceptions.run(func, {})
print(func)
示例3: Translate
# 需要导入模块: from pykit.ir import Builder [as 别名]
# 或者: from pykit.ir.Builder import exc_setup [as 别名]
#.........这里部分代码省略.........
# Add unpacked iterable to args list
f, args = call.args
call.set_args([f, args + [it]])
# Annotate call as a 'varargs' application
self.call_annotations[call]['varargs'] = True
def op_GET_ITER(self, inst):
self.call(iter, [self.pop()])
def op_FOR_ITER(self, inst):
"""
Translate a for loop to:
it = getiter(iterable)
try:
while 1:
i = next(t)
...
except StopIteration:
pass
"""
iterobj = self.peek()
delta = inst.arg
loopexit = self.blocks[inst.next + delta]
loop_block = self.loop_stack[-1]
loop_block.catch_block = loopexit
# -------------------------------------------------
# Try
self.insert('exc_setup', [loopexit])
self.call(next, [iterobj])
# We assume a 1-to-1 block mapping, resolve a block split in a
# later pass
self.insert('exc_end')
# -------------------------------------------------
# Catch
with self.builder.at_front(loopexit):
self.insert('exc_catch', [Const(StopIteration, type=types.Exception)])
# -------------------------------------------------
# Exit
# Add the loop exit at a successor to the header
self.predecessors[loopexit].add(self.curblock)
# Remove ourselves as a predecessor from the actual exit block, set by
# SETUP_LOOP
self.predecessors[loop_block.end].remove(self.prevblock)
def op_BREAK_LOOP(self, inst):
loopblock = self.loop_stack[-1]
self.jump(target=loopblock.catch_block or loopblock.end)
def op_BUILD_TUPLE(self, inst):
count = inst.arg
items = [self.pop() for _ in range(count)]
ordered = list(reversed(items))
if all(isinstance(item, Const) for item in ordered):
# create constant tuple