]> granicus.if.org Git - clang/commitdiff
Change CodeGenModule to only create ObjC runtime for ObjC files
authorDaniel Dunbar <daniel@zuster.org>
Mon, 11 Aug 2008 18:12:00 +0000 (18:12 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Mon, 11 Aug 2008 18:12:00 +0000 (18:12 +0000)
 - Changed CodeGenModule::getObjCRuntime to return reference.
 - Added CodeGenModule::hasObjCRuntime predicate.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@54645 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGExpr.cpp
lib/CodeGen/CGExprConstant.cpp
lib/CodeGen/CGExprScalar.cpp
lib/CodeGen/CGObjC.cpp
lib/CodeGen/CodeGenModule.cpp
lib/CodeGen/CodeGenModule.h

index 68878a2e5111ee88da7d39e3bd4ae3c72b145fc8..89f552225c1a31f386cf14e52961cba97b8dc0a1 100644 (file)
@@ -744,7 +744,7 @@ LValue CodeGenFunction::EmitObjCIvarRefLValue(const ObjCIvarRefExpr *E) {
   // a class without recompiling all of the subclasses.  If this is the case
   // then the CGObjCRuntime subclass must return true to LateBoundIvars and
   // implement the lookup itself.
-  if (CGM.getObjCRuntime()->LateBoundIVars()) {
+  if (CGM.getObjCRuntime().LateBoundIVars()) {
     assert(0 && "FIXME: Implement support for late-bound instance variables");
     return LValue(); // Not reached.
   }
index b1f7c5161d7cacec2f35e9e4e5df4cccd2c10e58..5865f21522300803c15cd1aa37b5364748acd009 100644 (file)
@@ -61,7 +61,7 @@ public:
     return llvm::ConstantInt::get(ConvertType(E->getType()), E->getValue());
   }
   llvm::Constant *VisitObjCStringLiteral(const ObjCStringLiteral *E) {
-    return CGM.getObjCRuntime()->GenerateConstantString(
+    return CGM.getObjCRuntime().GenerateConstantString(
         E->getString()->getStrData(), E->getString()->getByteLength());
   }
   
index 63b8efc5dcbcca334492fb2a47296c7070489d88..2bd39c1bd6b9c841730e2a939b1772c465cd5c0a 100644 (file)
@@ -49,7 +49,9 @@ public:
 
   ScalarExprEmitter(CodeGenFunction &cgf) : CGF(cgf), 
     Builder(CGF.Builder), 
-    Runtime(CGF.CGM.getObjCRuntime()) {
+    Runtime(0) {
+    if (CGF.CGM.hasObjCRuntime())
+      Runtime = &CGF.CGM.getObjCRuntime();
   }
   
   //===--------------------------------------------------------------------===//
index d1545a2d359246213a891cba65cadb32e4f71ce3..e152488bfae9ce0539b49242d12cffb298c627e7 100644 (file)
@@ -21,7 +21,7 @@ using namespace CodeGen;
 
 /// Emits an instance of NSConstantString representing the object.
 llvm::Value *CodeGenFunction::EmitObjCStringLiteral(const ObjCStringLiteral *E){
-  return CGM.getObjCRuntime()->GenerateConstantString(
+  return CGM.getObjCRuntime().GenerateConstantString(
       E->getString()->getStrData(), E->getString()->getByteLength());
 }
 
@@ -31,7 +31,7 @@ llvm::Value *CodeGenFunction::EmitObjCSelectorExpr(const ObjCSelectorExpr *E) {
   // Note that this implementation allows for non-constant strings to be passed
   // as arguments to @selector().  Currently, the only thing preventing this
   // behaviour is the type checking in the front end.
-  return CGM.getObjCRuntime()->GetSelector(Builder, E->getSelector());
+  return CGM.getObjCRuntime().GetSelector(Builder, E->getSelector());
 }
 
 
@@ -41,7 +41,7 @@ llvm::Value *CodeGenFunction::EmitObjCMessageExpr(const ObjCMessageExpr *E) {
   // implementation vary between runtimes.  We can get the receiver and
   // arguments in generic code.
   
-  CGObjCRuntime *Runtime = CGM.getObjCRuntime();
+  CGObjCRuntime &Runtime = CGM.getObjCRuntime();
   const Expr *ReceiverExpr = E->getReceiver();
   bool isSuperMessage = false;
   // Find the receiver
@@ -53,7 +53,7 @@ llvm::Value *CodeGenFunction::EmitObjCMessageExpr(const ObjCMessageExpr *E) {
     }
     llvm::Value *ClassName = CGM.GetAddrOfConstantString(classname);
     ClassName = Builder.CreateStructGEP(ClassName, 0);
-    Receiver = Runtime->LookupClass(Builder, ClassName);
+    Receiver = Runtime.LookupClass(Builder, ClassName);
   } else if (const PredefinedExpr *PDE =
                dyn_cast<PredefinedExpr>(E->getReceiver())) {
     assert(PDE->getIdentType() == PredefinedExpr::ObjCSuper);
@@ -89,12 +89,12 @@ llvm::Value *CodeGenFunction::EmitObjCMessageExpr(const ObjCMessageExpr *E) {
     const ObjCMethodDecl *OMD = cast<ObjCMethodDecl>(CurFuncDecl);
     const char *SuperClass =
       OMD->getClassInterface()->getSuperClass()->getName();
-    return Runtime->GenerateMessageSendSuper(Builder, ConvertType(E->getType()),
+    return Runtime.GenerateMessageSendSuper(Builder, ConvertType(E->getType()),
                                              Receiver, SuperClass,
                                              Receiver, E->getSelector(),
                                              &Args[0], Args.size());
   }
-  return Runtime->GenerateMessageSend(Builder, ConvertType(E->getType()),
+  return Runtime.GenerateMessageSend(Builder, ConvertType(E->getType()),
                                       LoadObjCSelf(),
                                       Receiver, E->getSelector(),
                                       &Args[0], Args.size());
@@ -119,7 +119,7 @@ void CodeGenFunction::GenerateObjCMethod(const ObjCMethodDecl *OMD) {
   }
   const llvm::Type *ReturnTy = 
     CGM.getTypes().ConvertReturnType(OMD->getResultType());
-  CurFn = CGM.getObjCRuntime()->MethodPreamble(
+  CurFn = CGM.getObjCRuntime().MethodPreamble(
                                           OMD->getClassInterface()->getName(),
                                               CategoryName,
                                               OMD->getSelector().getName(),
index b3e721308d654bbda4a134e943645e76a7c63dde..347f4d24f903fc8d6aad66e76906863740dd6bd4 100644 (file)
@@ -33,13 +33,16 @@ CodeGenModule::CodeGenModule(ASTContext &C, const LangOptions &LO,
                              Diagnostic &diags, bool GenerateDebugInfo,
                              bool UseMacObjCRuntime)
   : Context(C), Features(LO), TheModule(M), TheTargetData(TD), Diags(diags),
-    Types(C, M, TD), MemCpyFn(0), MemMoveFn(0), MemSetFn(0),
+    Types(C, M, TD), Runtime(0), MemCpyFn(0), MemMoveFn(0), MemSetFn(0),
     CFConstantStringClassRef(0) {
-  //TODO: Make this selectable at runtime
-  if (UseMacObjCRuntime) {
-    Runtime = CreateMacObjCRuntime(*this);
-  } else {
-    Runtime = CreateGNUObjCRuntime(*this);
+
+  if (Features.ObjC1) {
+    // TODO: Make this selectable at runtime
+    if (UseMacObjCRuntime) {
+      Runtime = CreateMacObjCRuntime(*this);
+    } else {
+      Runtime = CreateGNUObjCRuntime(*this);
+    }
   }
 
   // If debug info generation is enabled, create the CGDebugInfo object.
@@ -53,9 +56,9 @@ CodeGenModule::~CodeGenModule() {
 
 void CodeGenModule::Release() {
   EmitStatics();
-  llvm::Function *ObjCInitFunction = Runtime->ModuleInitFunction();
-  if (ObjCInitFunction)
-    AddGlobalCtor(ObjCInitFunction);
+  if (Runtime)
+    if (llvm::Function *ObjCInitFunction = Runtime->ModuleInitFunction())
+      AddGlobalCtor(ObjCInitFunction);
   EmitCtorList(GlobalCtors, "llvm.global_ctors");
   EmitCtorList(GlobalDtors, "llvm.global_dtors");
   EmitAnnotations();
index bd45f6580f02a45202659d28c32373ccf78d6db7..0b313c4205241d232fddafeed42a0ff4f7c19bbb 100644 (file)
@@ -111,8 +111,18 @@ public:
   
   /// Release - Finalize LLVM code generation.
   void Release();
+
+  /// getObjCRuntime() - Return a reference to the configured
+  /// Objective-C runtime.
+  CGObjCRuntime &getObjCRuntime() { 
+    assert(Runtime && "No Objective-C runtime has been configured.");
+    return *Runtime; 
+  }
   
-  CGObjCRuntime *getObjCRuntime() { return Runtime; }
+  /// hasObjCRuntime() - Return true iff an Objective-C runtime has
+  /// been configured.
+  bool hasObjCRuntime() { return !!Runtime; }
+
   CGDebugInfo *getDebugInfo() { return DebugInfo; }
   ASTContext &getContext() const { return Context; }
   const LangOptions &getLangOptions() const { return Features; }