LLVM 19.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
16#include "llvm/Support/Mutex.h"
18#include <vector>
19using namespace llvm;
20
21namespace {
22
23struct Plugins {
25 std::vector<std::string> List;
26};
27
28Plugins &getPlugins() {
29 static Plugins P;
30 return P;
31}
32
33} // anonymous namespace
34
35void PluginLoader::operator=(const std::string &Filename) {
36 auto &P = getPlugins();
38 std::string Error;
39 if (sys::DynamicLibrary::LoadLibraryPermanently(Filename.c_str(), &Error)) {
40 errs() << "Error opening '" << Filename << "': " << Error
41 << "\n -load request ignored.\n";
42 } else {
43 P.List.push_back(Filename);
44 }
45}
46
48 auto &P = getPlugins();
50 return P.List.size();
51}
52
53std::string &PluginLoader::getPlugin(unsigned num) {
54 auto &P = getPlugins();
56 assert(num < P.List.size() && "Asking for an out of bounds plugin");
57 return P.List[num];
58}
#define P(N)
const NodeList & List
Definition: RDFGraph.cpp:201
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
static bool LoadLibraryPermanently(const char *Filename, std::string *ErrMsg=nullptr)
This function permanently loads the dynamic library at the given path.
SmartMutex - A mutex with a compile time constant parameter that indicates whether this mutex should ...
Definition: Mutex.h:28
std::lock_guard< SmartMutex< mt_only > > SmartScopedLock
Definition: Mutex.h:69
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
static std::string & getPlugin(unsigned num)
static unsigned getNumPlugins()
void operator=(const std::string &Filename)