Significantly simplify gep_type_iterator, and make its interface more general/powerful
[oota-llvm.git] / include / llvm / Support / Mangler.h
1 //===-- Mangler.h - Self-contained llvm 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 Module;
24 class GlobalValue;
25
26 class Mangler {
27   /// This keeps track of which global values have had their names
28   /// mangled in the current module.
29   ///
30   std::set<const Value *> MangledGlobals;
31
32   Module &M;
33   bool AddUnderscorePrefix;
34
35   typedef std::map<const Value *, std::string> ValueMap;
36   ValueMap Memo;
37
38   unsigned Count;
39
40   void InsertName(GlobalValue *GV, std::map<std::string, GlobalValue*> &Names);
41 public:
42
43   // Mangler ctor - if AddUnderscorePrefix is true, then all public global
44   // symbols will be prefixed with an underscore.
45   Mangler(Module &M, bool AddUnderscorePrefix = false);
46
47   /// getValueName - Returns the mangled name of V, an LLVM Value,
48   /// in the current module.
49   ///
50   std::string getValueName(const Value *V);
51
52   /// makeNameProper - We don't want identifier names with ., space, or
53   /// - in them, so we mangle these characters into the strings "d_",
54   /// "s_", and "D_", respectively. This is a very simple mangling that
55   /// doesn't guarantee unique names for values. getValueName already
56   /// does this for you, so there's no point calling it on the result
57   /// from getValueName.
58   /// 
59   static std::string makeNameProper(const std::string &x);
60 };
61
62 } // End llvm namespace
63
64 #endif // LLVM_SUPPORT_MANGLER_H