LLVM  13.0.0git
PluginLoader.cpp
Go to the documentation of this file.
1 //===-- PluginLoader.cpp - Implement -load command line option ------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements the -load <plugin> command line option handler.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #define DONT_GET_PLUGIN_LOADER_OPTION
17 #include "llvm/Support/Mutex.h"
19 #include <vector>
20 using namespace llvm;
21 
24 
25 void PluginLoader::operator=(const std::string &Filename) {
27  std::string Error;
28  if (sys::DynamicLibrary::LoadLibraryPermanently(Filename.c_str(), &Error)) {
29  errs() << "Error opening '" << Filename << "': " << Error
30  << "\n -load request ignored.\n";
31  } else {
32  Plugins->push_back(Filename);
33  }
34 }
35 
38  return Plugins.isConstructed() ? Plugins->size() : 0;
39 }
40 
41 std::string &PluginLoader::getPlugin(unsigned num) {
43  assert(Plugins.isConstructed() && num < Plugins->size() &&
44  "Asking for an out of bounds plugin");
45  return (*Plugins)[num];
46 }
PluginLoader.h
llvm
Definition: AllocatorList.h:23
Plugins
static ManagedStatic< std::vector< std::string > > Plugins
Definition: PluginLoader.cpp:22
ManagedStatic.h
DynamicLibrary.h
llvm::errs
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
Definition: raw_ostream.cpp:892
llvm::Lock
static sys::Mutex Lock
Definition: NVPTXUtilities.cpp:39
llvm::ManagedStatic
ManagedStatic - This transparently changes the behavior of global statics to be lazily constructed on...
Definition: ManagedStatic.h:83
llvm::PluginLoader::getNumPlugins
static unsigned getNumPlugins()
Definition: PluginLoader.cpp:36
llvm::sys::SmartScopedLock
std::lock_guard< SmartMutex< mt_only > > SmartScopedLock
Definition: Mutex.h:71
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::PluginLoader::operator=
void operator=(const std::string &Filename)
Definition: PluginLoader.cpp:25
llvm::size
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
Definition: STLExtras.h:1463
Mutex.h
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
llvm::sys::DynamicLibrary::LoadLibraryPermanently
static bool LoadLibraryPermanently(const char *Filename, std::string *ErrMsg=nullptr)
This function permanently loads the dynamic library at the given path.
Definition: DynamicLibrary.h:85
raw_ostream.h
PluginsLock
static ManagedStatic< sys::SmartMutex< true > > PluginsLock
Definition: PluginLoader.cpp:23
llvm::PluginLoader::getPlugin
static std::string & getPlugin(unsigned num)
Definition: PluginLoader.cpp:41