Is it possible to generate and read PCH with an output stream

I am working on generating a PCH file from a header file and use the generated PCH file to compile different sets of code. Now I can generate the PCH file by invoking the clang compiler instance with GeneratePCHAction, and read the generated PCH file back by setting up its path in ImplicitPCHInclude. The example header and code can be found in this post.

However, I would like to avoid writing and reading the PCH file from the disk since it introduces slow disk access overhead. I tried to find if there is any approach to allow the GeneratePCHAction to invoke a output stream specified by setOutputStream, and a way to make the compiler instance aware of the generated PCH stuff from a given output stream/variable, instead of specify its path through ImplicitPCHInclude. Unfortunately, after reading the code base in llvm-12, I couldn’t find any.

I resort to llvm-14 to see if there is any new API provided, but I can’t find any useful other than the ReadPCHAndPreprocessAction. It seems this action could help read the PCH from a in memory variable, but I can’t find an example to check it really does. Also, the implementation of GeneratePCHAction still doesn’t take the outputStream setup by setOutputStream.

I wonder if there is anything I am missing and any methods I can take advantage of to do the whole thing in memory. I appreciate any comment and hint. Any suggestion could be extremely helpful. Thank you so much!