[cfe-commits] r88792 - /cfe/trunk/lib/CodeGen/CGRtti.cpp
Mike Stump
mrs at apple.com
Sat Nov 14 06:25:19 PST 2009
Author: mrs
Date: Sat Nov 14 08:25:18 2009
New Revision: 88792
URL: http://llvm.org/viewvc/llvm-project?rev=88792&view=rev
Log:
Add the name to the rtti data structure.
Modified:
cfe/trunk/lib/CodeGen/CGRtti.cpp
Modified: cfe/trunk/lib/CodeGen/CGRtti.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGRtti.cpp?rev=88792&r1=88791&r2=88792&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGRtti.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGRtti.cpp Sat Nov 14 08:25:18 2009
@@ -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 @@
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());
More information about the cfe-commits
mailing list