LLVM  10.0.0svn
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) {
26  sys::SmartScopedLock<true> Lock(*PluginsLock);
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 
37  sys::SmartScopedLock<true> Lock(*PluginsLock);
38  return Plugins.isConstructed() ? Plugins->size() : 0;
39 }
40 
41 std::string &PluginLoader::getPlugin(unsigned num) {
42  sys::SmartScopedLock<true> Lock(*PluginsLock);
43  assert(Plugins.isConstructed() && num < Plugins->size() &&
44  "Asking for an out of bounds plugin");
45  return (*Plugins)[num];
46 }
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
This class represents lattice values for constants.
Definition: AllocatorList.h:23
void operator=(const std::string &Filename)
static sys::Mutex Lock
static ManagedStatic< sys::SmartMutex< true > > PluginsLock
static bool LoadLibraryPermanently(const char *Filename, std::string *ErrMsg=nullptr)
This function permanently loads the dynamic library at the given path.
static unsigned getNumPlugins()
static ManagedStatic< std::vector< std::string > > Plugins
std::lock_guard< SmartMutex< mt_only > > SmartScopedLock
Definition: Mutex.h:71
bool isConstructed() const
isConstructed - Return true if this object has not been created yet.
Definition: ManagedStatic.h:71
static std::string & getPlugin(unsigned num)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ManagedStatic - This transparently changes the behavior of global statics to be lazily constructed on...
Definition: ManagedStatic.h:83