Good APIs for area analyzers

I am working on some code generation tools and a lot of the complexity comes from area analysis. I often find myself wanting to know things like

  • What are the free variables of a function or block?
  • Where is this symbol declared?
  • What does this declaration mean?
  • Is this use of the symbol before initialization?
  • Can this variable escape?

and I think it's time to rethink my clown.

I can do all this analysis, but I'm trying to figure out a way to structure the APIs so that it's easy to use and ideally lazy enough.

What tools like this are the people they are familiar with and what have they done right and wrong in their APIs?

0


source to share


1 answer


I'm a bit surprised at the question, since I've done a ton of code generation and the question of review frequency rarely comes up (except for the desire to generate unique names ).

To answer your question, the questions require serious analysis of the programs, not counting the area . Escape analysis itself is non-trivial. Usage-before-initialization can be trivial or non-trivial depending on the target language.

In my experience, APIs for program analysis are complex to develop and are often language dependent . If you are targeting a low-level language, you might learn something useful from the Machine SUIF API .

If I were you, I would be tempted to steal someone's structure for analyzing programs . George Necula and his students built CIL , which appears to be the current standard for analyzing C code. The Laurie Hendren group has developed several useful tools for Java analysis.



If I had to rollback my own , I would worry less about the API and more about a really good representation for abstract syntax trees.

In the very limited area of ​​data flow analysis (which includes the question of an uninitialized variable) Jo & atilde; o Dias and I adapted some good work by Sorin Lerner, David Grove and Craig Chambers . Only our preliminary results are published .

Finally, if you want to generate code in multiple languages , this is a complete worm . I've done it badly several times. If you create something that you like, post it!

+2


source







All Articles