[phc-general] how to dump an AST?

Paul Biggar paul.biggar at gmail.com
Fri Aug 1 17:10:04 IST 2008


Hi Tim,

On Fri, Aug 1, 2008 at 4:55 PM, Tim Fletcher <twoggle at gmail.com> wrote:
> What's the recommended way of using phc to dump an AST so I can easily
> load into another language?
>
> The command line options for SVN trunk differ from the website. I
> found "--xdump=", but I don't understand what all the passes are and
> which one I should use. Any suggestions?

Sadly, I haven't had the change to update the documentation in quite a
while. Sorry about that.

There are 3 logical places to use --xdump (which is the proper way to
do it). The first is the 'ast' pass, which is what we would
traditionally refer to as an AST. That is, it represents the source as
closely as possible, and has constructs for all PHP language
constructs. The 'hir' pass removes many constructs from the AST, and
represents a simpler version of the program which is still valid PHP,
and has the same sematics as the original. The 'mir' pass is no longer
PHP, in that control-flow has been replaced by Gotos (and a few
similar changes).

So it depends on what you're trying to do. If you want to do source
analysis at a high level, use the AST. If you'd like to keep the
program as close to the original state as possible (say for
refactoring), use the AST. If you'd like to do deeper analysis on PHP,
use the HIR or the MIR, depending on your preference.

What are you trying to do?

Paul


-- 
Paul Biggar
paul.biggar at gmail.com


More information about the phc-general mailing list