• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-- llvm/Target/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 
19 namespace llvm {
20 class StringRef;
21 class Twine;
22 class Value;
23 class GlobalValue;
24 template <typename T> class SmallVectorImpl;
25 class MCContext;
26 class MCSymbol;
27 class TargetData;
28 
29 class Mangler {
30 public:
31   enum ManglerPrefixTy {
32     Default,               ///< Emit default string before each symbol.
33     Private,               ///< Emit "private" prefix before each symbol.
34     LinkerPrivate          ///< Emit "linker private" prefix before each symbol.
35   };
36 
37 private:
38   MCContext &Context;
39   const TargetData &TD;
40 
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
43   /// ones.
44   ///
45   DenseMap<const GlobalValue*, unsigned> AnonGlobalIDs;
46 
47   /// NextAnonGlobalID - This simple counter is used to unique value names.
48   ///
49   unsigned NextAnonGlobalID;
50 
51 public:
Mangler(MCContext & context,const TargetData & td)52   Mangler(MCContext &context, const TargetData &td)
53     : Context(context), TD(td), NextAnonGlobalID(1) {}
54 
55   /// getSymbol - Return the MCSymbol for the specified global value.  This
56   /// symbol is the main label that is the address of the global.
57   MCSymbol *getSymbol(const GlobalValue *GV);
58 
59 
60   /// getNameWithPrefix - Fill OutName with the name of the appropriate prefix
61   /// and the specified global variable's name.  If the global variable doesn't
62   /// have a name, this fills in a unique name for the global.
63   void getNameWithPrefix(SmallVectorImpl<char> &OutName, const GlobalValue *GV,
64                          bool isImplicitlyPrivate);
65 
66   /// getNameWithPrefix - Fill OutName with the name of the appropriate prefix
67   /// and the specified name as the global variable name.  GVName must not be
68   /// empty.
69   void getNameWithPrefix(SmallVectorImpl<char> &OutName, const Twine &GVName,
70                          ManglerPrefixTy PrefixTy = Mangler::Default);
71 };
72 
73 } // End llvm namespace
74 
75 #endif // LLVM_SUPPORT_MANGLER_H
76