[RISCV] Fix mgather -> riscv.masked.strided.load combine not extending indices (...
[llvm-project.git] / llvm / lib / ObjCopy / CommonConfig.cpp
blobff3cb4d44c126ef7318a507759b3304979135992
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 //===----------------------------------------------------------------------===//
9 #include "llvm/ObjCopy/CommonConfig.h"
10 #include "llvm/Support/Errc.h"
12 namespace llvm {
13 namespace objcopy {
15 Expected<NameOrPattern>
16 NameOrPattern::create(StringRef Pattern, MatchStyle MS,
17 function_ref<Error(Error)> ErrorCallback) {
18 switch (MS) {
19 case MatchStyle::Literal:
20 return NameOrPattern(Pattern);
21 case MatchStyle::Wildcard: {
22 SmallVector<char, 32> Data;
23 bool IsPositiveMatch = !Pattern.consume_front("!");
24 Expected<GlobPattern> GlobOrErr = GlobPattern::create(Pattern);
26 // If we couldn't create it as a glob, report the error, but try again
27 // with a literal if the error reporting is non-fatal.
28 if (!GlobOrErr) {
29 if (Error E = ErrorCallback(GlobOrErr.takeError()))
30 return std::move(E);
31 return create(Pattern, MatchStyle::Literal, ErrorCallback);
34 return NameOrPattern(std::make_shared<GlobPattern>(*GlobOrErr),
35 IsPositiveMatch);
37 case MatchStyle::Regex: {
38 Regex RegEx(Pattern);
39 std::string Err;
40 if (!RegEx.isValid(Err))
41 return createStringError(errc::invalid_argument,
42 "cannot compile regular expression \'" +
43 Pattern + "\': " + Err);
44 SmallVector<char, 32> Data;
45 return NameOrPattern(std::make_shared<Regex>(
46 ("^" + Pattern.ltrim('^').rtrim('$') + "$").toStringRef(Data)));
49 llvm_unreachable("Unhandled llvm.objcopy.MatchStyle enum");
52 } // end namespace objcopy
53 } // end namespace llvm