LLVM API Documentation
00001 //===-- llvm/Support/Mangler.h - Self-contained name mangler ----*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file was developed by the LLVM research group and is distributed under 00006 // the University of Illinois Open Source License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // Unified name mangler for various backends. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #ifndef LLVM_SUPPORT_MANGLER_H 00015 #define LLVM_SUPPORT_MANGLER_H 00016 00017 #include <map> 00018 #include <set> 00019 #include <string> 00020 00021 namespace llvm { 00022 class Value; 00023 class Type; 00024 class Module; 00025 class GlobalValue; 00026 00027 class Mangler { 00028 /// This keeps track of which global values have had their names 00029 /// mangled in the current module. 00030 /// 00031 std::set<const Value *> MangledGlobals; 00032 00033 Module &M; 00034 const char *Prefix; 00035 00036 unsigned TypeCounter; 00037 std::map<const Type*, unsigned> TypeMap; 00038 00039 typedef std::map<const Value *, std::string> ValueMap; 00040 ValueMap Memo; 00041 00042 unsigned Count; 00043 00044 void InsertName(GlobalValue *GV, std::map<std::string, GlobalValue*> &Names); 00045 public: 00046 00047 // Mangler ctor - if a prefix is specified, it will be prepended onto all 00048 // symbols. 00049 Mangler(Module &M, const char *Prefix = ""); 00050 00051 /// getTypeID - Return a unique ID for the specified LLVM type. 00052 /// 00053 unsigned getTypeID(const Type *Ty); 00054 00055 /// getValueName - Returns the mangled name of V, an LLVM Value, 00056 /// in the current module. 00057 /// 00058 std::string getValueName(const Value *V); 00059 00060 /// makeNameProper - We don't want identifier names with ., space, or 00061 /// - in them, so we mangle these characters into the strings "d_", 00062 /// "s_", and "D_", respectively. This is a very simple mangling that 00063 /// doesn't guarantee unique names for values. getValueName already 00064 /// does this for you, so there's no point calling it on the result 00065 /// from getValueName. 00066 /// 00067 static std::string makeNameProper(const std::string &x); 00068 }; 00069 00070 } // End llvm namespace 00071 00072 #endif // LLVM_SUPPORT_MANGLER_H