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/Support/Error.h"
17 using namespace llvm::codeview
;
19 SymbolSerializer::SymbolSerializer(BumpPtrAllocator
&Allocator
,
20 CodeViewContainer Container
)
21 : Storage(Allocator
), Stream(RecordBuffer
, llvm::endianness::little
),
22 Writer(Stream
), Mapping(Writer
, Container
) {}
24 Error
SymbolSerializer::visitSymbolBegin(CVSymbol
&Record
) {
25 assert(!CurrentSymbol
&& "Already in a symbol mapping!");
29 if (auto EC
= writeRecordPrefix(Record
.kind()))
32 CurrentSymbol
= Record
.kind();
33 if (auto EC
= Mapping
.visitSymbolBegin(Record
))
36 return Error::success();
39 Error
SymbolSerializer::visitSymbolEnd(CVSymbol
&Record
) {
40 assert(CurrentSymbol
&& "Not in a symbol mapping!");
42 if (auto EC
= Mapping
.visitSymbolEnd(Record
))
45 uint32_t RecordEnd
= Writer
.getOffset();
46 uint16_t Length
= RecordEnd
- 2;
48 if (auto EC
= Writer
.writeInteger(Length
))
51 uint8_t *StableStorage
= Storage
.Allocate
<uint8_t>(RecordEnd
);
52 ::memcpy(StableStorage
, &RecordBuffer
[0], RecordEnd
);
53 Record
.RecordData
= ArrayRef
<uint8_t>(StableStorage
, RecordEnd
);
54 CurrentSymbol
.reset();
56 return Error::success();