1 //===- lib/Passes/PassPluginLoader.cpp - Load Plugins for New PM Passes ---===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/Passes/PassPlugin.h"
11 #include "llvm/Support/raw_ostream.h"
17 Expected
<PassPlugin
> PassPlugin::Load(const std::string
&Filename
) {
20 sys::DynamicLibrary::getPermanentLibrary(Filename
.c_str(), &Error
);
21 if (!Library
.isValid())
22 return make_error
<StringError
>(Twine("Could not load library '") +
23 Filename
+ "': " + Error
,
24 inconvertibleErrorCode());
26 PassPlugin P
{Filename
, Library
};
27 intptr_t getDetailsFn
=
28 (intptr_t)Library
.SearchForAddressOfSymbol("llvmGetPassPluginInfo");
31 // If the symbol isn't found, this is probably a legacy plugin, which is an
33 return make_error
<StringError
>(Twine("Plugin entry point not found in '") +
34 Filename
+ "'. Is this a legacy plugin?",
35 inconvertibleErrorCode());
37 P
.Info
= reinterpret_cast<decltype(llvmGetPassPluginInfo
) *>(getDetailsFn
)();
39 if (P
.Info
.APIVersion
!= LLVM_PLUGIN_API_VERSION
)
40 return make_error
<StringError
>(
41 Twine("Wrong API version on plugin '") + Filename
+ "'. Got version " +
42 Twine(P
.Info
.APIVersion
) + ", supported version is " +
43 Twine(LLVM_PLUGIN_API_VERSION
) + ".",
44 inconvertibleErrorCode());
46 if (!P
.Info
.RegisterPassBuilderCallbacks
)
47 return make_error
<StringError
>(Twine("Empty entry callback in plugin '") +
49 inconvertibleErrorCode());