LLVM API Documentation

Mangler.h
Go to the documentation of this file.
00001 //===-- llvm/IR/Mangler.h - Self-contained name mangler ---------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // Unified name mangler for various backends.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #ifndef LLVM_IR_MANGLER_H
00015 #define LLVM_IR_MANGLER_H
00016 
00017 #include "llvm/ADT/DenseMap.h"
00018 #include "llvm/Support/raw_ostream.h"
00019 
00020 namespace llvm {
00021 
00022 class DataLayout;
00023 class GlobalValue;
00024 template <typename T> class SmallVectorImpl;
00025 class Twine;
00026 
00027 class Mangler {
00028 public:
00029   enum ManglerPrefixTy {
00030     Default,               ///< Emit default string before each symbol.
00031     Private,               ///< Emit "private" prefix before each symbol.
00032     LinkerPrivate          ///< Emit "linker private" prefix before each symbol.
00033   };
00034 
00035 private:
00036   const DataLayout *DL;
00037 
00038   /// AnonGlobalIDs - We need to give global values the same name every time
00039   /// they are mangled.  This keeps track of the number we give to anonymous
00040   /// ones.
00041   ///
00042   mutable DenseMap<const GlobalValue*, unsigned> AnonGlobalIDs;
00043 
00044   /// NextAnonGlobalID - This simple counter is used to unique value names.
00045   ///
00046   mutable unsigned NextAnonGlobalID;
00047 
00048 public:
00049   Mangler(const DataLayout *DL) : DL(DL), NextAnonGlobalID(1) {}
00050 
00051   /// Print the appropriate prefix and the specified global variable's name.
00052   /// If the global variable doesn't have a name, this fills in a unique name
00053   /// for the global.
00054   void getNameWithPrefix(raw_ostream &OS, const GlobalValue *GV,
00055                          bool CannotUsePrivateLabel) const;
00056   void getNameWithPrefix(SmallVectorImpl<char> &OutName, const GlobalValue *GV,
00057                          bool CannotUsePrivateLabel) const;
00058 
00059   /// Print the appropriate prefix and the specified name as the global variable
00060   /// name. GVName must not be empty.
00061   void getNameWithPrefix(raw_ostream &OS, const Twine &GVName,
00062                          ManglerPrefixTy PrefixTy = Mangler::Default) const;
00063   void getNameWithPrefix(SmallVectorImpl<char> &OutName, const Twine &GVName,
00064                          ManglerPrefixTy PrefixTy = Mangler::Default) const;
00065 };
00066 
00067 } // End llvm namespace
00068 
00069 #endif