Path: blob/main/contrib/llvm-project/llvm/lib/DebugInfo/CodeView/SymbolSerializer.cpp
35271 views
//===- SymbolSerializer.cpp -----------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "llvm/DebugInfo/CodeView/SymbolSerializer.h"9#include "llvm/ADT/ArrayRef.h"10#include "llvm/Support/Error.h"11#include "llvm/Support/ErrorHandling.h"12#include <cassert>13#include <cstdint>14#include <cstring>1516using namespace llvm;17using namespace llvm::codeview;1819SymbolSerializer::SymbolSerializer(BumpPtrAllocator &Allocator,20CodeViewContainer Container)21: Storage(Allocator), Stream(RecordBuffer, llvm::endianness::little),22Writer(Stream), Mapping(Writer, Container) {}2324Error SymbolSerializer::visitSymbolBegin(CVSymbol &Record) {25assert(!CurrentSymbol && "Already in a symbol mapping!");2627Writer.setOffset(0);2829if (auto EC = writeRecordPrefix(Record.kind()))30return EC;3132CurrentSymbol = Record.kind();33if (auto EC = Mapping.visitSymbolBegin(Record))34return EC;3536return Error::success();37}3839Error SymbolSerializer::visitSymbolEnd(CVSymbol &Record) {40assert(CurrentSymbol && "Not in a symbol mapping!");4142if (auto EC = Mapping.visitSymbolEnd(Record))43return EC;4445uint32_t RecordEnd = Writer.getOffset();46uint16_t Length = RecordEnd - 2;47Writer.setOffset(0);48if (auto EC = Writer.writeInteger(Length))49return EC;5051uint8_t *StableStorage = Storage.Allocate<uint8_t>(RecordEnd);52::memcpy(StableStorage, &RecordBuffer[0], RecordEnd);53Record.RecordData = ArrayRef<uint8_t>(StableStorage, RecordEnd);54CurrentSymbol.reset();5556return Error::success();57}585960