3838#include " swift/Subsystems.h"
3939#include " llvm/Config/config.h"
4040
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-
4941using namespace swift ;
5042
5143extern " C" void *swift_ASTGen_resolveMacroType (const void *macroType);
@@ -90,10 +82,10 @@ extern "C" bool swift_ASTGen_pluginServerLoadLibraryPlugin(
9082
9183#if SWIFT_SWIFT_PARSER
9284// / 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 ) {
9789 // Look up the type metadata accessor as a struct, enum, or class.
9890 const Demangle::Node::Kind typeKinds[] = {
9991 Demangle::Node::Kind::Structure,
@@ -105,11 +97,7 @@ static void const *lookupMacroTypeMetadataByExternalName(
10597 for (auto typeKind : typeKinds) {
10698 auto symbolName = Demangle::mangledNameForTypeMetadataAccessor (
10799 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 ());
113101 if (accessorAddr)
114102 break ;
115103 }
@@ -276,7 +264,8 @@ MacroDefinition MacroDefinitionRequest::evaluate(
276264}
277265
278266// / 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) {
280269 std::string libraryPath;
281270 if (auto found = ctx.lookupLibraryPluginByModuleName (moduleName)) {
282271 libraryPath = *found;
@@ -367,33 +356,28 @@ loadExecutablePluginByName(ASTContext &ctx, Identifier moduleName) {
367356LoadedCompilerPlugin
368357CompilerPluginLoadRequest::evaluate (Evaluator &evaluator, ASTContext *ctx,
369358 Identifier moduleName) const {
370- auto fs = ctx->SourceMgr .getFileSystem ();
371- auto &searchPathOpts = ctx->SearchPathOpts ;
372- auto *registry = ctx->getPluginRegistry ();
373-
374359 // Check dynamic link library plugins.
375360 // 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+ }
378364
379365 // Fall back to executable plugins.
380366 // i.e. '-external-plugin-path', and '-load-plugin-executable'.
381367 if (auto *found = loadExecutablePluginByName (*ctx, moduleName)) {
382- return LoadedCompilerPlugin::executable ( found) ;
368+ return found;
383369 }
384370
385371 return nullptr ;
386372}
387373
388374static 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) {
393377#if SWIFT_SWIFT_PARSER
394378 // / Look for the type metadata given the external module and type names.
395379 auto macroMetatype = lookupMacroTypeMetadataByExternalName (
396- ctx, moduleName.str (), typeName.str (), libraryHint );
380+ ctx, moduleName.str (), typeName.str (), plugin );
397381 if (macroMetatype) {
398382 // Check whether the macro metatype is in-process.
399383 if (auto inProcess = swift_ASTGen_resolveMacroType (macroMetatype)) {
@@ -438,7 +422,7 @@ ExternalMacroDefinitionRequest::evaluate(Evaluator &evaluator, ASTContext *ctx,
438422 LoadedCompilerPlugin loaded =
439423 evaluateOrDefault (evaluator, loadRequest, nullptr );
440424
441- if (auto loadedLibrary = loaded.getAsInProcessPlugin ()) {
425+ if (auto loadedLibrary = loaded.getAsLibraryPlugin ()) {
442426 if (auto inProcess = resolveInProcessMacro (
443427 *ctx, moduleName, typeName, loadedLibrary))
444428 return *inProcess;
0 commit comments