Get MCSymbol out of the mangling business, and move all the logic
[oota-llvm.git] / include / llvm / Target / 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 <string>
19
20 namespace llvm {
21 class StringRef;
22 class Twine;
23 class Value;
24 class GlobalValue;
25 template <typename T> class SmallVectorImpl; 
26 class MCAsmInfo;
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   const MCAsmInfo &MAI;
38
39   /// AnonGlobalIDs - We need to give global values the same name every time
40   /// they are mangled.  This keeps track of the number we give to anonymous
41   /// ones.
42   ///
43   DenseMap<const GlobalValue*, unsigned> AnonGlobalIDs;
44
45   /// NextAnonGlobalID - This simple counter is used to unique value names.
46   ///
47   unsigned NextAnonGlobalID;
48
49 public:
50   // Mangler ctor - if a prefix is specified, it will be prepended onto all
51   // symbols.
52   Mangler(const MCAsmInfo &mai) : MAI(mai) {}
53
54   /// getNameWithPrefix - Fill OutName with the name of the appropriate prefix
55   /// and the specified global variable's name.  If the global variable doesn't
56   /// have a name, this fills in a unique name for the global.
57   void getNameWithPrefix(SmallVectorImpl<char> &OutName, const GlobalValue *GV,
58                          bool isImplicitlyPrivate);
59   
60   /// getNameWithPrefix - Fill OutName with the name of the appropriate prefix
61   /// and the specified name as the global variable name.  GVName must not be
62   /// empty.
63   void getNameWithPrefix(SmallVectorImpl<char> &OutName, const Twine &GVName,
64                          ManglerPrefixTy PrefixTy = Mangler::Default);
65
66   /// getNameWithPrefix - Return the name of the appropriate prefix
67   /// and the specified global variable's name.  If the global variable doesn't
68   /// have a name, this fills in a unique name for the global.
69   std::string getNameWithPrefix(const GlobalValue *GV,
70                                 bool isImplicitlyPrivate = false);
71
72   /// appendMangledName - Add the specified string in mangled form if it uses
73   /// any unusual characters.
74   static void appendMangledName(SmallVectorImpl<char> &OutName, StringRef Str,
75                                 const MCAsmInfo *MAI);
76 };
77
78 } // End llvm namespace
79
80 #endif // LLVM_SUPPORT_MANGLER_H