[cfe-dev] Basic source-to-source transformation with Clang
Slav
slavmfm at gmail.com
Mon Jun 25 07:57:29 PDT 2012
I tried to use "Tooling" but was unable to specify multiple headers
searching directories, redefine preprocessor and so on - as I understood,
"Tooling" exposes pretty narrow interface.
Prakash, I think this example will be helpful for you:
http://eli.thegreenplace.net/2012/06/08/basic-source-to-source-transformation-with-clang/
2012/6/25 Slav <slavmfm at gmail.com>
>
> Cheers,
>> /Manuel
>>
>> On Mon, Jun 25, 2012 at 3:37 PM, Slav <slavmfm at gmail.com> wrote:
>>
>>> I tried to use "Tooling" but was unable to specify multiple headers
>>> searching directory, redefine preprocessor...
>>
>> Prakash, I think this example will be helpful for you:
>>> http://eli.thegreenplace.net/2012/06/08/basic-source-to-source-transformation-with-clang/
>>>
>>>
>>> 2012/6/25 Manuel Klimek <klimek at google.com>
>>>
>>>> On Mon, Jun 25, 2012 at 2:30 PM, Satya Prakash Prasad <
>>>> satyaprakash.prasad at gmail.com> wrote:
>>>>
>>>>> 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.
>>>>>
>>>>
>>>> Yea, getting the include path search logic right & correctly setup is
>>>> not trivial. That's exactly what the tooling library takes care of for you
>>>> :) If you want to duplicate that logic, you're of course free to, but I
>>>> would guess it'll be more time than switching your code to use the tooling
>>>> library...
>>>>
>>>> Cheers,
>>>> /Manuel
>>>>
>>>>
>>>>>
>>>>> 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
>>>>> >
>>>>> >
>>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> cfe-dev mailing list
>>>> cfe-dev at cs.uiuc.edu
>>>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>>>>
>>>>
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20120625/4ff6eed6/attachment.html>
More information about the cfe-dev
mailing list