LCOV - code coverage report
Current view: top level - lib/ObjectYAML - CodeViewYAMLTypes.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 342 441 77.6 %
Date: 2018-02-18 16:14:26 Functions: 194 253 76.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- CodeViewYAMLTypes.cpp - CodeView YAMLIO types implementation -------===//
       2             : //
       3             : //                     The LLVM Compiler Infrastructure
       4             : //
       5             : // This file is distributed under the University of Illinois Open Source
       6             : // License. See LICENSE.TXT for details.
       7             : //
       8             : //===----------------------------------------------------------------------===//
       9             : //
      10             : // This file defines classes for handling the YAML representation of CodeView
      11             : // Debug Info.
      12             : //
      13             : //===----------------------------------------------------------------------===//
      14             : 
      15             : #include "llvm/ObjectYAML/CodeViewYAMLTypes.h"
      16             : #include "llvm/ADT/APSInt.h"
      17             : #include "llvm/ADT/ArrayRef.h"
      18             : #include "llvm/ADT/StringRef.h"
      19             : #include "llvm/BinaryFormat/COFF.h"
      20             : #include "llvm/DebugInfo/CodeView/AppendingTypeTableBuilder.h"
      21             : #include "llvm/DebugInfo/CodeView/CVTypeVisitor.h"
      22             : #include "llvm/DebugInfo/CodeView/CodeView.h"
      23             : #include "llvm/DebugInfo/CodeView/CodeViewError.h"
      24             : #include "llvm/DebugInfo/CodeView/ContinuationRecordBuilder.h"
      25             : #include "llvm/DebugInfo/CodeView/TypeDeserializer.h"
      26             : #include "llvm/DebugInfo/CodeView/TypeIndex.h"
      27             : #include "llvm/DebugInfo/CodeView/TypeVisitorCallbacks.h"
      28             : #include "llvm/Support/Allocator.h"
      29             : #include "llvm/Support/BinaryStreamReader.h"
      30             : #include "llvm/Support/BinaryStreamWriter.h"
      31             : #include "llvm/Support/Endian.h"
      32             : #include "llvm/Support/Error.h"
      33             : #include "llvm/Support/ErrorHandling.h"
      34             : #include "llvm/Support/YAMLTraits.h"
      35             : #include "llvm/Support/raw_ostream.h"
      36             : #include <algorithm>
      37             : #include <cassert>
      38             : #include <cstdint>
      39             : #include <vector>
      40             : 
      41             : using namespace llvm;
      42             : using namespace llvm::codeview;
      43             : using namespace llvm::CodeViewYAML;
      44             : using namespace llvm::CodeViewYAML::detail;
      45             : using namespace llvm::yaml;
      46             : 
      47             : LLVM_YAML_IS_SEQUENCE_VECTOR(OneMethodRecord)
      48             : LLVM_YAML_IS_SEQUENCE_VECTOR(VFTableSlotKind)
      49             : LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(TypeIndex)
      50             : 
      51             : LLVM_YAML_DECLARE_SCALAR_TRAITS(TypeIndex, QuotingType::None)
      52             : LLVM_YAML_DECLARE_SCALAR_TRAITS(APSInt, QuotingType::None)
      53             : 
      54             : LLVM_YAML_DECLARE_ENUM_TRAITS(TypeLeafKind)
      55             : LLVM_YAML_DECLARE_ENUM_TRAITS(PointerToMemberRepresentation)
      56             : LLVM_YAML_DECLARE_ENUM_TRAITS(VFTableSlotKind)
      57             : LLVM_YAML_DECLARE_ENUM_TRAITS(CallingConvention)
      58             : LLVM_YAML_DECLARE_ENUM_TRAITS(PointerKind)
      59             : LLVM_YAML_DECLARE_ENUM_TRAITS(PointerMode)
      60             : LLVM_YAML_DECLARE_ENUM_TRAITS(HfaKind)
      61             : LLVM_YAML_DECLARE_ENUM_TRAITS(MemberAccess)
      62             : LLVM_YAML_DECLARE_ENUM_TRAITS(MethodKind)
      63             : LLVM_YAML_DECLARE_ENUM_TRAITS(WindowsRTClassKind)
      64             : LLVM_YAML_DECLARE_ENUM_TRAITS(LabelType)
      65             : 
      66             : LLVM_YAML_DECLARE_BITSET_TRAITS(PointerOptions)
      67             : LLVM_YAML_DECLARE_BITSET_TRAITS(ModifierOptions)
      68             : LLVM_YAML_DECLARE_BITSET_TRAITS(FunctionOptions)
      69             : LLVM_YAML_DECLARE_BITSET_TRAITS(ClassOptions)
      70             : LLVM_YAML_DECLARE_BITSET_TRAITS(MethodOptions)
      71             : 
      72             : LLVM_YAML_DECLARE_MAPPING_TRAITS(OneMethodRecord)
      73             : LLVM_YAML_DECLARE_MAPPING_TRAITS(MemberPointerInfo)
      74             : 
      75             : namespace llvm {
      76             : namespace CodeViewYAML {
      77             : namespace detail {
      78             : 
      79             : struct LeafRecordBase {
      80             :   TypeLeafKind Kind;
      81             : 
      82        1878 :   explicit LeafRecordBase(TypeLeafKind K) : Kind(K) {}
      83             :   virtual ~LeafRecordBase() = default;
      84             : 
      85             :   virtual void map(yaml::IO &io) = 0;
      86             :   virtual CVType toCodeViewRecord(AppendingTypeTableBuilder &TS) const = 0;
      87             :   virtual Error fromCodeViewRecord(CVType Type) = 0;
      88             : };
      89             : 
      90        2032 : template <typename T> struct LeafRecordImpl : public LeafRecordBase {
      91        1664 :   explicit LeafRecordImpl(TypeLeafKind K)
      92        1664 :       : LeafRecordBase(K), Record(static_cast<TypeRecordKind>(K)) {}
      93             : 
      94             :   void map(yaml::IO &io) override;
      95             : 
      96         501 :   Error fromCodeViewRecord(CVType Type) override {
      97         501 :     return TypeDeserializer::deserializeAs<T>(Type, Record);
      98             :   }
      99             : 
     100        1108 :   CVType toCodeViewRecord(AppendingTypeTableBuilder &TS) const override {
     101        1108 :     TS.writeLeafType(Record);
     102        3324 :     return CVType(Kind, TS.records().back());
     103             :   }
     104             : 
     105             :   mutable T Record;
     106             : };
     107             : 
     108         214 : template <> struct LeafRecordImpl<FieldListRecord> : public LeafRecordBase {
     109         428 :   explicit LeafRecordImpl(TypeLeafKind K) : LeafRecordBase(K) {}
     110             : 
     111             :   void map(yaml::IO &io) override;
     112             :   CVType toCodeViewRecord(AppendingTypeTableBuilder &TS) const override;
     113             :   Error fromCodeViewRecord(CVType Type) override;
     114             : 
     115             :   std::vector<MemberRecord> Members;
     116             : };
     117             : 
     118             : struct MemberRecordBase {
     119             :   TypeLeafKind Kind;
     120             : 
     121        1291 :   explicit MemberRecordBase(TypeLeafKind K) : Kind(K) {}
     122             :   virtual ~MemberRecordBase() = default;
     123             : 
     124             :   virtual void map(yaml::IO &io) = 0;
     125             :   virtual void writeTo(ContinuationRecordBuilder &CRB) = 0;
     126             : };
     127             : 
     128        1998 : template <typename T> struct MemberRecordImpl : public MemberRecordBase {
     129        1291 :   explicit MemberRecordImpl(TypeLeafKind K)
     130        1291 :       : MemberRecordBase(K), Record(static_cast<TypeRecordKind>(K)) {}
     131             : 
     132             :   void map(yaml::IO &io) override;
     133             : 
     134         701 :   void writeTo(ContinuationRecordBuilder &CRB) override {
     135         701 :     CRB.writeMemberType(Record);
     136         701 :   }
     137             : 
     138             :   mutable T Record;
     139             : };
     140             : 
     141             : } // end namespace detail
     142             : } // end namespace CodeViewYAML
     143             : } // end namespace llvm
     144             : 
     145          10 : void ScalarTraits<GUID>::output(const GUID &G, void *, llvm::raw_ostream &OS) {
     146          10 :   OS << G;
     147          10 : }
     148             : 
     149          10 : StringRef ScalarTraits<GUID>::input(StringRef Scalar, void *Ctx, GUID &S) {
     150          10 :   if (Scalar.size() != 38)
     151           0 :     return "GUID strings are 38 characters long";
     152          20 :   if (Scalar[0] != '{' || Scalar[37] != '}')
     153           0 :     return "GUID is not enclosed in {}";
     154          40 :   if (Scalar[9] != '-' || Scalar[14] != '-' || Scalar[19] != '-' ||
     155             :       Scalar[24] != '-')
     156           0 :     return "GUID sections are not properly delineated with dashes";
     157             : 
     158          10 :   uint8_t *OutBuffer = S.Guid;
     159         230 :   for (auto Iter = Scalar.begin(); Iter != Scalar.end();) {
     160         280 :     if (*Iter == '-' || *Iter == '{' || *Iter == '}') {
     161          60 :       ++Iter;
     162          60 :       continue;
     163             :     }
     164         320 :     uint8_t Value = (llvm::hexDigitValue(*Iter++) << 4);
     165         320 :     Value |= llvm::hexDigitValue(*Iter++);
     166         160 :     *OutBuffer++ = Value;
     167             :   }
     168             : 
     169          10 :   return "";
     170             : }
     171             : 
     172        1524 : void ScalarTraits<TypeIndex>::output(const TypeIndex &S, void *,
     173             :                                      raw_ostream &OS) {
     174             :   OS << S.getIndex();
     175        1524 : }
     176             : 
     177        2954 : StringRef ScalarTraits<TypeIndex>::input(StringRef Scalar, void *Ctx,
     178             :                                          TypeIndex &S) {
     179             :   uint32_t I;
     180        2954 :   StringRef Result = ScalarTraits<uint32_t>::input(Scalar, Ctx, I);
     181        2954 :   S.setIndex(I);
     182        2954 :   return Result;
     183             : }
     184             : 
     185         321 : void ScalarTraits<APSInt>::output(const APSInt &S, void *, raw_ostream &OS) {
     186         642 :   S.print(OS, S.isSigned());
     187         321 : }
     188             : 
     189         386 : StringRef ScalarTraits<APSInt>::input(StringRef Scalar, void *Ctx, APSInt &S) {
     190         772 :   S = APSInt(Scalar);
     191         386 :   return "";
     192             : }
     193             : 
     194        3169 : void ScalarEnumerationTraits<TypeLeafKind>::enumeration(IO &io,
     195             :                                                         TypeLeafKind &Value) {
     196             : #define CV_TYPE(name, val) io.enumCase(Value, #name, name);
     197             : #include "llvm/DebugInfo/CodeView/CodeViewTypes.def"
     198             : #undef CV_TYPE
     199        3169 : }
     200             : 
     201           0 : void ScalarEnumerationTraits<PointerToMemberRepresentation>::enumeration(
     202             :     IO &IO, PointerToMemberRepresentation &Value) {
     203           0 :   IO.enumCase(Value, "Unknown", PointerToMemberRepresentation::Unknown);
     204           0 :   IO.enumCase(Value, "SingleInheritanceData",
     205             :               PointerToMemberRepresentation::SingleInheritanceData);
     206           0 :   IO.enumCase(Value, "MultipleInheritanceData",
     207             :               PointerToMemberRepresentation::MultipleInheritanceData);
     208           0 :   IO.enumCase(Value, "VirtualInheritanceData",
     209             :               PointerToMemberRepresentation::VirtualInheritanceData);
     210           0 :   IO.enumCase(Value, "GeneralData", PointerToMemberRepresentation::GeneralData);
     211           0 :   IO.enumCase(Value, "SingleInheritanceFunction",
     212             :               PointerToMemberRepresentation::SingleInheritanceFunction);
     213           0 :   IO.enumCase(Value, "MultipleInheritanceFunction",
     214             :               PointerToMemberRepresentation::MultipleInheritanceFunction);
     215           0 :   IO.enumCase(Value, "VirtualInheritanceFunction",
     216             :               PointerToMemberRepresentation::VirtualInheritanceFunction);
     217           0 :   IO.enumCase(Value, "GeneralFunction",
     218             :               PointerToMemberRepresentation::GeneralFunction);
     219           0 : }
     220             : 
     221           7 : void ScalarEnumerationTraits<VFTableSlotKind>::enumeration(
     222             :     IO &IO, VFTableSlotKind &Kind) {
     223           7 :   IO.enumCase(Kind, "Near16", VFTableSlotKind::Near16);
     224           7 :   IO.enumCase(Kind, "Far16", VFTableSlotKind::Far16);
     225           7 :   IO.enumCase(Kind, "This", VFTableSlotKind::This);
     226           7 :   IO.enumCase(Kind, "Outer", VFTableSlotKind::Outer);
     227           7 :   IO.enumCase(Kind, "Meta", VFTableSlotKind::Meta);
     228           7 :   IO.enumCase(Kind, "Near", VFTableSlotKind::Near);
     229           7 :   IO.enumCase(Kind, "Far", VFTableSlotKind::Far);
     230           7 : }
     231             : 
     232         316 : void ScalarEnumerationTraits<CallingConvention>::enumeration(
     233             :     IO &IO, CallingConvention &Value) {
     234         316 :   IO.enumCase(Value, "NearC", CallingConvention::NearC);
     235         316 :   IO.enumCase(Value, "FarC", CallingConvention::FarC);
     236         316 :   IO.enumCase(Value, "NearPascal", CallingConvention::NearPascal);
     237         316 :   IO.enumCase(Value, "FarPascal", CallingConvention::FarPascal);
     238         316 :   IO.enumCase(Value, "NearFast", CallingConvention::NearFast);
     239         316 :   IO.enumCase(Value, "FarFast", CallingConvention::FarFast);
     240         316 :   IO.enumCase(Value, "NearStdCall", CallingConvention::NearStdCall);
     241         316 :   IO.enumCase(Value, "FarStdCall", CallingConvention::FarStdCall);
     242         316 :   IO.enumCase(Value, "NearSysCall", CallingConvention::NearSysCall);
     243         316 :   IO.enumCase(Value, "FarSysCall", CallingConvention::FarSysCall);
     244         316 :   IO.enumCase(Value, "ThisCall", CallingConvention::ThisCall);
     245         316 :   IO.enumCase(Value, "MipsCall", CallingConvention::MipsCall);
     246         316 :   IO.enumCase(Value, "Generic", CallingConvention::Generic);
     247         316 :   IO.enumCase(Value, "AlphaCall", CallingConvention::AlphaCall);
     248         316 :   IO.enumCase(Value, "PpcCall", CallingConvention::PpcCall);
     249         316 :   IO.enumCase(Value, "SHCall", CallingConvention::SHCall);
     250         316 :   IO.enumCase(Value, "ArmCall", CallingConvention::ArmCall);
     251         316 :   IO.enumCase(Value, "AM33Call", CallingConvention::AM33Call);
     252         316 :   IO.enumCase(Value, "TriCall", CallingConvention::TriCall);
     253         316 :   IO.enumCase(Value, "SH5Call", CallingConvention::SH5Call);
     254         316 :   IO.enumCase(Value, "M32RCall", CallingConvention::M32RCall);
     255         316 :   IO.enumCase(Value, "ClrCall", CallingConvention::ClrCall);
     256         316 :   IO.enumCase(Value, "Inline", CallingConvention::Inline);
     257         316 :   IO.enumCase(Value, "NearVector", CallingConvention::NearVector);
     258         316 : }
     259             : 
     260           0 : void ScalarEnumerationTraits<PointerKind>::enumeration(IO &IO,
     261             :                                                        PointerKind &Kind) {
     262           0 :   IO.enumCase(Kind, "Near16", PointerKind::Near16);
     263           0 :   IO.enumCase(Kind, "Far16", PointerKind::Far16);
     264           0 :   IO.enumCase(Kind, "Huge16", PointerKind::Huge16);
     265           0 :   IO.enumCase(Kind, "BasedOnSegment", PointerKind::BasedOnSegment);
     266           0 :   IO.enumCase(Kind, "BasedOnValue", PointerKind::BasedOnValue);
     267           0 :   IO.enumCase(Kind, "BasedOnSegmentValue", PointerKind::BasedOnSegmentValue);
     268           0 :   IO.enumCase(Kind, "BasedOnAddress", PointerKind::BasedOnAddress);
     269           0 :   IO.enumCase(Kind, "BasedOnSegmentAddress",
     270             :               PointerKind::BasedOnSegmentAddress);
     271           0 :   IO.enumCase(Kind, "BasedOnType", PointerKind::BasedOnType);
     272           0 :   IO.enumCase(Kind, "BasedOnSelf", PointerKind::BasedOnSelf);
     273           0 :   IO.enumCase(Kind, "Near32", PointerKind::Near32);
     274           0 :   IO.enumCase(Kind, "Far32", PointerKind::Far32);
     275           0 :   IO.enumCase(Kind, "Near64", PointerKind::Near64);
     276           0 : }
     277             : 
     278           0 : void ScalarEnumerationTraits<PointerMode>::enumeration(IO &IO,
     279             :                                                        PointerMode &Mode) {
     280           0 :   IO.enumCase(Mode, "Pointer", PointerMode::Pointer);
     281           0 :   IO.enumCase(Mode, "LValueReference", PointerMode::LValueReference);
     282           0 :   IO.enumCase(Mode, "PointerToDataMember", PointerMode::PointerToDataMember);
     283           0 :   IO.enumCase(Mode, "PointerToMemberFunction",
     284             :               PointerMode::PointerToMemberFunction);
     285           0 :   IO.enumCase(Mode, "RValueReference", PointerMode::RValueReference);
     286           0 : }
     287             : 
     288           0 : void ScalarEnumerationTraits<HfaKind>::enumeration(IO &IO, HfaKind &Value) {
     289           0 :   IO.enumCase(Value, "None", HfaKind::None);
     290           0 :   IO.enumCase(Value, "Float", HfaKind::Float);
     291           0 :   IO.enumCase(Value, "Double", HfaKind::Double);
     292           0 :   IO.enumCase(Value, "Other", HfaKind::Other);
     293           0 : }
     294             : 
     295           0 : void ScalarEnumerationTraits<MemberAccess>::enumeration(IO &IO,
     296             :                                                         MemberAccess &Access) {
     297           0 :   IO.enumCase(Access, "None", MemberAccess::None);
     298           0 :   IO.enumCase(Access, "Private", MemberAccess::Private);
     299           0 :   IO.enumCase(Access, "Protected", MemberAccess::Protected);
     300           0 :   IO.enumCase(Access, "Public", MemberAccess::Public);
     301           0 : }
     302             : 
     303           0 : void ScalarEnumerationTraits<MethodKind>::enumeration(IO &IO,
     304             :                                                       MethodKind &Kind) {
     305           0 :   IO.enumCase(Kind, "Vanilla", MethodKind::Vanilla);
     306           0 :   IO.enumCase(Kind, "Virtual", MethodKind::Virtual);
     307           0 :   IO.enumCase(Kind, "Static", MethodKind::Static);
     308           0 :   IO.enumCase(Kind, "Friend", MethodKind::Friend);
     309           0 :   IO.enumCase(Kind, "IntroducingVirtual", MethodKind::IntroducingVirtual);
     310           0 :   IO.enumCase(Kind, "PureVirtual", MethodKind::PureVirtual);
     311           0 :   IO.enumCase(Kind, "PureIntroducingVirtual",
     312             :               MethodKind::PureIntroducingVirtual);
     313           0 : }
     314             : 
     315           0 : void ScalarEnumerationTraits<WindowsRTClassKind>::enumeration(
     316             :     IO &IO, WindowsRTClassKind &Value) {
     317           0 :   IO.enumCase(Value, "None", WindowsRTClassKind::None);
     318           0 :   IO.enumCase(Value, "Ref", WindowsRTClassKind::RefClass);
     319           0 :   IO.enumCase(Value, "Value", WindowsRTClassKind::ValueClass);
     320           0 :   IO.enumCase(Value, "Interface", WindowsRTClassKind::Interface);
     321           0 : }
     322             : 
     323           0 : void ScalarEnumerationTraits<LabelType>::enumeration(IO &IO, LabelType &Value) {
     324           0 :   IO.enumCase(Value, "Near", LabelType::Near);
     325           0 :   IO.enumCase(Value, "Far", LabelType::Far);
     326           0 : }
     327             : 
     328           0 : void ScalarBitSetTraits<PointerOptions>::bitset(IO &IO,
     329             :                                                 PointerOptions &Options) {
     330           0 :   IO.bitSetCase(Options, "None", PointerOptions::None);
     331           0 :   IO.bitSetCase(Options, "Flat32", PointerOptions::Flat32);
     332           0 :   IO.bitSetCase(Options, "Volatile", PointerOptions::Volatile);
     333           0 :   IO.bitSetCase(Options, "Const", PointerOptions::Const);
     334           0 :   IO.bitSetCase(Options, "Unaligned", PointerOptions::Unaligned);
     335           0 :   IO.bitSetCase(Options, "Restrict", PointerOptions::Restrict);
     336           0 :   IO.bitSetCase(Options, "WinRTSmartPointer",
     337             :                 PointerOptions::WinRTSmartPointer);
     338           0 : }
     339             : 
     340          28 : void ScalarBitSetTraits<ModifierOptions>::bitset(IO &IO,
     341             :                                                  ModifierOptions &Options) {
     342          28 :   IO.bitSetCase(Options, "None", ModifierOptions::None);
     343          28 :   IO.bitSetCase(Options, "Const", ModifierOptions::Const);
     344          28 :   IO.bitSetCase(Options, "Volatile", ModifierOptions::Volatile);
     345          28 :   IO.bitSetCase(Options, "Unaligned", ModifierOptions::Unaligned);
     346          28 : }
     347             : 
     348         316 : void ScalarBitSetTraits<FunctionOptions>::bitset(IO &IO,
     349             :                                                  FunctionOptions &Options) {
     350         316 :   IO.bitSetCase(Options, "None", FunctionOptions::None);
     351         316 :   IO.bitSetCase(Options, "CxxReturnUdt", FunctionOptions::CxxReturnUdt);
     352         316 :   IO.bitSetCase(Options, "Constructor", FunctionOptions::Constructor);
     353         316 :   IO.bitSetCase(Options, "ConstructorWithVirtualBases",
     354             :                 FunctionOptions::ConstructorWithVirtualBases);
     355         316 : }
     356             : 
     357         338 : void ScalarBitSetTraits<ClassOptions>::bitset(IO &IO, ClassOptions &Options) {
     358         338 :   IO.bitSetCase(Options, "None", ClassOptions::None);
     359         338 :   IO.bitSetCase(Options, "HasConstructorOrDestructor",
     360             :                 ClassOptions::HasConstructorOrDestructor);
     361         338 :   IO.bitSetCase(Options, "HasOverloadedOperator",
     362             :                 ClassOptions::HasOverloadedOperator);
     363         338 :   IO.bitSetCase(Options, "Nested", ClassOptions::Nested);
     364         338 :   IO.bitSetCase(Options, "ContainsNestedClass",
     365             :                 ClassOptions::ContainsNestedClass);
     366         338 :   IO.bitSetCase(Options, "HasOverloadedAssignmentOperator",
     367             :                 ClassOptions::HasOverloadedAssignmentOperator);
     368         338 :   IO.bitSetCase(Options, "HasConversionOperator",
     369             :                 ClassOptions::HasConversionOperator);
     370         338 :   IO.bitSetCase(Options, "ForwardReference", ClassOptions::ForwardReference);
     371         338 :   IO.bitSetCase(Options, "Scoped", ClassOptions::Scoped);
     372         338 :   IO.bitSetCase(Options, "HasUniqueName", ClassOptions::HasUniqueName);
     373         338 :   IO.bitSetCase(Options, "Sealed", ClassOptions::Sealed);
     374         338 :   IO.bitSetCase(Options, "Intrinsic", ClassOptions::Intrinsic);
     375         338 : }
     376             : 
     377           0 : void ScalarBitSetTraits<MethodOptions>::bitset(IO &IO, MethodOptions &Options) {
     378           0 :   IO.bitSetCase(Options, "None", MethodOptions::None);
     379           0 :   IO.bitSetCase(Options, "Pseudo", MethodOptions::Pseudo);
     380           0 :   IO.bitSetCase(Options, "NoInherit", MethodOptions::NoInherit);
     381           0 :   IO.bitSetCase(Options, "NoConstruct", MethodOptions::NoConstruct);
     382           0 :   IO.bitSetCase(Options, "CompilerGenerated", MethodOptions::CompilerGenerated);
     383           0 :   IO.bitSetCase(Options, "Sealed", MethodOptions::Sealed);
     384           0 : }
     385             : 
     386           0 : void MappingTraits<MemberPointerInfo>::mapping(IO &IO, MemberPointerInfo &MPI) {
     387           0 :   IO.mapRequired("ContainingType", MPI.ContainingType);
     388           0 :   IO.mapRequired("Representation", MPI.Representation);
     389           0 : }
     390             : 
     391             : namespace llvm {
     392             : namespace CodeViewYAML {
     393             : namespace detail {
     394             : 
     395          28 : template <> void LeafRecordImpl<ModifierRecord>::map(IO &IO) {
     396          28 :   IO.mapRequired("ModifiedType", Record.ModifiedType);
     397          28 :   IO.mapRequired("Modifiers", Record.Modifiers);
     398          28 : }
     399             : 
     400          69 : template <> void LeafRecordImpl<ProcedureRecord>::map(IO &IO) {
     401          69 :   IO.mapRequired("ReturnType", Record.ReturnType);
     402          69 :   IO.mapRequired("CallConv", Record.CallConv);
     403          69 :   IO.mapRequired("Options", Record.Options);
     404          69 :   IO.mapRequired("ParameterCount", Record.ParameterCount);
     405          69 :   IO.mapRequired("ArgumentList", Record.ArgumentList);
     406          69 : }
     407             : 
     408         247 : template <> void LeafRecordImpl<MemberFunctionRecord>::map(IO &IO) {
     409         247 :   IO.mapRequired("ReturnType", Record.ReturnType);
     410         247 :   IO.mapRequired("ClassType", Record.ClassType);
     411         247 :   IO.mapRequired("ThisType", Record.ThisType);
     412         247 :   IO.mapRequired("CallConv", Record.CallConv);
     413         247 :   IO.mapRequired("Options", Record.Options);
     414         247 :   IO.mapRequired("ParameterCount", Record.ParameterCount);
     415         247 :   IO.mapRequired("ArgumentList", Record.ArgumentList);
     416         247 :   IO.mapRequired("ThisPointerAdjustment", Record.ThisPointerAdjustment);
     417         247 : }
     418             : 
     419           0 : template <> void LeafRecordImpl<LabelRecord>::map(IO &IO) {
     420           0 :   IO.mapRequired("Mode", Record.Mode);
     421           0 : }
     422             : 
     423          23 : template <> void LeafRecordImpl<MemberFuncIdRecord>::map(IO &IO) {
     424          23 :   IO.mapRequired("ClassType", Record.ClassType);
     425          23 :   IO.mapRequired("FunctionType", Record.FunctionType);
     426          23 :   IO.mapRequired("Name", Record.Name);
     427          23 : }
     428             : 
     429         213 : template <> void LeafRecordImpl<ArgListRecord>::map(IO &IO) {
     430         213 :   IO.mapRequired("ArgIndices", Record.ArgIndices);
     431         213 : }
     432             : 
     433          30 : template <> void LeafRecordImpl<StringListRecord>::map(IO &IO) {
     434          30 :   IO.mapRequired("StringIndices", Record.StringIndices);
     435          30 : }
     436             : 
     437         207 : template <> void LeafRecordImpl<PointerRecord>::map(IO &IO) {
     438         207 :   IO.mapRequired("ReferentType", Record.ReferentType);
     439         207 :   IO.mapRequired("Attrs", Record.Attrs);
     440         207 :   IO.mapOptional("MemberInfo", Record.MemberInfo);
     441         207 : }
     442             : 
     443           5 : template <> void LeafRecordImpl<ArrayRecord>::map(IO &IO) {
     444           5 :   IO.mapRequired("ElementType", Record.ElementType);
     445           5 :   IO.mapRequired("IndexType", Record.IndexType);
     446           5 :   IO.mapRequired("Size", Record.Size);
     447           5 :   IO.mapRequired("Name", Record.Name);
     448           5 : }
     449             : 
     450         214 : void LeafRecordImpl<FieldListRecord>::map(IO &IO) {
     451         214 :   IO.mapRequired("FieldList", Members);
     452         214 : }
     453             : 
     454             : } // end namespace detail
     455             : } // end namespace CodeViewYAML
     456             : } // end namespace llvm
     457             : 
     458             : namespace {
     459             : 
     460           0 : class MemberRecordConversionVisitor : public TypeVisitorCallbacks {
     461             : public:
     462             :   explicit MemberRecordConversionVisitor(std::vector<MemberRecord> &Records)
     463          92 :       : Records(Records) {}
     464             : 
     465             : #define TYPE_RECORD(EnumName, EnumVal, Name)
     466             : #define MEMBER_RECORD(EnumName, EnumVal, Name)                                 \
     467             :   Error visitKnownMember(CVMemberRecord &CVR, Name##Record &Record) override { \
     468             :     return visitKnownMemberImpl(Record);                                       \
     469             :   }
     470             : #define TYPE_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName)
     471             : #define MEMBER_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName)
     472             : #include "llvm/DebugInfo/CodeView/CodeViewTypes.def"
     473             : private:
     474         581 :   template <typename T> Error visitKnownMemberImpl(T &Record) {
     475         581 :     TypeLeafKind K = static_cast<TypeLeafKind>(Record.getKind());
     476             :     auto Impl = std::make_shared<MemberRecordImpl<T>>(K);
     477         260 :     Impl->Record = Record;
     478        1162 :     Records.push_back(MemberRecord{Impl});
     479         581 :     return Error::success();
     480             :   }
     481             : 
     482             :   std::vector<MemberRecord> &Records;
     483             : };
     484             : 
     485             : } // end anonymous namespace
     486             : 
     487          92 : Error LeafRecordImpl<FieldListRecord>::fromCodeViewRecord(CVType Type) {
     488          92 :   MemberRecordConversionVisitor V(Members);
     489          92 :   return visitMemberRecordStream(Type.content(), V);
     490             : }
     491             : 
     492         118 : CVType LeafRecordImpl<FieldListRecord>::toCodeViewRecord(
     493             :     AppendingTypeTableBuilder &TS) const {
     494         236 :   ContinuationRecordBuilder CRB;
     495         118 :   CRB.begin(ContinuationRecordKind::FieldList);
     496         819 :   for (const auto &Member : Members) {
     497         701 :     Member.Member->writeTo(CRB);
     498             :   }
     499         118 :   TS.insertRecord(CRB);
     500         472 :   return CVType(Kind, TS.records().back());
     501             : }
     502             : 
     503         243 : void MappingTraits<OneMethodRecord>::mapping(IO &io, OneMethodRecord &Record) {
     504         243 :   io.mapRequired("Type", Record.Type);
     505         243 :   io.mapRequired("Attrs", Record.Attrs.Attrs);
     506         243 :   io.mapRequired("VFTableOffset", Record.VFTableOffset);
     507         243 :   io.mapRequired("Name", Record.Name);
     508         243 : }
     509             : 
     510             : namespace llvm {
     511             : namespace CodeViewYAML {
     512             : namespace detail {
     513             : 
     514         230 : template <> void LeafRecordImpl<ClassRecord>::map(IO &IO) {
     515         230 :   IO.mapRequired("MemberCount", Record.MemberCount);
     516         230 :   IO.mapRequired("Options", Record.Options);
     517         230 :   IO.mapRequired("FieldList", Record.FieldList);
     518         230 :   IO.mapRequired("Name", Record.Name);
     519         230 :   IO.mapRequired("UniqueName", Record.UniqueName);
     520         230 :   IO.mapRequired("DerivationList", Record.DerivationList);
     521         230 :   IO.mapRequired("VTableShape", Record.VTableShape);
     522         230 :   IO.mapRequired("Size", Record.Size);
     523         230 : }
     524             : 
     525           2 : template <> void LeafRecordImpl<UnionRecord>::map(IO &IO) {
     526           2 :   IO.mapRequired("MemberCount", Record.MemberCount);
     527           2 :   IO.mapRequired("Options", Record.Options);
     528           2 :   IO.mapRequired("FieldList", Record.FieldList);
     529           2 :   IO.mapRequired("Name", Record.Name);
     530           2 :   IO.mapRequired("UniqueName", Record.UniqueName);
     531           2 :   IO.mapRequired("Size", Record.Size);
     532           2 : }
     533             : 
     534         106 : template <> void LeafRecordImpl<EnumRecord>::map(IO &IO) {
     535         106 :   IO.mapRequired("NumEnumerators", Record.MemberCount);
     536         106 :   IO.mapRequired("Options", Record.Options);
     537         106 :   IO.mapRequired("FieldList", Record.FieldList);
     538         106 :   IO.mapRequired("Name", Record.Name);
     539         106 :   IO.mapRequired("UniqueName", Record.UniqueName);
     540         106 :   IO.mapRequired("UnderlyingType", Record.UnderlyingType);
     541         106 : }
     542             : 
     543           4 : template <> void LeafRecordImpl<BitFieldRecord>::map(IO &IO) {
     544           4 :   IO.mapRequired("Type", Record.Type);
     545           4 :   IO.mapRequired("BitSize", Record.BitSize);
     546           4 :   IO.mapRequired("BitOffset", Record.BitOffset);
     547           4 : }
     548             : 
     549           7 : template <> void LeafRecordImpl<VFTableShapeRecord>::map(IO &IO) {
     550           7 :   IO.mapRequired("Slots", Record.Slots);
     551           7 : }
     552             : 
     553           7 : template <> void LeafRecordImpl<TypeServer2Record>::map(IO &IO) {
     554           7 :   IO.mapRequired("Guid", Record.Guid);
     555           7 :   IO.mapRequired("Age", Record.Age);
     556           7 :   IO.mapRequired("Name", Record.Name);
     557           7 : }
     558             : 
     559         204 : template <> void LeafRecordImpl<StringIdRecord>::map(IO &IO) {
     560         204 :   IO.mapRequired("Id", Record.Id);
     561         204 :   IO.mapRequired("String", Record.String);
     562         204 : }
     563             : 
     564          62 : template <> void LeafRecordImpl<FuncIdRecord>::map(IO &IO) {
     565          62 :   IO.mapRequired("ParentScope", Record.ParentScope);
     566          62 :   IO.mapRequired("FunctionType", Record.FunctionType);
     567          62 :   IO.mapRequired("Name", Record.Name);
     568          62 : }
     569             : 
     570          74 : template <> void LeafRecordImpl<UdtSourceLineRecord>::map(IO &IO) {
     571          74 :   IO.mapRequired("UDT", Record.UDT);
     572          74 :   IO.mapRequired("SourceFile", Record.SourceFile);
     573          74 :   IO.mapRequired("LineNumber", Record.LineNumber);
     574          74 : }
     575             : 
     576          28 : template <> void LeafRecordImpl<UdtModSourceLineRecord>::map(IO &IO) {
     577          28 :   IO.mapRequired("UDT", Record.UDT);
     578          28 :   IO.mapRequired("SourceFile", Record.SourceFile);
     579          28 :   IO.mapRequired("LineNumber", Record.LineNumber);
     580          28 :   IO.mapRequired("Module", Record.Module);
     581          28 : }
     582             : 
     583          31 : template <> void LeafRecordImpl<BuildInfoRecord>::map(IO &IO) {
     584          31 :   IO.mapRequired("ArgIndices", Record.ArgIndices);
     585          31 : }
     586             : 
     587           4 : template <> void LeafRecordImpl<VFTableRecord>::map(IO &IO) {
     588           4 :   IO.mapRequired("CompleteClass", Record.CompleteClass);
     589           4 :   IO.mapRequired("OverriddenVFTable", Record.OverriddenVFTable);
     590           4 :   IO.mapRequired("VFPtrOffset", Record.VFPtrOffset);
     591           4 :   IO.mapRequired("MethodNames", Record.MethodNames);
     592           4 : }
     593             : 
     594          83 : template <> void LeafRecordImpl<MethodOverloadListRecord>::map(IO &IO) {
     595          83 :   IO.mapRequired("Methods", Record.Methods);
     596          83 : }
     597             : 
     598          44 : template <> void MemberRecordImpl<OneMethodRecord>::map(IO &IO) {
     599          44 :   MappingTraits<OneMethodRecord>::mapping(IO, Record);
     600          44 : }
     601             : 
     602          83 : template <> void MemberRecordImpl<OverloadedMethodRecord>::map(IO &IO) {
     603          83 :   IO.mapRequired("NumOverloads", Record.NumOverloads);
     604          83 :   IO.mapRequired("MethodList", Record.MethodList);
     605          83 :   IO.mapRequired("Name", Record.Name);
     606          83 : }
     607             : 
     608         106 : template <> void MemberRecordImpl<NestedTypeRecord>::map(IO &IO) {
     609         106 :   IO.mapRequired("Type", Record.Type);
     610         106 :   IO.mapRequired("Name", Record.Name);
     611         106 : }
     612             : 
     613         335 : template <> void MemberRecordImpl<DataMemberRecord>::map(IO &IO) {
     614         335 :   IO.mapRequired("Attrs", Record.Attrs.Attrs);
     615         335 :   IO.mapRequired("Type", Record.Type);
     616         335 :   IO.mapRequired("FieldOffset", Record.FieldOffset);
     617         335 :   IO.mapRequired("Name", Record.Name);
     618         335 : }
     619             : 
     620           2 : template <> void MemberRecordImpl<StaticDataMemberRecord>::map(IO &IO) {
     621           2 :   IO.mapRequired("Attrs", Record.Attrs.Attrs);
     622           2 :   IO.mapRequired("Type", Record.Type);
     623           2 :   IO.mapRequired("Name", Record.Name);
     624           2 : }
     625             : 
     626         707 : template <> void MemberRecordImpl<EnumeratorRecord>::map(IO &IO) {
     627         707 :   IO.mapRequired("Attrs", Record.Attrs.Attrs);
     628         707 :   IO.mapRequired("Value", Record.Value);
     629         707 :   IO.mapRequired("Name", Record.Name);
     630         707 : }
     631             : 
     632           4 : template <> void MemberRecordImpl<VFPtrRecord>::map(IO &IO) {
     633           4 :   IO.mapRequired("Type", Record.Type);
     634           4 : }
     635             : 
     636           6 : template <> void MemberRecordImpl<BaseClassRecord>::map(IO &IO) {
     637           6 :   IO.mapRequired("Attrs", Record.Attrs.Attrs);
     638           6 :   IO.mapRequired("Type", Record.Type);
     639           6 :   IO.mapRequired("Offset", Record.Offset);
     640           6 : }
     641             : 
     642           4 : template <> void MemberRecordImpl<VirtualBaseClassRecord>::map(IO &IO) {
     643           4 :   IO.mapRequired("Attrs", Record.Attrs.Attrs);
     644           4 :   IO.mapRequired("BaseType", Record.BaseType);
     645           4 :   IO.mapRequired("VBPtrType", Record.VBPtrType);
     646           4 :   IO.mapRequired("VBPtrOffset", Record.VBPtrOffset);
     647           4 :   IO.mapRequired("VTableIndex", Record.VTableIndex);
     648           4 : }
     649             : 
     650           0 : template <> void MemberRecordImpl<ListContinuationRecord>::map(IO &IO) {
     651           0 :   IO.mapRequired("ContinuationIndex", Record.ContinuationIndex);
     652           0 : }
     653             : 
     654             : } // end namespace detail
     655             : } // end namespace CodeViewYAML
     656             : } // end namespace llvm
     657             : 
     658             : template <typename T>
     659         593 : static inline Expected<LeafRecord> fromCodeViewRecordImpl(CVType Type) {
     660         593 :   LeafRecord Result;
     661             : 
     662        1186 :   auto Impl = std::make_shared<LeafRecordImpl<T>>(Type.kind());
     663        1779 :   if (auto EC = Impl->fromCodeViewRecord(Type))
     664             :     return std::move(EC);
     665             :   Result.Leaf = Impl;
     666             :   return Result;
     667             : }
     668             : 
     669         593 : Expected<LeafRecord> LeafRecord::fromCodeViewRecord(CVType Type) {
     670             : #define TYPE_RECORD(EnumName, EnumVal, ClassName)                              \
     671             :   case EnumName:                                                               \
     672             :     return fromCodeViewRecordImpl<ClassName##Record>(Type);
     673             : #define TYPE_RECORD_ALIAS(EnumName, EnumVal, AliasName, ClassName)             \
     674             :   TYPE_RECORD(EnumName, EnumVal, ClassName)
     675             : #define MEMBER_RECORD(EnumName, EnumVal, ClassName)
     676             : #define MEMBER_RECORD_ALIAS(EnumName, EnumVal, AliasName, ClassName)
     677         593 :   switch (Type.kind()) {
     678             : #include "llvm/DebugInfo/CodeView/CodeViewTypes.def"
     679           0 :   default:
     680           0 :       llvm_unreachable("Unknown leaf kind!");
     681             :   }
     682             :   return make_error<CodeViewError>(cv_error_code::corrupt_record);
     683             : }
     684             : 
     685             : CVType
     686         438 : LeafRecord::toCodeViewRecord(AppendingTypeTableBuilder &Serializer) const {
     687         438 :   return Leaf->toCodeViewRecord(Serializer);
     688             : }
     689             : 
     690             : namespace llvm {
     691             : namespace yaml {
     692             : 
     693             : template <> struct MappingTraits<LeafRecordBase> {
     694        1664 :   static void mapping(IO &io, LeafRecordBase &Record) { Record.map(io); }
     695             : };
     696             : 
     697             : template <> struct MappingTraits<MemberRecordBase> {
     698        1291 :   static void mapping(IO &io, MemberRecordBase &Record) { Record.map(io); }
     699             : };
     700             : 
     701             : } // end namespace yaml
     702             : } // end namespace llvm
     703             : 
     704             : template <typename ConcreteType>
     705        1878 : static void mapLeafRecordImpl(IO &IO, const char *Class, TypeLeafKind Kind,
     706             :                               LeafRecord &Obj) {
     707        1878 :   if (!IO.outputting())
     708        1285 :     Obj.Leaf = std::make_shared<LeafRecordImpl<ConcreteType>>(Kind);
     709             : 
     710        1878 :   if (Kind == LF_FIELDLIST)
     711         214 :     Obj.Leaf->map(IO);
     712             :   else
     713             :     IO.mapRequired(Class, *Obj.Leaf);
     714        1878 : }
     715             : 
     716        1878 : void MappingTraits<LeafRecord>::mapping(IO &IO, LeafRecord &Obj) {
     717             :   TypeLeafKind Kind;
     718        1878 :   if (IO.outputting())
     719         593 :     Kind = Obj.Leaf->Kind;
     720             :   IO.mapRequired("Kind", Kind);
     721             : 
     722             : #define TYPE_RECORD(EnumName, EnumVal, ClassName)                              \
     723             :   case EnumName:                                                               \
     724             :     mapLeafRecordImpl<ClassName##Record>(IO, #ClassName, Kind, Obj);           \
     725             :     break;
     726             : #define TYPE_RECORD_ALIAS(EnumName, EnumVal, AliasName, ClassName)             \
     727             :   TYPE_RECORD(EnumName, EnumVal, ClassName)
     728             : #define MEMBER_RECORD(EnumName, EnumVal, ClassName)
     729             : #define MEMBER_RECORD_ALIAS(EnumName, EnumVal, AliasName, ClassName)
     730        1878 :   switch (Kind) {
     731             : #include "llvm/DebugInfo/CodeView/CodeViewTypes.def"
     732           0 :   default: { llvm_unreachable("Unknown leaf kind!"); }
     733             :   }
     734        1878 : }
     735             : 
     736             : template <typename ConcreteType>
     737        1291 : static void mapMemberRecordImpl(IO &IO, const char *Class, TypeLeafKind Kind,
     738             :                                 MemberRecord &Obj) {
     739        1291 :   if (!IO.outputting())
     740         710 :     Obj.Member = std::make_shared<MemberRecordImpl<ConcreteType>>(Kind);
     741             : 
     742             :   IO.mapRequired(Class, *Obj.Member);
     743        1291 : }
     744             : 
     745        1291 : void MappingTraits<MemberRecord>::mapping(IO &IO, MemberRecord &Obj) {
     746             :   TypeLeafKind Kind;
     747        1291 :   if (IO.outputting())
     748         581 :     Kind = Obj.Member->Kind;
     749             :   IO.mapRequired("Kind", Kind);
     750             : 
     751             : #define MEMBER_RECORD(EnumName, EnumVal, ClassName)                            \
     752             :   case EnumName:                                                               \
     753             :     mapMemberRecordImpl<ClassName##Record>(IO, #ClassName, Kind, Obj);         \
     754             :     break;
     755             : #define MEMBER_RECORD_ALIAS(EnumName, EnumVal, AliasName, ClassName)           \
     756             :   MEMBER_RECORD(EnumName, EnumVal, ClassName)
     757             : #define TYPE_RECORD(EnumName, EnumVal, ClassName)
     758             : #define TYPE_RECORD_ALIAS(EnumName, EnumVal, AliasName, ClassName)
     759        1291 :   switch (Kind) {
     760             : #include "llvm/DebugInfo/CodeView/CodeViewTypes.def"
     761           0 :   default: { llvm_unreachable("Unknown member kind!"); }
     762             :   }
     763        1291 : }
     764             : 
     765             : std::vector<LeafRecord>
     766           3 : llvm::CodeViewYAML::fromDebugT(ArrayRef<uint8_t> DebugT) {
     767           9 :   ExitOnError Err("Invalid .debug$T section!");
     768           3 :   BinaryStreamReader Reader(DebugT, support::little);
     769             :   CVTypeArray Types;
     770             :   uint32_t Magic;
     771             : 
     772           6 :   Err(Reader.readInteger(Magic));
     773             :   assert(Magic == COFF::DEBUG_SECTION_MAGIC && "Invalid .debug$T section!");
     774             : 
     775             :   std::vector<LeafRecord> Result;
     776           6 :   Err(Reader.readArray(Types, Reader.bytesRemaining()));
     777          22 :   for (const auto &T : Types) {
     778          19 :     auto CVT = Err(LeafRecord::fromCodeViewRecord(T));
     779          19 :     Result.push_back(CVT);
     780             :   }
     781           3 :   return Result;
     782             : }
     783             : 
     784          32 : ArrayRef<uint8_t> llvm::CodeViewYAML::toDebugT(ArrayRef<LeafRecord> Leafs,
     785             :                                                BumpPtrAllocator &Alloc) {
     786          64 :   AppendingTypeTableBuilder TS(Alloc);
     787             :   uint32_t Size = sizeof(uint32_t);
     788        1608 :   for (const auto &Leaf : Leafs) {
     789         788 :     CVType T = Leaf.Leaf->toCodeViewRecord(TS);
     790         788 :     Size += T.length();
     791             :     assert(T.length() % 4 == 0 && "Improper type record alignment!");
     792             :   }
     793          32 :   uint8_t *ResultBuffer = Alloc.Allocate<uint8_t>(Size);
     794             :   MutableArrayRef<uint8_t> Output(ResultBuffer, Size);
     795          32 :   BinaryStreamWriter Writer(Output, support::little);
     796          96 :   ExitOnError Err("Error writing type record to .debug$T section");
     797          64 :   Err(Writer.writeInteger<uint32_t>(COFF::DEBUG_SECTION_MAGIC));
     798        1640 :   for (const auto &R : TS.records()) {
     799        1576 :     Err(Writer.writeBytes(R));
     800             :   }
     801             :   assert(Writer.bytesRemaining() == 0 && "Didn't write all type record bytes!");
     802          64 :   return Output;
     803             : }

Generated by: LCOV version 1.13