38
38
#include " swift/Subsystems.h"
39
39
#include " llvm/Config/config.h"
40
40
41
- #if defined(_WIN32)
42
- #define WIN32_LEAN_AND_MEAN
43
- #define NOMINMAX
44
- #include < windows.h>
45
- #else
46
- #include < dlfcn.h>
47
- #endif
48
-
49
41
using namespace swift ;
50
42
51
43
extern " C" void *swift_ASTGen_resolveMacroType (const void *macroType);
@@ -90,10 +82,10 @@ extern "C" bool swift_ASTGen_pluginServerLoadLibraryPlugin(
90
82
91
83
#if SWIFT_SWIFT_PARSER
92
84
// / Look for macro's type metadata given its external module and type name.
93
- static void const *lookupMacroTypeMetadataByExternalName (
94
- ASTContext &ctx, StringRef moduleName, StringRef typeName ,
95
- void *libraryHint = nullptr
96
- ) {
85
+ static void const *
86
+ lookupMacroTypeMetadataByExternalName ( ASTContext &ctx, StringRef moduleName,
87
+ StringRef typeName,
88
+ LoadedLibraryPlugin *plugin ) {
97
89
// Look up the type metadata accessor as a struct, enum, or class.
98
90
const Demangle::Node::Kind typeKinds[] = {
99
91
Demangle::Node::Kind::Structure,
@@ -105,11 +97,7 @@ static void const *lookupMacroTypeMetadataByExternalName(
105
97
for (auto typeKind : typeKinds) {
106
98
auto symbolName = Demangle::mangledNameForTypeMetadataAccessor (
107
99
moduleName, typeName, typeKind);
108
- #if !defined(_WIN32)
109
- // / FIXME: 'PluginRegistry' should vend a wrapper object of the library
110
- // / handle (like llvm::sys::DynamicLibrary) and dlsym should be abstracted.
111
- accessorAddr = dlsym (libraryHint, symbolName.c_str ());
112
- #endif
100
+ accessorAddr = plugin->getAddressOfSymbol (symbolName.c_str ());
113
101
if (accessorAddr)
114
102
break ;
115
103
}
@@ -276,7 +264,8 @@ MacroDefinition MacroDefinitionRequest::evaluate(
276
264
}
277
265
278
266
// / Load a plugin library based on a module name.
279
- static void *loadLibraryPluginByName (ASTContext &ctx, Identifier moduleName) {
267
+ static LoadedLibraryPlugin *loadLibraryPluginByName (ASTContext &ctx,
268
+ Identifier moduleName) {
280
269
std::string libraryPath;
281
270
if (auto found = ctx.lookupLibraryPluginByModuleName (moduleName)) {
282
271
libraryPath = *found;
@@ -367,33 +356,28 @@ loadExecutablePluginByName(ASTContext &ctx, Identifier moduleName) {
367
356
LoadedCompilerPlugin
368
357
CompilerPluginLoadRequest::evaluate (Evaluator &evaluator, ASTContext *ctx,
369
358
Identifier moduleName) const {
370
- auto fs = ctx->SourceMgr .getFileSystem ();
371
- auto &searchPathOpts = ctx->SearchPathOpts ;
372
- auto *registry = ctx->getPluginRegistry ();
373
-
374
359
// Check dynamic link library plugins.
375
360
// i.e. '-plugin-path', and '-load-plugin-library'.
376
- if (auto found = loadLibraryPluginByName (*ctx, moduleName))
377
- return LoadedCompilerPlugin::inProcess (found);
361
+ if (auto found = loadLibraryPluginByName (*ctx, moduleName)) {
362
+ return found;
363
+ }
378
364
379
365
// Fall back to executable plugins.
380
366
// i.e. '-external-plugin-path', and '-load-plugin-executable'.
381
367
if (auto *found = loadExecutablePluginByName (*ctx, moduleName)) {
382
- return LoadedCompilerPlugin::executable ( found) ;
368
+ return found;
383
369
}
384
370
385
371
return nullptr ;
386
372
}
387
373
388
374
static Optional<ExternalMacroDefinition>
389
- resolveInProcessMacro (
390
- ASTContext &ctx, Identifier moduleName, Identifier typeName,
391
- void *libraryHint = nullptr
392
- ) {
375
+ resolveInProcessMacro (ASTContext &ctx, Identifier moduleName,
376
+ Identifier typeName, LoadedLibraryPlugin *plugin) {
393
377
#if SWIFT_SWIFT_PARSER
394
378
// / Look for the type metadata given the external module and type names.
395
379
auto macroMetatype = lookupMacroTypeMetadataByExternalName (
396
- ctx, moduleName.str (), typeName.str (), libraryHint );
380
+ ctx, moduleName.str (), typeName.str (), plugin );
397
381
if (macroMetatype) {
398
382
// Check whether the macro metatype is in-process.
399
383
if (auto inProcess = swift_ASTGen_resolveMacroType (macroMetatype)) {
@@ -438,7 +422,7 @@ ExternalMacroDefinitionRequest::evaluate(Evaluator &evaluator, ASTContext *ctx,
438
422
LoadedCompilerPlugin loaded =
439
423
evaluateOrDefault (evaluator, loadRequest, nullptr );
440
424
441
- if (auto loadedLibrary = loaded.getAsInProcessPlugin ()) {
425
+ if (auto loadedLibrary = loaded.getAsLibraryPlugin ()) {
442
426
if (auto inProcess = resolveInProcessMacro (
443
427
*ctx, moduleName, typeName, loadedLibrary))
444
428
return *inProcess;
0 commit comments