1 //===-- TestModuleFileExtension.h - Module Extension Tester -----*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 #ifndef LLVM_CLANG_FRONTEND_TESTMODULEFILEEXTENSION_H 10 #define LLVM_CLANG_FRONTEND_TESTMODULEFILEEXTENSION_H 11 12 #include "clang/Serialization/ModuleFileExtension.h" 13 #include "clang/Basic/LLVM.h" 14 #include "llvm/ADT/StringRef.h" 15 #include "llvm/Bitcode/BitstreamReader.h" 16 #include <string> 17 18 namespace clang { 19 20 /// A module file extension used for testing purposes. 21 class TestModuleFileExtension : public ModuleFileExtension { 22 std::string BlockName; 23 unsigned MajorVersion; 24 unsigned MinorVersion; 25 bool Hashed; 26 std::string UserInfo; 27 28 class Writer : public ModuleFileExtensionWriter { 29 public: Writer(ModuleFileExtension * Ext)30 Writer(ModuleFileExtension *Ext) : ModuleFileExtensionWriter(Ext) { } 31 ~Writer() override; 32 33 void writeExtensionContents(Sema &SemaRef, 34 llvm::BitstreamWriter &Stream) override; 35 }; 36 37 class Reader : public ModuleFileExtensionReader { 38 llvm::BitstreamCursor Stream; 39 40 public: 41 ~Reader() override; 42 43 Reader(ModuleFileExtension *Ext, const llvm::BitstreamCursor &InStream); 44 }; 45 46 public: TestModuleFileExtension(StringRef BlockName,unsigned MajorVersion,unsigned MinorVersion,bool Hashed,StringRef UserInfo)47 TestModuleFileExtension(StringRef BlockName, 48 unsigned MajorVersion, 49 unsigned MinorVersion, 50 bool Hashed, 51 StringRef UserInfo) 52 : BlockName(BlockName), 53 MajorVersion(MajorVersion), MinorVersion(MinorVersion), 54 Hashed(Hashed), UserInfo(UserInfo) { } 55 ~TestModuleFileExtension() override; 56 57 ModuleFileExtensionMetadata getExtensionMetadata() const override; 58 59 llvm::hash_code hashExtension(llvm::hash_code Code) const override; 60 61 std::unique_ptr<ModuleFileExtensionWriter> 62 createExtensionWriter(ASTWriter &Writer) override; 63 64 std::unique_ptr<ModuleFileExtensionReader> 65 createExtensionReader(const ModuleFileExtensionMetadata &Metadata, 66 ASTReader &Reader, serialization::ModuleFile &Mod, 67 const llvm::BitstreamCursor &Stream) override; 68 }; 69 70 } // end namespace clang 71 72 #endif // LLVM_CLANG_FRONTEND_TESTMODULEFILEEXTENSION_H 73