18#include <system_error>
29 auto Matches = [RegisteredName](
StringRef Candidate) {
30 size_t Position = Candidate.rfind_insensitive(RegisteredName);
32 (Position + RegisteredName.
size() == Candidate.size() ||
35 return Matches(Stem) || Matches(
Filename);
38bool isMulticallName(
StringRef Name) {
return matchesToolName(
"llvm", Name); }
45 std::vector<std::pair<std::string, ToolMainFn>>
Tools;
48 bool InstallPipeSignalExitHandler,
bool NeedsPOSIXUtilitySignalHandling)
50 NeedsPOSIXUtilitySignalHandling),
54 Tools.emplace_back(Tool.Name.str(), Tool.Main);
59 bool InstallPipeSignalExitHandler,
60 bool NeedsPOSIXUtilitySignalHandling) {
61 assert(Argc > 0 && Argv && Argv[0] &&
"ToolSession requires a valid argv[0]");
63 std::make_unique<Impl>(Argc, Argv, Tools, InstallPipeSignalExitHandler,
64 NeedsPOSIXUtilitySignalHandling);
72 for (
const auto &[RegisteredName, Main] : PImpl->Tools)
74 Filename.equals_insensitive(RegisteredName))
77 for (
const auto &[RegisteredName, Main] : PImpl->Tools)
78 if (matchesToolName(RegisteredName, Name))
84 const char *PrependArg) {
85 ErrorOr<CallableTool> ExecutableTool = findTool(PImpl->ExecutablePath);
86 bool NeedsPrependArg =
88 !ExecutableTool->Name.equals_insensitive(RegisteredName);
102 if (InvokedName != PImpl->ExecutablePath && !isMulticallName(InvokedName))
104 Args = Args.drop_front();
107 InvokedName = Args.front();
108 Tool = findTool(InvokedName);
115 ToolContext Context = makeContext(Tool->Name, PrependArg.c_str());
117 MutableArgs.
reserve(Args.size() + 1);
118 for (
const char *Arg : Args)
119 MutableArgs.
push_back(
const_cast<char *
>(Arg));
121 return Tool->Main(Args.size(), MutableArgs.
data(), Context);
127 return Session->findTool(Name);
133 return Session->callTool(Args);
for(const MachineOperand &MO :llvm::drop_begin(OldMI.operands(), Desc.getNumOperands()))
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static constexpr StringLiteral Filename
This file defines the SmallVector class.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
Get the array size.
Represents either an error or a value T.
std::error_code getError() const
void reserve(size_type N)
void push_back(const T &Elt)
pointer data()
Return a pointer to the vector's buffer, even if empty().
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
static constexpr size_t npos
std::string str() const
Get the contents as an std::string.
constexpr size_t size() const
Get the string size.
bool equals_insensitive(StringRef RHS) const
Check for string equality, ignoring case.
Describes how a tool was invoked and provides access to its host session.
LLVM_ABI ErrorOr< int > callTool(ArrayRef< const char * > Args) const
Invokes another tool registered with the same host session.
LLVM_ABI ErrorOr< CallableTool > getCallableTool(StringRef Name) const
Finds a tool registered with the session that owns this context.
LLVM_ABI StringRef stem(StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get stem.
LLVM_ABI StringRef filename(StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get filename.
This is an optimization pass for GlobalISel generic memory operations.
std::error_code make_error_code(BitcodeError E)
bool isAlnum(char C)
Checks whether character C is either a decimal digit or an uppercase or lowercase letter as classifie...