-
Notifications
You must be signed in to change notification settings - Fork 4
/
analyze.py
32 lines (23 loc) · 994 Bytes
/
analyze.py
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
import clang.cindex
def get_functions(version):
index = clang.cindex.Index.create()
tu = index.parse(f"wasmpy_build/include/{version}/Python.h")
functions = []
for child in tu.cursor.get_children():
if not child.location.file.name.startswith(f"wasmpy_build/include/{version}"):
# exclude external files
continue
if child.kind == clang.cindex.CursorKind.FUNCTION_DECL:
if clang.cindex.conf.lib.clang_Cursor_isFunctionInlined(child):
# inline function
continue
func_result = child.type.get_result().spelling
func_name = child.spelling
func_args = []
# get arguments
for arg in child.get_arguments():
arg_name = arg.spelling
arg_type = arg.type.spelling
func_args.append((arg_type, arg_name))
functions.append((func_result, func_name, func_args))
return functions