[cfe-dev] extending ClangTool libASTUnit saving and loading

mobi phil mobi at mobiphil.com
Tue Dec 16 08:12:25 PST 2014


>
> Multiple questions:
> 1. You should already be able to use ASTUnit to save and load ASTs - why
> do you need integration with ClangTool?
> 2. What are you trying to do? Why do you want to store the AST?
>

I need some little detail to be clarified. Did not check, but I assume that
"clang -emit-ast" is using ASTUnit::Save. Now the main questions:
-> is this AST fit to reload it and generate code or do any other actions
that one would do with source code? Well, tried to do for instance
-> is it possible to load the AST by clang itself to generate code?

I tried this:
clang  -c Sema.cpp  <bunch of includes, defines>
#above one compiles and generates Sema.o from clang Sema.cpp without errors
clang  -emit-ast Sema.cpp  <bunch of includes, defines>
#this generates Sema.ast without any errors/warnings
clang -c  Sema.ast

the latest one whatsoever parameters I try to feed there are compilation
errors. For instance

.../include/llvm/Support/SourceMgr.h:48:10: error: call to deleted
constructor of 'std::unique_ptr<MemoryBuffer>'
  struct SrcBuffer {

tried to do lunch an older version of clang with the same ast and get an
error:

error: PCH file uses an older PCH format that is no longer supported
error: unable to load PCH file

This makes me thinking that whatsoever similarities or differences there
are, clang tries to load my ast as PCH and not as AST.

This is the context that generated my original question. Now I see that
does not make sense to extend the ClangTool.

All this makes me thinking that would be nice to have a way to tell to
clang infra to l load an AST instead of file to generate code, do static
analyzis or any other operation.

Or... there is a way to do it?

thanks a lot for

regards
Mobiphil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20141216/a95388f2/attachment.html>


More information about the cfe-dev mailing list