Skip to content

Commit 99bd649

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

File tree

2 files changed

+64
-2
lines changed

2 files changed

+64
-2
lines changed

src/libasr/asr_utils.h

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,53 @@
1414
namespace LCompilers {
1515

1616
namespace ASRUtils {
17-
17+
static inline void print_symbol(const ASR::symbol_t *f) {
18+
if (!f) {
19+
std::cout << "(null)\n";
20+
}
21+
switch (f->type) {
22+
case ASR::symbolType::Program: {
23+
std::cout << "Program_t\n";
24+
break;}
25+
case ASR::symbolType::Module: {
26+
std::cout << "Module_t\n";
27+
break;}
28+
case ASR::symbolType::Function: {
29+
std::cout << "Function_t\n";
30+
break;}
31+
case ASR::symbolType::GenericProcedure: {
32+
std::cout << "GenericProcedure_t\n";
33+
break;}
34+
case ASR::symbolType::StructType: {
35+
std::cout << "StructType_t\n";
36+
break;}
37+
case ASR::symbolType::EnumType: {
38+
std::cout << "EnumType_t\n";
39+
break;}
40+
case ASR::symbolType::UnionType: {
41+
std::cout << "UnionType_t\n";
42+
break;}
43+
case ASR::symbolType::Variable: {
44+
std::cout << "Variable_t\n";
45+
break;}
46+
case ASR::symbolType::ExternalSymbol: {
47+
std::cout << "ExternalSymbol_t\n";
48+
break;}
49+
case ASR::symbolType::ClassProcedure: {
50+
std::cout << "ClassProcedure_t\n";
51+
break;}
52+
case ASR::symbolType::CustomOperator: {
53+
std::cout << "CustomOperator_t\n";
54+
break;}
55+
case ASR::symbolType::AssociateBlock: {
56+
std::cout << "AssociateBlock_t\n";
57+
break;}
58+
case ASR::symbolType::Block: {
59+
std::cout << "Block_t\n";
60+
break;}
61+
default : throw LCompilersException("Not implemented");
62+
}
63+
}
1864
static inline double extract_real(const char *s) {
1965
// TODO: this is inefficient. We should
2066
// convert this in the tokenizer where we know most information

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)