Changes For Bug 352
[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 Value;
23 class Type;
24 class Module;
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 Value *> MangledGlobals;
32
33   Module &M;
34   const char *Prefix;
35
36   unsigned TypeCounter;
37   std::map<const Type*, unsigned> TypeMap;
38
39   typedef std::map<const Value *, std::string> ValueMap;
40   ValueMap Memo;
41
42   unsigned Count;
43
44   void InsertName(GlobalValue *GV, std::map<std::string, GlobalValue*> &Names);
45 public:
46
47   // Mangler ctor - if a prefix is specified, it will be prepended onto all
48   // symbols.
49   Mangler(Module &M, const char *Prefix = "");
50
51   /// getTypeID - Return a unique ID for the specified LLVM type.
52   ///
53   unsigned getTypeID(const Type *Ty);
54
55   /// getValueName - Returns the mangled name of V, an LLVM Value,
56   /// in the current module.
57   ///
58   std::string getValueName(const Value *V);
59
60   /// makeNameProper - We don't want identifier names with ., space, or
61   /// - in them, so we mangle these characters into the strings "d_",
62   /// "s_", and "D_", respectively. This is a very simple mangling that
63   /// doesn't guarantee unique names for values. getValueName already
64   /// does this for you, so there's no point calling it on the result
65   /// from getValueName.
66   /// 
67   static std::string makeNameProper(const std::string &x);
68 };
69
70 } // End llvm namespace
71
72 #endif // LLVM_SUPPORT_MANGLER_H