source: proto/parabix2/src/carryq/cq_asm.py @ 1496

Last change on this file since 1496 was 540, checked in by ksherdy, 9 years ago

Rename carry queue directory files.

File size: 1.6 KB
Line 
1import sys
2
3usage = "python carry_queue_asm.py <infile> [outfile]"
4
5def emit_buffer(buffer, outfile):
6    for line in buffer:
7        outfile.write(line)       
8
9def peep_hole_optimize(infile, outfile):
10    f = open(infile)
11   
12    crt_state = 0
13    buffer = []
14    s0_line = ""
15    s1_line = ""
16    s2_line = ""
17    s3_line = ""
18   
19    for line in f.readlines():
20
21        buffer.append(line)
22       
23        if str(line).__contains__("mov $0"):
24            s0_line = line
25            crt_state = 1
26        elif crt_state == 1 and str(line).__contains__("adc"):
27            s1_line = line
28            crt_state = 2   
29        elif crt_state == 2 and str(line).__contains__("add"):
30            s2_line = line
31            crt_state = 3
32        elif crt_state == 3 and str(line).__contains__("adc"):
33            s3_line = line
34            buffer[buffer.index(s3_line)] = s3_line
35            buffer.remove(s0_line)
36            buffer.remove(s1_line)
37            buffer.remove(s2_line)
38            emit_buffer(buffer,outfile)   
39
40            buffer = []
41            crt_state = 0
42            s0_line = ""
43            s1_line = ""
44            s2_line = ""
45            s3_line = ""
46
47    emit_buffer(buffer,outfile)       
48    f.close()
49
50def main():
51    if len(sys.argv) < 2 or len(sys.argv) > 4:
52        print usage
53    else: 
54        infile = sys.argv[1]
55        if len(sys.argv) == 2:
56            peep_hole_optimize(infile, sys.stdout)
57        else:
58            outfile = open(sys.argv[2],"w")
59            peep_hole_optimize(infile, outfile)
60            outfile.close()
61               
62if __name__ == "__main__": main()
Note: See TracBrowser for help on using the repository browser.