Python::Bytecode - Disassemble and investigate Python bytecode
use Python::Bytecode my $bytecode = Python::Bytecode->new($bytecode); my $bytecode = Python::Bytecode->new(FH); for ($bytecode->disassemble) { print $_->[0],"\n"; # Textual representation of disassembly }
Python::Bytecode accepts a string or filehandle contain Python bytecode and puts it into a format you can manipulate.
Python::Bytecode
disassemble
This is the basic method for getting at the actual code. It returns an array representing the individual operations in the bytecode stream. Each element is a reference to a three-element array containing a textual representation of the disassembly, the opcode number, (the opname() function can be used to turn this into an op name) and the argument to the op, if any.
opname()
constants
This returns an array reflecting the constants table of the bytecode. Some operations such as LOAD_CONST refer to constants by index in this array.
LOAD_CONST
labels
Similar to constants, some operations branch to labels by index in this table.
varnames
Again, when variables are referred to by name, the names are stored as an index into this table.
filename
The filename from which this compiled bytecode is derived.
There are other methods, but you can read the code to find them. It's not hard, and besides, it's probably easiest to work off the textual representation of the disassembly anyway.
Simon Cozens, simon@cpan.org
simon@cpan.org
This code is licensed under the same terms as Perl itself.
To install Python::Bytecode, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Python::Bytecode
CPAN shell
perl -MCPAN -e shell install Python::Bytecode
For more information on module installation, please visit the detailed CPAN module installation guide.