1 //===-- llvm/Support/Mangler.h - Self-contained name mangler ----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Unified name mangler for various backends.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_SUPPORT_MANGLER_H
15 #define LLVM_SUPPORT_MANGLER_H
17 #include "llvm/ADT/DenseMap.h"
18 #include "llvm/ADT/SmallPtrSet.h"
27 template <typename T> class SmallVectorImpl;
31 enum ManglerPrefixTy {
32 Default, ///< Emit default string before each symbol.
33 Private, ///< Emit "private" prefix before each symbol.
34 LinkerPrivate ///< Emit "linker private" prefix before each symbol.
38 /// Prefix - This string is added to each symbol that is emitted, unless the
39 /// symbol is marked as not needing this prefix.
42 /// PrivatePrefix - This string is emitted before each symbol with private
44 const char *PrivatePrefix;
46 /// LinkerPrivatePrefix - This string is emitted before each symbol with
47 /// "linker_private" linkage.
48 const char *LinkerPrivatePrefix;
50 /// UseQuotes - If this is set, the target accepts global names in quotes,
51 /// e.g. "foo bar" is a legal name. This syntax is used instead of escaping
52 /// the space character. By default, this is false.
55 /// SymbolsCanStartWithDigit - If this is set, the target allows symbols to
56 /// start with digits (e.g., "0x0021"). By default, this is false.
57 bool SymbolsCanStartWithDigit;
59 /// AnonGlobalIDs - We need to give global values the same name every time
60 /// they are mangled. This keeps track of the number we give to anonymous
63 DenseMap<const GlobalValue*, unsigned> AnonGlobalIDs;
65 /// NextAnonGlobalID - This simple counter is used to unique value names.
67 unsigned NextAnonGlobalID;
69 /// AcceptableChars - This bitfield contains a one for each character that is
70 /// allowed to be part of an unmangled name.
71 unsigned AcceptableChars[256 / 32];
74 // Mangler ctor - if a prefix is specified, it will be prepended onto all
76 Mangler(Module &M, const char *Prefix = "", const char *privatePrefix = "",
77 const char *linkerPrivatePrefix = "");
79 /// setUseQuotes - If UseQuotes is set to true, this target accepts quoted
80 /// strings for assembler labels.
81 void setUseQuotes(bool Val) { UseQuotes = Val; }
83 /// setSymbolsCanStartWithDigit - If SymbolsCanStartWithDigit is set to true,
84 /// this target allows symbols to start with digits.
85 void setSymbolsCanStartWithDigit(bool Val) { SymbolsCanStartWithDigit = Val; }
87 /// Acceptable Characters - This allows the target to specify which characters
88 /// are acceptable to the assembler without being mangled. By default we
89 /// allow letters, numbers, '_', '$', '.', which is what GAS accepts, and '@'.
90 void markCharAcceptable(unsigned char X) {
91 AcceptableChars[X/32] |= 1 << (X&31);
93 void markCharUnacceptable(unsigned char X) {
94 AcceptableChars[X/32] &= ~(1 << (X&31));
96 bool isCharAcceptable(unsigned char X) const {
97 return (AcceptableChars[X/32] & (1 << (X&31))) != 0;
100 /// getMangledName - Returns the mangled name of V, an LLVM Value,
101 /// in the current module. If 'Suffix' is specified, the name ends with the
102 /// specified suffix. If 'ForcePrivate' is specified, the label is specified
103 /// to have a private label prefix.
105 /// FIXME: This is deprecated, new code should use getNameWithPrefix and use
106 /// MCSymbol printing to handle quotes or not etc.
108 std::string getMangledName(const GlobalValue *V, const char *Suffix = "",
109 bool ForcePrivate = false);
111 /// getNameWithPrefix - Fill OutName with the name of the appropriate prefix
112 /// and the specified global variable's name. If the global variable doesn't
113 /// have a name, this fills in a unique name for the global.
114 void getNameWithPrefix(SmallVectorImpl<char> &OutName, const GlobalValue *GV,
115 bool isImplicitlyPrivate);
117 /// getNameWithPrefix - Fill OutName with the name of the appropriate prefix
118 /// and the specified name as the global variable name. GVName must not be
120 void getNameWithPrefix(SmallVectorImpl<char> &OutName, const Twine &GVName,
121 ManglerPrefixTy PrefixTy = Mangler::Default);
124 /// makeNameProper - We don't want identifier names with ., space, or
125 /// - in them, so we mangle these characters into the strings "d_",
126 /// "s_", and "D_", respectively. This is a very simple mangling that
127 /// doesn't guarantee unique names for values. getValueName already
128 /// does this for you, so there's no point calling it on the result
129 /// from getValueName.
131 /// FIXME: This is deprecated, new code should use getNameWithPrefix and use
132 /// MCSymbol printing to handle quotes or not etc.
134 void makeNameProper(SmallVectorImpl<char> &OutName,
136 ManglerPrefixTy PrefixTy = Mangler::Default);
140 } // End llvm namespace
142 #endif // LLVM_SUPPORT_MANGLER_H