1 //===- Strings.h ------------------------------------------------*- C++ -*-===//
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLD_ELF_STRINGS_H
11 #define LLD_ELF_STRINGS_H
13 #include "lld/Core/LLVM.h"
14 #include "llvm/ADT/ArrayRef.h"
15 #include "llvm/ADT/BitVector.h"
16 #include "llvm/ADT/Optional.h"
17 #include "llvm/ADT/StringRef.h"
18 #include "llvm/Support/GlobPattern.h"
24 std::vector<uint8_t> parseHex(StringRef S);
25 bool isValidCIdentifier(StringRef S);
27 // This is a lazy version of StringRef. String size is computed lazily
28 // when it is needed. It is more efficient than StringRef to instantiate
29 // if you have a string whose size is unknown.
31 // ELF string tables contain a lot of null-terminated strings.
32 // Most of them are not necessary for the linker because they are names
33 // of local symbols and the linker doesn't use local symbol names for
34 // name resolution. So, we use this class to represents strings read
35 // from string tables.
38 StringRefZ() : Start(nullptr), Size(0) {}
39 StringRefZ(const char *S, size_t Size) : Start(S), Size(Size) {}
41 /*implicit*/ StringRefZ(const char *S) : Start(S), Size(-1) {}
43 /*implicit*/ StringRefZ(llvm::StringRef S)
44 : Start(S.data()), Size(S.size()) {}
46 operator llvm::StringRef() const {
47 if (Size == (size_t)-1)
57 // This class represents multiple glob patterns.
60 StringMatcher() = default;
61 explicit StringMatcher(ArrayRef<StringRef> Pat);
63 bool match(StringRef S) const;
66 std::vector<llvm::GlobPattern> Patterns;
69 // Returns a demangled C++ symbol name. If Name is not a mangled
70 // name, it returns Optional::None.
71 llvm::Optional<std::string> demangle(StringRef Name);
73 inline ArrayRef<uint8_t> toArrayRef(StringRef S) {
74 return {(const uint8_t *)S.data(), S.size()};