File: qemu-plugin-symbols.py

package info (click to toggle)
qemu 1%3A10.0.3%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 413,680 kB
  • sloc: ansic: 4,733,433; pascal: 114,769; python: 105,506; asm: 68,431; sh: 52,881; makefile: 27,469; perl: 18,778; cpp: 11,435; xml: 3,404; objc: 2,877; yacc: 2,505; php: 1,299; tcl: 1,296; lex: 1,110; sql: 71; awk: 43; sed: 35; javascript: 7
file content (45 lines) | stat: -rwxr-xr-x 1,346 bytes parent folder | download | duplicates (8)
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
# -*- coding: utf-8 -*-
#
# Extract QEMU Plugin API symbols from a header file
#
# Copyright 2024 Linaro Ltd
#
# Author: Pierrick Bouvier <pierrick.bouvier@linaro.org>
#
# This work is licensed under the terms of the GNU GPL, version 2 or later.
# See the COPYING file in the top-level directory.
#
# SPDX-License-Identifier: GPL-2.0-or-later

import argparse
import re

def extract_symbols(plugin_header):
    with open(plugin_header) as file:
        content = file.read()
    # Remove QEMU_PLUGIN_API macro definition.
    content = content.replace('#define QEMU_PLUGIN_API', '')
    expected = content.count('QEMU_PLUGIN_API')
    # Find last word between QEMU_PLUGIN_API and (, matching on several lines.
    # We use *? non-greedy quantifier.
    syms = re.findall(r'QEMU_PLUGIN_API.*?(\w+)\s*\(', content, re.DOTALL)
    syms.sort()
    # Ensure we found as many symbols as API markers.
    assert len(syms) == expected
    return syms

def main() -> None:
    parser = argparse.ArgumentParser(description='Extract QEMU plugin symbols')
    parser.add_argument('plugin_header', help='Path to QEMU plugin header.')
    args = parser.parse_args()

    syms = extract_symbols(args.plugin_header)

    print('{')
    for s in syms:
        print("  {};".format(s))
    print('};')

if __name__ == '__main__':
    main()