[cfe-dev] Is there a tool that restores a previously saved AST?

Douglas Gregor dgregor at apple.com
Mon Jul 8 11:34:11 PDT 2013


On Jul 5, 2013, at 3:28 PM, Daniel Albuschat <d.albuschat at gmail.com> wrote:

> Hi there,
> 
> I recently started looking into the Clang project and have to admit that I would never have expected it to be that mature. And I really appreciate the design decisions that lead to Clang being that re-usable and flexible. I think you're doing each and every C++ programmer a great favor and Clang will spawn an immense number of awesome tools in the future that we previously might not have imagined being possible to implement.
> 
> Enough praising, here is my actual question:
> Is there any tool that reads an AST, saves it to some file or database, and later is able to *restore* that AST completely (e.g. to be able to create LLVM IR from it)? I'm trying to do something similar, so it'd be nice to know whether someone did that before.
> The precompiled header implementations should do something like this, shouldn't they? Is their AST representation complete, or are they missing things like control-flow?

Yes to everything. The precompiled header implementation serializes the entire AST. You can use clang -cc1’s ‘-emit-ast’ option to emit the serialized AST into a “.ast” file, which can then be used to generate LLVM IR. It hasn’t been extensively tested, and to my knowledge nobody is doing this in a production environment, but the test file test/Frontend/ast-codegen.c illustrates how to do it and that it isn’t *completely* broken.

	- Doug

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130708/0388a3fb/attachment.html>


More information about the cfe-dev mailing list