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