diff options
author | Mike Stump <mrs@apple.com> | 2009-11-14 15:55:18 +0000 |
---|---|---|
committer | Mike Stump <mrs@apple.com> | 2009-11-14 15:55:18 +0000 |
commit | 1acec6a41a76f84c2a5f0ecb411da60b97ad674e (patch) | |
tree | 984d5e6f7c3bc1f04db572bf44553ceaff44dcbf /clang | |
parent | 4197054ece68096af832070812526eea5802e81e (diff) | |
download | bcm5719-llvm-1acec6a41a76f84c2a5f0ecb411da60b97ad674e.tar.gz bcm5719-llvm-1acec6a41a76f84c2a5f0ecb411da60b97ad674e.zip |
Build up more of the rtti info for a class. WIP.
llvm-svn: 88795
Diffstat (limited to 'clang')
-rw-r--r-- | clang/lib/CodeGen/CGRtti.cpp | 75 |
1 files changed, 49 insertions, 26 deletions
diff --git a/clang/lib/CodeGen/CGRtti.cpp b/clang/lib/CodeGen/CGRtti.cpp index 8484e2d7dab..3d76bcd9651 100644 --- a/clang/lib/CodeGen/CGRtti.cpp +++ b/clang/lib/CodeGen/CGRtti.cpp @@ -24,6 +24,25 @@ public: : CGM(cgm), VMContext(cgm.getModule().getContext()), Int8PtrTy(llvm::Type::getInt8PtrTy(VMContext)) { } + llvm::Constant *Buildclass_type_infoDesc() { + // Build a descriptor for class_type_info. + llvm::StringRef Name = "_ZTVN10__cxxabiv121__vmi_class_type_infoE"; + llvm::Constant *GV = CGM.getModule().getGlobalVariable(Name); + if (GV) + GV = llvm::ConstantExpr::getBitCast(GV, + llvm::PointerType::get(Int8PtrTy, 0)); + else { + llvm::GlobalVariable::LinkageTypes linktype; + linktype = llvm::GlobalValue::ExternalLinkage; + GV = new llvm::GlobalVariable(CGM.getModule(), Int8PtrTy, + true, linktype, 0, Name); + } + llvm::Constant *C; + C = llvm::ConstantInt::get(llvm::Type::getInt64Ty(VMContext), 2); + C = llvm::ConstantExpr::getInBoundsGetElementPtr(GV, &C, 1); + return llvm::ConstantExpr::getBitCast(C, Int8PtrTy); + } + llvm::Constant *BuildName(const CXXRecordDecl *RD) { llvm::SmallString<256> OutName; llvm::raw_svector_ostream Out(OutName); @@ -42,36 +61,40 @@ public: s = llvm::ConstantExpr::getBitCast(s, Int8PtrTy); return s; }; -}; -llvm::Constant *CodeGenModule::GenerateRtti(const CXXRecordDecl *RD) { - RttiBuilder b(*this); + llvm::Constant *Buildclass_type_info(const CXXRecordDecl *RD) { + const llvm::Type *Int8PtrTy = llvm::Type::getInt8PtrTy(VMContext); - const llvm::Type *Int8PtrTy = llvm::Type::getInt8PtrTy(VMContext); + if (!CGM.getContext().getLangOptions().Rtti) + return llvm::Constant::getNullValue(Int8PtrTy); - if (!getContext().getLangOptions().Rtti) - return llvm::Constant::getNullValue(Int8PtrTy); - - llvm::SmallString<256> OutName; - llvm::raw_svector_ostream Out(OutName); - mangleCXXRtti(getMangleContext(), Context.getTagDeclType(RD), Out); + llvm::SmallString<256> OutName; + llvm::raw_svector_ostream Out(OutName); + mangleCXXRtti(CGM.getMangleContext(), CGM.getContext().getTagDeclType(RD), + Out); - llvm::GlobalVariable::LinkageTypes linktype; - linktype = llvm::GlobalValue::LinkOnceODRLinkage; - std::vector<llvm::Constant *> info; - // assert(0 && "FIXME: implement rtti descriptor"); - // FIXME: descriptor - info.push_back(llvm::Constant::getNullValue(Int8PtrTy)); - info.push_back(b.BuildName(RD)); + llvm::GlobalVariable::LinkageTypes linktype; + linktype = llvm::GlobalValue::LinkOnceODRLinkage; + std::vector<llvm::Constant *> info; + + info.push_back(Buildclass_type_infoDesc()); + info.push_back(BuildName(RD)); + + // FIXME: rest of rtti bits + + llvm::Constant *C; + llvm::ArrayType *type = llvm::ArrayType::get(Int8PtrTy, info.size()); + C = llvm::ConstantArray::get(type, info); + llvm::Constant *Rtti = + new llvm::GlobalVariable(CGM.getModule(), type, true, linktype, C, + Out.str()); + Rtti = llvm::ConstantExpr::getBitCast(Rtti, Int8PtrTy); + return Rtti; + } +}; - // FIXME: rest of rtti bits +llvm::Constant *CodeGenModule::GenerateRtti(const CXXRecordDecl *RD) { + RttiBuilder b(*this); - llvm::Constant *C; - llvm::ArrayType *type = llvm::ArrayType::get(Int8PtrTy, info.size()); - C = llvm::ConstantArray::get(type, info); - llvm::Constant *Rtti = - new llvm::GlobalVariable(getModule(), type, true, linktype, C, - Out.str()); - Rtti = llvm::ConstantExpr::getBitCast(Rtti, Int8PtrTy); - return Rtti; + return b.Buildclass_type_info(RD); } |