aubinator/genxml: use gzipped files to store embedded genxml
authorLionel Landwerlin <lionel.g.landwerlin@intel.com>
Fri, 10 Mar 2017 16:14:43 +0000 (16:14 +0000)
committerLionel Landwerlin <lionel.g.landwerlin@intel.com>
Mon, 13 Mar 2017 13:36:31 +0000 (13:36 +0000)
This reduces the size of the aubinator binary from ~1.4Mb to ~700Kb.
With can now drop the checks on xxd in configure.

v2: Fix incorrect makefile dependency (Lionel)

v3: use $(PYTHON2) (Emil)

Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
configure.ac
src/intel/Makefile.genxml.am
src/intel/Makefile.tools.am
src/intel/tools/decoder.c

index bc9a9e48ddb02ff7f6b3980264fd77f82742bfd1..a99684bd4343e4cc288ee7a8d620ce3c6fa5c5b4 100644 (file)
@@ -126,7 +126,6 @@ LT_PREREQ([2.2])
 LT_INIT([disable-static])
 
 AC_CHECK_PROG(RM, rm, [rm -f])
-AC_CHECK_PROG(XXD, xxd, [xxd])
 
 AX_PROG_BISON([],
               AS_IF([test ! -f "$srcdir/src/compiler/glsl/glcpp/glcpp-parse.c"],
index 1866d7e2df14623e1a9b4692e3152d28403fe3b3..bea0aab817f858acc6b9129b47f159368d9618df 100644 (file)
@@ -35,18 +35,11 @@ $(GENXML_GENERATED_FILES): genxml/gen_pack_header.py
        $(MKDIR_GEN)
        $(PYTHON_GEN) $(srcdir)/genxml/gen_pack_header.py $< > $@ || ($(RM) $@; false)
 
-# xxd generates variable names based on the path of the input file. We
-# prefer to generate our own name here, so it doesn't vary from
-# in/out-of-tree builds.
-
-$(GENXML_GENERATED_FILES): Makefile.am
+$(GENXML_GENERATED_FILES): genxml/gen_zipped_file.py
 
 .xml_xml.h:
        $(MKDIR_GEN)
-       $(AM_V_GEN) echo -n "static const uint8_t " > $@; \
-       echo "$(@F)_xml[] = {" | sed -e 's,_xml.h,,' >> $@; \
-       cat $< | $(XXD) -i >> $@; \
-       echo "};" >> $@
+       $(AM_V_GEN) $(PYTHON2) $(srcdir)/genxml/gen_zipped_file.py $< > $@ || ($(RM) $@; false)
 
 EXTRA_DIST += \
        genxml/gen4.xml \
index 5838819f255cab9588081b419bd9d7ea7db5b793..3c98c81c87693adeb1d9d3f4611ad4813186cdf1 100644 (file)
@@ -30,7 +30,8 @@ tools_aubinator_SOURCES = \
 
 tools_aubinator_CFLAGS = \
        $(AM_CFLAGS) \
-       $(EXPAT_CFLAGS)
+       $(EXPAT_CFLAGS) \
+       $(ZLIB_CFLAGS)
 
 tools_aubinator_LDADD = \
        common/libintel_common.la \
@@ -40,4 +41,5 @@ tools_aubinator_LDADD = \
        $(PTHREAD_LIBS) \
        $(DLOPEN_LIBS) \
        $(EXPAT_LIBS) \
+       $(ZLIB_LIBS) \
        -lm
index defb0873da0f7112d1115b09f855037bd855d0b4..72913601c048ae9e7ab8742d9ebf57fd1f200b07 100644 (file)
@@ -28,6 +28,7 @@
 #include <string.h>
 #include <expat.h>
 #include <inttypes.h>
+#include <zlib.h>
 
 #include <util/macros.h>
 
@@ -508,13 +509,62 @@ devinfo_to_xml_data(const struct gen_device_info *devinfo,
    return NULL;
 }
 
+static uint32_t zlib_inflate(const void *compressed_data,
+                             uint32_t compressed_len,
+                             void **out_ptr)
+{
+   struct z_stream_s zstream;
+   void *out;
+
+   memset(&zstream, 0, sizeof(zstream));
+
+   zstream.next_in = (unsigned char *)compressed_data;
+   zstream.avail_in = compressed_len;
+
+   if (inflateInit(&zstream) != Z_OK)
+      return 0;
+
+   out = malloc(4096);
+   zstream.next_out = out;
+   zstream.avail_out = 4096;
+
+   do {
+      switch (inflate(&zstream, Z_SYNC_FLUSH)) {
+      case Z_STREAM_END:
+         goto end;
+      case Z_OK:
+         break;
+      default:
+         inflateEnd(&zstream);
+         return 0;
+      }
+
+      if (zstream.avail_out)
+         break;
+
+      out = realloc(out, 2*zstream.total_out);
+      if (out == NULL) {
+         inflateEnd(&zstream);
+         return 0;
+      }
+
+      zstream.next_out = (unsigned char *)out + zstream.total_out;
+      zstream.avail_out = zstream.total_out;
+   } while (1);
+ end:
+   inflateEnd(&zstream);
+   *out_ptr = out;
+   return zstream.total_out;
+}
+
 struct gen_spec *
 gen_spec_load(const struct gen_device_info *devinfo)
 {
    struct parser_context ctx;
    void *buf;
-   const void *data;
-   uint32_t data_length = 0;
+   const void *zlib_data;
+   void *text_data;
+   uint32_t zlib_length = 0, text_length;
 
    memset(&ctx, 0, sizeof ctx);
    ctx.parser = XML_ParserCreate(NULL);
@@ -529,22 +579,26 @@ gen_spec_load(const struct gen_device_info *devinfo)
 
    ctx.spec = xzalloc(sizeof(*ctx.spec));
 
-   data = devinfo_to_xml_data(devinfo, &data_length);
-   buf = XML_GetBuffer(ctx.parser, data_length);
+   zlib_data = devinfo_to_xml_data(devinfo, &zlib_length);
+   text_length = zlib_inflate(zlib_data, zlib_length, &text_data);
 
-   memcpy(buf, data, data_length);
+   buf = XML_GetBuffer(ctx.parser, text_length);
+   memcpy(buf, text_data, text_length);
 
-   if (XML_ParseBuffer(ctx.parser, data_length, true) == 0) {
+   if (XML_ParseBuffer(ctx.parser, text_length, true) == 0) {
       fprintf(stderr,
-              "Error parsing XML at line %ld col %ld: %s\n",
+              "Error parsing XML at line %ld col %ld byte %ld/%u: %s\n",
               XML_GetCurrentLineNumber(ctx.parser),
               XML_GetCurrentColumnNumber(ctx.parser),
+              XML_GetCurrentByteIndex(ctx.parser), text_length,
               XML_ErrorString(XML_GetErrorCode(ctx.parser)));
       XML_ParserFree(ctx.parser);
+      free(text_data);
       return NULL;
    }
 
    XML_ParserFree(ctx.parser);
+   free(text_data);
 
    return ctx.spec;
 }