Add llvm_start_multithreaded(), which starts up the LLVM internals in thread-safe...
[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   /// Prefix - This string is added to each symbol that is emitted, unless the
29   /// symbol is marked as not needing this prefix.
30   const char *Prefix;
31
32   /// PrivatePrefix - This string is emitted before each symbol with private
33   /// linkage.
34   const char *PrivatePrefix;
35
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.
39   bool UseQuotes;
40
41   /// PreserveAsmNames - If this is set, the asm escape character is not removed
42   /// from names with 'asm' specifiers.
43   bool PreserveAsmNames;
44
45   /// Memo - This is used to remember the name that we assign a value.
46   ///
47   DenseMap<const Value*, std::string> Memo;
48
49   /// Count - This simple counter is used to unique value names.
50   ///
51   unsigned Count;
52
53   /// TypeMap - If the client wants us to unique types, this keeps track of the
54   /// current assignments and TypeCounter keeps track of the next id to assign.
55   DenseMap<const Type*, unsigned> TypeMap;
56   unsigned TypeCounter;
57
58   /// AcceptableChars - This bitfield contains a one for each character that is
59   /// allowed to be part of an unmangled name.
60   unsigned AcceptableChars[256/32];
61 public:
62
63   // Mangler ctor - if a prefix is specified, it will be prepended onto all
64   // symbols.
65   Mangler(Module &M, const char *Prefix = "", const char *privatePrefix = "");
66
67   /// setUseQuotes - If UseQuotes is set to true, this target accepts quoted
68   /// strings for assembler labels.
69   void setUseQuotes(bool Val) { UseQuotes = Val; }
70
71   /// setPreserveAsmNames - If the mangler should not strip off the asm name
72   /// @verbatim identifier (\001), this should be set. @endverbatim
73   void setPreserveAsmNames(bool Val) { PreserveAsmNames = Val; }
74
75   /// Acceptable Characters - This allows the target to specify which characters
76   /// are acceptable to the assembler without being mangled.  By default we
77   /// allow letters, numbers, '_', '$', and '.', which is what GAS accepts.
78   void markCharAcceptable(unsigned char X) {
79     AcceptableChars[X/32] |= 1 << (X&31);
80   }
81   void markCharUnacceptable(unsigned char X) {
82     AcceptableChars[X/32] &= ~(1 << (X&31));
83   }
84   bool isCharAcceptable(unsigned char X) const {
85     return (AcceptableChars[X/32] & (1 << (X&31))) != 0;
86   }
87
88   /// getValueName - Returns the mangled name of V, an LLVM Value,
89   /// in the current module.
90   ///
91   std::string getValueName(const GlobalValue *V, const char *Suffix = "");
92   std::string getValueName(const Value *V);
93
94   /// makeNameProper - We don't want identifier names with ., space, or
95   /// - in them, so we mangle these characters into the strings "d_",
96   /// "s_", and "D_", respectively. This is a very simple mangling that
97   /// doesn't guarantee unique names for values. getValueName already
98   /// does this for you, so there's no point calling it on the result
99   /// from getValueName.
100   ///
101   std::string makeNameProper(const std::string &x, const char *Prefix = 0,
102                              const char *PrivatePrefix = 0);
103
104 private:
105   /// getTypeID - Return a unique ID for the specified LLVM type.
106   ///
107   unsigned getTypeID(const Type *Ty);
108 };
109
110 } // End llvm namespace
111
112 #endif // LLVM_SUPPORT_MANGLER_H