10
0
mirror of https://gitlab.com/scemama/irpf90.git synced 2024-06-02 11:25:19 +02:00

Merge branch 'new'

This commit is contained in:
Anthony Scemama 2017-03-17 09:49:33 +01:00
commit 23d9daaba5
9 changed files with 59 additions and 59 deletions

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python #!/usr/bin/env python
# IRPF90 is a Fortran90 preprocessor written in Python for programming using # IRPF90 is a Fortran90 preprocessor written in Python for programming using
# the Implicit Reference to Parameters (IRP) method. # the Implicit Reference to Parameters (IRP) method.
# Copyright (C) 2009 Anthony SCEMAMA # Copyright (C) 2009 Anthony SCEMAMA
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -20,8 +20,8 @@
# Anthony Scemama # Anthony Scemama
# LCPQ - IRSAMC - CNRS # LCPQ - IRSAMC - CNRS
# Universite Paul Sabatier # Universite Paul Sabatier
# 118, route de Narbonne # 118, route de Narbonne
# 31062 Toulouse Cedex 4 # 31062 Toulouse Cedex 4
# scemama@irsamc.ups-tlse.fr # scemama@irsamc.ups-tlse.fr
import os, sys import os, sys
@ -41,7 +41,7 @@ def dress(f, in_root=False):
""" Transfoms the filename into $PWD/IRPF90_temp/f """ Transfoms the filename into $PWD/IRPF90_temp/f
Note: Note:
In root=True resurn $PWD/f In root=True resurn $PWD/f
""" """
pwd = os.getcwd() pwd = os.getcwd()
@ -124,7 +124,7 @@ def create_build_link(t, l_irp_m, l_usr_m, l_ext_m, ninja=True):
basename = os.path.basename(filename) basename = os.path.basename(filename)
if basename != progname: if basename != progname:
from util import logger from util import logger
logger.info('program-name `{0}` != file-name `{1}` (using file-name for now...)'.format(progname,basename)) logger.info('program-name `{0}` != file-name `{1}` (using file-name for now...)'.format(progname,basename))
target = dress(filename, in_root=True) target = dress(filename, in_root=True)
@ -158,8 +158,8 @@ def create_build_compile(t, l_module, l_ext_modfile=[], ninja=True):
- The module can produce a .MOD file - The module can produce a .MOD file
- The module can Need another .MOD file. - The module can Need another .MOD file.
This .MOD file can be produced by: This .MOD file can be produced by:
1) a file generated by IRP_F90 preprocessor. 1) a file generated by IRP_F90 preprocessor.
2) a file defined by the user but a .irp.f90 file. 2) a file defined by the user but a .irp.f90 file.
3) a file not handle at all by IRPF90. 3) a file not handle at all by IRPF90.
@ -211,12 +211,12 @@ def create_build_compile(t, l_module, l_ext_modfile=[], ninja=True):
inline_include = True inline_include = True
if not inline_include: if not inline_include:
#Wrong name, this not work! #Wrong name, this not work!
#list_of_includes = ' '.join(map(lambda x: dress(x, in_root=True), t.includes)) #list_of_includes = ' '.join(map(lambda x: dress(x, in_root=True), t.includes))
raise NotImplemented raise NotImplemented
else: else:
#The include have already by included #The include have already by included
list_of_includes = ' ' list_of_includes = ' '
l_build = [ l_build = [
"build {target_o}: compile_fortran_{irp_id} {target_F90} | {list_of_includes} {list_of_modules} {list_of_modules_irp}", "build {target_o}: compile_fortran_{irp_id} {target_F90} | {list_of_includes} {list_of_modules} {list_of_modules_irp}",
@ -236,8 +236,8 @@ def create_build_compile(t, l_module, l_ext_modfile=[], ninja=True):
l_build += [ l_build += [
"build {target_module_o}: compile_fortran_{irp_id} {target_module_F90} | {list_of_includes} {list_of_modules} ", "build {target_module_o}: compile_fortran_{irp_id} {target_module_F90} | {list_of_includes} {list_of_modules} ",
" short_in = {short_target_module_F90}", " short_in = {short_target_module_F90}",
" short_out = {short_target_module_o}", " short_out = {short_target_module_o}",
"" ""
] ]
l_build_make += [ l_build_make += [
@ -363,7 +363,7 @@ def create_make_all_clean(l_main):
''' '''
l_executable =' '.join(dress( t.filename, in_root=True) for t in l_main) l_executable =' '.join(dress( t.filename, in_root=True) for t in l_main)
output = [".PHONY : all", output = [".PHONY : all",
"all: {l_executable}", "all: {l_executable}",
@ -511,7 +511,7 @@ def run(d_module, ninja):
output = create_var_and_rule(d_flags, ninja) output = create_var_and_rule(d_flags, ninja)
if not ninja: if not ninja:
output += create_make_all_clean(l_mod_main) output += create_make_all_clean(l_mod_main)
# Create all the .irp.F90 -> .o # Create all the .irp.F90 -> .o
for m in l_mod: for m in l_mod:
output.append(create_build_compile(m, l_mod, l_ext_m, ninja)) output.append(create_build_compile(m, l_mod, l_ext_m, ninja))

View File

@ -90,7 +90,7 @@ class Entity(object):
@irpy.lazy_property @irpy.lazy_property
def d_type_lines(self): def d_type_lines(self):
# () -> Dict[Line, Tuple[int,Line] ] # () -> Dict[Line, Tuple[int,Line] ]
'''Contruct a mapping table between the type of the line and the possition''' '''Contruct a mapping table between the type of the line and the possition'''
from collections import defaultdict from collections import defaultdict
d = defaultdict(list) d = defaultdict(list)
for i, line in enumerate(self.text): for i, line in enumerate(self.text):
@ -105,11 +105,11 @@ class Entity(object):
def is_main(self): def is_main(self):
# () -> bool # () -> bool
'''Check if this Entity is the main one '''Check if this Entity is the main one
Exemple: Exemple:
BEGIN_PROVIDER [pi, double precision] & BEGIN_PROVIDER [pi, double precision] &
BEGIN_PROVIDER [e, double preision] BEGIN_PROVIDER [e, double preision]
return True for 'pi' and False for 'e' return True for 'pi' and False for 'e'
''' '''
return self.name == self.same_as return self.name == self.same_as
@ -337,8 +337,8 @@ class Entity(object):
type_ = self.prototype.text.split(',')[0].split('[')[1].strip() type_ = self.prototype.text.split(',')[0].split('[')[1].strip()
if not type_: if not type_:
logger.error( "Error in definition of %s." % (self.name)) logger.error( "Error in definition of %s." % (self.name))
sys.exit(1) sys.exit(1)
if self.dim: if self.dim:
return "%s, allocatable" % (type_) return "%s, allocatable" % (type_)
@ -627,7 +627,7 @@ class Entity(object):
# Get the raw text for the builder # Get the raw text for the builder
# ~#~#~#~#~# # ~#~#~#~#~#
#Next return the first element of the iterator #Next return the first element of the iterator
ps_text = next(text for filename, text in self.cm_t_filename_parsed_text ps_text = next(text for filename, text in self.cm_t_filename_parsed_text
if self.prototype.filename[0].startswith(filename)) if self.prototype.filename[0].startswith(filename))
begin = next(i for i, (_, line) in enumerate(ps_text) begin = next(i for i, (_, line) in enumerate(ps_text)

View File

@ -59,8 +59,8 @@ def main():
print 'graph { ' print 'graph { '
for name,entity in comm_world.d_entity.items(): for name,entity in comm_world.d_entity.items():
if entity.needs: if entity.needs:
print ' {0} -> {1}'.format(name, ' '.join(entity.needs)) print ' {0} -> {1}'.format(name, ' '.join(entity.needs))
print '}' print '}'
return return

View File

@ -31,7 +31,7 @@ import sys
if __name__ == "__main__": if __name__ == "__main__":
from irpf90_t import mandir from irpf90_t import mandir
entity = sys.argv[1].lower() entity = sys.argv[1].lower()
filename = '%s.l'% entity filename = '%s.l'% entity
if filename not in os.listdir(mandir): if filename not in os.listdir(mandir):
print "Error: `%s` does not exist"% entity print "Error: `%s` does not exist"% entity

View File

@ -45,20 +45,20 @@ class Irpy_comm_world(object):
s_file_folder = filter(lambda f: os.path.isfile(f) and not f.startswith("."), s_file_folder_all) s_file_folder = filter(lambda f: os.path.isfile(f) and not f.startswith("."), s_file_folder_all)
s_file_tot = set(l_file) if l_file else set() s_file_tot = set(l_file) if l_file else set()
s_file_tot.update(s_file_folder) s_file_tot.update(s_file_folder)
s_file_rel = set(os.path.relpath(f,self.cwd) for f in s_file_tot) s_file_rel = set(os.path.relpath(f,self.cwd) for f in s_file_tot)
# Lazy Copy file # Lazy Copy file
for f in s_file_rel: for f in s_file_rel:
src = os.path.join(self.cwd,f) src = os.path.join(self.cwd,f)
text_ref = open(src, 'rb').read() text_ref = open(src, 'rb').read()
dest = os.path.join(self.cwd,irpf90_t.irpdir, f) dest = os.path.join(self.cwd,irpf90_t.irpdir, f)
lazy_write_file(dest, text_ref) lazy_write_file(dest, text_ref)
if command_line.do_codelet: if command_line.do_codelet:
s_file_tot.update(command_line.codelet[3]) s_file_tot.update(command_line.codelet[3])
@ -134,7 +134,7 @@ class Irpy_comm_world(object):
# #
# Modify parameter of variables # Modify parameter of variables
# Touch Softouch # Touch Softouch
def find_variable(line): def find_variable(line):
l_var = line.lower.split()[1:] l_var = line.lower.split()[1:]
if len(l_var) < 1: if len(l_var) < 1:
@ -238,8 +238,8 @@ class Irpy_comm_world(object):
from irpf90_t import NoDep,Declaration,Implicit,Use,Cont_provider from irpf90_t import NoDep,Declaration,Implicit,Use,Cont_provider
def moved_to_top_l(ptext): def moved_to_top_l(ptext):
l = [NoDep, Declaration, Implicit, Use, Cont_provider] l = [NoDep, Declaration, Implicit, Use, Cont_provider]
for _, text in ptext: for _, text in ptext:
parsed_text.move_to_top_list(text, l) parsed_text.move_to_top_list(text, l)
#Touch routine #Touch routine
parsed_text.build_sub_needs(parsed_text_0, d_routine) parsed_text.build_sub_needs(parsed_text_0, d_routine)
@ -318,5 +318,5 @@ class Irpy_comm_world(object):
out += [ "end subroutine", "" ] out += [ "end subroutine", "" ]
filename = os.path.join(irpf90_t.irpdir,'irp_locks.irp.F90') filename = os.path.join(irpf90_t.irpdir,'irp_locks.irp.F90')
lazy_write_file(filename, '\n'.join(out)) lazy_write_file(filename, '\n'.join(out))

View File

@ -144,8 +144,8 @@ class Fmodule(object):
continue continue
if type(line) in [Subroutine, Function, Program]: if type(line) in [Subroutine, Function, Program]:
#Deep copy... #Deep copy...
variable_list = list(vars) variable_list = list(vars)
elif type(line) == End: elif type(line) == End:
result += [([], Use(line.i, x, line.filename)) for x in build_use(variable_list, self.d_all_variable)] result += [([], Use(line.i, x, line.filename)) for x in build_use(variable_list, self.d_all_variable)]
@ -163,7 +163,7 @@ class Fmodule(object):
result,dec,use,module = [],[],[],[] result,dec,use,module = [],[],[],[]
for vars, line in text: for vars, line in text:
if isinstance(line, (Subroutine, Function, Program,Interface,Module)): if isinstance(line, (Subroutine, Function, Program,Interface,Module)):
inside += 1 inside += 1
@ -177,7 +177,7 @@ class Fmodule(object):
use.append((vars, line)) use.append((vars, line))
elif type(line) == Declaration: elif type(line) == Declaration:
dec.append((vars, line)) dec.append((vars, line))
if isinstance(line,(End,End_interface,End_module)): if isinstance(line,(End,End_interface,End_module)):
inside += -1 inside += -1
@ -208,10 +208,10 @@ class Fmodule(object):
@irpy.lazy_property @irpy.lazy_property
def dec(self): def dec(self):
'''The declaration of this module '''The declaration of this module
Note: Note:
Because user can define F90 Type, we need to keep the correct order. Because user can define F90 Type, we need to keep the correct order.
Warning: Warning:
If we uniquify that can cause a problem with the type in guess. If we uniquify that can cause a problem with the type in guess.
```type toto ```type toto

View File

@ -208,7 +208,7 @@ def move_to_top_list(text, it):
- We can have `nested` subroutine / Function. (Because of interface) - We can have `nested` subroutine / Function. (Because of interface)
- This function is called way to much. Is need to be efficient - This function is called way to much. Is need to be efficient
- This function is Impure - This function is Impure
- One pass over `text` - One pass over `text`
NB: NB:
@ -231,7 +231,7 @@ def move_to_top_list(text, it):
for i, (l_var, line) in enumerate(text): for i, (l_var, line) in enumerate(text):
t = type(line) t = type(line)
if t in [Begin_provider, Module,Program, Subroutine, Function]: if t in [Begin_provider, Module,Program, Subroutine, Function]:
l_begin.append(i) l_begin.append(i)
elif t in [End_provider, End]: elif t in [End_provider, End]:
@ -240,7 +240,7 @@ def move_to_top_list(text, it):
elif l_begin and t in it: elif l_begin and t in it:
d_permutation[t].append( (l_begin[-1], [l_var, line]) ) d_permutation[t].append( (l_begin[-1], [l_var, line]) )
# Put the sentinel, will be deleted after the insertion # Put the sentinel, will be deleted after the insertion
text[i] = None text[i] = None
# ~ # ~ # ~ # ~ # ~ # ~
# O r d e r t h e m # O r d e r t h e m
@ -276,7 +276,7 @@ def move_interface(parsed_text,s_type=(Use,Implicit,Declaration,Subroutine,Funct
= This function is impure = This function is impure
''' '''
# Get the born of the interface # Get the born of the interface
i_begin = [ i for i, (_, line) in enumerate(parsed_text) if isinstance(line,Interface) ] i_begin = [ i for i, (_, line) in enumerate(parsed_text) if isinstance(line,Interface) ]
i_end = [ i+1 for i, (_, line) in enumerate(parsed_text) if isinstance(line,End_interface) ] i_end = [ i+1 for i, (_, line) in enumerate(parsed_text) if isinstance(line,End_interface) ]
@ -290,7 +290,7 @@ def move_interface(parsed_text,s_type=(Use,Implicit,Declaration,Subroutine,Funct
parsed_text[insert:insert] = parsed_text[begin:end] parsed_text[insert:insert] = parsed_text[begin:end]
padding = end-begin padding = end-begin
parsed_text[begin+padding:end+padding] = [] parsed_text[begin+padding:end+padding] = []
###################################################################### ######################################################################
def build_sub_needs(parsed_text, d_subroutine): def build_sub_needs(parsed_text, d_subroutine):
@ -298,7 +298,7 @@ def build_sub_needs(parsed_text, d_subroutine):
'''Set the needs, and provides arguements of Routine present in parsed_text '''Set the needs, and provides arguements of Routine present in parsed_text
Note: Note:
This function is impure This function is impure
''' '''
l_buffer = [] l_buffer = []
@ -352,7 +352,7 @@ def move_variables(parsed_text):
for vars, line in revtext: for vars, line in revtext:
if type(line) in [Interface, End_interface]: if type(line) in [Interface, End_interface]:
skip_interface = not skip_interface skip_interface = not skip_interface
if skip_interface: if skip_interface:
append(([], line)) append(([], line))
continue continue

View File

@ -152,7 +152,7 @@ def get_type(i, filename, line, line_lower, line_lower_canonized, is_doc):
reg_do_lab = ur":\s+do\s+" reg_do_lab = ur":\s+do\s+"
if re.search(reg_do_lab,line_lower): if re.search(reg_do_lab,line_lower):
return [Do(i,line,filename)], is_doc return [Do(i,line,filename)], is_doc
lower_line = line_lower.strip()[1:] lower_line = line_lower.strip()[1:]
@ -445,7 +445,7 @@ def remove_comments(text, form):
text = remove_after_bang(line.text) text = remove_after_bang(line.text)
if text: if text:
line.text = text line.text = text
result.append(line) result.append(line)
return result return result
else: else:
@ -769,7 +769,7 @@ def process_old_style_do(text):
###################################################################### ######################################################################
def change_single_line_ifs(text): def change_single_line_ifs(text):
# List[Line] -> List[Line] # List[Line] -> List[Line]
'''Changes: `if (test) result` '''Changes: `if (test) result`
into into
`if (test) then `if (test) then
result result
@ -853,7 +853,7 @@ def check_begin_end(raw_text):
if n_end > n_begin: if n_end > n_begin:
logger.error("You have more close statement than open statement (%s) (%s)",line.filename,t_end) logger.error("You have more close statement than open statement (%s) (%s)",line.filename,t_end)
else: else:
logger.error('You have more end statement than open statenemt for (%s) (%s)' % (line.filename, t_end)) logger.error('You have more end statement than open statenemt for (%s) (%s)' % (line.filename, t_end))
for i in zip([l for i in l_begin for l in d_type[i]], d_type[t_end]): for i in zip([l for i in l_begin for l in d_type[i]], d_type[t_end]):
@ -913,7 +913,7 @@ class Preprocess_text(object):
str_ = f.read() str_ = f.read()
#Dirty thing. We will replace 'end program' by 'end subroutine' #Dirty thing. We will replace 'end program' by 'end subroutine'
#because afterward the program will be replaced by a subroutine... #because afterward the program will be replaced by a subroutine...
import re import re
transform = re.compile(re.escape('end program'), re.IGNORECASE) transform = re.compile(re.escape('end program'), re.IGNORECASE)

View File

@ -82,12 +82,12 @@ def parmap(f, it, parallel=False):
# https://docs.python.org/2/library/pickle.html#what-can-be-pickled-and-unpickled # https://docs.python.org/2/library/pickle.html#what-can-be-pickled-and-unpickled
#from cPickle import PicklingError #from cPickle import PicklingError
#try: #try:
# p = multiprocessing.Pool(nproc) # p = multiprocessing.Pool(nproc)
# l_res = p.map(f, it,nproc) # l_res = p.map(f, it,nproc)
#except PicklingError: #except PicklingError:
# pass # pass
#else: #else:
# return l_res # return l_res
# ~!~!~! # ~!~!~!
# Parallelisation By Us # Parallelisation By Us
@ -127,8 +127,8 @@ def parmap(f, it, parallel=False):
result = F(x) result = F(x)
except BaseException as e: except BaseException as e:
t = e t = e
else: else:
t = (i, result) t = (i, result)
q_out.put(t) q_out.put(t)
q_in.task_done() q_in.task_done()
@ -162,8 +162,8 @@ def parmap(f, it, parallel=False):
from itertools import ifilter from itertools import ifilter
e = next(ifilter(lambda t: isinstance(t,BaseException), l_res)) e = next(ifilter(lambda t: isinstance(t,BaseException), l_res))
except StopIteration: except StopIteration:
# Now we need first to order the result, and secondly to flatte it # Now we need first to order the result, and secondly to flatte it
return [item for _, chunk in sorted(l_res) for item in chunk] return [item for _, chunk in sorted(l_res) for item in chunk]
else: else:
raise e raise e