Remove M, which is dead. Eliminate a dead typedef. Add comments.
[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 was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source 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 <map>
18 #include <set>
19 #include <string>
20
21 namespace llvm {
22 class Type;
23 class Module;
24 class Value;
25 class GlobalValue;
26
27 class Mangler {
28   /// This keeps track of which global values have had their names
29   /// mangled in the current module.
30   ///
31   std::set<const GlobalValue*> MangledGlobals;
32
33   /// Prefix - This string is added to each symbol that is emitted, unless the
34   /// symbol is marked as not needing this prefix.
35   const char *Prefix;
36
37   /// Memo - This is used to remember the name that we assign a value.
38   ///
39   std::map<const Value*, std::string> Memo;
40
41   /// Count - This simple counter is used to unique value names.
42   ///
43   unsigned Count;
44   
45   /// TypeMap - If the client wants us to unique types, this keeps track of the
46   /// current assignments and TypeCounter keeps track of the next id to assign.
47   std::map<const Type*, unsigned> TypeMap;
48   unsigned TypeCounter;
49
50   void InsertName(GlobalValue *GV, std::map<std::string, GlobalValue*> &Names);
51 public:
52
53   // Mangler ctor - if a prefix is specified, it will be prepended onto all
54   // symbols.
55   Mangler(Module &M, const char *Prefix = "");
56
57   /// getTypeID - Return a unique ID for the specified LLVM type.
58   ///
59   unsigned getTypeID(const Type *Ty);
60
61   /// getValueName - Returns the mangled name of V, an LLVM Value,
62   /// in the current module.
63   ///
64   std::string getValueName(const GlobalValue *V);
65   std::string getValueName(const Value *V);
66
67   /// makeNameProper - We don't want identifier names with ., space, or
68   /// - in them, so we mangle these characters into the strings "d_",
69   /// "s_", and "D_", respectively. This is a very simple mangling that
70   /// doesn't guarantee unique names for values. getValueName already
71   /// does this for you, so there's no point calling it on the result
72   /// from getValueName.
73   ///
74   std::string makeNameProper(const std::string &x, const char *Prefix = "");
75 };
76
77 } // End llvm namespace
78
79 #endif // LLVM_SUPPORT_MANGLER_H