]> git.saurik.com Git - apple/objc4.git/blob - test/swift-class-def.m
objc4-779.1.tar.gz
[apple/objc4.git] / test / swift-class-def.m
1 #include <sys/cdefs.h>
2
3 #if __LP64__
4 # define PTR " .quad "
5 # define PTRSIZE "8"
6 # define LOGPTRSIZE "3"
7 # define ONLY_LP64(x) x
8 #else
9 # define PTR " .long "
10 # define PTRSIZE "4"
11 # define LOGPTRSIZE "2"
12 # define ONLY_LP64(x)
13 #endif
14
15 #if __has_feature(ptrauth_calls)
16 # define SIGNED_METHOD_LIST_IMP "@AUTH(ia,0,addr) "
17 # define SIGNED_STUB_INITIALIZER "@AUTH(ia,0xc671,addr) "
18 #else
19 # define SIGNED_METHOD_LIST_IMP
20 # define SIGNED_STUB_INITIALIZER
21 #endif
22
23 #define str(x) #x
24 #define str2(x) str(x)
25
26 // Swift metadata initializers. Define these in the test.
27 EXTERN_C Class initSuper(Class cls, void *arg);
28 EXTERN_C Class initSub(Class cls, void *arg);
29
30 @interface SwiftSuper : NSObject @end
31 @interface SwiftSub : SwiftSuper @end
32
33 __BEGIN_DECLS
34 // not id to avoid ARC operations because the class doesn't implement RR methods
35 void* nop(void* self) { return self; }
36 __END_DECLS
37
38 #define SWIFT_CLASS(name, superclass, swiftInit) \
39 asm( \
40 ".globl _OBJC_CLASS_$_" #name "\n" \
41 ".section __DATA,__objc_data \n" \
42 ".align 3 \n" \
43 "_OBJC_CLASS_$_" #name ": \n" \
44 PTR "_OBJC_METACLASS_$_" #name "\n" \
45 PTR "_OBJC_CLASS_$_" #superclass "\n" \
46 PTR "__objc_empty_cache \n" \
47 PTR "0 \n" \
48 PTR "L_" #name "_ro + 2 \n" \
49 /* Swift class fields. */ \
50 ".long 0 \n" /* flags */ \
51 ".long 0 \n" /* instanceAddressOffset */ \
52 ".long 16 \n" /* instanceSize */ \
53 ".short 15 \n" /* instanceAlignMask */ \
54 ".short 0 \n" /* reserved */ \
55 ".long 256 \n" /* classSize */ \
56 ".long 0 \n" /* classAddressOffset */ \
57 PTR "0 \n" /* description */ \
58 /* pad to OBJC_MAX_CLASS_SIZE */ \
59 PTR "0 \n" \
60 PTR "0 \n" \
61 PTR "0 \n" \
62 PTR "0 \n" \
63 PTR "0 \n" \
64 PTR "0 \n" \
65 PTR "0 \n" \
66 PTR "0 \n" \
67 PTR "0 \n" \
68 PTR "0 \n" \
69 PTR "0 \n" \
70 PTR "0 \n" \
71 PTR "0 \n" \
72 PTR "0 \n" \
73 PTR "0 \n" \
74 PTR "0 \n" \
75 PTR "0 \n" \
76 PTR "0 \n" \
77 PTR "0 \n" \
78 PTR "0 \n" \
79 PTR "0 \n" \
80 PTR "0 \n" \
81 PTR "0 \n" \
82 PTR "0 \n" \
83 \
84 "_OBJC_METACLASS_$_" #name ": \n" \
85 PTR "_OBJC_METACLASS_$_" #superclass "\n" \
86 PTR "_OBJC_METACLASS_$_" #superclass "\n" \
87 PTR "__objc_empty_cache \n" \
88 PTR "0 \n" \
89 PTR "L_" #name "_meta_ro \n" \
90 /* pad to OBJC_MAX_CLASS_SIZE */ \
91 PTR "0 \n" \
92 PTR "0 \n" \
93 PTR "0 \n" \
94 PTR "0 \n" \
95 PTR "0 \n" \
96 PTR "0 \n" \
97 PTR "0 \n" \
98 PTR "0 \n" \
99 PTR "0 \n" \
100 PTR "0 \n" \
101 PTR "0 \n" \
102 PTR "0 \n" \
103 PTR "0 \n" \
104 PTR "0 \n" \
105 PTR "0 \n" \
106 PTR "0 \n" \
107 PTR "0 \n" \
108 PTR "0 \n" \
109 PTR "0 \n" \
110 PTR "0 \n" \
111 PTR "0 \n" \
112 PTR "0 \n" \
113 PTR "0 \n" \
114 PTR "0 \n" \
115 PTR "0 \n" \
116 PTR "0 \n" \
117 PTR "0 \n" \
118 \
119 "L_" #name "_ro: \n" \
120 ".long (1<<6) \n" \
121 ".long 0 \n" \
122 ".long " PTRSIZE " \n" \
123 ONLY_LP64(".long 0 \n") \
124 PTR "0 \n" \
125 PTR "L_" #name "_name \n" \
126 PTR "L_" #name "_methods \n" \
127 PTR "0 \n" \
128 PTR "L_" #name "_ivars \n" \
129 PTR "0 \n" \
130 PTR "0 \n" \
131 PTR "_" #swiftInit SIGNED_METHOD_LIST_IMP "\n" \
132 \
133 "L_" #name "_meta_ro: \n" \
134 ".long 1 \n" \
135 ".long 40 \n" \
136 ".long 40 \n" \
137 ONLY_LP64(".long 0 \n") \
138 PTR "0 \n" \
139 PTR "L_" #name "_name \n" \
140 PTR "L_" #name "_meta_methods \n" \
141 PTR "0 \n" \
142 PTR "0 \n" \
143 PTR "0 \n" \
144 PTR "0 \n" \
145 \
146 "L_" #name "_methods: \n" \
147 "L_" #name "_meta_methods: \n" \
148 ".long 3*" PTRSIZE "\n" \
149 ".long 1 \n" \
150 PTR "L_" #name "_self \n" \
151 PTR "L_" #name "_self \n" \
152 PTR "_nop" SIGNED_METHOD_LIST_IMP "\n" \
153 \
154 "L_" #name "_ivars: \n" \
155 ".long 4*" PTRSIZE " \n" \
156 ".long 1 \n" \
157 PTR "L_" #name "_ivar_offset \n" \
158 PTR "L_" #name "_ivar_name \n" \
159 PTR "L_" #name "_ivar_type \n" \
160 ".long " LOGPTRSIZE "\n" \
161 ".long " PTRSIZE "\n" \
162 \
163 "L_" #name "_ivar_offset: \n" \
164 ".long 0 \n" \
165 \
166 ".cstring \n" \
167 "L_" #name "_name: .ascii \"" #name "\\0\" \n" \
168 "L_" #name "_self: .ascii \"self\\0\" \n" \
169 "L_" #name "_ivar_name: " \
170 " .ascii \"" #name "_ivar\\0\" \n" \
171 "L_" #name "_ivar_type: .ascii \"c\\0\" \n" \
172 \
173 \
174 ".text \n" \
175 ); \
176 extern char OBJC_CLASS_$_ ## name; \
177 Class Raw ## name = (Class)&OBJC_CLASS_$_ ## name
178
179 #define SWIFT_STUB_CLASSREF(name) \
180 extern char OBJC_CLASS_$_ ## name; \
181 static Class name ## Classref = (Class)(&OBJC_CLASS_$_ ## name + 1)
182
183 #define SWIFT_STUB_CLASS(name, initializer) \
184 asm( \
185 ".globl _OBJC_CLASS_$_" #name "\n" \
186 ".section __DATA,__objc_data \n" \
187 ".align 3 \n" \
188 "_dummy" #name ": \n" \
189 PTR "0 \n" \
190 ".alt_entry _OBJC_CLASS_$_" #name "\n" \
191 "_OBJC_CLASS_$_" #name ": \n" \
192 PTR "1 \n" \
193 PTR "_" #initializer SIGNED_STUB_INITIALIZER "\n" \
194 ".text" \
195 ); \
196 extern char OBJC_CLASS_$_ ## name; \
197 Class Raw ## name = (Class)&OBJC_CLASS_$_ ## name; \
198 SWIFT_STUB_CLASSREF(name)
199
200
201 void fn(void) { }