Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line | 
|---|---|---|---|
| 14 | pmbaty | 1 | //===--- ItaniumManglingCanonicalizer.h -------------------------*- C++ -*-===// | 
| 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 | // | ||
| 9 | // This file defines a class for computing equivalence classes of mangled names | ||
| 10 | // given a set of equivalences between name fragments. | ||
| 11 | // | ||
| 12 | //===----------------------------------------------------------------------===// | ||
| 13 | |||
| 14 | #ifndef LLVM_SUPPORT_ITANIUMMANGLINGCANONICALIZER_H | ||
| 15 | #define LLVM_SUPPORT_ITANIUMMANGLINGCANONICALIZER_H | ||
| 16 | |||
| 17 | #include <cstdint> | ||
| 18 | |||
| 19 | namespace llvm { | ||
| 20 | |||
| 21 | class StringRef; | ||
| 22 | |||
| 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 | |||
| 42 | enum class EquivalenceError { | ||
| 43 | Success, | ||
| 44 | |||
| 45 |     /// Both the equivalent manglings have already been used as components of | ||
| 46 |     /// some other mangling we've looked at. It's too late to add this | ||
| 47 |     /// equivalence. | ||
| 48 | ManglingAlreadyUsed, | ||
| 49 | |||
| 50 |     /// The first equivalent mangling is invalid. | ||
| 51 | InvalidFirstMangling, | ||
| 52 | |||
| 53 |     /// The second equivalent mangling is invalid. | ||
| 54 | InvalidSecondMangling, | ||
| 55 | }; | ||
| 56 | |||
| 57 | enum class FragmentKind { | ||
| 58 |     /// The mangling fragment is a <name> (or a predefined <substitution>). | ||
| 59 | Name, | ||
| 60 |     /// The mangling fragment is a <type>. | ||
| 61 | Type, | ||
| 62 |     /// The mangling fragment is an <encoding>. | ||
| 63 | Encoding, | ||
| 64 | }; | ||
| 65 | |||
| 66 |   /// Add an equivalence between \p First and \p Second. Both manglings must | ||
| 67 |   /// live at least as long as the canonicalizer. | ||
| 68 |   EquivalenceError addEquivalence(FragmentKind Kind, StringRef First, | ||
| 69 | StringRef Second); | ||
| 70 | |||
| 71 | using Key = uintptr_t; | ||
| 72 | |||
| 73 |   /// Form a canonical key for the specified mangling. They key will be the | ||
| 74 |   /// same for all equivalent manglings, and different for any two | ||
| 75 |   /// non-equivalent manglings, but is otherwise unspecified. | ||
| 76 |   /// | ||
| 77 |   /// Returns Key() if (and only if) the mangling is not a valid Itanium C++ | ||
| 78 |   /// ABI mangling. | ||
| 79 |   /// | ||
| 80 |   /// The string denoted by Mangling must live as long as the canonicalizer. | ||
| 81 | Key canonicalize(StringRef Mangling); | ||
| 82 | |||
| 83 |   /// Find a canonical key for the specified mangling, if one has already been | ||
| 84 |   /// formed. Otherwise returns Key(). | ||
| 85 | Key lookup(StringRef Mangling); | ||
| 86 | |||
| 87 | private: | ||
| 88 | struct Impl; | ||
| 89 | Impl *P; | ||
| 90 | }; | ||
| 91 | } // namespace llvm | ||
| 92 | |||
| 93 | #endif // LLVM_SUPPORT_ITANIUMMANGLINGCANONICALIZER_H |