summary refs log tree commit diff stats
path: root/scripts/qapi/gen.py
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2021-10-28 12:25:15 +0200
committerMarkus Armbruster <armbru@redhat.com>2021-10-29 15:56:29 +0200
commitc67db1ed16ff5a7c1b186caa754e0c738aa945b8 (patch)
tree49b8efb6f3c2360b238b361ef9bbf9448b3355dd /scripts/qapi/gen.py
parent9bafe07bc8b00ce9ba5ea6f4c590239c579d83ee (diff)
downloadfocaccia-qemu-c67db1ed16ff5a7c1b186caa754e0c738aa945b8.tar.gz
focaccia-qemu-c67db1ed16ff5a7c1b186caa754e0c738aa945b8.zip
qapi: Tools for sets of special feature flags in generated code
New enum QapiSpecialFeature enumerates the special feature flags.

New helper gen_special_features() returns code to represent a
collection of special feature flags as a bitset.

The next few commits will put them to use.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: John Snow <jsnow@redhat.com>
Message-Id: <20211028102520.747396-5-armbru@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Diffstat (limited to 'scripts/qapi/gen.py')
-rw-r--r--scripts/qapi/gen.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py
index 2ec1e7b3b6..995a97d2b8 100644
--- a/scripts/qapi/gen.py
+++ b/scripts/qapi/gen.py
@@ -18,6 +18,7 @@ from typing import (
     Dict,
     Iterator,
     Optional,
+    Sequence,
     Tuple,
 )
 
@@ -29,6 +30,7 @@ from .common import (
     mcgen,
 )
 from .schema import (
+    QAPISchemaFeature,
     QAPISchemaIfCond,
     QAPISchemaModule,
     QAPISchemaObjectType,
@@ -37,6 +39,12 @@ from .schema import (
 from .source import QAPISourceInfo
 
 
+def gen_special_features(features: Sequence[QAPISchemaFeature]) -> str:
+    special_features = [f"1u << QAPI_{feat.name.upper()}"
+                        for feat in features if feat.is_special()]
+    return ' | '.join(special_features) or '0'
+
+
 class QAPIGen:
     def __init__(self, fname: str):
         self.fname = fname