7e44827a476478e3085b272355fd0de7cfbaf3f8
[oota-llvm.git] / include / llvm / Support / Mangler.h
1 //===-- Mangler.h - Self-contained c/asm llvm name mangler ------*- C++ -*-===//
2 //
3 // Unified name mangler for CWriter and assembly backends.
4 //
5 //===----------------------------------------------------------------------===//
6
7 #ifndef LLVM_SUPPORT_MANGLER_H
8 #define LLVM_SUPPORT_MANGLER_H
9
10 class Value;
11 class Module;
12 #include <map>
13 #include <set>
14 #include <string>
15
16 class Mangler {
17   /// This keeps track of which global values have had their names
18   /// mangled in the current module.
19   ///
20   std::set<const Value *> MangledGlobals;
21
22   Module &M;
23   bool AddUnderscorePrefix;
24
25   typedef std::map<const Value *, std::string> ValueMap;
26   ValueMap Memo;
27
28   unsigned Count;
29 public:
30
31   // Mangler ctor - if AddUnderscorePrefix is true, then all public global
32   // symbols will be prefixed with an underscore.
33   Mangler(Module &M, bool AddUnderscorePrefix = false);
34
35   /// getValueName - Returns the mangled name of V, an LLVM Value,
36   /// in the current module.
37   ///
38   std::string getValueName(const Value *V);
39
40   /// makeNameProper - We don't want identifier names with ., space, or
41   /// - in them, so we mangle these characters into the strings "d_",
42   /// "s_", and "D_", respectively. This is a very simple mangling that
43   /// doesn't guarantee unique names for values. getValueName already
44   /// does this for you, so there's no point calling it on the result
45   /// from getValueName.
46   /// 
47   static std::string makeNameProper(const std::string &x);
48 };
49
50 #endif // LLVM_SUPPORT_MANGLER_H