Douglas Gregor | 6ec3668 | 2009-02-18 23:53:56 +0000 | [diff] [blame] | 1 | //===--- Mangle.h - Mangle C++ Names ----------------------------*- C++ -*-===// |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // Implements C++ name mangling according to the Itanium C++ ABI, |
| 11 | // which is used in GCC 3.2 and newer (and many compilers that are |
| 12 | // ABI-compatible with GCC): |
| 13 | // |
| 14 | // http://www.codesourcery.com/public/cxx-abi/abi.html |
| 15 | // |
| 16 | //===----------------------------------------------------------------------===// |
Chris Lattner | ca3f25c | 2009-03-21 08:24:40 +0000 | [diff] [blame] | 17 | |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 18 | #ifndef LLVM_CLANG_CODEGEN_MANGLE_H |
| 19 | #define LLVM_CLANG_CODEGEN_MANGLE_H |
| 20 | |
Anders Carlsson | 3ac86b5 | 2009-04-15 05:36:58 +0000 | [diff] [blame] | 21 | #include "CGCXX.h" |
Mike Stump | f121677 | 2009-07-31 18:25:34 +0000 | [diff] [blame] | 22 | #include "clang/AST/Type.h" |
Anders Carlsson | c4355b6 | 2009-10-07 01:45:02 +0000 | [diff] [blame] | 23 | #include "llvm/ADT/DenseMap.h" |
Anders Carlsson | 3ac86b5 | 2009-04-15 05:36:58 +0000 | [diff] [blame] | 24 | |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 25 | namespace llvm { |
Anders Carlsson | b73a5be | 2009-11-26 02:49:32 +0000 | [diff] [blame] | 26 | template<typename T> class SmallVectorImpl; |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | namespace clang { |
Anders Carlsson | b73a5be | 2009-11-26 02:49:32 +0000 | [diff] [blame] | 30 | class ASTContext; |
| 31 | class CXXConstructorDecl; |
| 32 | class CXXDestructorDecl; |
| 33 | class FunctionDecl; |
| 34 | class NamedDecl; |
| 35 | class VarDecl; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 36 | |
Anders Carlsson | b73a5be | 2009-11-26 02:49:32 +0000 | [diff] [blame] | 37 | namespace CodeGen { |
| 38 | class ThunkAdjustment; |
| 39 | |
Daniel Dunbar | 1b07711 | 2009-11-21 09:06:10 +0000 | [diff] [blame] | 40 | /// MangleContext - Context for tracking state which persists across multiple |
| 41 | /// calls to the C++ name mangler. |
| 42 | class MangleContext { |
| 43 | ASTContext &Context; |
Anders Carlsson | c4355b6 | 2009-10-07 01:45:02 +0000 | [diff] [blame] | 44 | |
Daniel Dunbar | 1b07711 | 2009-11-21 09:06:10 +0000 | [diff] [blame] | 45 | llvm::DenseMap<const TagDecl *, uint64_t> AnonStructIds; |
| 46 | |
| 47 | public: |
| 48 | explicit MangleContext(ASTContext &Context) |
Anders Carlsson | b540491 | 2009-10-07 01:06:45 +0000 | [diff] [blame] | 49 | : Context(Context) { } |
Anders Carlsson | b540491 | 2009-10-07 01:06:45 +0000 | [diff] [blame] | 50 | |
Daniel Dunbar | 1b07711 | 2009-11-21 09:06:10 +0000 | [diff] [blame] | 51 | ASTContext &getASTContext() const { return Context; } |
| 52 | |
| 53 | uint64_t getAnonymousStructId(const TagDecl *TD) { |
| 54 | std::pair<llvm::DenseMap<const TagDecl *, |
| 55 | uint64_t>::iterator, bool> Result = |
| 56 | AnonStructIds.insert(std::make_pair(TD, AnonStructIds.size())); |
| 57 | return Result.first->second; |
| 58 | } |
| 59 | |
| 60 | /// @name Mangler Entry Points |
| 61 | /// @{ |
| 62 | |
Daniel Dunbar | f981bf8 | 2009-11-21 09:14:52 +0000 | [diff] [blame] | 63 | bool shouldMangleDeclName(const NamedDecl *D); |
| 64 | |
| 65 | void mangleName(const NamedDecl *D, llvm::SmallVectorImpl<char> &); |
Anders Carlsson | a94822e | 2009-11-26 02:32:05 +0000 | [diff] [blame] | 66 | void mangleThunk(const FunctionDecl *FD, |
Anders Carlsson | b73a5be | 2009-11-26 02:49:32 +0000 | [diff] [blame] | 67 | const ThunkAdjustment &ThisAdjustment, |
Daniel Dunbar | 94fd26d | 2009-11-21 09:06:22 +0000 | [diff] [blame] | 68 | llvm::SmallVectorImpl<char> &); |
Daniel Dunbar | 1b07711 | 2009-11-21 09:06:10 +0000 | [diff] [blame] | 69 | void mangleCovariantThunk(const FunctionDecl *FD, int64_t nv_t, int64_t v_t, |
Daniel Dunbar | 94fd26d | 2009-11-21 09:06:22 +0000 | [diff] [blame] | 70 | int64_t nv_r, int64_t v_r, |
| 71 | llvm::SmallVectorImpl<char> &); |
| 72 | void mangleGuardVariable(const VarDecl *D, llvm::SmallVectorImpl<char> &); |
| 73 | void mangleCXXVtable(const CXXRecordDecl *RD, llvm::SmallVectorImpl<char> &); |
| 74 | void mangleCXXVTT(const CXXRecordDecl *RD, llvm::SmallVectorImpl<char> &); |
Daniel Dunbar | 1b07711 | 2009-11-21 09:06:10 +0000 | [diff] [blame] | 75 | void mangleCXXCtorVtable(const CXXRecordDecl *RD, int64_t Offset, |
Daniel Dunbar | 94fd26d | 2009-11-21 09:06:22 +0000 | [diff] [blame] | 76 | const CXXRecordDecl *Type, |
| 77 | llvm::SmallVectorImpl<char> &); |
| 78 | void mangleCXXRtti(QualType T, llvm::SmallVectorImpl<char> &); |
| 79 | void mangleCXXRttiName(QualType T, llvm::SmallVectorImpl<char> &); |
Daniel Dunbar | 1b07711 | 2009-11-21 09:06:10 +0000 | [diff] [blame] | 80 | void mangleCXXCtor(const CXXConstructorDecl *D, CXXCtorType Type, |
Daniel Dunbar | 94fd26d | 2009-11-21 09:06:22 +0000 | [diff] [blame] | 81 | llvm::SmallVectorImpl<char> &); |
Daniel Dunbar | 1b07711 | 2009-11-21 09:06:10 +0000 | [diff] [blame] | 82 | void mangleCXXDtor(const CXXDestructorDecl *D, CXXDtorType Type, |
Daniel Dunbar | 94fd26d | 2009-11-21 09:06:22 +0000 | [diff] [blame] | 83 | llvm::SmallVectorImpl<char> &); |
Daniel Dunbar | 1b07711 | 2009-11-21 09:06:10 +0000 | [diff] [blame] | 84 | |
| 85 | /// @} |
| 86 | }; |
Anders Carlsson | b73a5be | 2009-11-26 02:49:32 +0000 | [diff] [blame] | 87 | |
| 88 | } |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 89 | } |
| 90 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 91 | #endif |