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

Douglas Gregor dgregor at apple.com
Tue Sep 1 08:36:21 PDT 2009


On Aug 31, 2009, at 10:51 PM, Daniel Dunbar wrote:

> 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.

Makes sense.

> 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).

Seems reasonable.

> 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.

If nothing else, we need to know when the AST file is a C++ file, so  
that we can link in the C++ standard library.

> 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.

We should poke the AST file for this information.

> Comments?

Looks great! No red flags in the patch; I say, "go for it".

> 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).


If we do nothing, we'll end up checking the AST-backed options  
(complaining when there are differences) and just passing the other  
compilation options through to CodeGen for generation of the .s file.  
That seems fine to me.

   - Doug



More information about the cfe-dev mailing list