[ARM] Split large truncating MVE stores
[llvm-complete.git] / lib / DebugInfo / CodeView / SymbolSerializer.cpp
blobde9bb42b17987336f85559369a117ef6cb720769
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/DebugInfo/CodeView/SymbolRecord.h"
12 #include "llvm/Support/Endian.h"
13 #include "llvm/Support/Error.h"
14 #include <cassert>
15 #include <cstdint>
16 #include <cstring>
18 using namespace llvm;
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!");
29 Writer.setOffset(0);
31 if (auto EC = writeRecordPrefix(Record.kind()))
32 return EC;
34 CurrentSymbol = Record.kind();
35 if (auto EC = Mapping.visitSymbolBegin(Record))
36 return EC;
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))
45 return EC;
47 uint32_t RecordEnd = Writer.getOffset();
48 uint16_t Length = RecordEnd - 2;
49 Writer.setOffset(0);
50 if (auto EC = Writer.writeInteger(Length))
51 return EC;
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();