This builds on the support being added to LLVM to import and export
registries from DLLs. This will allow us to pick up the registry
entries added in the DLL's copy of FrontendPluginRegistry.
This will allow us to use plugins on Windows using:
$ clang-cl -Xclang -load -Xclang plugin.dll \
-Xclang -add-plugin -Xclang foo
llvm-svn: 260265
====================
A plugin is loaded from a dynamic library at runtime by the compiler. To
-register a plugin in a library, use ``FrontendPluginRegistry::Add<>``:
+register a plugin in a library, use ``FrontendPluginRegistry::Add<>``.
+On Windows, you also need to export your plugin registry using
+``LLVM_EXPORT_REGISTRY``. Here is an example:
.. code-block:: c++
static FrontendPluginRegistry::Add<MyPlugin> X("my-plugin-name", "my plugin description");
+ LLVM_EXPORT_REGISTRY(FrontendPluginRegistry)
Putting it all together
=======================
static FrontendPluginRegistry::Add<PrintFunctionNamesAction>
X("print-fns", "print function names");
+LLVM_EXPORT_REGISTRY(FrontendPluginRegistry)
e = Clang->getFrontendOpts().Plugins.size(); i != e; ++i) {
const std::string &Path = Clang->getFrontendOpts().Plugins[i];
std::string Error;
- if (llvm::sys::DynamicLibrary::LoadLibraryPermanently(Path.c_str(), &Error))
+ llvm::sys::DynamicLibrary DL(
+ llvm::sys::DynamicLibrary::getPermanentLibrary(Path.c_str(), &Error));
+ if (DL.isValid()) {
+ // On Windows, we need to import the plugin front-end action
+ // dynamically.
+ LLVM_IMPORT_REGISTRY(FrontendPluginRegistry, DL);
+ } else {
Clang->getDiagnostics().Report(diag::err_fe_unable_to_load_plugin)
<< Path << Error;
+ }
}
// Honor -mllvm.