Don't attribute in file headers anymore. See llvmdev for the
[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/System/IncludeFile.h"
18 #include <map>
19 #include <set>
20 #include <string>
21
22 namespace llvm {
23 class Type;
24 class Module;
25 class Value;
26 class GlobalValue;
27
28 class Mangler {
29   /// Prefix - This string is added to each symbol that is emitted, unless the
30   /// symbol is marked as not needing this prefix.
31   const char *Prefix;
32   
33   /// UseQuotes - If this is set, the target accepts global names in quotes, 
34   /// e.g. "foo bar" is a legal name.  This syntax is used instead of escaping
35   /// the space character.  By default, this is false.
36   bool UseQuotes;
37   
38   /// PreserveAsmNames - If this is set, the asm escape character is not removed
39   /// from names with 'asm' specifiers. 
40   bool PreserveAsmNames;
41   
42   /// Memo - This is used to remember the name that we assign a value.
43   ///
44   std::map<const Value*, std::string> Memo;
45
46   /// Count - This simple counter is used to unique value names.
47   ///
48   unsigned Count;
49   
50   /// TypeMap - If the client wants us to unique types, this keeps track of the
51   /// current assignments and TypeCounter keeps track of the next id to assign.
52   std::map<const Type*, unsigned> TypeMap;
53   unsigned TypeCounter;
54
55   /// This keeps track of which global values have had their names
56   /// mangled in the current module.
57   ///
58   std::set<const GlobalValue*> MangledGlobals;
59   
60   /// AcceptableChars - This bitfield contains a one for each character that is
61   /// allowed to be part of an unmangled name.
62   unsigned AcceptableChars[256/32];
63 public:
64
65   // Mangler ctor - if a prefix is specified, it will be prepended onto all
66   // symbols.
67   Mangler(Module &M, const char *Prefix = "");
68
69   /// setUseQuotes - If UseQuotes is set to true, this target accepts quoted
70   /// strings for assembler labels.
71   void setUseQuotes(bool Val) { UseQuotes = Val; }
72   
73   /// setPreserveAsmNames - If the mangler should not strip off the asm name
74   /// @verbatim identifier (\001), this should be set. @endverbatim
75   void setPreserveAsmNames(bool Val) { PreserveAsmNames = 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   /// getTypeID - Return a unique ID for the specified LLVM type.
91   ///
92   unsigned getTypeID(const Type *Ty);
93
94   /// getValueName - Returns the mangled name of V, an LLVM Value,
95   /// in the current module.
96   ///
97   std::string getValueName(const GlobalValue *V, const char *Suffix = "");
98   std::string getValueName(const Value *V);
99
100   /// makeNameProper - We don't want identifier names with ., space, or
101   /// - in them, so we mangle these characters into the strings "d_",
102   /// "s_", and "D_", respectively. This is a very simple mangling that
103   /// doesn't guarantee unique names for values. getValueName already
104   /// does this for you, so there's no point calling it on the result
105   /// from getValueName.
106   ///
107   std::string makeNameProper(const std::string &x, const char *Prefix = "");
108   
109 private:
110   void InsertName(GlobalValue *GV, std::map<std::string, GlobalValue*> &Names);
111 };
112
113 } // End llvm namespace
114
115 // Force the Mangler.cpp file to be linked when this header is #included
116 FORCE_DEFINING_FILE_TO_BE_LINKED(Mangler)
117
118 #endif // LLVM_SUPPORT_MANGLER_H