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"
26 template <typename T> class SmallVectorImpl;
30 enum ManglerPrefixTy {
31 Default, ///< Emit default string before each symbol.
32 Private, ///< Emit "private" prefix before each symbol.
33 LinkerPrivate ///< Emit "linker private" prefix before each symbol.
37 /// Prefix - This string is added to each symbol that is emitted, unless the
38 /// symbol is marked as not needing this prefix.
41 /// PrivatePrefix - This string is emitted before each symbol with private
43 const char *PrivatePrefix;
45 /// LinkerPrivatePrefix - This string is emitted before each symbol with
46 /// "linker_private" linkage.
47 const char *LinkerPrivatePrefix;
49 /// UseQuotes - If this is set, the target accepts global names in quotes,
50 /// e.g. "foo bar" is a legal name. This syntax is used instead of escaping
51 /// the space character. By default, this is false.
54 /// SymbolsCanStartWithDigit - If this is set, the target allows symbols to
55 /// start with digits (e.g., "0x0021"). By default, this is false.
56 bool SymbolsCanStartWithDigit;
58 /// AnonGlobalIDs - We need to give global values the same name every time
59 /// they are mangled. This keeps track of the number we give to anonymous
62 DenseMap<const GlobalValue*, unsigned> AnonGlobalIDs;
64 /// NextAnonGlobalID - This simple counter is used to unique value names.
66 unsigned NextAnonGlobalID;
68 /// AcceptableChars - This bitfield contains a one for each character that is
69 /// allowed to be part of an unmangled name.
70 unsigned AcceptableChars[256 / 32];
73 // Mangler ctor - if a prefix is specified, it will be prepended onto all
75 Mangler(Module &M, const char *Prefix = "", const char *privatePrefix = "",
76 const char *linkerPrivatePrefix = "");
78 /// setUseQuotes - If UseQuotes is set to true, this target accepts quoted
79 /// strings for assembler labels.
80 void setUseQuotes(bool Val) { UseQuotes = Val; }
82 /// setSymbolsCanStartWithDigit - If SymbolsCanStartWithDigit is set to true,
83 /// this target allows symbols to start with digits.
84 void setSymbolsCanStartWithDigit(bool Val) { SymbolsCanStartWithDigit = Val; }
86 /// Acceptable Characters - This allows the target to specify which characters
87 /// are acceptable to the assembler without being mangled. By default we
88 /// allow letters, numbers, '_', '$', '.', which is what GAS accepts, and '@'.
89 void markCharAcceptable(unsigned char X) {
90 AcceptableChars[X/32] |= 1 << (X&31);
92 void markCharUnacceptable(unsigned char X) {
93 AcceptableChars[X/32] &= ~(1 << (X&31));
95 bool isCharAcceptable(unsigned char X) const {
96 return (AcceptableChars[X/32] & (1 << (X&31))) != 0;
99 /// getMangledName - Returns the mangled name of V, an LLVM Value,
100 /// in the current module. If 'Suffix' is specified, the name ends with the
101 /// specified suffix. If 'ForcePrivate' is specified, the label is specified
102 /// to have a private label prefix.
104 std::string getMangledName(const GlobalValue *V, const char *Suffix = "",
105 bool ForcePrivate = false);
107 /// makeNameProper - We don't want identifier names with ., space, or
108 /// - in them, so we mangle these characters into the strings "d_",
109 /// "s_", and "D_", respectively. This is a very simple mangling that
110 /// doesn't guarantee unique names for values. getValueName already
111 /// does this for you, so there's no point calling it on the result
112 /// from getValueName.
114 std::string makeNameProper(const std::string &x,
115 ManglerPrefixTy PrefixTy = Mangler::Default);
117 /// getNameWithPrefix - Fill OutName with the name of the appropriate prefix
118 /// and the specified global variable's name. If the global variable doesn't
119 /// have a name, this fills in a unique name for the global.
120 void getNameWithPrefix(SmallVectorImpl<char> &OutName, const GlobalValue *GV,
121 bool isImplicitlyPrivate);
124 } // End llvm namespace
126 #endif // LLVM_SUPPORT_MANGLER_H