Code indexing in gitaly is broken and leads to code not being visible to the user. We work on the issue with highest priority.

Skip to content
Snippets Groups Projects
Commit 0cbf2cd6 authored by ulrich_y's avatar ulrich_y
Browse files

Added routine for hot switching of double / quad

parent 8037e23a
No related branches found
No related tags found
No related merge requests found
import re
import sys
def parsedec(l):
if "::" in l:
l = l.split("::")[-1]
else:
l = l.split("(kind=prec)")[-1]
l = l.split('=')[0]
return [
re.sub(
'\(.*?\)',
'',
i.strip()
) for i in l.split(',')]
def expand_switch(block):
prec = re.sub(
"END FUNCTION (.*)", r"END FUNCTION \1prec",
re.sub(
"^( *)FUNCTION (.*?)\((.*?)\)",
r"\1FUNCTION \2prec(\3) result(\2)",
block,
flags=re.S|re.M
)
)
cond = re.findall("!BEGIN SWITCHEROO\n(.*?)\n!CODE", block, flags=re.M|re.S)
if len(cond) == 1:
cond = cond[0]
prec = prec.replace("!BEGIN SWITCHEROO\n"+cond+"\n!CODE", "")
else:
cond = ".false."
interfaces = []
for func, args, body in re.findall("^ *FUNCTION (.*?)\((.*?)\)(.*?)END FUNCTION", block,flags=re.M|re.S):
iface = " FUNCTION %s(%s)\n" % (func, args)
lines = body.splitlines()
realvars = []
cmplxvars = []
while len(lines) > 0:
l = lines.pop(0).strip()
if len(l) == 0: continue
if l.startswith("implicit ") or l.startswith("use "):
iface += ' ' + l + '\n'
elif l.startswith("real(kind=prec)"):
iface += ' ' + l + '\n'
realvars += parsedec(l)
elif l.startswith("complex(kind=prec)"):
iface += ' ' + l + '\n'
cmplxvars += parsedec(l)
elif l.startswith("integer"):
iface += ' ' + l + '\n'
else:
break
argsex = re.sub('[&\n ]','',args).split(',')
if not all([i in realvars or i in cmplxvars for i in argsex]):
sys.stderr.write("Some args are not defined. Please check your code\n")
args16 = [
("real(%s, kind=16)" if i in realvars else "cmplx(%s, kind=16)") % i
for i in argsex
]
ind = ', &\n ' + (' '*len(" %s = %s16" % (func, func)))
iface += " if(%s) then\n" % cond
iface += " %s = %s16(%s)\n" % (func, func, ind.join(args16))
iface += " else\n"
iface += " %s = %s8 (%s)\n" % (func, func, args)
iface += " endif\n"
iface += " END FUNCTION "+func
interfaces.append(iface)
return prec.replace('prec', '16') + '\n\n' + prec.replace('prec', '8') + '\n\n\n' + '\n\n'.join(interfaces)
with open(sys.argv[1]) as fp:
buf=fp.read()
print re.sub(
"!BEGIN SWITCHEROO.*?!END SWITCHEROO",
lambda m : expand_switch(m.group()),
buf,
flags=re.M|re.S
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment