@@ -290,11 +290,11 @@ ASR::Module_t* load_module(Allocator &al, SymbolTable *symtab,
290290
291291// Here, we call the global_initializer & global_statements to
292292// initialize and execute the global symbols
293- void get_calls_to_global_init_and_stmts (Allocator &al, const Location &loc, SymbolTable* scope,
293+ void get_calls_to_global_stmts (Allocator &al, const Location &loc, SymbolTable* scope,
294294 ASR::Module_t* mod, std::vector<ASR::asr_t *> &tmp_vec) {
295295
296296 std::string mod_name = mod->m_name ;
297- std::string g_func_name = mod_name + " global_init " ;
297+ std::string g_func_name = mod_name + " global_stmts " ;
298298 ASR::symbol_t *g_func = mod->m_symtab ->get_symbol (g_func_name);
299299 if (g_func && !scope->get_symbol (g_func_name)) {
300300 ASR::symbol_t *es = ASR::down_cast<ASR::symbol_t >(
@@ -306,19 +306,6 @@ void get_calls_to_global_init_and_stmts(Allocator &al, const Location &loc, Symb
306306 tmp_vec.push_back (ASRUtils::make_SubroutineCall_t_util (al, loc,
307307 es, g_func, nullptr , 0 , nullptr , nullptr , false , false ));
308308 }
309-
310- g_func_name = mod_name + " global_stmts" ;
311- g_func = mod->m_symtab ->get_symbol (g_func_name);
312- if (g_func && !scope->get_symbol (g_func_name)) {
313- ASR::symbol_t *es = ASR::down_cast<ASR::symbol_t >(
314- ASR::make_ExternalSymbol_t (al, mod->base .base .loc ,
315- scope, s2c (al, g_func_name), g_func,
316- s2c (al, mod_name), nullptr , 0 , s2c (al, g_func_name),
317- ASR::accessType::Public));
318- scope->add_symbol (g_func_name, es);
319- tmp_vec.push_back (ASRUtils::make_SubroutineCall_t_util (al, loc,
320- es, g_func, nullptr , 0 , nullptr , nullptr , false , false ));
321- }
322309}
323310
324311template <class Struct >
@@ -4888,6 +4875,12 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
48884875 tmp = nullptr ;
48894876 tmp_vec.clear ();
48904877 visit_stmt (*x.m_body [i]);
4878+ for (auto t: global_init) {
4879+ if (t) {
4880+ items.push_back (al, t);
4881+ }
4882+ }
4883+ global_init.n = 0 ;
48914884 if (tmp) {
48924885 items.push_back (al, tmp);
48934886 } else if (!tmp_vec.empty ()) {
@@ -4905,30 +4898,7 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
49054898 mod->m_dependencies = current_module_dependencies.p ;
49064899 mod->n_dependencies = current_module_dependencies.n ;
49074900
4908- if (global_init.n > 0 ) {
4909- // unit->m_items is used and set to nullptr in the
4910- // `pass_wrap_global_stmts_into_function` pass
4911- unit->m_items = global_init.p ;
4912- unit->n_items = global_init.size ();
4913- std::string func_name = module_name + " global_init" ;
4914- LCompilers::PassOptions pass_options;
4915- pass_options.run_fun = func_name;
4916- pass_wrap_global_stmts (al, *unit, pass_options);
4917-
4918- ASR::symbol_t *f_sym = unit->m_symtab ->get_symbol (func_name);
4919- if (f_sym) {
4920- // Add the `global_initilaizer` function into the
4921- // module and later call this function to initialize the
4922- // global variables like list, ...
4923- ASR::Function_t *f = ASR::down_cast<ASR::Function_t>(f_sym);
4924- f->m_symtab ->parent = mod->m_symtab ;
4925- mod->m_symtab ->add_symbol (func_name, (ASR::symbol_t *) f);
4926- // Erase the function in TranslationUnit
4927- unit->m_symtab ->erase_symbol (func_name);
4928- }
4929- global_init.p = nullptr ;
4930- global_init.n = 0 ;
4931- }
4901+ LCOMPILERS_ASSERT (global_init.empty ())
49324902
49334903 if (items.n > 0 ) {
49344904 unit->m_items = items.p ;
@@ -5012,7 +4982,7 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
50124982 ASR::symbol_t *mod_sym = current_scope->resolve_symbol (mod_name);
50134983 if (mod_sym) {
50144984 ASR::Module_t *mod = ASR::down_cast<ASR::Module_t>(mod_sym);
5015- get_calls_to_global_init_and_stmts (al, x.base .base .loc , current_scope, mod, tmp_vec);
4985+ get_calls_to_global_stmts (al, x.base .base .loc , current_scope, mod, tmp_vec);
50164986 }
50174987 }
50184988 }
@@ -5031,7 +5001,7 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
50315001 ASR::symbol_t *mod_sym = current_scope->resolve_symbol (mod_name);
50325002 if (mod_sym) {
50335003 ASR::Module_t *mod = ASR::down_cast<ASR::Module_t>(mod_sym);
5034- get_calls_to_global_init_and_stmts (al, x.base .base .loc , current_scope, mod, tmp_vec);
5004+ get_calls_to_global_stmts (al, x.base .base .loc , current_scope, mod, tmp_vec);
50355005 }
50365006 tmp = nullptr ;
50375007 }
@@ -8444,7 +8414,7 @@ Result<ASR::TranslationUnit_t*> python_ast_to_asr(Allocator &al, LocationManager
84448414 ASR::Module_t *mod = ASR::down_cast<ASR::Module_t>(mod_sym);
84458415 LCOMPILERS_ASSERT (mod);
84468416 std::vector<ASR::asr_t *> tmp_vec;
8447- get_calls_to_global_init_and_stmts (al, tu->base .base .loc , program_scope, mod, tmp_vec);
8417+ get_calls_to_global_stmts (al, tu->base .base .loc , program_scope, mod, tmp_vec);
84488418
84498419 for (auto i:tmp_vec) {
84508420 prog_body.push_back (al, ASRUtils::STMT (i));
0 commit comments