remove SectionFlags::Small: it is only used on Xcore, and we'll find
[oota-llvm.git] / include / llvm / Support / Mangler.h
1 //===-- llvm/Support/Mangler.h - Self-contained name mangler ----*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Unified name mangler for various backends.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_SUPPORT_MANGLER_H
15 #define LLVM_SUPPORT_MANGLER_H
16
17 #include "llvm/ADT/DenseMap.h"
18 #include "llvm/ADT/SmallPtrSet.h"
19 #include <string>
20
21 namespace llvm {
22 class Type;
23 class Module;
24 class Value;
25 class GlobalValue;
26
27 class Mangler {
28 public:
29   enum ManglerPrefixTy {
30     Default,               ///< Emit default string before each symbol.
31     Private,               ///< Emit "private" prefix before each symbol.
32     LinkerPrivate          ///< Emit "linker private" prefix before each symbol.
33   };
34
35 private:
36   /// Prefix - This string is added to each symbol that is emitted, unless the
37   /// symbol is marked as not needing this prefix.
38   const char *Prefix;
39
40   /// PrivatePrefix - This string is emitted before each symbol with private
41   /// linkage.
42   const char *PrivatePrefix;
43
44   /// LinkerPrivatePrefix - This string is emitted before each symbol with
45   /// "linker_private" linkage.
46   const char *LinkerPrivatePrefix;
47
48   /// UseQuotes - If this is set, the target accepts global names in quotes,
49   /// e.g. "foo bar" is a legal name.  This syntax is used instead of escaping
50   /// the space character.  By default, this is false.
51   bool UseQuotes;
52
53   /// AnonGlobalIDs - We need to give global values the same name every time
54   /// they are mangled.  This keeps track of the number we give to anonymous
55   /// ones.
56   ///
57   DenseMap<const GlobalValue*, unsigned> AnonGlobalIDs;
58
59   /// NextAnonGlobalID - This simple counter is used to unique value names.
60   ///
61   unsigned NextAnonGlobalID;
62
63   /// AcceptableChars - This bitfield contains a one for each character that is
64   /// allowed to be part of an unmangled name.
65   unsigned AcceptableChars[256 / 32];
66
67 public:
68   // Mangler ctor - if a prefix is specified, it will be prepended onto all
69   // symbols.
70   Mangler(Module &M, const char *Prefix = "", const char *privatePrefix = "",
71           const char *linkerPrivatePrefix = "");
72
73   /// setUseQuotes - If UseQuotes is set to true, this target accepts quoted
74   /// strings for assembler labels.
75   void setUseQuotes(bool Val) { UseQuotes = Val; }
76
77   /// Acceptable Characters - This allows the target to specify which characters
78   /// are acceptable to the assembler without being mangled.  By default we
79   /// allow letters, numbers, '_', '$', and '.', which is what GAS accepts.
80   void markCharAcceptable(unsigned char X) {
81     AcceptableChars[X/32] |= 1 << (X&31);
82   }
83   void markCharUnacceptable(unsigned char X) {
84     AcceptableChars[X/32] &= ~(1 << (X&31));
85   }
86   bool isCharAcceptable(unsigned char X) const {
87     return (AcceptableChars[X/32] & (1 << (X&31))) != 0;
88   }
89
90   /// getMangledName - Returns the mangled name of V, an LLVM Value,
91   /// in the current module.  If 'Suffix' is specified, the name ends with the
92   /// specified suffix.  If 'ForcePrivate' is specified, the label is specified
93   /// to have a private label prefix.
94   ///
95   std::string getMangledName(const GlobalValue *V, const char *Suffix = "",
96                              bool ForcePrivate = false);
97
98   /// makeNameProper - We don't want identifier names with ., space, or
99   /// - in them, so we mangle these characters into the strings "d_",
100   /// "s_", and "D_", respectively. This is a very simple mangling that
101   /// doesn't guarantee unique names for values. getValueName already
102   /// does this for you, so there's no point calling it on the result
103   /// from getValueName.
104   ///
105   std::string makeNameProper(const std::string &x,
106                              ManglerPrefixTy PrefixTy = Mangler::Default);
107 };
108
109 } // End llvm namespace
110
111 #endif // LLVM_SUPPORT_MANGLER_H