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