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 { |
| 26 | class raw_ostream; |
| 27 | } |
| 28 | |
| 29 | namespace clang { |
| 30 | class ASTContext; |
Anders Carlsson | 3ac86b5 | 2009-04-15 05:36:58 +0000 | [diff] [blame] | 31 | class CXXConstructorDecl; |
Anders Carlsson | 27ae536 | 2009-04-17 01:58:57 +0000 | [diff] [blame] | 32 | class CXXDestructorDecl; |
Mike Stump | dec025b | 2009-09-07 04:27:52 +0000 | [diff] [blame] | 33 | class FunctionDecl; |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 34 | class NamedDecl; |
Anders Carlsson | 41aa8c1 | 2009-04-13 18:02:10 +0000 | [diff] [blame] | 35 | class VarDecl; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 36 | |
Anders Carlsson | b540491 | 2009-10-07 01:06:45 +0000 | [diff] [blame] | 37 | class MangleContext { |
| 38 | ASTContext &Context; |
Anders Carlsson | c4355b6 | 2009-10-07 01:45:02 +0000 | [diff] [blame^] | 39 | |
| 40 | llvm::DenseMap<const TagDecl *, uint64_t> AnonStructIds; |
| 41 | |
Anders Carlsson | b540491 | 2009-10-07 01:06:45 +0000 | [diff] [blame] | 42 | public: |
| 43 | explicit MangleContext(ASTContext &Context) |
| 44 | : Context(Context) { } |
| 45 | |
| 46 | ASTContext &getASTContext() const { return Context; } |
Anders Carlsson | c4355b6 | 2009-10-07 01:45:02 +0000 | [diff] [blame^] | 47 | |
| 48 | uint64_t getAnonymousStructId(const TagDecl *TD) { |
| 49 | std::pair<llvm::DenseMap<const TagDecl *, |
| 50 | uint64_t>::iterator, bool> Result = |
| 51 | AnonStructIds.insert(std::make_pair(TD, AnonStructIds.size())); |
| 52 | return Result.first->second; |
| 53 | } |
Anders Carlsson | b540491 | 2009-10-07 01:06:45 +0000 | [diff] [blame] | 54 | }; |
| 55 | |
| 56 | bool mangleName(MangleContext &Context, const NamedDecl *D, |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 57 | llvm::raw_ostream &os); |
Anders Carlsson | b540491 | 2009-10-07 01:06:45 +0000 | [diff] [blame] | 58 | void mangleThunk(MangleContext &Context, const FunctionDecl *FD, |
| 59 | int64_t n, int64_t vn, llvm::raw_ostream &os); |
| 60 | void mangleCovariantThunk(MangleContext &Context, const FunctionDecl *FD, |
| 61 | int64_t nv_t, int64_t v_t, |
| 62 | int64_t nv_r, int64_t v_r, |
Mike Stump | 6e319f6 | 2009-09-11 23:25:56 +0000 | [diff] [blame] | 63 | llvm::raw_ostream &os); |
Anders Carlsson | b540491 | 2009-10-07 01:06:45 +0000 | [diff] [blame] | 64 | void mangleGuardVariable(MangleContext &Context, const VarDecl *D, |
Anders Carlsson | 41aa8c1 | 2009-04-13 18:02:10 +0000 | [diff] [blame] | 65 | llvm::raw_ostream &os); |
Anders Carlsson | b540491 | 2009-10-07 01:06:45 +0000 | [diff] [blame] | 66 | void mangleCXXVtable(MangleContext &Context, QualType T, llvm::raw_ostream &os); |
| 67 | void mangleCXXRtti(MangleContext &Context, QualType T, llvm::raw_ostream &os); |
| 68 | void mangleCXXCtor(MangleContext &Context, const CXXConstructorDecl *D, |
| 69 | CXXCtorType Type, llvm::raw_ostream &os); |
| 70 | void mangleCXXDtor(MangleContext &Context, const CXXDestructorDecl *D, |
| 71 | CXXDtorType Type, llvm::raw_ostream &os); |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 72 | } |
| 73 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 74 | #endif |