| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | #ifndef LLVM_CLANG_LIB_CODEGEN_CGOBJCRUNTIME_H |
| 16 | #define LLVM_CLANG_LIB_CODEGEN_CGOBJCRUNTIME_H |
| 17 | #include "CGBuilder.h" |
| 18 | #include "CGCall.h" |
| 19 | #include "CGCleanup.h" |
| 20 | #include "CGValue.h" |
| 21 | #include "clang/AST/DeclObjC.h" |
| 22 | #include "clang/Basic/IdentifierTable.h" |
| 23 | |
| 24 | namespace llvm { |
| 25 | class Constant; |
| 26 | class Function; |
| 27 | class Module; |
| 28 | class StructLayout; |
| 29 | class StructType; |
| 30 | class Type; |
| 31 | class Value; |
| 32 | } |
| 33 | |
| 34 | namespace clang { |
| 35 | namespace CodeGen { |
| 36 | class CodeGenFunction; |
| 37 | } |
| 38 | |
| 39 | class FieldDecl; |
| 40 | class ObjCAtTryStmt; |
| 41 | class ObjCAtThrowStmt; |
| 42 | class ObjCAtSynchronizedStmt; |
| 43 | class ObjCContainerDecl; |
| 44 | class ObjCCategoryImplDecl; |
| 45 | class ObjCImplementationDecl; |
| 46 | class ObjCInterfaceDecl; |
| 47 | class ObjCMessageExpr; |
| 48 | class ObjCMethodDecl; |
| 49 | class ObjCProtocolDecl; |
| 50 | class Selector; |
| 51 | class ObjCIvarDecl; |
| 52 | class ObjCStringLiteral; |
| 53 | class BlockDeclRefExpr; |
| 54 | |
| 55 | namespace CodeGen { |
| 56 | class CodeGenModule; |
| 57 | class CGBlockInfo; |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | class CGObjCRuntime { |
| 64 | protected: |
| 65 | CodeGen::CodeGenModule &CGM; |
| 66 | CGObjCRuntime(CodeGen::CodeGenModule &CGM) : CGM(CGM) {} |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | uint64_t ComputeIvarBaseOffset(CodeGen::CodeGenModule &CGM, |
| 79 | const ObjCInterfaceDecl *OID, |
| 80 | const ObjCIvarDecl *Ivar); |
| 81 | uint64_t ComputeIvarBaseOffset(CodeGen::CodeGenModule &CGM, |
| 82 | const ObjCImplementationDecl *OID, |
| 83 | const ObjCIvarDecl *Ivar); |
| 84 | |
| 85 | LValue EmitValueForIvarAtOffset(CodeGen::CodeGenFunction &CGF, |
| 86 | const ObjCInterfaceDecl *OID, |
| 87 | llvm::Value *BaseValue, |
| 88 | const ObjCIvarDecl *Ivar, |
| 89 | unsigned CVRQualifiers, |
| 90 | llvm::Value *Offset); |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | void EmitTryCatchStmt(CodeGenFunction &CGF, const ObjCAtTryStmt &S, |
| 99 | llvm::FunctionCallee beginCatchFn, |
| 100 | llvm::FunctionCallee endCatchFn, |
| 101 | llvm::FunctionCallee exceptionRethrowFn); |
| 102 | |
| 103 | void EmitInitOfCatchParam(CodeGenFunction &CGF, llvm::Value *exn, |
| 104 | const VarDecl *paramDecl); |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | void EmitAtSynchronizedStmt(CodeGenFunction &CGF, |
| 111 | const ObjCAtSynchronizedStmt &S, |
| 112 | llvm::FunctionCallee syncEnterFn, |
| 113 | llvm::FunctionCallee syncExitFn); |
| 114 | |
| 115 | public: |
| 116 | virtual ~CGObjCRuntime(); |
| 117 | |
| 118 | |
| 119 | |
| 120 | virtual llvm::Function *ModuleInitFunction() = 0; |
| 121 | |
| 122 | |
| 123 | |
| 124 | virtual llvm::Value *GetSelector(CodeGenFunction &CGF, Selector Sel) = 0; |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | virtual Address GetAddrOfSelector(CodeGenFunction &CGF, Selector Sel) = 0; |
| 132 | |
| 133 | |
| 134 | virtual llvm::Value *GetSelector(CodeGenFunction &CGF, |
| 135 | const ObjCMethodDecl *Method) = 0; |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | virtual llvm::Constant *GetEHType(QualType T) = 0; |
| 142 | |
| 143 | virtual CatchTypeInfo getCatchAllTypeInfo() { return { nullptr, 0 }; } |
| 144 | |
| 145 | |
| 146 | virtual ConstantAddress GenerateConstantString(const StringLiteral *) = 0; |
| 147 | |
| 148 | |
| 149 | |
| 150 | virtual void GenerateCategory(const ObjCCategoryImplDecl *OCD) = 0; |
| 151 | |
| 152 | |
| 153 | virtual void GenerateClass(const ObjCImplementationDecl *OID) = 0; |
| 154 | |
| 155 | |
| 156 | virtual void RegisterAlias(const ObjCCompatibleAliasDecl *OAD) = 0; |
| 157 | |
| 158 | |
| 159 | |
| 160 | |
| 161 | |
| 162 | virtual CodeGen::RValue |
| 163 | GenerateMessageSend(CodeGen::CodeGenFunction &CGF, |
| 164 | ReturnValueSlot ReturnSlot, |
| 165 | QualType ResultType, |
| 166 | Selector Sel, |
| 167 | llvm::Value *Receiver, |
| 168 | const CallArgList &CallArgs, |
| 169 | const ObjCInterfaceDecl *Class = nullptr, |
| 170 | const ObjCMethodDecl *Method = nullptr) = 0; |
| 171 | |
| 172 | |
| 173 | |
| 174 | |
| 175 | |
| 176 | |
| 177 | |
| 178 | virtual CodeGen::RValue |
| 179 | GenerateMessageSendSuper(CodeGen::CodeGenFunction &CGF, |
| 180 | ReturnValueSlot ReturnSlot, |
| 181 | QualType ResultType, |
| 182 | Selector Sel, |
| 183 | const ObjCInterfaceDecl *Class, |
| 184 | bool isCategoryImpl, |
| 185 | llvm::Value *Self, |
| 186 | bool IsClassMessage, |
| 187 | const CallArgList &CallArgs, |
| 188 | const ObjCMethodDecl *Method = nullptr) = 0; |
| 189 | |
| 190 | |
| 191 | |
| 192 | virtual llvm::Value *GenerateProtocolRef(CodeGenFunction &CGF, |
| 193 | const ObjCProtocolDecl *OPD) = 0; |
| 194 | |
| 195 | |
| 196 | |
| 197 | virtual void GenerateProtocol(const ObjCProtocolDecl *OPD) = 0; |
| 198 | |
| 199 | |
| 200 | |
| 201 | |
| 202 | |
| 203 | |
| 204 | |
| 205 | virtual llvm::Function *GenerateMethod(const ObjCMethodDecl *OMD, |
| 206 | const ObjCContainerDecl *CD) = 0; |
| 207 | |
| 208 | |
| 209 | virtual llvm::FunctionCallee GetPropertyGetFunction() = 0; |
| 210 | |
| 211 | |
| 212 | virtual llvm::FunctionCallee GetPropertySetFunction() = 0; |
| 213 | |
| 214 | |
| 215 | virtual llvm::FunctionCallee GetOptimizedPropertySetFunction(bool atomic, |
| 216 | bool copy) = 0; |
| 217 | |
| 218 | |
| 219 | virtual llvm::FunctionCallee GetGetStructFunction() = 0; |
| 220 | |
| 221 | virtual llvm::FunctionCallee GetSetStructFunction() = 0; |
| 222 | |
| 223 | |
| 224 | virtual llvm::FunctionCallee GetCppAtomicObjectSetFunction() = 0; |
| 225 | |
| 226 | |
| 227 | virtual llvm::FunctionCallee GetCppAtomicObjectGetFunction() = 0; |
| 228 | |
| 229 | |
| 230 | |
| 231 | virtual llvm::Value *GetClass(CodeGenFunction &CGF, |
| 232 | const ObjCInterfaceDecl *OID) = 0; |
| 233 | |
| 234 | |
| 235 | virtual llvm::Value *EmitNSAutoreleasePoolClassRef(CodeGenFunction &CGF) { |
| 236 | llvm_unreachable("autoreleasepool unsupported in this ABI"); |
| 237 | } |
| 238 | |
| 239 | |
| 240 | |
| 241 | virtual llvm::FunctionCallee EnumerationMutationFunction() = 0; |
| 242 | |
| 243 | virtual void EmitSynchronizedStmt(CodeGen::CodeGenFunction &CGF, |
| 244 | const ObjCAtSynchronizedStmt &S) = 0; |
| 245 | virtual void EmitTryStmt(CodeGen::CodeGenFunction &CGF, |
| 246 | const ObjCAtTryStmt &S) = 0; |
| 247 | virtual void EmitThrowStmt(CodeGen::CodeGenFunction &CGF, |
| 248 | const ObjCAtThrowStmt &S, |
| 249 | bool ClearInsertionPoint=true) = 0; |
| 250 | virtual llvm::Value *EmitObjCWeakRead(CodeGen::CodeGenFunction &CGF, |
| 251 | Address AddrWeakObj) = 0; |
| 252 | virtual void EmitObjCWeakAssign(CodeGen::CodeGenFunction &CGF, |
| 253 | llvm::Value *src, Address dest) = 0; |
| 254 | virtual void EmitObjCGlobalAssign(CodeGen::CodeGenFunction &CGF, |
| 255 | llvm::Value *src, Address dest, |
| 256 | bool threadlocal=false) = 0; |
| 257 | virtual void EmitObjCIvarAssign(CodeGen::CodeGenFunction &CGF, |
| 258 | llvm::Value *src, Address dest, |
| 259 | llvm::Value *ivarOffset) = 0; |
| 260 | virtual void EmitObjCStrongCastAssign(CodeGen::CodeGenFunction &CGF, |
| 261 | llvm::Value *src, Address dest) = 0; |
| 262 | |
| 263 | virtual LValue EmitObjCValueForIvar(CodeGen::CodeGenFunction &CGF, |
| 264 | QualType ObjectTy, |
| 265 | llvm::Value *BaseValue, |
| 266 | const ObjCIvarDecl *Ivar, |
| 267 | unsigned CVRQualifiers) = 0; |
| 268 | virtual llvm::Value *EmitIvarOffset(CodeGen::CodeGenFunction &CGF, |
| 269 | const ObjCInterfaceDecl *Interface, |
| 270 | const ObjCIvarDecl *Ivar) = 0; |
| 271 | virtual void EmitGCMemmoveCollectable(CodeGen::CodeGenFunction &CGF, |
| 272 | Address DestPtr, |
| 273 | Address SrcPtr, |
| 274 | llvm::Value *Size) = 0; |
| 275 | virtual llvm::Constant *BuildGCBlockLayout(CodeGen::CodeGenModule &CGM, |
| 276 | const CodeGen::CGBlockInfo &blockInfo) = 0; |
| 277 | virtual llvm::Constant *BuildRCBlockLayout(CodeGen::CodeGenModule &CGM, |
| 278 | const CodeGen::CGBlockInfo &blockInfo) = 0; |
| 279 | virtual std::string getRCBlockLayoutStr(CodeGen::CodeGenModule &CGM, |
| 280 | const CGBlockInfo &blockInfo) { |
| 281 | return {}; |
| 282 | } |
| 283 | |
| 284 | |
| 285 | virtual llvm::Constant *BuildByrefLayout(CodeGen::CodeGenModule &CGM, |
| 286 | QualType T) = 0; |
| 287 | |
| 288 | struct MessageSendInfo { |
| 289 | const CGFunctionInfo &CallInfo; |
| 290 | llvm::PointerType *MessengerType; |
| 291 | |
| 292 | MessageSendInfo(const CGFunctionInfo &callInfo, |
| 293 | llvm::PointerType *messengerType) |
| 294 | : CallInfo(callInfo), MessengerType(messengerType) {} |
| 295 | }; |
| 296 | |
| 297 | MessageSendInfo getMessageSendInfo(const ObjCMethodDecl *method, |
| 298 | QualType resultType, |
| 299 | CallArgList &callArgs); |
| 300 | |
| 301 | |
| 302 | |
| 303 | unsigned ComputeBitfieldBitOffset(CodeGen::CodeGenModule &CGM, |
| 304 | const ObjCInterfaceDecl *ID, |
| 305 | const ObjCIvarDecl *Ivar); |
| 306 | }; |
| 307 | |
| 308 | |
| 309 | |
| 310 | CGObjCRuntime *CreateGNUObjCRuntime(CodeGenModule &CGM); |
| 311 | CGObjCRuntime *CreateMacObjCRuntime(CodeGenModule &CGM); |
| 312 | } |
| 313 | } |
| 314 | #endif |
| 315 | |