From 9cbd156fc0690eb0fc4937193d85c0e200b971d0 Mon Sep 17 00:00:00 2001 From: LunaTheFoxgirl Date: Wed, 20 Nov 2024 04:25:11 +0100 Subject: [PATCH] Add swift stub classref get ir gen --- gen/objcgen.cpp | 10 +++++++++- gen/objcgen.h | 3 ++- gen/toir.cpp | 8 +++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/gen/objcgen.cpp b/gen/objcgen.cpp index d6f9be6820..07c2e7925b 100644 --- a/gen/objcgen.cpp +++ b/gen/objcgen.cpp @@ -15,6 +15,7 @@ #include "dmd/declaration.h" #include "dmd/identifier.h" #include "gen/irstate.h" +#include "gen/runtime.h" #include "ir/irfunction.h" bool objc_isSupported(const llvm::Triple &triple) { @@ -394,7 +395,14 @@ LLGlobalVariable *ObjCState::getClassRoSymbol(const ClassDeclaration& cd, bool m return var; } -LLGlobalVariable *ObjCState::getClassReference(const ClassDeclaration& cd) { +LLValue *ObjCState::getSwiftStubClassReference(const ClassDeclaration& cd) { + auto classref = getClassReference(cd); + auto toClassRefFunc = getRuntimeFunction(cd.loc, module, "objc_loadClassRef"); + auto retv = gIR->CreateCallOrInvoke(toClassRefFunc, classref, ""); + return retv; +} + +LLConstant *ObjCState::getClassReference(const ClassDeclaration& cd) { llvm::StringRef name(cd.objc.identifier->toChars()); auto it = classReferenceTable.find(name); if (it != classReferenceTable.end()) { diff --git a/gen/objcgen.h b/gen/objcgen.h index 2adf9db731..7b05edcfcb 100644 --- a/gen/objcgen.h +++ b/gen/objcgen.h @@ -66,7 +66,8 @@ class ObjCState { // Classes LLGlobalVariable *getClassSymbol(const ClassDeclaration& cd, bool meta); LLGlobalVariable *getClassRoSymbol(const ClassDeclaration& cd, bool meta); - LLGlobalVariable *getClassReference(const ClassDeclaration& cd); + LLConstant *getClassReference(const ClassDeclaration& cd); + LLValue *getSwiftStubClassReference(const ClassDeclaration& cd); // Categories diff --git a/gen/toir.cpp b/gen/toir.cpp index 8f4692b8e5..dc3822ee33 100644 --- a/gen/toir.cpp +++ b/gen/toir.cpp @@ -334,7 +334,7 @@ class ToElemVisitor : public Visitor { e->type->toChars()); LOG_SCOPE; - LLGlobalVariable *decl; + // Protocols if (auto iface = e->classDeclaration->isInterfaceDeclaration()) { auto loaded = DtoLoad(DtoType(e->type), gIR->objc.getProtocolReference(*iface)); @@ -342,6 +342,12 @@ class ToElemVisitor : public Visitor { return; } + // Swift stub classes + if (e->classDeclaration->objc.isSwiftStub) { + result = new DImValue(e->type, gIR->objc.getSwiftStubClassReference(*e->classDeclaration)); + return; + } + auto loaded = DtoLoad(DtoType(e->type), gIR->objc.getClassReference(*e->classDeclaration)); result = new DImValue(e->type, loaded); }