source: icGREP/icgrep-devel/performance/Regxp_cl_fixer.py @ 6053

Last change on this file since 6053 was 4126, checked in by linmengl, 5 years ago

initial checkin of performance script; based on Ben's script, will do correctness check first and record performance data in json format. A python script will be developed to visualize performance difference.

File size: 1.4 KB
Line 
1# This program fix Regxp.cl according to this instruction:
2#
3# 3. Open re.cpp and replace functions in Regxp.cl
4#   a. replace content of classify_bytes_do_block (from do to while)
5#   b. replace content of demo_do_block
6#   c. replace lex structure
7
8import sys
9
10def extract_code_content(start_sign, stop_sign, source_file):   
11        extract = []
12        flag = False
13        for line in open(source_file, 'r'):     
14                if start_sign in line:
15                        flag = True
16
17                if flag:                       
18                        extract.append(line)
19
20                if flag and stop_sign in line:
21                        flag = False
22
23        return extract
24
25if len(sys.argv) < 3:
26        print "Usage: python <this_script> <path to re.cpp> <path to Regxp.cl.template>"
27        exit()
28else:
29        source_file = sys.argv[1]
30        template_file = sys.argv[2]
31        print "Generating Regxp.cl from %s" % source_file
32
33classify_bytes_do_block = extract_code_content("#define classify_bytes_do_block", "} while (0)", source_file)[2:-1]
34demo_do_block = extract_code_content("#define demo_do_block", "} while (0)", source_file)[2:-1]
35lex_definition = extract_code_content("struct Lex {", "};", source_file)[1:-1]
36
37outf = open(template_file.replace('.template', ''), 'w')
38for line in open(template_file):
39        if "{{{@classify_bytes_do_block}}}" in line:
40                outf.write(''.join(classify_bytes_do_block))
41        elif "{{{@demo_do_block}}}" in line:
42                outf.write(''.join(demo_do_block))
43        elif "{{{@lex_definition}}}" in line:
44                outf.write(''.join(lex_definition))
45        else:
46                outf.write(line)
47
48
Note: See TracBrowser for help on using the repository browser.