Skip to content

Commit

Permalink
Add swift stub classref get ir gen
Browse files Browse the repository at this point in the history
  • Loading branch information
LunaTheFoxgirl committed Nov 20, 2024
1 parent 3679436 commit 9cbd156
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
10 changes: 9 additions & 1 deletion gen/objcgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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()) {
Expand Down
3 changes: 2 additions & 1 deletion gen/objcgen.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 7 additions & 1 deletion gen/toir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,14 +334,20 @@ 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));
result = new DImValue(e->type, loaded);
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);
}
Expand Down

0 comments on commit 9cbd156

Please sign in to comment.