Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
9c8f7eaf
Commit
9c8f7eaf
authored
Oct 28, 2003
by
Armin Rigo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed dis.disassemble_string().
Added dis.findlinestarts(). SF bug 811294
parent
3be6d5d3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
28 deletions
+24
-28
Lib/dis.py
Lib/dis.py
+24
-28
No files found.
Lib/dis.py
View file @
9c8f7eaf
...
...
@@ -60,21 +60,8 @@ def distb(tb=None):
def
disassemble
(
co
,
lasti
=-
1
):
"""Disassemble a code object."""
code
=
co
.
co_code
byte_increments
=
[
ord
(
c
)
for
c
in
co
.
co_lnotab
[
0
::
2
]]
line_increments
=
[
ord
(
c
)
for
c
in
co
.
co_lnotab
[
1
::
2
]]
table_length
=
len
(
byte_increments
)
# == len(line_increments)
lineno
=
co
.
co_firstlineno
table_index
=
0
while
(
table_index
<
table_length
and
byte_increments
[
table_index
]
==
0
):
lineno
+=
line_increments
[
table_index
]
table_index
+=
1
addr
=
0
line_incr
=
0
labels
=
findlabels
(
code
)
linestarts
=
dict
(
findlinestarts
(
co
))
n
=
len
(
code
)
i
=
0
extended_arg
=
0
...
...
@@ -82,20 +69,10 @@ def disassemble(co, lasti=-1):
while
i
<
n
:
c
=
code
[
i
]
op
=
ord
(
c
)
if
i
>=
addr
:
lineno
+=
line_incr
while
table_index
<
table_length
:
addr
+=
byte_increments
[
table_index
]
line_incr
=
line_increments
[
table_index
]
table_index
+=
1
if
line_incr
:
break
else
:
addr
=
sys
.
maxint
if
i
in
linestarts
:
if
i
>
0
:
print
print
"%3d"
%
lineno
,
print
"%3d"
%
linestarts
[
i
]
,
else
:
print
' '
,
...
...
@@ -137,8 +114,6 @@ def disassemble_string(code, lasti=-1, varnames=None, names=None,
while
i
<
n
:
c
=
code
[
i
]
op
=
ord
(
c
)
if
op
==
opmap
[
'SET_LINENO'
]
and
i
>
0
:
print
# Extra blank line
if
i
==
lasti
:
print
'-->'
,
else
:
print
' '
,
if
i
in
labels
:
print
'>>'
,
...
...
@@ -199,6 +174,27 @@ def findlabels(code):
labels
.
append
(
label
)
return
labels
def
findlinestarts
(
code
):
"""Find the offsets in a byte code which are start of lines in the source.
Generate pairs (offset, lineno) as described in Python/compile.c.
"""
byte_increments
=
[
ord
(
c
)
for
c
in
code
.
co_lnotab
[
0
::
2
]]
line_increments
=
[
ord
(
c
)
for
c
in
code
.
co_lnotab
[
1
::
2
]]
lastlineno
=
None
lineno
=
code
.
co_firstlineno
addr
=
0
for
byte_incr
,
line_incr
in
zip
(
byte_increments
,
line_increments
):
if
byte_incr
:
if
lineno
!=
lastlineno
:
yield
(
addr
,
lineno
)
lastlineno
=
lineno
addr
+=
byte_incr
lineno
+=
line_incr
if
lineno
!=
lastlineno
:
yield
(
addr
,
lineno
)
def
_test
():
"""Simple test program to disassemble a file."""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment