Information from the FlowObjSpace
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? With thanks, Brian
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 -- Christian Tismer :^) <mailto:tismer@stackless.com> tismerysoft GmbH : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9A : *Starship* http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 802 86 56 mobile +49 173 24 18 776 fax +49 30 80 90 57 05 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/
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
"Brian C. Lum" <bclum@cs.ucsd.edu> writes:
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.
for block in graph.iterblocks(): for op in block.operations: print op Cheers, mwh -- In the 1950s and 60s there was a regular brain drain of young Australians from the cities to London, but it was because of money, culture and opportunity, not spiders. -- Al Grant, ucam.chat, from Owen Dunn's review of the year
participants (3)
-
Brian C. Lum
-
Christian Tismer
-
Michael Hudson