[cfe-dev] Basic source-to-source transformation with Clang
Satya Prakash Prasad
satyaprakash.prasad at gmail.com
Mon Jun 25 05:30:15 PDT 2012
Thanks to all for the response.
I was able to make a progress at least remove the C++ errors but one
issue remains - identifying the include path for C++ header file. I
now get output as :
fatal error: 'aio.h' file not found
#include <aio.h>
// Begin function inc returning int
int inc(int &p)
{
p++;
printf("In inc [%d]\n", p);
return p;
}
// End function inc
……………………………………………………
The file aio.h is in /usr/include directory of my system:
llvm/build/Release+Asserts/examples> ls -l /usr/include/aio.h
-rw-r--r-- 1 root root 7135 Jul 17 2009 /usr/include/aio.h
My code modifications are:
LangOptions languageOptions;
languageOptions.CPlusPlus= 1;
TheCompInst.createFileManager();
FileManager &FileMgr = TheCompInst.getFileManager();
TheCompInst.createSourceManager(FileMgr);
CompilerInvocation* CI = new CompilerInvocation;
CI->setLangDefaults(languageOptions, IK_CXX);
TheCompInst.setInvocation(CI);
DiagnosticsEngine DiagnosticsEngine = TheCompInst.getDiagnostics();
HeaderSearch headerSearch(FileMgr, DiagnosticsEngine, languageOptions, TI);
HeaderSearchOptions headerSearchOptions;
headerSearchOptions.AddPath("/usr/include/c++/4.1.2/backward/",
frontend::Angled, false, false, false, false, false);
headerSearchOptions.AddPath("/usr/include/c++/4.1.2/",
frontend::Angled, false, false, false, false, false);
headerSearchOptions.AddPath("/usr/include/c++/", frontend::Angled,
false, false, false, false, false);
headerSearchOptions.AddPath("/usr/include/", frontend::Angled,
false, false, false, false, false);
Preprocessor preprocessor(DiagnosticsEngine, languageOptions, TI ,
SourceMgr, headerSearch, TheCompInst);
TheCompInst.setPreprocessor(&preprocessor);
I am not sure what I need to do now to remove this error? Though I
have not yet tried libtooling library but since I have explored CLANG
using Frontend APIs I am proceeding with the same.
Thanks gain in advance.
Regards,
Prakash
On Sat, Jun 23, 2012 at 12:05 AM, Manuel Klimek <klimek at google.com> wrote:
> On Fri, Jun 22, 2012 at 7:55 PM, John McCall <rjmccall at apple.com> wrote:
>>
>> On Jun 22, 2012, at 3:06 AM, Satya Prakash Prasad wrote:
>> > Thanks John for the clarification.
>> >
>> > Can you please let me know how to then create clang instance for C++
>> > input file?
>>
>> I suggest looking at some of the example code to see how it initializes
>> the
>> CompilerInstance. clang-interpreter is an example of this.
>>
>> Alternatively, you might be happier just running as a clang plugin, in
>> which case you should look at the PrintFunctionNames example.
>
>
> For source-2-source translation, there are more alternatives with different
> trade-offs to consider:
> http://clang.llvm.org/docs/Tooling.html
>
> Cheers,
> /Manuel
>
>>
>>
>> John.
>>
>> _______________________________________________
>> cfe-dev mailing list
>> cfe-dev at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>
More information about the cfe-dev
mailing list