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

typeBuilder.h « debugInfo « ObjWriter « Native « src - github.com/mono/corert.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f3e3046e505348c79269c82d34c79408a92da59c (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
146
147
148
149
150
151
152
153
154
155
156
157
158
//===---- typeBuilder.h -----------------------------------------*- C++ -*-===//
//
// type builder is used to convert .Net types into debuginfo.
//
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
//
//===----------------------------------------------------------------------===//

#pragma once

#include "llvm/MC/MCObjectStreamer.h"

#include <string>
#include <vector>

using namespace llvm;

// Keep in sync with Internal.TypeSystem.TypeFlags (Common/src/TypeSystem/Common/TypeFlags.cs)
enum class PrimitiveTypeFlags {
  Unknown = 0x00,
  Void    = 0x01,
  Boolean = 0x02,
  Char    = 0x03,
  SByte   = 0x04,
  Byte    = 0x05,
  Int16   = 0x06,
  UInt16  = 0x07,
  Int32   = 0x08,
  UInt32  = 0x09,
  Int64   = 0x0A,
  UInt64  = 0x0B,
  IntPtr  = 0x0C,
  UIntPtr = 0x0D,
  Single  = 0x0E,
  Double  = 0x0F
};

typedef unsigned long long uint64;

#pragma pack(push, 8)

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

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

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

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

extern "C" struct StaticDataFieldDescriptor {
  const char *StaticDataName;
  uint64 StaticOffset;
  int IsStaticDataInObject;
};

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

extern "C" struct ArrayTypeDescriptor {
  uint32_t Rank;
  uint32_t ElementType;
  uint32_t Size; // ElementSize
  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;
  const char *Name;
};

#pragma pack(pop)
class UserDefinedTypesBuilder {
public:
  UserDefinedTypesBuilder() : Streamer(nullptr), TargetPointerSize(0) {}
  virtual ~UserDefinedTypesBuilder() {}
  void SetStreamer(MCObjectStreamer *Streamer) {
    assert(this->Streamer == nullptr);
    assert(Streamer != nullptr);
    this->Streamer = Streamer;
  }
  MCObjectStreamer *GetStreamer() const {
    return Streamer;
  }
  void SetTargetPointerSize(unsigned TargetPointerSize) {
    assert(this->TargetPointerSize == 0);
    assert(TargetPointerSize != 0);
    this->TargetPointerSize = TargetPointerSize;
  }
  virtual void EmitTypeInformation(MCSection *TypeSection, MCSection *StrSection = nullptr) = 0;

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

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

  virtual unsigned GetPointerTypeIndex(const PointerTypeDescriptor& PointerDescriptor) = 0;

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

  virtual unsigned GetMemberFunctionId(const MemberFunctionIdTypeDescriptor& MemberIdDescriptor) = 0;

  virtual unsigned GetPrimitiveTypeIndex(PrimitiveTypeFlags Type) = 0;

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

protected:
  MCObjectStreamer *Streamer;
  unsigned TargetPointerSize;

  std::vector<std::pair<std::string, uint32_t>> UserDefinedTypes;
};