[cfe-dev] A small example on how to initiate header search and configure CFG from an already formed AST.

Parijat Banerjee parijat.pcr at gmail.com
Tue Sep 14 02:14:58 PDT 2010


Thanks a lot ! :) .By the way can someone guide me on how do I need to go
about initializing header search paths because my parser collapses when it
comes across included header files in the test code.

This is how I have initialized the preprocessor :



>
>
> llvm::raw_ostream *os = NULL;
>
> llvm::raw_ostream *ps = NULL;
>
> const DiagnosticOptions diagop;
>
> bool OwnsOutputStream=false;
>
> TextDiagnosticPrinter diagClient(*os,diagop,OwnsOutputStream);
>
> Diagnostic diags(&diagClient);
>
> LangOptions opts;
>
> TargetOptions to;
>
> const std::string& triple = LLVM_HOSTTRIPLE;
>
> to.ABI="";
>
> to.CXXABI="itanium";
>
> to.CPU="";
>
> to.Features.clear();
>
> to.Triple=triple;
>
> TargetInfo* target = TargetInfo::CreateTargetInfo(diags,to);
>
> SourceManager sm(diags);
>
> FileManager fm;
>
> HeaderSearch headers(fm);
>
> Preprocessor pp(diags,opts,*target,sm,headers);
>

Any suggestions / modifications needed to make sure the included file search
paths are taken care while parsing a test file  ?


Thanks and Regards ,
Parijat


On Mon, Sep 13, 2010 at 11:28 PM, Ted Kremenek <kremenek at apple.com> wrote:

> It's optional, and you can leave it NULL.  It's there to support
> cross-translation unit analysis (in the future).
>
>  On Sep 13, 2010, at 11:00 PM, Parijat Banerjee wrote:
>
>
> What is the TranslationUnit required as a parameter for AnalysisContext
> creation ?
>
> Thanks and Regards
> Parijat
> On Mon, Sep 13, 2010 at 8:24 AM, Ted Kremenek <kremenek at apple.com> wrote:
>
>> On Sep 13, 2010, at 5:25 AM, Parijat Banerjee wrote:
>>
>> > Also can someone give a small snippet of code to demonstrate forming a
>> CFG class( branch 2.7 + )  given an already formed ASTContext class and
>> maybe a RecursiveASTVisitor to traverse the AST .
>>
>> Probably the best way to construct a CFG is to have an AnalysisContext
>> object do it for you.  You can construct an AnalysisContext object using a
>> FunctionDecl, and then call the getCFG() method to have it lazily create a
>> CFG.  When the AnalysisContext object is destroyed, the CFG will be
>> destroyed as well.
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20100914/a560a4b0/attachment.html>


More information about the cfe-dev mailing list