Remove uber-gross hack. The define _snprintf to snprintf is invalid due to two reason...
[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 template <typename T> class SmallVectorImpl; 
27
28 class Mangler {
29 public:
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.
34   };
35
36 private:
37   /// Prefix - This string is added to each symbol that is emitted, unless the
38   /// symbol is marked as not needing this prefix.
39   const char *Prefix;
40
41   /// PrivatePrefix - This string is emitted before each symbol with private
42   /// linkage.
43   const char *PrivatePrefix;
44
45   /// LinkerPrivatePrefix - This string is emitted before each symbol with
46   /// "linker_private" linkage.
47   const char *LinkerPrivatePrefix;
48
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.
52   bool UseQuotes;
53
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;
57
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
60   /// ones.
61   ///
62   DenseMap<const GlobalValue*, unsigned> AnonGlobalIDs;
63
64   /// NextAnonGlobalID - This simple counter is used to unique value names.
65   ///
66   unsigned NextAnonGlobalID;
67
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];
71
72 public:
73   // Mangler ctor - if a prefix is specified, it will be prepended onto all
74   // symbols.
75   Mangler(Module &M, const char *Prefix = "", const char *privatePrefix = "",
76           const char *linkerPrivatePrefix = "");
77
78   /// setUseQuotes - If UseQuotes is set to true, this target accepts quoted
79   /// strings for assembler labels.
80   void setUseQuotes(bool Val) { UseQuotes = Val; }
81
82   /// setSymbolsCanStartWithDigit - If SymbolsCanStartWithDigit is set to true,
83   /// this target allows symbols to start with digits.
84   void setSymbolsCanStartWithDigit(bool Val) { SymbolsCanStartWithDigit = Val; }
85
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);
91   }
92   void markCharUnacceptable(unsigned char X) {
93     AcceptableChars[X/32] &= ~(1 << (X&31));
94   }
95   bool isCharAcceptable(unsigned char X) const {
96     return (AcceptableChars[X/32] & (1 << (X&31))) != 0;
97   }
98
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.
103   ///
104   std::string getMangledName(const GlobalValue *V, const char *Suffix = "",
105                              bool ForcePrivate = false);
106
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.
113   ///
114   std::string makeNameProper(const std::string &x,
115                              ManglerPrefixTy PrefixTy = Mangler::Default);
116   
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);
122 };
123
124 } // End llvm namespace
125
126 #endif // LLVM_SUPPORT_MANGLER_H