File: mark_armfns.py

package info (click to toggle)
llvm-toolchain-4.0 1%3A4.0.1-10~deb9u2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 493,332 kB
  • sloc: cpp: 2,698,100; ansic: 552,773; asm: 128,821; python: 121,589; objc: 105,054; sh: 21,174; lisp: 6,758; ml: 5,532; perl: 5,311; pascal: 5,245; makefile: 2,083; cs: 1,868; xml: 686; php: 212; csh: 117
file content (54 lines) | stat: -rwxr-xr-x 1,415 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python
#
# Mark functions in an arm assembly file. This is done by surrounding the
# function with "# -- Begin Name" and "# -- End Name"
# (This script is designed for arm ios assembly syntax)
import sys
import re

inp = open(sys.argv[1], "r").readlines()

# First pass
linenum = 0
INVALID=-100
last_align = INVALID
last_code = INVALID
last_globl = INVALID
begin = INVALID
begins = dict()
for line in inp:
    linenum += 1
    if ".align" in line:
        last_align = linenum
    if ".code" in line:
        last_code = linenum
    if ".globl" in line:
        last_globl = linenum
    m = re.search(r'.thumb_func\s+(\w+)', line)
    if m:
        funcname = m.group(1)
        if last_code == last_align+1 and (linenum - last_code) < 4:
            begin = last_align
            if last_globl+1 == last_align:
                begin = last_globl
    if line == "\n" and begin != INVALID:
        end = linenum
        triple = (funcname, begin, end)
        begins[begin] = triple
        begin = INVALID

# Second pass: Mark
out = open(sys.argv[1], "w")
in_func = None
linenum = 0
for line in inp:
    linenum += 1
    if in_func is not None and linenum == end:
        out.write("# -- End  %s\n" % in_func)
        in_func = None

    triple = begins.get(linenum)
    if triple is not None:
        in_func, begin, end = triple
        out.write("# -- Begin  %s\n" % in_func)
    out.write(line)