LLVM 20.0.0git
SymbolSerializer.cpp
Go to the documentation of this file.
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//===----------------------------------------------------------------------===//
8
10#include "llvm/ADT/ArrayRef.h"
11#include "llvm/Support/Error.h"
12#include <cassert>
13#include <cstdint>
14#include <cstring>
15
16using namespace llvm;
17using namespace llvm::codeview;
18
20 CodeViewContainer Container)
21 : Storage(Allocator), Stream(RecordBuffer, llvm::endianness::little),
22 Writer(Stream), Mapping(Writer, Container) {}
23
25 assert(!CurrentSymbol && "Already in a symbol mapping!");
26
27 Writer.setOffset(0);
28
29 if (auto EC = writeRecordPrefix(Record.kind()))
30 return EC;
31
32 CurrentSymbol = Record.kind();
33 if (auto EC = Mapping.visitSymbolBegin(Record))
34 return EC;
35
36 return Error::success();
37}
38
40 assert(CurrentSymbol && "Not in a symbol mapping!");
41
42 if (auto EC = Mapping.visitSymbolEnd(Record))
43 return EC;
44
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;
50
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();
55
56 return Error::success();
57}
Basic Register Allocator
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
Error writeInteger(T Value)
Write the integer Value to the underlying stream in the specified endianness.
void setOffset(uint64_t Off)
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:66
LLVM_ATTRIBUTE_RETURNS_NONNULL void * Allocate(size_t Size, Align Alignment)
Allocate space at the specified alignment.
Definition: Allocator.h:148
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
static ErrorSuccess success()
Create a success value.
Definition: Error.h:337
CVRecord is a fat pointer (base + size pair) to a symbol or type record.
Definition: CVRecord.h:29
Error visitSymbolEnd(CVSymbol &Record) override
Error visitSymbolBegin(CVSymbol &Record) override
Error visitSymbolBegin(CVSymbol &Record) override
SymbolSerializer(BumpPtrAllocator &Storage, CodeViewContainer Container)
Error visitSymbolEnd(CVSymbol &Record) override
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Length
Definition: DWP.cpp:480
endianness
Definition: bit.h:70