forked from OSchip/llvm-project
Start attempting to generate code for C++ ctors.
llvm-svn: 69168
This commit is contained in:
parent
635168aa33
commit
f747524819
|
@ -114,7 +114,6 @@ RValue CodeGenFunction::EmitCXXMemberCallExpr(const CXXMemberCallExpr *CE) {
|
||||||
Callee, Args, MD);
|
Callee, Args, MD);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
llvm::Value *CodeGenFunction::LoadCXXThis() {
|
llvm::Value *CodeGenFunction::LoadCXXThis() {
|
||||||
assert(isa<CXXMethodDecl>(CurFuncDecl) &&
|
assert(isa<CXXMethodDecl>(CurFuncDecl) &&
|
||||||
"Must be in a C++ member function decl to load 'this'");
|
"Must be in a C++ member function decl to load 'this'");
|
||||||
|
@ -124,3 +123,35 @@ llvm::Value *CodeGenFunction::LoadCXXThis() {
|
||||||
// FIXME: What if we're inside a block?
|
// FIXME: What if we're inside a block?
|
||||||
return Builder.CreateLoad(LocalDeclMap[CXXThisDecl], "this");
|
return Builder.CreateLoad(LocalDeclMap[CXXThisDecl], "this");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *CodeGenModule::getMangledCXXCtorName(const CXXConstructorDecl *D,
|
||||||
|
CXXCtorType Type) {
|
||||||
|
llvm::SmallString<256> Name;
|
||||||
|
llvm::raw_svector_ostream Out(Name);
|
||||||
|
mangleCXXCtor(D, Type, Context, Out);
|
||||||
|
|
||||||
|
Name += '\0';
|
||||||
|
return UniqueMangledName(Name.begin(), Name.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
void CodeGenModule::EmitCXXConstructor(const CXXConstructorDecl *D,
|
||||||
|
CXXCtorType Type) {
|
||||||
|
const llvm::FunctionType *Ty =
|
||||||
|
getTypes().GetFunctionType(getTypes().getFunctionInfo(D), false);
|
||||||
|
|
||||||
|
const char *Name = getMangledCXXCtorName(D, Type);
|
||||||
|
llvm::Function *Fn =
|
||||||
|
cast<llvm::Function>(GetOrCreateLLVMFunction(Name, Ty, D));
|
||||||
|
|
||||||
|
CodeGenFunction(*this).GenerateCode(D, Fn);
|
||||||
|
|
||||||
|
SetFunctionDefinitionAttributes(D, Fn);
|
||||||
|
SetLLVMFunctionAttributesForDefinition(D, Fn);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CodeGenModule::EmitCXXConstructors(const CXXConstructorDecl *D) {
|
||||||
|
ErrorUnsupported(D, "C++ constructor", true);
|
||||||
|
|
||||||
|
EmitCXXConstructor(D, Ctor_Complete);
|
||||||
|
EmitCXXConstructor(D, Ctor_Base);
|
||||||
|
}
|
||||||
|
|
|
@ -156,7 +156,14 @@ const char *CodeGenModule::getMangledName(const NamedDecl *ND) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Name += '\0';
|
Name += '\0';
|
||||||
return MangledNames.GetOrCreateValue(Name.begin(), Name.end()).getKeyData();
|
return UniqueMangledName(Name.begin(), Name.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *CodeGenModule::UniqueMangledName(const char *NameStart,
|
||||||
|
const char *NameEnd) {
|
||||||
|
assert(*(NameEnd - 1) == '\0' && "Mangled name must be null terminated!");
|
||||||
|
|
||||||
|
return MangledNames.GetOrCreateValue(NameStart, NameEnd).getKeyData();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// AddGlobalCtor - Add a function to the list that will be called before
|
/// AddGlobalCtor - Add a function to the list that will be called before
|
||||||
|
@ -1344,9 +1351,13 @@ void CodeGenModule::EmitTopLevelDecl(Decl *D) {
|
||||||
EmitGlobal(cast<ValueDecl>(D));
|
EmitGlobal(cast<ValueDecl>(D));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
// C++ Decls
|
||||||
case Decl::Namespace:
|
case Decl::Namespace:
|
||||||
EmitNamespace(cast<NamespaceDecl>(D));
|
EmitNamespace(cast<NamespaceDecl>(D));
|
||||||
break;
|
break;
|
||||||
|
case Decl::CXXConstructor:
|
||||||
|
EmitCXXConstructors(cast<CXXConstructorDecl>(D));
|
||||||
|
break;
|
||||||
|
|
||||||
// Objective-C Decls
|
// Objective-C Decls
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#include "clang/AST/Attr.h"
|
#include "clang/AST/Attr.h"
|
||||||
#include "CGBlocks.h"
|
#include "CGBlocks.h"
|
||||||
#include "CGCall.h"
|
#include "CGCall.h"
|
||||||
|
#include "CGCXX.h"
|
||||||
#include "CodeGenTypes.h"
|
#include "CodeGenTypes.h"
|
||||||
#include "llvm/ADT/DenseMap.h"
|
#include "llvm/ADT/DenseMap.h"
|
||||||
#include "llvm/ADT/StringMap.h"
|
#include "llvm/ADT/StringMap.h"
|
||||||
|
@ -311,6 +312,8 @@ public:
|
||||||
AttributeListType &PAL);
|
AttributeListType &PAL);
|
||||||
|
|
||||||
const char *getMangledName(const NamedDecl *ND);
|
const char *getMangledName(const NamedDecl *ND);
|
||||||
|
const char *getMangledCXXCtorName(const CXXConstructorDecl *D,
|
||||||
|
CXXCtorType Type);
|
||||||
|
|
||||||
enum GVALinkage {
|
enum GVALinkage {
|
||||||
GVA_Internal,
|
GVA_Internal,
|
||||||
|
@ -320,6 +323,10 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
/// UniqueMangledName - Unique a name by (if necessary) inserting it into the
|
||||||
|
/// MangledNames string map.
|
||||||
|
const char *UniqueMangledName(const char *NameStart, const char *NameEnd);
|
||||||
|
|
||||||
llvm::Constant *GetOrCreateLLVMFunction(const char *MangledName,
|
llvm::Constant *GetOrCreateLLVMFunction(const char *MangledName,
|
||||||
const llvm::Type *Ty,
|
const llvm::Type *Ty,
|
||||||
const FunctionDecl *D);
|
const FunctionDecl *D);
|
||||||
|
@ -353,9 +360,20 @@ private:
|
||||||
void EmitGlobalVarDefinition(const VarDecl *D);
|
void EmitGlobalVarDefinition(const VarDecl *D);
|
||||||
void EmitAliasDefinition(const ValueDecl *D);
|
void EmitAliasDefinition(const ValueDecl *D);
|
||||||
void EmitObjCPropertyImplementations(const ObjCImplementationDecl *D);
|
void EmitObjCPropertyImplementations(const ObjCImplementationDecl *D);
|
||||||
|
|
||||||
|
// C++ related functions.
|
||||||
|
|
||||||
void EmitNamespace(const NamespaceDecl *D);
|
void EmitNamespace(const NamespaceDecl *D);
|
||||||
void EmitLinkageSpec(const LinkageSpecDecl *D);
|
void EmitLinkageSpec(const LinkageSpecDecl *D);
|
||||||
|
|
||||||
|
/// EmitCXXConstructors - Emit constructors (base, complete) from a
|
||||||
|
/// C++ constructor Decl.
|
||||||
|
void EmitCXXConstructors(const CXXConstructorDecl *D);
|
||||||
|
|
||||||
|
/// EmitCXXConstructor - Emit a single constructor with the given type from
|
||||||
|
/// a C++ constructor Decl.
|
||||||
|
void EmitCXXConstructor(const CXXConstructorDecl *D, CXXCtorType Type);
|
||||||
|
|
||||||
// FIXME: Hardcoding priority here is gross.
|
// FIXME: Hardcoding priority here is gross.
|
||||||
void AddGlobalCtor(llvm::Function * Ctor, int Priority=65535);
|
void AddGlobalCtor(llvm::Function * Ctor, int Priority=65535);
|
||||||
void AddGlobalDtor(llvm::Function * Dtor, int Priority=65535);
|
void AddGlobalDtor(llvm::Function * Dtor, int Priority=65535);
|
||||||
|
|
Loading…
Reference in New Issue