12 #include "llvm/ADT/Hashing.h"
13 #include "llvm/Bitcode/BitstreamWriter.h"
14 #include "llvm/Support/raw_ostream.h"
16 using namespace clang;
17 using namespace clang::serialization;
19 TestModuleFileExtension::Writer::~Writer() { }
21 void TestModuleFileExtension::Writer::writeExtensionContents(
23 llvm::BitstreamWriter &Stream) {
27 BitCodeAbbrev *Abv =
new llvm::BitCodeAbbrev();
29 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
30 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
31 auto Abbrev = Stream.EmitAbbrev(Abv);
37 raw_svector_ostream OS(Message);
38 OS <<
"Hello from " << Ext->BlockName <<
" v" << Ext->MajorVersion <<
"."
42 Stream.EmitRecordWithBlob(Abbrev, Record, Message);
46 const llvm::BitstreamCursor &InStream)
52 llvm::BitstreamEntry Entry = Stream.advanceSkippingSubblocks();
54 case llvm::BitstreamEntry::SubBlock:
55 case llvm::BitstreamEntry::EndBlock:
59 case llvm::BitstreamEntry::Record:
65 unsigned RecCode = Stream.readRecord(Entry.ID, Record, &Blob);
68 StringRef Message = Blob.substr(0, Record[0]);
69 fprintf(stderr,
"Read extension block message: %s\n",
70 Message.str().c_str());
77 TestModuleFileExtension::Reader::~Reader() { }
79 TestModuleFileExtension::~TestModuleFileExtension() { }
82 TestModuleFileExtension::getExtensionMetadata()
const {
83 return { BlockName, MajorVersion, MinorVersion, UserInfo };
86 llvm::hash_code TestModuleFileExtension::hashExtension(
87 llvm::hash_code Code)
const {
89 Code = llvm::hash_combine(Code, BlockName);
90 Code = llvm::hash_combine(Code, MajorVersion);
91 Code = llvm::hash_combine(Code, MinorVersion);
92 Code = llvm::hash_combine(Code, UserInfo);
98 std::unique_ptr<ModuleFileExtensionWriter>
99 TestModuleFileExtension::createExtensionWriter(
ASTWriter &) {
100 return std::unique_ptr<ModuleFileExtensionWriter>(
new Writer(
this));
103 std::unique_ptr<ModuleFileExtensionReader>
104 TestModuleFileExtension::createExtensionReader(
107 const llvm::BitstreamCursor &Stream)
109 assert(Metadata.
BlockName == BlockName &&
"Wrong block name");
111 std::make_pair(MajorVersion, MinorVersion)) {
113 diag::err_test_module_file_extension_version)
115 << MajorVersion << MinorVersion;
119 return std::unique_ptr<ModuleFileExtensionReader>(
120 new TestModuleFileExtension::Reader(
this, Stream));
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
SourceLocation ImportLoc
The source location where this module was first imported.
A module file extension used for testing purposes.
DiagnosticsEngine & getDiags() const
The first record ID allocated to the extensions themselves.
Sema - This implements semantic analysis and AST building for C.
Abstract base class that reads a module file extension block from a module file.
Information about a module that has been loaded by the ASTReader.
Reads an AST files chain containing the contents of a translation unit.
Writes an AST file containing the contents of a translation unit.
An abstract superclass that describes a custom extension to the module/precompiled header file format...