11#include "llvm/ADT/Hashing.h"
12#include "llvm/Bitstream/BitstreamWriter.h"
13#include "llvm/Support/raw_ostream.h"
20TestModuleFileExtension::Writer::~Writer() { }
22void TestModuleFileExtension::Writer::writeExtensionContents(
24 llvm::BitstreamWriter &Stream) {
28 auto Abv = std::make_shared<llvm::BitCodeAbbrev>();
30 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
31 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
32 auto Abbrev = Stream.EmitAbbrev(std::move(Abv));
38 raw_svector_ostream OS(Message);
39 OS <<
"Hello from " << Ext->BlockName <<
" v" << Ext->MajorVersion <<
"."
43 Stream.EmitRecordWithBlob(Abbrev,
Record, Message);
47 const llvm::BitstreamCursor &InStream)
54 Stream.advanceSkippingSubblocks();
56 (void)MaybeEntry.takeError();
57 llvm::BitstreamEntry Entry = MaybeEntry.get();
60 case llvm::BitstreamEntry::SubBlock:
61 case llvm::BitstreamEntry::EndBlock:
62 case llvm::BitstreamEntry::Error:
65 case llvm::BitstreamEntry::Record:
72 Stream.readRecord(Entry.ID,
Record, &Blob);
74 fprintf(stderr,
"Failed reading rec code: %s\n",
75 toString(MaybeRecCode.takeError()).c_str());
76 switch (MaybeRecCode.get()) {
78 StringRef Message = Blob.substr(0,
Record[0]);
79 fprintf(stderr,
"Read extension block message: %s\n",
80 Message.str().c_str());
87TestModuleFileExtension::Reader::~Reader() { }
93 return { BlockName, MajorVersion, MinorVersion, UserInfo };
97 ExtensionHashBuilder &HBuilder)
const {
99 HBuilder.add(BlockName);
100 HBuilder.add(MajorVersion);
101 HBuilder.add(MinorVersion);
102 HBuilder.add(UserInfo);
106std::unique_ptr<ModuleFileExtensionWriter>
108 return std::unique_ptr<ModuleFileExtensionWriter>(
new Writer(
this));
111std::unique_ptr<ModuleFileExtensionReader>
115 const llvm::BitstreamCursor &Stream)
117 assert(Metadata.
BlockName == BlockName &&
"Wrong block name");
119 std::make_pair(MajorVersion, MinorVersion)) {
121 diag::err_test_module_file_extension_version)
123 << MajorVersion << MinorVersion;
127 return std::unique_ptr<ModuleFileExtensionReader>(
128 new TestModuleFileExtension::Reader(
this, Stream));
133 llvm::raw_string_ostream OS(Buffer);
134 OS << BlockName <<
":" << MajorVersion <<
":" << MinorVersion <<
":" << Hashed
llvm::MachO::Record Record
static std::string toString(const clang::SanitizerSet &Sanitizers)
Produce a string containing comma-separated names of sanitizers in Sanitizers set.
Reads an AST files chain containing the contents of a translation unit.
DiagnosticsEngine & getDiags() const
Writes an AST file containing the contents of a translation unit.
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Abstract base class that reads a module file extension block from a module file.
An abstract superclass that describes a custom extension to the module/precompiled header file format...
Sema - This implements semantic analysis and AST building for C.
A module file extension used for testing purposes.
ModuleFileExtensionMetadata getExtensionMetadata() const override
~TestModuleFileExtension() override
std::unique_ptr< ModuleFileExtensionWriter > createExtensionWriter(ASTWriter &Writer) override
void hashExtension(ExtensionHashBuilder &HBuilder) const override
std::unique_ptr< ModuleFileExtensionReader > createExtensionReader(const ModuleFileExtensionMetadata &Metadata, ASTReader &Reader, serialization::ModuleFile &Mod, const llvm::BitstreamCursor &Stream) override
Information about a module that has been loaded by the ASTReader.
SourceLocation ImportLoc
The source location where this module was first imported.
@ FIRST_EXTENSION_RECORD_ID
The first record ID allocated to the extensions themselves.
The JSON file list parser is used to communicate input to InstallAPI.
Diagnostic wrappers for TextAPI types for error reporting.