@@ -41,6 +41,12 @@ struct RecordIdToIndexFunctor
41
41
}
42
42
};
43
43
44
+ // ------------------------------------------------
45
+ //
46
+ // Abbrev
47
+ //
48
+ // ------------------------------------------------
49
+
44
50
using AbbrevDsc = void (*)(std::shared_ptr<llvm::BitCodeAbbrev>& Abbrev);
45
51
46
52
static void AbbrevGen (
@@ -51,24 +57,32 @@ static void AbbrevGen(
51
57
Abbrev->Add (Op);
52
58
}
53
59
54
- static void BoolAbbrev (
60
+ static void Integer32Abbrev (
55
61
std::shared_ptr<llvm::BitCodeAbbrev>& Abbrev)
56
62
{
57
63
AbbrevGen (Abbrev, {
58
- // 0. Boolean
64
+ // 0. 32-bit signed or unsigned integer
59
65
llvm::BitCodeAbbrevOp (
60
- llvm::BitCodeAbbrevOp::Fixed,
61
- BitCodeConstants::BoolSize) });
66
+ llvm::BitCodeAbbrevOp::Fixed, 32 ) });
62
67
}
63
68
64
- static void IntAbbrev (
69
+ static void Integer16Abbrev (
65
70
std::shared_ptr<llvm::BitCodeAbbrev>& Abbrev)
66
71
{
67
72
AbbrevGen (Abbrev, {
68
- // 0. Fixed-size integer
73
+ // 0. 16-bit signed or unsigned integer
74
+ llvm::BitCodeAbbrevOp (
75
+ llvm::BitCodeAbbrevOp::Fixed, 16 ) });
76
+ }
77
+
78
+ static void BoolAbbrev (
79
+ std::shared_ptr<llvm::BitCodeAbbrev>& Abbrev)
80
+ {
81
+ AbbrevGen (Abbrev, {
82
+ // 0. Boolean
69
83
llvm::BitCodeAbbrevOp (
70
84
llvm::BitCodeAbbrevOp::Fixed,
71
- BitCodeConstants::IntSize ) });
85
+ BitCodeConstants::BoolSize ) });
72
86
}
73
87
74
88
static void SymbolIDAbbrev (
@@ -182,16 +196,16 @@ RecordIdNameMap = []()
182
196
// There is no init-list constructor for the IndexedMap, so have to
183
197
// improvise
184
198
static const std::vector<std::pair<RecordId, RecordIdDsc>> Inits = {
185
- {VERSION, {" Version" , &IntAbbrev }},
186
- {JAVADOC_LIST_KIND, {" JavadocListKind" , &IntAbbrev }},
187
- {JAVADOC_NODE_KIND, {" JavadocNodeKind" , &IntAbbrev }},
199
+ {VERSION, {" Version" , &Integer32Abbrev }},
200
+ {JAVADOC_LIST_KIND, {" JavadocListKind" , &Integer32Abbrev }},
201
+ {JAVADOC_NODE_KIND, {" JavadocNodeKind" , &Integer32Abbrev }},
188
202
{JAVADOC_NODE_STRING, {" JavadocNodeString" , &StringAbbrev}},
189
- {JAVADOC_NODE_STYLE, {" JavadocNodeStyle" , &IntAbbrev }},
190
- {JAVADOC_NODE_ADMONISH, {" JavadocNodeAdmonish" , &IntAbbrev }},
203
+ {JAVADOC_NODE_STYLE, {" JavadocNodeStyle" , &Integer32Abbrev }},
204
+ {JAVADOC_NODE_ADMONISH, {" JavadocNodeAdmonish" , &Integer32Abbrev }},
191
205
{FIELD_TYPE_NAME, {" Name" , &StringAbbrev}},
192
206
{FIELD_DEFAULT_VALUE, {" DefaultValue" , &StringAbbrev}},
193
207
{MEMBER_TYPE_NAME, {" Name" , &StringAbbrev}},
194
- {MEMBER_TYPE_ACCESS, {" Access" , &IntAbbrev }},
208
+ {MEMBER_TYPE_ACCESS, {" Access" , &Integer32Abbrev }},
195
209
{NAMESPACE_USR, {" USR" , &SymbolIDAbbrev}},
196
210
{NAMESPACE_NAME, {" Name" , &StringAbbrev}},
197
211
{ENUM_USR, {" USR" , &SymbolIDAbbrev}},
@@ -206,25 +220,25 @@ RecordIdNameMap = []()
206
220
{RECORD_NAME, {" Name" , &StringAbbrev}},
207
221
{RECORD_DEFLOCATION, {" DefLocation" , &LocationAbbrev}},
208
222
{RECORD_LOCATION, {" Location" , &LocationAbbrev}},
209
- {RECORD_TAG_TYPE, {" TagType" , &IntAbbrev }},
223
+ {RECORD_TAG_TYPE, {" TagType" , &Integer32Abbrev }},
210
224
{RECORD_IS_TYPE_DEF, {" IsTypeDef" , &BoolAbbrev}},
211
225
{BASE_RECORD_USR, {" USR" , &SymbolIDAbbrev}},
212
226
{BASE_RECORD_NAME, {" Name" , &StringAbbrev}},
213
- {BASE_RECORD_TAG_TYPE, {" TagType" , &IntAbbrev }},
227
+ {BASE_RECORD_TAG_TYPE, {" TagType" , &Integer32Abbrev }},
214
228
{BASE_RECORD_IS_VIRTUAL, {" IsVirtual" , &BoolAbbrev}},
215
- {BASE_RECORD_ACCESS, {" Access" , &IntAbbrev }},
229
+ {BASE_RECORD_ACCESS, {" Access" , &Integer32Abbrev }},
216
230
{BASE_RECORD_IS_PARENT, {" IsParent" , &BoolAbbrev}},
217
231
{FUNCTION_USR, {" USR" , &SymbolIDAbbrev}},
218
232
{FUNCTION_NAME, {" Name" , &StringAbbrev}},
219
233
{FUNCTION_DEFLOCATION, {" DefLocation" , &LocationAbbrev}},
220
234
{FUNCTION_LOCATION, {" Location" , &LocationAbbrev}},
221
- {FUNCTION_ACCESS, {" Access" , &IntAbbrev }},
235
+ {FUNCTION_ACCESS, {" Access" , &Integer32Abbrev }},
222
236
{FUNCTION_IS_METHOD, {" IsMethod" , &BoolAbbrev}},
223
- {FUNCTION_BITS, {" Specs" , &IntAbbrev }},
237
+ {FUNCTION_BITS, {" Specs" , &Integer16Abbrev }},
224
238
{REFERENCE_USR, {" USR" , &SymbolIDAbbrev}},
225
239
{REFERENCE_NAME, {" Name" , &StringAbbrev}},
226
- {REFERENCE_TYPE, {" RefType" , &IntAbbrev }},
227
- {REFERENCE_FIELD, {" Field" , &IntAbbrev }},
240
+ {REFERENCE_TYPE, {" RefType" , &Integer32Abbrev }},
241
+ {REFERENCE_FIELD, {" Field" , &Integer32Abbrev }},
228
242
{TEMPLATE_PARAM_CONTENTS, {" Contents" , &StringAbbrev}},
229
243
{TEMPLATE_SPECIALIZATION_OF, {" SpecializationOf" , &SymbolIDAbbrev}},
230
244
{TYPEDEF_USR, {" USR" , &SymbolIDAbbrev}},
@@ -726,17 +740,46 @@ emitAbbrev(
726
740
727
741
// ------------------------------------------------
728
742
//
729
- // emitRecord
743
+ // Records
730
744
//
731
745
// ------------------------------------------------
732
746
733
- template <class Enum , class >
747
+ // 16 and 32 bit integers
748
+ template <class Integer >
749
+ requires std::is_integral_v<Integer>
750
+ void
751
+ BitcodeWriter::
752
+ emitRecord (
753
+ Integer Value, RecordId ID)
754
+ {
755
+ Assert (RecordIdNameMap[ID]);
756
+ if constexpr (sizeof (Integer) == 4 )
757
+ {
758
+ Assert (RecordIdNameMap[ID].Abbrev == &Integer32Abbrev);
759
+ }
760
+ else if constexpr (sizeof (Integer) == 2 )
761
+ {
762
+ Assert (RecordIdNameMap[ID].Abbrev == &Integer16Abbrev);
763
+ }
764
+ else
765
+ {
766
+ static_assert (" can't use Integer type" );
767
+ }
768
+ if (!prepRecordData (ID, Value))
769
+ return ;
770
+ Record.push_back (static_cast <RecordValue>(Value));
771
+ Stream.EmitRecordWithAbbrev (Abbrevs.get (ID), Record);
772
+ }
773
+
774
+ // enumerations
775
+ template <class Enum >
776
+ requires std::is_enum_v<Enum>
734
777
void
735
778
BitcodeWriter::
736
779
emitRecord (
737
- Enum value , RecordId ID)
780
+ Enum Value , RecordId ID)
738
781
{
739
- emitRecord (static_cast <std::underlying_type_t <Enum>>(value ), ID);
782
+ emitRecord (static_cast <std::underlying_type_t <Enum>>(Value ), ID);
740
783
}
741
784
742
785
void
@@ -803,34 +846,6 @@ emitRecord(
803
846
Stream.EmitRecordWithAbbrev (Abbrevs.get (ID), Record);
804
847
}
805
848
806
- void
807
- BitcodeWriter::
808
- emitRecord (
809
- int Val, RecordId ID)
810
- {
811
- Assert (RecordIdNameMap[ID] && " Unknown RecordId." );
812
- Assert (RecordIdNameMap[ID].Abbrev == &IntAbbrev && " Abbrev type mismatch." );
813
- if (!prepRecordData (ID, Val))
814
- return ;
815
- // FIXME: Assert that the integer is of the appropriate size.
816
- Record.push_back (Val);
817
- Stream.EmitRecordWithAbbrev (Abbrevs.get (ID), Record);
818
- }
819
-
820
- void
821
- BitcodeWriter::
822
- emitRecord (
823
- unsigned Val, RecordId ID)
824
- {
825
- Assert (RecordIdNameMap[ID] && " Unknown RecordId." );
826
- Assert (RecordIdNameMap[ID].Abbrev == &IntAbbrev && " Abbrev type mismatch." );
827
- if (!prepRecordData (ID, Val))
828
- return ;
829
- Assert (Val < (1U << BitCodeConstants::IntSize));
830
- Record.push_back (Val);
831
- Stream.EmitRecordWithAbbrev (Abbrevs.get (ID), Record);
832
- }
833
-
834
849
void
835
850
BitcodeWriter::
836
851
emitRecord (
0 commit comments