mirror of https://gitlab.com/scemama/irpf90.git
Merge branch 'new'
This commit is contained in:
commit
23d9daaba5
|
@ -1,7 +1,7 @@
|
|||
#!/usr/bin/env python
|
||||
# IRPF90 is a Fortran90 preprocessor written in Python for programming using
|
||||
# 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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
@ -20,8 +20,8 @@
|
|||
# Anthony Scemama
|
||||
# LCPQ - IRSAMC - CNRS
|
||||
# Universite Paul Sabatier
|
||||
# 118, route de Narbonne
|
||||
# 31062 Toulouse Cedex 4
|
||||
# 118, route de Narbonne
|
||||
# 31062 Toulouse Cedex 4
|
||||
# scemama@irsamc.ups-tlse.fr
|
||||
|
||||
import os, sys
|
||||
|
@ -41,7 +41,7 @@ def dress(f, in_root=False):
|
|||
""" Transfoms the filename into $PWD/IRPF90_temp/f
|
||||
|
||||
Note:
|
||||
In root=True resurn $PWD/f
|
||||
In root=True resurn $PWD/f
|
||||
"""
|
||||
|
||||
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)
|
||||
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))
|
||||
|
||||
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 Need another .MOD file.
|
||||
This .MOD file can be produced by:
|
||||
1) a file generated by IRP_F90 preprocessor.
|
||||
This .MOD file can be produced by:
|
||||
1) a file generated by IRP_F90 preprocessor.
|
||||
2) a file defined by the user but a .irp.f90 file.
|
||||
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
|
||||
if not inline_include:
|
||||
#Wrong name, this not work!
|
||||
#list_of_includes = ' '.join(map(lambda x: dress(x, in_root=True), t.includes))
|
||||
raise NotImplemented
|
||||
#Wrong name, this not work!
|
||||
#list_of_includes = ' '.join(map(lambda x: dress(x, in_root=True), t.includes))
|
||||
raise NotImplemented
|
||||
else:
|
||||
#The include have already by included
|
||||
list_of_includes = ' '
|
||||
#The include have already by included
|
||||
list_of_includes = ' '
|
||||
|
||||
l_build = [
|
||||
"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 += [
|
||||
"build {target_module_o}: compile_fortran_{irp_id} {target_module_F90} | {list_of_includes} {list_of_modules} ",
|
||||
" short_in = {short_target_module_F90}",
|
||||
" short_out = {short_target_module_o}",
|
||||
""
|
||||
" short_out = {short_target_module_o}",
|
||||
""
|
||||
]
|
||||
|
||||
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",
|
||||
"all: {l_executable}",
|
||||
|
@ -511,7 +511,7 @@ def run(d_module, ninja):
|
|||
output = create_var_and_rule(d_flags, ninja)
|
||||
if not ninja:
|
||||
output += create_make_all_clean(l_mod_main)
|
||||
|
||||
|
||||
# Create all the .irp.F90 -> .o
|
||||
for m in l_mod:
|
||||
output.append(create_build_compile(m, l_mod, l_ext_m, ninja))
|
||||
|
|
|
@ -90,7 +90,7 @@ class Entity(object):
|
|||
@irpy.lazy_property
|
||||
def d_type_lines(self):
|
||||
# () -> 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
|
||||
d = defaultdict(list)
|
||||
for i, line in enumerate(self.text):
|
||||
|
@ -105,11 +105,11 @@ class Entity(object):
|
|||
def is_main(self):
|
||||
# () -> bool
|
||||
'''Check if this Entity is the main one
|
||||
|
||||
|
||||
Exemple:
|
||||
BEGIN_PROVIDER [pi, double precision] &
|
||||
BEGIN_PROVIDER [e, double preision]
|
||||
|
||||
|
||||
return True for 'pi' and False for 'e'
|
||||
'''
|
||||
return self.name == self.same_as
|
||||
|
@ -337,8 +337,8 @@ class Entity(object):
|
|||
type_ = self.prototype.text.split(',')[0].split('[')[1].strip()
|
||||
|
||||
if not type_:
|
||||
logger.error( "Error in definition of %s." % (self.name))
|
||||
sys.exit(1)
|
||||
logger.error( "Error in definition of %s." % (self.name))
|
||||
sys.exit(1)
|
||||
|
||||
if self.dim:
|
||||
return "%s, allocatable" % (type_)
|
||||
|
@ -627,7 +627,7 @@ class Entity(object):
|
|||
# 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
|
||||
if self.prototype.filename[0].startswith(filename))
|
||||
begin = next(i for i, (_, line) in enumerate(ps_text)
|
||||
|
|
|
@ -59,8 +59,8 @@ def main():
|
|||
|
||||
print 'graph { '
|
||||
for name,entity in comm_world.d_entity.items():
|
||||
if entity.needs:
|
||||
print ' {0} -> {1}'.format(name, ' '.join(entity.needs))
|
||||
if entity.needs:
|
||||
print ' {0} -> {1}'.format(name, ' '.join(entity.needs))
|
||||
print '}'
|
||||
return
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ import sys
|
|||
if __name__ == "__main__":
|
||||
from irpf90_t import mandir
|
||||
entity = sys.argv[1].lower()
|
||||
|
||||
|
||||
filename = '%s.l'% entity
|
||||
if filename not in os.listdir(mandir):
|
||||
print "Error: `%s` does not exist"% entity
|
||||
|
|
|
@ -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_tot = set(l_file) if l_file else set()
|
||||
s_file_tot.update(s_file_folder)
|
||||
|
||||
|
||||
s_file_rel = set(os.path.relpath(f,self.cwd) for f in s_file_tot)
|
||||
|
||||
# Lazy Copy file
|
||||
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()
|
||||
|
||||
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:
|
||||
s_file_tot.update(command_line.codelet[3])
|
||||
|
@ -134,7 +134,7 @@ class Irpy_comm_world(object):
|
|||
#
|
||||
# Modify parameter of variables
|
||||
|
||||
# Touch Softouch
|
||||
# Touch Softouch
|
||||
def find_variable(line):
|
||||
l_var = line.lower.split()[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
|
||||
def moved_to_top_l(ptext):
|
||||
l = [NoDep, Declaration, Implicit, Use, Cont_provider]
|
||||
for _, text in ptext:
|
||||
parsed_text.move_to_top_list(text, l)
|
||||
for _, text in ptext:
|
||||
parsed_text.move_to_top_list(text, l)
|
||||
|
||||
#Touch routine
|
||||
parsed_text.build_sub_needs(parsed_text_0, d_routine)
|
||||
|
@ -318,5 +318,5 @@ class Irpy_comm_world(object):
|
|||
out += [ "end subroutine", "" ]
|
||||
|
||||
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))
|
||||
|
||||
|
|
|
@ -144,8 +144,8 @@ class Fmodule(object):
|
|||
continue
|
||||
|
||||
|
||||
if type(line) in [Subroutine, Function, Program]:
|
||||
#Deep copy...
|
||||
if type(line) in [Subroutine, Function, Program]:
|
||||
#Deep copy...
|
||||
variable_list = list(vars)
|
||||
elif type(line) == End:
|
||||
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 = [],[],[],[]
|
||||
|
||||
for vars, line in text:
|
||||
|
||||
|
||||
if isinstance(line, (Subroutine, Function, Program,Interface,Module)):
|
||||
inside += 1
|
||||
|
||||
|
@ -177,7 +177,7 @@ class Fmodule(object):
|
|||
use.append((vars, line))
|
||||
elif type(line) == Declaration:
|
||||
dec.append((vars, line))
|
||||
|
||||
|
||||
|
||||
if isinstance(line,(End,End_interface,End_module)):
|
||||
inside += -1
|
||||
|
@ -208,10 +208,10 @@ class Fmodule(object):
|
|||
@irpy.lazy_property
|
||||
def dec(self):
|
||||
'''The declaration of this module
|
||||
|
||||
|
||||
Note:
|
||||
Because user can define F90 Type, we need to keep the correct order.
|
||||
|
||||
|
||||
Warning:
|
||||
If we uniquify that can cause a problem with the type in guess.
|
||||
```type toto
|
||||
|
|
|
@ -208,7 +208,7 @@ def move_to_top_list(text, it):
|
|||
- We can have `nested` subroutine / Function. (Because of interface)
|
||||
- This function is called way to much. Is need to be efficient
|
||||
- This function is Impure
|
||||
- One pass over `text`
|
||||
- One pass over `text`
|
||||
|
||||
|
||||
NB:
|
||||
|
@ -231,7 +231,7 @@ def move_to_top_list(text, it):
|
|||
|
||||
for i, (l_var, line) in enumerate(text):
|
||||
t = type(line)
|
||||
|
||||
|
||||
if t in [Begin_provider, Module,Program, Subroutine, Function]:
|
||||
l_begin.append(i)
|
||||
elif t in [End_provider, End]:
|
||||
|
@ -240,7 +240,7 @@ def move_to_top_list(text, it):
|
|||
elif l_begin and t in it:
|
||||
d_permutation[t].append( (l_begin[-1], [l_var, line]) )
|
||||
# Put the sentinel, will be deleted after the insertion
|
||||
text[i] = None
|
||||
text[i] = None
|
||||
|
||||
# ~ # ~ # ~
|
||||
# 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
|
||||
'''
|
||||
|
||||
# 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_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]
|
||||
|
||||
padding = end-begin
|
||||
parsed_text[begin+padding:end+padding] = []
|
||||
parsed_text[begin+padding:end+padding] = []
|
||||
|
||||
######################################################################
|
||||
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
|
||||
|
||||
Note:
|
||||
This function is impure
|
||||
This function is impure
|
||||
'''
|
||||
|
||||
l_buffer = []
|
||||
|
@ -352,7 +352,7 @@ def move_variables(parsed_text):
|
|||
for vars, line in revtext:
|
||||
if type(line) in [Interface, End_interface]:
|
||||
skip_interface = not skip_interface
|
||||
|
||||
|
||||
if skip_interface:
|
||||
append(([], line))
|
||||
continue
|
||||
|
|
|
@ -152,7 +152,7 @@ def get_type(i, filename, line, line_lower, line_lower_canonized, is_doc):
|
|||
reg_do_lab = ur":\s+do\s+"
|
||||
if re.search(reg_do_lab,line_lower):
|
||||
return [Do(i,line,filename)], is_doc
|
||||
|
||||
|
||||
|
||||
lower_line = line_lower.strip()[1:]
|
||||
|
||||
|
@ -445,7 +445,7 @@ def remove_comments(text, form):
|
|||
text = remove_after_bang(line.text)
|
||||
if text:
|
||||
line.text = text
|
||||
result.append(line)
|
||||
result.append(line)
|
||||
|
||||
return result
|
||||
else:
|
||||
|
@ -769,7 +769,7 @@ def process_old_style_do(text):
|
|||
######################################################################
|
||||
def change_single_line_ifs(text):
|
||||
# List[Line] -> List[Line]
|
||||
'''Changes: `if (test) result`
|
||||
'''Changes: `if (test) result`
|
||||
into
|
||||
`if (test) then
|
||||
result
|
||||
|
@ -853,7 +853,7 @@ def check_begin_end(raw_text):
|
|||
|
||||
if n_end > n_begin:
|
||||
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))
|
||||
|
||||
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()
|
||||
|
||||
#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
|
||||
transform = re.compile(re.escape('end program'), re.IGNORECASE)
|
||||
|
|
16
src/util.py
16
src/util.py
|
@ -82,12 +82,12 @@ def parmap(f, it, parallel=False):
|
|||
# https://docs.python.org/2/library/pickle.html#what-can-be-pickled-and-unpickled
|
||||
#from cPickle import PicklingError
|
||||
#try:
|
||||
# p = multiprocessing.Pool(nproc)
|
||||
# l_res = p.map(f, it,nproc)
|
||||
# p = multiprocessing.Pool(nproc)
|
||||
# l_res = p.map(f, it,nproc)
|
||||
#except PicklingError:
|
||||
# pass
|
||||
# pass
|
||||
#else:
|
||||
# return l_res
|
||||
# return l_res
|
||||
|
||||
# ~!~!~!
|
||||
# Parallelisation By Us
|
||||
|
@ -127,8 +127,8 @@ def parmap(f, it, parallel=False):
|
|||
result = F(x)
|
||||
except BaseException as e:
|
||||
t = e
|
||||
else:
|
||||
t = (i, result)
|
||||
else:
|
||||
t = (i, result)
|
||||
|
||||
q_out.put(t)
|
||||
q_in.task_done()
|
||||
|
@ -162,8 +162,8 @@ def parmap(f, it, parallel=False):
|
|||
from itertools import ifilter
|
||||
e = next(ifilter(lambda t: isinstance(t,BaseException), l_res))
|
||||
except StopIteration:
|
||||
# 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]
|
||||
# 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]
|
||||
else:
|
||||
raise e
|
||||
|
||||
|
|
Loading…
Reference in New Issue