mirror of
https://gitlab.com/scemama/irpf90.git
synced 2024-12-22 04:13:33 +01:00
Loop pattern substitutions
Version:1.2.3
This commit is contained in:
parent
fc531fe0d2
commit
c08a0c7ab4
@ -13,6 +13,15 @@ END_PROVIDER
|
|||||||
BEGIN_PROVIDER [ integer, u1 ]
|
BEGIN_PROVIDER [ integer, u1 ]
|
||||||
integer :: fu
|
integer :: fu
|
||||||
u1 = fu(d1,d2)
|
u1 = fu(d1,d2)
|
||||||
|
integer :: n, m
|
||||||
|
n=3
|
||||||
|
do i=1,n
|
||||||
|
print *, i
|
||||||
|
enddo
|
||||||
|
m=2
|
||||||
|
do i=1,m
|
||||||
|
print *, i
|
||||||
|
enddo
|
||||||
PROVIDE u2
|
PROVIDE u2
|
||||||
END_PROVIDER
|
END_PROVIDER
|
||||||
|
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
import getopt, sys
|
import getopt, sys
|
||||||
from version import version
|
from version import version
|
||||||
|
import re
|
||||||
|
|
||||||
description = "IRPF90 Fortran preprocessor."
|
description = "IRPF90 Fortran preprocessor."
|
||||||
options = {}
|
options = {}
|
||||||
@ -42,6 +43,7 @@ options['t'] = [ 'touch' , 'Display which entities are touched', 1 ]
|
|||||||
options['m'] = [ 'memory' , 'Debug memory info', 0 ]
|
options['m'] = [ 'memory' , 'Debug memory info', 0 ]
|
||||||
options['z'] = [ 'openmp' , 'Automatic openMP tasks (may not work)', 0 ]
|
options['z'] = [ 'openmp' , 'Automatic openMP tasks (may not work)', 0 ]
|
||||||
options['l'] = [ 'align' , 'Align arrays using compiler directives', 1 ]
|
options['l'] = [ 'align' , 'Align arrays using compiler directives', 1 ]
|
||||||
|
options['s'] = [ 'substitute' , 'Substitute values for loop max values', 1 ]
|
||||||
options['r'] = [ 'no_directives', 'Ignore compiler directives !DEC$ and !DIR$', 0 ]
|
options['r'] = [ 'no_directives', 'Ignore compiler directives !DEC$ and !DIR$', 0 ]
|
||||||
|
|
||||||
class CommandLine(object):
|
class CommandLine(object):
|
||||||
@ -61,6 +63,17 @@ class CommandLine(object):
|
|||||||
return self._defined
|
return self._defined
|
||||||
defined = property(fget=defined)
|
defined = property(fget=defined)
|
||||||
|
|
||||||
|
def substituted(self):
|
||||||
|
if '_substituted' not in self.__dict__:
|
||||||
|
self._substituted = {}
|
||||||
|
for o,a in self.opts:
|
||||||
|
if o in [ "-s", '--'+options['s'][0] ]:
|
||||||
|
k, v = a.split(':')
|
||||||
|
v_re = re.compile(r"(^.*[,| ]+)(%s)(\s*$)"%k.strip())
|
||||||
|
self._substituted[k] = [v, v_re]
|
||||||
|
return self._substituted
|
||||||
|
substituted = property(fget=substituted)
|
||||||
|
|
||||||
def preprocessed(self):
|
def preprocessed(self):
|
||||||
if '_preprocessed' not in self.__dict__:
|
if '_preprocessed' not in self.__dict__:
|
||||||
self._preprocessed = []
|
self._preprocessed = []
|
||||||
|
@ -30,7 +30,7 @@ from irpf90_t import *
|
|||||||
from variables import variables
|
from variables import variables
|
||||||
from preprocessed_text import preprocessed_text
|
from preprocessed_text import preprocessed_text
|
||||||
from subroutines import subroutines
|
from subroutines import subroutines
|
||||||
import regexps
|
import regexps, re
|
||||||
import error
|
import error
|
||||||
|
|
||||||
vtuple = map(lambda v: (v, variables[v].same_as, variables[v].regexp), variables.keys())
|
vtuple = map(lambda v: (v, variables[v].same_as, variables[v].regexp), variables.keys())
|
||||||
@ -505,10 +505,28 @@ def check_opt():
|
|||||||
do_level -= 1
|
do_level -= 1
|
||||||
check_opt()
|
check_opt()
|
||||||
|
|
||||||
|
######################################################################
|
||||||
|
def perform_loop_substitutions():
|
||||||
|
main_result = []
|
||||||
|
for filename, text in parsed_text:
|
||||||
|
result = []
|
||||||
|
append = result.append
|
||||||
|
for vars,line in text:
|
||||||
|
if type(line) == Do:
|
||||||
|
for k,v in command_line.substituted.items():
|
||||||
|
reg = v[1]
|
||||||
|
if reg.search(line.text) is not None:
|
||||||
|
line.text = re.sub(reg,r'\1%s\3', line.text)%v[0]
|
||||||
|
append( (vars,line) )
|
||||||
|
main_result.append( (filename, result) )
|
||||||
|
return main_result
|
||||||
|
|
||||||
|
parsed_text = perform_loop_substitutions()
|
||||||
|
|
||||||
######################################################################
|
######################################################################
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
for i in range(len(parsed_text)):
|
for i in range(len(parsed_text)):
|
||||||
if parsed_text[i][0] == 'psi.irp.f':
|
# if parsed_text[i][0] == 'psi.irp.f':
|
||||||
print '!-------- %s -----------'%(parsed_text[i][0])
|
print '!-------- %s -----------'%(parsed_text[i][0])
|
||||||
for line in parsed_text[i][1]:
|
for line in parsed_text[i][1]:
|
||||||
print line[1]
|
print line[1]
|
||||||
|
@ -1 +1 @@
|
|||||||
version = "1.2.2"
|
version = "1.2.3"
|
||||||
|
Loading…
Reference in New Issue
Block a user