Correct way to generate IR code with Frontend?

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Correct way to generate IR code with Frontend?

David Chisnall via cfe-dev

I would like to use the clang Frontend api to build a file and output
the IR code.  I have found that I can set the TargetInfo on the
CompilerInstance but I cant seem to set the LangStandard to c++11.  
Instead I have to provide an argument and call
CompilerInvocation::CreateFromArgs to get the LangStandard setting.  
What am I doing wrong in my code (see 
for the full listing)?

In my code the following does not work:

     clang::CompilerInvocation &compInvocation = compInst.getInvocation();

     clang::TargetOptions &targetOptions = compInvocation.getTargetOpts();
     targetOptions.Triple = llvm::sys::getDefaultTargetTriple();
     llvm::Triple llvmTriple(compInvocation.getTargetOpts().Triple);

     std::shared_ptr<clang::TargetOptions> pTargetOptions =
     clang::TargetInfo *pTargetInfo =
     compInst.setTarget(pTargetInfo);   // this works ok setting the

     clang::LangOptions langOpts;
     langOpts.GNUMode = 1;
     langOpts.CXXExceptions = 1;
     langOpts.RTTI = 1;
     langOpts.Bool = 1;
     langOpts.CPlusPlus11 = 1;
     clang::PreprocessorOptions &PreprocOpts =

         clang::LangStandard::lang_cxx11);  // this does not work,
instead I have to set -std=c++11 and CreateFromArgs()

I have been looking at the tutorials and other document but so far have
not found a good description of how to do this.

Thanks in advance for any assistance you can provide.


cfe-dev mailing list
[hidden email]