1 //===- SymbolSerializer.cpp -----------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/DebugInfo/CodeView/SymbolSerializer.h"
11 #include "llvm/ADT/ArrayRef.h"
12 #include "llvm/DebugInfo/CodeView/SymbolRecord.h"
13 #include "llvm/Support/Endian.h"
14 #include "llvm/Support/Error.h"
20 using namespace llvm::codeview
;
22 SymbolSerializer::SymbolSerializer(BumpPtrAllocator
&Allocator
,
23 CodeViewContainer Container
)
24 : Storage(Allocator
), Stream(RecordBuffer
, support::little
), Writer(Stream
),
25 Mapping(Writer
, Container
) {}
27 Error
SymbolSerializer::visitSymbolBegin(CVSymbol
&Record
) {
28 assert(!CurrentSymbol
.hasValue() && "Already in a symbol mapping!");
32 if (auto EC
= writeRecordPrefix(Record
.kind()))
35 CurrentSymbol
= Record
.kind();
36 if (auto EC
= Mapping
.visitSymbolBegin(Record
))
39 return Error::success();
42 Error
SymbolSerializer::visitSymbolEnd(CVSymbol
&Record
) {
43 assert(CurrentSymbol
.hasValue() && "Not in a symbol mapping!");
45 if (auto EC
= Mapping
.visitSymbolEnd(Record
))
48 uint32_t RecordEnd
= Writer
.getOffset();
49 uint16_t Length
= RecordEnd
- 2;
51 if (auto EC
= Writer
.writeInteger(Length
))
54 uint8_t *StableStorage
= Storage
.Allocate
<uint8_t>(RecordEnd
);
55 ::memcpy(StableStorage
, &RecordBuffer
[0], RecordEnd
);
56 Record
.RecordData
= ArrayRef
<uint8_t>(StableStorage
, RecordEnd
);
57 CurrentSymbol
.reset();
59 return Error::success();