diff options
author | Mike Stump <mrs@apple.com> | 2009-07-31 21:43:43 +0000 |
---|---|---|
committer | Mike Stump <mrs@apple.com> | 2009-07-31 21:43:43 +0000 |
commit | 82b56961dcb813674dbda3c5f5aaee703d55741c (patch) | |
tree | 4982f875374f7cad4039c0bbfe0521c5027cd117 /lib/CodeGen/CGCXX.cpp | |
parent | aaed50dfb52d358a407dbbdd1ca323f9328e957a (diff) |
And now we can generate a simple vtable. Still a work in progress...
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@77737 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGCXX.cpp')
-rw-r--r-- | lib/CodeGen/CGCXX.cpp | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/lib/CodeGen/CGCXX.cpp b/lib/CodeGen/CGCXX.cpp index 6c0c0d90f1..62dabf77d6 100644 --- a/lib/CodeGen/CGCXX.cpp +++ b/lib/CodeGen/CGCXX.cpp @@ -494,7 +494,6 @@ llvm::Value *CodeGenFunction::GenerateVtable(const CXXRecordDecl *RD) { const llvm::FunctionType *FTy; FTy = llvm::FunctionType::get(llvm::Type::VoidTy, std::vector<const llvm::Type*>(), false); - llvm::SmallString<256> OutName; llvm::raw_svector_ostream Out(OutName); QualType ClassTy; @@ -503,23 +502,36 @@ llvm::Value *CodeGenFunction::GenerateVtable(const CXXRecordDecl *RD) { ClassTy = getContext().getTagDeclType(const_cast<CXXRecordDecl*>(RD)); mangleCXXVtable(ClassTy, getContext(), Out); const char *Name = OutName.c_str(); - llvm::Value *vtable = CGM.CreateRuntimeFunction(FTy, Name); - llvm::SmallVector<CXXMethodDecl *,32> methods; + llvm::GlobalVariable::LinkageTypes linktype; + linktype = llvm::GlobalValue::WeakAnyLinkage; + std::vector<llvm::Constant *> methods; typedef CXXRecordDecl::method_iterator meth_iter; + llvm::Constant *m; + llvm::Type *Ptr8Ty; + Ptr8Ty = llvm::PointerType::get(llvm::Type::Int8Ty, 0); + m = llvm::Constant::getNullValue(Ptr8Ty); + int64_t offset = 0; + methods.push_back(m); offset += LLVMPointerWidth; + methods.push_back(m); offset += LLVMPointerWidth; for (meth_iter mi = RD->method_begin(), me = RD->method_end(); mi != me; ++mi) { - if (mi->isVirtual()) - methods.push_back(*mi); + if (mi->isVirtual()) { + m = CGM.GetAddrOfFunction(GlobalDecl(*mi)); + m = llvm::ConstantExpr::getBitCast(m, Ptr8Ty); + methods.push_back(m); + } } - - llvm::Type *Ptr8Ty; - Ptr8Ty = llvm::PointerType::get(llvm::Type::Int8Ty, 0); + llvm::Constant *C; + llvm::ArrayType *type = llvm::ArrayType::get(Ptr8Ty, methods.size()); + C = llvm::ConstantArray::get(type, methods); + llvm::Value *vtable = new llvm::GlobalVariable(CGM.getModule(), type, true, + linktype, C, Name); + // CGM.CreateRuntimeFunction(FTy, Name); vtable = Builder.CreateBitCast(vtable, Ptr8Ty); - // FIXME: finish layout for virtual bases and fix for 32-bit - int64_t offset = 16; + // FIXME: finish layout for virtual bases vtable = Builder.CreateGEP(vtable, llvm::ConstantInt::get(llvm::Type::Int64Ty, - offset)); + offset/8)); return vtable; } |