Added function to iterate through nested code objects, llpython.opcode_util.itercodeobjs(), and used it in llpython.addr_flow.
This commit is contained in:
parent
c890cbdd92
commit
b5a15a5019
2 changed files with 42 additions and 3 deletions
|
|
@ -1,9 +1,10 @@
|
|||
#! /usr/bin/env python
|
||||
# ______________________________________________________________________
|
||||
|
||||
from collections import namedtuple
|
||||
import dis
|
||||
import opcode
|
||||
from collections import namedtuple
|
||||
import types
|
||||
|
||||
# ______________________________________________________________________
|
||||
# Module data
|
||||
|
|
@ -195,6 +196,16 @@ def itercode(code, start = 0):
|
|||
|
||||
# ______________________________________________________________________
|
||||
|
||||
def itercodeobjs(codeobj):
|
||||
"Iterator that traverses code objects via the co_consts member."
|
||||
yield codeobj
|
||||
for const in codeobj.co_consts:
|
||||
if isinstance(const, types.CodeType):
|
||||
for childobj in itercodeobjs(const):
|
||||
yield childobj
|
||||
|
||||
# ______________________________________________________________________
|
||||
|
||||
def extendlabels(code, labels = None):
|
||||
"""Extend the set of jump target labels to account for the
|
||||
passthrough targets of conditional branches.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue