mirror of
https://gitlab.com/scemama/irpf90.git
synced 2024-12-22 04:13:33 +01:00
Initial version.
Version:1.1.0
This commit is contained in:
commit
62f3085eff
89
src/command_line.py
Normal file
89
src/command_line.py
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
import getopt, sys
|
||||||
|
from IRPPython import irp
|
||||||
|
from version import version
|
||||||
|
|
||||||
|
description = "IRPF90 Fortran preprocessor."
|
||||||
|
options = {}
|
||||||
|
options['d'] = [ 'debug' , 'Activate debug', 0 ]
|
||||||
|
options['v'] = [ 'version' , 'Print version of irpf90', 0 ]
|
||||||
|
options['a'] = [ 'assert' , 'Activate assertions', 0 ]
|
||||||
|
options['h'] = [ 'help' , 'Print this help', 0 ]
|
||||||
|
options['o'] = [ 'openmp' , 'Activate openMP', 0 ]
|
||||||
|
options['c'] = [ 'check_cycles' , 'Check cycles in dependencies', 0 ]
|
||||||
|
options['i'] = [ 'init' , 'Initialize current directory', 0 ]
|
||||||
|
|
||||||
|
class CommandLine(object):
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def executable_name(self):
|
||||||
|
return sys.argv[0]
|
||||||
|
executable_name = irp(executable_name,str)
|
||||||
|
|
||||||
|
def usage(self):
|
||||||
|
t = """
|
||||||
|
$EXE - $DESCR
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
$EXE [OPTION]
|
||||||
|
|
||||||
|
Options:
|
||||||
|
"""
|
||||||
|
t = t.replace("$EXE",self.executable_name)
|
||||||
|
t = t.replace("$DESCR",description)
|
||||||
|
print t
|
||||||
|
sorted = options.keys()
|
||||||
|
sorted.sort()
|
||||||
|
for o in sorted:
|
||||||
|
print " -%s , --%15s : %s"%(o,options[o][0].ljust(15),options[o][1])
|
||||||
|
if options[o][2] == 1:
|
||||||
|
print " Requires an argument"
|
||||||
|
print ""
|
||||||
|
print "Version : ", version
|
||||||
|
print ""
|
||||||
|
|
||||||
|
def opts(self):
|
||||||
|
optlist = ["",[]]
|
||||||
|
for o in options.keys():
|
||||||
|
b = [o]+options[o]
|
||||||
|
if b[3] == 1:
|
||||||
|
b[0] = b[0]+":"
|
||||||
|
b[1] = b[1]+"="
|
||||||
|
optlist[0] += b[0]
|
||||||
|
optlist[1] += [b[1]]
|
||||||
|
|
||||||
|
try:
|
||||||
|
opts, args = getopt.getopt(sys.argv[1:], optlist[0], optlist[1])
|
||||||
|
except getopt.GetoptError, err:
|
||||||
|
# print help information and exit:
|
||||||
|
self.usage()
|
||||||
|
print str(err) # will print something like "option -a not recognized"
|
||||||
|
sys.exit(2)
|
||||||
|
|
||||||
|
return opts
|
||||||
|
opts = irp(opts,list,tuple,str)
|
||||||
|
|
||||||
|
t = """
|
||||||
|
def do_$LONG(self):
|
||||||
|
result = False
|
||||||
|
for o,a in self.opts:
|
||||||
|
if o in ("-$SHORT", "--$LONG"):
|
||||||
|
result = True
|
||||||
|
break
|
||||||
|
return result
|
||||||
|
do_$LONG = irp(do_$LONG,bool)
|
||||||
|
"""
|
||||||
|
for short in options.keys():
|
||||||
|
long = options[short][0]
|
||||||
|
exec t.replace("$LONG",long).replace("$SHORT",short)
|
||||||
|
|
||||||
|
def do_run(self):
|
||||||
|
result = not (self.do_version or self.do_init)
|
||||||
|
return result
|
||||||
|
do_run = irp(do_run,bool)
|
||||||
|
|
||||||
|
|
||||||
|
command_line = CommandLine()
|
35
src/error.py
Normal file
35
src/error.py
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
import sys
|
||||||
|
from irpf90_t import *
|
||||||
|
|
||||||
|
######################################################################
|
||||||
|
def fail(line,message):
|
||||||
|
assert isinstance(line,Line)
|
||||||
|
print """
|
||||||
|
Error:
|
||||||
|
-----
|
||||||
|
"""
|
||||||
|
if line.i > 0:
|
||||||
|
print "file %s, line %d:\n%s"%(line.filename,line.i,line.text)
|
||||||
|
print message, '\n'
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
######################################################################
|
||||||
|
def warn(line,message):
|
||||||
|
assert isinstance(line,Line)
|
||||||
|
print """
|
||||||
|
Warning:
|
||||||
|
-------
|
||||||
|
"""
|
||||||
|
if line.i > 0:
|
||||||
|
print "file %s, line %d:\n%s"%(line.filename,line.i,line.text)
|
||||||
|
print message, '\n'
|
||||||
|
|
||||||
|
|
||||||
|
######################################################################
|
||||||
|
if __name__ == '__main__':
|
||||||
|
line = Empty_line(3,"empty", "testfile")
|
||||||
|
fail(line, "Message")
|
||||||
|
|
45
src/init.py
Normal file
45
src/init.py
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
|
import util
|
||||||
|
import makefile
|
||||||
|
import irpf90_t
|
||||||
|
|
||||||
|
initialized = False
|
||||||
|
|
||||||
|
|
||||||
|
def init():
|
||||||
|
|
||||||
|
global initialized
|
||||||
|
if initialized:
|
||||||
|
return
|
||||||
|
|
||||||
|
# Create directories
|
||||||
|
for dir in [ irpf90_t.irpdir, irpf90_t.mandir ]:
|
||||||
|
try:
|
||||||
|
wd = os.getcwd()
|
||||||
|
os.chdir(dir)
|
||||||
|
os.chdir(wd)
|
||||||
|
except OSError:
|
||||||
|
os.mkdir(dir)
|
||||||
|
|
||||||
|
# Create makefile
|
||||||
|
makefile.create()
|
||||||
|
|
||||||
|
# Copy current files in the irpdir
|
||||||
|
for filename in os.listdir(os.getcwd()):
|
||||||
|
if not filename[0].startswith(".") and not os.path.isdir(filename):
|
||||||
|
file = open(filename,"r")
|
||||||
|
buffer = file.readlines()
|
||||||
|
file.close()
|
||||||
|
if not util.same_file(irpf90_t.irpdir+filename,buffer):
|
||||||
|
file = open(filename,"r")
|
||||||
|
buffer = file.read()
|
||||||
|
file.close()
|
||||||
|
file = open(irpf90_t.irpdir+filename,"w")
|
||||||
|
file.write(buffer)
|
||||||
|
file.close()
|
||||||
|
|
||||||
|
initialized = True
|
||||||
|
|
111
src/irp_stack.py
Normal file
111
src/irp_stack.py
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
import util
|
||||||
|
from command_line import command_line
|
||||||
|
|
||||||
|
do_assert = command_line.do_assert
|
||||||
|
do_debug = command_line.do_debug
|
||||||
|
do_openmp = command_line.do_openmp
|
||||||
|
|
||||||
|
import irpf90_t
|
||||||
|
|
||||||
|
FILENAME = irpf90_t.irpdir+"irp_stack.irp.F90"
|
||||||
|
|
||||||
|
def create():
|
||||||
|
|
||||||
|
txt = """
|
||||||
|
module irp_stack_mod
|
||||||
|
integer, parameter :: STACKMAX=1000
|
||||||
|
character*(128),allocatable :: irp_stack(:,:)
|
||||||
|
double precision,allocatable :: irp_cpu(:,:)
|
||||||
|
integer,allocatable :: stack_index(:)
|
||||||
|
logical :: alloc = .False.
|
||||||
|
character*(128) :: white = ''
|
||||||
|
end module
|
||||||
|
|
||||||
|
subroutine irp_enter(irp_where)
|
||||||
|
use irp_stack_mod
|
||||||
|
integer :: ithread
|
||||||
|
integer :: nthread
|
||||||
|
character*(*) :: irp_where
|
||||||
|
ithread = 0
|
||||||
|
nthread = 1
|
||||||
|
$1
|
||||||
|
$2
|
||||||
|
end subroutine
|
||||||
|
|
||||||
|
subroutine irp_leave (irp_where)
|
||||||
|
use irp_stack_mod
|
||||||
|
character*(*) :: irp_where
|
||||||
|
integer :: ithread
|
||||||
|
double precision :: cpu
|
||||||
|
ithread = 0
|
||||||
|
$3
|
||||||
|
$4
|
||||||
|
end subroutine
|
||||||
|
"""
|
||||||
|
|
||||||
|
# $1
|
||||||
|
if do_assert or do_debug:
|
||||||
|
txt = txt.replace("$1","""
|
||||||
|
!$OMP CRITICAL
|
||||||
|
if (.not.alloc) then
|
||||||
|
allocate(irp_stack(STACKMAX,nthread))
|
||||||
|
allocate(irp_cpu(STACKMAX,nthread))
|
||||||
|
allocate(stack_index(nthread))
|
||||||
|
alloc = .True.
|
||||||
|
endif
|
||||||
|
!$OMP END CRITICAL
|
||||||
|
stack_index(ithread+1) = stack_index(ithread+1)+1
|
||||||
|
irp_stack(stack_index(ithread+1),ithread+1) = irp_where""")
|
||||||
|
else:
|
||||||
|
txt = txt.replace("$1","")
|
||||||
|
|
||||||
|
# $2
|
||||||
|
if do_debug:
|
||||||
|
txt = txt.replace("$2","""
|
||||||
|
print *, ithread, ':', white(1:stack_index(ithread+1))//'-> ', trim(irp_where)
|
||||||
|
call cpu_time(irp_cpu(stack_index(ithread+1),ithread+1))""")
|
||||||
|
else:
|
||||||
|
txt = txt.replace("$2","")
|
||||||
|
|
||||||
|
# $3
|
||||||
|
if do_debug:
|
||||||
|
txt = txt.replace("$3","""
|
||||||
|
call cpu_time(cpu)
|
||||||
|
print *, ithread, ':', white(1:stack_index(ithread+1))//'<- ', &
|
||||||
|
trim(irp_stack(stack_index(ithread+1),ithread+1)), &
|
||||||
|
cpu-irp_cpu(stack_index(ithread+1),ithread+1)""")
|
||||||
|
else:
|
||||||
|
txt = txt.replace("$3","")
|
||||||
|
|
||||||
|
# $4
|
||||||
|
if do_debug or do_assert:
|
||||||
|
txt = txt.replace("$4","""
|
||||||
|
stack_index(ithread+1) = stack_index(ithread+1)-1""")
|
||||||
|
else:
|
||||||
|
txt = txt.replace("$4","")
|
||||||
|
|
||||||
|
if do_debug or do_assert:
|
||||||
|
txt += """
|
||||||
|
subroutine irp_trace
|
||||||
|
use irp_stack_mod
|
||||||
|
integer :: ithread
|
||||||
|
integer :: i
|
||||||
|
ithread = 0
|
||||||
|
if (.not.alloc) return
|
||||||
|
print *, 'Stack trace: ', ithread
|
||||||
|
print *, '-------------------------'
|
||||||
|
do i=1,stack_index(ithread+1)
|
||||||
|
print *, trim(irp_stack(i,ithread+1))
|
||||||
|
enddo
|
||||||
|
print *, '-------------------------'
|
||||||
|
end subroutine
|
||||||
|
"""
|
||||||
|
|
||||||
|
if not util.same_file(FILENAME, txt):
|
||||||
|
file = open(FILENAME,'w')
|
||||||
|
file.write(txt)
|
||||||
|
file.close()
|
||||||
|
|
||||||
|
|
21
src/irpf90.py
Normal file
21
src/irpf90.py
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
def main():
|
||||||
|
from command_line import command_line
|
||||||
|
|
||||||
|
if command_line.do_version:
|
||||||
|
from version import version
|
||||||
|
print version
|
||||||
|
return
|
||||||
|
|
||||||
|
from init import init
|
||||||
|
if command_line.do_init:
|
||||||
|
init()
|
||||||
|
if not command_line.do_run:
|
||||||
|
return
|
||||||
|
|
||||||
|
init()
|
||||||
|
import irp_stack
|
||||||
|
irp_stack.create()
|
||||||
|
|
||||||
|
main()
|
264
src/irpf90_t.py
Normal file
264
src/irpf90_t.py
Normal file
@ -0,0 +1,264 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
irpdir = "IRPF90_temp/"
|
||||||
|
mandir = "IRPF90_man/"
|
||||||
|
|
||||||
|
|
||||||
|
class Line(object):
|
||||||
|
def __init__(self,i,text,filename):
|
||||||
|
self.i = i
|
||||||
|
self.text = text
|
||||||
|
self.filename = filename
|
||||||
|
|
||||||
|
class Empty_line(Line):
|
||||||
|
def __init__(self,i,text,filename):
|
||||||
|
Line.__init__(self,i,text,filename)
|
||||||
|
def __repr__(self):
|
||||||
|
return "%20s:%5d : %s"%("Empty_line",self.i,self.text)
|
||||||
|
|
||||||
|
class Simple_line(Line):
|
||||||
|
def __init__(self,i,text,filename):
|
||||||
|
Line.__init__(self,i,text,filename)
|
||||||
|
def __repr__(self):
|
||||||
|
return "%20s:%5d : %s"%("Simple_line",self.i,self.text)
|
||||||
|
|
||||||
|
class Declaration(Line):
|
||||||
|
def __init__(self,i,text,filename):
|
||||||
|
Line.__init__(self,i,text,filename)
|
||||||
|
def __repr__(self):
|
||||||
|
return "%20s:%5d : %s"%("Declaration",self.i,self.text)
|
||||||
|
|
||||||
|
class Continue(Line):
|
||||||
|
def __init__(self,i,text,filename):
|
||||||
|
Line.__init__(self,i,text,filename)
|
||||||
|
def __repr__(self):
|
||||||
|
return "%20s:%5d : %s"%("Continue",self.i,self.text)
|
||||||
|
|
||||||
|
class Begin_provider(Line):
|
||||||
|
def __init__(self,i,text,filename):
|
||||||
|
Line.__init__(self,i,text,filename)
|
||||||
|
def __repr__(self):
|
||||||
|
return "%20s:%5d : %s"%("Begin_provider",self.i,self.text)
|
||||||
|
|
||||||
|
class Cont_provider(Line):
|
||||||
|
def __init__(self,i,text,filename):
|
||||||
|
Line.__init__(self,i,text,filename)
|
||||||
|
def __repr__(self):
|
||||||
|
return "%20s:%5d : %s"%("Cont_provider",self.i,self.text)
|
||||||
|
|
||||||
|
class End_provider(Line):
|
||||||
|
def __init__(self,i,text,filename):
|
||||||
|
Line.__init__(self,i,text,filename)
|
||||||
|
def __repr__(self):
|
||||||
|
return "%20s:%5d : %s"%("End_provider",self.i,self.text)
|
||||||
|
|
||||||
|
class Begin_doc(Line):
|
||||||
|
def __init__(self,i,text,filename):
|
||||||
|
Line.__init__(self,i,text,filename)
|
||||||
|
def __repr__(self):
|
||||||
|
return "%20s:%5d : %s"%("Begin_doc",self.i,self.text)
|
||||||
|
|
||||||
|
class Doc(Line):
|
||||||
|
def __init__(self,i,text,filename):
|
||||||
|
Line.__init__(self,i,text,filename)
|
||||||
|
def __repr__(self):
|
||||||
|
return "%20s:%5d : %s"%("Doc",self.i,self.text)
|
||||||
|
|
||||||
|
class End_doc(Line):
|
||||||
|
def __init__(self,i,text,filename):
|
||||||
|
Line.__init__(self,i,text,filename)
|
||||||
|
def __repr__(self):
|
||||||
|
return "%20s:%5d : %s"%("End_doc",self.i,self.text)
|
||||||
|
|
||||||
|
class Begin_shell(Line):
|
||||||
|
def __init__(self,i,text,filename):
|
||||||
|
Line.__init__(self,i,text,filename)
|
||||||
|
def __repr__(self):
|
||||||
|
return "%20s:%5d : %s"%("Begin_shell",self.i,self.text)
|
||||||
|
|
||||||
|
class End_shell(Line):
|
||||||
|
def __init__(self,i,text,filename):
|
||||||
|
Line.__init__(self,i,text,filename)
|
||||||
|
def __repr__(self):
|
||||||
|
return "%20s:%5d : %s"%("End_shell",self.i,self.text)
|
||||||
|
|
||||||
|
class Assert(Line):
|
||||||
|
def __init__(self,i,text,filename):
|
||||||
|
Line.__init__(self,i,text,filename)
|
||||||
|
def __repr__(self):
|
||||||
|
return "%20s:%5d : %s"%("Assert",self.i,self.text)
|
||||||
|
|
||||||
|
class Touch(Line):
|
||||||
|
def __init__(self,i,text,filename):
|
||||||
|
Line.__init__(self,i,text,filename)
|
||||||
|
def __repr__(self):
|
||||||
|
return "%20s:%5d : %s"%("Touch",self.i,self.text)
|
||||||
|
|
||||||
|
class Irp_read(Line):
|
||||||
|
def __init__(self,i,text,filename):
|
||||||
|
Line.__init__(self,i,text,filename)
|
||||||
|
def __repr__(self):
|
||||||
|
return "%20s:%5d : %s"%("Irp_read",self.i,self.text)
|
||||||
|
|
||||||
|
class Irp_write(Line):
|
||||||
|
def __init__(self,i,text,filename):
|
||||||
|
Line.__init__(self,i,text,filename)
|
||||||
|
def __repr__(self):
|
||||||
|
return "%20s:%5d : %s"%("Irp_write",self.i,self.text)
|
||||||
|
|
||||||
|
class Irp_If(Line):
|
||||||
|
def __init__(self,i,text,filename):
|
||||||
|
Line.__init__(self,i,text,filename)
|
||||||
|
def __repr__(self):
|
||||||
|
return "%20s:%5d : %s"%("Irp_If",self.i,self.text)
|
||||||
|
|
||||||
|
class Irp_Else(Line):
|
||||||
|
def __init__(self,i,text,filename):
|
||||||
|
Line.__init__(self,i,text,filename)
|
||||||
|
def __repr__(self):
|
||||||
|
return "%20s:%5d : %s"%("Irp_Else",self.i,self.text)
|
||||||
|
|
||||||
|
class Irp_Endif(Line):
|
||||||
|
def __init__(self,i,text,filename):
|
||||||
|
Line.__init__(self,i,text,filename)
|
||||||
|
def __repr__(self):
|
||||||
|
return "%20s:%5d : %s"%("Irp_Endif",self.i,self.text)
|
||||||
|
|
||||||
|
class Openmp(Line):
|
||||||
|
def __init__(self,i,text,filename):
|
||||||
|
Line.__init__(self,i,text,filename)
|
||||||
|
def __repr__(self):
|
||||||
|
return "%20s:%5d : %s"%("Openmp",self.i,self.text)
|
||||||
|
|
||||||
|
class Use(Line):
|
||||||
|
def __init__(self,i,text,filename):
|
||||||
|
Line.__init__(self,i,text,filename)
|
||||||
|
def __repr__(self):
|
||||||
|
return "%20s:%5d : %s"%("Use",self.i,self.text)
|
||||||
|
|
||||||
|
class Do(Line):
|
||||||
|
def __init__(self,i,text,filename):
|
||||||
|
Line.__init__(self,i,text,filename)
|
||||||
|
def __repr__(self):
|
||||||
|
return "%20s:%5d : %s"%("Do",self.i,self.text)
|
||||||
|
|
||||||
|
class Enddo (Line):
|
||||||
|
def __init__(self,i,text,filename):
|
||||||
|
Line.__init__(self,i,text,filename)
|
||||||
|
def __repr__(self):
|
||||||
|
return "%20s:%5d : %s"%("Enddo",self.i,self.text)
|
||||||
|
|
||||||
|
class If(Line):
|
||||||
|
def __init__(self,i,text,filename):
|
||||||
|
Line.__init__(self,i,text,filename)
|
||||||
|
def __repr__(self):
|
||||||
|
return "%20s:%5d : %s"%("If",self.i,self.text)
|
||||||
|
|
||||||
|
class Elseif(Line):
|
||||||
|
def __init__(self,i,text,filename):
|
||||||
|
Line.__init__(self,i,text,filename)
|
||||||
|
def __repr__(self):
|
||||||
|
return "%20s:%5d : %s"%("Elseif",self.i,self.text)
|
||||||
|
|
||||||
|
class Else(Line):
|
||||||
|
def __init__(self,i,text,filename):
|
||||||
|
Line.__init__(self,i,text,filename)
|
||||||
|
def __repr__(self):
|
||||||
|
return "%20s:%5d : %s"%("Else",self.i,self.text)
|
||||||
|
|
||||||
|
class Endif(Line):
|
||||||
|
def __init__(self,i,text,filename):
|
||||||
|
Line.__init__(self,i,text,filename)
|
||||||
|
def __repr__(self):
|
||||||
|
return "%20s:%5d : %s"%("Endif",self.i,self.text)
|
||||||
|
|
||||||
|
class Select(Line):
|
||||||
|
def __init__(self,i,text,filename):
|
||||||
|
Line.__init__(self,i,text,filename)
|
||||||
|
def __repr__(self):
|
||||||
|
return "%20s:%5d : %s"%("Select",self.i,self.text)
|
||||||
|
|
||||||
|
class Case(Line):
|
||||||
|
def __init__(self,i,text,filename):
|
||||||
|
Line.__init__(self,i,text,filename)
|
||||||
|
def __repr__(self):
|
||||||
|
return "%20s:%5d : %s"%("Case",self.i,self.text)
|
||||||
|
|
||||||
|
class End_select(Line):
|
||||||
|
def __init__(self,i,text,filename):
|
||||||
|
Line.__init__(self,i,text,filename)
|
||||||
|
def __repr__(self):
|
||||||
|
return "%20s:%5d : %s"%("End_select",self.i,self.text)
|
||||||
|
|
||||||
|
class Program(Line):
|
||||||
|
def __init__(self,i,text,filename):
|
||||||
|
Line.__init__(self,i,text,filename)
|
||||||
|
def __repr__(self):
|
||||||
|
return "%20s:%5d : %s"%("Program",self.i,self.text)
|
||||||
|
|
||||||
|
class Subroutine(Line):
|
||||||
|
def __init__(self,i,text,filename):
|
||||||
|
Line.__init__(self,i,text,filename)
|
||||||
|
def __repr__(self):
|
||||||
|
return "%20s:%5d : %s"%("Subroutine",self.i,self.text)
|
||||||
|
|
||||||
|
class Function(Line):
|
||||||
|
def __init__(self,i,text,filename):
|
||||||
|
Line.__init__(self,i,text,filename)
|
||||||
|
def __repr__(self):
|
||||||
|
return "%20s:%5d : %s"%("Function",self.i,self.text)
|
||||||
|
|
||||||
|
class Call(Line):
|
||||||
|
def __init__(self,i,text,filename):
|
||||||
|
Line.__init__(self,i,text,filename)
|
||||||
|
def __repr__(self):
|
||||||
|
return "%20s:%5d : %s"%("Call",self.i,self.text)
|
||||||
|
|
||||||
|
class Provide(Line):
|
||||||
|
def __init__(self,i,text,filename):
|
||||||
|
Line.__init__(self,i,text,filename)
|
||||||
|
def __repr__(self):
|
||||||
|
return "%20s:%5d : %s"%("Provide",self.i,self.text)
|
||||||
|
|
||||||
|
class Return (Line):
|
||||||
|
def __init__(self,i,text,filename):
|
||||||
|
Line.__init__(self,i,text,filename)
|
||||||
|
def __repr__(self):
|
||||||
|
return "%20s:%5d : %s"%("Return",self.i,self.text)
|
||||||
|
|
||||||
|
class Include(Line):
|
||||||
|
def __init__(self,i,text,filename):
|
||||||
|
Line.__init__(self,i,text,filename)
|
||||||
|
def __repr__(self):
|
||||||
|
return "%20s:%5d : %s"%("Include",self.i,self.text)
|
||||||
|
|
||||||
|
class Implicit (Line):
|
||||||
|
def __init__(self,i,text,filename):
|
||||||
|
Line.__init__(self,i,text,filename)
|
||||||
|
def __repr__(self):
|
||||||
|
return "%20s:%5d : %s"%("Implicit",self.i,self.text)
|
||||||
|
|
||||||
|
class Free(Line):
|
||||||
|
def __init__(self,i,text,filename):
|
||||||
|
Line.__init__(self,i,text,filename)
|
||||||
|
def __repr__(self):
|
||||||
|
return "%20s:%5d : %s"%("Free",self.i,self.text)
|
||||||
|
|
||||||
|
class End(Line):
|
||||||
|
def __init__(self,i,text,filename):
|
||||||
|
Line.__init__(self,i,text,filename)
|
||||||
|
def __repr__(self):
|
||||||
|
return "%20s:%5d : %s"%("End",self.i,self.text)
|
||||||
|
|
||||||
|
class Provide_all (Line):
|
||||||
|
def __init__(self,i,text,filename):
|
||||||
|
Line.__init__(self,i,text,filename)
|
||||||
|
def __repr__(self):
|
||||||
|
return "%20s:%5d : %s"%("Provide_all",self.i,self.text)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
34
src/makefile.py
Normal file
34
src/makefile.py
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
import irpf90_t
|
||||||
|
irpdir = irpf90_t.irpdir
|
||||||
|
mandir = irpf90_t.mandir
|
||||||
|
|
||||||
|
FILENAME = "Makefile"
|
||||||
|
|
||||||
|
|
||||||
|
def create():
|
||||||
|
has_makefile = True
|
||||||
|
try:
|
||||||
|
file = open(FILENAME,"r")
|
||||||
|
except OSError:
|
||||||
|
has_makefile = False
|
||||||
|
if has_makefile:
|
||||||
|
return
|
||||||
|
file = open(FILENAME,"w")
|
||||||
|
t = """IRPF90 = irpf90 #-a -d
|
||||||
|
FC = gfortran
|
||||||
|
FCFLAGS= -ffree-line-length-none -O2
|
||||||
|
|
||||||
|
SRC=
|
||||||
|
OBJ=
|
||||||
|
LIB=
|
||||||
|
|
||||||
|
include irpf90.make
|
||||||
|
|
||||||
|
irpf90.make: $(wildcard *.irp.f)
|
||||||
|
\t$(IRPF90)
|
||||||
|
"""
|
||||||
|
file.write(t)
|
||||||
|
file.close()
|
||||||
|
|
319
src/preprocessed_text.py
Normal file
319
src/preprocessed_text.py
Normal file
@ -0,0 +1,319 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
from irpf90_t import *
|
||||||
|
from regexps import *
|
||||||
|
import error
|
||||||
|
|
||||||
|
# Local regular expressions
|
||||||
|
re_endif = re.compile("end\s+if")
|
||||||
|
re_elseif = re.compile("else\s+if")
|
||||||
|
re_enddo = re.compile("end\s+do")
|
||||||
|
re_endselect = re.compile("end\s+select")
|
||||||
|
|
||||||
|
# Local variables
|
||||||
|
Free_form = 0
|
||||||
|
Fixed_form = 1
|
||||||
|
|
||||||
|
|
||||||
|
######################################################################
|
||||||
|
def get_type (i, filename, line, is_doc):
|
||||||
|
'''Find the type of a text line'''
|
||||||
|
assert isinstance(i,int)
|
||||||
|
assert isinstance(filename,str)
|
||||||
|
assert isinstance(line,str)
|
||||||
|
assert isinstance(is_doc,bool)
|
||||||
|
|
||||||
|
line = line.rstrip()
|
||||||
|
lower_line0 = line.lstrip().lower()
|
||||||
|
lower_line = lower_line0.replace("!"," ! ")
|
||||||
|
|
||||||
|
# Replacements
|
||||||
|
lower_line = re_elseif.sub("elseif",lower_line)
|
||||||
|
lower_line = re_enddo.sub("enddo",lower_line)
|
||||||
|
lower_line = re_endif.sub("endif",lower_line)
|
||||||
|
lower_line = re_endselect.sub("endselect",lower_line)
|
||||||
|
for c in """()'"[]""":
|
||||||
|
lower_line = lower_line.replace(c," ")
|
||||||
|
|
||||||
|
buffer = lower_line.split()
|
||||||
|
if len(buffer) == 0:
|
||||||
|
return [ Empty_line(i,line,filename) ], is_doc
|
||||||
|
|
||||||
|
firstword = buffer[0]
|
||||||
|
if firstword.isdigit():
|
||||||
|
assert len(buffer) > 1
|
||||||
|
buffer = buffer[1:]
|
||||||
|
firstword = buffer[0]
|
||||||
|
|
||||||
|
# Detect errors
|
||||||
|
if firstword == "dowhile":
|
||||||
|
error.fail( Do(i,line,filename) , "'do while' should be in 2 words." )
|
||||||
|
|
||||||
|
# Identify line
|
||||||
|
if firstword == "end_doc":
|
||||||
|
return [ End_doc (i,line,filename) ], False
|
||||||
|
|
||||||
|
if firstword == "begin_doc":
|
||||||
|
return [ Begin_doc (i,line,filename) ], True
|
||||||
|
|
||||||
|
if is_doc:
|
||||||
|
return [ Doc (i,line,filename) ], is_doc
|
||||||
|
|
||||||
|
# Dictionary of simple statements
|
||||||
|
simple_dict = {
|
||||||
|
"program": [ Program (i,line,filename) ] ,
|
||||||
|
"subroutine": [ Subroutine (i,line,filename) ] ,
|
||||||
|
"begin_shell": [ Begin_shell (i,line,filename) ] ,
|
||||||
|
"end_shell": [ End_shell (i,line,filename) ] ,
|
||||||
|
"end_doc": [ End_doc (i,line,filename) ] ,
|
||||||
|
"begin_provider": [ Begin_provider (i,line,filename) ] ,
|
||||||
|
"&begin_provider": [ Cont_provider (i,line,filename) ] ,
|
||||||
|
"end_provider": [ End_provider (i,line,filename) ] ,
|
||||||
|
"assert": [ Assert (i,line,filename) ] ,
|
||||||
|
"touch": [ Touch (i,line,filename) ] ,
|
||||||
|
"provide": [ Provide (i,line,filename) ] ,
|
||||||
|
"free": [ Free (i,line,filename) ] ,
|
||||||
|
"irp_if": [ Irp_If (i,line,filename) ] ,
|
||||||
|
"irp_else": [ Irp_Else (i,line,filename) ] ,
|
||||||
|
"irp_endif": [ Irp_Endif (i,line,filename) ] ,
|
||||||
|
"irp_read": [ Irp_read (i,line,filename) ] ,
|
||||||
|
"irp_write": [ Irp_write (i,line,filename) ] ,
|
||||||
|
"use": [ Use (i,line,filename) ] ,
|
||||||
|
"do": [ Do (i,line,filename) ] ,
|
||||||
|
"selectcase": [ Select (i,"",filename) ,
|
||||||
|
Simple_line (i,line,filename) ] ,
|
||||||
|
"select": [ Select (i,"",filename) ,
|
||||||
|
Simple_line (i,line,filename) ] ,
|
||||||
|
"if": [ If (i,line,filename) ] ,
|
||||||
|
"case": [ Case (i,line,filename) ] ,
|
||||||
|
"elseif": [ Elseif (i,line,filename) ] ,
|
||||||
|
"else": [ Else (i,line,filename) ] ,
|
||||||
|
"enddo": [ Enddo (i,line,filename) ] ,
|
||||||
|
"endif": [ Endif (i,line,filename) ] ,
|
||||||
|
"endselect": [ End_select (i,line,filename) ] ,
|
||||||
|
"end": [ End (i,line,filename) ] ,
|
||||||
|
"include": [ Include (i,line,filename) ] ,
|
||||||
|
"call": [ Call (i,line,filename) ] ,
|
||||||
|
"continue": [ Continue (i,line,filename) ] ,
|
||||||
|
"return": [ Return (i,line,filename) ] ,
|
||||||
|
"implicit": [ Implicit (i,line,filename) ] ,
|
||||||
|
"save": [ Declaration (i,line,filename) ] ,
|
||||||
|
"function": [ Function (i,line,filename) ] ,
|
||||||
|
"recursive": [ Function (i,line,filename) ] ,
|
||||||
|
}
|
||||||
|
|
||||||
|
if firstword in simple_dict.keys():
|
||||||
|
return simple_dict[firstword], is_doc
|
||||||
|
|
||||||
|
if len(lower_line0) > 4:
|
||||||
|
|
||||||
|
if firstword[0] == '#':
|
||||||
|
result = [ Simple_line(i,line,filename) ]
|
||||||
|
error.warn ( result ,
|
||||||
|
"""irpf90 may not work with preprocessor directives. You can use
|
||||||
|
Irp_if ... Irp_else ... Irp_endif
|
||||||
|
instead of
|
||||||
|
#ifdef ... #else ... #endif""" )
|
||||||
|
return result, is_doc
|
||||||
|
|
||||||
|
if firstword.startswith("case("):
|
||||||
|
return [ Case(i,line,filename) ], is_doc
|
||||||
|
|
||||||
|
if lower_line0[1:5] == "$omp":
|
||||||
|
return [ Openmp(i,line,filename) ], is_doc
|
||||||
|
|
||||||
|
if re_decl.match(lower_line) is not None:
|
||||||
|
if "function" in buffer[1:3]:
|
||||||
|
return [ Function (i,line,filename) ], is_doc
|
||||||
|
else:
|
||||||
|
return [ Declaration (i,line,filename) ], is_doc
|
||||||
|
|
||||||
|
return [ Simple_line(i,line,filename) ], is_doc
|
||||||
|
|
||||||
|
|
||||||
|
######################################################################
|
||||||
|
def get_text(lines,filename):
|
||||||
|
'''Read the input file and transform it to labeled lines'''
|
||||||
|
assert isinstance(filename,str)
|
||||||
|
assert isinstance(lines,list)
|
||||||
|
|
||||||
|
result = []
|
||||||
|
is_doc = False
|
||||||
|
for i,line in enumerate(lines):
|
||||||
|
line, is_doc = get_type(i+1,filename,line,is_doc)
|
||||||
|
result += line
|
||||||
|
assert not is_doc
|
||||||
|
return result
|
||||||
|
|
||||||
|
######################################################################
|
||||||
|
def execute_shell(text):
|
||||||
|
'''Execute the embedded shell scripts'''
|
||||||
|
def fail(l,a,b): error.fail(l,"In Begin_Shell, %s '%s'"%(a,b))
|
||||||
|
inside = False
|
||||||
|
result = []
|
||||||
|
for line in text:
|
||||||
|
if inside:
|
||||||
|
if isinstance(line,Begin_shell):
|
||||||
|
error.fail(line,"Nested Begin_shell")
|
||||||
|
elif isinstance(line,End_shell):
|
||||||
|
inside = False
|
||||||
|
# Write script file
|
||||||
|
scriptname = "%s_shell_%d"%(line.filename,line.i)
|
||||||
|
file = open(scriptname,'w')
|
||||||
|
file.writelines(script)
|
||||||
|
file.close()
|
||||||
|
# Execute shell
|
||||||
|
import os
|
||||||
|
pipe = os.popen("%s < %s"%(shell,scriptname),'r')
|
||||||
|
lines = pipe.readlines()
|
||||||
|
pipe.close()
|
||||||
|
result += get_text(lines,scriptname)
|
||||||
|
else:
|
||||||
|
script.append(line.text+'\n')
|
||||||
|
else:
|
||||||
|
if isinstance(line,Begin_shell):
|
||||||
|
inside = True
|
||||||
|
begin = line.i
|
||||||
|
script = []
|
||||||
|
# Find shell executable
|
||||||
|
buffer = line.text.split('[')
|
||||||
|
if len(buffer) > 2:
|
||||||
|
fail(line,"Too many",'[')
|
||||||
|
elif len(buffer) < 2:
|
||||||
|
fail(line,"Missing",'[')
|
||||||
|
buffer = buffer[1]
|
||||||
|
buffer = buffer.split(']')
|
||||||
|
if len(buffer) > 2:
|
||||||
|
fail(line,"Too many",']')
|
||||||
|
elif len(buffer) < 2:
|
||||||
|
fail(line,"Missing",']')
|
||||||
|
shell = buffer[0].strip()
|
||||||
|
elif isinstance(line,End_shell):
|
||||||
|
error.fail(line,"Begin_shell missing")
|
||||||
|
else:
|
||||||
|
result.append(line)
|
||||||
|
return result
|
||||||
|
|
||||||
|
######################################################################
|
||||||
|
def form(text):
|
||||||
|
'''Find if the text is in fixed form or in free form'''
|
||||||
|
assert isinstance(text,list)
|
||||||
|
if len(text) == 0:
|
||||||
|
return Free_form
|
||||||
|
assert isinstance(text[0],Line)
|
||||||
|
|
||||||
|
re2 = re.compile(r"^\s*[!#]")
|
||||||
|
re3 = re.compile(r"^\s*[^ 0-9]+")
|
||||||
|
for line in text:
|
||||||
|
if isinstance(line,Empty_line) or \
|
||||||
|
isinstance(line,Doc) or \
|
||||||
|
isinstance(line,Openmp):
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
if len(line.text) > 5:
|
||||||
|
test = line.text[0:5]
|
||||||
|
if test[0] in "Cc#!*":
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
if re2.match(test) is None and \
|
||||||
|
re3.match(test) is not None:
|
||||||
|
return Free_form
|
||||||
|
return Fixed_form
|
||||||
|
|
||||||
|
######################################################################
|
||||||
|
def remove_comments(text,form):
|
||||||
|
'''Remove all comments'''
|
||||||
|
result = []
|
||||||
|
|
||||||
|
def remove_after_bang(line):
|
||||||
|
match = re_comment.match(line)
|
||||||
|
if match is None:
|
||||||
|
return line
|
||||||
|
else:
|
||||||
|
return re_comment.split(line)[1].rstrip()
|
||||||
|
|
||||||
|
if form == Free_form:
|
||||||
|
for line in text:
|
||||||
|
if isinstance(line,Openmp) or \
|
||||||
|
isinstance(line,Doc):
|
||||||
|
result.append(line)
|
||||||
|
elif isinstance(line,Empty_line):
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
newline = line.text.lstrip()
|
||||||
|
if newline == "" or newline[0] == "!":
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
line.text = remove_after_bang(line.text)
|
||||||
|
result.append(line)
|
||||||
|
return result
|
||||||
|
else:
|
||||||
|
for line in text:
|
||||||
|
if isinstance(line,Openmp) or \
|
||||||
|
isinstance(line,Doc):
|
||||||
|
result.append(line)
|
||||||
|
elif isinstance(line,Empty_line):
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
line.text = remove_after_bang(line.text)
|
||||||
|
if line.text[0] in "#123456789 ":
|
||||||
|
result.append(line)
|
||||||
|
return result
|
||||||
|
|
||||||
|
######################################################################
|
||||||
|
def remove_continuation(text,form):
|
||||||
|
'''Removes continuation lines'''
|
||||||
|
result = []
|
||||||
|
buffer = ""
|
||||||
|
number = 0
|
||||||
|
if form == Free_form:
|
||||||
|
for line in text:
|
||||||
|
if line.text[-1] == '&':
|
||||||
|
buffer = "%s%s "%(buffer,line.text[:-1].lstrip())
|
||||||
|
if number == 0:
|
||||||
|
number = line.i
|
||||||
|
else:
|
||||||
|
if number != 0:
|
||||||
|
line.text = "%s%s"%(buffer,line.text.lstrip())
|
||||||
|
line.i = number
|
||||||
|
number = 0
|
||||||
|
buffer = ""
|
||||||
|
result.append(line)
|
||||||
|
else:
|
||||||
|
rev_text = list(text)
|
||||||
|
rev_text.reverse()
|
||||||
|
for line in rev_text:
|
||||||
|
is_continuation = False
|
||||||
|
if isinstance(line,Simple_line):
|
||||||
|
if len(line.text) >= 6:
|
||||||
|
if line.text[5] != ' ':
|
||||||
|
is_continuation = True
|
||||||
|
if is_continuation:
|
||||||
|
buffer = "%s %s"%(line.text[6:].lstrip(),buffer)
|
||||||
|
else:
|
||||||
|
line.text = line.text+buffer
|
||||||
|
result.insert(0,line)
|
||||||
|
buffer = ""
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
######################################################################
|
||||||
|
def preprocessed_text(filename):
|
||||||
|
file = open(filename,"r")
|
||||||
|
lines = file.readlines()
|
||||||
|
file.close()
|
||||||
|
result = get_text(lines,filename)
|
||||||
|
result = execute_shell(result)
|
||||||
|
fortran_form = form(result)
|
||||||
|
result = remove_comments(result,fortran_form)
|
||||||
|
result = remove_continuation(result,fortran_form)
|
||||||
|
return result
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
txt = preprocessed_text('testfile.irp.f')
|
||||||
|
for line in txt:
|
||||||
|
print line
|
||||||
|
txt = preprocessed_text('testfile_fixed.irp.f')
|
||||||
|
for line in txt:
|
||||||
|
print line
|
||||||
|
|
37
src/regexps.py
Normal file
37
src/regexps.py
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
import re
|
||||||
|
|
||||||
|
re_comment = re.compile(r"^([^'!]*)('[^']*'[^']*)*!")
|
||||||
|
|
||||||
|
re_decl = re.compile( "".join( [ r"^\ *",
|
||||||
|
r"(integer *(::)?",
|
||||||
|
r"|double *precision *(::)?",
|
||||||
|
r"|logical *(::)?",
|
||||||
|
r"|character *(::)?",
|
||||||
|
r"|real *(::)?",
|
||||||
|
r"|dimension *(::)?",
|
||||||
|
r"|parameter *(::)?",
|
||||||
|
r"|data */",
|
||||||
|
r"|allocatable *(::)?",
|
||||||
|
r"|common */",
|
||||||
|
r"|namelist */",
|
||||||
|
r"|save */",
|
||||||
|
r"|complex *(::)?",
|
||||||
|
r"|intrinsic *(::)?",
|
||||||
|
r"|external *(::)?",
|
||||||
|
r"|equivalence *(::)?",
|
||||||
|
r")[^=(]"
|
||||||
|
] ) )
|
||||||
|
|
||||||
|
re_left = re.compile(r"\[")
|
||||||
|
re_right = re.compile(r"\]")
|
||||||
|
|
||||||
|
re_test = re.compile(r"\( *(.*)(\.[a-zA-Z]*\.|[<>]=?|[=/]=)([^=]*)\)")
|
||||||
|
|
||||||
|
re_space = re.compile("\s")
|
||||||
|
|
||||||
|
re_string = re.compile(r"'.*'")
|
||||||
|
re_assert = re.compile(r"assert *",re.I)
|
||||||
|
re_check = re.compile(r".*[() ].*")
|
||||||
|
|
24
src/util.py
Normal file
24
src/util.py
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
def same_file(filename,txt):
|
||||||
|
assert isinstance(filename,str)
|
||||||
|
assert isinstance(txt,list)
|
||||||
|
|
||||||
|
try:
|
||||||
|
file = open(filename,"r")
|
||||||
|
except IOError:
|
||||||
|
return False
|
||||||
|
lines = file.readlines()
|
||||||
|
file.close()
|
||||||
|
if len(lines) != len(txt):
|
||||||
|
return False
|
||||||
|
for a,b in zip(lines,txt):
|
||||||
|
if a != b:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
txt = open('/etc/passwd','r').readlines()
|
||||||
|
print same_file('/etc/passwd',txt)
|
||||||
|
print same_file('/etc/group',txt)
|
||||||
|
print same_file('/etc/passwd-',txt)
|
1
src/version.py
Normal file
1
src/version.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
version = "1.1.0"
|
13
tools/commit-msg
Executable file
13
tools/commit-msg
Executable file
@ -0,0 +1,13 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
import os,sys
|
||||||
|
ROOT = os.path.dirname(__file__)+'/../../'
|
||||||
|
file = open(ROOT+'src/version.py','r')
|
||||||
|
exec file
|
||||||
|
file.close()
|
||||||
|
file = open(sys.argv[1],'a')
|
||||||
|
print >>file, 'Version:'+version
|
||||||
|
file.close()
|
||||||
|
|
||||||
|
|
||||||
|
|
10
tools/install_tools.sh
Executable file
10
tools/install_tools.sh
Executable file
@ -0,0 +1,10 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
OLD_DIR=$PWD
|
||||||
|
cd ../.git/hooks/
|
||||||
|
|
||||||
|
for i in commit-msg post-commit
|
||||||
|
do
|
||||||
|
rm $i
|
||||||
|
ln -s $OLD_DIR/$i $PWD/$i
|
||||||
|
done
|
18
tools/post-commit
Executable file
18
tools/post-commit
Executable file
@ -0,0 +1,18 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
import os
|
||||||
|
ROOT = os.path.dirname(__file__)+'/../../'
|
||||||
|
|
||||||
|
file = open(ROOT+'src/version.py','r') ;
|
||||||
|
exec file
|
||||||
|
file.close() ;
|
||||||
|
v = version.split('.')
|
||||||
|
v = map(int,v)
|
||||||
|
|
||||||
|
v[2] += 1
|
||||||
|
line = 'version = "%d.%d.%d"\n'%tuple(v)
|
||||||
|
|
||||||
|
file = open(ROOT+'src/version.py','w')
|
||||||
|
file.writelines([line])
|
||||||
|
file.close()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user