44#define CV_TYPE(enum, val) {#enum, enum},
45#include "llvm/DebugInfo/CodeView/CodeViewTypes.def"
50#define TYPE_RECORD(ename, value, name) \
53#include "llvm/DebugInfo/CodeView/CodeViewTypes.def"
65template <
typename T,
typename TFlag>
69 return std::string(
"");
73 for (
const auto &Flag : Flags) {
77 SetFlags.push_back(Flag);
83 std::string FlagLabel;
85 for (
const auto &Flag : SetFlags) {
94 if (!FlagLabel.empty()) {
95 std::string LabelWithBraces(
" ( ");
96 LabelWithBraces += FlagLabel +
" )";
97 return LabelWithBraces;
102template <
typename T,
typename TEnum>
108 for (
const auto &EnumItem : EnumValues) {
109 if (EnumItem.Value ==
Value) {
110 Name = EnumItem.Name;
123 std::string AccessSpecifier = std::string(
125 std::string MemberAttrs(AccessSpecifier);
139struct MapOneMethodRecord {
140 explicit MapOneMethodRecord(
bool IsFromOverloadList)
141 : IsFromOverloadList(IsFromOverloadList) {}
143 Error operator()(CodeViewRecordIO &IO, OneMethodRecord &Method)
const {
144 std::string
Attrs = getMemberAttributes(
147 if (IsFromOverloadList) {
152 if (
Method.isIntroducingVirtual()) {
155 Method.VFTableOffset = -1;
157 if (!IsFromOverloadList)
164 bool IsFromOverloadList;
187 size_t BytesNeeded = Name.size() + UniqueName.
size() + 2;
188 if (BytesNeeded > BytesLeft) {
195 std::string UniqueB =
Twine(
"??@" + Hash +
"@").
str();
196 assert(UniqueB.size() == 36);
200 const size_t MaxTakeN = 4096;
201 size_t TakeN = std::min(MaxTakeN, BytesLeft - UniqueB.size() - 2) - 32;
203 std::string NameB = (Name.take_front(TakeN) + Hash).str();
232 assert(!TypeKind &&
"Already in a type mapping!");
233 assert(!MemberKind &&
"Already in a member mapping!");
238 std::optional<uint32_t> MaxLen;
239 if (CVR.
kind() != TypeLeafKind::LF_FIELDLIST &&
240 CVR.
kind() != TypeLeafKind::LF_METHODLIST)
242 error(IO.beginRecord(MaxLen));
243 TypeKind = CVR.
kind();
245 if (IO.isStreaming()) {
246 auto RecordKind = CVR.
kind();
248 std::string RecordKindName = std::string(
250 error(IO.mapInteger(RecordLen,
"Record length"));
251 error(IO.mapEnum(RecordKind,
"Record kind: " + RecordKindName));
257 if (IO.isStreaming())
264 assert(TypeKind &&
"Not in a type mapping!");
265 assert(!MemberKind &&
"Still in a member mapping!");
267 error(IO.endRecord());
274 assert(TypeKind &&
"Not in a type mapping!");
275 assert(!MemberKind &&
"Already in a member mapping!");
287 if (IO.isStreaming()) {
294 error(IO.mapEnum(
Record.Kind,
"Member kind: " + MemberKindName));
300 assert(TypeKind &&
"Not in a type mapping!");
301 assert(MemberKind &&
"Not in a member mapping!");
303 if (IO.isReading()) {
304 if (
auto EC = IO.skipPadding())
309 error(IO.endRecord());
314 std::string ModifierNames =
322Error TypeRecordMapping::visitKnownRecord(
CVType &CVR,
324 std::string CallingConvName = std::string(getEnumName(
326 std::string FuncOptionNames =
338Error TypeRecordMapping::visitKnownRecord(
CVType &CVR,
340 std::string CallingConvName = std::string(getEnumName(
342 std::string FuncOptionNames =
358 error(IO.mapVectorN<uint32_t>(
360 [](CodeViewRecordIO &IO, TypeIndex &
N) {
361 return IO.mapInteger(N,
"Argument");
367Error TypeRecordMapping::visitKnownRecord(
CVType &CVR,
369 error(IO.mapVectorN<uint32_t>(
371 [](CodeViewRecordIO &IO, TypeIndex &
N) {
372 return IO.mapInteger(N,
"Strings");
381 SmallString<128> Attr(
"Attrs: ");
383 if (IO.isStreaming()) {
384 std::string PtrType = std::string(getEnumName(
386 Attr +=
"[ Type: " + PtrType;
388 std::string PtrMode = std::string(getEnumName(
390 Attr +=
", Mode: " + PtrMode;
392 auto PtrSizeOf = Record.
getSize();
393 Attr +=
", SizeOf: " +
itostr(PtrSizeOf);
400 Attr +=
", isVolatile";
402 Attr +=
", isUnaligned";
404 Attr +=
", isRestricted";
406 Attr +=
", isThisPtr&";
408 Attr +=
", isThisPtr&&";
420 error(IO.mapInteger(
M.ContainingType,
"ClassType"));
421 std::string PtrMemberGetRepresentation = std::string(getEnumName(
423 error(IO.mapEnum(
M.Representation,
424 "Representation: " + PtrMemberGetRepresentation));
433 error(IO.mapEncodedInteger(Record.
Size,
"SizeOf"));
434 error(IO.mapStringZ(Record.
Name,
"Name"));
440 assert((CVR.
kind() == TypeLeafKind::LF_STRUCTURE) ||
441 (CVR.
kind() == TypeLeafKind::LF_CLASS) ||
442 (CVR.
kind() == TypeLeafKind::LF_INTERFACE));
444 std::string PropertiesNames =
445 getFlagNames(IO,
static_cast<uint16_t
>(Record.
Options),
448 error(IO.mapEnum(Record.
Options,
"Properties" + PropertiesNames));
452 error(IO.mapEncodedInteger(Record.
Size,
"SizeOf"));
460 std::string PropertiesNames =
461 getFlagNames(IO,
static_cast<uint16_t
>(Record.
Options),
464 error(IO.mapEnum(Record.
Options,
"Properties" + PropertiesNames));
466 error(IO.mapEncodedInteger(Record.
Size,
"SizeOf"));
474 std::string PropertiesNames =
475 getFlagNames(IO,
static_cast<uint16_t
>(Record.
Options),
478 error(IO.mapEnum(Record.
Options,
"Properties" + PropertiesNames));
488 error(IO.mapInteger(Record.
Type,
"Type"));
495Error TypeRecordMapping::visitKnownRecord(
CVType &CVR,
498 if (!IO.isReading()) {
499 ArrayRef<VFTableSlotKind> Slots = Record.
getSlots();
501 error(IO.mapInteger(
Size,
"VFEntryCount"));
503 for (
size_t SlotIndex = 0; SlotIndex < Slots.
size(); SlotIndex += 2) {
504 uint8_t
Byte =
static_cast<uint8_t
>(Slots[SlotIndex]) << 4;
505 if ((SlotIndex + 1) < Slots.
size()) {
506 Byte |=
static_cast<uint8_t
>(Slots[SlotIndex + 1]);
512 for (uint16_t
I = 0;
I <
Size;
I += 2) {
528 uint32_t NamesLen = 0;
529 if (!IO.isReading()) {
531 NamesLen +=
Name.size() + 1;
533 error(IO.mapInteger(NamesLen));
534 error(IO.mapVectorTail(
536 [](CodeViewRecordIO &IO, StringRef &S) {
537 return IO.mapStringZ(S,
"MethodName");
545 error(IO.mapInteger(Record.
Id,
"Id"));
551Error TypeRecordMapping::visitKnownRecord(
CVType &CVR,
553 error(IO.mapInteger(Record.
UDT,
"UDT"));
560Error TypeRecordMapping::visitKnownRecord(
CVType &CVR,
562 error(IO.mapInteger(Record.
UDT,
"UDT"));
573 error(IO.mapStringZ(Record.
Name,
"Name"));
578Error TypeRecordMapping::visitKnownRecord(
CVType &CVR,
582 error(IO.mapStringZ(Record.
Name,
"Name"));
587Error TypeRecordMapping::visitKnownRecord(
CVType &CVR,
589 error(IO.mapVectorN<uint16_t>(
591 [](CodeViewRecordIO &IO, TypeIndex &
N) {
592 return IO.mapInteger(N,
"Argument");
599Error TypeRecordMapping::visitKnownRecord(
CVType &CVR,
603 error(IO.mapVectorTail(Record.
Methods, MapOneMethodRecord(
true),
"Method"));
608Error TypeRecordMapping::visitKnownRecord(
CVType &CVR,
610 if (IO.isStreaming()) {
614 error(IO.mapByteVectorTail(Record.
Data));
619Error TypeRecordMapping::visitKnownRecord(
CVType &CVR,
622 error(IO.mapInteger(Record.
Age,
"Age"));
623 error(IO.mapStringZ(Record.
Name,
"Name"));
628 std::string ModeName = std::string(
630 error(IO.mapEnum(Record.
Mode,
"Mode: " + ModeName));
636 std::string
Attrs = getMemberAttributes(
639 error(IO.mapInteger(Record.
Type,
"BaseType"));
640 error(IO.mapEncodedInteger(Record.
Offset,
"BaseOffset"));
647 std::string
Attrs = getMemberAttributes(
652 error(IO.mapEncodedInteger(Record.
Value,
"EnumValue"));
653 error(IO.mapStringZ(Record.
Name,
"Name"));
660 std::string
Attrs = getMemberAttributes(
663 error(IO.mapInteger(Record.
Type,
"Type"));
665 error(IO.mapStringZ(Record.
Name,
"Name"));
674 error(IO.mapStringZ(Record.
Name,
"Name"));
681 const bool IsFromOverloadList = (TypeKind == LF_METHODLIST);
682 MapOneMethodRecord Mapper(IsFromOverloadList);
683 return Mapper(IO, Record);
689 error(IO.mapInteger(Padding,
"Padding"));
690 error(IO.mapInteger(Record.
Type,
"Type"));
691 error(IO.mapStringZ(Record.
Name,
"Name"));
699 std::string
Attrs = getMemberAttributes(
702 error(IO.mapInteger(Record.
Type,
"Type"));
703 error(IO.mapStringZ(Record.
Name,
"Name"));
711 std::string
Attrs = getMemberAttributes(
725 error(IO.mapInteger(Padding,
"Padding"));
726 error(IO.mapInteger(Record.
Type,
"Type"));
734 error(IO.mapInteger(Padding,
"Padding"));
740Error TypeRecordMapping::visitKnownRecord(
CVType &CVR,
749Error TypeRecordMapping::visitKnownRecord(
CVType &CVR,
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static constexpr uint32_t ContinuationLength
This file defines the SmallString class.
This file defines the SmallVector class.
static StringRef getLeafTypeName(TypeLeafKind LT)
static const EnumEntry< TypeLeafKind > LeafTypeNames[]
static void computeHashString(StringRef Name, SmallString< 32 > &StringifiedHash)
static Error mapNameAndUniqueName(CodeViewRecordIO &IO, StringRef &Name, StringRef &UniqueName, bool HasUniqueName)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
LLVM_ABI void update(ArrayRef< uint8_t > Data)
Updates the hash for the byte stream provided.
static LLVM_ABI void stringifyResult(MD5Result &Result, SmallVectorImpl< char > &Str)
Translates the bytes in Res to a hex string that is deposited into Str.
LLVM_ABI void final(MD5Result &Result)
Finishes off the hash and puts the result in result.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
constexpr size_t size() const
size - Get the string size.
StringRef take_front(size_t N=1) const
Return a StringRef equal to 'this' but with only the first N elements remaining.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
LLVM_ABI std::string str() const
Return the twine contents as a std::string.
LLVM Value Representation.
std::vector< TypeIndex > ArgIndices
MemberAccess getAccess() const
SmallVector< TypeIndex, MaxArgs > ArgIndices
LLVM_ABI Error mapInteger(TypeIndex &TypeInd, const Twine &Comment="")
LLVM_ABI Error mapStringZ(StringRef &Value, const Twine &Comment="")
Error mapEnum(T &Value, const Twine &Comment="")
LLVM_ABI uint32_t maxFieldLength() const
MemberAccess getAccess() const
MemberAccess getAccess() const
LF_INDEX - Used to chain two large LF_FIELDLIST or LF_METHODLIST records together.
TypeIndex ContinuationIndex
std::vector< OneMethodRecord > Methods
For method overload sets. LF_METHOD.
bool isRValueReferenceThisPtr() const
std::optional< MemberPointerInfo > MemberInfo
bool isPointerToMember() const
bool isLValueReferenceThisPtr() const
PointerMode getMode() const
PointerKind getPointerKind() const
StringRef PrecompFilePath
MemberAccess getAccess() const
std::vector< TypeIndex > StringIndices
bool hasUniqueName() const
Error visitTypeBegin(CVType &Record) override
Paired begin/end actions for all types.
Error visitMemberBegin(CVMemberRecord &Record) override
Error visitTypeEnd(CVType &Record) override
Error visitMemberEnd(CVMemberRecord &Record) override
TypeIndex OverriddenVFTable
std::vector< StringRef > MethodNames
ArrayRef< VFTableSlotKind > getSlots() const
std::vector< VFTableSlotKind > Slots
MemberAccess getAccess() const
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
Flag
These should be considered private to the implementation of the MCInstrDesc class.
LLVM_ABI ArrayRef< EnumEntry< uint16_t > > getMethodOptionNames()
MethodKind
Part of member attribute flags. (CV_methodprop_e)
LLVM_ABI ArrayRef< EnumEntry< uint8_t > > getCallingConventions()
LLVM_ABI ArrayRef< EnumEntry< uint8_t > > getMemberAccessNames()
CVRecord< TypeLeafKind > CVType
LLVM_ABI ArrayRef< EnumEntry< uint8_t > > getPtrKindNames()
LLVM_ABI ArrayRef< EnumEntry< uint16_t > > getPtrMemberRepNames()
LLVM_ABI ArrayRef< EnumEntry< uint16_t > > getLabelTypeEnum()
LLVM_ABI Error visitMemberRecordStream(ArrayRef< uint8_t > FieldList, TypeVisitorCallbacks &Callbacks)
LLVM_ABI ArrayRef< EnumEntry< uint16_t > > getTypeModifierNames()
MethodOptions
Equivalent to CV_fldattr_t bitfield.
LLVM_ABI ArrayRef< EnumEntry< uint16_t > > getMemberKindNames()
MemberAccess
Source-level access specifier. (CV_access_e)
TypeLeafKind
Duplicate copy of the above enum, but using the official CV names.
LLVM_ABI ArrayRef< EnumEntry< uint8_t > > getPtrModeNames()
LLVM_ABI ArrayRef< EnumEntry< uint8_t > > getFunctionOptionEnum()
LLVM_ABI ArrayRef< EnumEntry< uint16_t > > getClassOptionNames()
This is an optimization pass for GlobalISel generic memory operations.
std::string utohexstr(uint64_t X, bool LowerCase=false, unsigned Width=0)
void sort(IteratorTy Start, IteratorTy End)
ArrayRef(const T &OneElt) -> ArrayRef< T >
std::string itostr(int64_t X)