LLVM  15.0.0git
CommonConfig.cpp
Go to the documentation of this file.
1 //===- CommonConfig.cpp ---------------------------------------------------===//
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 
10 
11 namespace llvm {
12 namespace objcopy {
13 
14 Expected<NameOrPattern>
16  function_ref<Error(Error)> ErrorCallback) {
17  switch (MS) {
19  return NameOrPattern(Pattern);
20  case MatchStyle::Wildcard: {
22  bool IsPositiveMatch = true;
23  if (Pattern[0] == '!') {
24  IsPositiveMatch = false;
25  Pattern = Pattern.drop_front();
26  }
28 
29  // If we couldn't create it as a glob, report the error, but try again
30  // with a literal if the error reporting is non-fatal.
31  if (!GlobOrErr) {
32  if (Error E = ErrorCallback(GlobOrErr.takeError()))
33  return std::move(E);
34  return create(Pattern, MatchStyle::Literal, ErrorCallback);
35  }
36 
37  return NameOrPattern(std::make_shared<GlobPattern>(*GlobOrErr),
38  IsPositiveMatch);
39  }
40  case MatchStyle::Regex: {
42  return NameOrPattern(std::make_shared<Regex>(
43  ("^" + Pattern.ltrim('^').rtrim('$') + "$").toStringRef(Data)));
44  }
45  }
46  llvm_unreachable("Unhandled llvm.objcopy.MatchStyle enum");
47 }
48 
49 } // end namespace objcopy
50 } // end namespace llvm
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::objcopy::MatchStyle::Wildcard
@ Wildcard
llvm::SmallVector< char, 32 >
llvm::objcopy::NameOrPattern
Definition: CommonConfig.h:98
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:41
llvm::Data
@ Data
Definition: SIMachineScheduler.h:55
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
CommonConfig.h
llvm::function_ref
An efficient, type-erasing, non-owning reference to a callable.
Definition: STLFunctionalExtras.h:36
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::GlobPattern::create
static Expected< GlobPattern > create(StringRef Pat)
Definition: GlobPattern.cpp:108
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:143
llvm::objcopy::MatchStyle::Literal
@ Literal
llvm::objcopy::MatchStyle
MatchStyle
Definition: CommonConfig.h:92
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:155
llvm::objcopy::NameOrPattern::create
static Expected< NameOrPattern > create(StringRef Pattern, MatchStyle MS, llvm::function_ref< Error(Error)> ErrorCallback)
Definition: CommonConfig.cpp:15
llvm::Expected::takeError
Error takeError()
Take ownership of the stored error.
Definition: Error.h:597
llvm::Pattern
Definition: FileCheckImpl.h:614
llvm::objcopy::MatchStyle::Regex
@ Regex