1 //===-- APINotesWriter.h - API Notes Writer ---------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_CLANG_LIB_APINOTES_APINOTESFORMAT_H
10 #define LLVM_CLANG_LIB_APINOTES_APINOTESFORMAT_H
12 #include "llvm/ADT/PointerEmbeddedInt.h"
13 #include "llvm/Bitcode/BitcodeConvenience.h"
17 /// Magic number for API notes files.
18 const unsigned char API_NOTES_SIGNATURE
[] = {0xE2, 0x9C, 0xA8, 0x01};
20 /// API notes file major version number.
21 const uint16_t VERSION_MAJOR
= 0;
23 /// API notes file minor version number.
25 /// When the format changes IN ANY WAY, this number should be incremented.
26 const uint16_t VERSION_MINOR
= 24; // EnumExtensibility + FlagEnum
28 using IdentifierID
= llvm::PointerEmbeddedInt
<unsigned, 31>;
29 using IdentifierIDField
= llvm::BCVBR
<16>;
31 using SelectorID
= llvm::PointerEmbeddedInt
<unsigned, 31>;
32 using SelectorIDField
= llvm::BCVBR
<16>;
34 /// The various types of blocks that can occur within a API notes file.
36 /// These IDs must \em not be renumbered or reordered without incrementing
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.
43 CONTROL_BLOCK_ID
= llvm::bitc::FIRST_APPLICATION_BLOCKID
,
45 /// The identifier data block, which maps identifier strings to IDs.
48 /// The Objective-C context data block, which contains information about
49 /// Objective-C classes and protocols.
50 OBJC_CONTEXT_BLOCK_ID
,
52 /// The Objective-C property data block, which maps Objective-C
53 /// (class name, property name) pairs to information about the
55 OBJC_PROPERTY_BLOCK_ID
,
57 /// The Objective-C property data block, which maps Objective-C
58 /// (class name, selector, is_instance_method) tuples to information
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
,
67 /// The global variables data block, which maps global variable names to
68 /// information about the global variable.
69 GLOBAL_VARIABLE_BLOCK_ID
,
71 /// The (global) functions data block, which maps global function names to
72 /// information about the global function.
73 GLOBAL_FUNCTION_BLOCK_ID
,
75 /// The tag data block, which maps tag names to information about
79 /// The typedef data block, which maps typedef names to information about
83 /// The enum constant data block, which maps enumerator names to
84 /// information about the enumerators.
85 ENUM_CONSTANT_BLOCK_ID
,
88 namespace control_block
{
89 // These IDs must \em not be renumbered or reordered without incrementing
98 using MetadataLayout
=
99 llvm::BCRecordLayout
<METADATA
, // ID
100 llvm::BCFixed
<16>, // Module format major version
101 llvm::BCFixed
<16> // Module format minor version
104 using ModuleNameLayout
= llvm::BCRecordLayout
<MODULE_NAME
,
105 llvm::BCBlob
// Module name
108 using ModuleOptionsLayout
=
109 llvm::BCRecordLayout
<MODULE_OPTIONS
,
110 llvm::BCFixed
<1> // SwiftInferImportAsMember
113 using SourceFileLayout
= llvm::BCRecordLayout
<SOURCE_FILE
,
114 llvm::BCVBR
<16>, // file size
115 llvm::BCVBR
<16> // creation time
117 } // namespace control_block
119 namespace identifier_block
{
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
129 } // namespace identifier_block
131 namespace objc_context_block
{
133 OBJC_CONTEXT_ID_DATA
= 1,
134 OBJC_CONTEXT_INFO_DATA
= 2,
137 using ObjCContextIDLayout
=
138 llvm::BCRecordLayout
<OBJC_CONTEXT_ID_DATA
, // record ID
139 llvm::BCVBR
<16>, // table offset within the blob (see
141 llvm::BCBlob
// map from ObjC class names/protocol (as
142 // IDs) to context IDs
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.
150 } // namespace objc_context_block
152 namespace objc_property_block
{
154 OBJC_PROPERTY_DATA
= 1,
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
163 } // namespace objc_property_block
165 namespace objc_method_block
{
167 OBJC_METHOD_DATA
= 1,
170 using ObjCMethodDataLayout
=
171 llvm::BCRecordLayout
<OBJC_METHOD_DATA
, // record ID
172 llvm::BCVBR
<16>, // table offset within the blob (see
174 llvm::BCBlob
// map from ObjC (class names, selector,
175 // is-instance-method) tuples to ObjC
176 // method information
178 } // namespace objc_method_block
180 namespace objc_selector_block
{
182 OBJC_SELECTOR_DATA
= 1,
185 using ObjCSelectorDataLayout
=
186 llvm::BCRecordLayout
<OBJC_SELECTOR_DATA
, // record ID
187 llvm::BCVBR
<16>, // table offset within the blob (see
189 llvm::BCBlob
// map from (# pieces, identifier IDs) to
190 // Objective-C selector ID.
192 } // namespace objc_selector_block
194 namespace global_variable_block
{
195 enum { GLOBAL_VARIABLE_DATA
= 1 };
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
202 } // namespace global_variable_block
204 namespace global_function_block
{
205 enum { GLOBAL_FUNCTION_DATA
= 1 };
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
212 } // namespace global_function_block
214 namespace tag_block
{
215 enum { TAG_DATA
= 1 };
217 using TagDataLayout
=
218 llvm::BCRecordLayout
<TAG_DATA
, // record ID
219 llvm::BCVBR
<16>, // table offset within the blob (see
221 llvm::BCBlob
// map from name to tag information
223 }; // namespace tag_block
225 namespace typedef_block
{
226 enum { TYPEDEF_DATA
= 1 };
228 using TypedefDataLayout
=
229 llvm::BCRecordLayout
<TYPEDEF_DATA
, // record ID
230 llvm::BCVBR
<16>, // table offset within the blob (see
232 llvm::BCBlob
// map from name to typedef information
234 }; // namespace typedef_block
236 namespace enum_constant_block
{
237 enum { ENUM_CONSTANT_DATA
= 1 };
239 using EnumConstantDataLayout
=
240 llvm::BCRecordLayout
<ENUM_CONSTANT_DATA
, // record ID
241 llvm::BCVBR
<16>, // table offset within the blob (see
243 llvm::BCBlob
// map from name to enumerator information
245 } // namespace enum_constant_block
247 /// A stored Objective-C selector.
248 struct StoredObjCSelector
{
250 llvm::SmallVector
<IdentifierID
, 2> Identifiers
;
252 } // namespace api_notes