[pypy-dev] Information from the FlowObjSpace
Brian C. Lum
bclum at cs.ucsd.edu
Thu Apr 13 08:14:50 CEST 2006
Hi,
Thank you for the reply. I have looked at model.py and I can make a
FunctionGraph. However, I am still not sure how to use it.
space = FlowObjSpace()
graph = space.build_flow(test.is_perfect_number)
fun = FunctionGraph(test.is_perfect_number, graph.startblock)
That is how I create an instance of FunctionGraph, and I can still make
the blocks into an iterator, but I still cannot see what is inside the
blocks, i.e. what would be the code in the function graph.
Basically, all I want is a flowgraph of the code so that I can try to
perform some static analysis on it (I want to bound the length of lists at
compile time). I cannot figure out how to access the instructions in
each basic block from the flowgraph.
Calling translate_as_module from pypy.translator.geninterplevel as
described in
http://codespeak.net/pypy/dist/pypy/doc/translation.html#example actually
produces the SSA. I was hoping that I would be able to get the
instructions of each block from the flowgraph like in the example.
Brian
On Wed, 12 Apr 2006, Christian Tismer wrote:
> Brian C. Lum wrote:
>> Dear Pypy developers:
>>
>> I have gone through the source code for the FlowObjSpace in
>> pypy.objspace.flow.objspace, but I am confused how to traverse through the
>> blocks or obtain the information for each blocks in the graph. From my
>> understanding:
>>
>> space = FlowObjSpace()
>> graph = space.build_flow(func)
>>
>> Once you have the graph, however, how do you know what instructions are in
>> each block? I can iterate through the graph with iterblocks, but how do I
>> get information from each block?
>>
>> I want to analyze the information in each block to do code analysis for
>> python. Can anyone help me with this?
>
> First of all, flowing doesn't work for full CPython. You need
> to use the RPython subset (see
> http://codespeak.net/pypy/dist/pypy/doc/coding-guide.html#restricted-python
> )
>
> Then, if you have a block, you can iterate over block.operations
> which is a list, and so on. See pypy/objspace/flow/model.py
>
> ciao - chris
>
More information about the Pypy-dev
mailing list