v3d: Pass the version being generated to the pack generator script.
authorEric Anholt <eric@anholt.net>
Wed, 27 Jun 2018 17:46:04 +0000 (10:46 -0700)
committerEric Anholt <eric@anholt.net>
Fri, 29 Jun 2018 20:36:28 +0000 (13:36 -0700)
It turns out that most V3D versions change very few packets, so keeping
separate copies of the XML per version makes changing the XML a pain as
you have to replicate your changes to each one.  This is the start of
changing it so that one XML can generate headers for multiple versions.

src/broadcom/Android.genxml.mk
src/broadcom/Makefile.genxml.am
src/broadcom/cle/gen_pack_header.py
src/broadcom/cle/meson.build

index fc5494fb673e07353721be3b2307909c2ff56fee..908569fcc76d3b19de3aa0d76efde5eceada96a0 100644 (file)
@@ -42,26 +42,30 @@ LOCAL_GENERATED_SOURCES += $(addprefix $(intermediates)/broadcom/, $(BROADCOM_GE
 define header-gen
        @mkdir -p $(dir $@)
        @echo "Gen Header: $(PRIVATE_MODULE) <= $(notdir $(@))"
-       $(hide) $(PRIVATE_SCRIPT) $(PRIVATE_SCRIPT_FLAGS) $(PRIVATE_XML) > $@
+       $(hide) $(PRIVATE_SCRIPT) $(PRIVATE_SCRIPT_FLAGS) $(PRIVATE_XML) $(PRIVATE_VER) > $@
 endef
 
 $(intermediates)/broadcom/cle/v3d_packet_v21_pack.h: PRIVATE_SCRIPT := $(MESA_PYTHON2) $(LOCAL_PATH)/cle/gen_pack_header.py
 $(intermediates)/broadcom/cle/v3d_packet_v21_pack.h: PRIVATE_XML := $(LOCAL_PATH)/cle/v3d_packet_v21.xml
+$(intermediates)/broadcom/cle/v3d_packet_v21_pack.h: PRIVATE_VER := 21
 $(intermediates)/broadcom/cle/v3d_packet_v21_pack.h: $(LOCAL_PATH)/cle/v3d_packet_v21.xml $(LOCAL_PATH)/cle/gen_pack_header.py
        $(call header-gen)
 
 $(intermediates)/broadcom/cle/v3d_packet_v33_pack.h: PRIVATE_SCRIPT := $(MESA_PYTHON2) $(LOCAL_PATH)/cle/gen_pack_header.py
 $(intermediates)/broadcom/cle/v3d_packet_v33_pack.h: PRIVATE_XML := $(LOCAL_PATH)/cle/v3d_packet_v33.xml
+$(intermediates)/broadcom/cle/v3d_packet_v33_pack.h: PRIVATE_VER := 33
 $(intermediates)/broadcom/cle/v3d_packet_v33_pack.h: $(LOCAL_PATH)/cle/v3d_packet_v33.xml $(LOCAL_PATH)/cle/gen_pack_header.py
        $(call header-gen)
 
 $(intermediates)/broadcom/cle/v3d_packet_v41_pack.h: PRIVATE_SCRIPT := $(MESA_PYTHON2) $(LOCAL_PATH)/cle/gen_pack_header.py
 $(intermediates)/broadcom/cle/v3d_packet_v41_pack.h: PRIVATE_XML := $(LOCAL_PATH)/cle/v3d_packet_v41.xml
+$(intermediates)/broadcom/cle/v3d_packet_v41_pack.h: PRIVATE_VER := 41
 $(intermediates)/broadcom/cle/v3d_packet_v41_pack.h: $(LOCAL_PATH)/cle/v3d_packet_v41.xml $(LOCAL_PATH)/cle/gen_pack_header.py
        $(call header-gen)
 
 $(intermediates)/broadcom/cle/v3d_packet_v42_pack.h: PRIVATE_SCRIPT := $(MESA_PYTHON2) $(LOCAL_PATH)/cle/gen_pack_header.py
 $(intermediates)/broadcom/cle/v3d_packet_v42_pack.h: PRIVATE_XML := $(LOCAL_PATH)/cle/v3d_packet_v42.xml
+$(intermediates)/broadcom/cle/v3d_packet_v42_pack.h: PRIVATE_VER := 42
 $(intermediates)/broadcom/cle/v3d_packet_v42_pack.h: $(LOCAL_PATH)/cle/v3d_packet_v42.xml $(LOCAL_PATH)/cle/gen_pack_header.py
        $(call header-gen)
 
index 6cfabaebcb87b938cd26369f8605d211667f76ed..7949bf6f705aeed690664b1149fc7b19282fe164 100644 (file)
@@ -30,7 +30,7 @@ $(BROADCOM_GENXML_GENERATED_FILES): cle/gen_pack_header.py
 
 .xml_pack.h:
        $(MKDIR_GEN)
-       $(PYTHON_GEN) $(srcdir)/cle/gen_pack_header.py $< > $@ || ($(RM) $@; false)
+       $(PYTHON_GEN) $(srcdir)/cle/gen_pack_header.py $< `echo $@ | sed -r 's|.*_v([0-9][0-9])_pack.h|\1|g'` > $@ || ($(RM) $@; false)
 
 GEN_ZIPPED = $(srcdir)/../intel/genxml/gen_zipped_file.py
 cle/v3d_xml.h: $(GEN_ZIPPED) $(BROADCOM_GENXML_XML_FILES)
index 5fde7bb07ade99f40d220aad9d158359b05150e1..df547fb5ab1de457148b2e022b9156976f3ad0d6 100644 (file)
@@ -392,7 +392,7 @@ class Value(object):
         self.value = int(attrs["value"])
 
 class Parser(object):
-    def __init__(self):
+    def __init__(self, ver):
         self.parser = xml.parsers.expat.ParserCreate()
         self.parser.StartElementHandler = self.start_element
         self.parser.EndElementHandler = self.end_element
@@ -403,6 +403,7 @@ class Parser(object):
         # Set of enum names we've seen.
         self.enums = set()
         self.registers = {}
+        self.ver = ver
 
     def gen_prefix(self, name):
         if name[0] == "_":
@@ -415,8 +416,7 @@ class Parser(object):
 
     def start_element(self, name, attrs):
         if name == "vcxml":
-            self.platform = "V3D {}".format(attrs["gen"])
-            self.ver = attrs["gen"].replace('.', '')
+            self.platform = "V3D {}.{}".format(self.ver[0], self.ver[1])
             print(pack_header % {'license': license, 'platform': self.platform, 'guard': self.gen_guard()})
         elif name in ("packet", "struct", "register"):
             default_field = None
@@ -579,5 +579,5 @@ if len(sys.argv) < 2:
 
 input_file = sys.argv[1]
 
-p = Parser()
+p = Parser(sys.argv[2])
 p.parse(input_file)
index b1ff8322524eddbe2f934bed8334bbe8d1d12a28..a45538c986f071227af299959e641c67fa7cc083 100644 (file)
@@ -26,30 +26,28 @@ v3d_versions = [
 ]
 
 v3d_xml_files = []
-foreach v: v3d_versions
-  v3d_xml_files += 'v3d_packet_v@0@.xml'.format(v)
-endforeach
-
-v3d_xml_h = custom_target(
-  'v3d_xml.h',
-  input : ['../../intel/genxml/gen_zipped_file.py', v3d_xml_files],
-  output : 'v3d_xml.h',
-  command : [prog_python2, '@INPUT@'],
-  capture : true,
-)
-
 v3d_xml_pack = []
-foreach f : v3d_xml_files
+foreach v : v3d_versions
+  f = 'v3d_packet_v@0@.xml'.format(v)
   _name = '@0@_pack.h'.format(f.split('.')[0])
+  v3d_xml_files += f
   v3d_xml_pack += custom_target(
     _name,
     input : ['gen_pack_header.py', f],
     output : _name,
-    command : [prog_python2, '@INPUT@'],
+    command : [prog_python2, '@INPUT@', '@0@'.format(v)],
     capture : true,
   )
 endforeach
 
+v3d_xml_h = custom_target(
+  'v3d_xml.h',
+  input : ['../../intel/genxml/gen_zipped_file.py', v3d_xml_files],
+  output : 'v3d_xml.h',
+  command : [prog_python2, '@INPUT@'],
+  capture : true,
+)
+
 libbroadcom_cle = static_library(
   ['broadcom_cle', v3d_xml_h],
   'v3d_decoder.c',