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,10 +356,6 @@ 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'.
376361 if (auto found = loadLibraryPluginByName (*ctx, moduleName))
@@ -386,14 +371,12 @@ CompilerPluginLoadRequest::evaluate(Evaluator &evaluator, ASTContext *ctx,
386371}
387372
388373static Optional<ExternalMacroDefinition>
389- resolveInProcessMacro (
390- ASTContext &ctx, Identifier moduleName, Identifier typeName,
391- void *libraryHint = nullptr
392- ) {
374+ resolveInProcessMacro (ASTContext &ctx, Identifier moduleName,
375+ Identifier typeName, LoadedLibraryPlugin *plugin) {
393376#if SWIFT_SWIFT_PARSER
394377 // / Look for the type metadata given the external module and type names.
395378 auto macroMetatype = lookupMacroTypeMetadataByExternalName (
396- ctx, moduleName.str (), typeName.str (), libraryHint );
379+ ctx, moduleName.str (), typeName.str (), plugin );
397380 if (macroMetatype) {
398381 // Check whether the macro metatype is in-process.
399382 if (auto inProcess = swift_ASTGen_resolveMacroType (macroMetatype)) {
0 commit comments