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"
13#include <cassert>
14#include <cstdint>
15#include <cstring>
16
17using namespace llvm;
18using namespace llvm::codeview;
19
21 CodeViewContainer Container)
22 : Storage(Allocator), Stream(RecordBuffer, llvm::endianness::little),
23 Writer(Stream), Mapping(Writer, Container) {}
24
26 assert(!CurrentSymbol && "Already in a symbol mapping!");
27
28 Writer.setOffset(0);
29
30 if (auto EC = writeRecordPrefix(Record.kind()))
31 return EC;
32
33 CurrentSymbol = Record.kind();
34 if (auto EC = Mapping.visitSymbolBegin(Record))
35 return EC;
36
37 return Error::success();
38}
39
41 assert(CurrentSymbol && "Not in a symbol mapping!");
42
43 if (auto EC = Mapping.visitSymbolEnd(Record))
44 return EC;
45
46 uint32_t RecordEnd = Writer.getOffset();
47 uint16_t Length = RecordEnd - 2;
48 Writer.setOffset(0);
49 if (auto EC = Writer.writeInteger(Length))
50 return EC;
51
52 uint8_t *StableStorage = Storage.Allocate<uint8_t>(RecordEnd);
53 ::memcpy(StableStorage, &RecordBuffer[0], RecordEnd);
54 Record.RecordData = ArrayRef<uint8_t>(StableStorage, RecordEnd);
55 CurrentSymbol.reset();
56
57 return Error::success();
58}
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