Skip to content

Commit 0003a20

Browse files
[x86] Visit all the symbols in _global_symbols
1 parent 521596a commit 0003a20

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/libasr/codegen/asr_to_x86.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,21 @@ class ASRToX86Visitor : public ASR::BaseVisitor<ASRToX86Visitor>
7979
visit_symbol(*sym);
8080
}
8181

82+
if (x.m_global_scope->get_symbol("_global_symbols") != nullptr) {
83+
SymbolTable *global_symbols = ASR::down_cast<ASR::Module_t>(
84+
x.m_global_scope->get_symbol("_global_symbols"))->m_symtab;
85+
std::vector<std::string> global_func_order
86+
= ASRUtils::determine_function_definition_order(global_symbols);
87+
for (size_t i = 0; i < global_func_order.size(); i++) {
88+
ASR::symbol_t* sym = global_symbols->get_symbol(global_func_order[i]);
89+
// Ignore external symbols because they are already defined by the loop above.
90+
if( !sym || ASR::is_a<ASR::ExternalSymbol_t>(*sym) ) {
91+
continue;
92+
}
93+
visit_symbol(*sym);
94+
}
95+
}
96+
8297
// Then the main program:
8398
for (auto &item : x.m_global_scope->get_scope()) {
8499
if (ASR::is_a<ASR::Program_t>(*item.second)) {
@@ -504,7 +519,8 @@ class ASRToX86Visitor : public ASR::BaseVisitor<ASRToX86Visitor>
504519
}
505520

506521
void visit_SubroutineCall(const ASR::SubroutineCall_t &x) {
507-
ASR::Function_t *s = ASR::down_cast<ASR::Function_t>(x.m_name);
522+
ASR::Function_t *s = ASR::down_cast<ASR::Function_t>(
523+
ASRUtils::symbol_get_past_external(x.m_name));
508524

509525
uint32_t h = get_hash((ASR::asr_t*)s);
510526
if (x86_symtab.find(h) == x86_symtab.end()) {

0 commit comments

Comments
 (0)