[cfe-commits] r54624 - in /cfe/trunk/lib/CodeGen: CGObjCGNU.cpp CGObjCMac.cpp CGObjCRuntime.h CodeGenModule.cpp CodeGenModule.h ModuleBuilder.cpp

Daniel Dunbar daniel at zuster.org
Sun Aug 10 19:45:12 PDT 2008


Author: ddunbar
Date: Sun Aug 10 21:45:11 2008
New Revision: 54624

URL: http://llvm.org/viewvc/llvm-project?rev=54624&view=rev
Log:
Add dummy Mac Objective-C runtime interface.
  - Not currently accessible and completely non-functional.

Added:
    cfe/trunk/lib/CodeGen/CGObjCMac.cpp
Modified:
    cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
    cfe/trunk/lib/CodeGen/CGObjCRuntime.h
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp
    cfe/trunk/lib/CodeGen/CodeGenModule.h
    cfe/trunk/lib/CodeGen/ModuleBuilder.cpp

Modified: cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCGNU.cpp?rev=54624&r1=54623&r2=54624&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCGNU.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCGNU.cpp Sun Aug 10 21:45:11 2008
@@ -864,6 +864,6 @@
   return Method;
 }
 
-CodeGen::CGObjCRuntime *CodeGen::CreateObjCRuntime(CodeGen::CodeGenModule &CGM){
+CodeGen::CGObjCRuntime *CodeGen::CreateGNUObjCRuntime(CodeGen::CodeGenModule &CGM){
   return new CGObjCGNU(CGM);
 }

Added: cfe/trunk/lib/CodeGen/CGObjCMac.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCMac.cpp?rev=54624&view=auto

==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (added)
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Sun Aug 10 21:45:11 2008
@@ -0,0 +1,214 @@
+//===------- CGObjCMac.cpp - Interface to Apple Objective-C Runtime -------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This provides Objective-C code generation targetting the Apple runtime.
+//
+//===----------------------------------------------------------------------===//
+
+#include "CGObjCRuntime.h"
+#include "CodeGenModule.h"
+#include "clang/AST/ASTContext.h"
+#include "llvm/Module.h"
+#include "llvm/Support/Compiler.h"
+#include "llvm/Support/IRBuilder.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringMap.h"
+#include <map>
+
+using namespace clang;
+
+namespace {
+class CGObjCMac : public CodeGen::CGObjCRuntime {
+private:
+  CodeGen::CodeGenModule &CGM;
+
+public:
+  CGObjCMac(CodeGen::CodeGenModule &cgm);
+  virtual llvm::Constant *GenerateConstantString(const char *String, 
+                                                 const size_t length);
+
+  virtual llvm::Value *GenerateMessageSend(llvm::IRBuilder<> &Builder,
+                                           const llvm::Type *ReturnTy,
+                                           llvm::Value *Sender,
+                                           llvm::Value *Receiver,
+                                           Selector Sel,
+                                           llvm::Value** ArgV,
+                                           unsigned ArgC);
+
+  virtual llvm::Value *GenerateMessageSendSuper(llvm::IRBuilder<> &Builder,
+                                                const llvm::Type *ReturnTy,
+                                                llvm::Value *Sender,
+                                                const char *SuperClassName,
+                                                llvm::Value *Receiver,
+                                                Selector Sel,
+                                                llvm::Value** ArgV,
+                                                unsigned ArgC);
+
+  virtual llvm::Value *LookupClass(llvm::IRBuilder<> &Builder,
+                                   llvm::Value *ClassName);
+
+  virtual llvm::Value *GetSelector(llvm::IRBuilder<> &Builder, Selector Sel);
+  
+  virtual llvm::Function *MethodPreamble(const std::string &ClassName,
+                                         const std::string &CategoryName,
+                                         const std::string &MethodName,
+                                         const llvm::Type *ReturnTy,
+                                         const llvm::Type *SelfTy,
+                                         const llvm::Type **ArgTy,
+                                         unsigned ArgC,
+                                         bool isClassMethod,
+                                         bool isVarArg);
+
+  virtual void GenerateCategory(const char *ClassName, const char *CategoryName,
+           const llvm::SmallVectorImpl<Selector>  &InstanceMethodSels,
+           const llvm::SmallVectorImpl<llvm::Constant *>  &InstanceMethodTypes,
+           const llvm::SmallVectorImpl<Selector>  &ClassMethodSels,
+           const llvm::SmallVectorImpl<llvm::Constant *>  &ClassMethodTypes,
+           const llvm::SmallVectorImpl<std::string> &Protocols);
+
+  virtual void GenerateClass(
+           const char *ClassName,
+           const char *SuperClassName,
+           const int instanceSize,
+           const llvm::SmallVectorImpl<llvm::Constant *>  &IvarNames,
+           const llvm::SmallVectorImpl<llvm::Constant *>  &IvarTypes,
+           const llvm::SmallVectorImpl<llvm::Constant *>  &IvarOffsets,
+           const llvm::SmallVectorImpl<Selector>  &InstanceMethodSels,
+           const llvm::SmallVectorImpl<llvm::Constant *>  &InstanceMethodTypes,
+           const llvm::SmallVectorImpl<Selector>  &ClassMethodSels,
+           const llvm::SmallVectorImpl<llvm::Constant *>  &ClassMethodTypes,
+           const llvm::SmallVectorImpl<std::string> &Protocols);
+
+  virtual llvm::Value *GenerateProtocolRef(llvm::IRBuilder<> &Builder,
+                                           const char *ProtocolName);
+
+  virtual void GenerateProtocol(const char *ProtocolName,
+      const llvm::SmallVectorImpl<std::string> &Protocols,
+      const llvm::SmallVectorImpl<llvm::Constant *>  &InstanceMethodNames,
+      const llvm::SmallVectorImpl<llvm::Constant *>  &InstanceMethodTypes,
+      const llvm::SmallVectorImpl<llvm::Constant *>  &ClassMethodNames,
+      const llvm::SmallVectorImpl<llvm::Constant *>  &ClassMethodTypes);
+
+  virtual llvm::Function *ModuleInitFunction();
+};
+} // end anonymous namespace
+ 
+CGObjCMac::CGObjCMac(CodeGen::CodeGenModule &cgm) : CGM(cgm) {
+}
+
+// This has to perform the lookup every time, since posing and related
+// techniques can modify the name -> class mapping.
+llvm::Value *CGObjCMac::LookupClass(llvm::IRBuilder<> &Builder,                                    
+                                    llvm::Value *ClassName) {
+  assert(0 && "Cannot lookup classes on Mac runtime.");
+  return 0;
+}
+
+/// GetSelector - Return the pointer to the unique'd string for this selector.
+llvm::Value *CGObjCMac::GetSelector(llvm::IRBuilder<> &Builder, Selector Sel) {
+  assert(0 && "Cannot get selector on Mac runtime.");
+  return 0;
+}
+
+/// Generate an NSConstantString object.
+llvm::Constant *CGObjCMac::GenerateConstantString(const char *String, 
+                                                  const size_t length) {
+  assert(0 && "Cannot generate constant string for Mac runtime.");
+  return 0;
+}
+
+/// Generates a message send where the super is the receiver.  This is
+/// a message send to self with special delivery semantics indicating
+/// which class's method should be called.
+llvm::Value *CGObjCMac::GenerateMessageSendSuper(llvm::IRBuilder<> &Builder,
+                                                 const llvm::Type *ReturnTy,
+                                                 llvm::Value *Sender,
+                                                 const char *SuperClassName,
+                                                 llvm::Value *Receiver,
+                                                 Selector Sel,
+                                                 llvm::Value** ArgV,
+                                                 unsigned ArgC) {
+  assert(0 && "Cannot generate message send to super for Mac runtime.");
+  return 0;
+}
+
+/// Generate code for a message send expression.  
+llvm::Value *CGObjCMac::GenerateMessageSend(llvm::IRBuilder<> &Builder,
+                                            const llvm::Type *ReturnTy,
+                                            llvm::Value *Sender,
+                                            llvm::Value *Receiver,
+                                            Selector Sel,
+                                            llvm::Value** ArgV,
+                                            unsigned ArgC) {
+  assert(0 && "Cannot generate message send for Mac runtime.");
+  return 0;
+}
+
+llvm::Value *CGObjCMac::GenerateProtocolRef(llvm::IRBuilder<> &Builder, 
+                                            const char *ProtocolName) {
+  assert(0 && "Cannot get protocol reference on Mac runtime.");
+  return 0;
+}
+
+void CGObjCMac::GenerateProtocol(const char *ProtocolName,
+    const llvm::SmallVectorImpl<std::string> &Protocols,
+    const llvm::SmallVectorImpl<llvm::Constant *>  &InstanceMethodNames,
+    const llvm::SmallVectorImpl<llvm::Constant *>  &InstanceMethodTypes,
+    const llvm::SmallVectorImpl<llvm::Constant *>  &ClassMethodNames,
+    const llvm::SmallVectorImpl<llvm::Constant *>  &ClassMethodTypes) {
+  assert(0 && "Cannot generate protocol for Mac runtime.");
+}
+
+void CGObjCMac::GenerateCategory(
+           const char *ClassName,
+           const char *CategoryName,
+           const llvm::SmallVectorImpl<Selector>  &InstanceMethodSels,
+           const llvm::SmallVectorImpl<llvm::Constant *>  &InstanceMethodTypes,
+           const llvm::SmallVectorImpl<Selector>  &ClassMethodSels,
+           const llvm::SmallVectorImpl<llvm::Constant *>  &ClassMethodTypes,
+           const llvm::SmallVectorImpl<std::string> &Protocols) {
+  assert(0 && "Cannot generate category for Mac runtime.");
+}
+
+void CGObjCMac::GenerateClass(
+           const char *ClassName,
+           const char *SuperClassName,
+           const int instanceSize,
+           const llvm::SmallVectorImpl<llvm::Constant *>  &IvarNames,
+           const llvm::SmallVectorImpl<llvm::Constant *>  &IvarTypes,
+           const llvm::SmallVectorImpl<llvm::Constant *>  &IvarOffsets,
+           const llvm::SmallVectorImpl<Selector>  &InstanceMethodSels,
+           const llvm::SmallVectorImpl<llvm::Constant *>  &InstanceMethodTypes,
+           const llvm::SmallVectorImpl<Selector>  &ClassMethodSels,
+           const llvm::SmallVectorImpl<llvm::Constant *>  &ClassMethodTypes,
+           const llvm::SmallVectorImpl<std::string> &Protocols) {
+  assert(0 && "Cannot generate class for Mac runtime.");
+}
+
+llvm::Function *CGObjCMac::ModuleInitFunction() { 
+  return NULL;
+}
+
+llvm::Function *CGObjCMac::MethodPreamble(
+                                         const std::string &ClassName,
+                                         const std::string &CategoryName,
+                                         const std::string &MethodName,
+                                         const llvm::Type *ReturnTy,
+                                         const llvm::Type *SelfTy,
+                                         const llvm::Type **ArgTy,
+                                         unsigned ArgC,
+                                         bool isClassMethod,
+                                         bool isVarArg) {
+  assert(0 && "Cannot generate method preamble for Mac runtime.");
+  return 0;
+}
+
+CodeGen::CGObjCRuntime *CodeGen::CreateMacObjCRuntime(CodeGen::CodeGenModule &CGM){
+  return new CGObjCMac(CGM);
+}

Modified: cfe/trunk/lib/CodeGen/CGObjCRuntime.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCRuntime.h?rev=54624&r1=54623&r2=54624&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCRuntime.h (original)
+++ cfe/trunk/lib/CodeGen/CGObjCRuntime.h Sun Aug 10 21:45:11 2008
@@ -1,4 +1,4 @@
-//===----- CGObjCRuntime.h - Emit LLVM Code from ASTs for a Module --------===//
+//===----- CGObjCRuntime.h - Interface to ObjC Runtimes ---------*- C++ -*-===//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -81,7 +81,7 @@
              const llvm::SmallVectorImpl<std::string> &Protocols) =0;
   /// Generate a reference to the named protocol.
   virtual llvm::Value *GenerateProtocolRef(llvm::IRBuilder<true> &Builder,
-                                           const char *ProtocolName) =0;
+                                           const char *ProtocolName) = 0;
   virtual llvm::Value *GenerateMessageSendSuper(llvm::IRBuilder<true> &Builder,
                                                 const llvm::Type *ReturnTy,
                                                 llvm::Value *Sender,
@@ -121,7 +121,8 @@
 
 /// Creates an instance of an Objective-C runtime class.  
 //TODO: This should include some way of selecting which runtime to target.
-CGObjCRuntime *CreateObjCRuntime(CodeGenModule &CGM);
+CGObjCRuntime *CreateGNUObjCRuntime(CodeGenModule &CGM);
+CGObjCRuntime *CreateMacObjCRuntime(CodeGenModule &CGM);
 }
 }
 #endif

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=54624&r1=54623&r2=54624&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Sun Aug 10 21:45:11 2008
@@ -34,12 +34,17 @@
 
 CodeGenModule::CodeGenModule(ASTContext &C, const LangOptions &LO,
                              llvm::Module &M, const llvm::TargetData &TD,
-                             Diagnostic &diags, bool GenerateDebugInfo)
+                             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),
     CFConstantStringClassRef(0) {
   //TODO: Make this selectable at runtime
-  Runtime = CreateObjCRuntime(*this);
+  if (UseMacObjCRuntime) {
+    Runtime = CreateMacObjCRuntime(*this);
+  } else {
+    Runtime = CreateGNUObjCRuntime(*this);
+  }
 
   // If debug info generation is enabled, create the CGDebugInfo object.
   DebugInfo = GenerateDebugInfo ? new CGDebugInfo(this) : 0;      

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.h?rev=54624&r1=54623&r2=54624&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.h Sun Aug 10 21:45:11 2008
@@ -105,7 +105,7 @@
 public:
   CodeGenModule(ASTContext &C, const LangOptions &Features, llvm::Module &M, 
                 const llvm::TargetData &TD, Diagnostic &Diags,
-                bool GenerateDebugInfo);
+                bool GenerateDebugInfo, bool UseMacObjCRuntime);
 
   ~CodeGenModule();
   

Modified: cfe/trunk/lib/CodeGen/ModuleBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ModuleBuilder.cpp?rev=54624&r1=54623&r2=54624&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/ModuleBuilder.cpp (original)
+++ cfe/trunk/lib/CodeGen/ModuleBuilder.cpp Sun Aug 10 21:45:11 2008
@@ -60,7 +60,8 @@
       M->setDataLayout(Ctx->Target.getTargetDescription());
       TD.reset(new llvm::TargetData(Ctx->Target.getTargetDescription()));
       Builder.reset(new CodeGen::CodeGenModule(Context, Features, *M, *TD,
-                                               Diags, GenerateDebugInfo));
+                                               Diags, GenerateDebugInfo,
+                                               false));
     }
     
     virtual void HandleTopLevelDecl(Decl *D) {





More information about the cfe-commits mailing list