2009-10-11 04:49:04 +08:00
|
|
|
//===--- CGCXXRtti.cpp - Emit LLVM Code for C++ RTTI descriptors ----------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This contains code dealing with C++ code generation of RTTI descriptors.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "CodeGenModule.h"
|
|
|
|
using namespace clang;
|
|
|
|
using namespace CodeGen;
|
|
|
|
|
|
|
|
llvm::Constant *CodeGenModule::GenerateRtti(const CXXRecordDecl *RD) {
|
2009-10-30 09:26:12 +08:00
|
|
|
const llvm::Type *Int8PtrTy = llvm::Type::getInt8PtrTy(VMContext);
|
2009-10-11 04:49:04 +08:00
|
|
|
|
|
|
|
if (!getContext().getLangOptions().Rtti)
|
2009-10-30 09:26:12 +08:00
|
|
|
return llvm::Constant::getNullValue(Int8PtrTy);
|
2009-10-11 04:49:04 +08:00
|
|
|
|
|
|
|
llvm::SmallString<256> OutName;
|
|
|
|
llvm::raw_svector_ostream Out(OutName);
|
2009-10-30 09:52:02 +08:00
|
|
|
mangleCXXRtti(getMangleContext(), Context.getTagDeclType(RD), Out);
|
2009-10-12 05:24:51 +08:00
|
|
|
|
2009-10-11 04:49:04 +08:00
|
|
|
llvm::GlobalVariable::LinkageTypes linktype;
|
|
|
|
linktype = llvm::GlobalValue::WeakAnyLinkage;
|
|
|
|
std::vector<llvm::Constant *> info;
|
|
|
|
// assert(0 && "FIXME: implement rtti descriptor");
|
|
|
|
// FIXME: descriptor
|
2009-10-30 09:26:12 +08:00
|
|
|
info.push_back(llvm::Constant::getNullValue(Int8PtrTy));
|
2009-10-11 04:49:04 +08:00
|
|
|
// assert(0 && "FIXME: implement rtti ts");
|
|
|
|
// FIXME: TS
|
2009-10-30 09:26:12 +08:00
|
|
|
info.push_back(llvm::Constant::getNullValue(Int8PtrTy));
|
2009-10-11 04:49:04 +08:00
|
|
|
|
|
|
|
llvm::Constant *C;
|
2009-10-30 09:26:12 +08:00
|
|
|
llvm::ArrayType *type = llvm::ArrayType::get(Int8PtrTy, info.size());
|
2009-10-11 04:49:04 +08:00
|
|
|
C = llvm::ConstantArray::get(type, info);
|
2009-10-30 09:26:12 +08:00
|
|
|
llvm::Constant *Rtti =
|
|
|
|
new llvm::GlobalVariable(getModule(), type, true, linktype, C,
|
|
|
|
Out.str());
|
|
|
|
Rtti = llvm::ConstantExpr::getBitCast(Rtti, Int8PtrTy);
|
2009-10-11 04:49:04 +08:00
|
|
|
return Rtti;
|
|
|
|
}
|