[cfe-dev] Paths to system header files

Mikhail Ramalho via cfe-dev cfe-dev at lists.llvm.org
Fri Feb 26 07:29:24 PST 2016


Hello Pedro,

I was able to embed the builtin headers using vritual files as follow.

Right now, I have two vectors to hold the filename and its content.

  std::vector<std::string> clang_headers_name;
  std::vector<std::string> clang_headers_content;

For some reason I couldn't get working using one
std::vector<std::pair<std::string, std::string> > (neither using a map),
but I didn't dig it further to understand why.

So, the two vectors are filled with the header's name and content, attached
is the method I use to embed them. It isn't an ideal solution but it works.
I created a small script that (more or less) automatically converts all the
builtin headers to strings. If you want it, just let me know.

After both vectors are filled, I simply do (bold):

  clang::tooling::FixedCompilationDatabase Compilations("./",
compiler_string);

  std::vector<std::string> sources;
  sources.push_back("/esbmc_intrinsics.h");
  sources.push_back(path);

  clang::tooling::ClangTool Tool(Compilations, sources);
  Tool.mapVirtualFile("/esbmc_intrinsics.h", intrinsics);

*  for(auto it = clang_headers_name.begin(), it1 =
clang_headers_content.begin();*
*      (it != clang_headers_name.end()) && (it1 !=
clang_headers_content.end());*
*      ++it, ++it1)*
*    Tool.mapVirtualFile(*it, *it1);*

  Tool.buildASTs(ASTs);

As soon as clang 3.8 is released, we'll open source our project that uses
this code, so it'll be easier to understand how it's done. I hope this
helps for now.

Also, You will need clang 3.8, as this doesn't work on clang 3.7.

Cheers,

2016-02-26 15:08 GMT+00:00 Jacob Carlborg via cfe-dev <
cfe-dev at lists.llvm.org>:

> On 2016-02-26 14:06, Pedro Delgado Perez via cfe-dev wrote:
>
>> Sorry about the format of the previous message. I write it again here.
>>
>>
>> Sorry, Jacob, no idea on how to use your solution in my code. Manuel,
>> nothing is written in your message I think...
>> My code is something like this:
>>
>> static cl::OptionCategory MyToolCategory("My tool options");
>>
>>   int main(int argc, const char **argv) {
>>     CommonOptionsParser OptionsParser(argc, argv, MyToolCategory);
>>     ClangTool Tool(OptionsParser.getCompilations(),
>>     OptionsParser.getSourcePathList());
>>     return Tool.run(newFrontendActionFactory<SyntaxOnlyAction>().get());
>> }
>>
>> What I was doing by the moment is to process argv before creating the
>> object OptionsParser and then include internal Clang headers, but I
>> guess I can't do that when using Json compilation database. Could you
>> help me with that? Otherwise, is there a way to ship in the executable
>> all the necessary headers so that the user does not require to have
>> clang installed?
>>
>
> I haven't used the C++ interface, only the C interface. But look at the
> original post in the thread I linked to [1]. There it seems like
> "mapVirtualFile" in clang::tooling::ClangTool is used to add a virtual
> header file. See also the last post by "Mikhail Ramalho". You need to add
> the path where the virtual file is located as an include path.
>
> [1]
> http://clang-developers.42468.n3.nabble.com/Builtin-headers-td4049705.html
>
>
> --
> /Jacob Carlborg
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>



-- 

Mikhail Ramalho.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20160226/aa4b1ef5/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: clang_headers.cpp
Type: text/x-c++src
Size: 59864 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20160226/aa4b1ef5/attachment.cpp>


More information about the cfe-dev mailing list