From 391d77a26382dddf25da73e29fc1fa5aaaea4c6f Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 30 Mar 2008 23:03:07 +0000 Subject: Add initial support for objc codegen for methods, ivars, and the etoile runtime, patch by David Chisnall! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@48969 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CodeGenModule.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'lib/CodeGen/CodeGenModule.cpp') diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index b5d9db98ef..8374f2bab6 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -34,10 +34,16 @@ CodeGenModule::CodeGenModule(ASTContext &C, const LangOptions &LO, : Context(C), Features(LO), TheModule(M), TheTargetData(TD), Diags(diags), Types(C, M, TD), MemCpyFn(0), MemSetFn(0), CFConstantStringClassRef(0) { //TODO: Make this selectable at runtime - Runtime = CreateObjCRuntime(M); + Runtime = CreateObjCRuntime(M, + getTypes().ConvertType(getContext().IntTy), + getTypes().ConvertType(getContext().LongTy)); } CodeGenModule::~CodeGenModule() { + llvm::Function *ObjCInitFunction = Runtime->ModuleInitFunction(); + if (ObjCInitFunction) { + AddGlobalCtor(ObjCInitFunction); + } EmitGlobalCtors(); delete Runtime; } @@ -70,7 +76,10 @@ void CodeGenModule::AddGlobalCtor(llvm::Function * Ctor) { GlobalCtors.push_back(Ctor); } +/// EmitGlobalCtors - Generates the array of contsturctor functions to be +/// called on module load, if any have been registered with AddGlobalCtor. void CodeGenModule::EmitGlobalCtors() { + if (GlobalCtors.empty()) return; // Get the type of @llvm.global_ctors std::vector CtorFields; CtorFields.push_back(llvm::IntegerType::get(32)); @@ -114,6 +123,8 @@ void CodeGenModule::EmitGlobalCtors() { } + + /// ReplaceMapValuesWith - This is a really slow and bad function that /// searches for any entries in GlobalDeclMap that point to OldVal, changing /// them to point to NewVal. This is badbadbad, FIXME! @@ -263,6 +274,12 @@ llvm::Constant *CodeGenModule::GetAddrOfGlobalVar(const VarDecl *D, } +void CodeGenModule::EmitObjCMethod(const ObjCMethodDecl *OMD) { + // If this is not a prototype, emit the body. + if (OMD->getBody()) + CodeGenFunction(*this).GenerateObjCMethod(OMD); +} + void CodeGenModule::EmitFunction(const FunctionDecl *FD) { // If this is not a prototype, emit the body. if (FD->getBody()) -- cgit v1.2.3-18-g5258