xref: /qemu/scripts/qapi/backend.py (revision fc8da54ec43cf6302ac496d8fe54832812954679)
1# This work is licensed under the terms of the GNU GPL, version 2 or later.
2# See the COPYING file in the top-level directory.
3
4from abc import ABC, abstractmethod
5
6from .commands import gen_commands
7from .events import gen_events
8from .features import gen_features
9from .introspect import gen_introspect
10from .schema import QAPISchema
11from .types import gen_types
12from .visit import gen_visit
13
14
15class QAPIBackend(ABC):
16    # pylint: disable=too-few-public-methods
17
18    @abstractmethod
19    def generate(self,
20                 schema: QAPISchema,
21                 output_dir: str,
22                 prefix: str,
23                 unmask: bool,
24                 builtins: bool,
25                 gen_tracing: bool) -> None:
26        """
27        Generate code for the given schema into the target directory.
28
29        :param schema: The primary QAPI schema object.
30        :param output_dir: The output directory to store generated code.
31        :param prefix: Optional C-code prefix for symbol names.
32        :param unmask: Expose non-ABI names through introspection?
33        :param builtins: Generate code for built-in types?
34
35        :raise QAPIError: On failures.
36        """
37
38
39class QAPICBackend(QAPIBackend):
40    # pylint: disable=too-few-public-methods
41
42    def generate(self,
43                 schema: QAPISchema,
44                 output_dir: str,
45                 prefix: str,
46                 unmask: bool,
47                 builtins: bool,
48                 gen_tracing: bool) -> None:
49        """
50        Generate C code for the given schema into the target directory.
51
52        :param schema_file: The primary QAPI schema file.
53        :param output_dir: The output directory to store generated code.
54        :param prefix: Optional C-code prefix for symbol names.
55        :param unmask: Expose non-ABI names through introspection?
56        :param builtins: Generate code for built-in types?
57
58        :raise QAPIError: On failures.
59        """
60        gen_types(schema, output_dir, prefix, builtins)
61        gen_features(schema, output_dir, prefix)
62        gen_visit(schema, output_dir, prefix, builtins)
63        gen_commands(schema, output_dir, prefix, gen_tracing)
64        gen_events(schema, output_dir, prefix)
65        gen_introspect(schema, output_dir, prefix, unmask)
66