forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIRGenMangler.h
183 lines (149 loc) · 5.49 KB
/
IRGenMangler.h
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
//===--- IRGenMangler.h - mangling of IRGen symbols -------------*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
#ifndef SWIFT_IRGEN_IRGENMANGLER_H
#define SWIFT_IRGEN_IRGENMANGLER_H
#include "swift/AST/ASTMangler.h"
#include "ValueWitness.h"
namespace swift {
namespace irgen {
/// The mangler for all kind of symbols produced in IRGen.
class IRGenMangler : public NewMangling::ASTMangler {
public:
IRGenMangler() { }
std::string mangleValueWitness(Type type, ValueWitness witness);
std::string mangleValueWitnessTable(Type type) {
return mangleTypeSymbol(type, "WV");
}
std::string mangleTypeMetadataAccessFunction(Type type) {
return mangleTypeSymbol(type, "Ma");
}
std::string mangleTypeMetadataLazyCacheVariable(Type type) {
return mangleTypeSymbol(type, "ML");
}
std::string mangleTypeFullMetadataFull(Type type) {
return mangleTypeSymbol(type, "Mf");
}
std::string mangleTypeMetadataFull(Type type, bool isPattern) {
return mangleTypeSymbol(type, isPattern ? "MP" : "N");
}
std::string mangleClassMetaClass(const ClassDecl *Decl) {
return mangleNominalTypeSymbol(Decl, "Mm");
}
std::string mangleNominalTypeDescriptor(const NominalTypeDecl *Decl) {
return mangleNominalTypeSymbol(Decl, "Mn");
}
std::string mangleProtocolDescriptor(const ProtocolDecl *Decl) {
beginMangling();
appendProtocolName(Decl);
appendOperator("Mp");
return finalize();
}
std::string mangleWitnessTableOffset(const ValueDecl *Decl) {
beginMangling();
if (auto ctor = dyn_cast<ConstructorDecl>(Decl)) {
appendConstructorEntity(ctor, /*isAllocating=*/true);
} else {
appendEntity(Decl);
}
appendOperator("Wo");
return finalize();
}
std::string mangleFieldOffsetFull(const ValueDecl *Decl, bool isIndirect) {
beginMangling();
appendEntity(Decl);
appendOperator("Wv", isIndirect ? "i" : "d");
return finalize();
}
std::string mangleDirectProtocolWitnessTable(const ProtocolConformance *C) {
return mangleConformanceSymbol(Type(), C, "WP");
}
std::string mangleGenericProtocolWitnessTableCache(
const ProtocolConformance *C) {
return mangleConformanceSymbol(Type(), C, "WG");
}
std::string mangleGenericProtocolWitnessTableInstantiationFunction(
const ProtocolConformance *C) {
return mangleConformanceSymbol(Type(), C, "WI");
}
std::string mangleProtocolWitnessTableAccessFunction(
const ProtocolConformance *C) {
return mangleConformanceSymbol(Type(), C, "Wa");
}
std::string mangleProtocolWitnessTableLazyAccessFunction(Type type,
const ProtocolConformance *C) {
return mangleConformanceSymbol(type, C, "Wl");
}
std::string mangleProtocolWitnessTableLazyCacheVariable(Type type,
const ProtocolConformance *C) {
return mangleConformanceSymbol(type, C, "WL");
}
std::string mangleAssociatedTypeMetadataAccessFunction(
const ProtocolConformance *Conformance,
StringRef AssocTyName) {
beginMangling();
appendProtocolConformance(Conformance);
appendIdentifier(AssocTyName);
appendOperator("Wt");
return finalize();
}
std::string mangleAssociatedTypeWitnessTableAccessFunction(
const ProtocolConformance *Conformance,
StringRef AssocTyName,
const ProtocolDecl *Proto) {
beginMangling();
appendProtocolConformance(Conformance);
appendIdentifier(AssocTyName);
appendNominalType(Proto);
appendOperator("WT");
return finalize();
}
std::string mangleReflectionBuiltinDescriptor(Type type) {
return mangleTypeSymbol(type, "MB");
}
std::string mangleReflectionFieldDescriptor(Type type) {
return mangleTypeSymbol(type, "MF");
}
std::string mangleReflectionAssociatedTypeDescriptor(
const ProtocolConformance *C) {
return mangleConformanceSymbol(Type(), C, "MA");
}
std::string mangleReflectionSuperclassDescriptor(const ClassDecl *Decl) {
return mangleNominalTypeSymbol(Decl, "MC");
}
protected:
std::string mangleTypeSymbol(Type type, const char *Op) {
beginMangling();
appendType(type);
appendOperator(Op);
return finalize();
}
std::string mangleNominalTypeSymbol(const NominalTypeDecl *Decl,
const char *Op) {
beginMangling();
appendNominalType(Decl);
appendOperator(Op);
return finalize();
}
std::string mangleConformanceSymbol(Type type,
const ProtocolConformance *Conformance,
const char *Op) {
beginMangling();
if (type)
appendType(type);
appendProtocolConformance(Conformance);
appendOperator(Op);
return finalize();
}
};
} // end namespace irgen
} // end namespace swift
#endif