[cfe-dev] Driver support for AST features (UI Proposal)

Daniel Dunbar daniel at zuster.org
Mon Aug 31 22:51:00 PDT 2009


Hi all,

This is a UI design proposal for the clang driver for providing user /
tool access to clang AST based features.

 1. Support '-emit-ast'; this will be an option like '-S' in that it
stops compilation at the AST production phase, and will generate files
with a '.ast' suffix.

 2. Recognize '.ast' files as source inputs which can be compiled.
Obviously this will start at the compilation phase, in the same way
that '.i' etc inputs bypass the preprocessing phase.
    a. clang will call clang with an explicit argument telling it to
compile from .ast (-compile-ast) instead of -S.

    b. The compile-ast action will skip passing preprocessing specific
options to clang (but still pass options used by the code generator).

Eventually we will probably also want a feature '-write-ast' (or so)
which will output an AST while doing other things (like compiling),
but that is not part of this proposal.

One salient design point is that the default suffix for AST files is
'.ast', which does not indicate the source language. This means the
driver won't be able to make decisions about things like code
generator options based on its language. I'm not sure yet if this
matters. If it did we would either (a) have to poke the .ast to figure
out its language, or (b) use -x with new options like c++-ast etc
(like for preprocessed inputs) and optionally use suffixes like
'.c-ast', '.cpp-ast', etc.

Comments?

A patch following this design is attached. The compile-ast option is
not implemented in clang, and I don't know exactly what model we want
for compile options passed to an ast -> .s compile step (most of them
are backed in the .ast, but not all of them).

 - Daniel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Initial-emit-ast-support.patch
Type: application/octet-stream
Size: 11071 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20090831/2e44b7ca/attachment.obj>


More information about the cfe-dev mailing list