|
45 | 45 | pn = re.compile('^([\s0-9]{1,5}\s*)call ([a-z0-9_]+)\W', re.IGNORECASE)
|
46 | 46 | pi = re.compile('^(\s+)(if\s*\(.*\))\s*call ([^\(]+)[ ]*(.*)$', re.IGNORECASE)
|
47 | 47 |
|
| 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) |
48 | 50 |
|
49 | 51 | # Check to see if a processed file
|
50 | 52 | # also exists in the list
|
@@ -167,6 +169,84 @@ def processFile(fname):
|
167 | 169 | f.close()
|
168 | 170 | return newlines
|
169 | 171 |
|
| 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 |
170 | 250 |
|
171 | 251 | def outputFile(fname, content):
|
172 | 252 | global nowrite_files,VERBOSE
|
@@ -293,96 +373,14 @@ def main():
|
293 | 373 | for f in files:
|
294 | 374 | try:
|
295 | 375 | content = processFile(f)
|
| 376 | + #content = filterCommonSizeLoops(content, f, VERBOSE) |
296 | 377 | outputFile(f, content)
|
297 | 378 | except Exception as err:
|
298 | 379 | print("Could not process file: %s"%err)
|
299 | 380 |
|
300 | 381 | else:
|
301 | 382 | print("No files to process")
|
302 | 383 |
|
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) |
386 | 384 |
|
387 | 385 | if __name__ == "__main__":
|
388 | 386 | main()
|
0 commit comments