Skip to content

Commit ff59cd4

Browse files
committed
refactor(DITypeLifter): streamline type handling by adding handleSubroutineType and updating method signatures
1 parent c07f489 commit ff59cd4

1 file changed

Lines changed: 45 additions & 8 deletions

File tree

lib/IRDec/DITypeLifter.cpp

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include "DITypeLifter.hpp"
2-
#include "AST/Decls.hpp"
32
#include <llvm/BinaryFormat/Dwarf.h>
43

54
namespace glu::irdec {
@@ -27,9 +26,8 @@ DITypeLifter::handleBasicType(llvm::DIBasicType const *diBasicType) const
2726
}
2827
}
2928

30-
glu::types::TypeBase *DITypeLifter::handleComposedTypes(
31-
llvm::DICompositeType const *diCompositeType
32-
) const
29+
glu::types::TypeBase *
30+
DITypeLifter::handleComposedTypes(llvm::DICompositeType const *diCompositeType)
3331
{
3432
using namespace glu::types;
3533

@@ -73,6 +71,7 @@ glu::types::TypeBase *DITypeLifter::handleComposedTypes(
7371
),
7472
fieldDecls
7573
);
74+
_declBindings[diCompositeType] = structDecl;
7675
return typesArena.create<StructTy>(structDecl);
7776
}
7877
case llvm::dwarf::DW_TAG_array_type: {
@@ -129,14 +128,15 @@ glu::types::TypeBase *DITypeLifter::handleComposedTypes(
129128
),
130129
enumerators
131130
);
131+
_declBindings[diCompositeType] = enumDecl;
132132
return typesArena.create<EnumTy>(enumDecl);
133133
}
134134
default: return nullptr;
135135
}
136136
}
137137

138138
glu::types::TypeBase *
139-
DITypeLifter::handleDerivedType(llvm::DIDerivedType const *diDerivedType) const
139+
DITypeLifter::handleDerivedType(llvm::DIDerivedType const *diDerivedType)
140140
{
141141
using namespace glu::types;
142142

@@ -162,7 +162,43 @@ DITypeLifter::handleDerivedType(llvm::DIDerivedType const *diDerivedType) const
162162
}
163163
}
164164

165-
glu::types::TypeBase *DITypeLifter::lift(llvm::DIType const *diType) const
165+
glu::types::TypeBase *DITypeLifter::handleSubroutineType(
166+
llvm::DISubroutineType const *diSubroutineType
167+
)
168+
{
169+
using namespace glu::types;
170+
171+
auto &typesArena = _context.getTypesMemoryArena();
172+
auto types = diSubroutineType->getTypeArray();
173+
174+
if (types.size() == 0) {
175+
return nullptr;
176+
}
177+
178+
// First element is return type
179+
auto *returnType = lift(llvm::cast<llvm::DIType>(types[0]));
180+
if (!returnType) {
181+
return nullptr;
182+
}
183+
184+
// Remaining elements are parameter types
185+
llvm::SmallVector<TypeBase *, 4> paramTypes;
186+
for (size_t i = 1; i < types.size(); ++i) {
187+
if (auto *diType = llvm::dyn_cast_if_present<llvm::DIType>(types[i])) {
188+
auto *paramType = lift(diType);
189+
if (!paramType) {
190+
return nullptr;
191+
}
192+
paramTypes.push_back(paramType);
193+
}
194+
}
195+
196+
return FunctionTy::create(
197+
typesArena.getAllocator(), paramTypes, returnType, false
198+
);
199+
}
200+
201+
glu::types::TypeBase *DITypeLifter::lift(llvm::DIType const *diType)
166202
{
167203
if (!diType) {
168204
return nullptr;
@@ -172,9 +208,10 @@ glu::types::TypeBase *DITypeLifter::lift(llvm::DIType const *diType) const
172208
return handleBasicType(llvm::cast<llvm::DIBasicType>(diType));
173209
case llvm::Metadata::MetadataKind::DICompositeTypeKind:
174210
return handleComposedTypes(llvm::cast<llvm::DICompositeType>(diType));
175-
case llvm::Metadata::MetadataKind::DIDerivedTypeKind: {
211+
case llvm::Metadata::MetadataKind::DIDerivedTypeKind:
176212
return handleDerivedType(llvm::cast<llvm::DIDerivedType>(diType));
177-
}
213+
case llvm::Metadata::MetadataKind::DISubroutineTypeKind:
214+
return handleSubroutineType(llvm::cast<llvm::DISubroutineType>(diType));
178215
default: return nullptr;
179216
}
180217
}

0 commit comments

Comments
 (0)