ItaniumManglingCanonicalizer.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===--- ItaniumManglingCanonicalizer.h -------------------------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This file defines a class for computing equivalence classes of mangled names
  15. // given a set of equivalences between name fragments.
  16. //
  17. //===----------------------------------------------------------------------===//
  18. #ifndef LLVM_SUPPORT_ITANIUMMANGLINGCANONICALIZER_H
  19. #define LLVM_SUPPORT_ITANIUMMANGLINGCANONICALIZER_H
  20. #include <cstdint>
  21. namespace llvm {
  22. class StringRef;
  23. /// Canonicalizer for mangled names.
  24. ///
  25. /// This class allows specifying a list of "equivalent" manglings. For example,
  26. /// you can specify that Ss is equivalent to
  27. /// NSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEE
  28. /// and then manglings that refer to libstdc++'s 'std::string' will be
  29. /// considered equivalent to manglings that are the same except that they refer
  30. /// to libc++'s 'std::string'.
  31. ///
  32. /// This can be used when data (eg, profiling data) is available for a version
  33. /// of a program built in a different configuration, with correspondingly
  34. /// different manglings.
  35. class ItaniumManglingCanonicalizer {
  36. public:
  37. ItaniumManglingCanonicalizer();
  38. ItaniumManglingCanonicalizer(const ItaniumManglingCanonicalizer &) = delete;
  39. void operator=(const ItaniumManglingCanonicalizer &) = delete;
  40. ~ItaniumManglingCanonicalizer();
  41. enum class EquivalenceError {
  42. Success,
  43. /// Both the equivalent manglings have already been used as components of
  44. /// some other mangling we've looked at. It's too late to add this
  45. /// equivalence.
  46. ManglingAlreadyUsed,
  47. /// The first equivalent mangling is invalid.
  48. InvalidFirstMangling,
  49. /// The second equivalent mangling is invalid.
  50. InvalidSecondMangling,
  51. };
  52. enum class FragmentKind {
  53. /// The mangling fragment is a <name> (or a predefined <substitution>).
  54. Name,
  55. /// The mangling fragment is a <type>.
  56. Type,
  57. /// The mangling fragment is an <encoding>.
  58. Encoding,
  59. };
  60. /// Add an equivalence between \p First and \p Second. Both manglings must
  61. /// live at least as long as the canonicalizer.
  62. EquivalenceError addEquivalence(FragmentKind Kind, StringRef First,
  63. StringRef Second);
  64. using Key = uintptr_t;
  65. /// Form a canonical key for the specified mangling. They key will be the
  66. /// same for all equivalent manglings, and different for any two
  67. /// non-equivalent manglings, but is otherwise unspecified.
  68. ///
  69. /// Returns Key() if (and only if) the mangling is not a valid Itanium C++
  70. /// ABI mangling.
  71. ///
  72. /// The string denoted by Mangling must live as long as the canonicalizer.
  73. Key canonicalize(StringRef Mangling);
  74. /// Find a canonical key for the specified mangling, if one has already been
  75. /// formed. Otherwise returns Key().
  76. Key lookup(StringRef Mangling);
  77. private:
  78. struct Impl;
  79. Impl *P;
  80. };
  81. } // namespace llvm
  82. #endif // LLVM_SUPPORT_ITANIUMMANGLINGCANONICALIZER_H
  83. #ifdef __GNUC__
  84. #pragma GCC diagnostic pop
  85. #endif