Home | History | Annotate | Download | only in abtest
      1 #!/usr/bin/env python
      2 #
      3 # Mark functions in an arm assembly file. This is done by surrounding the
      4 # function with "# -- Begin Name" and "# -- End Name"
      5 # (This script is designed for arm ios assembly syntax)
      6 import sys
      7 import re
      8 
      9 inp = open(sys.argv[1], "r").readlines()
     10 
     11 # First pass
     12 linenum = 0
     13 INVALID=-100
     14 last_align = INVALID
     15 last_code = INVALID
     16 last_globl = INVALID
     17 begin = INVALID
     18 begins = dict()
     19 for line in inp:
     20     linenum += 1
     21     if ".align" in line:
     22         last_align = linenum
     23     if ".code" in line:
     24         last_code = linenum
     25     if ".globl" in line:
     26         last_globl = linenum
     27     m = re.search(r'.thumb_func\s+(\w+)', line)
     28     if m:
     29         funcname = m.group(1)
     30         if last_code == last_align+1 and (linenum - last_code) < 4:
     31             begin = last_align
     32             if last_globl+1 == last_align:
     33                 begin = last_globl
     34     if line == "\n" and begin != INVALID:
     35         end = linenum
     36         triple = (funcname, begin, end)
     37         begins[begin] = triple
     38         begin = INVALID
     39 
     40 # Second pass: Mark
     41 out = open(sys.argv[1], "w")
     42 in_func = None
     43 linenum = 0
     44 for line in inp:
     45     linenum += 1
     46     if in_func is not None and linenum == end:
     47         out.write("# -- End  %s\n" % in_func)
     48         in_func = None
     49 
     50     triple = begins.get(linenum)
     51     if triple is not None:
     52         in_func, begin, end = triple
     53         out.write("# -- Begin  %s\n" % in_func)
     54     out.write(line)
     55