Skip to content

Commit bb3f1dd

Browse files
committed
refactor(ModuleLifter): replace TypeLifter with DITypeLifter and update type handling in detectExternalFunctions
1 parent ff59cd4 commit bb3f1dd

2 files changed

Lines changed: 28 additions & 6 deletions

File tree

include/IRDec/DITypeLifter.hpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define GLU_IR_DEC_DI_TYPE_LIFTER_HPP
33

44
#include "AST/ASTContext.hpp"
5+
#include "AST/Decls.hpp"
56
#include "AST/Types.hpp"
67
#include <llvm/IR/DebugInfoMetadata.h>
78

@@ -19,7 +20,7 @@ class DITypeLifter {
1920
/// @brief Lift a DIType to a GLU type
2021
/// @param diType The DIType to lift
2122
/// @return The lifted GLU type, or nullptr if the type could not be lifted
22-
glu::types::TypeBase *lift(llvm::DIType const *diType) const;
23+
glu::types::TypeBase *lift(llvm::DIType const *diType);
2324

2425
/// @brief Handle a DIBasicType and lift it to a GLU type
2526
/// @param arena The memory arena to use for allocation
@@ -34,15 +35,29 @@ class DITypeLifter {
3435
/// @param diCompositeType The DICompositeType to handle
3536
/// @return The lifted GLU type, or nullptr if the type could not be lifted
3637
glu::types::TypeBase *
37-
handleComposedTypes(llvm::DICompositeType const *diCompositeType) const;
38+
handleComposedTypes(llvm::DICompositeType const *diCompositeType);
3839

3940
/// @brief Handle a DIDerivedType and lift it to a GLU type
4041
/// @param typesArena The memory arena to use for type allocation
4142
/// @param astArena The memory arena to use for AST allocation
4243
/// @param diDerivedType The DIDerivedType to handle
4344
/// @return The lifted GLU type, or nullptr if the type could not be lifted
4445
glu::types::TypeBase *
45-
handleDerivedType(llvm::DIDerivedType const *diDerivedType) const;
46+
handleDerivedType(llvm::DIDerivedType const *diDerivedType);
47+
48+
/// @brief Handle a DISubroutineType and lift it to a GLU type
49+
/// @param diSubroutineType The DISubroutineType to handle
50+
/// @return The lifted GLU type, or nullptr if the type could not be lifted
51+
glu::types::TypeBase *
52+
handleSubroutineType(llvm::DISubroutineType const *diSubroutineType);
53+
54+
/// @brief Get the declaration bindings map
55+
/// @return The declaration bindings map
56+
llvm::DenseMap<llvm::DIType const *, glu::ast::DeclBase *> &
57+
getDeclBindings()
58+
{
59+
return _declBindings;
60+
}
4661
};
4762

4863
} // namespace glu::irdec

lib/IRDec/ModuleLifter.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "ModuleLifter.hpp"
2+
#include "DITypeLifter.hpp"
23
#include "GILGen/GILGen.hpp"
3-
#include "TypeLifter.hpp"
44
#include "llvm/IR/Function.h"
55

66
namespace glu::irdec {
@@ -39,13 +39,16 @@ class ModuleLifter {
3939

4040
glu::ast::ModuleDecl *detectExternalFunctions()
4141
{
42-
TypeLifter typeLifter(_astContext);
42+
DITypeLifter typeLifter(_astContext);
4343
std::vector<glu::ast::DeclBase *> decls;
4444

4545
for (auto &func : _llvmModule->functions()) {
4646
if (!func.isDeclaration()
4747
&& func.getLinkage() == llvm::Function::ExternalLinkage) {
48-
auto type = typeLifter.lift(func.getFunctionType());
48+
auto DIType = func.getSubprogram();
49+
if (!DIType)
50+
continue;
51+
auto type = typeLifter.lift(DIType->getType());
4952
if (auto funcType
5053
= llvm::dyn_cast_if_present<glu::types::FunctionTy>(type)) {
5154
auto funcDecl
@@ -61,6 +64,10 @@ class ModuleLifter {
6164
}
6265
}
6366
}
67+
68+
for (auto decl : typeLifter.getDeclBindings()) {
69+
decls.push_back(decl.second);
70+
}
6471
return _astContext.getASTMemoryArena().create<glu::ast::ModuleDecl>(
6572
SourceLocation::invalid, std::move(decls), &_astContext
6673
);

0 commit comments

Comments
 (0)