[llvm-dev] Clang API: any way to use a virtual filesystem ?
Jacob Carlborg via llvm-dev
llvm-dev at lists.llvm.org
Mon Oct 5 09:00:45 PDT 2020
On 2020-10-05 09:44, Jean-Michaël Celerier via llvm-dev wrote:
> My question is: is it possible to hook something in clang to allow it to
> go look for files inside a virtual file system à la
> https://github.com/yevgeniy-logachev/vfspp for instance ? This way I
> would only download the zip, not extract it, and it'd be just opened in
> ram when needed.
> Or does it necessarily go through fopen() for includes right now ?
I have a tool where I use libclang (the C API). For the internal
headers, I've embedded those inside the executable, to avoid the need to
ship them separately or have the users to install them.
What I do is for each header file I create a `CXUnsavedFile` [1]. Then
I can pass that to `clang_parseTranslationUnit` when parsing the source
files.
`CXUnsavedFile` expects the filename and the content of the file. If you
can get that, you should be able to use the same approach.
If you're using the C++ API, you can have a look at the implementation
of `clang_parseTranslationUnit` to see how to do the same using the C++ API.
[1] https://clang.llvm.org/doxygen/structCXUnsavedFile.html
[2]
https://clang.llvm.org/doxygen/group__CINDEX__TRANSLATION__UNIT.html#ga2baf83f8c3299788234c8bce55e4472e
--
/Jacob Carlborg
More information about the llvm-dev
mailing list