1 //===--- ObjCRuntime.h - Objective-C Runtime Configuration ------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// \brief Defines types useful for describing an Objective-C runtime.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CLANG_OBJCRUNTIME_H
16 #define LLVM_CLANG_OBJCRUNTIME_H
18 #include "clang/Basic/VersionTuple.h"
19 #include "llvm/ADT/Triple.h"
20 #include "llvm/Support/ErrorHandling.h"
24 /// \brief The basic abstraction for the target Objective-C runtime.
27 /// \brief The basic Objective-C runtimes that we know about.
29 /// 'macosx' is the Apple-provided NeXT-derived runtime on Mac OS
30 /// X platforms that use the non-fragile ABI; the version is a
31 /// release of that OS.
34 /// 'macosx-fragile' is the Apple-provided NeXT-derived runtime on
35 /// Mac OS X platforms that use the fragile ABI; the version is a
36 /// release of that OS.
39 /// 'ios' is the Apple-provided NeXT-derived runtime on iOS or the iOS
40 /// simulator; it is always non-fragile. The version is a release
44 /// 'gcc' is the Objective-C runtime shipped with GCC, implementing a
45 /// fragile Objective-C ABI
48 /// 'gnustep' is the modern non-fragile GNUstep runtime.
51 /// 'objfw' is the Objective-C runtime included in ObjFW
60 /// A bogus initialization of the runtime.
61 ObjCRuntime() : TheKind(MacOSX) {}
63 ObjCRuntime(Kind kind, const VersionTuple &version)
64 : TheKind(kind), Version(version) {}
66 void set(Kind kind, VersionTuple version) {
71 Kind getKind() const { return TheKind; }
72 const VersionTuple &getVersion() const { return Version; }
74 /// \brief Does this runtime follow the set of implied behaviors for a
75 /// "non-fragile" ABI?
76 bool isNonFragile() const {
78 case FragileMacOSX: return false;
79 case GCC: return false;
80 case MacOSX: return true;
81 case GNUstep: return true;
82 case ObjFW: return false;
83 case iOS: return true;
85 llvm_unreachable("bad kind");
88 /// The inverse of isNonFragile(): does this runtime follow the set of
89 /// implied behaviors for a "fragile" ABI?
90 bool isFragile() const { return !isNonFragile(); }
92 /// The default dispatch mechanism to use for the specified architecture
93 bool isLegacyDispatchDefaultForArch(llvm::Triple::ArchType Arch) {
94 // The GNUstep runtime uses a newer dispatch method by default from
95 // version 1.6 onwards
96 if (getKind() == GNUstep && getVersion() >= VersionTuple(1, 6)) {
97 if (Arch == llvm::Triple::arm ||
98 Arch == llvm::Triple::x86 ||
99 Arch == llvm::Triple::x86_64)
101 // Mac runtimes use legacy dispatch everywhere except x86-64
102 } else if (isNeXTFamily() && isNonFragile())
103 return Arch != llvm::Triple::x86_64;
107 /// \brief Is this runtime basically of the GNUstep family of runtimes?
108 bool isGNUFamily() const {
119 llvm_unreachable("bad kind");
122 /// \brief Is this runtime basically of the NeXT family of runtimes?
123 bool isNeXTFamily() const {
124 // For now, this is just the inverse of isGNUFamily(), but that's
125 // not inherently true.
126 return !isGNUFamily();
129 /// \brief Does this runtime natively provide the ARC entrypoints?
131 /// ARC cannot be directly supported on a platform that does not provide
132 /// these entrypoints, although it may be supportable via a stub
134 bool hasARC() const {
136 case FragileMacOSX: return false;
137 case MacOSX: return getVersion() >= VersionTuple(10, 7);
138 case iOS: return getVersion() >= VersionTuple(5);
140 case GCC: return false;
141 case GNUstep: return getVersion() >= VersionTuple(1, 6);
142 case ObjFW: return false; // XXX: this will change soon
144 llvm_unreachable("bad kind");
147 /// \brief Does this runtime natively provide ARC-compliant 'weak'
149 bool hasWeak() const {
150 // Right now, this is always equivalent to the ARC decision.
154 /// \brief Does this runtime directly support the subscripting methods?
156 /// This is really a property of the library, not the runtime.
157 bool hasSubscripting() const {
159 case FragileMacOSX: return false;
160 case MacOSX: return getVersion() >= VersionTuple(10, 8);
161 case iOS: return false;
163 // This is really a lie, because some implementations and versions
164 // of the runtime do not support ARC. Probably -fgnu-runtime
165 // should imply a "maximal" runtime or something?
166 case GCC: return true;
167 case GNUstep: return true;
168 case ObjFW: return true;
170 llvm_unreachable("bad kind");
173 /// \brief Does this runtime allow sizeof or alignof on object types?
174 bool allowsSizeofAlignof() const {
178 /// \brief Does this runtime allow pointer arithmetic on objects?
180 /// This covers +, -, ++, --, and (if isSubscriptPointerArithmetic()
182 bool allowsPointerArithmetic() const {
193 llvm_unreachable("bad kind");
196 /// \brief Is subscripting pointer arithmetic?
197 bool isSubscriptPointerArithmetic() const {
198 return allowsPointerArithmetic();
201 /// \brief Does this runtime provide an objc_terminate function?
203 /// This is used in handlers for exceptions during the unwind process;
204 /// without it, abort() must be used in pure ObjC files.
205 bool hasTerminate() const {
207 case FragileMacOSX: return getVersion() >= VersionTuple(10, 8);
208 case MacOSX: return getVersion() >= VersionTuple(10, 8);
209 case iOS: return getVersion() >= VersionTuple(5);
210 case GCC: return false;
211 case GNUstep: return false;
212 case ObjFW: return false;
214 llvm_unreachable("bad kind");
217 /// \brief Does this runtime support weakly importing classes?
218 bool hasWeakClassImport() const {
220 case MacOSX: return true;
221 case iOS: return true;
222 case FragileMacOSX: return false;
223 case GCC: return true;
224 case GNUstep: return true;
225 case ObjFW: return true;
227 llvm_unreachable("bad kind");
229 /// \brief Does this runtime use zero-cost exceptions?
230 bool hasUnwindExceptions() const {
232 case MacOSX: return true;
233 case iOS: return true;
234 case FragileMacOSX: return false;
235 case GCC: return true;
236 case GNUstep: return true;
237 case ObjFW: return true;
239 llvm_unreachable("bad kind");
242 /// \brief Try to parse an Objective-C runtime specification from the given
245 /// \return true on error.
246 bool tryParse(StringRef input);
248 std::string getAsString() const;
250 friend bool operator==(const ObjCRuntime &left, const ObjCRuntime &right) {
251 return left.getKind() == right.getKind() &&
252 left.getVersion() == right.getVersion();
255 friend bool operator!=(const ObjCRuntime &left, const ObjCRuntime &right) {
256 return !(left == right);
260 raw_ostream &operator<<(raw_ostream &out, const ObjCRuntime &value);
262 } // end namespace clang