1 //===- SymbolSerializer.cpp -----------------------------------------------===//
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 #include "llvm/DebugInfo/CodeView/SymbolSerializer.h"
10 #include "llvm/ADT/ArrayRef.h"
11 #include "llvm/DebugInfo/CodeView/SymbolRecord.h"
12 #include "llvm/Support/Endian.h"
13 #include "llvm/Support/Error.h"
19 using namespace llvm::codeview
;
21 SymbolSerializer::SymbolSerializer(BumpPtrAllocator
&Allocator
,
22 CodeViewContainer Container
)
23 : Storage(Allocator
), Stream(RecordBuffer
, support::little
), Writer(Stream
),
24 Mapping(Writer
, Container
) {}
26 Error
SymbolSerializer::visitSymbolBegin(CVSymbol
&Record
) {
27 assert(!CurrentSymbol
.hasValue() && "Already in a symbol mapping!");
31 if (auto EC
= writeRecordPrefix(Record
.kind()))
34 CurrentSymbol
= Record
.kind();
35 if (auto EC
= Mapping
.visitSymbolBegin(Record
))
38 return Error::success();
41 Error
SymbolSerializer::visitSymbolEnd(CVSymbol
&Record
) {
42 assert(CurrentSymbol
.hasValue() && "Not in a symbol mapping!");
44 if (auto EC
= Mapping
.visitSymbolEnd(Record
))
47 uint32_t RecordEnd
= Writer
.getOffset();
48 uint16_t Length
= RecordEnd
- 2;
50 if (auto EC
= Writer
.writeInteger(Length
))
53 uint8_t *StableStorage
= Storage
.Allocate
<uint8_t>(RecordEnd
);
54 ::memcpy(StableStorage
, &RecordBuffer
[0], RecordEnd
);
55 Record
.RecordData
= ArrayRef
<uint8_t>(StableStorage
, RecordEnd
);
56 CurrentSymbol
.reset();
58 return Error::success();