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"
28 /// Prefix - This string is added to each symbol that is emitted, unless the
29 /// symbol is marked as not needing this prefix.
32 /// PrivatePrefix - This string is emitted before each symbol with private
34 const char *PrivatePrefix;
36 /// UseQuotes - If this is set, the target accepts global names in quotes,
37 /// e.g. "foo bar" is a legal name. This syntax is used instead of escaping
38 /// the space character. By default, this is false.
41 /// AnonGlobalIDs - We need to give global values the same name every time
42 /// they are mangled. This keeps track of the number we give to anonymous
45 DenseMap<const GlobalValue*, unsigned> AnonGlobalIDs;
47 /// NextAnonGlobalID - This simple counter is used to unique value names.
49 unsigned NextAnonGlobalID;
51 /// AcceptableChars - This bitfield contains a one for each character that is
52 /// allowed to be part of an unmangled name.
53 unsigned AcceptableChars[256/32];
56 // Mangler ctor - if a prefix is specified, it will be prepended onto all
58 Mangler(Module &M, const char *Prefix = "", const char *privatePrefix = "");
60 /// setUseQuotes - If UseQuotes is set to true, this target accepts quoted
61 /// strings for assembler labels.
62 void setUseQuotes(bool Val) { UseQuotes = Val; }
64 /// Acceptable Characters - This allows the target to specify which characters
65 /// are acceptable to the assembler without being mangled. By default we
66 /// allow letters, numbers, '_', '$', and '.', which is what GAS accepts.
67 void markCharAcceptable(unsigned char X) {
68 AcceptableChars[X/32] |= 1 << (X&31);
70 void markCharUnacceptable(unsigned char X) {
71 AcceptableChars[X/32] &= ~(1 << (X&31));
73 bool isCharAcceptable(unsigned char X) const {
74 return (AcceptableChars[X/32] & (1 << (X&31))) != 0;
77 /// getMangledName - Returns the mangled name of V, an LLVM Value,
78 /// in the current module. If 'Suffix' is specified, the name ends with the
79 /// specified suffix. If 'ForcePrivate' is specified, the label is specified
80 /// to have a private label prefix.
82 std::string getMangledName(const GlobalValue *V, const char *Suffix = "",
83 bool ForcePrivate = false);
85 /// makeNameProper - We don't want identifier names with ., space, or
86 /// - in them, so we mangle these characters into the strings "d_",
87 /// "s_", and "D_", respectively. This is a very simple mangling that
88 /// doesn't guarantee unique names for values. getValueName already
89 /// does this for you, so there's no point calling it on the result
90 /// from getValueName.
92 std::string makeNameProper(const std::string &x,
93 bool hasPrivateLinkage = false);
96 } // End llvm namespace
98 #endif // LLVM_SUPPORT_MANGLER_H