[cfe-dev] [LLVMdev] Clang and AST Generation

Sebastian Redl sebastian.redl at getdesigned.at
Thu Nov 5 09:09:32 PST 2009


Pushkar Ratnalikar wrote:
> Hi,
>
> I tried printing the ast for a simple Hello world "C" program using 
> *clang-cc -ast-print hello.c*.
>
> the output that I get is 
>
> typedef signed char __int8_t;
> typedef unsigned char __uint8_t;
> typedef short __int16_t;
> typedef unsigned short __uint16_t;
> typedef int __int32_t;
> typedef unsigned int __uint32_t;
> typedef long long __int64_t;
> typedef unsigned long long __uint64_t;
> typedef long __darwin_intptr_t;
> typedef unsigned int __darwin_natural_t;
> .
> .
> .
> .
> int main(int argc, char **argv) (CompoundStmt 0x1806170 <hello.c:3:1, 
> line:10:1>
>   (DeclStmt 0x180f350 <line:4:3, col:12>
>     0x180e6a0 "int x"
>     0x180f2f0 "int y"
>     0x180f320 "int z"
That looks like an AST dump, not a print.
> .
> .
> .
>
>
> If I want get/print the AST starting from *int main(int argc, char 
> **argv) (CompoundStmt 0x1806170 <hello.c:3:1, line:10:1>*
> *  (DeclStmt 0x180f350 <line:4:3, col:12>*, 
>
> How should I proceed ?
For what do you need it? The printers (both -ast-dump and -ast-print) 
are primarily debugging tools.
>
> Also, I came across constant folding in the Clangs Internals Manual 
> at http://clang.llvm.org/docs/InternalsManual.html#Constants
> Since I just started looking at Clang's code, I am not sure, if that 
> really happens or not. But I need that the AST that I get be as close 
> to the original source as possible.
The AST is not modified by constant evaluation.

Sebastian



More information about the cfe-dev mailing list