diff options
Diffstat (limited to 'lib/CodeGen/CGRtti.cpp')
-rw-r--r-- | lib/CodeGen/CGRtti.cpp | 39 |
1 files changed, 35 insertions, 4 deletions
diff --git a/lib/CodeGen/CGRtti.cpp b/lib/CodeGen/CGRtti.cpp index 7af15f0a8c..8484e2d7da 100644 --- a/lib/CodeGen/CGRtti.cpp +++ b/lib/CodeGen/CGRtti.cpp @@ -15,7 +15,38 @@ using namespace clang; using namespace CodeGen; +class RttiBuilder { + CodeGenModule &CGM; // Per-module state. + llvm::LLVMContext &VMContext; + const llvm::Type *Int8PtrTy; +public: + RttiBuilder(CodeGenModule &cgm) + : CGM(cgm), VMContext(cgm.getModule().getContext()), + Int8PtrTy(llvm::Type::getInt8PtrTy(VMContext)) { } + + llvm::Constant *BuildName(const CXXRecordDecl *RD) { + llvm::SmallString<256> OutName; + llvm::raw_svector_ostream Out(OutName); + mangleCXXRttiName(CGM.getMangleContext(), + CGM.getContext().getTagDeclType(RD), Out); + + llvm::GlobalVariable::LinkageTypes linktype; + linktype = llvm::GlobalValue::LinkOnceODRLinkage; + + llvm::Constant *C; + C = llvm::ConstantArray::get(VMContext, Out.str().substr(4)); + + llvm::Constant *s = new llvm::GlobalVariable(CGM.getModule(), C->getType(), + true, linktype, C, + Out.str()); + s = llvm::ConstantExpr::getBitCast(s, Int8PtrTy); + return s; + }; +}; + llvm::Constant *CodeGenModule::GenerateRtti(const CXXRecordDecl *RD) { + RttiBuilder b(*this); + const llvm::Type *Int8PtrTy = llvm::Type::getInt8PtrTy(VMContext); if (!getContext().getLangOptions().Rtti) @@ -26,14 +57,14 @@ llvm::Constant *CodeGenModule::GenerateRtti(const CXXRecordDecl *RD) { mangleCXXRtti(getMangleContext(), Context.getTagDeclType(RD), Out); llvm::GlobalVariable::LinkageTypes linktype; - linktype = llvm::GlobalValue::WeakAnyLinkage; + linktype = llvm::GlobalValue::LinkOnceODRLinkage; std::vector<llvm::Constant *> info; // assert(0 && "FIXME: implement rtti descriptor"); // FIXME: descriptor info.push_back(llvm::Constant::getNullValue(Int8PtrTy)); - // assert(0 && "FIXME: implement rtti ts"); - // FIXME: TS - info.push_back(llvm::Constant::getNullValue(Int8PtrTy)); + info.push_back(b.BuildName(RD)); + + // FIXME: rest of rtti bits llvm::Constant *C; llvm::ArrayType *type = llvm::ArrayType::get(Int8PtrTy, info.size()); |