1*e038c9c4Sjoerg //===-- APINotesWriter.h - API Notes Writer ---------------------*- C++ -*-===// 2*e038c9c4Sjoerg // 3*e038c9c4Sjoerg // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*e038c9c4Sjoerg // See https://llvm.org/LICENSE.txt for license information. 5*e038c9c4Sjoerg // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*e038c9c4Sjoerg // 7*e038c9c4Sjoerg //===----------------------------------------------------------------------===// 8*e038c9c4Sjoerg 9*e038c9c4Sjoerg #ifndef LLVM_CLANG_LIB_APINOTES_APINOTESFORMAT_H 10*e038c9c4Sjoerg #define LLVM_CLANG_LIB_APINOTES_APINOTESFORMAT_H 11*e038c9c4Sjoerg 12*e038c9c4Sjoerg #include "llvm/ADT/PointerEmbeddedInt.h" 13*e038c9c4Sjoerg #include "llvm/Bitcode/BitcodeConvenience.h" 14*e038c9c4Sjoerg 15*e038c9c4Sjoerg namespace clang { 16*e038c9c4Sjoerg namespace api_notes { 17*e038c9c4Sjoerg /// Magic number for API notes files. 18*e038c9c4Sjoerg const unsigned char API_NOTES_SIGNATURE[] = {0xE2, 0x9C, 0xA8, 0x01}; 19*e038c9c4Sjoerg 20*e038c9c4Sjoerg /// API notes file major version number. 21*e038c9c4Sjoerg const uint16_t VERSION_MAJOR = 0; 22*e038c9c4Sjoerg 23*e038c9c4Sjoerg /// API notes file minor version number. 24*e038c9c4Sjoerg /// 25*e038c9c4Sjoerg /// When the format changes IN ANY WAY, this number should be incremented. 26*e038c9c4Sjoerg const uint16_t VERSION_MINOR = 24; // EnumExtensibility + FlagEnum 27*e038c9c4Sjoerg 28*e038c9c4Sjoerg using IdentifierID = llvm::PointerEmbeddedInt<unsigned, 31>; 29*e038c9c4Sjoerg using IdentifierIDField = llvm::BCVBR<16>; 30*e038c9c4Sjoerg 31*e038c9c4Sjoerg using SelectorID = llvm::PointerEmbeddedInt<unsigned, 31>; 32*e038c9c4Sjoerg using SelectorIDField = llvm::BCVBR<16>; 33*e038c9c4Sjoerg 34*e038c9c4Sjoerg /// The various types of blocks that can occur within a API notes file. 35*e038c9c4Sjoerg /// 36*e038c9c4Sjoerg /// These IDs must \em not be renumbered or reordered without incrementing 37*e038c9c4Sjoerg /// VERSION_MAJOR. 38*e038c9c4Sjoerg enum BlockID { 39*e038c9c4Sjoerg /// The control block, which contains all of the information that needs to 40*e038c9c4Sjoerg /// be validated prior to committing to loading the API notes file. 41*e038c9c4Sjoerg /// 42*e038c9c4Sjoerg /// \sa control_block 43*e038c9c4Sjoerg CONTROL_BLOCK_ID = llvm::bitc::FIRST_APPLICATION_BLOCKID, 44*e038c9c4Sjoerg 45*e038c9c4Sjoerg /// The identifier data block, which maps identifier strings to IDs. 46*e038c9c4Sjoerg IDENTIFIER_BLOCK_ID, 47*e038c9c4Sjoerg 48*e038c9c4Sjoerg /// The Objective-C context data block, which contains information about 49*e038c9c4Sjoerg /// Objective-C classes and protocols. 50*e038c9c4Sjoerg OBJC_CONTEXT_BLOCK_ID, 51*e038c9c4Sjoerg 52*e038c9c4Sjoerg /// The Objective-C property data block, which maps Objective-C 53*e038c9c4Sjoerg /// (class name, property name) pairs to information about the 54*e038c9c4Sjoerg /// property. 55*e038c9c4Sjoerg OBJC_PROPERTY_BLOCK_ID, 56*e038c9c4Sjoerg 57*e038c9c4Sjoerg /// The Objective-C property data block, which maps Objective-C 58*e038c9c4Sjoerg /// (class name, selector, is_instance_method) tuples to information 59*e038c9c4Sjoerg /// about the method. 60*e038c9c4Sjoerg OBJC_METHOD_BLOCK_ID, 61*e038c9c4Sjoerg 62*e038c9c4Sjoerg /// The Objective-C selector data block, which maps Objective-C 63*e038c9c4Sjoerg /// selector names (# of pieces, identifier IDs) to the selector ID 64*e038c9c4Sjoerg /// used in other tables. 65*e038c9c4Sjoerg OBJC_SELECTOR_BLOCK_ID, 66*e038c9c4Sjoerg 67*e038c9c4Sjoerg /// The global variables data block, which maps global variable names to 68*e038c9c4Sjoerg /// information about the global variable. 69*e038c9c4Sjoerg GLOBAL_VARIABLE_BLOCK_ID, 70*e038c9c4Sjoerg 71*e038c9c4Sjoerg /// The (global) functions data block, which maps global function names to 72*e038c9c4Sjoerg /// information about the global function. 73*e038c9c4Sjoerg GLOBAL_FUNCTION_BLOCK_ID, 74*e038c9c4Sjoerg 75*e038c9c4Sjoerg /// The tag data block, which maps tag names to information about 76*e038c9c4Sjoerg /// the tags. 77*e038c9c4Sjoerg TAG_BLOCK_ID, 78*e038c9c4Sjoerg 79*e038c9c4Sjoerg /// The typedef data block, which maps typedef names to information about 80*e038c9c4Sjoerg /// the typedefs. 81*e038c9c4Sjoerg TYPEDEF_BLOCK_ID, 82*e038c9c4Sjoerg 83*e038c9c4Sjoerg /// The enum constant data block, which maps enumerator names to 84*e038c9c4Sjoerg /// information about the enumerators. 85*e038c9c4Sjoerg ENUM_CONSTANT_BLOCK_ID, 86*e038c9c4Sjoerg }; 87*e038c9c4Sjoerg 88*e038c9c4Sjoerg namespace control_block { 89*e038c9c4Sjoerg // These IDs must \em not be renumbered or reordered without incrementing 90*e038c9c4Sjoerg // VERSION_MAJOR. 91*e038c9c4Sjoerg enum { 92*e038c9c4Sjoerg METADATA = 1, 93*e038c9c4Sjoerg MODULE_NAME = 2, 94*e038c9c4Sjoerg MODULE_OPTIONS = 3, 95*e038c9c4Sjoerg SOURCE_FILE = 4, 96*e038c9c4Sjoerg }; 97*e038c9c4Sjoerg 98*e038c9c4Sjoerg using MetadataLayout = 99*e038c9c4Sjoerg llvm::BCRecordLayout<METADATA, // ID 100*e038c9c4Sjoerg llvm::BCFixed<16>, // Module format major version 101*e038c9c4Sjoerg llvm::BCFixed<16> // Module format minor version 102*e038c9c4Sjoerg >; 103*e038c9c4Sjoerg 104*e038c9c4Sjoerg using ModuleNameLayout = llvm::BCRecordLayout<MODULE_NAME, 105*e038c9c4Sjoerg llvm::BCBlob // Module name 106*e038c9c4Sjoerg >; 107*e038c9c4Sjoerg 108*e038c9c4Sjoerg using ModuleOptionsLayout = 109*e038c9c4Sjoerg llvm::BCRecordLayout<MODULE_OPTIONS, 110*e038c9c4Sjoerg llvm::BCFixed<1> // SwiftInferImportAsMember 111*e038c9c4Sjoerg >; 112*e038c9c4Sjoerg 113*e038c9c4Sjoerg using SourceFileLayout = llvm::BCRecordLayout<SOURCE_FILE, 114*e038c9c4Sjoerg llvm::BCVBR<16>, // file size 115*e038c9c4Sjoerg llvm::BCVBR<16> // creation time 116*e038c9c4Sjoerg >; 117*e038c9c4Sjoerg } // namespace control_block 118*e038c9c4Sjoerg 119*e038c9c4Sjoerg namespace identifier_block { 120*e038c9c4Sjoerg enum { 121*e038c9c4Sjoerg IDENTIFIER_DATA = 1, 122*e038c9c4Sjoerg }; 123*e038c9c4Sjoerg 124*e038c9c4Sjoerg using IdentifierDataLayout = llvm::BCRecordLayout< 125*e038c9c4Sjoerg IDENTIFIER_DATA, // record ID 126*e038c9c4Sjoerg llvm::BCVBR<16>, // table offset within the blob (see below) 127*e038c9c4Sjoerg llvm::BCBlob // map from identifier strings to decl kinds / decl IDs 128*e038c9c4Sjoerg >; 129*e038c9c4Sjoerg } // namespace identifier_block 130*e038c9c4Sjoerg 131*e038c9c4Sjoerg namespace objc_context_block { 132*e038c9c4Sjoerg enum { 133*e038c9c4Sjoerg OBJC_CONTEXT_ID_DATA = 1, 134*e038c9c4Sjoerg OBJC_CONTEXT_INFO_DATA = 2, 135*e038c9c4Sjoerg }; 136*e038c9c4Sjoerg 137*e038c9c4Sjoerg using ObjCContextIDLayout = 138*e038c9c4Sjoerg llvm::BCRecordLayout<OBJC_CONTEXT_ID_DATA, // record ID 139*e038c9c4Sjoerg llvm::BCVBR<16>, // table offset within the blob (see 140*e038c9c4Sjoerg // below) 141*e038c9c4Sjoerg llvm::BCBlob // map from ObjC class names/protocol (as 142*e038c9c4Sjoerg // IDs) to context IDs 143*e038c9c4Sjoerg >; 144*e038c9c4Sjoerg 145*e038c9c4Sjoerg using ObjCContextInfoLayout = llvm::BCRecordLayout< 146*e038c9c4Sjoerg OBJC_CONTEXT_INFO_DATA, // record ID 147*e038c9c4Sjoerg llvm::BCVBR<16>, // table offset within the blob (see below) 148*e038c9c4Sjoerg llvm::BCBlob // map from ObjC context IDs to context information. 149*e038c9c4Sjoerg >; 150*e038c9c4Sjoerg } // namespace objc_context_block 151*e038c9c4Sjoerg 152*e038c9c4Sjoerg namespace objc_property_block { 153*e038c9c4Sjoerg enum { 154*e038c9c4Sjoerg OBJC_PROPERTY_DATA = 1, 155*e038c9c4Sjoerg }; 156*e038c9c4Sjoerg 157*e038c9c4Sjoerg using ObjCPropertyDataLayout = llvm::BCRecordLayout< 158*e038c9c4Sjoerg OBJC_PROPERTY_DATA, // record ID 159*e038c9c4Sjoerg llvm::BCVBR<16>, // table offset within the blob (see below) 160*e038c9c4Sjoerg llvm::BCBlob // map from ObjC (class name, property name) pairs to 161*e038c9c4Sjoerg // ObjC property information 162*e038c9c4Sjoerg >; 163*e038c9c4Sjoerg } // namespace objc_property_block 164*e038c9c4Sjoerg 165*e038c9c4Sjoerg namespace objc_method_block { 166*e038c9c4Sjoerg enum { 167*e038c9c4Sjoerg OBJC_METHOD_DATA = 1, 168*e038c9c4Sjoerg }; 169*e038c9c4Sjoerg 170*e038c9c4Sjoerg using ObjCMethodDataLayout = 171*e038c9c4Sjoerg llvm::BCRecordLayout<OBJC_METHOD_DATA, // record ID 172*e038c9c4Sjoerg llvm::BCVBR<16>, // table offset within the blob (see 173*e038c9c4Sjoerg // below) 174*e038c9c4Sjoerg llvm::BCBlob // map from ObjC (class names, selector, 175*e038c9c4Sjoerg // is-instance-method) tuples to ObjC 176*e038c9c4Sjoerg // method information 177*e038c9c4Sjoerg >; 178*e038c9c4Sjoerg } // namespace objc_method_block 179*e038c9c4Sjoerg 180*e038c9c4Sjoerg namespace objc_selector_block { 181*e038c9c4Sjoerg enum { 182*e038c9c4Sjoerg OBJC_SELECTOR_DATA = 1, 183*e038c9c4Sjoerg }; 184*e038c9c4Sjoerg 185*e038c9c4Sjoerg using ObjCSelectorDataLayout = 186*e038c9c4Sjoerg llvm::BCRecordLayout<OBJC_SELECTOR_DATA, // record ID 187*e038c9c4Sjoerg llvm::BCVBR<16>, // table offset within the blob (see 188*e038c9c4Sjoerg // below) 189*e038c9c4Sjoerg llvm::BCBlob // map from (# pieces, identifier IDs) to 190*e038c9c4Sjoerg // Objective-C selector ID. 191*e038c9c4Sjoerg >; 192*e038c9c4Sjoerg } // namespace objc_selector_block 193*e038c9c4Sjoerg 194*e038c9c4Sjoerg namespace global_variable_block { 195*e038c9c4Sjoerg enum { GLOBAL_VARIABLE_DATA = 1 }; 196*e038c9c4Sjoerg 197*e038c9c4Sjoerg using GlobalVariableDataLayout = llvm::BCRecordLayout< 198*e038c9c4Sjoerg GLOBAL_VARIABLE_DATA, // record ID 199*e038c9c4Sjoerg llvm::BCVBR<16>, // table offset within the blob (see below) 200*e038c9c4Sjoerg llvm::BCBlob // map from name to global variable information 201*e038c9c4Sjoerg >; 202*e038c9c4Sjoerg } // namespace global_variable_block 203*e038c9c4Sjoerg 204*e038c9c4Sjoerg namespace global_function_block { 205*e038c9c4Sjoerg enum { GLOBAL_FUNCTION_DATA = 1 }; 206*e038c9c4Sjoerg 207*e038c9c4Sjoerg using GlobalFunctionDataLayout = llvm::BCRecordLayout< 208*e038c9c4Sjoerg GLOBAL_FUNCTION_DATA, // record ID 209*e038c9c4Sjoerg llvm::BCVBR<16>, // table offset within the blob (see below) 210*e038c9c4Sjoerg llvm::BCBlob // map from name to global function information 211*e038c9c4Sjoerg >; 212*e038c9c4Sjoerg } // namespace global_function_block 213*e038c9c4Sjoerg 214*e038c9c4Sjoerg namespace tag_block { 215*e038c9c4Sjoerg enum { TAG_DATA = 1 }; 216*e038c9c4Sjoerg 217*e038c9c4Sjoerg using TagDataLayout = 218*e038c9c4Sjoerg llvm::BCRecordLayout<TAG_DATA, // record ID 219*e038c9c4Sjoerg llvm::BCVBR<16>, // table offset within the blob (see 220*e038c9c4Sjoerg // below) 221*e038c9c4Sjoerg llvm::BCBlob // map from name to tag information 222*e038c9c4Sjoerg >; 223*e038c9c4Sjoerg }; // namespace tag_block 224*e038c9c4Sjoerg 225*e038c9c4Sjoerg namespace typedef_block { 226*e038c9c4Sjoerg enum { TYPEDEF_DATA = 1 }; 227*e038c9c4Sjoerg 228*e038c9c4Sjoerg using TypedefDataLayout = 229*e038c9c4Sjoerg llvm::BCRecordLayout<TYPEDEF_DATA, // record ID 230*e038c9c4Sjoerg llvm::BCVBR<16>, // table offset within the blob (see 231*e038c9c4Sjoerg // below) 232*e038c9c4Sjoerg llvm::BCBlob // map from name to typedef information 233*e038c9c4Sjoerg >; 234*e038c9c4Sjoerg }; // namespace typedef_block 235*e038c9c4Sjoerg 236*e038c9c4Sjoerg namespace enum_constant_block { 237*e038c9c4Sjoerg enum { ENUM_CONSTANT_DATA = 1 }; 238*e038c9c4Sjoerg 239*e038c9c4Sjoerg using EnumConstantDataLayout = 240*e038c9c4Sjoerg llvm::BCRecordLayout<ENUM_CONSTANT_DATA, // record ID 241*e038c9c4Sjoerg llvm::BCVBR<16>, // table offset within the blob (see 242*e038c9c4Sjoerg // below) 243*e038c9c4Sjoerg llvm::BCBlob // map from name to enumerator information 244*e038c9c4Sjoerg >; 245*e038c9c4Sjoerg } // namespace enum_constant_block 246*e038c9c4Sjoerg 247*e038c9c4Sjoerg /// A stored Objective-C selector. 248*e038c9c4Sjoerg struct StoredObjCSelector { 249*e038c9c4Sjoerg unsigned NumPieces; 250*e038c9c4Sjoerg llvm::SmallVector<IdentifierID, 2> Identifiers; 251*e038c9c4Sjoerg }; 252*e038c9c4Sjoerg } // namespace api_notes 253*e038c9c4Sjoerg } // namespace clang 254*e038c9c4Sjoerg 255*e038c9c4Sjoerg #endif 256