Provide dimensions in subroutines

Version:1.2.5
This commit is contained in:
Anthony Scemama 2011-11-09 12:26:39 +01:00
parent 4a16a6398b
commit 6763923a94
6 changed files with 55 additions and 36 deletions

View File

@ -1,4 +1,5 @@
program irp_example1
integer :: x(w)
BEGIN_SHELL [ /bin/bash ]
echo print *, \'Compiled by `whoami` on `date`\'
echo print *, \'$FC $FCFLAGS\'

View File

@ -151,7 +151,7 @@ class Fmodule(object):
dec = []
use = []
for vars,line in text:
if type(line) in [ Subroutine, Function]:
if type(line) in [ Subroutine, Function, Program]:
inside = True
if inside:
result.append( (vars,line) )
@ -182,22 +182,6 @@ class Fmodule(object):
result = move_to_top(result,Use)
result = map(lambda x: x[1], result)
result = map(lambda x: x.text, result)
if self.is_main:
temp = [ "program irp_program" ]
if command_line.do_profile:
temp += [ "call irp_init_timer()" ]
if command_line.do_openmp:
temp += [ "!$OMP PARALLEL" ]
temp += [ "!$OMP MASTER" ]
temp += [ " call %s"%(self.prog_name) ]
if command_line.do_openmp:
temp += [ "!$OMP END MASTER" ]
temp += [ "!$OMP END PARALLEL" ]
if command_line.do_profile:
temp += [ "call irp_print_timer()" ]
temp += [ " call irp_finalize_%s()"%(irp_id) ]
temp += [ "end program" ]
result = temp + result
self._residual_text = result
return self._residual_text
residual_text = property(residual_text)

View File

@ -257,7 +257,7 @@ def move_to_top(text,t):
inside = False
for i in range(len(text)):
vars, line = text[i]
if type(line) in [ Begin_provider, Subroutine, Function ]:
if type(line) in [ Begin_provider, Program, Subroutine, Function ]:
begin = i
inside = True
elif type(line) in [ End_provider, End ]:
@ -286,17 +286,25 @@ def build_sub_needs():
# Needs
for filename, text in parsed_text:
sub = None
in_program = False
for vars,line in text:
if type(line) in [ Subroutine, Function ]:
subname = find_subname(line)
sub = subroutines[subname]
sub.needs = []
sub.to_provide = vars
sub._needs = []
sub._to_provide = []
elif type(line) == End:
sub.needs = make_single(sub.needs)
sub = None
if not in_program:
sub._needs = make_single(sub._needs)
sub._to_provide = make_single(sub._to_provide)
sub = None
elif type(line) == Program:
in_program = True
if sub is not None:
sub.needs += vars
if type(line) == Declaration:
sub._to_provide += vars
else:
sub._needs += vars
build_sub_needs()
@ -361,7 +369,7 @@ def move_variables():
ifvars = old_ifvars.pop()
elsevars = old_elsevars.pop()
varlist = old_varlist.pop() + vars
elif type(line) in [ Begin_provider, Subroutine, Function ]:
elif type(line) in [ Begin_provider, Program, Subroutine, Function ]:
varlist += vars
append( (varlist,line) )
if old_varlist != [] \
@ -385,7 +393,7 @@ def move_variables():
for vars,line in text:
if vars != []:
vars = make_single(vars)
if type(line) in [ Begin_provider, Subroutine, Function ]:
if type(line) in [ Begin_provider, Program, Subroutine, Function ]:
varlist = list(vars)
elif type(line) in [ If, Select ]:
old_varlist.append(varlist)

View File

@ -605,7 +605,21 @@ def irp_simple_statements(text):
def process_program(line):
assert type(line) == Program
program_name = line.lower.split()[1]
result = [ Program(0,"",program_name) ] + \
temp = [ Program(0,"program irp_program",program_name) ]
if command_line.do_profile:
temp += [ Simple_line(0,"call irp_init_timer()",line.filename) ]
if command_line.do_openmp:
temp += [ Openmp(0,"!$OMP PARALLEL",line.filename) ]
temp += [ Openmp(0,"!$OMP MASTER",line.filename) ]
temp += [ Call(0," call %s"%(program_name),line.filename) ]
if command_line.do_openmp:
temp += [ Openmp(0,"!$OMP END MASTER",line.filename) ]
temp += [ Openmp(0,"!$OMP END PARALLEL",line.filename) ]
if command_line.do_profile:
temp += [ Simple_line(0,"call irp_print_timer()",line.filename) ]
temp += [ Simple_line(0," call irp_finalize_%s()"%(irp_id),line.filename) ]
temp += [ End(0,"end program",line.filename) ]
result = temp + \
process_subroutine( Subroutine(line.i,"subroutine %s"%(program_name,),line.filename) )
return result
@ -739,7 +753,7 @@ def check_begin_end(text):
'''Checks x...endx consistence'''
filter_line = lambda line: type(line) in [ Do, Enddo, If, Endif, \
Begin_provider, End_provider, \
Program, Begin_provider, End_provider, \
Subroutine, Function, End, Begin_doc, End_doc ]
text = filter(filter_line, text)
@ -767,9 +781,9 @@ def check_begin_end(text):
line = text[i]
if type(line) == x:
return
if type(line) in [ Subroutine, Function, Begin_provider ]:
error.fail(text[begin],"Subroutine/Function/Provider is not closed")
error.fail(text[begin],"Subroutine/Function/Provider is not closed")
if type(line) in [ Subroutine, Function, Program, Begin_provider ]:
error.fail(text[begin],type(line)+" is not closed")
error.fail(text[begin],type(line) + " is not closed")
level = 0
@ -781,10 +795,7 @@ def check_begin_end(text):
find_matching_end_ifdo(i,'do')
elif type(line) == If:
find_matching_end_ifdo(i,'if')
elif type(line) == Subroutine:
level += 1
find_matching_end_subfunpro(i,End)
elif type(line) == Function:
elif type(line) in [Subroutine, Function, Program]:
level += 1
find_matching_end_subfunpro(i,End)
elif type(line) == Begin_provider:

View File

@ -85,6 +85,20 @@ class Sub(object):
return self._touches
touches = property(touches)
############################################################
def needs(self):
if '_needs' not in self.__dict__:
import parsed_text
return self._needs
needs = property(needs)
############################################################
def to_provide(self):
if '_to_provide' not in self.__dict__:
import parsed_text
return self._to_provide
to_provide = property(to_provide)
############################################################
def regexp(self):
if '_regexp' not in self.__dict__:
@ -110,4 +124,5 @@ class Sub(object):
if __name__ == '__main__':
from preprocessed_text import preprocessed_text
from subroutines import subroutines
print subroutines['brownian_step'].touches
print subroutines['run'].needs
print subroutines['run'].to_provide

View File

@ -1 +1 @@
version = "1.2.4"
version = "1.2.5"