[IRBuilder] Add Align argument for CreateMaskedExpandLoad and CreateMaskedCompressSto...
[llvm-project.git] / llvm / lib / DebugInfo / CodeView / SymbolSerializer.cpp
blobfa798d7b242d83750b1e21b9d833e5c12d5fffa1
1 //===- SymbolSerializer.cpp -----------------------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
9 #include "llvm/DebugInfo/CodeView/SymbolSerializer.h"
10 #include "llvm/ADT/ArrayRef.h"
11 #include "llvm/Support/Error.h"
12 #include <cassert>
13 #include <cstdint>
14 #include <cstring>
16 using namespace llvm;
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!");
27 Writer.setOffset(0);
29 if (auto EC = writeRecordPrefix(Record.kind()))
30 return EC;
32 CurrentSymbol = Record.kind();
33 if (auto EC = Mapping.visitSymbolBegin(Record))
34 return EC;
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))
43 return EC;
45 uint32_t RecordEnd = Writer.getOffset();
46 uint16_t Length = RecordEnd - 2;
47 Writer.setOffset(0);
48 if (auto EC = Writer.writeInteger(Length))
49 return EC;
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();