[cfe-commits] r160102 - in /cfe/trunk: include/clang/Basic/ObjCRuntime.h lib/Basic/ObjCRuntime.cpp lib/CodeGen/CGException.cpp lib/CodeGen/CGObjCGNU.cpp lib/CodeGen/CGObjCMac.cpp lib/CodeGen/CodeGenModule.cpp test/CodeGenObjC/objfw.m
John McCall
rjmccall at apple.com
Wed Jul 11 19:07:58 PDT 2012
Author: rjmccall
Date: Wed Jul 11 21:07:58 2012
New Revision: 160102
URL: http://llvm.org/viewvc/llvm-project?rev=160102&view=rev
Log:
Add the ObjFW runtime. Patch by Jonathan Schleifer!
Added:
cfe/trunk/test/CodeGenObjC/objfw.m
Modified:
cfe/trunk/include/clang/Basic/ObjCRuntime.h
cfe/trunk/lib/Basic/ObjCRuntime.cpp
cfe/trunk/lib/CodeGen/CGException.cpp
cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
cfe/trunk/lib/CodeGen/CGObjCMac.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
Modified: cfe/trunk/include/clang/Basic/ObjCRuntime.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/ObjCRuntime.h?rev=160102&r1=160101&r2=160102&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/ObjCRuntime.h (original)
+++ cfe/trunk/include/clang/Basic/ObjCRuntime.h Wed Jul 11 21:07:58 2012
@@ -46,7 +46,10 @@
GCC,
/// 'gnustep' is the modern non-fragile GNUstep runtime.
- GNUstep
+ GNUstep,
+
+ /// 'objfw' is the Objective-C runtime included in ObjFW
+ ObjFW
};
private:
@@ -76,6 +79,7 @@
case GCC: return false;
case MacOSX: return true;
case GNUstep: return true;
+ case ObjFW: return false;
case iOS: return true;
}
llvm_unreachable("bad kind");
@@ -109,6 +113,7 @@
return false;
case GCC:
case GNUstep:
+ case ObjFW:
return true;
}
llvm_unreachable("bad kind");
@@ -134,6 +139,7 @@
case GCC: return false;
case GNUstep: return getVersion() >= VersionTuple(1, 6);
+ case ObjFW: return false; // XXX: this will change soon
}
llvm_unreachable("bad kind");
}
@@ -159,6 +165,7 @@
// should imply a "maximal" runtime or something?
case GCC: return true;
case GNUstep: return true;
+ case ObjFW: return true;
}
llvm_unreachable("bad kind");
}
@@ -174,6 +181,7 @@
case iOS: return getVersion() >= VersionTuple(5);
case GCC: return false;
case GNUstep: return false;
+ case ObjFW: return false;
}
llvm_unreachable("bad kind");
}
@@ -186,6 +194,7 @@
case FragileMacOSX: return false;
case GCC: return true;
case GNUstep: return true;
+ case ObjFW: return true;
}
llvm_unreachable("bad kind");
}
@@ -197,6 +206,7 @@
case FragileMacOSX: return false;
case GCC: return true;
case GNUstep: return true;
+ case ObjFW: return true;
}
llvm_unreachable("bad kind");
}
Modified: cfe/trunk/lib/Basic/ObjCRuntime.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/ObjCRuntime.cpp?rev=160102&r1=160101&r2=160102&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/ObjCRuntime.cpp (original)
+++ cfe/trunk/lib/Basic/ObjCRuntime.cpp Wed Jul 11 21:07:58 2012
@@ -32,6 +32,7 @@
case ObjCRuntime::iOS: out << "ios"; break;
case ObjCRuntime::GNUstep: out << "gnustep"; break;
case ObjCRuntime::GCC: out << "gcc"; break;
+ case ObjCRuntime::ObjFW: out << "objfw"; break;
}
if (value.getVersion() > VersionTuple(0)) {
out << '-' << value.getVersion();
@@ -68,6 +69,8 @@
kind = ObjCRuntime::GNUstep;
} else if (runtimeName == "gcc") {
kind = ObjCRuntime::GCC;
+ } else if (runtimeName == "objfw") {
+ kind = ObjCRuntime::ObjFW;
} else {
return true;
}
Modified: cfe/trunk/lib/CodeGen/CGException.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGException.cpp?rev=160102&r1=160101&r2=160102&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGException.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGException.cpp Wed Jul 11 21:07:58 2012
@@ -188,6 +188,7 @@
return EHPersonality::NeXT_ObjC;
case ObjCRuntime::GNUstep:
case ObjCRuntime::GCC:
+ case ObjCRuntime::ObjFW:
return EHPersonality::GNU_ObjC;
}
llvm_unreachable("bad runtime kind");
@@ -219,6 +220,7 @@
// The GCC runtime's personality function inherently doesn't support
// mixed EH. Use the C++ personality just to avoid returning null.
case ObjCRuntime::GCC:
+ case ObjCRuntime::ObjFW: // XXX: this will change soon
return EHPersonality::GNU_ObjC;
case ObjCRuntime::GNUstep:
return EHPersonality::GNU_ObjCXX;
Modified: cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCGNU.cpp?rev=160102&r1=160101&r2=160102&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCGNU.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCGNU.cpp Wed Jul 11 21:07:58 2012
@@ -99,8 +99,8 @@
/// GNU Objective-C runtime code generation. This class implements the parts of
-/// Objective-C support that are specific to the GNU family of runtimes (GCC and
-/// GNUstep).
+/// Objective-C support that are specific to the GNU family of runtimes (GCC,
+/// GNUstep and ObjFW).
class CGObjCGNU : public CGObjCRuntime {
protected:
/// The LLVM module into which output is inserted
@@ -397,11 +397,11 @@
const ObjCIvarDecl *Ivar);
/// Emits a reference to a class. This allows the linker to object if there
/// is no class of the matching name.
+protected:
void EmitClassRef(const std::string &className);
/// Emits a pointer to the named class
- llvm::Value *GetClassNamed(CGBuilderTy &Builder, const std::string &Name,
- bool isWeak);
-protected:
+ virtual llvm::Value *GetClassNamed(CGBuilderTy &Builder,
+ const std::string &Name, bool isWeak);
/// Looks up the method for sending a message to the specified object. This
/// mechanism differs between the GCC and GNU runtimes, so this method must be
/// overridden in subclasses.
@@ -653,6 +653,30 @@
}
};
+/// Class used when targeting the ObjFW runtime.
+class CGObjCObjFW: public CGObjCGCC {
+ virtual llvm::Value *GetClassNamed(CGBuilderTy &Builder,
+ const std::string &Name, bool isWeak) {
+ if (isWeak)
+ return CGObjCGNU::GetClassNamed(Builder, Name, isWeak);
+
+ EmitClassRef(Name);
+
+ std::string SymbolName = "_OBJC_CLASS_" + Name;
+
+ llvm::GlobalVariable *ClassSymbol = TheModule.getGlobalVariable(SymbolName);
+
+ if (!ClassSymbol)
+ ClassSymbol = new llvm::GlobalVariable(TheModule, LongTy, false,
+ llvm::GlobalValue::ExternalLinkage,
+ 0, SymbolName);
+
+ return ClassSymbol;
+ }
+
+public:
+ CGObjCObjFW(CodeGenModule &Mod): CGObjCGCC(Mod) {}
+};
} // end anonymous namespace
@@ -2672,6 +2696,9 @@
case ObjCRuntime::GCC:
return new CGObjCGCC(CGM);
+ case ObjCRuntime::ObjFW:
+ return new CGObjCObjFW(CGM);
+
case ObjCRuntime::FragileMacOSX:
case ObjCRuntime::MacOSX:
case ObjCRuntime::iOS:
Modified: cfe/trunk/lib/CodeGen/CGObjCMac.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCMac.cpp?rev=160102&r1=160101&r2=160102&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Wed Jul 11 21:07:58 2012
@@ -6391,6 +6391,7 @@
case ObjCRuntime::GNUstep:
case ObjCRuntime::GCC:
+ case ObjCRuntime::ObjFW:
llvm_unreachable("these runtimes are not Mac runtimes");
}
llvm_unreachable("bad runtime");
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=160102&r1=160101&r2=160102&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Wed Jul 11 21:07:58 2012
@@ -140,6 +140,7 @@
switch (LangOpts.ObjCRuntime.getKind()) {
case ObjCRuntime::GNUstep:
case ObjCRuntime::GCC:
+ case ObjCRuntime::ObjFW:
ObjCRuntime = CreateGNUObjCRuntime(*this);
return;
Added: cfe/trunk/test/CodeGenObjC/objfw.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/objfw.m?rev=160102&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenObjC/objfw.m (added)
+++ cfe/trunk/test/CodeGenObjC/objfw.m Wed Jul 11 21:07:58 2012
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fobjc-runtime=objfw -emit-llvm -o - %s | FileCheck %s
+
+// Test the ObjFW runtime.
+
+ at interface Test0
++ (void) test;
+ at end
+void test0(void) {
+ [Test0 test];
+}
+// CHECK: define void @test0()
+// CHECK: [[T0:%.*]] = call i8* (i8*, i8*, ...)* (i8*, i8*)* @objc_msg_lookup(i8* bitcast (i64* @_OBJC_CLASS_Test0 to i8*),
+// CHECK-NEXT: [[T1:%.*]] = bitcast i8* (i8*, i8*, ...)* [[T0]] to void (i8*, i8*)*
+// CHECK-NEXT: call void [[T1]](i8* bitcast (i64* @_OBJC_CLASS_Test0 to i8*),
+// CHECK-NEXT: ret void
More information about the cfe-commits
mailing list