@@ -42,6 +42,7 @@ namespace swift {
42
42
class AutoClosureExpr ;
43
43
class ASTContext ;
44
44
class ClassDecl ;
45
+ class FileUnit ;
45
46
class SILFunctionType ;
46
47
enum IsSerialized_t : unsigned char ;
47
48
enum class SubclassScope : unsigned char ;
@@ -83,7 +84,14 @@ enum ForDefinition_t : bool {
83
84
// / declaration, such as uncurry levels of a function, the allocating and
84
85
// / initializing entry points of a constructor, etc.
85
86
struct SILDeclRef {
86
- using Loc = llvm::PointerUnion<ValueDecl *, AbstractClosureExpr *>;
87
+ // / The type of AST node location being stored.
88
+ enum LocKind {
89
+ Decl,
90
+ Closure,
91
+ File
92
+ };
93
+ using Loc = llvm::PointerUnion<ValueDecl *, AbstractClosureExpr *,
94
+ FileUnit *>;
87
95
88
96
// / Represents the "kind" of the SILDeclRef. For some Swift decls there
89
97
// / are multiple SIL entry points, and the kind is used to distinguish them.
@@ -144,9 +152,16 @@ struct SILDeclRef {
144
152
// / References the function used to initialize a property wrapper storage
145
153
// / instance from a projected value.
146
154
PropertyWrapperInitFromProjectedValue,
155
+
156
+ // / The main entry-point function. This may reference a SourceFile for a
157
+ // / top-level main, or a decl for e.g an @main decl.
158
+ EntryPoint,
159
+
160
+ // / The asynchronous main entry-point function.
161
+ AsyncEntryPoint,
147
162
};
148
-
149
- // / The ValueDecl or AbstractClosureExpr represented by this SILDeclRef.
163
+
164
+ // / The AST node represented by this SILDeclRef.
150
165
Loc loc;
151
166
// / The Kind of this SILDeclRef.
152
167
Kind kind : 4 ;
@@ -159,6 +174,17 @@ struct SILDeclRef {
159
174
const GenericSignatureImpl *>
160
175
pointer;
161
176
177
+ // / Returns the type of AST node location being stored by the SILDeclRef.
178
+ LocKind getLocKind () const {
179
+ if (loc.is <ValueDecl *>())
180
+ return LocKind::Decl;
181
+ if (loc.is <AbstractClosureExpr *>())
182
+ return LocKind::Closure;
183
+ if (loc.is <FileUnit *>())
184
+ return LocKind::File;
185
+ llvm_unreachable (" Unhandled location kind!" );
186
+ }
187
+
162
188
// / The derivative function identifier.
163
189
AutoDiffDerivativeFunctionIdentifier * getDerivativeFunctionIdentifier () const {
164
190
if (!pointer.is <AutoDiffDerivativeFunctionIdentifier *>())
@@ -201,6 +227,15 @@ struct SILDeclRef {
201
227
// / Produce a SIL constant for a default argument generator.
202
228
static SILDeclRef getDefaultArgGenerator (Loc loc, unsigned defaultArgIndex);
203
229
230
+ // / Produces a SILDeclRef for a synthetic main entry-point such as @main.
231
+ static SILDeclRef getMainDeclEntryPoint (ValueDecl *decl);
232
+
233
+ // / Produces a SILDeclRef for the synthesized async main entry-point
234
+ static SILDeclRef getAsyncMainDeclEntryPoint (ValueDecl *decl);
235
+
236
+ // / Produces a SILDeclRef for the entry-point of a main FileUnit.
237
+ static SILDeclRef getMainFileEntryPoint (FileUnit *file);
238
+
204
239
bool isNull () const { return loc.isNull (); }
205
240
explicit operator bool () const { return !isNull (); }
206
241
@@ -217,7 +252,13 @@ struct SILDeclRef {
217
252
AutoClosureExpr *getAutoClosureExpr () const ;
218
253
FuncDecl *getFuncDecl () const ;
219
254
AbstractFunctionDecl *getAbstractFunctionDecl () const ;
220
-
255
+ FileUnit *getFileUnit () const {
256
+ return loc.get <FileUnit *>();
257
+ }
258
+
259
+ // / Retrieves the ASTContext from the underlying AST node being stored.
260
+ ASTContext &getASTContext () const ;
261
+
221
262
llvm::Optional<AnyFunctionRef> getAnyFunctionRef () const ;
222
263
223
264
SILLocation getAsRegularLocation () const ;
0 commit comments