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 Type; 00023 class Module; 00024 class Value; 00025 class GlobalValue; 00026 00027 class Mangler { 00028 /// Prefix - This string is added to each symbol that is emitted, unless the 00029 /// symbol is marked as not needing this prefix. 00030 const char *Prefix; 00031 00032 /// UseQuotes - If this is set, the target accepts global names in quotes, 00033 /// e.g. "foo bar" is a legal name. This syntax is used instead of escaping 00034 /// the space character. By default, this is false. 00035 bool UseQuotes; 00036 00037 /// Memo - This is used to remember the name that we assign a value. 00038 /// 00039 std::map<const Value*, std::string> Memo; 00040 00041 /// Count - This simple counter is used to unique value names. 00042 /// 00043 unsigned Count; 00044 00045 /// TypeMap - If the client wants us to unique types, this keeps track of the 00046 /// current assignments and TypeCounter keeps track of the next id to assign. 00047 std::map<const Type*, unsigned> TypeMap; 00048 unsigned TypeCounter; 00049 00050 /// This keeps track of which global values have had their names 00051 /// mangled in the current module. 00052 /// 00053 std::set<const GlobalValue*> MangledGlobals; 00054 00055 /// AcceptableChars - This bitfield contains a one for each character that is 00056 /// allowed to be part of an unmangled name. 00057 unsigned AcceptableChars[256/32]; 00058 public: 00059 00060 // Mangler ctor - if a prefix is specified, it will be prepended onto all 00061 // symbols. 00062 Mangler(Module &M, const char *Prefix = ""); 00063 00064 /// setUseQuotes - If UseQuotes is set to true, this target accepts quoted 00065 /// strings for assembler labels. 00066 void setUseQuotes(bool Val) { UseQuotes = Val; } 00067 00068 /// Acceptable Characters - This allows the target to specify which characters 00069 /// are acceptable to the assembler without being mangled. By default we 00070 /// allow letters, numbers, '_', '$', and '.', which is what GAS accepts. 00071 void markCharAcceptable(unsigned char X) { 00072 AcceptableChars[X/32] |= 1 << (X&31); 00073 } 00074 void markCharUnacceptable(unsigned char X) { 00075 AcceptableChars[X/32] &= ~(1 << (X&31)); 00076 } 00077 bool isCharAcceptable(unsigned char X) const { 00078 return (AcceptableChars[X/32] & (1 << (X&31))) != 0; 00079 } 00080 00081 /// getTypeID - Return a unique ID for the specified LLVM type. 00082 /// 00083 unsigned getTypeID(const Type *Ty); 00084 00085 /// getValueName - Returns the mangled name of V, an LLVM Value, 00086 /// in the current module. 00087 /// 00088 std::string getValueName(const GlobalValue *V); 00089 std::string getValueName(const Value *V); 00090 00091 /// makeNameProper - We don't want identifier names with ., space, or 00092 /// - in them, so we mangle these characters into the strings "d_", 00093 /// "s_", and "D_", respectively. This is a very simple mangling that 00094 /// doesn't guarantee unique names for values. getValueName already 00095 /// does this for you, so there's no point calling it on the result 00096 /// from getValueName. 00097 /// 00098 std::string makeNameProper(const std::string &x, const char *Prefix = ""); 00099 00100 private: 00101 void InsertName(GlobalValue *GV, std::map<std::string, GlobalValue*> &Names); 00102 }; 00103 00104 } // End llvm namespace 00105 00106 #endif // LLVM_SUPPORT_MANGLER_H