@@ -35,6 +35,7 @@ namespace swift {
35
35
36
36
class CompilerInstance ;
37
37
38
+ // / A JIT stack able to lazily JIT Swift programs
38
39
class SwiftJIT {
39
40
public:
40
41
SwiftJIT (const SwiftJIT &) = delete ;
@@ -49,23 +50,33 @@ class SwiftJIT {
49
50
50
51
~SwiftJIT ();
51
52
53
+ // / Get the dylib associated with the main program
52
54
llvm::orc::JITDylib &getMainJITDylib ();
53
55
54
56
// / Register a the materialization unit `MU` with the `JITDylib``JD` and
55
57
// / create lazy reexports for all functions defined in the interface of `MU`
56
58
llvm::Error addSwift (llvm::orc::JITDylib &JD,
57
59
std::unique_ptr<llvm::orc::MaterializationUnit> MU);
58
60
61
+ // / Return a linker-mangled version of `Name`
59
62
std::string mangle (llvm::StringRef Name);
60
63
61
- llvm::orc::SymbolStringPtr mangleAndIntern (llvm::StringRef Name);
62
-
64
+ // / Add a symbol name to the underlying `SymbolStringPool` and return
65
+ // / a pointer to it
63
66
llvm::orc::SymbolStringPtr intern (llvm::StringRef Name);
64
67
68
+ // / Return a linker-mangled version of `Name` and intern the result
69
+ llvm::orc::SymbolStringPtr mangleAndIntern (llvm::StringRef Name);
70
+
71
+ // / Get the `IRCompileLayer` associated with this `SwiftJIT`
65
72
llvm::orc::IRCompileLayer &getIRCompileLayer ();
66
73
74
+ // / Get the `ObjectTransformLayer` associated with this `SwiftJIT`
67
75
llvm::orc::ObjectTransformLayer &getObjTransformLayer ();
68
76
77
+ // / Initialize the main `JITDylib`, lookup the main symbol, execute it,
78
+ // / deinitialize the main `JITDylib`, and return the exit code of the
79
+ // / JIT'd program
69
80
llvm::Expected<int > runMain (llvm::ArrayRef<std::string> Args);
70
81
71
82
private:
@@ -100,10 +111,15 @@ class SwiftJIT {
100
111
std::unique_ptr<llvm::orc::IndirectStubsManager> ISM;
101
112
};
102
113
114
+ // / Lazily JITs a Swift AST using function at a time compilation
103
115
class LazySwiftMaterializationUnit : public llvm ::orc::MaterializationUnit {
104
116
public:
117
+
118
+ // / Create a new `LazySwiftMaterializationUnit` with the associated
119
+ // / JIT stack `JIT` and compiler instance `CI`
105
120
static std::unique_ptr<LazySwiftMaterializationUnit>
106
121
Create (SwiftJIT &JIT, CompilerInstance &CI);
122
+
107
123
llvm::StringRef getName () const override ;
108
124
109
125
private:
@@ -112,15 +128,21 @@ class LazySwiftMaterializationUnit : public llvm::orc::MaterializationUnit {
112
128
llvm::orc::SymbolFlagsMap Symbols);
113
129
void materialize (
114
130
std::unique_ptr<llvm::orc::MaterializationResponsibility> MR) override ;
131
+
115
132
void discard (const llvm::orc::JITDylib &JD,
116
133
const llvm::orc::SymbolStringPtr &Sym) override ;
134
+
117
135
SymbolSourceMap Sources;
118
136
SwiftJIT &JIT;
119
137
CompilerInstance &CI;
120
138
};
121
139
140
+ // / Eagerly materializes a whole `SILModule`
122
141
class EagerSwiftMaterializationUnit : public llvm ::orc::MaterializationUnit {
123
142
public:
143
+
144
+ // / Create a new `EagerSwiftMaterializationUnit` with the JIT stack `JIT`
145
+ // / and provided compiler options
124
146
EagerSwiftMaterializationUnit (SwiftJIT &JIT, const CompilerInstance &CI,
125
147
const IRGenOptions &IRGenOpts,
126
148
std::unique_ptr<SILModule> SM);
@@ -130,17 +152,22 @@ class EagerSwiftMaterializationUnit : public llvm::orc::MaterializationUnit {
130
152
private:
131
153
void materialize (
132
154
std::unique_ptr<llvm::orc::MaterializationResponsibility> MR) override ;
155
+
156
+ // / Get the linker-level interface defined by the `SILModule` being materialized
133
157
static MaterializationUnit::Interface
134
158
getInterface (SwiftJIT &JIT, const CompilerInstance &CI);
159
+
135
160
void dumpJIT (const llvm::Module &Module);
161
+
136
162
void discard (const llvm::orc::JITDylib &JD,
137
163
const llvm::orc::SymbolStringPtr &Sym) override ;
164
+
138
165
SwiftJIT &JIT;
139
166
const CompilerInstance &CI;
140
167
const IRGenOptions &IRGenOpts;
141
168
std::unique_ptr<SILModule> SM;
142
169
};
143
170
144
- } // namespace swift
171
+ } // end namespace swift
145
172
146
173
#endif // SWIFT_IMMEDIATE_SWIFTMATERIALIZATIONUNIT_H
0 commit comments