• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2"""Generates the builtins map to be used by host_init_verifier.
3
4It copies the builtin function map from builtins.cpp, then replaces do_xxx() functions with the
5equivalent check_xxx() if found in check_builtins.cpp.
6
7"""
8
9import re
10import argparse
11
12parser = argparse.ArgumentParser('host_builtin_map.py')
13parser.add_argument('--builtins', required=True, help='Path to builtins.cpp')
14parser.add_argument('--check_builtins', required=True, help='Path to check_builtins.cpp')
15args = parser.parse_args()
16
17CHECK_REGEX = re.compile(r'.+check_(\S+)\(.+')
18check_functions = []
19with open(args.check_builtins) as check_file:
20  for line in check_file:
21    match = CHECK_REGEX.match(line)
22    if match:
23      check_functions.append(match.group(1))
24
25function_map = []
26with open(args.builtins) as builtins_file:
27  in_function_map = False
28  for line in builtins_file:
29    if '// Builtin-function-map start' in line:
30      in_function_map = True
31    elif '// Builtin-function-map end' in line:
32      in_function_map = False
33    elif in_function_map:
34      function_map.append(line)
35
36DO_REGEX = re.compile(r'.+do_([^\}]+).+')
37FUNCTION_REGEX = re.compile(r'(do_[^\}]+)')
38for line in function_map:
39  match = DO_REGEX.match(line)
40  if match:
41    if match.group(1) in check_functions:
42      line = line.replace('do_', 'check_')
43    else:
44      line = FUNCTION_REGEX.sub('check_stub', line)
45  print(line, end=' ')
46