Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parameterised init and methods #2761

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/libasr/codegen/asr_to_llvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3054,6 +3054,30 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
}
}

void instantiate_methods(const ASR::Struct_t &x) {
SymbolTable *current_scope_copy = current_scope;
current_scope = x.m_symtab;
for ( auto &item : x.m_symtab->get_scope() ) {
if ( is_a<ASR::Function_t>(*item.second) ) {
ASR::Function_t *v = down_cast<ASR::Function_t>(item.second);
instantiate_function(*v);
}
}
current_scope = current_scope_copy;
}

void visit_methods (const ASR::Struct_t &x) {
SymbolTable *current_scope_copy = current_scope;
current_scope = x.m_symtab;
for ( auto &item : x.m_symtab->get_scope() ) {
if ( is_a<ASR::Function_t>(*item.second) ) {
ASR::Function_t *v = down_cast<ASR::Function_t>(item.second);
visit_Function(*v);
}
}
current_scope = current_scope_copy;
}

void start_module_init_function_prototype(const ASR::Module_t &x) {
uint32_t h = get_hash((ASR::asr_t*)&x);
llvm::FunctionType *function_type = llvm::FunctionType::get(
Expand Down Expand Up @@ -3095,6 +3119,9 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
} else if (is_a<ASR::EnumType_t>(*item.second)) {
ASR::EnumType_t *et = down_cast<ASR::EnumType_t>(item.second);
visit_EnumType(*et);
} else if (is_a<ASR::Struct_t>(*item.second)) {
ASR::Struct_t *st = down_cast<ASR::Struct_t>(item.second);
instantiate_methods(*st);
}
}
finish_module_init_function_prototype(x);
Expand Down Expand Up @@ -4145,6 +4172,9 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
if (is_a<ASR::Function_t>(*item.second)) {
ASR::Function_t *s = ASR::down_cast<ASR::Function_t>(item.second);
visit_Function(*s);
} else if ( is_a<ASR::Struct_t>(*item.second) ) {
ASR::Struct_t *st = down_cast<ASR::Struct_t>(item.second);
visit_methods(*st);
}
}
}
Expand Down
Loading
Loading