From: Tim Wiederhake <twiederh@redhat.com>
To: qemu-devel@nongnu.org
Cc: Tim Wiederhake <twiederh@redhat.com>
Subject: [PATCH 4/4] target/i386: Autogenerate feature_word_info.c.inc
Date: Fri, 11 Aug 2023 15:50:11 +0200 [thread overview]
Message-ID: <20230811135011.23343-5-twiederh@redhat.com> (raw)
In-Reply-To: <20230811135011.23343-1-twiederh@redhat.com>
This introduces no semantic changes to the file.
Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
---
target/i386/feature_word_info.c.inc | 2 +
target/i386/feature_word_info.py | 110 ++++++++++++++++++++++++++++
target/i386/feature_word_info.xml | 3 +
3 files changed, 115 insertions(+)
create mode 100755 target/i386/feature_word_info.py
diff --git a/target/i386/feature_word_info.c.inc b/target/i386/feature_word_info.c.inc
index 040c3c4e56..b8e77ab7e5 100644
--- a/target/i386/feature_word_info.c.inc
+++ b/target/i386/feature_word_info.c.inc
@@ -1,3 +1,5 @@
+/* This file is autogenerated by feature_word_info.py. */
+
FeatureWordInfo feature_word_info[FEATURE_WORDS] = {
[FEAT_1_EDX] = {
.type = CPUID_FEATURE_WORD,
diff --git a/target/i386/feature_word_info.py b/target/i386/feature_word_info.py
new file mode 100755
index 0000000000..95f3931aa0
--- /dev/null
+++ b/target/i386/feature_word_info.py
@@ -0,0 +1,110 @@
+#!/bin/env python3
+
+import lxml.etree
+import os
+
+
+class FeatureWord:
+ def __init__(self, xml):
+ self.index = xml.values()[0]
+ for node in xml:
+ if node.tag == "cpuid":
+ self.cpuid = dict()
+ for child in node:
+ self.cpuid[child.tag] = child.text
+ elif node.tag == "feat_names":
+ self.feat_names = [child.text for child in node]
+ else:
+ setattr(self, node.tag, node.text)
+
+
+def write_feat_names(f, data):
+ f.write(" .feat_names = {\n")
+ for index, name in enumerate(data):
+ if name is None:
+ name = "NULL"
+ if index % 4 == 0:
+ f.write(" " * 11)
+ f.write(" " + str(name) + ",")
+ if index % 4 == 3:
+ f.write("\n")
+ f.write(" },\n")
+
+
+def write_cpuid(f, data):
+ f.write(" .cpuid = {\n")
+ f.write(" .eax = {},\n".format(data["eax"]))
+ if "ecx" in data:
+ f.write(" .needs_ecx = true,\n")
+ f.write(" .ecx = {},\n".format(data["ecx"]))
+ f.write(" .reg = {},\n".format(data["reg"]))
+ f.write(" },\n")
+
+
+def write_msr(f, data):
+ f.write(" .msr = {\n")
+ f.write(" .index = {},\n".format(data))
+ f.write(" },\n")
+
+
+def write_tcg_features(f, data):
+ f.write(" .tcg_features = {},\n".format(data))
+
+
+def write_unmigratable_flags(f, data):
+ f.write(" .unmigratable_flags = {},\n".format(data))
+
+
+def write_migratable_flags(f, data):
+ f.write(" .migratable_flags = {},\n".format(data))
+
+
+def write_no_autoenable_flags(f, data):
+ f.write(" .no_autoenable_flags = {},\n".format(data))
+
+
+def write_feature_word(f, data):
+ f.write(" [{}] = {{\n".format(data.index))
+ f.write(" .type = {},\n".format(data.type))
+ if hasattr(data, "feat_names"):
+ write_feat_names(f, data.feat_names)
+ if hasattr(data, "cpuid"):
+ write_cpuid(f, data.cpuid)
+ if hasattr(data, "msr"):
+ write_msr(f, data.msr)
+ if hasattr(data, "tcg_features"):
+ write_tcg_features(f, data.tcg_features)
+ if hasattr(data, "unmigratable_flags"):
+ write_unmigratable_flags(f, data.unmigratable_flags)
+ if hasattr(data, "migratable_flags"):
+ write_migratable_flags(f, data.migratable_flags)
+ if hasattr(data, "no_autoenable_flags"):
+ write_no_autoenable_flags(f, data.no_autoenable_flags)
+ f.write(" },\n")
+
+
+def write_feature_words(f, data):
+ f.write("/* This file is autogenerated by feature_word_info.py. */\n\n")
+ f.write("FeatureWordInfo feature_word_info[FEATURE_WORDS] = {\n")
+ for feature_word in data:
+ write_feature_word(f, feature_word)
+ f.write("};\n")
+
+
+def main():
+ dirname = os.path.dirname(__file__)
+ ifile = os.path.join(dirname, "feature_word_info.xml")
+ ofile = os.path.join(dirname, "feature_word_info.c.inc")
+
+ parser = lxml.etree.XMLParser(remove_comments=True, remove_blank_text=True)
+ with open(ifile, "tr") as f:
+ doc = lxml.etree.parse(f, parser=parser)
+
+ feature_words = [FeatureWord(node) for node in doc.getroot()]
+
+ with open(ofile, "tw") as f:
+ write_feature_words(f, feature_words)
+
+
+if __name__ == "__main__":
+ main()
diff --git a/target/i386/feature_word_info.xml b/target/i386/feature_word_info.xml
index ff741b9f5a..662b8b1dfc 100644
--- a/target/i386/feature_word_info.xml
+++ b/target/i386/feature_word_info.xml
@@ -1,3 +1,6 @@
+<!--
+ Run `feature_word_info.py` when you make changes to this file.
+-->
<feature_words>
<feature_word index="FEAT_1_EDX">
<type>CPUID_FEATURE_WORD</type>
--
2.39.2
prev parent reply other threads:[~2023-08-11 13:52 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-11 13:50 [PATCH 0/4] Generate x86 cpu features Tim Wiederhake
2023-08-11 13:50 ` [PATCH 1/4] target/i386: Split out feature_word_info Tim Wiederhake
2023-09-06 14:34 ` Philippe Mathieu-Daudé
2023-08-11 13:50 ` [PATCH 2/4] target/i386: Translate feature_word_info to xml Tim Wiederhake
2023-08-17 11:07 ` Daniel P. Berrangé
2023-08-21 9:54 ` Tim Wiederhake
2023-09-06 14:33 ` Philippe Mathieu-Daudé
2023-09-06 14:21 ` Michael S. Tsirkin
2023-08-11 13:50 ` [PATCH 3/4] target/i386: Format feature_word_info.c.inc Tim Wiederhake
2023-08-11 13:50 ` Tim Wiederhake [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230811135011.23343-5-twiederh@redhat.com \
--to=twiederh@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).