VM Architecture.

Neal Norwitz neal at metaslash.com
Sun Aug 11 15:11:10 EDT 2002

On Sun, 11 Aug 2002 12:59:53 -0400, Venkatesh Prasad Ranganath wrote:

> Well, I am looking for libraries to represent python code in some
> intermediate representation in memory to perform static analyses.
> Although it is trivial to write a parser for python, it is necessary to
> address the issue of how would one handle the part of the system with no
> source code, but with byte codes.  I know dis module disassembles.  I
> also looked into decompyle which can decompile python bytecodes.
> However, none of these modules have an intermediate representation which
> can be used as input to other sort activities like static analysis.

I encourage you to *not* use byte codes after writing
a static analysis tool that uses byte codes (http://pychecker.sf.net).
It can be done and a surprising about of info is available.
However, if you are interested in maintaining the software for
several versions of Python, it gets very difficult.
Not only that how a byte code works may vary from version to version.

You may want to decompyle into source, then use the compiler package
(standard in 2.1 and beyond).  The compiler package compiles to
Abstract Syntax Trees (ASTs).

Feel free to look into the pychecker code, but be prepared 
to get scared.  :-)  There are two versions, one which uses
the byte codes to do static analysis and one (pychecker2)
which uses the compiler package.


More information about the Python-list mailing list