Changeset 1802 for trunk


Ignore:
Timestamp:
Dec 21, 2011, 4:58:48 PM (8 years ago)
Author:
cameron
Message:

Recursive fixing

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libgen/fix_idisa_calls.py

    r1801 r1802  
    66# Licensed under Academic Free License, 3.0.
    77#
    8 import sys, re
     8import sys, re, os, shutil, optparse
    99
    1010sisd_to_int_RE = re.compile("sisd_to_int")
     
    2828default_sisd_RE = re.compile("sisd_(store_aligned|store_unaligned|load_aligned|load_unaligned|srl|sll|srli|slli)")
    2929
     30simd_lib_RE = re.compile("lib_simd.h")
    3031
    3132def simd_fixer(s):
     33        s = simd_lib_RE.sub("lib/bitblock.hpp", s)
    3234        s = sisd_from_int_RE.sub("convert", s)
    3335        s = sisd_to_int_RE.sub("mvmd::extract<0>", s)
     
    4648        return s
    4749
    48 if __name__ == '__main__':
    49         infile, outfile = sys.stdin, sys.stdout   # defaults if no arguments
    50         if len(sys.argv) >= 3: outfile = open(sys.argv[2],'w')
    51         if len(sys.argv) >= 2: infile = open(sys.argv[1])
    52        
    53         outfile.write(simd_fixer(infile.read()))
    54         outfile.close()
     50def fix_file(path):
     51        infile = open(path)
     52        indata = infile.read()
     53        infile.close()
     54        outdata = simd_fixer(indata)
     55        if outdata != indata:
     56                print("Modifying %s\n" % (path))
     57                shutil.move(path, path + '.bak')
     58                outfile = open(path, 'w')
     59                outfile.write(outdata)
     60                outfile.close()
     61
     62def fix_directory(path, do_recursive = False):
     63        for f in os.listdir(path):
     64                if os.path.isdir(f):
     65                        if do_recursive: fix_directory(path + "/" + f)
     66                else:
     67                        fix_file(f)
    5568
    5669
     70if __name__ == '__main__':
     71        do_recursive = False
     72        option_parser = optparse.OptionParser(usage='python %prog [options] <input file>', version='1.0')
     73        option_parser.add_option('-r', '--recursive',
     74                          dest = 'do_recursive', action='store_true', default=False,
     75                          help = 'Process subdirectories recursively.')
     76        options, args = option_parser.parse_args(sys.argv[1:])
     77        if len(args) != 1:
     78                option_parser.print_usage()
     79                sys.exit()
     80        if os.path.isdir(args[0]):
     81                fix_directory(args[0], do_recursive)
     82        else:
     83                fix_file(args[0])
     84
     85
Note: See TracChangeset for help on using the changeset viewer.