Skip to content

Commit

Permalink
#2716 more fixes [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
arporter committed Oct 2, 2024
1 parent 62b5da5 commit 5a10b88
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -393,10 +393,10 @@ def apply(self, node, options=None):
if not existing_symbol:
# If it doesn't exist already, module-inline the subroutine by:
# 1) Registering the subroutine symbol in the Container
routine_symbol = RoutineSymbol(
callee_name, interface=DefaultModuleInterface(),
visibility=Symbol.Visibility.PRIVATE)
container.symbol_table.add(routine_symbol)
#routine_symbol = RoutineSymbol(
# callee_name, interface=DefaultModuleInterface(),
# visibility=Symbol.Visibility.PRIVATE)
#container.symbol_table.add(routine_symbol)
# 2) Insert the relevant code into the tree.
container.addchild(code_to_inline.detach())
else:
Expand All @@ -414,8 +414,7 @@ def apply(self, node, options=None):
existing_symbol.visibility = Symbol.Visibility.PRIVATE
if remove_csym:
ctable.remove(csym)
for routine in code_to_inline:
container.addchild(routine.detach())
container.addchild(routine.detach())
else:
# The routine symbol already exists, and we know from the
# validation that it's a Routine. Now check if they are
Expand Down
2 changes: 1 addition & 1 deletion src/psyclone/domain/lfric/lfric_kern.py
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ class creates the PSyIR schedule on first invocation which is

#import pdb; pdb.set_trace()
if len(routines) > 1:
table = self._kern_schedule[0].scope.symbol_table
table = routines[0].scope.symbol_table
sym = table.lookup(self.name)
else:
sym = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,8 @@ def test_module_inline_apply_bring_in_non_local_symbols(
''')

routine = psyir.walk(Routine)[0]
inline_trans._prepare_code_to_inline(routine)
sym = routine.scope.symbol_table.lookup(routine.name)
inline_trans._prepare_code_to_inline([routine], sym)
result = fortran_writer(routine)
assert "use external_mod1" in result
assert "use external_mod2" in result
Expand All @@ -548,7 +549,8 @@ def test_module_inline_apply_bring_in_non_local_symbols(
''')

routine = psyir.walk(Routine)[0]
inline_trans._prepare_code_to_inline(routine)
sym = routine.scope.symbol_table.lookup(routine.name)
inline_trans._prepare_code_to_inline([routine], sym)
result = fortran_writer(routine)
assert "use external_mod1, only : a" in result
assert "use external_mod2, only : b=>var1, c=>var2" in result
Expand All @@ -572,7 +574,8 @@ def test_module_inline_apply_bring_in_non_local_symbols(
''')

routine = psyir.walk(Routine)[0]
inline_trans._prepare_code_to_inline(routine)
sym = routine.scope.symbol_table.lookup(routine.name)
inline_trans._prepare_code_to_inline([routine], sym)
result = fortran_writer(routine)
assert "use external_mod1, only : a, d" in result
assert "use external_mod2, only : b=>var1, c=>var2, var1" in result
Expand All @@ -596,7 +599,8 @@ def test_module_inline_apply_bring_in_non_local_symbols(
''')

routine = psyir.walk(Routine)[0]
inline_trans._prepare_code_to_inline(routine)
sym = routine.scope.symbol_table.lookup(routine.name)
inline_trans._prepare_code_to_inline([routine], sym)
result = fortran_writer(routine)
assert "use external_mod1, only : r_def" in result
assert "use external_mod2, only : my_user_type" in result
Expand All @@ -617,7 +621,8 @@ def test_module_inline_apply_bring_in_non_local_symbols(
''')

routine = psyir.walk(Routine)[0]
inline_trans._prepare_code_to_inline(routine)
sym = routine.scope.symbol_table.lookup(routine.name)
inline_trans._prepare_code_to_inline([routine], sym)
result = fortran_writer(routine)
assert "use external_mod1, only : r_def" in result
assert "use not_needed" not in result
Expand All @@ -637,7 +642,8 @@ def test_module_inline_apply_bring_in_non_local_symbols(
''')

routine = psyir.walk(Routine)[0]
inline_trans._prepare_code_to_inline(routine)
sym = routine.scope.symbol_table.lookup(routine.name)
inline_trans._prepare_code_to_inline([routine], sym)
result = fortran_writer(routine)
assert "use external_mod1, only : my_sub" in result

Expand All @@ -654,7 +660,8 @@ def test_module_inline_apply_bring_in_non_local_symbols(
''')

routine = psyir.walk(Routine)[0]
inline_trans._prepare_code_to_inline(routine)
sym = routine.scope.symbol_table.lookup(routine.name)
inline_trans._prepare_code_to_inline([routine], sym)
result = fortran_writer(routine)
assert "use external_mod1, only : a, b" in result

Expand All @@ -674,7 +681,8 @@ def test_module_inline_apply_bring_in_non_local_symbols(
''')

routine = psyir.walk(Routine)[0]
inline_trans._prepare_code_to_inline(routine)
sym = routine.scope.symbol_table.lookup(routine.name)
inline_trans._prepare_code_to_inline([routine], sym)
result = fortran_writer(routine)
assert "use external_mod1, only : c" in result

Expand All @@ -692,7 +700,8 @@ def test_module_inline_apply_bring_in_non_local_symbols(
end module my_mod
''')
routine = psyir.walk(Routine)[0]
inline_trans._prepare_code_to_inline(routine)
sym = routine.scope.symbol_table.lookup(routine.name)
inline_trans._prepare_code_to_inline([routine], sym)
result = fortran_writer(routine)
assert "use external_mod\n" in result
assert "use external_mod, only : r_def" not in result
Expand All @@ -708,7 +717,8 @@ def test_module_inline_apply_bring_in_non_local_symbols(
end module my_mod
''')
routine = psyir.walk(Routine)[0]
inline_trans._prepare_code_to_inline(routine)
sym = routine.scope.symbol_table.lookup(routine.name)
inline_trans._prepare_code_to_inline([routine], sym)
result = fortran_writer(routine)
assert "use external_mod, only : a" in result

Expand Down

0 comments on commit 5a10b88

Please sign in to comment.