Welcome to mirror list, hosted at ThFree Co, Russian Federation.

typeBuilder.h « ObjWriter « Native « src - github.com/mono/corert.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a5037b7690ecf9473579f0a7df01aaa3f98c1a0e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
//===---- typeBuilder.h --------------------------------*- C++ -*-===//
//
// type builder is used to convert .Net types into CodeView descriptors.
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license.
// See LICENSE file in the project root for full license information.
//
//===----------------------------------------------------------------------===//

#pragma once

#include "llvm/DebugInfo/CodeView/TypeTableBuilder.h"
#include "llvm/MC/MCObjectStreamer.h"

#include <string>
#include <vector>

using namespace llvm;
using namespace llvm::codeview;

typedef unsigned long long uint64;

#pragma pack(push, 8)

extern "C" struct EnumRecordTypeDescriptor {
  uint64 Value;
  char *Name;
};

extern "C" struct EnumTypeDescriptor {
  uint32_t ElementType;
  uint64 ElementCount;
  char *Name;
};

extern "C" struct ClassTypeDescriptor {
  int32_t IsStruct;
  char *Name;
  uint32_t BaseClassId;
};

extern "C" struct DataFieldDescriptor {
  uint32_t FieldTypeIndex;
  uint64 Offset;
  char *Name;
};

extern "C" struct ClassFieldsTypeDescriptior {
  uint64 Size;
  int32_t FieldsCount;
};

extern "C" struct ArrayTypeDescriptor {
  uint32_t Rank;
  uint32_t ElementType;
  uint32_t Size;
  int32_t IsMultiDimensional;
};

extern "C" struct PointerTypeDescriptor {
    uint32_t ElementType;
    int32_t IsReference;
    int32_t IsConst;
    int32_t Is64Bit;
};

extern "C" struct MemberFunctionTypeDescriptor {
    uint32_t ReturnType;
    uint32_t ContainingClass;
    uint32_t TypeIndexOfThisPointer;
    int32_t ThisAdjust;
    uint32_t CallingConvention;
    uint16_t NumberOfArguments;
};

extern "C" struct MemberFunctionIdTypeDescriptor {
    uint32_t MemberFunction;
    uint32_t ParentClass;
    char *Name;
};

class ArrayDimensionsDescriptor {
public:
  const char *GetLengthName(unsigned index);
  const char *GetBoundsName(unsigned index);

private:
  void Resize(unsigned NewSize);

  std::vector<std::string> Lengths;
  std::vector<std::string> Bounds;
};

#pragma pack(pop)
class UserDefinedTypesBuilder {
public:
  UserDefinedTypesBuilder();
  void SetStreamer(MCObjectStreamer *Streamer);
  void SetTargetPointerSize(unsigned TargetPointerSize);
  void EmitTypeInformation(MCSection *COFFDebugTypesSection);

  unsigned GetEnumTypeIndex(const EnumTypeDescriptor &TypeDescriptor,
                            const EnumRecordTypeDescriptor *TypeRecords);
  unsigned GetClassTypeIndex(const ClassTypeDescriptor &ClassDescriptor);
  unsigned GetCompleteClassTypeIndex(
      const ClassTypeDescriptor &ClassDescriptor,
      const ClassFieldsTypeDescriptior &ClassFieldsDescriptor,
      const DataFieldDescriptor *FieldsDescriptors);

  unsigned GetArrayTypeIndex(const ClassTypeDescriptor &ClassDescriptor,
                             const ArrayTypeDescriptor &ArrayDescriptor);

  unsigned GetPointerTypeIndex(const PointerTypeDescriptor& PointerDescriptor);

  unsigned GetMemberFunctionTypeIndex(const MemberFunctionTypeDescriptor& MemberDescriptor,
      uint32_t const *const ArgumentTypes);

  unsigned GetMemberFunctionId(const MemberFunctionIdTypeDescriptor& MemberIdDescriptor);

  const std::vector<std::pair<std::string, codeview::TypeIndex>> &GetUDTs() {
    return UserDefinedTypes;
  }

private:
  void EmitCodeViewMagicVersion();
  ClassOptions GetCommonClassOptions();

  unsigned GetEnumFieldListType(uint64 Count,
                                const EnumRecordTypeDescriptor *TypeRecords);

  void AddBaseClass(FieldListRecordBuilder &FLBR, unsigned BaseClassId);
  void AddClassVTShape(FieldListRecordBuilder &FLBR);

  BumpPtrAllocator Allocator;
  TypeTableBuilder TypeTable;

  MCObjectStreamer *Streamer;
  unsigned TargetPointerSize;

  ArrayDimensionsDescriptor ArrayDimentions;
  TypeIndex ClassVTableTypeIndex;

  std::vector<std::pair<std::string, codeview::TypeIndex>> UserDefinedTypes;
};