Skip to content

Commit f887bd7

Browse files
committed
Removed a lot of old code, and added in a stubed and commented out function that re-generates do loops that use COMMON_INIT.. It works, but it's stubbed and commented out to remove complexity from the fortran files (in essence, I gave up trying to use bounds checking, but didn't want to erase my work in case I pick it up again
1 parent 159fe23 commit f887bd7

File tree

1 file changed

+81
-83
lines changed

1 file changed

+81
-83
lines changed

insert_debug.py

+81-83
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
pn = re.compile('^([\s0-9]{1,5}\s*)call ([a-z0-9_]+)\W', re.IGNORECASE)
4646
pi = re.compile('^(\s+)(if\s*\(.*\))\s*call ([^\(]+)[ ]*(.*)$', re.IGNORECASE)
4747

48+
co = re.compile('^(\s+)do ([a-z]+)=1,\s*COMMON_SIZE.([^)]+).\s*$', re.IGNORECASE)
49+
sd = re.compile("^\s*([a-z0-9_]+)\(.\)\s*=\s*([a-z0-9_]+)\(.*$", re.IGNORECASE)
4850

4951
# Check to see if a processed file
5052
# also exists in the list
@@ -167,6 +169,84 @@ def processFile(fname):
167169
f.close()
168170
return newlines
169171

172+
def filterCommonSizeLoops(lines, fname, VERBOSE):
173+
# Though this filter could be run in the loop above,
174+
# it makes the code more complicated. Plus, this way
175+
# it's simpler to en/disable this filter alone
176+
177+
# Disabling this function
178+
return lines
179+
180+
line0='' # line0 is basically last line
181+
182+
in_common_init = False
183+
src_var = ""
184+
dest_var = ""
185+
main_var = ""
186+
space=""
187+
188+
newlines=[]
189+
190+
for line1, line2 in get_next(lines):
191+
192+
if not line2:
193+
line2=""
194+
195+
#print("Line0: ", line0.strip())
196+
#print("Line1: ", line1.strip())
197+
#print("Line2: ", line2.strip(), "\n")
198+
199+
if in_common_init:
200+
201+
m=sd.match(line2)
202+
203+
if re.match("\s*end\s*do.*", line1):
204+
205+
if len(src_var) == 0:
206+
raise Exception("While replacing COMMON_SIZE loop, could not find source var")
207+
if len(dest_var) == 0:
208+
raise Exception("While replacing COMMON_SIZE loop, could not find destination var")
209+
210+
in_common_init = False
211+
212+
if VERBOSE>0:
213+
print("Replacing a COMMON_SIZE do loop for %s"%main_var)
214+
215+
# Write out stuff
216+
newlines.append("\n%scall mattdebug(\"Calling COMMON_SIZE(%s) - %s\", __LINE__)\n"%(space, main_var, fname))
217+
newlines.append("%s CALL copy_with_offset_1(%s(0), %s(1), COMMON_SIZE(%s))\n"%(space, src_var, dest_var, main_var))
218+
219+
src_var=""
220+
dest_var = ""
221+
main_var = ""
222+
223+
elif m:
224+
src_var=m.group(2)
225+
dest_var=m.group(1)
226+
else:
227+
if VERBOSE>1:
228+
print("src_var=%s, dest_var=%s"%(src_var, dest_var))
229+
230+
231+
else:
232+
# Second filter, modify the COMMON_SIZE do loops
233+
m = co.match(line2)
234+
if m:
235+
236+
in_common_init = True
237+
main_var = m.group(3)
238+
space=m.group(1)
239+
240+
if VERBOSE>0:
241+
print("Matched a COMMON_INIT do loop, main_var=%s"%(main_var))
242+
243+
else:
244+
245+
newlines.append(line1)
246+
247+
line0=line1
248+
249+
return newlines
170250

171251
def outputFile(fname, content):
172252
global nowrite_files,VERBOSE
@@ -293,96 +373,14 @@ def main():
293373
for f in files:
294374
try:
295375
content = processFile(f)
376+
#content = filterCommonSizeLoops(content, f, VERBOSE)
296377
outputFile(f, content)
297378
except Exception as err:
298379
print("Could not process file: %s"%err)
299380

300381
else:
301382
print("No files to process")
302383

303-
#
304-
# # Ver basic for now..
305-
# if VERBOSE>1:
306-
# print("Received %d arguments"%len(sys.argv))
307-
# if len(sys.argv)>2:
308-
# if VERBOSE>2:
309-
# print("Received arguments: %s"%str(sys.argv))
310-
# cmd=sys.argv[1]
311-
# if cmd == "reset" or cmd == "undo":
312-
# # Resetting
313-
# # Some duplicate code here, but doing it in a hurry
314-
# # will regret still later.
315-
#
316-
#
317-
# files=[]
318-
# # Again, improve later when there is time
319-
# if len(sys.argv)==3:
320-
# pf="%s.%s"%(sys.argv[2], processed_suf)
321-
# if not isfile(pf):
322-
# print("File %s was not processed by this script (%s doesn't exist.)"%(sys.argv[2], pf))
323-
# exit(1)
324-
#
325-
# files.append(pf)
326-
# if VERBOSE>0:
327-
# print("Undoing file %s"%pf)
328-
# else:
329-
# files=listdir('.')
330-
#
331-
# if VERBOSE>0:
332-
# print("Files to undo: %s"%" ".join(map(str, files)))
333-
# for pf in files:
334-
# m = re.match("^(.*)\.%s$"%processed_suf, pf)
335-
# if m:
336-
# f = m.group(1)
337-
# if VERBOSE>1:
338-
# print("pf=%s, f=%s"%(pf, f))
339-
#
340-
# changeBack=False
341-
# mode=bool(os.stat(f).st_mode & stat.S_IWUSR)
342-
# if not mode:
343-
# if VERBOSE > 0:
344-
# print("- Setting %s to writable (temporararily)"%f)
345-
# os.chmod(f, os.stat(f).st_mode | stat.S_IWUSR)
346-
# changeBack=True
347-
#
348-
# if VERBOSE>0:
349-
# print("Undoing debug to %s"%pf)
350-
# copyfile(pf, f)
351-
# unlink(pf)
352-
#
353-
# if changeBack:
354-
# if VERBOSE > 0:
355-
# print("- Setting %s to not-writable"%f)
356-
# os.chmod(f, os.stat(f).st_mode & ~stat.S_IWUSR)
357-
# else:
358-
# if VERBOSE>1:
359-
# print("Skipping %s"%pf)
360-
#
361-
# #print("Files to undo: %s"%"\n".join(map(str, files)))
362-
# #exit(1)
363-
# else:
364-
# print("Do not reconginize %s, ABORT"%cmd)
365-
#
366-
# else:
367-
# # Normal operation..
368-
#
369-
# # Get file listing
370-
# files=[]
371-
# for f in listdir('.'):
372-
# # Avoid cdk files
373-
# m=re.match("^([a-z0-9_]+)\.(ftn|ftn90|cdk90)+$", f)
374-
# if m and not any(m.group(1) in s for s in FILE_EXCLUDE_LIST):
375-
# files.append(f)
376-
# #print("Pre-filtered Files: %s"%"\n".join(map(str, files)))
377-
# #exit(0)
378-
# files=filterFiles(files)
379-
# if len(files):
380-
# print("Processing Files: %s"%"\n".join(map(str, files)))
381-
# else:
382-
# print("No files to process")
383-
# for f in files:
384-
# content = processFile(f)
385-
# outputFile(f, content)
386384

387385
if __name__ == "__main__":
388386
main()

0 commit comments

Comments
 (0)