22#include "clang/Frontend/FrontendDiagnostic.h"
23#include "clang/Lex/HeaderSearchOptions.h"
24#include "clang/Lex/Preprocessor.h"
25#include "clang/Sema/Sema.h"
26#include "clang/Serialization/ASTReader.h"
28#include "llvm/ADT/Hashing.h"
29#include "llvm/Bitstream/BitstreamWriter.h"
30#include "llvm/Support/FileSystem.h"
31#include "llvm/Support/MemoryBuffer.h"
32#include "llvm/Support/Path.h"
33#include "llvm/Support/raw_ostream.h"
55 const clang::LangOptions &Opts = SemaRef.getLangOpts();
56 const clang::Preprocessor &PP = SemaRef.getPreprocessor();
58 llvm::StringRef CachePath = PP.getHeaderSearchInfo().getHeaderSearchOpts().ModuleCachePath;
59 std::string RdictsStart =
"lib" + Opts.CurrentModule +
"_";
60 const std::string RdictsEnd =
"_rdict.pcm";
63 using namespace clang;
64 using namespace clang::serialization;
66 auto Abv = std::make_shared<BitCodeAbbrev>();
67 Abv->Add(BitCodeAbbrevOp(FIRST_EXTENSION_RECORD_ID));
68 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
69 auto Abbrev = Stream.EmitAbbrev(std::move(Abv));
70 auto Abv1 = std::make_shared<BitCodeAbbrev>();
71 Abv1->Add(BitCodeAbbrevOp(FIRST_EXTENSION_RECORD_ID + 1));
72 Abv1->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
73 auto Abbrev1 = Stream.EmitAbbrev(std::move(Abv1));
77 for (llvm::sys::fs::directory_iterator DirIt(CachePath, EC), DirEnd; DirIt != DirEnd && !EC; DirIt.increment(EC)) {
78 StringRef FilePath(DirIt->path());
79 if (llvm::sys::fs::is_directory(FilePath))
81 StringRef FileName = llvm::sys::path::filename(FilePath);
82 if (FileName.startswith(RdictsStart) && FileName.endswith(RdictsEnd)) {
84 uint64_t Record[] = {FIRST_EXTENSION_RECORD_ID};
85 Stream.EmitRecordWithBlob(Abbrev, Record, FileName);
87 uint64_t Record1[] = {FIRST_EXTENSION_RECORD_ID + 1};
88 std::ifstream fp(FilePath.str(), std::ios::binary);
89 std::ostringstream os;
91 Stream.EmitRecordWithBlob(Abbrev1, Record1, StringRef(os.str()));
94 EC = llvm::sys::fs::remove(FilePath);
95 assert(!EC &&
"Unable to close _rdict file");
103 clang::serialization::ModuleFile &Mod,
104 const llvm::BitstreamCursor &InStream)
105 : ModuleFileExtensionReader(Ext), Stream(InStream)
108 llvm::SmallVector<uint64_t, 4> Record;
109 llvm::StringRef CurrentRdictName;
111 llvm::BitstreamEntry Entry = llvm::cantFail(
Stream.advanceSkippingSubblocks());
112 switch (Entry.Kind) {
113 case llvm::BitstreamEntry::SubBlock:
114 case llvm::BitstreamEntry::EndBlock:
115 case llvm::BitstreamEntry::Error:
return;
117 case llvm::BitstreamEntry::Record:
break;
121 llvm::StringRef Blob;
122 unsigned RecCode = llvm::cantFail(
Stream.readRecord(Entry.ID, Record, &Blob));
123 using namespace clang::serialization;
125 case FIRST_EXTENSION_RECORD_ID: {
126 CurrentRdictName = Blob;
129 case FIRST_EXTENSION_RECORD_ID + 1: {
131 std::string ResolvedFileName
133 llvm::StringRef ModDir = llvm::sys::path::parent_path(ResolvedFileName);
134 llvm::SmallString<255> FullRdictName = ModDir;
135 llvm::sys::path::append(FullRdictName, CurrentRdictName);
149 const std::string UserInfo =
"";
160std::unique_ptr<clang::ModuleFileExtensionWriter>
163 return std::unique_ptr<clang::ModuleFileExtensionWriter>(
new Writer(
this));
166std::unique_ptr<clang::ModuleFileExtensionReader>
168 clang::ASTReader &
Reader, clang::serialization::ModuleFile &Mod,
169 const llvm::BitstreamCursor &Stream)
171 return std::unique_ptr<clang::ModuleFileExtensionReader>(
constexpr uint16_t ROOT_CLING_RDICT_VERSION_MINOR
Rdict module extension minor version number.
const std::string ROOT_CLING_RDICT_BLOCK_NAME
Rdict module extension block name.
constexpr uint16_t ROOT_CLING_RDICT_VERSION_MAJOR
Rdict module extension major version number.
The file contains facilities to work with C++ module files extensions used to store rdict files.
void TCling__RegisterRdictForLoadPCM(const std::string &pcmFileNameFullPath, llvm::StringRef *pcmContent)
llvm::BitstreamCursor Stream
Reader(clang::ModuleFileExtension *Ext, clang::ASTReader &Reader, clang::serialization::ModuleFile &Mod, const llvm::BitstreamCursor &InStream)
void writeExtensionContents(clang::Sema &SemaRef, llvm::BitstreamWriter &Stream) override
std::unique_ptr< clang::ModuleFileExtensionReader > createExtensionReader(const clang::ModuleFileExtensionMetadata &Metadata, clang::ASTReader &Reader, clang::serialization::ModuleFile &Mod, const llvm::BitstreamCursor &Stream) override
clang::ModuleFileExtensionMetadata getExtensionMetadata() const override
std::unique_ptr< clang::ModuleFileExtensionWriter > createExtensionWriter(clang::ASTWriter &Writer) override
~TClingRdictModuleFileExtension() override
void hashExtension(ExtensionHashBuilder &HBuilder) const override