File: host_builtin_map.py

package info (click to toggle)
android-platform-tools 34.0.5-12
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 150,900 kB
  • sloc: cpp: 805,786; java: 293,500; ansic: 128,288; xml: 127,491; python: 41,481; sh: 14,245; javascript: 9,665; cs: 3,846; asm: 2,049; makefile: 1,917; yacc: 440; awk: 368; ruby: 183; sql: 140; perl: 88; lex: 67
file content (45 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
#!/usr/bin/env python3
"""Generates the builtins map to be used by host_init_verifier.

It copies the builtin function map from builtins.cpp, then replaces do_xxx() functions with the
equivalent check_xxx() if found in check_builtins.cpp.

"""

import re
import argparse

parser = argparse.ArgumentParser('host_builtin_map.py')
parser.add_argument('--builtins', required=True, help='Path to builtins.cpp')
parser.add_argument('--check_builtins', required=True, help='Path to check_builtins.cpp')
args = parser.parse_args()

CHECK_REGEX = re.compile(r'.+check_(\S+)\(.+')
check_functions = []
with open(args.check_builtins) as check_file:
  for line in check_file:
    match = CHECK_REGEX.match(line)
    if match:
      check_functions.append(match.group(1))

function_map = []
with open(args.builtins) as builtins_file:
  in_function_map = False
  for line in builtins_file:
    if '// Builtin-function-map start' in line:
      in_function_map = True
    elif '// Builtin-function-map end' in line:
      in_function_map = False
    elif in_function_map:
      function_map.append(line)

DO_REGEX = re.compile(r'.+do_([^\}]+).+')
FUNCTION_REGEX = re.compile(r'(do_[^\}]+)')
for line in function_map:
  match = DO_REGEX.match(line)
  if match:
    if match.group(1) in check_functions:
      line = line.replace('do_', 'check_')
    else:
      line = FUNCTION_REGEX.sub('check_stub', line)
  print(line, end=' ')