Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 1 | //===--- CGVtable.h - Emit LLVM Code for C++ vtables ----------------------===// |
| 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 | // This contains code dealing with C++ code generation of virtual tables. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef CLANG_CODEGEN_CGVTABLE_H |
| 15 | #define CLANG_CODEGEN_CGVTABLE_H |
| 16 | |
| 17 | #include "llvm/ADT/DenseMap.h" |
| 18 | |
| 19 | namespace clang { |
| 20 | class CXXMethodDecl; |
| 21 | class CXXRecordDecl; |
| 22 | |
| 23 | namespace CodeGen { |
| 24 | class CodeGenModule; |
| 25 | |
| 26 | class CGVtableInfo { |
| 27 | CodeGenModule &CGM; |
| 28 | |
| 29 | /// MethodVtableIndices - Contains the index (relative to the vtable address |
| 30 | /// point) where the function pointer for a virtual function is stored. |
| 31 | typedef llvm::DenseMap<const CXXMethodDecl *, int64_t> MethodVtableIndicesTy; |
| 32 | MethodVtableIndicesTy MethodVtableIndices; |
| 33 | |
| 34 | typedef std::pair<const CXXRecordDecl *, |
| 35 | const CXXRecordDecl *> ClassPairTy; |
| 36 | |
| 37 | /// VirtualBaseClassIndicies - Contains the index into the vtable where the |
| 38 | /// offsets for virtual bases of a class are stored. |
| 39 | typedef llvm::DenseMap<ClassPairTy, int64_t> VirtualBaseClassIndiciesTy; |
| 40 | VirtualBaseClassIndiciesTy VirtualBaseClassIndicies; |
Mike Stump | 380dd75 | 2009-11-10 07:44:33 +0000 | [diff] [blame] | 41 | |
| 42 | llvm::DenseMap<const CXXRecordDecl *, llvm::Constant *> Vtables; |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 43 | public: |
| 44 | CGVtableInfo(CodeGenModule &CGM) |
| 45 | : CGM(CGM) { } |
| 46 | |
| 47 | /// getMethodVtableIndex - Return the index (relative to the vtable address |
| 48 | /// point) where the function pointer for the given virtual function is |
| 49 | /// stored. |
| 50 | int64_t getMethodVtableIndex(const CXXMethodDecl *MD); |
| 51 | |
Mike Stump | ab28c13 | 2009-10-13 22:54:56 +0000 | [diff] [blame] | 52 | /// getVirtualBaseOffsetIndex - Return the index (relative to the vtable |
| 53 | /// address point) where the offset of the virtual base that contains the |
| 54 | /// given Base is stored, otherwise, if no virtual base contains the given |
| 55 | /// class, return 0. Base must be a virtual base class or an unambigious |
| 56 | /// base. |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 57 | int64_t getVirtualBaseOffsetIndex(const CXXRecordDecl *RD, |
| 58 | const CXXRecordDecl *VBase); |
Mike Stump | 380dd75 | 2009-11-10 07:44:33 +0000 | [diff] [blame] | 59 | |
Mike Stump | 8cfcb52 | 2009-11-11 20:26:26 +0000 | [diff] [blame^] | 60 | llvm::Constant *getVtable(const CXXRecordDecl *RD); |
| 61 | llvm::Constant *getCtorVtable(const CXXRecordDecl *RD, |
| 62 | const CXXRecordDecl *Class, uint64_t Offset); |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | } |
| 66 | } |
| 67 | #endif |