llvm.org GIT mirror llvm / 43afbce
Remove derelict serialization code. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@92374 91177308-0d34-0410-b5e6-96231b3b80d8 Ted Kremenek 10 years ago
11 changed file(s) with 1 addition(s) and 987 deletion(s). Raw diff Collapse all Expand all
+0
-68
include/llvm/Bitcode/Serialization.h less more
None //==- Serialization.h - Generic Object Serialization to Bitcode ---*- C++ -*-=//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines traits for primitive types used for both object
10 // serialization and deserialization.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_BITCODE_SERIALIZE
15 #define LLVM_BITCODE_SERIALIZE
16
17 #include "llvm/Bitcode/SerializationFwd.h"
18
19 namespace llvm {
20
21 /// SerializeTrait - SerializeTrait bridges between the Serializer/Deserializer
22 /// and the functions that serialize objects of specific types. The default
23 /// behavior is to call static methods of the class for the object being
24 /// serialized, but this behavior can be changed by specializing this
25 /// template. Classes only need to implement the methods corresponding
26 /// to the serialization scheme they want to support. For example, "Read"
27 /// and "ReadVal" correspond to different deserialization schemes which make
28 /// sense for different types; a class need only implement one of them.
29 /// Serialization and deserialization of pointers are specially handled
30 /// by the Serializer and Deserializer using the EmitOwnedPtr, etc. methods.
31 /// To serialize the actual object referred to by a pointer, the class
32 /// of the object either must implement the methods called by the default
33 /// behavior of SerializeTrait, or specialize SerializeTrait. This latter
34 /// is useful when one cannot add methods to an existing class (for example).
35 template
36 struct SerializeTrait {
37 static inline void Emit(Serializer& S, const T& X) { X.Emit(S); }
38 static inline void Read(Deserializer& D, T& X) { X.Read(D); }
39 static inline T* Create(Deserializer& D) { return T::Create(D); }
40
41 template
42 static inline T* Create(Deserializer& D, Arg1& arg1) {
43 return T::Create(D, arg1);
44 }
45 };
46
47 #define SERIALIZE_INT_TRAIT(TYPE)\
48 template <> struct SerializeTrait {\
49 static void Emit(Serializer& S, TYPE X);\
50 static void Read(Deserializer& S, TYPE& X); };
51
52 SERIALIZE_INT_TRAIT(bool)
53 SERIALIZE_INT_TRAIT(unsigned char)
54 SERIALIZE_INT_TRAIT(unsigned short)
55 SERIALIZE_INT_TRAIT(unsigned int)
56 SERIALIZE_INT_TRAIT(unsigned long)
57
58 SERIALIZE_INT_TRAIT(signed char)
59 SERIALIZE_INT_TRAIT(signed short)
60 SERIALIZE_INT_TRAIT(signed int)
61 SERIALIZE_INT_TRAIT(signed long)
62
63 #undef SERIALIZE_INT_TRAIT
64
65 } // end namespace llvm
66
67 #endif
+0
-27
include/llvm/Bitcode/SerializationFwd.h less more
None //==- SerializationFwd.h - Forward references for Serialization ---*- C++ -*-=//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file provides forward references for bitcode object serialization.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #ifndef LLVM_BITCODE_SERIALIZE_FWD
14 #define LLVM_BITCODE_SERIALIZE_FWD
15
16 namespace llvm {
17
18 class Serializer;
19 class Deserializer;
20 template struct SerializeTrait;
21
22 typedef unsigned SerializedPtrID;
23
24 } // end namespace llvm
25
26 #endif
+0
-211
include/llvm/Bitcode/Serialize.h less more
None //==- Serialize.h - Generic Object Serialization to Bitcode -------*- C++ -*-=//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines the interface for generic object serialization to
10 // LLVM bitcode.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_BITCODE_SERIALIZE_OUTPUT
15 #define LLVM_BITCODE_SERIALIZE_OUTPUT
16
17 #include "llvm/Bitcode/Serialization.h"
18 #include "llvm/Bitcode/BitstreamWriter.h"
19 #include "llvm/ADT/SmallVector.h"
20 #include "llvm/ADT/DenseMap.h"
21
22 namespace llvm {
23
24 class Serializer {
25 BitstreamWriter& Stream;
26 SmallVector Record;
27 unsigned BlockLevel;
28
29 typedef DenseMap MapTy;
30 MapTy PtrMap;
31
32 public:
33 explicit Serializer(BitstreamWriter& stream);
34 ~Serializer();
35
36 //==------------------------------------------------==//
37 // Template-based dispatch to emit arbitrary types.
38 //==------------------------------------------------==//
39
40 template
41 inline void Emit(const T& X) { SerializeTrait::Emit(*this,X); }
42
43 //==------------------------------------------------==//
44 // Methods to emit primitive types.
45 //==------------------------------------------------==//
46
47 void EmitInt(uint64_t X);
48 void EmitSInt(int64_t X);
49
50 inline void EmitBool(bool X) { EmitInt(X); }
51 void EmitCStr(const char* beg, const char* end);
52 void EmitCStr(const char* cstr);
53
54 void EmitPtr(const void* ptr) { EmitInt(getPtrId(ptr)); }
55
56 template
57 inline void EmitRef(const T& ref) { EmitPtr(&ref); }
58
59 // Emit a pointer and the object pointed to. (This has no relation to the
60 // OwningPtr<> class.)
61 template
62 inline void EmitOwnedPtr(T* ptr) {
63 EmitPtr(ptr);
64 if (ptr) SerializeTrait::Emit(*this,*ptr);
65 }
66
67
68 //==------------------------------------------------==//
69 // Batch emission of pointers.
70 //==------------------------------------------------==//
71
72 template
73 void BatchEmitOwnedPtrs(T1* p1, T2* p2) {
74 EmitPtr(p1);
75 EmitPtr(p2);
76 if (p1) SerializeTrait::Emit(*this,*p1);
77 if (p2) SerializeTrait::Emit(*this,*p2);
78 }
79
80 template
81 void BatchEmitOwnedPtrs(T1* p1, T2* p2, T3* p3) {
82 EmitPtr(p1);
83 EmitPtr(p2);
84 EmitPtr(p3);
85 if (p1) SerializeTrait::Emit(*this,*p1);
86 if (p2) SerializeTrait::Emit(*this,*p2);
87 if (p3) SerializeTrait::Emit(*this,*p3);
88 }
89
90 template
91 void BatchEmitOwnedPtrs(T1* p1, T2* p2, T3* p3, T4& p4) {
92 EmitPtr(p1);
93 EmitPtr(p2);
94 EmitPtr(p3);
95 EmitPtr(p4);
96 if (p1) SerializeTrait::Emit(*this,*p1);
97 if (p2) SerializeTrait::Emit(*this,*p2);
98 if (p3) SerializeTrait::Emit(*this,*p3);
99 if (p4) SerializeTrait::Emit(*this,*p4);
100 }
101
102 template
103 void BatchEmitOwnedPtrs(unsigned NumPtrs, T* const * Ptrs) {
104 for (unsigned i = 0; i < NumPtrs; ++i)
105 EmitPtr(Ptrs[i]);
106
107 for (unsigned i = 0; i < NumPtrs; ++i)
108 if (Ptrs[i]) SerializeTrait::Emit(*this,*Ptrs[i]);
109 }
110
111 template
112 void BatchEmitOwnedPtrs(unsigned NumT1Ptrs, T1* const * Ptrs, T2* p2) {
113
114 for (unsigned i = 0; i < NumT1Ptrs; ++i)
115 EmitPtr(Ptrs[i]);
116
117 EmitPtr(p2);
118
119 for (unsigned i = 0; i < NumT1Ptrs; ++i)
120 if (Ptrs[i]) SerializeTrait::Emit(*this,*Ptrs[i]);
121
122 if (p2) SerializeTrait::Emit(*this,*p2);
123 }
124
125 template
126 void BatchEmitOwnedPtrs(unsigned NumT1Ptrs, T1* const * Ptrs,
127 T2* p2, T3* p3) {
128
129 for (unsigned i = 0; i < NumT1Ptrs; ++i)
130 EmitPtr(Ptrs[i]);
131
132 EmitPtr(p2);
133 EmitPtr(p3);
134
135 for (unsigned i = 0; i < NumT1Ptrs; ++i)
136 if (Ptrs[i]) SerializeTrait::Emit(*this,*Ptrs[i]);
137
138 if (p2) SerializeTrait::Emit(*this,*p2);
139 if (p3) SerializeTrait::Emit(*this,*p3);
140 }
141
142 //==------------------------------------------------==//
143 // Emitter Functors
144 //==------------------------------------------------==//
145
146 template
147 struct Emitter0 {
148 Serializer& S;
149 Emitter0(Serializer& s) : S(s) {}
150 void operator()(const T& x) const {
151 SerializeTrait::Emit(S,x);
152 }
153 };
154
155 template
156 struct Emitter1 {
157 Serializer& S;
158 Arg1 A1;
159
160 Emitter1(Serializer& s, Arg1 a1) : S(s), A1(a1) {}
161 void operator()(const T& x) const {
162 SerializeTrait::Emit(S,x,A1);
163 }
164 };
165
166 template
167 struct Emitter2 {
168 Serializer& S;
169 Arg1 A1;
170 Arg2 A2;
171
172 Emitter2(Serializer& s, Arg1 a1, Arg2 a2) : S(s), A1(a1), A2(a2) {}
173 void operator()(const T& x) const {
174 SerializeTrait::Emit(S,x,A1,A2);
175 }
176 };
177
178 template
179 Emitter0 MakeEmitter() {
180 return Emitter0(*this);
181 }
182
183 template
184 Emitter1 MakeEmitter(Arg1 a1) {
185 return Emitter1(*this,a1);
186 }
187
188 template
189 Emitter2 MakeEmitter(Arg1 a1, Arg2 a2) {
190 return Emitter2(*this,a1,a2);
191 }
192
193 //==------------------------------------------------==//
194 // Misc. query and block/record manipulation methods.
195 //==------------------------------------------------==//
196
197 bool isRegistered(const void* p) const;
198
199 void FlushRecord() { if (inRecord()) EmitRecord(); }
200 void EnterBlock(unsigned BlockID = 8, unsigned CodeLen = 3);
201 void ExitBlock();
202
203 private:
204 void EmitRecord();
205 inline bool inRecord() { return Record.size() > 0; }
206 SerializedPtrID getPtrId(const void* ptr);
207 };
208
209 } // end namespace llvm
210 #endif
0 add_llvm_library(LLVMBitReader
11 BitReader.cpp
22 BitcodeReader.cpp
3 Deserialize.cpp
4 DeserializeAPFloat.cpp
5 DeserializeAPInt.cpp
6 )
3 )
+0
-450
lib/Bitcode/Reader/Deserialize.cpp less more
None //==- Deserialize.cpp - Generic Object Serialization to Bitcode --*- C++ -*-==//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines the internal methods used for object serialization.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #include "llvm/Bitcode/Deserialize.h"
14 #include "llvm/Support/raw_ostream.h"
15 using namespace llvm;
16
17 Deserializer::Deserializer(BitstreamReader& stream)
18 : Stream(stream), RecIdx(0), FreeList(NULL), AbbrevNo(0), RecordCode(0) {
19
20 StreamStart = Stream.GetCurrentBitNo();
21 }
22
23 Deserializer::~Deserializer() {
24 assert (RecIdx >= Record.size() &&
25 "Still scanning bitcode record when deserialization completed.");
26
27 #ifdef DEBUG_BACKPATCH
28 for (MapTy::iterator I=BPatchMap.begin(), E=BPatchMap.end(); I!=E; ++I)
29 assert (I->first.hasFinalPtr() &&
30 "Some pointers were not backpatched.");
31 #endif
32 }
33
34
35 bool Deserializer::inRecord() {
36 if (Record.size() > 0) {
37 if (RecIdx >= Record.size()) {
38 RecIdx = 0;
39 Record.clear();
40 AbbrevNo = 0;
41 return false;
42 }
43 else
44 return true;
45 }
46
47 return false;
48 }
49
50 bool Deserializer::AdvanceStream() {
51 assert (!inRecord() &&
52 "Cannot advance stream. Still processing a record.");
53
54 if (AbbrevNo == bitc::ENTER_SUBBLOCK ||
55 AbbrevNo >= bitc::UNABBREV_RECORD)
56 return true;
57
58 while (!Stream.AtEndOfStream()) {
59
60 uint64_t Pos = Stream.GetCurrentBitNo();
61 AbbrevNo = Stream.ReadCode();
62
63 switch (AbbrevNo) {
64 case bitc::ENTER_SUBBLOCK: {
65 unsigned id = Stream.ReadSubBlockID();
66
67 // Determine the extent of the block. This is useful for jumping around
68 // the stream. This is hack: we read the header of the block, save
69 // the length, and then revert the bitstream to a location just before
70 // the block is entered.
71 uint64_t BPos = Stream.GetCurrentBitNo();
72 Stream.ReadVBR(bitc::CodeLenWidth); // Skip the code size.
73 Stream.SkipToWord();
74 unsigned NumWords = Stream.Read(bitc::BlockSizeWidth);
75 Stream.JumpToBit(BPos);
76
77 BlockStack.push_back(Location(Pos,id,NumWords));
78 break;
79 }
80
81 case bitc::END_BLOCK: {
82 bool x = Stream.ReadBlockEnd();
83 assert(!x && "Error at block end."); x=x;
84 BlockStack.pop_back();
85 continue;
86 }
87
88 case bitc::DEFINE_ABBREV:
89 Stream.ReadAbbrevRecord();
90 continue;
91
92 default:
93 break;
94 }
95
96 return true;
97 }
98
99 return false;
100 }
101
102 void Deserializer::ReadRecord() {
103
104 while (AdvanceStream() && AbbrevNo == bitc::ENTER_SUBBLOCK) {
105 assert (!BlockStack.empty());
106 Stream.EnterSubBlock(BlockStack.back().BlockID);
107 AbbrevNo = 0;
108 }
109
110 if (Stream.AtEndOfStream())
111 return;
112
113 assert (Record.empty());
114 assert (AbbrevNo >= bitc::UNABBREV_RECORD);
115 RecordCode = Stream.ReadRecord(AbbrevNo,Record);
116 assert (Record.size() > 0);
117 }
118
119 void Deserializer::SkipBlock() {
120 assert (!inRecord());
121
122 if (AtEnd())
123 return;
124
125 AdvanceStream();
126
127 assert (AbbrevNo == bitc::ENTER_SUBBLOCK);
128 BlockStack.pop_back();
129 Stream.SkipBlock();
130
131 AbbrevNo = 0;
132 AdvanceStream();
133 }
134
135 bool Deserializer::SkipToBlock(unsigned BlockID) {
136 assert (!inRecord());
137
138 AdvanceStream();
139 assert (AbbrevNo == bitc::ENTER_SUBBLOCK);
140
141 unsigned BlockLevel = BlockStack.size();
142
143 while (!AtEnd() &&
144 BlockLevel == BlockStack.size() &&
145 getCurrentBlockID() != BlockID)
146 SkipBlock();
147
148 return !(AtEnd() || BlockLevel != BlockStack.size());
149 }
150
151 Deserializer::Location Deserializer::getCurrentBlockLocation() {
152 if (!inRecord())
153 AdvanceStream();
154
155 return BlockStack.back();
156 }
157
158 bool Deserializer::JumpTo(const Location& Loc) {
159
160 assert (!inRecord());
161
162 AdvanceStream();
163
164 assert (!BlockStack.empty() || AtEnd());
165
166 uint64_t LastBPos = StreamStart;
167
168 while (!BlockStack.empty()) {
169
170 LastBPos = BlockStack.back().BitNo;
171
172 // Determine of the current block contains the location of the block
173 // we are looking for.
174 if (BlockStack.back().contains(Loc)) {
175 // We found the enclosing block. We must first POP it off to
176 // destroy any accumulated context within the block scope. We then
177 // jump to the position of the block and enter it.
178 Stream.JumpToBit(LastBPos);
179
180 if (BlockStack.size() == Stream.BlockScope.size())
181 Stream.PopBlockScope();
182
183 BlockStack.pop_back();
184
185 AbbrevNo = 0;
186 AdvanceStream();
187 assert (AbbrevNo == bitc::ENTER_SUBBLOCK);
188
189 Stream.EnterSubBlock(BlockStack.back().BlockID);
190 break;
191 }
192
193 // This block does not contain the block we are looking for. Pop it.
194 if (BlockStack.size() == Stream.BlockScope.size())
195 Stream.PopBlockScope();
196
197 BlockStack.pop_back();
198
199 }
200
201 // Check if we have popped our way to the outermost scope. If so,
202 // we need to adjust our position.
203 if (BlockStack.empty()) {
204 assert (Stream.BlockScope.empty());
205
206 Stream.JumpToBit(Loc.BitNo < LastBPos ? StreamStart : LastBPos);
207 AbbrevNo = 0;
208 AdvanceStream();
209 }
210
211 assert (AbbrevNo == bitc::ENTER_SUBBLOCK);
212 assert (!BlockStack.empty());
213
214 while (!AtEnd() && BlockStack.back() != Loc) {
215 if (BlockStack.back().contains(Loc)) {
216 Stream.EnterSubBlock(BlockStack.back().BlockID);
217 AbbrevNo = 0;
218 AdvanceStream();
219 continue;
220 }
221 else
222 SkipBlock();
223 }
224
225 if (AtEnd())
226 return false;
227
228 assert (BlockStack.back() == Loc);
229
230 return true;
231 }
232
233 void Deserializer::Rewind() {
234 while (!Stream.BlockScope.empty())
235 Stream.PopBlockScope();
236
237 while (!BlockStack.empty())
238 BlockStack.pop_back();
239
240 Stream.JumpToBit(StreamStart);
241 AbbrevNo = 0;
242 }
243
244
245 unsigned Deserializer::getCurrentBlockID() {
246 if (!inRecord())
247 AdvanceStream();
248
249 return BlockStack.back().BlockID;
250 }
251
252 unsigned Deserializer::getRecordCode() {
253 if (!inRecord()) {
254 AdvanceStream();
255 assert (AbbrevNo >= bitc::UNABBREV_RECORD);
256 ReadRecord();
257 }
258
259 return RecordCode;
260 }
261
262 bool Deserializer::FinishedBlock(Location BlockLoc) {
263 if (!inRecord())
264 AdvanceStream();
265
266 for (llvm::SmallVector::reverse_iterator
267 I=BlockStack.rbegin(), E=BlockStack.rend(); I!=E; ++I)
268 if (*I == BlockLoc)
269 return false;
270
271 return true;
272 }
273
274 unsigned Deserializer::getAbbrevNo() {
275 if (!inRecord())
276 AdvanceStream();
277
278 return AbbrevNo;
279 }
280
281 bool Deserializer::AtEnd() {
282 if (inRecord())
283 return false;
284
285 if (!AdvanceStream())
286 return true;
287
288 return false;
289 }
290
291 uint64_t Deserializer::ReadInt() {
292 // FIXME: Any error recovery/handling with incomplete or bad files?
293 if (!inRecord())
294 ReadRecord();
295
296 return Record[RecIdx++];
297 }
298
299 int64_t Deserializer::ReadSInt() {
300 uint64_t x = ReadInt();
301 int64_t magnitude = x >> 1;
302 return x & 0x1 ? -magnitude : magnitude;
303 }
304
305 char* Deserializer::ReadCStr(char* cstr, unsigned MaxLen, bool isNullTerm) {
306 if (cstr == NULL)
307 MaxLen = 0; // Zero this just in case someone does something funny.
308
309 unsigned len = ReadInt();
310
311 assert (MaxLen == 0 || (len + (isNullTerm ? 1 : 0)) <= MaxLen);
312
313 if (!cstr)
314 cstr = new char[len + (isNullTerm ? 1 : 0)];
315
316 assert (cstr != NULL);
317
318 for (unsigned i = 0; i < len; ++i)
319 cstr[i] = (char) ReadInt();
320
321 if (isNullTerm)
322 cstr[len] = '\0';
323
324 return cstr;
325 }
326
327 void Deserializer::ReadCStr(std::vector& buff, bool isNullTerm,
328 unsigned Idx) {
329
330 unsigned len = ReadInt();
331
332 // If Idx is beyond the current before size, reduce Idx to refer to the
333 // element after the last element.
334 if (Idx > buff.size())
335 Idx = buff.size();
336
337 buff.reserve(len+Idx);
338 buff.resize(Idx);
339
340 for (unsigned i = 0; i < len; ++i)
341 buff.push_back((char) ReadInt());
342
343 if (isNullTerm)
344 buff.push_back('\0');
345 }
346
347 void Deserializer::RegisterPtr(const SerializedPtrID& PtrId,
348 const void* Ptr) {
349
350 MapTy::value_type& E = BPatchMap.FindAndConstruct(BPKey(PtrId));
351
352 assert (!HasFinalPtr(E) && "Pointer already registered.");
353
354 #ifdef DEBUG_BACKPATCH
355 dbgs() << "RegisterPtr: " << PtrId << " => " << Ptr << "\n";
356 #endif
357
358 SetPtr(E,Ptr);
359 }
360
361 void Deserializer::ReadUIntPtr(uintptr_t& PtrRef,
362 const SerializedPtrID& PtrId,
363 bool AllowBackpatch) {
364 if (PtrId == 0) {
365 PtrRef = 0;
366 return;
367 }
368
369 MapTy::value_type& E = BPatchMap.FindAndConstruct(BPKey(PtrId));
370
371 if (HasFinalPtr(E)) {
372 PtrRef = GetFinalPtr(E);
373
374 #ifdef DEBUG_BACKPATCH
375 dbgs() << "ReadUintPtr: " << PtrId
376 << " <-- " << (void*) GetFinalPtr(E) << '\n';
377 #endif
378 }
379 else {
380 assert (AllowBackpatch &&
381 "Client forbids backpatching for this pointer.");
382
383 #ifdef DEBUG_BACKPATCH
384 dbgs() << "ReadUintPtr: " << PtrId << " (NO PTR YET)\n";
385 #endif
386
387 // Register backpatch. Check the freelist for a BPNode.
388 BPNode* N;
389
390 if (FreeList) {
391 N = FreeList;
392 FreeList = FreeList->Next;
393 }
394 else // No available BPNode. Allocate one.
395 N = (BPNode*) Allocator.Allocate();
396
397 new (N) BPNode(GetBPNode(E),PtrRef);
398 SetBPNode(E,N);
399 }
400 }
401
402 uintptr_t Deserializer::ReadInternalRefPtr() {
403 SerializedPtrID PtrId = ReadPtrID();
404
405 assert (PtrId != 0 && "References cannot refer the NULL address.");
406
407 MapTy::value_type& E = BPatchMap.FindAndConstruct(BPKey(PtrId));
408
409 assert (HasFinalPtr(E) &&
410 "Cannot backpatch references. Object must be already deserialized.");
411
412 return GetFinalPtr(E);
413 }
414
415 void BPEntry::SetPtr(BPNode*& FreeList, void* P) {
416 BPNode* Last = NULL;
417
418 for (BPNode* N = Head; N != NULL; N=N->Next) {
419 Last = N;
420 N->PtrRef |= reinterpret_cast(P);
421 }
422
423 if (Last) {
424 Last->Next = FreeList;
425 FreeList = Head;
426 }
427
428 Ptr = const_cast(P);
429 }
430
431
432 #define INT_READ(TYPE)\
433 void SerializeTrait::Read(Deserializer& D, TYPE& X) {\
434 X = (TYPE) D.ReadInt(); }
435
436 INT_READ(bool)
437 INT_READ(unsigned char)
438 INT_READ(unsigned short)
439 INT_READ(unsigned int)
440 INT_READ(unsigned long)
441
442 #define SINT_READ(TYPE)\
443 void SerializeTrait::Read(Deserializer& D, TYPE& X) {\
444 X = (TYPE) D.ReadSInt(); }
445
446 INT_READ(signed char)
447 INT_READ(signed short)
448 INT_READ(signed int)
449 INT_READ(signed long)
+0
-24
lib/Bitcode/Reader/DeserializeAPFloat.cpp less more
None //===-- SerializeAPInt.cpp - Serialization for APFloat ---------*- C++ -*--===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements deserialization of APFloat.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #include "llvm/ADT/APFloat.h"
14 #include "llvm/Bitcode/Deserialize.h"
15
16 using namespace llvm;
17
18 APFloat APFloat::ReadVal(Deserializer& D) {
19 APInt x;
20 D.Read(x);
21 return APFloat(x);
22 }
23
+0
-33
lib/Bitcode/Reader/DeserializeAPInt.cpp less more
None //===-- DeserializeAPInt.cpp - Deserialization for APInts ------*- C++ -*--===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements deserialization of APInts.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #include "llvm/ADT/APInt.h"
14 #include "llvm/Bitcode/Deserialize.h"
15 #include
16
17 using namespace llvm;
18
19 void APInt::Read(Deserializer& D) {
20 BitWidth = D.ReadInt();
21
22 if (isSingleWord())
23 VAL = D.ReadInt();
24 else {
25 uint32_t NumWords = D.ReadInt();
26 assert (NumWords > 1);
27 pVal = new uint64_t[NumWords];
28 assert (pVal && "Allocation in deserialization of APInt failed.");
29 for (unsigned i = 0; i < NumWords; ++i)
30 pVal[i] = D.ReadInt();
31 }
32 }
11 BitWriter.cpp
22 BitcodeWriter.cpp
33 BitcodeWriterPass.cpp
4 Serialize.cpp
5 SerializeAPFloat.cpp
6 SerializeAPInt.cpp
74 ValueEnumerator.cpp
85 )
+0
-115
lib/Bitcode/Writer/Serialize.cpp less more
None //==- Serialize.cpp - Generic Object Serialization to Bitcode ----*- C++ -*-==//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines the internal methods used for object serialization.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #include "llvm/Bitcode/Serialize.h"
14 #include "llvm/Support/raw_ostream.h"
15 #include
16
17 using namespace llvm;
18
19 Serializer::Serializer(BitstreamWriter& stream)
20 : Stream(stream), BlockLevel(0) {}
21
22 Serializer::~Serializer() {
23 if (inRecord())
24 EmitRecord();
25
26 while (BlockLevel > 0)
27 Stream.ExitBlock();
28
29 Stream.FlushToWord();
30 }
31
32 void Serializer::EmitRecord() {
33 assert(Record.size() > 0 && "Cannot emit empty record.");
34 Stream.EmitRecord(8,Record);
35 Record.clear();
36 }
37
38 void Serializer::EnterBlock(unsigned BlockID,unsigned CodeLen) {
39 FlushRecord();
40 Stream.EnterSubblock(BlockID,CodeLen);
41 ++BlockLevel;
42 }
43
44 void Serializer::ExitBlock() {
45 assert (BlockLevel > 0);
46 --BlockLevel;
47 FlushRecord();
48 Stream.ExitBlock();
49 }
50
51 void Serializer::EmitInt(uint64_t X) {
52 assert (BlockLevel > 0);
53 Record.push_back(X);
54 }
55
56 void Serializer::EmitSInt(int64_t X) {
57 if (X >= 0)
58 EmitInt(X << 1);
59 else
60 EmitInt((-X << 1) | 1);
61 }
62
63 void Serializer::EmitCStr(const char* s, const char* end) {
64 Record.push_back(end - s);
65
66 while(s != end) {
67 Record.push_back(*s);
68 ++s;
69 }
70 }
71
72 void Serializer::EmitCStr(const char* s) {
73 EmitCStr(s,s+strlen(s));
74 }
75
76 SerializedPtrID Serializer::getPtrId(const void* ptr) {
77 if (!ptr)
78 return 0;
79
80 MapTy::iterator I = PtrMap.find(ptr);
81
82 if (I == PtrMap.end()) {
83 unsigned id = PtrMap.size()+1;
84 #ifdef DEBUG_BACKPATCH
85 dbgs() << "Registered PTR: " << ptr << " => " << id << "\n";
86 #endif
87 PtrMap[ptr] = id;
88 return id;
89 }
90 else return I->second;
91 }
92
93 bool Serializer::isRegistered(const void* ptr) const {
94 MapTy::const_iterator I = PtrMap.find(ptr);
95 return I != PtrMap.end();
96 }
97
98
99 #define INT_EMIT(TYPE)\
100 void SerializeTrait::Emit(Serializer&S, TYPE X) { S.EmitInt(X); }
101
102 INT_EMIT(bool)
103 INT_EMIT(unsigned char)
104 INT_EMIT(unsigned short)
105 INT_EMIT(unsigned int)
106 INT_EMIT(unsigned long)
107
108 #define SINT_EMIT(TYPE)\
109 void SerializeTrait::Emit(Serializer&S, TYPE X) { S.EmitSInt(X); }
110
111 SINT_EMIT(signed char)
112 SINT_EMIT(signed short)
113 SINT_EMIT(signed int)
114 SINT_EMIT(signed long)
+0
-21
lib/Bitcode/Writer/SerializeAPFloat.cpp less more
None //===-- SerializeAPInt.cpp - Serialization for APFloat ---------*- C++ -*--===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements serialization of APFloat.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #include "llvm/ADT/APFloat.h"
14 #include "llvm/Bitcode/Serialize.h"
15
16 using namespace llvm;
17
18 void APFloat::Emit(Serializer& S) const {
19 S.Emit(bitcastToAPInt());
20 }
+0
-31
lib/Bitcode/Writer/SerializeAPInt.cpp less more
None //===-- SerializeAPInt.cpp - Serialization for APInts ----------*- C++ -*--===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements serialization of APInts.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #include "llvm/ADT/APInt.h"
14 #include "llvm/Bitcode/Serialize.h"
15 #include
16
17 using namespace llvm;
18
19 void APInt::Emit(Serializer& S) const {
20 S.EmitInt(BitWidth);
21
22 if (isSingleWord())
23 S.EmitInt(VAL);
24 else {
25 uint32_t NumWords = getNumWords();
26 S.EmitInt(NumWords);
27 for (unsigned i = 0; i < NumWords; ++i)
28 S.EmitInt(pVal[i]);
29 }
30 }