/3rd_party/llvm/lib/Support/PluginLoader.cpp

https://code.google.com/p/softart/ · C++ · 47 lines · 30 code · 5 blank · 12 comment · 3 complexity · 837e418b5b543bc6a0bea9ee52dca636 MD5 · raw file

  1. //===-- PluginLoader.cpp - Implement -load command line option ------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file implements the -load <plugin> command line option handler.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #define DONT_GET_PLUGIN_LOADER_OPTION
  14. #include "llvm/Support/PluginLoader.h"
  15. #include "llvm/Support/DynamicLibrary.h"
  16. #include "llvm/Support/ManagedStatic.h"
  17. #include "llvm/Support/Mutex.h"
  18. #include "llvm/Support/raw_ostream.h"
  19. #include <vector>
  20. using namespace llvm;
  21. static ManagedStatic<std::vector<std::string> > Plugins;
  22. static ManagedStatic<sys::SmartMutex<true> > PluginsLock;
  23. void PluginLoader::operator=(const std::string &Filename) {
  24. sys::SmartScopedLock<true> Lock(*PluginsLock);
  25. std::string Error;
  26. if (sys::DynamicLibrary::LoadLibraryPermanently(Filename.c_str(), &Error)) {
  27. errs() << "Error opening '" << Filename << "': " << Error
  28. << "\n -load request ignored.\n";
  29. } else {
  30. Plugins->push_back(Filename);
  31. }
  32. }
  33. unsigned PluginLoader::getNumPlugins() {
  34. sys::SmartScopedLock<true> Lock(*PluginsLock);
  35. return Plugins.isConstructed() ? Plugins->size() : 0;
  36. }
  37. std::string &PluginLoader::getPlugin(unsigned num) {
  38. sys::SmartScopedLock<true> Lock(*PluginsLock);
  39. assert(Plugins.isConstructed() && num < Plugins->size() &&
  40. "Asking for an out of bounds plugin");
  41. return (*Plugins)[num];
  42. }