mirror of
https://gitlab.com/scemama/irpf90.git
synced 2024-11-09 07:33:43 +01:00
Merge branch 'master' of ssh://git.code.sf.net/p/irpf90/code
* 'master' of ssh://git.code.sf.net/p/irpf90/code: (23 commits) IRPF90_MAKE variable Gitignore file added Error messages cleaned Compile external sources first Compile first external sources support for recursive subroutines in indent Added support of documentation of subroutines and functions Added irpf90_indent Add tags for vi navigation Forgot to remove debug print Fixed man error in make Corrected bug with unexisting directories Added auto codelet generation Forgot file Added autocompletion in irpman Fixed bug with Cython Added -I option Work to do Added man pages Bug with += ...
This commit is contained in:
commit
7a4b8cb8dc
6
Makefile
6
Makefile
@ -1,10 +1,10 @@
|
|||||||
.PHONY: all src man
|
.PHONY: all src man
|
||||||
|
|
||||||
all: src man
|
|
||||||
|
|
||||||
src:
|
src:
|
||||||
$(MAKE) -C $@
|
$(MAKE) -C $@
|
||||||
|
|
||||||
man:
|
man:
|
||||||
$(MAKE) -C $@
|
- $(MAKE) -C $@
|
||||||
|
|
||||||
|
all: src man
|
||||||
|
|
||||||
|
6
README
6
README
@ -7,7 +7,7 @@ Dependencies
|
|||||||
|
|
||||||
- GNU make (>= 3.81 recommended)
|
- GNU make (>= 3.81 recommended)
|
||||||
- Python > 2.3
|
- Python > 2.3
|
||||||
- Any Fortran 90 compiler (Intel recommended, for example)
|
- Any Fortran 90 compiler (Intel recommended)
|
||||||
|
|
||||||
Installing IRPF90
|
Installing IRPF90
|
||||||
-----------------
|
-----------------
|
||||||
@ -19,7 +19,9 @@ ${IRPF90_HOME} is the location of your irpf90 directory::
|
|||||||
cat << EOF >> ${HOME}/.bash_profile
|
cat << EOF >> ${HOME}/.bash_profile
|
||||||
export PYTHONPATH=${IRPF90_HOME}/src:${PYTHONPATH}
|
export PYTHONPATH=${IRPF90_HOME}/src:${PYTHONPATH}
|
||||||
export PATH=${IRPF90_HOME}/bin:${PATH}
|
export PATH=${IRPF90_HOME}/bin:${PATH}
|
||||||
|
export MANPATH=${IRPF90_HOME}/man:${MANPATH}
|
||||||
EOF
|
EOF
|
||||||
|
. ${HOME}/.bash_profile
|
||||||
|
|
||||||
|
|
||||||
Using IRPF90
|
Using IRPF90
|
||||||
@ -42,6 +44,6 @@ Author
|
|||||||
------
|
------
|
||||||
|
|
||||||
| Anthony Scemama, LCPQ-IRSAMC, CNRS-Universite Paul Sabatier
|
| Anthony Scemama, LCPQ-IRSAMC, CNRS-Universite Paul Sabatier
|
||||||
| scemama@irsamc.ups-tlse.fr
|
| <scemama@irsamc.ups-tlse.fr>
|
||||||
| http://scemama.mooo.com
|
| http://scemama.mooo.com
|
||||||
|
|
||||||
|
@ -1 +1 @@
|
|||||||
../src/irpf90.exe
|
../src/irpf90_python.exe
|
40
bin/irpf90_indent
Executable file
40
bin/irpf90_indent
Executable file
@ -0,0 +1,40 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# IRPF90 is a Fortran90 preprocessor written in Python for programming using
|
||||||
|
# the Implicit Reference to Parameters (IRP) method.
|
||||||
|
# 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
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License along
|
||||||
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
#
|
||||||
|
# Anthony Scemama
|
||||||
|
# LCPQ - IRSAMC - CNRS
|
||||||
|
# Universite Paul Sabatier
|
||||||
|
# 118, route de Narbonne
|
||||||
|
# 31062 Toulouse Cedex 4
|
||||||
|
# scemama@irsamc.ups-tlse.fr
|
||||||
|
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
wd = os.path.abspath(os.path.dirname(__file__))
|
||||||
|
sys.path.insert(0,(wd+"/../src/"))
|
||||||
|
sys.path.insert(0,(wd+"/../share/irpf90/src/"))
|
||||||
|
|
||||||
|
def main():
|
||||||
|
import irpf90_indent
|
||||||
|
irpf90_indent.main()
|
||||||
|
|
||||||
|
main()
|
||||||
|
|
36
bin/irpman
36
bin/irpman
@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/python
|
#!/bin/bash
|
||||||
# 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
|
||||||
@ -24,19 +24,25 @@
|
|||||||
# 31062 Toulouse Cedex 4
|
# 31062 Toulouse Cedex 4
|
||||||
# scemama@irsamc.ups-tlse.fr
|
# scemama@irsamc.ups-tlse.fr
|
||||||
|
|
||||||
|
# Define auto-completion for bash
|
||||||
|
|
||||||
import os
|
case "$0" in
|
||||||
import sys
|
*bash*)
|
||||||
|
_irpman_complete()
|
||||||
wd = os.path.abspath(os.path.dirname(__file__))
|
{
|
||||||
sys.path.insert(0,(wd+"/../src/"))
|
local cur
|
||||||
sys.path.insert(0,(wd+"/../share/irpf90/src/"))
|
COMPREPLY=()
|
||||||
|
cur=${COMP_WORDS[COMP_CWORD]}
|
||||||
if len(sys.argv) != 2:
|
COMPREPLY=( $(compgen -W "`cat tags | cut -d' ' -f 1`" -- "$cur" ) )
|
||||||
print "Usage:"
|
} && complete -F _irpman_complete irpman
|
||||||
print sys.argv[0]+" <irp_variable>"
|
;;
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
from irpf90_t import mandir
|
|
||||||
os.system("man ./"+mandir+sys.argv[1].lower()+".l")
|
|
||||||
|
|
||||||
|
*)
|
||||||
|
if [[ -z $1 ]] ; then
|
||||||
|
echo "To activate auto-completion in bash:"
|
||||||
|
echo "source " $0
|
||||||
|
else
|
||||||
|
python $(dirname $0)/../src/irpman.py $1
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
IRPF90 = ~/irpf90/bin/irpf90 -a -d
|
IRPF90 = python ../src/irpf90.py -I input -a -d
|
||||||
FC = gfortran
|
FC = gfortran
|
||||||
FCFLAGS= -O2
|
FCFLAGS= -O2
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@ BEGIN_PROVIDER [ integer, u2 ]
|
|||||||
integer :: fu
|
integer :: fu
|
||||||
! u2 = fu(d3,d4)
|
! u2 = fu(d3,d4)
|
||||||
u2 = d3+d4+1
|
u2 = d3+d4+1
|
||||||
|
ASSERT (u2 > d3)
|
||||||
END_PROVIDER
|
END_PROVIDER
|
||||||
|
|
||||||
integer function fu(x,y)
|
integer function fu(x,y)
|
||||||
|
Binary file not shown.
@ -1,5 +1,5 @@
|
|||||||
include version
|
include version
|
||||||
default:
|
default: version
|
||||||
set -x
|
set -x
|
||||||
NAME=irpf90-$(VERSION)-noarch-src.tar.gz ;\
|
NAME=irpf90-$(VERSION)-noarch-src.tar.gz ;\
|
||||||
cd ..;\
|
cd ..;\
|
||||||
|
@ -1,13 +1,10 @@
|
|||||||
PYTHON=python
|
PYTHON=python
|
||||||
PYVERSION=$(shell $(PYTHON) -c "import sys; print(sys.version[:3])")
|
PYVERSION=$(shell $(PYTHON) -c "import sys; print(sys.version[:3])")
|
||||||
HAS_CYTHON=$(shell which cython &> /dev/null && echo 1 || echo 0)
|
HAS_CYTHON=$(shell bash -c "which cython &> /dev/null && echo 1 || echo 0")
|
||||||
ifneq ($(HAS_CYTHON),0)
|
ifneq ($(HAS_CYTHON),0)
|
||||||
|
|
||||||
../bin/irpf90: irpf90.exe
|
../bin/irpf90: irpf90.so
|
||||||
rm ../bin/irpf90 ; cd ../bin ; ln -s ../src/irpf90.exe irpf90
|
rm ../bin/irpf90 ; cd ../bin ; ln -s ../src/irpf90_python.exe irpf90
|
||||||
|
|
||||||
irpf90.exe: irpf90.so
|
|
||||||
gcc build/*/irpf90.o -L/usr/lib64 -lpython$(PYVERSION) -o irpf90.exe
|
|
||||||
|
|
||||||
irpf90.so : $(wildcard *.py) irpf90.c
|
irpf90.so : $(wildcard *.py) irpf90.c
|
||||||
./cython_setup.py build_ext --inplace
|
./cython_setup.py build_ext --inplace
|
||||||
|
45
src/codelet.py
Normal file
45
src/codelet.py
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
from command_line import command_line
|
||||||
|
import irpf90_t
|
||||||
|
|
||||||
|
def run():
|
||||||
|
template = """
|
||||||
|
program codelet_%(name)s
|
||||||
|
implicit none
|
||||||
|
integer :: i
|
||||||
|
double precision :: ticks_0, ticks_1, cpu_0, cpu_1
|
||||||
|
integer, parameter :: irp_imax = %(NMAX)d
|
||||||
|
|
||||||
|
%(precondition)s
|
||||||
|
|
||||||
|
call provide_%(name)s
|
||||||
|
|
||||||
|
double precision :: irp_rdtsc
|
||||||
|
|
||||||
|
call cpu_time(cpu_0)
|
||||||
|
ticks_0 = irp_rdtsc()
|
||||||
|
do i=1,irp_imax
|
||||||
|
call bld_%(name)s
|
||||||
|
enddo
|
||||||
|
ticks_1 = irp_rdtsc()
|
||||||
|
call cpu_time(cpu_1)
|
||||||
|
print *, '%(name)s'
|
||||||
|
print *, '-----------'
|
||||||
|
print *, 'Cycles:'
|
||||||
|
print *, (ticks_1-ticks_0)/dble(irp_imax)
|
||||||
|
print *, 'Seconds:'
|
||||||
|
print *, (cpu_1-cpu_0)/dble(irp_imax)
|
||||||
|
end
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
name, NMAX, precondition, filename = command_line.codelet
|
||||||
|
if precondition is None:
|
||||||
|
precondition = ""
|
||||||
|
else:
|
||||||
|
precondition = "PROVIDE "+precondition
|
||||||
|
file = open(filename,'w')
|
||||||
|
file.write(template%locals())
|
||||||
|
file.close()
|
||||||
|
|
||||||
|
|
@ -48,9 +48,12 @@ options['s'] = [ 'substitute' , 'Substitute values in do loops for generating
|
|||||||
options['r'] = [ 'no_directives', 'Ignore all compiler directives !DEC$ and !DIR$', 0 ]
|
options['r'] = [ 'no_directives', 'Ignore all compiler directives !DEC$ and !DIR$', 0 ]
|
||||||
options['n'] = [ 'inline' , 'all|providers|builders : Force inlining of providers or builders', 1 ]
|
options['n'] = [ 'inline' , 'all|providers|builders : Force inlining of providers or builders', 1 ]
|
||||||
options['u'] = [ 'unused' , 'Print unused providers', 0 ]
|
options['u'] = [ 'unused' , 'Print unused providers', 0 ]
|
||||||
|
options['I'] = [ 'include' , 'Include directory', 1 ]
|
||||||
|
options['c'] = [ 'codelet' , 'entity:NMAX or entity:precondition:NMAX : Generate a codelet to profile a provider running NMAX times', 1 ]
|
||||||
|
|
||||||
class CommandLine(object):
|
class CommandLine(object):
|
||||||
|
|
||||||
|
do_openmp = False
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
global options
|
global options
|
||||||
self._opts = None
|
self._opts = None
|
||||||
@ -66,6 +69,19 @@ class CommandLine(object):
|
|||||||
return self._defined
|
return self._defined
|
||||||
defined = property(fget=defined)
|
defined = property(fget=defined)
|
||||||
|
|
||||||
|
def include_dir(self):
|
||||||
|
if '_include_dir' not in self.__dict__:
|
||||||
|
self._include_dir = []
|
||||||
|
for o,a in self.opts:
|
||||||
|
if o in [ "-I", '--'+options['I'][0] ]:
|
||||||
|
if len(a) < 1:
|
||||||
|
print "Error: -I option needs a directory"
|
||||||
|
if a[-1] != '/':
|
||||||
|
a = a+'/'
|
||||||
|
self._include_dir.append(a)
|
||||||
|
return self._include_dir
|
||||||
|
include_dir = property(fget=include_dir)
|
||||||
|
|
||||||
def inline(self):
|
def inline(self):
|
||||||
if '_inline' not in self.__dict__:
|
if '_inline' not in self.__dict__:
|
||||||
self._inline = ""
|
self._inline = ""
|
||||||
@ -87,6 +103,28 @@ class CommandLine(object):
|
|||||||
return self._substituted
|
return self._substituted
|
||||||
substituted = property(fget=substituted)
|
substituted = property(fget=substituted)
|
||||||
|
|
||||||
|
def codelet(self):
|
||||||
|
if '_codelet' not in self.__dict__:
|
||||||
|
self._codelet = []
|
||||||
|
for o,a in self.opts:
|
||||||
|
if o in [ "-c", '--'+options['c'][0] ]:
|
||||||
|
buffer = a.split(':')
|
||||||
|
filename = 'codelet_'+buffer[0]+'.irp.f'
|
||||||
|
if len(buffer) == 2:
|
||||||
|
self._codelet = [buffer[0], int(buffer[1]), None, filename]
|
||||||
|
elif len(buffer) == 3:
|
||||||
|
self._codelet = [buffer[0], int(buffer[2]), buffer[1], filename]
|
||||||
|
else:
|
||||||
|
print """
|
||||||
|
Error in codelet definition. Use:
|
||||||
|
--codelet=provider:NMAX
|
||||||
|
or
|
||||||
|
--codelet=provider:precondition:NMAX
|
||||||
|
"""
|
||||||
|
sys.exit(1)
|
||||||
|
return self._codelet
|
||||||
|
codelet = property(fget=codelet)
|
||||||
|
|
||||||
def preprocessed(self):
|
def preprocessed(self):
|
||||||
if '_preprocessed' not in self.__dict__:
|
if '_preprocessed' not in self.__dict__:
|
||||||
self._preprocessed = []
|
self._preprocessed = []
|
||||||
|
@ -27,6 +27,8 @@
|
|||||||
|
|
||||||
from variable import Variable
|
from variable import Variable
|
||||||
from variables import variables
|
from variables import variables
|
||||||
|
from subroutine import Sub
|
||||||
|
from subroutines import subroutines
|
||||||
from irpf90_t import *
|
from irpf90_t import *
|
||||||
from util import *
|
from util import *
|
||||||
|
|
||||||
@ -93,6 +95,46 @@ def do_print(var):
|
|||||||
process_deps(file,var.needed_by)
|
process_deps(file,var.needed_by)
|
||||||
file.close()
|
file.close()
|
||||||
|
|
||||||
|
######################################################################
|
||||||
|
def process_declaration_subroutine(file, sub):
|
||||||
|
print >>file, sub.line.text.split('!')[0].strip()
|
||||||
|
|
||||||
|
# for line in sub.text:
|
||||||
|
######################################################################
|
||||||
|
def do_print_subroutines(sub):
|
||||||
|
assert type(sub) == Sub
|
||||||
|
filename = sub.line.filename
|
||||||
|
name = sub.name
|
||||||
|
file = open("%s%s.l"%(mandir,sub.name), "w")
|
||||||
|
print >>file, '.TH "IRPF90 entities" l %s "IRPF90 entities" %s'%(name,name)
|
||||||
|
print >>file, ".SH Declaration"
|
||||||
|
print >>file, ".nf"
|
||||||
|
process_declaration_subroutine(file,sub)
|
||||||
|
print >>file, ".ni"
|
||||||
|
if sub.doc != []:
|
||||||
|
print >>file, ".SH Description"
|
||||||
|
for l in sub.doc:
|
||||||
|
process_doc(file,l)
|
||||||
|
print >>file, ".SH File\n.P"
|
||||||
|
print >>file, filename
|
||||||
|
if sub.needs != []:
|
||||||
|
sub.needs.sort()
|
||||||
|
print >>file, ".SH Needs"
|
||||||
|
process_deps(file,sub.needs)
|
||||||
|
if sub.called_by != []:
|
||||||
|
sub.called_by.sort()
|
||||||
|
print >>file, ".SH Called by"
|
||||||
|
process_deps(file,sub.called_by)
|
||||||
|
if sub.calls != []:
|
||||||
|
sub.calls.sort()
|
||||||
|
print >>file, ".SH Calls"
|
||||||
|
process_deps(file,sub.calls)
|
||||||
|
if sub.touches != []:
|
||||||
|
sub.touches.sort()
|
||||||
|
print >>file, ".SH Touches"
|
||||||
|
process_deps(file,sub.touches)
|
||||||
|
file.close()
|
||||||
|
|
||||||
######################################################################
|
######################################################################
|
||||||
def run():
|
def run():
|
||||||
import parsed_text
|
import parsed_text
|
||||||
@ -100,14 +142,28 @@ def run():
|
|||||||
if os.fork() == 0:
|
if os.fork() == 0:
|
||||||
for v in variables.values():
|
for v in variables.values():
|
||||||
do_print(v)
|
do_print(v)
|
||||||
|
for s in subroutines.values():
|
||||||
|
do_print_subroutines(s)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
if os.fork() == 0:
|
if os.fork() == 0:
|
||||||
|
tags = []
|
||||||
l = variables.keys()
|
l = variables.keys()
|
||||||
file = open("irpf90_entities","w")
|
file = open("irpf90_entities","w")
|
||||||
l.sort()
|
l.sort()
|
||||||
for v in l:
|
for v in l:
|
||||||
do_print_short(file,variables[v])
|
do_print_short(file,variables[v])
|
||||||
|
line = variables[v].line
|
||||||
|
tags.append( '%s\t%s\t/%s/;"\n'%(v,line.filename[0],line.text.split('!')[0].strip()) )
|
||||||
|
file.close()
|
||||||
|
l = subroutines.keys()
|
||||||
|
for v in l:
|
||||||
|
line = subroutines[v].line
|
||||||
|
tags.append('%s\t%s\t/%s/;"\n'%(v,line.filename,line.text.split('!')[0].strip()))
|
||||||
|
tags.sort()
|
||||||
|
file = open("tags","w")
|
||||||
|
for line in tags:
|
||||||
|
file.write(line)
|
||||||
file.close()
|
file.close()
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
26
src/init.py
26
src/init.py
@ -30,6 +30,7 @@ import os
|
|||||||
import util
|
import util
|
||||||
import makefile
|
import makefile
|
||||||
import irpf90_t
|
import irpf90_t
|
||||||
|
from command_line import command_line
|
||||||
|
|
||||||
initialized = False
|
initialized = False
|
||||||
|
|
||||||
@ -49,23 +50,36 @@ def init():
|
|||||||
except OSError:
|
except OSError:
|
||||||
os.mkdir(dir)
|
os.mkdir(dir)
|
||||||
|
|
||||||
|
for dir in command_line.include_dir:
|
||||||
|
dir = irpf90_t.irpdir+dir
|
||||||
|
try:
|
||||||
|
wd = os.getcwd()
|
||||||
|
os.chdir(dir)
|
||||||
|
os.chdir(wd)
|
||||||
|
except OSError:
|
||||||
|
os.mkdir(dir)
|
||||||
|
|
||||||
# Create makefile
|
# Create makefile
|
||||||
makefile.create()
|
makefile.create()
|
||||||
|
|
||||||
# Copy current files in the irpdir
|
# Copy current files in the irpdir
|
||||||
for filename in os.listdir(os.getcwd()):
|
for dir in ['./']+command_line.include_dir:
|
||||||
if not filename[0].startswith(".") and not os.path.isdir(filename):
|
try:
|
||||||
|
os.stat(dir)
|
||||||
|
except:
|
||||||
|
print dir,'not in dir'
|
||||||
|
continue
|
||||||
|
for filename in os.listdir(dir):
|
||||||
|
filename = dir+filename
|
||||||
|
if not filename.startswith(".") and not os.path.isdir(filename):
|
||||||
try:
|
try:
|
||||||
file = open(filename,"r")
|
file = open(filename,"r")
|
||||||
except IOError:
|
except IOError:
|
||||||
print "Warning : Unable to read file %s."%(filename)
|
print "Warning : Unable to read file %s."%(filename)
|
||||||
else:
|
else:
|
||||||
buffer = file.readlines()
|
|
||||||
file.close()
|
|
||||||
if not util.same_file(irpf90_t.irpdir+filename,buffer):
|
|
||||||
file = open(filename,"r")
|
|
||||||
buffer = file.read()
|
buffer = file.read()
|
||||||
file.close()
|
file.close()
|
||||||
|
if not util.same_file(irpf90_t.irpdir+filename,buffer):
|
||||||
file = open(irpf90_t.irpdir+filename,"w")
|
file = open(irpf90_t.irpdir+filename,"w")
|
||||||
file.write(buffer)
|
file.write(buffer)
|
||||||
file.close()
|
file.close()
|
||||||
|
@ -35,8 +35,9 @@ except:
|
|||||||
pass
|
pass
|
||||||
sys.setcheckinterval(1000)
|
sys.setcheckinterval(1000)
|
||||||
|
|
||||||
|
from command_line import command_line
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
from command_line import command_line
|
|
||||||
|
|
||||||
vim.install()
|
vim.install()
|
||||||
|
|
||||||
@ -72,10 +73,15 @@ def main():
|
|||||||
for x in parents:
|
for x in parents:
|
||||||
print "- %s"%(x,)
|
print "- %s"%(x,)
|
||||||
|
|
||||||
|
if command_line.do_codelet:
|
||||||
|
import profile
|
||||||
|
profile.build_rdtsc()
|
||||||
|
import codelet
|
||||||
|
codelet.run()
|
||||||
|
|
||||||
if not command_line.do_run:
|
if not command_line.do_run:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
init()
|
init()
|
||||||
|
|
||||||
import irp_stack
|
import irp_stack
|
||||||
@ -102,3 +108,4 @@ def main():
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
247
src/irpf90_indent.py
Executable file
247
src/irpf90_indent.py
Executable file
@ -0,0 +1,247 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import re
|
||||||
|
|
||||||
|
LENMAX = 70
|
||||||
|
tabn = 2
|
||||||
|
tab = " "*tabn
|
||||||
|
|
||||||
|
class Grep(object):
|
||||||
|
|
||||||
|
re_begin_program = re.compile(r"^\s*program\s",flags=re.I)
|
||||||
|
def begin_program(self,string):
|
||||||
|
return re.match(self.re_begin_program,string) is not None
|
||||||
|
|
||||||
|
re_end_program = re.compile(r"\s*(end\s*!?$|end\s*program)",flags=re.I)
|
||||||
|
def end_program(self,string):
|
||||||
|
return re.match(self.re_end_program,string) is not None
|
||||||
|
|
||||||
|
re_begin_subroutine = re.compile(r"^\s*(recursive)?\s*subroutine\s",flags=re.I)
|
||||||
|
def begin_subroutine(self,string):
|
||||||
|
return re.match(self.re_begin_subroutine,string) is not None
|
||||||
|
|
||||||
|
re_end_subroutine = re.compile(r"\s*(end\s*!?$|end\s*subroutine)",flags=re.I)
|
||||||
|
def end_subroutine(self,string):
|
||||||
|
return re.match(self.re_end_subroutine,string) is not None
|
||||||
|
|
||||||
|
re_begin_function = re.compile(r"^.*function\s+.*\(",flags=re.I)
|
||||||
|
def begin_function(self,string):
|
||||||
|
return re.match(self.re_begin_function,string) is not None
|
||||||
|
|
||||||
|
re_end_function = re.compile(r"\s*(end\s*!?$|end\s*function)",flags=re.I)
|
||||||
|
def end_function(self,string):
|
||||||
|
return re.match(self.re_end_function,string) is not None
|
||||||
|
|
||||||
|
re_begin_provider = re.compile(r"^\s*&?begin_provider\s",flags=re.I)
|
||||||
|
def begin_provider(self,string):
|
||||||
|
return re.match(self.re_begin_provider,string) is not None
|
||||||
|
|
||||||
|
re_end_provider = re.compile(r"^\s*end_provider\s*(!.*)?$", flags=re.I)
|
||||||
|
def end_provider(self,string):
|
||||||
|
return re.match(self.re_end_provider,string) is not None
|
||||||
|
|
||||||
|
re_begin_do = re.compile(r"^\s*do\s+",flags=re.I)
|
||||||
|
def begin_do(self,string):
|
||||||
|
return re.match(self.re_begin_do,string) is not None
|
||||||
|
|
||||||
|
re_end_do = re.compile(r"^\s*end\s*do\s*(!.*)?$",flags=re.I)
|
||||||
|
def end_do(self,string):
|
||||||
|
return re.match(self.re_end_do,string) is not None
|
||||||
|
|
||||||
|
re_begin_if = re.compile(r"^\s*if(\(|\s+).*(&|then)\s*(!.*)?$",flags=re.I)
|
||||||
|
def begin_if(self,string):
|
||||||
|
return re.match(self.re_begin_if,string) is not None
|
||||||
|
|
||||||
|
re_else = re.compile(r"^\s*else",flags=re.I)
|
||||||
|
def xelse(self,string):
|
||||||
|
return re.match(self.re_else,string) is not None
|
||||||
|
|
||||||
|
re_end_if = re.compile(r"^\s*end\s*if\s*(!.*)?$",flags=re.I)
|
||||||
|
def end_if(self,string):
|
||||||
|
return re.match(self.re_end_if,string) is not None
|
||||||
|
|
||||||
|
re_begin_select = re.compile(r"^\s*select\s*case",flags=re.I)
|
||||||
|
def begin_select(self,string):
|
||||||
|
return re.match(self.re_begin_select,string) is not None
|
||||||
|
|
||||||
|
re_case = re.compile(r"^\s*case\s*\(",flags=re.I)
|
||||||
|
def case(self,string):
|
||||||
|
return re.match(self.re_case,string) is not None
|
||||||
|
|
||||||
|
re_end_select = re.compile(r"^\s*end\s*select\s*(!.*)?$",flags=re.I)
|
||||||
|
def end_select(self,string):
|
||||||
|
return re.match(self.re_end_select,string) is not None
|
||||||
|
|
||||||
|
re_continuation = re.compile(r"^\s*\S+.*&")
|
||||||
|
def continuation(self,string):
|
||||||
|
return re.match(self.re_continuation,string) is not None
|
||||||
|
|
||||||
|
re_declaration = re.compile(r"^.*::.*$")
|
||||||
|
def declaration(self,string):
|
||||||
|
return re.match(self.re_declaration,string) is not None
|
||||||
|
|
||||||
|
grep = Grep()
|
||||||
|
|
||||||
|
class indent(object):
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
"""Run the program"""
|
||||||
|
self.run()
|
||||||
|
|
||||||
|
def format_declaration(self,string,n):
|
||||||
|
l,r = string.split('::')
|
||||||
|
return l.strip().ljust(n) + ' :: '+ r.strip()
|
||||||
|
|
||||||
|
def format_continuation(self,string,n):
|
||||||
|
buffer = string.split('&')
|
||||||
|
if len(buffer) == 1:
|
||||||
|
l = buffer[0]
|
||||||
|
return l
|
||||||
|
else:
|
||||||
|
l, r = buffer
|
||||||
|
return l.strip().ljust(69-len(n)) + '&'+ r.strip()
|
||||||
|
|
||||||
|
def get_filename(self):
|
||||||
|
"""The file name is the first argument"""
|
||||||
|
if '_filename' not in self.__dict__:
|
||||||
|
try:
|
||||||
|
self._filename = sys.argv[1]
|
||||||
|
except:
|
||||||
|
self._filename = None
|
||||||
|
return self._filename
|
||||||
|
filename=property(fget=get_filename)
|
||||||
|
|
||||||
|
def get_text(self):
|
||||||
|
"""The text of the file is a list of lines"""
|
||||||
|
if '_text' not in self.__dict__:
|
||||||
|
if self.filename is not None:
|
||||||
|
f = open(self.filename,'r')
|
||||||
|
self._text = f.read().splitlines()
|
||||||
|
f.close()
|
||||||
|
else:
|
||||||
|
self._text = sys.stdin.read().splitlines()
|
||||||
|
return self._text
|
||||||
|
text=property(fget=get_text)
|
||||||
|
|
||||||
|
def indentlevel(self,line):
|
||||||
|
line = line.rstrip()
|
||||||
|
k=0
|
||||||
|
if len(line) > 0:
|
||||||
|
while line[k] == ' ':
|
||||||
|
k+=1
|
||||||
|
return k
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
lines = self.text
|
||||||
|
indent0 = " "*self.indentlevel(self.text[0])
|
||||||
|
k = indent0
|
||||||
|
line = ""
|
||||||
|
for i in range(len(self.text)):
|
||||||
|
prevline = line
|
||||||
|
line = self.text[i].strip()
|
||||||
|
if grep.continuation(line):
|
||||||
|
line = self.format_continuation(line,k)
|
||||||
|
|
||||||
|
if grep.continuation(prevline):
|
||||||
|
print k+2*tab+self.format_continuation(line,k+2*tab)
|
||||||
|
continue
|
||||||
|
|
||||||
|
if grep.begin_subroutine(line):
|
||||||
|
print line
|
||||||
|
k = indent0+tab
|
||||||
|
continue
|
||||||
|
|
||||||
|
if grep.begin_function(line):
|
||||||
|
print line
|
||||||
|
k = indent0+tab
|
||||||
|
continue
|
||||||
|
|
||||||
|
if grep.begin_program(line):
|
||||||
|
print line
|
||||||
|
k = indent0+tab
|
||||||
|
continue
|
||||||
|
|
||||||
|
if grep.begin_provider(line):
|
||||||
|
if line[0] != '&':
|
||||||
|
k = indent0+tab
|
||||||
|
if grep.begin_provider(self.text[i+1].strip()):
|
||||||
|
print " "+line
|
||||||
|
else:
|
||||||
|
print line
|
||||||
|
else:
|
||||||
|
print line
|
||||||
|
continue
|
||||||
|
|
||||||
|
if grep.declaration(line):
|
||||||
|
print k+self.format_declaration(line,30)
|
||||||
|
continue
|
||||||
|
|
||||||
|
if grep.begin_do(line):
|
||||||
|
print k+line
|
||||||
|
k += tab
|
||||||
|
continue
|
||||||
|
|
||||||
|
if grep.begin_if(line):
|
||||||
|
print k+line
|
||||||
|
k += tab
|
||||||
|
continue
|
||||||
|
|
||||||
|
if grep.xelse(line):
|
||||||
|
print k[:-tabn]+line
|
||||||
|
continue
|
||||||
|
|
||||||
|
if grep.begin_select(line):
|
||||||
|
print k+line
|
||||||
|
k += 2*tab
|
||||||
|
continue
|
||||||
|
|
||||||
|
if grep.case(line):
|
||||||
|
print k[:-tabn]+line
|
||||||
|
continue
|
||||||
|
|
||||||
|
if grep.end_do(line):
|
||||||
|
k = k[:-tabn]
|
||||||
|
print k+line
|
||||||
|
continue
|
||||||
|
|
||||||
|
if grep.end_if(line):
|
||||||
|
k = k[:-tabn]
|
||||||
|
print k+line
|
||||||
|
continue
|
||||||
|
|
||||||
|
if grep.end_select(line):
|
||||||
|
k = k[:-2*tabn]
|
||||||
|
print k+line
|
||||||
|
continue
|
||||||
|
|
||||||
|
if grep.end_subroutine(line):
|
||||||
|
print line
|
||||||
|
k = indent0
|
||||||
|
continue
|
||||||
|
|
||||||
|
if grep.end_function(line):
|
||||||
|
print line
|
||||||
|
k = indent0
|
||||||
|
continue
|
||||||
|
|
||||||
|
if grep.end_provider(line):
|
||||||
|
print line
|
||||||
|
k = indent0
|
||||||
|
continue
|
||||||
|
|
||||||
|
if grep.end_program(line):
|
||||||
|
print line
|
||||||
|
k = indent0
|
||||||
|
continue
|
||||||
|
|
||||||
|
print k+line
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
indent()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
|
|
@ -54,286 +54,329 @@ class Line(object):
|
|||||||
lower = property(fget=get_lower)
|
lower = property(fget=get_lower)
|
||||||
|
|
||||||
class Empty_line(Line):
|
class Empty_line(Line):
|
||||||
|
str="Empty_line"
|
||||||
def __init__(self,i,text,filename):
|
def __init__(self,i,text,filename):
|
||||||
Line.__init__(self,i,text,filename)
|
Line.__init__(self,i,text,filename)
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "%20s:%5d : %s"%("Empty_line",self.i,self.text)
|
return "%20s:%5d : %s"%("Empty_line",self.i,self.text)
|
||||||
|
|
||||||
class Simple_line(Line):
|
class Simple_line(Line):
|
||||||
|
str="Simple_line"
|
||||||
def __init__(self,i,text,filename):
|
def __init__(self,i,text,filename):
|
||||||
Line.__init__(self,i,text,filename)
|
Line.__init__(self,i,text,filename)
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "%20s:%5d : %s"%("Simple_line",self.i,self.text)
|
return "%20s:%5d : %s"%("Simple_line",self.i,self.text)
|
||||||
|
|
||||||
class Declaration(Line):
|
class Declaration(Line):
|
||||||
|
str="Declaration"
|
||||||
def __init__(self,i,text,filename):
|
def __init__(self,i,text,filename):
|
||||||
Line.__init__(self,i,text,filename)
|
Line.__init__(self,i,text,filename)
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "%20s:%5d : %s"%("Declaration",self.i,self.text)
|
return "%20s:%5d : %s"%("Declaration",self.i,self.text)
|
||||||
|
|
||||||
class Continue(Line):
|
class Continue(Line):
|
||||||
|
str="Continue"
|
||||||
def __init__(self,i,text,filename):
|
def __init__(self,i,text,filename):
|
||||||
Line.__init__(self,i,text,filename)
|
Line.__init__(self,i,text,filename)
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "%20s:%5d : %s"%("Continue",self.i,self.text)
|
return "%20s:%5d : %s"%("Continue",self.i,self.text)
|
||||||
|
|
||||||
class Begin_provider(Line):
|
class Begin_provider(Line):
|
||||||
str = "Provider"
|
str="Begin_provider"
|
||||||
def __init__(self,i,text,filename):
|
def __init__(self,i,text,filename):
|
||||||
Line.__init__(self,i,text,filename)
|
Line.__init__(self,i,text,filename)
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "%20s:%5d : %s"%("Begin_provider",self.i,self.text)
|
return "%20s:%5d : %s"%("Begin_provider",self.i,self.text)
|
||||||
|
|
||||||
class Cont_provider(Line):
|
class Cont_provider(Line):
|
||||||
|
str="Cont_provider"
|
||||||
def __init__(self,i,text,filename):
|
def __init__(self,i,text,filename):
|
||||||
Line.__init__(self,i,text,filename)
|
Line.__init__(self,i,text,filename)
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "%20s:%5d : %s"%("Cont_provider",self.i,self.text)
|
return "%20s:%5d : %s"%("Cont_provider",self.i,self.text)
|
||||||
|
|
||||||
class End_provider(Line):
|
class End_provider(Line):
|
||||||
|
str="End_provider"
|
||||||
def __init__(self,i,text,filename):
|
def __init__(self,i,text,filename):
|
||||||
Line.__init__(self,i,text,filename)
|
Line.__init__(self,i,text,filename)
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "%20s:%5d : %s"%("End_provider",self.i,self.text)
|
return "%20s:%5d : %s"%("End_provider",self.i,self.text)
|
||||||
|
|
||||||
class Begin_doc(Line):
|
class Begin_doc(Line):
|
||||||
|
str="Begin_doc"
|
||||||
def __init__(self,i,text,filename):
|
def __init__(self,i,text,filename):
|
||||||
Line.__init__(self,i,text,filename)
|
Line.__init__(self,i,text,filename)
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "%20s:%5d : %s"%("Begin_doc",self.i,self.text)
|
return "%20s:%5d : %s"%("Begin_doc",self.i,self.text)
|
||||||
|
|
||||||
class Doc(Line):
|
class Doc(Line):
|
||||||
|
str="Doc"
|
||||||
def __init__(self,i,text,filename):
|
def __init__(self,i,text,filename):
|
||||||
Line.__init__(self,i,text,filename)
|
Line.__init__(self,i,text,filename)
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "%20s:%5d : %s"%("Doc",self.i,self.text)
|
return "%20s:%5d : %s"%("Doc",self.i,self.text)
|
||||||
|
|
||||||
class End_doc(Line):
|
class End_doc(Line):
|
||||||
|
str="End_doc"
|
||||||
def __init__(self,i,text,filename):
|
def __init__(self,i,text,filename):
|
||||||
Line.__init__(self,i,text,filename)
|
Line.__init__(self,i,text,filename)
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "%20s:%5d : %s"%("End_doc",self.i,self.text)
|
return "%20s:%5d : %s"%("End_doc",self.i,self.text)
|
||||||
|
|
||||||
class Begin_shell(Line):
|
class Begin_shell(Line):
|
||||||
|
str="Begin_shell"
|
||||||
def __init__(self,i,text,filename):
|
def __init__(self,i,text,filename):
|
||||||
Line.__init__(self,i,text,filename)
|
Line.__init__(self,i,text,filename)
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "%20s:%5d : %s"%("Begin_shell",self.i,self.text)
|
return "%20s:%5d : %s"%("Begin_shell",self.i,self.text)
|
||||||
|
|
||||||
class End_shell(Line):
|
class End_shell(Line):
|
||||||
|
str="End_shell"
|
||||||
def __init__(self,i,text,filename):
|
def __init__(self,i,text,filename):
|
||||||
Line.__init__(self,i,text,filename)
|
Line.__init__(self,i,text,filename)
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "%20s:%5d : %s"%("End_shell",self.i,self.text)
|
return "%20s:%5d : %s"%("End_shell",self.i,self.text)
|
||||||
|
|
||||||
class Begin_template(Line):
|
class Begin_template(Line):
|
||||||
|
str="Begin_template"
|
||||||
def __init__(self,i,text,filename):
|
def __init__(self,i,text,filename):
|
||||||
Line.__init__(self,i,text,filename)
|
Line.__init__(self,i,text,filename)
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "%20s:%5d : %s"%("Begin_template",self.i,self.text)
|
return "%20s:%5d : %s"%("Begin_template",self.i,self.text)
|
||||||
|
|
||||||
class End_template(Line):
|
class End_template(Line):
|
||||||
|
str="End_template"
|
||||||
def __init__(self,i,text,filename):
|
def __init__(self,i,text,filename):
|
||||||
Line.__init__(self,i,text,filename)
|
Line.__init__(self,i,text,filename)
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "%20s:%5d : %s"%("End_template",self.i,self.text)
|
return "%20s:%5d : %s"%("End_template",self.i,self.text)
|
||||||
|
|
||||||
class Subst(Line):
|
class Subst(Line):
|
||||||
|
str="Subst"
|
||||||
def __init__(self,i,text,filename):
|
def __init__(self,i,text,filename):
|
||||||
Line.__init__(self,i,text,filename)
|
Line.__init__(self,i,text,filename)
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "%20s:%5d : %s"%("Subst",self.i,self.text)
|
return "%20s:%5d : %s"%("Subst",self.i,self.text)
|
||||||
|
|
||||||
class Assert(Line):
|
class Assert(Line):
|
||||||
|
str="Assert"
|
||||||
def __init__(self,i,text,filename):
|
def __init__(self,i,text,filename):
|
||||||
Line.__init__(self,i,text,filename)
|
Line.__init__(self,i,text,filename)
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "%20s:%5d : %s"%("Assert",self.i,self.text)
|
return "%20s:%5d : %s"%("Assert",self.i,self.text)
|
||||||
|
|
||||||
class Touch(Line):
|
class Touch(Line):
|
||||||
|
str="Touch"
|
||||||
def __init__(self,i,text,filename):
|
def __init__(self,i,text,filename):
|
||||||
Line.__init__(self,i,text,filename)
|
Line.__init__(self,i,text,filename)
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "%20s:%5d : %s"%("Touch",self.i,self.text)
|
return "%20s:%5d : %s"%("Touch",self.i,self.text)
|
||||||
|
|
||||||
class SoftTouch(Touch):
|
class SoftTouch(Touch):
|
||||||
|
str="SoftTouch"
|
||||||
def __init__(self,i,text,filename):
|
def __init__(self,i,text,filename):
|
||||||
Line.__init__(self,i,text,filename)
|
Line.__init__(self,i,text,filename)
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "%20s:%5d : %s"%("SoftTouch",self.i,self.text)
|
return "%20s:%5d : %s"%("SoftTouch",self.i,self.text)
|
||||||
|
|
||||||
class Irp_read(Line):
|
class Irp_read(Line):
|
||||||
|
str="Irp_read"
|
||||||
def __init__(self,i,text,filename):
|
def __init__(self,i,text,filename):
|
||||||
Line.__init__(self,i,text,filename)
|
Line.__init__(self,i,text,filename)
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "%20s:%5d : %s"%("Irp_read",self.i,self.text)
|
return "%20s:%5d : %s"%("Irp_read",self.i,self.text)
|
||||||
|
|
||||||
class Irp_write(Line):
|
class Irp_write(Line):
|
||||||
|
str="Irp_write"
|
||||||
def __init__(self,i,text,filename):
|
def __init__(self,i,text,filename):
|
||||||
Line.__init__(self,i,text,filename)
|
Line.__init__(self,i,text,filename)
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "%20s:%5d : %s"%("Irp_write",self.i,self.text)
|
return "%20s:%5d : %s"%("Irp_write",self.i,self.text)
|
||||||
|
|
||||||
class Irp_If(Line):
|
class Irp_If(Line):
|
||||||
|
str="Irp_If"
|
||||||
def __init__(self,i,text,filename):
|
def __init__(self,i,text,filename):
|
||||||
Line.__init__(self,i,text,filename)
|
Line.__init__(self,i,text,filename)
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "%20s:%5d : %s"%("Irp_If",self.i,self.text)
|
return "%20s:%5d : %s"%("Irp_If",self.i,self.text)
|
||||||
|
|
||||||
class Irp_Else(Line):
|
class Irp_Else(Line):
|
||||||
|
str="Irp_Else"
|
||||||
def __init__(self,i,text,filename):
|
def __init__(self,i,text,filename):
|
||||||
Line.__init__(self,i,text,filename)
|
Line.__init__(self,i,text,filename)
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "%20s:%5d : %s"%("Irp_Else",self.i,self.text)
|
return "%20s:%5d : %s"%("Irp_Else",self.i,self.text)
|
||||||
|
|
||||||
class Irp_Endif(Line):
|
class Irp_Endif(Line):
|
||||||
|
str="Irp_Endif"
|
||||||
def __init__(self,i,text,filename):
|
def __init__(self,i,text,filename):
|
||||||
Line.__init__(self,i,text,filename)
|
Line.__init__(self,i,text,filename)
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "%20s:%5d : %s"%("Irp_Endif",self.i,self.text)
|
return "%20s:%5d : %s"%("Irp_Endif",self.i,self.text)
|
||||||
|
|
||||||
class Openmp(Line):
|
class Openmp(Line):
|
||||||
|
str="Openmp"
|
||||||
def __init__(self,i,text,filename):
|
def __init__(self,i,text,filename):
|
||||||
Line.__init__(self,i,text,filename)
|
Line.__init__(self,i,text,filename)
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "%20s:%5d : %s"%("Openmp",self.i,self.text)
|
return "%20s:%5d : %s"%("Openmp",self.i,self.text)
|
||||||
|
|
||||||
class Directive(Line):
|
class Directive(Line):
|
||||||
|
str="Directive"
|
||||||
def __init__(self,i,text,filename):
|
def __init__(self,i,text,filename):
|
||||||
Line.__init__(self,i,text,filename)
|
Line.__init__(self,i,text,filename)
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "%20s:%5d : %s"%("Directive",self.i,self.text)
|
return "%20s:%5d : %s"%("Directive",self.i,self.text)
|
||||||
|
|
||||||
class Use(Line):
|
class Use(Line):
|
||||||
|
str="Use"
|
||||||
def __init__(self,i,text,filename):
|
def __init__(self,i,text,filename):
|
||||||
Line.__init__(self,i,text,filename)
|
Line.__init__(self,i,text,filename)
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "%20s:%5d : %s"%("Use",self.i,self.text)
|
return "%20s:%5d : %s"%("Use",self.i,self.text)
|
||||||
|
|
||||||
class Do(Line):
|
class Do(Line):
|
||||||
|
str="Do"
|
||||||
def __init__(self,i,text,filename):
|
def __init__(self,i,text,filename):
|
||||||
Line.__init__(self,i,text,filename)
|
Line.__init__(self,i,text,filename)
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "%20s:%5d : %s"%("Do",self.i,self.text)
|
return "%20s:%5d : %s"%("Do",self.i,self.text)
|
||||||
|
|
||||||
class Enddo (Line):
|
class Enddo (Line):
|
||||||
|
str="Enddo"
|
||||||
def __init__(self,i,text,filename):
|
def __init__(self,i,text,filename):
|
||||||
Line.__init__(self,i,text,filename)
|
Line.__init__(self,i,text,filename)
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "%20s:%5d : %s"%("Enddo",self.i,self.text)
|
return "%20s:%5d : %s"%("Enddo",self.i,self.text)
|
||||||
|
|
||||||
class If(Line):
|
class If(Line):
|
||||||
|
str="If"
|
||||||
def __init__(self,i,text,filename):
|
def __init__(self,i,text,filename):
|
||||||
Line.__init__(self,i,text,filename)
|
Line.__init__(self,i,text,filename)
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "%20s:%5d : %s"%("If",self.i,self.text)
|
return "%20s:%5d : %s"%("If",self.i,self.text)
|
||||||
|
|
||||||
class Elseif(Line):
|
class Elseif(Line):
|
||||||
|
str="Elseif"
|
||||||
def __init__(self,i,text,filename):
|
def __init__(self,i,text,filename):
|
||||||
Line.__init__(self,i,text,filename)
|
Line.__init__(self,i,text,filename)
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "%20s:%5d : %s"%("Elseif",self.i,self.text)
|
return "%20s:%5d : %s"%("Elseif",self.i,self.text)
|
||||||
|
|
||||||
class Else(Line):
|
class Else(Line):
|
||||||
|
str="Else"
|
||||||
def __init__(self,i,text,filename):
|
def __init__(self,i,text,filename):
|
||||||
Line.__init__(self,i,text,filename)
|
Line.__init__(self,i,text,filename)
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "%20s:%5d : %s"%("Else",self.i,self.text)
|
return "%20s:%5d : %s"%("Else",self.i,self.text)
|
||||||
|
|
||||||
class Endif(Line):
|
class Endif(Line):
|
||||||
|
str="Endif"
|
||||||
def __init__(self,i,text,filename):
|
def __init__(self,i,text,filename):
|
||||||
Line.__init__(self,i,text,filename)
|
Line.__init__(self,i,text,filename)
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "%20s:%5d : %s"%("Endif",self.i,self.text)
|
return "%20s:%5d : %s"%("Endif",self.i,self.text)
|
||||||
|
|
||||||
class Select(Line):
|
class Select(Line):
|
||||||
|
str="Select"
|
||||||
def __init__(self,i,text,filename):
|
def __init__(self,i,text,filename):
|
||||||
Line.__init__(self,i,text,filename)
|
Line.__init__(self,i,text,filename)
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "%20s:%5d : %s"%("Select",self.i,self.text)
|
return "%20s:%5d : %s"%("Select",self.i,self.text)
|
||||||
|
|
||||||
class Case(Line):
|
class Case(Line):
|
||||||
|
str="Case"
|
||||||
def __init__(self,i,text,filename):
|
def __init__(self,i,text,filename):
|
||||||
Line.__init__(self,i,text,filename)
|
Line.__init__(self,i,text,filename)
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "%20s:%5d : %s"%("Case",self.i,self.text)
|
return "%20s:%5d : %s"%("Case",self.i,self.text)
|
||||||
|
|
||||||
class End_select(Line):
|
class End_select(Line):
|
||||||
|
str="End_select"
|
||||||
def __init__(self,i,text,filename):
|
def __init__(self,i,text,filename):
|
||||||
Line.__init__(self,i,text,filename)
|
Line.__init__(self,i,text,filename)
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "%20s:%5d : %s"%("End_select",self.i,self.text)
|
return "%20s:%5d : %s"%("End_select",self.i,self.text)
|
||||||
|
|
||||||
class Program(Line):
|
class Program(Line):
|
||||||
str = "Program"
|
str="Program"
|
||||||
def __init__(self,i,text,filename):
|
def __init__(self,i,text,filename):
|
||||||
Line.__init__(self,i,text,filename)
|
Line.__init__(self,i,text,filename)
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "%20s:%5d : %s"%("Program",self.i,self.text)
|
return "%20s:%5d : %s"%("Program",self.i,self.text)
|
||||||
|
|
||||||
class Subroutine(Line):
|
class Subroutine(Line):
|
||||||
str = "Subroutine"
|
str="Subroutine"
|
||||||
def __init__(self,i,text,filename):
|
def __init__(self,i,text,filename):
|
||||||
Line.__init__(self,i,text,filename)
|
Line.__init__(self,i,text,filename)
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "%20s:%5d : %s"%("Subroutine",self.i,self.text)
|
return "%20s:%5d : %s"%("Subroutine",self.i,self.text)
|
||||||
|
|
||||||
class Function(Line):
|
class Function(Line):
|
||||||
str = "Function"
|
str="Function"
|
||||||
def __init__(self,i,text,filename):
|
def __init__(self,i,text,filename):
|
||||||
Line.__init__(self,i,text,filename)
|
Line.__init__(self,i,text,filename)
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "%20s:%5d : %s"%("Function",self.i,self.text)
|
return "%20s:%5d : %s"%("Function",self.i,self.text)
|
||||||
|
|
||||||
class Call(Line):
|
class Call(Line):
|
||||||
|
str="Call"
|
||||||
def __init__(self,i,text,filename):
|
def __init__(self,i,text,filename):
|
||||||
Line.__init__(self,i,text,filename)
|
Line.__init__(self,i,text,filename)
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "%20s:%5d : %s"%("Call",self.i,self.text)
|
return "%20s:%5d : %s"%("Call",self.i,self.text)
|
||||||
|
|
||||||
class Provide(Line):
|
class Provide(Line):
|
||||||
|
str="Provide"
|
||||||
def __init__(self,i,text,filename):
|
def __init__(self,i,text,filename):
|
||||||
Line.__init__(self,i,text,filename)
|
Line.__init__(self,i,text,filename)
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "%20s:%5d : %s"%("Provide",self.i,self.text)
|
return "%20s:%5d : %s"%("Provide",self.i,self.text)
|
||||||
|
|
||||||
class NoDep(Line):
|
class NoDep(Line):
|
||||||
|
str="NoDep"
|
||||||
def __init__(self,i,text,filename):
|
def __init__(self,i,text,filename):
|
||||||
Line.__init__(self,i,text,filename)
|
Line.__init__(self,i,text,filename)
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "%20s:%5d : %s"%("NoDep",self.i,self.text)
|
return "%20s:%5d : %s"%("NoDep",self.i,self.text)
|
||||||
|
|
||||||
class Return (Line):
|
class Return (Line):
|
||||||
|
str="Return"
|
||||||
def __init__(self,i,text,filename):
|
def __init__(self,i,text,filename):
|
||||||
Line.__init__(self,i,text,filename)
|
Line.__init__(self,i,text,filename)
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "%20s:%5d : %s"%("Return",self.i,self.text)
|
return "%20s:%5d : %s"%("Return",self.i,self.text)
|
||||||
|
|
||||||
class Include(Line):
|
class Include(Line):
|
||||||
|
str="Include"
|
||||||
def __init__(self,i,text,filename):
|
def __init__(self,i,text,filename):
|
||||||
Line.__init__(self,i,text,filename)
|
Line.__init__(self,i,text,filename)
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "%20s:%5d : %s"%("Include",self.i,self.text)
|
return "%20s:%5d : %s"%("Include",self.i,self.text)
|
||||||
|
|
||||||
class Implicit (Line):
|
class Implicit (Line):
|
||||||
|
str="Implicit"
|
||||||
def __init__(self,i,text,filename):
|
def __init__(self,i,text,filename):
|
||||||
Line.__init__(self,i,text,filename)
|
Line.__init__(self,i,text,filename)
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "%20s:%5d : %s"%("Implicit",self.i,self.text)
|
return "%20s:%5d : %s"%("Implicit",self.i,self.text)
|
||||||
|
|
||||||
class Free(Line):
|
class Free(Line):
|
||||||
|
str="Free"
|
||||||
def __init__(self,i,text,filename):
|
def __init__(self,i,text,filename):
|
||||||
Line.__init__(self,i,text,filename)
|
Line.__init__(self,i,text,filename)
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "%20s:%5d : %s"%("Free",self.i,self.text)
|
return "%20s:%5d : %s"%("Free",self.i,self.text)
|
||||||
|
|
||||||
class End(Line):
|
class End(Line):
|
||||||
|
str="End"
|
||||||
def __init__(self,i,text,filename):
|
def __init__(self,i,text,filename):
|
||||||
Line.__init__(self,i,text,filename)
|
Line.__init__(self,i,text,filename)
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "%20s:%5d : %s"%("End",self.i,self.text)
|
return "%20s:%5d : %s"%("End",self.i,self.text)
|
||||||
|
|
||||||
class Provide_all (Line):
|
class Provide_all (Line):
|
||||||
|
str="Provide_all"
|
||||||
def __init__(self,i,text,filename):
|
def __init__(self,i,text,filename):
|
||||||
Line.__init__(self,i,text,filename)
|
Line.__init__(self,i,text,filename)
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
@ -349,6 +392,14 @@ def create_irpf90_files():
|
|||||||
def is_irpf90_file(filename):
|
def is_irpf90_file(filename):
|
||||||
return filename.endswith(".irp.f") and not filename.startswith('.')
|
return filename.endswith(".irp.f") and not filename.startswith('.')
|
||||||
result = filter ( is_irpf90_file, os.listdir(os.getcwd()) )
|
result = filter ( is_irpf90_file, os.listdir(os.getcwd()) )
|
||||||
|
for dir in command_line.include_dir:
|
||||||
|
try:
|
||||||
|
os.stat(dir)
|
||||||
|
result += map(lambda x: dir+x, filter ( is_irpf90_file, os.listdir(dir) ) )
|
||||||
|
except:
|
||||||
|
continue
|
||||||
|
if command_line.do_codelet:
|
||||||
|
result += [command_line.codelet[3]]
|
||||||
return result
|
return result
|
||||||
irpf90_files = create_irpf90_files()
|
irpf90_files = create_irpf90_files()
|
||||||
|
|
||||||
|
39
src/irpman.py
Executable file
39
src/irpman.py
Executable file
@ -0,0 +1,39 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# IRPF90 is a Fortran90 preprocessor written in Python for programming using
|
||||||
|
# the Implicit Reference to Parameters (IRP) method.
|
||||||
|
# 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
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License along
|
||||||
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
#
|
||||||
|
# Anthony Scemama
|
||||||
|
# LCPQ - IRSAMC - CNRS
|
||||||
|
# Universite Paul Sabatier
|
||||||
|
# 118, route de Narbonne
|
||||||
|
# 31062 Toulouse Cedex 4
|
||||||
|
# scemama@irsamc.ups-tlse.fr
|
||||||
|
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
wd = os.path.abspath(os.path.dirname(__file__))
|
||||||
|
from irpf90_t import mandir
|
||||||
|
filename = sys.argv[1].lower()+".l"
|
||||||
|
if filename not in os.listdir(mandir):
|
||||||
|
print "%s does not exist"%(sys.argv[1])
|
||||||
|
sys.exit(-1)
|
||||||
|
|
||||||
|
os.system("man ./"+mandir+sys.argv[1].lower()+".l")
|
||||||
|
|
@ -32,6 +32,8 @@ irpdir = irpf90_t.irpdir
|
|||||||
mandir = irpf90_t.mandir
|
mandir = irpf90_t.mandir
|
||||||
|
|
||||||
FILENAME = "Makefile"
|
FILENAME = "Makefile"
|
||||||
|
FILENAME_GITIGNORE = ".gitignore"
|
||||||
|
IRPF90_MAKE = "irpf90.make"
|
||||||
|
|
||||||
######################################################################
|
######################################################################
|
||||||
def create():
|
def create():
|
||||||
@ -51,45 +53,65 @@ SRC=
|
|||||||
OBJ=
|
OBJ=
|
||||||
LIB=
|
LIB=
|
||||||
|
|
||||||
include irpf90.make
|
include %s
|
||||||
|
|
||||||
irpf90.make: $(wildcard *.irp.f)
|
%s: $(filter-out %s%%, $(wildcard */*.irp.f)) $(wildcard *.irp.f) $(wildcard *.inc.f) Makefile
|
||||||
\t$(IRPF90)
|
\t$(IRPF90)
|
||||||
"""
|
"""%(IRPF90_MAKE,IRPF90_MAKE,irpdir)
|
||||||
|
file.write(t)
|
||||||
|
file.close()
|
||||||
|
create_gitignore()
|
||||||
|
|
||||||
|
######################################################################
|
||||||
|
def create_gitignore():
|
||||||
|
has_makefile = True
|
||||||
|
try:
|
||||||
|
file = open(FILENAME_GITIGNORE,"r")
|
||||||
|
except IOError:
|
||||||
|
has_makefile = False
|
||||||
|
if has_makefile:
|
||||||
|
return
|
||||||
|
file = open(FILENAME_GITIGNORE,"w")
|
||||||
|
t = "\n".join([ irpdir, mandir, IRPF90_MAKE, 'irpf90_entities', 'tags' ])
|
||||||
file.write(t)
|
file.write(t)
|
||||||
file.close()
|
file.close()
|
||||||
|
|
||||||
######################################################################
|
######################################################################
|
||||||
def run():
|
def run():
|
||||||
from modules import modules
|
from modules import modules
|
||||||
if os.fork() == 0:
|
|
||||||
mod = []
|
mod = []
|
||||||
for m in modules.values():
|
for m in modules.values():
|
||||||
mod.append(m)
|
mod.append(m)
|
||||||
|
|
||||||
file = open('irpf90.make','w')
|
file = open(IRPF90_MAKE,'w')
|
||||||
|
result = ""
|
||||||
result = "SRC += %sirp_stack.irp.F90"%(irpdir)
|
result += "FC+=-I %s "%(irpdir)
|
||||||
|
for i in command_line.include_dir:
|
||||||
|
result += "-I %s%s "%(irpdir,i)
|
||||||
|
result += "\n"
|
||||||
|
result += "SRC += %sirp_stack.irp.F90"%(irpdir)
|
||||||
result += " %sirp_touches.irp.F90"%(irpdir)
|
result += " %sirp_touches.irp.F90"%(irpdir)
|
||||||
if command_line.do_openmp:
|
if command_line.do_openmp:
|
||||||
result += " %sirp_locks.irp.F90"%(irpdir)
|
result += " %sirp_locks.irp.F90"%(irpdir)
|
||||||
if command_line.do_profile:
|
if command_line.do_profile:
|
||||||
result += " %sirp_profile.irp.F90"%(irpdir)
|
result += " %sirp_profile.irp.F90"%(irpdir)
|
||||||
for m in mod:
|
for m in mod:
|
||||||
result += " %s%s.irp.F90"%(irpdir,m.name[:-4])
|
result += " %s%s.irp.F90"%(irpdir,m.filename)
|
||||||
result += " %s%s.irp.module.F90"%(irpdir,m.name[:-4])
|
result += " %s%s.irp.module.F90"%(irpdir,m.filename)
|
||||||
print >>file, result
|
print >>file, result
|
||||||
|
|
||||||
result = "OBJ += %sirp_stack.irp.o"%(irpdir)
|
result = "OBJ_IRP = "
|
||||||
for m in mod:
|
for m in mod:
|
||||||
if not m.is_main:
|
if not m.is_main:
|
||||||
result += " %s%s.irp.o"%(irpdir,m.name[:-4])
|
result += " %s%s.irp.o"%(irpdir,m.filename)
|
||||||
result += " %s%s.irp.module.o"%(irpdir,m.name[:-4])
|
result += " %s%s.irp.module.o"%(irpdir,m.filename)
|
||||||
print >>file, result
|
print >>file, result
|
||||||
|
|
||||||
print >>file, "OBJ1 = $(patsubst %%, %s%%,$(notdir $(OBJ))) %sirp_touches.irp.o"%(irpdir,irpdir),
|
print >>file, "OBJ1 = $(OBJ_IRP) $(OBJ) %sirp_touches.irp.o"%(irpdir),
|
||||||
if command_line.do_profile:
|
if command_line.do_profile:
|
||||||
print >>file, " %sirp_profile.irp.o"%(irpdir), " irp_rdtsc.o",
|
print >>file, " %sirp_profile.irp.o"%(irpdir), " irp_rdtsc.o",
|
||||||
|
if command_line.do_codelet:
|
||||||
|
print >>file, " irp_rdtsc.o",
|
||||||
if command_line.do_openmp:
|
if command_line.do_openmp:
|
||||||
print >>file, " %sirp_locks.irp.o"%(irpdir),
|
print >>file, " %sirp_locks.irp.o"%(irpdir),
|
||||||
else:
|
else:
|
||||||
@ -106,14 +128,14 @@ def run():
|
|||||||
print >>file, "ifdef USE_IRPF90_A"
|
print >>file, "ifdef USE_IRPF90_A"
|
||||||
for m in mod:
|
for m in mod:
|
||||||
if m.is_main:
|
if m.is_main:
|
||||||
exe = m.name[:-4]
|
exe = m.filename
|
||||||
print >>file, "%s: %s%s.irp.o %s%s.irp.module.o irpf90.a"%(exe,irpdir,exe,irpdir,exe)
|
print >>file, "%s: %s%s.irp.o %s%s.irp.module.o irpf90.a"%(exe,irpdir,exe,irpdir,exe)
|
||||||
print >>file, "\t$(FC) -o $@ %s$@.irp.o %s$@.irp.module.o irpf90.a $(LIB)"%(irpdir,irpdir)
|
print >>file, "\t$(FC) -o $@ %s$@.irp.o %s$@.irp.module.o irpf90.a $(LIB)"%(irpdir,irpdir)
|
||||||
print >>file, "\t@$(MAKE) -s move"
|
print >>file, "\t@$(MAKE) -s move"
|
||||||
print >>file, "else"
|
print >>file, "else"
|
||||||
for m in mod:
|
for m in mod:
|
||||||
if m.is_main:
|
if m.is_main:
|
||||||
exe = m.name[:-4]
|
exe = m.filename
|
||||||
print >>file, "%s: %s%s.irp.o %s%s.irp.module.o $(OBJ1)"%(exe,irpdir,exe,irpdir,exe)
|
print >>file, "%s: %s%s.irp.o %s%s.irp.module.o $(OBJ1)"%(exe,irpdir,exe,irpdir,exe)
|
||||||
print >>file, "\t$(FC) -o $@ %s$@.irp.o %s$@.irp.module.o $(OBJ1) $(LIB)"%(irpdir,irpdir)
|
print >>file, "\t$(FC) -o $@ %s$@.irp.o %s$@.irp.module.o $(OBJ1) $(LIB)"%(irpdir,irpdir)
|
||||||
print >>file, "\t@$(MAKE) -s move"
|
print >>file, "\t@$(MAKE) -s move"
|
||||||
@ -121,14 +143,16 @@ def run():
|
|||||||
|
|
||||||
buffer = ""
|
buffer = ""
|
||||||
for m in mod:
|
for m in mod:
|
||||||
filename = "%s%s.irp.o: %s%s.irp.module.o"%(irpdir,m.name[:-4],irpdir,m.name[:-4])
|
filename = "%s%s.irp.o: $(OBJ) %s%s.irp.module.o"%(irpdir,m.filename,irpdir,m.filename)
|
||||||
mds = map (lambda x: " %s%s.irp.module.o"%(irpdir,x[:-4]),m.needed_modules)
|
needed_modules = filter( lambda x: modules[x].name in m.needed_modules, modules )
|
||||||
|
needed_files = map(lambda x: modules[x].filename, needed_modules)
|
||||||
|
mds = map (lambda x: " %s%s.irp.module.o"%(irpdir,x),needed_files)
|
||||||
print >>file, filename," ".join(mds)," ".join(m.includes)
|
print >>file, filename," ".join(mds)," ".join(m.includes)
|
||||||
if not m.is_main:
|
if not m.is_main:
|
||||||
buffer += "\t - @echo '"+filename+" ".join(mds)+"' >> %sdist_Makefile\n"%(irpdir)
|
buffer += "\t - @echo '"+filename+" ".join(mds)+"' >> %sdist_Makefile\n"%(irpdir)
|
||||||
print >>file, "%sirp_touches.irp.o:"%(irpdir),
|
print >>file, "%sirp_touches.irp.o: $(OBJ) "%(irpdir),
|
||||||
mds = filter(lambda x: not x.is_main,mod)
|
mds = filter(lambda x: not x.is_main,mod)
|
||||||
mds = map(lambda x: " %s%s.irp.o %s%s.irp.o"%(irpdir,x.name[:-4],irpdir,x.name[:-4]),mds)
|
mds = map(lambda x: " %s%s.irp.o %s%s.irp.o"%(irpdir,x.filename,irpdir,x.filename),mds)
|
||||||
print >>file," ".join(mds)
|
print >>file," ".join(mds)
|
||||||
if command_line.do_profile:
|
if command_line.do_profile:
|
||||||
print >>file, "%sirp_profile.irp.o:"%(irpdir),
|
print >>file, "%sirp_profile.irp.o:"%(irpdir),
|
||||||
@ -143,14 +167,14 @@ def run():
|
|||||||
# print >>file, "\t- @echo FCFLAGS=$(FCFLAGS) >> %sdist_Makefile"%(irpdir)
|
# print >>file, "\t- @echo FCFLAGS=$(FCFLAGS) >> %sdist_Makefile"%(irpdir)
|
||||||
# print >>file, "\t- @echo LIB=$(LIB) >> %sdist_Makefile"%(irpdir)
|
# print >>file, "\t- @echo LIB=$(LIB) >> %sdist_Makefile"%(irpdir)
|
||||||
# print >>file, "\t- @echo .DEFAULT_GOAL: exe >> %sdist_Makefile"%(irpdir)
|
# print >>file, "\t- @echo .DEFAULT_GOAL: exe >> %sdist_Makefile"%(irpdir)
|
||||||
# print >>file, "\t- @echo 'exe: $$(EXE).irp.F90 $(OBJ) irp_touches.irp.o' >> %sdist_Makefile"%(irpdir)
|
# print >>file, "\t- @echo 'exe: $$(EXE).irp.F90 $(OBJ_IRP) $(OBJ) irp_touches.irp.o' >> %sdist_Makefile"%(irpdir)
|
||||||
# print >>file, "\t- @echo '\t$$(FC) -o $$(EXE) $$(EXE).irp.F90 $(OBJ) irp_touches.irp.o $$(LIB)' >> %sdist_Makefile"%(irpdir)
|
# print >>file, "\t- @echo '\t$$(FC) -o $$(EXE) $$(EXE).irp.F90 $(OBJ_IRP) $(OBJ) irp_touches.irp.o $$(LIB)' >> %sdist_Makefile"%(irpdir)
|
||||||
# print >>file, "\t- @echo '%%.o: %%.F90' >> %sdist_Makefile"%(irpdir)
|
# print >>file, "\t- @echo '%%.o: %%.F90' >> %sdist_Makefile"%(irpdir)
|
||||||
# print >>file, "\t- @echo '\t$$(FC) $$(FCFLAGS) -c $$*.F90 -o $$*.o' >> %sdist_Makefile"%(irpdir)
|
# print >>file, "\t- @echo '\t$$(FC) $$(FCFLAGS) -c $$*.F90 -o $$*.o' >> %sdist_Makefile"%(irpdir)
|
||||||
# print >>file, "\t- @echo 'clean:' >> %sdist_Makefile"%(irpdir)
|
# print >>file, "\t- @echo 'clean:' >> %sdist_Makefile"%(irpdir)
|
||||||
# print >>file, "\t- @echo '\trm *.o *.mod $$(EXE) 2>/dev/null' >> %sdist_Makefile"%(irpdir)
|
# print >>file, "\t- @echo '\trm *.o *.mod $$(EXE) 2>/dev/null' >> %sdist_Makefile"%(irpdir)
|
||||||
# print >>file, buffer
|
# print >>file, buffer
|
||||||
# print >>file, "\t- @echo '\tirp_touches.irp.o: irp_touches.irp.F90 $(OBJ) >> %sdist_Makefile"%(irpdir)
|
# print >>file, "\t- @echo '\tirp_touches.irp.o: irp_touches.irp.F90 $(OBJ_IRP) $(OBJ) >> %sdist_Makefile"%(irpdir)
|
||||||
|
|
||||||
# print >>file, "%%.dist: %sdist_Makefile"%(irpdir)
|
# print >>file, "%%.dist: %sdist_Makefile"%(irpdir)
|
||||||
# print >>file, "\t- @mkdir -p dist/$*| DO_NOTHING="
|
# print >>file, "\t- @mkdir -p dist/$*| DO_NOTHING="
|
||||||
@ -165,23 +189,23 @@ def run():
|
|||||||
# print >>file, "\t- @cp %s$*.irp.F90 dist/$*/| DO_NOTHING="%(irpdir)
|
# print >>file, "\t- @cp %s$*.irp.F90 dist/$*/| DO_NOTHING="%(irpdir)
|
||||||
# print >>file, "\t- cd dist ; tar -zcvf ../$*.tar.gz $*\n"
|
# print >>file, "\t- cd dist ; tar -zcvf ../$*.tar.gz $*\n"
|
||||||
|
|
||||||
print >>file, irpdir+"%.irp.module.o: "+irpdir+"%.irp.module.F90"
|
for dir in [ irpdir ] + map(lambda x: irpdir+x, command_line.include_dir):
|
||||||
print >>file, "\t$(FC) $(FCFLAGS) -c "+irpdir+"$*.irp.module.F90 -o "+irpdir+"$*.irp.module.o"
|
print >>file, dir+"%.irp.module.o: $(OBJ) "+dir+"%.irp.module.F90"
|
||||||
print >>file, irpdir+"%.irp.o: "+irpdir+"%.irp.module.o "+irpdir+"%.irp.F90"
|
print >>file, "\t$(FC) $(FCFLAGS) -c "+dir+"$*.irp.module.F90 -o "+dir+"$*.irp.module.o"
|
||||||
print >>file, "\t$(FC) $(FCFLAGS) -c "+irpdir+"$*.irp.F90 -o "+irpdir+"$*.irp.o"
|
print >>file, dir+"%.irp.o: $(OBJ) "+dir+"%.irp.module.o "+dir+"%.irp.F90"
|
||||||
print >>file, irpdir+"%.irp.o: "+irpdir+"%.irp.F90"
|
print >>file, "\t$(FC) $(FCFLAGS) -c "+dir+"$*.irp.F90 -o "+dir+"$*.irp.o"
|
||||||
print >>file, "\t$(FC) $(FCFLAGS) -c "+irpdir+"$*.irp.F90 -o "+irpdir+"$*.irp.o"
|
print >>file, dir+"%.irp.o: $(OBJ) "+dir+"%.irp.F90"
|
||||||
print >>file, irpdir+"%.o: %.F90"
|
print >>file, "\t$(FC) $(FCFLAGS) -c "+dir+"$*.irp.F90 -o "+dir+"$*.irp.o"
|
||||||
print >>file, "\t$(FC) $(FCFLAGS) -c $*.F90 -o "+irpdir+"$*.o"
|
print >>file, dir+"%.o: %.F90"
|
||||||
print >>file, irpdir+"%.o: %.f90\n\t$(FC) $(FCFLAGS) -c $*.f90 -o "+irpdir+"$*.o"
|
print >>file, "\t$(FC) $(FCFLAGS) -c $*.F90 -o "+dir+"$*.o"
|
||||||
print >>file, irpdir+"%.o: %.f\n\t$(FC) $(FCFLAGS) -c $*.f -o "+irpdir+"$*.o"
|
print >>file, dir+"%.o: %.f90\n\t$(FC) $(FCFLAGS) -c $*.f90 -o "+dir+"$*.o"
|
||||||
print >>file, irpdir+"%.o: %.F\n\t$(FC) $(FCFLAGS) -c $*.F -o "+irpdir+"$*.o"
|
print >>file, dir+"%.o: %.f\n\t$(FC) $(FCFLAGS) -c $*.f -o "+dir+"$*.o"
|
||||||
print >>file, irpdir+"%.irp.F90: irpf90.make\n"
|
print >>file, dir+"%.o: %.F\n\t$(FC) $(FCFLAGS) -c $*.F -o "+dir+"$*.o"
|
||||||
|
print >>file, dir+"%.irp.F90: "+IRPF90_MAKE+"\n"
|
||||||
print >>file, "move:\n\t@mv -f *.mod IRPF90_temp/ 2> /dev/null | DO_NOTHING=\n"
|
print >>file, "move:\n\t@mv -f *.mod IRPF90_temp/ 2> /dev/null | DO_NOTHING=\n"
|
||||||
print >>file, "irpf90.a: $(OBJ1)\n\t$(AR) crf irpf90.a $(OBJ1)\n"
|
print >>file, "irpf90.a: $(OBJ) $(OBJ1)\n\t$(AR) crf irpf90.a $(OBJ1)\n"
|
||||||
print >>file, "clean:\n\trm -rf $(EXE) $(OBJ1) irpf90.a $(ALL_OBJ1) $(ALL)\n"
|
print >>file, "clean:\n\trm -rf $(EXE) $(OBJ1) irpf90.a $(ALL_OBJ1) $(ALL)\n"
|
||||||
print >>file, "veryclean:\n\t- $(MAKE) clean\n"
|
print >>file, "veryclean:\n\t- $(MAKE) clean\n"
|
||||||
print >>file, "\t- rm -rf "+irpdir+" "+mandir+" irpf90.make irpf90_variables dist\n"
|
print >>file, "\t- rm -rf "+irpdir+" "+mandir+" "+IRPF90_MAKE+" irpf90_entities dist\n"
|
||||||
|
|
||||||
file.close()
|
file.close()
|
||||||
sys.exit(0)
|
|
||||||
|
@ -46,7 +46,8 @@ class Fmodule(object):
|
|||||||
|
|
||||||
def __init__(self,text,filename):
|
def __init__(self,text,filename):
|
||||||
self.text = put_info(text,filename)
|
self.text = put_info(text,filename)
|
||||||
self.name = "%s_mod"%(filename[:-6])
|
self.filename = filename[:-6]
|
||||||
|
self.name = "%s_mod"%(self.filename).replace('/','__').replace('.','Dot')
|
||||||
|
|
||||||
def is_main(self):
|
def is_main(self):
|
||||||
if '_is_main' not in self.__dict__:
|
if '_is_main' not in self.__dict__:
|
||||||
|
@ -42,7 +42,7 @@ modules = create_modules()
|
|||||||
######################################################################
|
######################################################################
|
||||||
def write_module(m):
|
def write_module(m):
|
||||||
# Module data
|
# Module data
|
||||||
filename = irpdir+m.name[0:-4]+".irp.module.F90"
|
filename = irpdir+m.filename+".irp.module.F90"
|
||||||
text = m.header + m.head
|
text = m.header + m.head
|
||||||
text = map(lambda x: "%s\n"%(x),text)
|
text = map(lambda x: "%s\n"%(x),text)
|
||||||
if not same_file(filename,text):
|
if not same_file(filename,text):
|
||||||
@ -52,7 +52,7 @@ def write_module(m):
|
|||||||
file.close()
|
file.close()
|
||||||
|
|
||||||
# Subroutines
|
# Subroutines
|
||||||
filename = irpdir+m.name[0:-4]+".irp.F90"
|
filename = irpdir+m.filename+".irp.F90"
|
||||||
text = m.header + m.generated_text + m.residual_text
|
text = m.header + m.generated_text + m.residual_text
|
||||||
text = map(lambda x: "%s\n"%(x),text)
|
text = map(lambda x: "%s\n"%(x),text)
|
||||||
if not same_file(filename,text):
|
if not same_file(filename,text):
|
||||||
|
@ -355,23 +355,14 @@ def add_operators(text):
|
|||||||
for line in text:
|
for line in text:
|
||||||
buffer = line.text
|
buffer = line.text
|
||||||
if "+=" in buffer:
|
if "+=" in buffer:
|
||||||
if "if" in buffer:
|
if buffer.lstrip().startswith("if "):
|
||||||
re_incr = re.compile(r"(.*)(\))(\s*)(.*)(\+=)(.*$)",re.S)
|
re_incr = re.compile(r"(.*)(\))(\s*)(.*)(\+=)(.*$)",re.S)
|
||||||
line.text = re.sub(re_incr,r'\1\2\4=\4+(\6)', buffer)
|
line.text = re.sub(re_incr,r'\1\2\4=\4+(\6)', buffer)
|
||||||
else:
|
else:
|
||||||
line.text = re.sub(re_incr,r'\1\2=\2+(\4)', buffer)
|
line.text = re.sub(re_incr,r'\1\2=\2+(\4)', buffer)
|
||||||
elif "-=" in buffer:
|
elif "-=" in buffer:
|
||||||
if "if" in buffer:
|
|
||||||
re_decr = re.compile(r"(.*)(\))(\s*)(.*)(\-=)(.*$)",re.S)
|
|
||||||
line.text = re.sub(re_decr,r'\1\2\4=\4-(\6)', buffer)
|
|
||||||
else:
|
|
||||||
line.text = re.sub(re_decr,r'\1\2=\2-(\4)', buffer)
|
line.text = re.sub(re_decr,r'\1\2=\2-(\4)', buffer)
|
||||||
# line.text = re.sub(re_decr,r'\1\2=\2-(\4)', buffer)
|
|
||||||
elif "*=" in buffer:
|
elif "*=" in buffer:
|
||||||
if "if" in buffer:
|
|
||||||
re_mult = re.compile(r"(.*)(\))(\s*)(.*)(\*=)(.*$)",re.S)
|
|
||||||
line.text = re.sub(re_mult,r'\1\2\4=\4*(\6)', buffer)
|
|
||||||
else:
|
|
||||||
line.text = re.sub(re_mult,r'\1\2=\2*(\4)', buffer)
|
line.text = re.sub(re_mult,r'\1\2=\2*(\4)', buffer)
|
||||||
result.append(line)
|
result.append(line)
|
||||||
return result
|
return result
|
||||||
@ -673,7 +664,11 @@ def change_includes(text):
|
|||||||
if len(txt) != 3:
|
if len(txt) != 3:
|
||||||
print txt
|
print txt
|
||||||
error.fail(line,"Error in include statement")
|
error.fail(line,"Error in include statement")
|
||||||
|
directory = (("./"+line.filename).rsplit('/',1)[0]+'/')[2:]
|
||||||
|
if directory == "":
|
||||||
filename = txt[1].strip()
|
filename = txt[1].strip()
|
||||||
|
else:
|
||||||
|
filename = directory+txt[1].strip()
|
||||||
try:
|
try:
|
||||||
file = open(filename,'r')
|
file = open(filename,'r')
|
||||||
file.close()
|
file.close()
|
||||||
@ -793,6 +788,7 @@ def check_begin_end(text):
|
|||||||
error.fail(text[begin],"Missing 'end%s'"%(x,))
|
error.fail(text[begin],"Missing 'end%s'"%(x,))
|
||||||
|
|
||||||
def find_matching_end_subfunpro(begin,x):
|
def find_matching_end_subfunpro(begin,x):
|
||||||
|
line = text[begin]
|
||||||
for i in range(begin+1,len(text)):
|
for i in range(begin+1,len(text)):
|
||||||
line = text[i]
|
line = text[i]
|
||||||
if type(line) == x:
|
if type(line) == x:
|
||||||
|
@ -20,7 +20,6 @@ import subprocess
|
|||||||
import tempfile
|
import tempfile
|
||||||
import os
|
import os
|
||||||
import threading
|
import threading
|
||||||
from variables import variables
|
|
||||||
|
|
||||||
def build_rdtsc():
|
def build_rdtsc():
|
||||||
file,filename = tempfile.mkstemp()
|
file,filename = tempfile.mkstemp()
|
||||||
@ -36,6 +35,7 @@ def build_rdtsc():
|
|||||||
threading.Thread(target=t).start()
|
threading.Thread(target=t).start()
|
||||||
|
|
||||||
def build_module():
|
def build_module():
|
||||||
|
from variables import variables
|
||||||
data = """
|
data = """
|
||||||
module irp_timer
|
module irp_timer
|
||||||
double precision :: irp_profile(3,%(n)d)
|
double precision :: irp_profile(3,%(n)d)
|
||||||
|
@ -37,6 +37,7 @@ class Sub(object):
|
|||||||
assert len(text) > 0
|
assert len(text) > 0
|
||||||
assert type(text[0]) in [Subroutine, Function]
|
assert type(text[0]) in [Subroutine, Function]
|
||||||
self.text = text
|
self.text = text
|
||||||
|
self.called_by = []
|
||||||
|
|
||||||
############################################################
|
############################################################
|
||||||
def name(self):
|
def name(self):
|
||||||
@ -58,7 +59,7 @@ class Sub(object):
|
|||||||
if '_doc' not in self.__dict__:
|
if '_doc' not in self.__dict__:
|
||||||
def f(l): return
|
def f(l): return
|
||||||
buffer = filter(lambda l:type(l) == Doc, self.text)
|
buffer = filter(lambda l:type(l) == Doc, self.text)
|
||||||
self._doc = map(lambda l: l.text[1:], buffer)
|
self._doc = map(lambda l: l.text.lstrip()[1:], buffer)
|
||||||
if buffer == []:
|
if buffer == []:
|
||||||
error.warn(None,"Subroutine %s is not documented"%(self.name))
|
error.warn(None,"Subroutine %s is not documented"%(self.name))
|
||||||
return self._doc
|
return self._doc
|
||||||
@ -114,7 +115,7 @@ class Sub(object):
|
|||||||
buffer = filter(lambda x: type(x) == Call,self.text)
|
buffer = filter(lambda x: type(x) == Call,self.text)
|
||||||
self._calls = []
|
self._calls = []
|
||||||
for line in buffer:
|
for line in buffer:
|
||||||
sub = line.text.split('(',1)[0].split()[1]
|
sub = line.text.split('(',1)[0].split()[1].lower()
|
||||||
self._calls.append(sub)
|
self._calls.append(sub)
|
||||||
self._calls = make_single(self._calls)
|
self._calls = make_single(self._calls)
|
||||||
return self._calls
|
return self._calls
|
||||||
|
@ -25,7 +25,10 @@
|
|||||||
# scemama@irsamc.ups-tlse.fr
|
# scemama@irsamc.ups-tlse.fr
|
||||||
|
|
||||||
|
|
||||||
|
from util import *
|
||||||
from subroutine import *
|
from subroutine import *
|
||||||
|
from variables import variables
|
||||||
|
from variable import Variable
|
||||||
from irpf90_t import *
|
from irpf90_t import *
|
||||||
|
|
||||||
def create_subroutines():
|
def create_subroutines():
|
||||||
@ -47,7 +50,22 @@ def create_subroutines():
|
|||||||
inside = False
|
inside = False
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
def create_called_by(subs,vars):
|
||||||
|
for s in subs.values() + vars.values():
|
||||||
|
if type(s) == Variable and s.same_as != s.name:
|
||||||
|
continue
|
||||||
|
for x in s.calls:
|
||||||
|
try:
|
||||||
|
subs[x].called_by.append(s.name)
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
for s in subs.values():
|
||||||
|
s.called_by = make_single(s.called_by)
|
||||||
|
s.called_by.sort()
|
||||||
|
|
||||||
subroutines = create_subroutines()
|
subroutines = create_subroutines()
|
||||||
|
create_called_by(subroutines,variables)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
for v in subroutines.keys():
|
for v in subroutines.keys():
|
||||||
|
@ -35,7 +35,10 @@ def lower(x):
|
|||||||
|
|
||||||
def same_file(filename,txt):
|
def same_file(filename,txt):
|
||||||
assert isinstance(filename,str)
|
assert isinstance(filename,str)
|
||||||
assert type(txt) == list
|
if (type(txt) == list):
|
||||||
|
buffer = ''.join(txt)
|
||||||
|
else:
|
||||||
|
buffer = txt
|
||||||
|
|
||||||
try:
|
try:
|
||||||
file = open(filename,"r")
|
file = open(filename,"r")
|
||||||
@ -44,8 +47,6 @@ def same_file(filename,txt):
|
|||||||
stream = file.read()
|
stream = file.read()
|
||||||
file.close()
|
file.close()
|
||||||
|
|
||||||
buffer = ''.join(txt)
|
|
||||||
|
|
||||||
if len(stream) != len(buffer):
|
if len(stream) != len(buffer):
|
||||||
return False
|
return False
|
||||||
if stream != buffer:
|
if stream != buffer:
|
||||||
|
@ -106,7 +106,7 @@ class Variable(object):
|
|||||||
if '_doc' not in self.__dict__:
|
if '_doc' not in self.__dict__:
|
||||||
text = self.text
|
text = self.text
|
||||||
buffer = filter(lambda l:type(l) == Doc, text)
|
buffer = filter(lambda l:type(l) == Doc, text)
|
||||||
self._doc = map(lambda l: l.text[1:], buffer)
|
self._doc = map(lambda l: l.text.lstrip()[1:], buffer)
|
||||||
if buffer == []:
|
if buffer == []:
|
||||||
error.warn(None,"Variable %s is not documented"%(self.name))
|
error.warn(None,"Variable %s is not documented"%(self.name))
|
||||||
return self._doc
|
return self._doc
|
||||||
@ -130,6 +130,18 @@ class Variable(object):
|
|||||||
return self._includes
|
return self._includes
|
||||||
includes = property(includes)
|
includes = property(includes)
|
||||||
|
|
||||||
|
############################################################
|
||||||
|
def calls(self):
|
||||||
|
if '_calls' not in self.__dict__:
|
||||||
|
self._calls = []
|
||||||
|
text = self.text
|
||||||
|
for line in filter(lambda x: type(x) == Call,text):
|
||||||
|
sub = line.text.split('(',1)[0].split()[1].lower()
|
||||||
|
self._calls.append(sub)
|
||||||
|
make_single(self._calls)
|
||||||
|
return self._calls
|
||||||
|
calls=property(fget=calls)
|
||||||
|
|
||||||
############################################################
|
############################################################
|
||||||
def others(self):
|
def others(self):
|
||||||
if '_others' not in self.__dict__:
|
if '_others' not in self.__dict__:
|
||||||
@ -200,7 +212,7 @@ class Variable(object):
|
|||||||
############################################################
|
############################################################
|
||||||
def fmodule(self):
|
def fmodule(self):
|
||||||
if '_fmodule' not in self.__dict__:
|
if '_fmodule' not in self.__dict__:
|
||||||
self._fmodule = self.line.filename[0].split('.irp.f')[0]+'_mod'
|
self._fmodule = self.line.filename[0].replace('/','__').split('.irp.f')[0]+'_mod'
|
||||||
return self._fmodule
|
return self._fmodule
|
||||||
fmodule = property(fmodule)
|
fmodule = property(fmodule)
|
||||||
|
|
||||||
|
@ -1 +1 @@
|
|||||||
version = "1.2.20"
|
version = "1.3.6"
|
||||||
|
Loading…
Reference in New Issue
Block a user