10
0
mirror of https://gitlab.com/scemama/irpf90.git synced 2024-12-22 12:23:32 +01:00

Compiles with Python3

This commit is contained in:
Anthony Scemama 2020-01-27 18:43:22 +01:00
parent 2ea0e86564
commit 8b773a9d45
25 changed files with 141 additions and 138 deletions

View File

@ -0,0 +1,4 @@
# For relative imports to work in Python 3.6
import os, sys
sys.path = [ os.path.dirname(os.path.realpath(__file__)) ] + sys.path

View File

@ -25,10 +25,10 @@
# scemama@irsamc.ups-tlse.fr # scemama@irsamc.ups-tlse.fr
from .irpf90_t import * from irpf90_t import *
from .util import * from util import *
from .variables import variables from variables import variables
from .modules import modules from modules import modules
CHECKPOINT_UNIT_NUMBER=63 CHECKPOINT_UNIT_NUMBER=63

View File

@ -24,8 +24,8 @@
# 31062 Toulouse Cedex 4 # 31062 Toulouse Cedex 4
# scemama@irsamc.ups-tlse.fr # scemama@irsamc.ups-tlse.fr
from .command_line import command_line from command_line import command_line
from . import irpf90_t import irpf90_t
def run(): def run():
template = """ template = """

View File

@ -26,7 +26,7 @@
import getopt, sys import getopt, sys
from .version import version from version import version
import re import re
description = "IRPF90 Fortran preprocessor." description = "IRPF90 Fortran preprocessor."
@ -248,9 +248,9 @@ def do_$LONG(self):
return self._do_$LONG return self._do_$LONG
do_$LONG = property(fget=do_$LONG) do_$LONG = property(fget=do_$LONG)
""" """
for short in options: for short_opt in options:
long = options[short][0] long_opt = options[short_opt][0]
exec(t.replace("$LONG",int).replace("$SHORT",short)) #in locals() exec(t.replace("$LONG",long_opt).replace("$SHORT",short_opt)) #in locals()
def do_run(self): def do_run(self):
if '_do_run' not in self.__dict__: if '_do_run' not in self.__dict__:

View File

@ -25,12 +25,12 @@
# scemama@irsamc.ups-tlse.fr # scemama@irsamc.ups-tlse.fr
from .variable import Variable from variable import Variable
from .variables import variables from variables import variables
from .subroutine import Sub from subroutine import Sub
from .subroutines import subroutines from subroutines import subroutines
from .irpf90_t import * from irpf90_t import *
from .util import * from util import *
def do_print_short(file,var): def do_print_short(file,var):
@ -295,7 +295,7 @@ def do_print_subroutines_rst(sub):
###################################################################### ######################################################################
def run(): def run():
from . import parsed_text import parsed_text
import os,sys import os,sys
pid1 = os.fork() pid1 = os.fork()
if pid1 == 0: if pid1 == 0:

View File

@ -26,8 +26,8 @@
import sys import sys
from .irpf90_t import * from irpf90_t import *
from .command_line import command_line from command_line import command_line
do_warnings = command_line.do_warnings do_warnings = command_line.do_warnings
###################################################################### ######################################################################

View File

@ -27,10 +27,10 @@
import os import os
from . import util import util
from . import makefile import makefile
from . import irpf90_t import irpf90_t
from .command_line import command_line from command_line import command_line
initialized = False initialized = False

View File

@ -25,14 +25,14 @@
# scemama@irsamc.ups-tlse.fr # scemama@irsamc.ups-tlse.fr
from . import util import util
from .command_line import command_line from command_line import command_line
do_debug = command_line.do_debug do_debug = command_line.do_debug
do_openmp = command_line.do_openmp do_openmp = command_line.do_openmp
do_memory = command_line.do_memory do_memory = command_line.do_memory
from . import irpf90_t import irpf90_t
FILENAME = irpf90_t.irpdir+"irp_stack.irp.F90" FILENAME = irpf90_t.irpdir+"irp_stack.irp.F90"

View File

@ -26,16 +26,15 @@
from . import vim import vim
import os,sys import os,sys
try: try:
wd = os.path.abspath(os.path.dirname(__file__)) wd = os.path.abspath(os.path.dirname(__file__))
sys.path.insert(0,(wd+"/../src/")) sys.path.insert(0,(wd+"/../src/"))
except: except:
pass pass
sys.setcheckinterval(1000)
from .command_line import command_line from command_line import command_line
def main(): def main():
@ -45,16 +44,16 @@ def main():
command_line.usage() command_line.usage()
if command_line.do_version: if command_line.do_version:
from .version import version from version import version
print(version) print(version)
from .init import init from init import init
if command_line.do_init: if command_line.do_init:
init() init()
if command_line.do_preprocess: if command_line.do_preprocess:
init() init()
from .preprocessed_text import preprocessed_text from preprocessed_text import preprocessed_text
for filename,text in preprocessed_text: for filename,text in preprocessed_text:
if filename in command_line.preprocessed: if filename in command_line.preprocessed:
for line in text: for line in text:
@ -62,7 +61,7 @@ def main():
if command_line.do_touch: if command_line.do_touch:
from .variables import variables from variables import variables
for var in command_line.touched: for var in command_line.touched:
if var not in variables: if var not in variables:
print("%s is not an IRP entity"%(var,)) print("%s is not an IRP entity"%(var,))
@ -79,39 +78,39 @@ def main():
init() init()
from . import irp_stack import irp_stack
irp_stack.create() irp_stack.create()
from . import makefile import makefile
makefile.create() makefile.create()
if command_line.do_codelet: if command_line.do_codelet:
from . import profile import profile
profile.build_rdtsc() profile.build_rdtsc()
from . import codelet import codelet
codelet.run() codelet.run()
from .modules import modules, write_module from modules import modules, write_module
for m in list(modules.keys()): for m in list(modules.keys()):
write_module(modules[m]) write_module(modules[m])
makefile.run() makefile.run()
from . import touches import touches
touches.create() touches.create()
# import checkpoint # import checkpoint
# checkpoint.create() # checkpoint.create()
from . import create_man import create_man
create_man.run() create_man.run()
if command_line.do_profile: if command_line.do_profile:
from . import profile import profile
profile.run() profile.run()
if command_line.do_openmp: if command_line.do_openmp:
from . import locks import locks
locks.create() locks.create()
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -29,7 +29,7 @@ from zlib import crc32
irpdir = "IRPF90_temp/" irpdir = "IRPF90_temp/"
mandir = "IRPF90_man/" mandir = "IRPF90_man/"
irp_id = abs(crc32(os.getcwd())) irp_id = abs(crc32(os.getcwd().encode()))
class Line(object): class Line(object):
@ -387,7 +387,7 @@ class Provide_all (Line):
def create_irpf90_files(): def create_irpf90_files():
result = [] result = []
from .command_line import command_line from command_line import command_line
import os import os
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('.')

View File

@ -29,7 +29,7 @@ import os
import sys import sys
wd = os.path.abspath(os.path.dirname(__file__)) wd = os.path.abspath(os.path.dirname(__file__))
from .irpf90_t import mandir from irpf90_t import mandir
filename = sys.argv[1].lower()+".l" filename = sys.argv[1].lower()+".l"
if filename not in os.listdir(mandir): if filename not in os.listdir(mandir):
print("%s does not exist"%(sys.argv[1])) print("%s does not exist"%(sys.argv[1]))

View File

@ -25,11 +25,11 @@
# scemama@irsamc.ups-tlse.fr # scemama@irsamc.ups-tlse.fr
from .command_line import command_line from command_line import command_line
from .irpf90_t import * from irpf90_t import *
from .util import * from util import *
from .variables import variables from variables import variables
FILENAME=irpdir+'irp_locks.irp.F90' FILENAME=irpdir+'irp_locks.irp.F90'
def create(): def create():

View File

@ -26,8 +26,8 @@
import os,sys import os,sys
from . import irpf90_t import irpf90_t
from .command_line import command_line from command_line import command_line
irpdir = irpf90_t.irpdir irpdir = irpf90_t.irpdir
mandir = irpf90_t.mandir mandir = irpf90_t.mandir
@ -82,12 +82,12 @@ def create_gitignore():
###################################################################### ######################################################################
def run_ninja(): def run_ninja():
from . import ninja import ninja
ninja.run() ninja.run()
###################################################################### ######################################################################
def run_make(): def run_make():
from .modules import modules from modules import modules
mod = [] mod = []
for m in list(modules.values()): for m in list(modules.values()):
mod.append(m) mod.append(m)

View File

@ -25,12 +25,12 @@
# scemama@irsamc.ups-tlse.fr # scemama@irsamc.ups-tlse.fr
from .irpf90_t import * from irpf90_t import *
from .variable import * from variable import *
from .variables import variables from variables import variables
from .command_line import command_line from command_line import command_line
from . import preprocessed_text import preprocessed_text
from .util import * from util import *
class Fmodule(object): class Fmodule(object):
@ -67,7 +67,7 @@ class Fmodule(object):
def variables(self): def variables(self):
if '_variables' not in self.__dict__: if '_variables' not in self.__dict__:
from .variables import variables from variables import variables
name = self.name name = self.name
self._variables = [x for x in variables if variables[x].fmodule == name] self._variables = [x for x in variables if variables[x].fmodule == name]
return self._variables return self._variables
@ -119,8 +119,8 @@ class Fmodule(object):
def residual_text(self): def residual_text(self):
if '_residual_text' not in self.__dict__: if '_residual_text' not in self.__dict__:
from .variables import build_use, call_provides from variables import build_use, call_provides
from .parsed_text import move_to_top from parsed_text import move_to_top
def remove_providers(text): def remove_providers(text):
result = [] result = []
inside = False inside = False
@ -215,7 +215,7 @@ class Fmodule(object):
###################################################################### ######################################################################
if __name__ == '__main__': if __name__ == '__main__':
from .parsed_text import parsed_text from parsed_text import parsed_text
for filename, text in parsed_text: for filename, text in parsed_text:
if filename == 'vmc_step.irp.f': if filename == 'vmc_step.irp.f':
x = Fmodule(text,filename) x = Fmodule(text,filename)

View File

@ -25,10 +25,10 @@
# scemama@irsamc.ups-tlse.fr # scemama@irsamc.ups-tlse.fr
from .irpf90_t import * from irpf90_t import *
from .parsed_text import parsed_text from parsed_text import parsed_text
from .module import Fmodule from module import Fmodule
from .util import * from util import *
###################################################################### ######################################################################
def create_modules(): def create_modules():

View File

@ -26,9 +26,9 @@
import os,sys import os,sys
from . import irpf90_t from import irpf90_t
from .command_line import command_line from command_line import command_line
from .modules import modules from modules import modules
irpdir = irpf90_t.irpdir irpdir = irpf90_t.irpdir
mandir = irpf90_t.mandir mandir = irpf90_t.mandir
irp_id = irpf90_t.irp_id irp_id = irpf90_t.irp_id
@ -257,7 +257,7 @@ veryclean: clean
""".format(irpdir, targets) """.format(irpdir, targets)
from . import makefile import makefile
with open(makefile.IRPF90_MAKE,'w') as file: with open(makefile.IRPF90_MAKE,'w') as file:
file.write(result) file.write(result)

View File

@ -25,13 +25,13 @@
# scemama@irsamc.ups-tlse.fr # scemama@irsamc.ups-tlse.fr
from .util import * from util import *
from .irpf90_t import * from irpf90_t import *
from .variables import variables from variables import variables
from .preprocessed_text import preprocessed_text from preprocessed_text import preprocessed_text
from .subroutines import subroutines from subroutines import subroutines
import regexps, re import regexps, re
from . import error import error
vtuple = [(v, variables[v].same_as, variables[v].regexp) for v in list(variables.keys())] vtuple = [(v, variables[v].same_as, variables[v].regexp) for v in list(variables.keys())]
stuple = [(s, subroutines[s].regexp) for s in list(subroutines.keys())] stuple = [(s, subroutines[s].regexp) for s in list(subroutines.keys())]
@ -497,7 +497,7 @@ parsed_text = result
###################################################################### ######################################################################
from .command_line import command_line from command_line import command_line
def check_opt(): def check_opt():
if not command_line.do_checkopt: if not command_line.do_checkopt:

View File

@ -24,11 +24,11 @@
# 31062 Toulouse Cedex 4 # 31062 Toulouse Cedex 4
# scemama@irsamc.ups-tlse.fr # scemama@irsamc.ups-tlse.fr
from .irpf90_t import * from irpf90_t import *
from .regexps import * from regexps import *
from . import error import error
from .command_line import command_line from command_line import command_line
from .util import * from util import *
# Local regular expressions # Local regular expressions
re_endif = re.compile("end\s+if") re_endif = re.compile("end\s+if")

View File

@ -45,7 +45,7 @@ import subprocess
import tempfile import tempfile
import os import os
import threading import threading
from .irpf90_t import irpdir from irpf90_t import irpdir
def build_rdtsc(): def build_rdtsc():
filename = irpdir+"irp_rdtsc.c" filename = irpdir+"irp_rdtsc.c"
@ -60,7 +60,7 @@ def build_rdtsc():
threading.Thread(target=t).start() threading.Thread(target=t).start()
def build_module(): def build_module():
from .variables import variables 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)

View File

@ -25,9 +25,9 @@
# scemama@irsamc.ups-tlse.fr # scemama@irsamc.ups-tlse.fr
from .irpf90_t import * from irpf90_t import *
from .util import * from util import *
from . import error import error
class Sub(object): class Sub(object):
@ -75,7 +75,7 @@ class Sub(object):
############################################################ ############################################################
def touches(self): def touches(self):
if '_touches' not in self.__dict__: if '_touches' not in self.__dict__:
from .subroutines import subroutines from subroutines import subroutines
self._touches = [] self._touches = []
for line in [x for x in self.text if type(x) in [Touch, SoftTouch]]: for line in [x for x in self.text if type(x) in [Touch, SoftTouch]]:
self._touches += line.text.split()[1:] self._touches += line.text.split()[1:]
@ -89,7 +89,7 @@ class Sub(object):
############################################################ ############################################################
def needs(self): def needs(self):
if '_needs' not in self.__dict__: if '_needs' not in self.__dict__:
from . import parsed_text import parsed_text
self._needs = make_single(self._needs) self._needs = make_single(self._needs)
return self._needs return self._needs
needs = property(needs) needs = property(needs)
@ -97,7 +97,7 @@ class Sub(object):
############################################################ ############################################################
def to_provide(self): def to_provide(self):
if '_to_provide' not in self.__dict__: if '_to_provide' not in self.__dict__:
from . import parsed_text import parsed_text
return self._to_provide return self._to_provide
to_provide = property(to_provide) to_provide = property(to_provide)
@ -124,8 +124,8 @@ class Sub(object):
###################################################################### ######################################################################
if __name__ == '__main__': if __name__ == '__main__':
from .preprocessed_text import preprocessed_text from preprocessed_text import preprocessed_text
from .variables import variables from variables import variables
from .subroutines import subroutines from subroutines import subroutines
print([variables[x].needs for x in subroutines['full_ci'].needs]) print([variables[x].needs for x in subroutines['full_ci'].needs])
print(subroutines['full_ci'].calls) print(subroutines['full_ci'].calls)

View File

@ -25,14 +25,14 @@
# scemama@irsamc.ups-tlse.fr # scemama@irsamc.ups-tlse.fr
from .util import * from util import *
from .subroutine import * from subroutine import *
from .variables import variables from variables import variables
from .variable import Variable from variable import Variable
from .irpf90_t import * from irpf90_t import *
def create_subroutines(): def create_subroutines():
from .preprocessed_text import preprocessed_text from preprocessed_text import preprocessed_text
result = {} result = {}
for filename, text in preprocessed_text: for filename, text in preprocessed_text:
buffer = [] buffer = []

View File

@ -25,10 +25,10 @@
# scemama@irsamc.ups-tlse.fr # scemama@irsamc.ups-tlse.fr
from .irpf90_t import * from irpf90_t import *
from .util import * from util import *
from .variables import variables from variables import variables
from .modules import modules from modules import modules
FILENAME=irpdir+'irp_touches.irp.F90' FILENAME=irpdir+'irp_touches.irp.F90'

View File

@ -68,7 +68,7 @@ def build_dim_colons(v):
return "(%s)"%(','.join(x)) return "(%s)"%(','.join(x))
from . import error import error
def find_subname(line): def find_subname(line):
buffer = line.lower buffer = line.lower
if not buffer.endswith(')'): if not buffer.endswith(')'):
@ -119,7 +119,7 @@ def put_info(text,filename):
assert type(text) == list assert type(text) == list
if len(text) > 0: if len(text) > 0:
assert type(text[0]) == tuple assert type(text[0]) == tuple
from .irpf90_t import Line from irpf90_t import Line
assert type(text[0][0]) == list assert type(text[0][0]) == list
assert isinstance(text[0][1], Line) assert isinstance(text[0][1], Line)
lenmax = 80 - len(filename) lenmax = 80 - len(filename)

View File

@ -25,10 +25,10 @@
# scemama@irsamc.ups-tlse.fr # scemama@irsamc.ups-tlse.fr
from .irpf90_t import * from irpf90_t import *
from .util import * from util import *
from . import error import error
from .command_line import command_line from command_line import command_line
class Variable(object): class Variable(object):
@ -45,7 +45,7 @@ class Variable(object):
############################################################ ############################################################
def is_touched(self): def is_touched(self):
if '_is_touched' not in self.__dict__: if '_is_touched' not in self.__dict__:
from .variables import variables from variables import variables
result = self.is_read result = self.is_read
for i in self.children: for i in self.children:
if variables[i].is_touched: if variables[i].is_touched:
@ -66,7 +66,7 @@ class Variable(object):
############################################################ ############################################################
def is_written(self): def is_written(self):
if '_is_written' not in self.__dict__: if '_is_written' not in self.__dict__:
from .variables import variables from variables import variables
result = False result = False
for i in self.parents: for i in self.parents:
if variables[i].is_written: if variables[i].is_written:
@ -79,7 +79,7 @@ class Variable(object):
############################################################ ############################################################
def is_read(self): def is_read(self):
if '_is_read' not in self.__dict__: if '_is_read' not in self.__dict__:
from .variables import variables from variables import variables
result = False result = False
for i in self.parents: for i in self.parents:
if variables[i].is_read: if variables[i].is_read:
@ -187,7 +187,7 @@ dimension.
if not self.is_main: if not self.is_main:
self._allocate = [] self._allocate = []
else: else:
from .variables import variables from variables import variables
def f(var): def f(var):
return variables[var].dim != [] return variables[var].dim != []
self._allocate = list(filter ( f, self.others + [self.name] )) self._allocate = list(filter ( f, self.others + [self.name] ))
@ -276,10 +276,10 @@ dimension.
if not self.is_main: if not self.is_main:
self._toucher = [] self._toucher = []
else: else:
from .modules import modules from modules import modules
from .variables import variables from variables import variables
if '_needed_by' not in self.__dict__: if '_needed_by' not in self.__dict__:
from . import parsed_text import parsed_text
parents = self.parents parents = self.parents
parents.sort() parents.sort()
mods = [variables[x].fmodule for x in parents] mods = [variables[x].fmodule for x in parents]
@ -309,8 +309,8 @@ dimension.
if not command_line.do_openmp: if not command_line.do_openmp:
self._locker = [] self._locker = []
else: else:
from .modules import modules from modules import modules
from .variables import variables from variables import variables
name = self.name name = self.name
result = [ "subroutine irp_lock_%s(set)"%(name) ] result = [ "subroutine irp_lock_%s(set)"%(name) ]
result += [ " use omp_lib", result += [ " use omp_lib",
@ -348,8 +348,8 @@ dimension.
self._reader = [] self._reader = []
else: else:
if '_needs' not in self.__dict__: if '_needs' not in self.__dict__:
from . import parsed_text import parsed_text
from .variables import variables from variables import variables
name = self.name name = self.name
result = [ \ result = [ \
"subroutine reader_%s(irp_num)"%(name), "subroutine reader_%s(irp_num)"%(name),
@ -393,9 +393,9 @@ dimension.
if not self.is_main: if not self.is_main:
self._writer = [] self._writer = []
else: else:
from .variables import variables from variables import variables
if '_needs' not in self.__dict__: if '_needs' not in self.__dict__:
from . import parsed_text import parsed_text
name = self.name name = self.name
result = [ \ result = [ \
"subroutine writer_%s(irp_num)"%(name), "subroutine writer_%s(irp_num)"%(name),
@ -464,8 +464,8 @@ dimension.
self._provider = [] self._provider = []
else: else:
if '_to_provide' not in self.__dict__: if '_to_provide' not in self.__dict__:
from . import parsed_text import parsed_text
from .variables import variables, build_use, call_provides from variables import variables, build_use, call_provides
name = self.name name = self.name
same_as = self.same_as same_as = self.same_as
@ -576,8 +576,8 @@ dimension.
if not self.is_main: if not self.is_main:
self._builder = [] self._builder = []
else: else:
from . import parsed_text import parsed_text
from .variables import build_use, call_provides from variables import build_use, call_provides
for filename,buffer in parsed_text.parsed_text: for filename,buffer in parsed_text.parsed_text:
if self.line.filename[0].startswith(filename): if self.line.filename[0].startswith(filename):
break break
@ -642,9 +642,9 @@ dimension.
if '_children' not in self.__dict__: if '_children' not in self.__dict__:
if not self.is_main: if not self.is_main:
self._children = [] self._children = []
from .variables import variables from variables import variables
if '_needs' not in self.__dict__: if '_needs' not in self.__dict__:
from . import parsed_text import parsed_text
result = [] result = []
for x in self.needs: for x in self.needs:
result.append(x) result.append(x)
@ -664,9 +664,9 @@ dimension.
if not self.is_main: if not self.is_main:
self._parents = [] self._parents = []
else: else:
from .variables import variables from variables import variables
if '_needed_by' not in self.__dict__: if '_needed_by' not in self.__dict__:
from . import parsed_text import parsed_text
result = [] result = []
for x in self.needed_by: for x in self.needed_by:
result.append(x) result.append(x)
@ -682,8 +682,8 @@ dimension.
###################################################################### ######################################################################
if __name__ == '__main__': if __name__ == '__main__':
from .preprocessed_text import preprocessed_text from preprocessed_text import preprocessed_text
from .variables import variables from variables import variables
#for v in variables.keys(): #for v in variables.keys():
# print v # print v
def print_dot(x,done): def print_dot(x,done):

View File

@ -25,14 +25,14 @@
# scemama@irsamc.ups-tlse.fr # scemama@irsamc.ups-tlse.fr
from .variable import * from variable import *
from .irpf90_t import * from irpf90_t import *
from .command_line import command_line from command_line import command_line
from .util import * from util import *
###################################################################### ######################################################################
def create_variables(): def create_variables():
from .preprocessed_text import preprocessed_text from preprocessed_text import preprocessed_text
result = {} result = {}
icount = 0 icount = 0
for filename, text in preprocessed_text: for filename, text in preprocessed_text: