2016-06-29 16:01:32 +08:00
|
|
|
//===- Strings.h ------------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Linker
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2016-09-16 06:26:07 +08:00
|
|
|
#ifndef LLD_ELF_STRINGS_H
|
|
|
|
#define LLD_ELF_STRINGS_H
|
2016-06-29 16:01:32 +08:00
|
|
|
|
|
|
|
#include "lld/Core/LLVM.h"
|
2016-10-13 08:13:15 +08:00
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
2016-11-04 01:57:38 +08:00
|
|
|
#include "llvm/ADT/BitVector.h"
|
|
|
|
#include "llvm/ADT/Optional.h"
|
2016-10-13 08:13:15 +08:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2016-06-29 16:01:32 +08:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace lld {
|
|
|
|
namespace elf {
|
2016-11-04 01:57:38 +08:00
|
|
|
|
2016-09-16 03:15:12 +08:00
|
|
|
int getPriority(StringRef S);
|
2016-09-03 05:17:20 +08:00
|
|
|
bool hasWildcard(StringRef S);
|
2016-06-29 16:01:32 +08:00
|
|
|
std::vector<uint8_t> parseHex(StringRef S);
|
2016-06-29 17:08:02 +08:00
|
|
|
bool isValidCIdentifier(StringRef S);
|
2016-09-09 22:35:36 +08:00
|
|
|
StringRef unquote(StringRef S);
|
2016-07-08 07:04:15 +08:00
|
|
|
|
2016-11-04 01:57:38 +08:00
|
|
|
// This class represents a glob pattern. Supported metacharacters
|
|
|
|
// are "*", "?", "[<chars>]" and "[^<chars>]".
|
|
|
|
class GlobPattern {
|
|
|
|
public:
|
|
|
|
explicit GlobPattern(StringRef Pat);
|
|
|
|
bool match(StringRef S) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool matchOne(ArrayRef<llvm::BitVector> Pat, StringRef S) const;
|
|
|
|
llvm::BitVector scan(StringRef &S);
|
|
|
|
llvm::BitVector expand(StringRef S);
|
|
|
|
|
|
|
|
// Parsed glob pattern.
|
|
|
|
std::vector<llvm::BitVector> Tokens;
|
|
|
|
|
|
|
|
// A glob pattern given to this class. This is for error reporting.
|
|
|
|
StringRef Original;
|
|
|
|
|
|
|
|
// The following members are for optimization.
|
|
|
|
llvm::Optional<StringRef> Exact;
|
|
|
|
llvm::Optional<StringRef> Prefix;
|
|
|
|
llvm::Optional<StringRef> Suffix;
|
|
|
|
};
|
|
|
|
|
|
|
|
// This class represents multiple glob patterns.
|
2016-11-03 18:54:58 +08:00
|
|
|
class StringMatcher {
|
|
|
|
public:
|
|
|
|
StringMatcher() = default;
|
2016-11-04 01:57:38 +08:00
|
|
|
explicit StringMatcher(const std::vector<StringRef> &Pat);
|
|
|
|
|
|
|
|
bool match(StringRef S) const;
|
2016-11-03 18:54:58 +08:00
|
|
|
|
|
|
|
private:
|
2016-11-04 01:57:38 +08:00
|
|
|
std::vector<GlobPattern> Patterns;
|
2016-11-03 18:54:58 +08:00
|
|
|
};
|
|
|
|
|
2016-07-08 07:04:15 +08:00
|
|
|
// Returns a demangled C++ symbol name. If Name is not a mangled
|
|
|
|
// name or the system does not provide __cxa_demangle function,
|
|
|
|
// it returns an unmodified string.
|
|
|
|
std::string demangle(StringRef Name);
|
2016-10-13 08:13:15 +08:00
|
|
|
|
2016-10-27 02:28:06 +08:00
|
|
|
// Demangle if Config->Demangle is true.
|
|
|
|
std::string maybeDemangle(StringRef Name);
|
|
|
|
|
2016-10-13 08:13:15 +08:00
|
|
|
inline StringRef toStringRef(ArrayRef<uint8_t> Arr) {
|
|
|
|
return {(const char *)Arr.data(), Arr.size()};
|
|
|
|
}
|
2016-06-29 16:01:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|