Mesa (master): generate_builtins.py: Output large strings as arrays of characters.

Kenneth Graunke kwg at kemper.freedesktop.org
Thu Oct 21 18:45:43 UTC 2010


Module: Mesa
Branch: master
Commit: 2cacaf6e7b9bc38efd47413b5e667b6e750698b8
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=2cacaf6e7b9bc38efd47413b5e667b6e750698b8

Author: Kenneth Graunke <kenneth at whitecape.org>
Date:   Thu Oct 21 11:42:45 2010 -0700

generate_builtins.py: Output large strings as arrays of characters.

This works around MSVC's 65535 byte limit, unfortunately at the expense
of any semblance of readability and much larger file size.  Hopefully I
can implement a better solution later, but for now this fixes the build.

---

 src/glsl/builtins/tools/generate_builtins.py |   16 ++++++++++++++--
 1 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/src/glsl/builtins/tools/generate_builtins.py b/src/glsl/builtins/tools/generate_builtins.py
index e8191ee..9bde171 100755
--- a/src/glsl/builtins/tools/generate_builtins.py
+++ b/src/glsl/builtins/tools/generate_builtins.py
@@ -25,13 +25,25 @@ def get_builtin_definitions():
     return fs
 
 def stringify(s):
+    # Work around MSVC's 65535 byte limit by outputting an array of characters
+    # rather than actual string literals.
+    if len(s) >= 65535:
+        #t = "/* Warning: length " + repr(len(s)) + " too large */\n"
+	t = ""
+        for c in re.sub('\s\s+', ' ', s):
+            if c == '\n':
+	        t += '\n'
+            else:
+	        t += "'" + c + "',"
+        return '{' + t[:-1] + '}'
+
     t = s.replace('\\', '\\\\').replace('"', '\\"').replace('\n', '\\n"\n   "')
     return '   "' + t + '"\n'
 
 def write_function_definitions():
     fs = get_builtin_definitions()
     for k, v in sorted(fs.iteritems()):
-        print 'static const char *builtin_' + k + ' ='
+        print 'static const char builtin_' + k + '[] ='
         print stringify(v), ';'
 
 def run_compiler(args):
@@ -64,7 +76,7 @@ def write_profile(filename, profile):
     # clutter the diff output.
     proto_ir = re.sub(r'@0x[0-9a-f]+', '', proto_ir);
 
-    print 'static const char *prototypes_for_' + profile + ' ='
+    print 'static const char prototypes_for_' + profile + '[] ='
     print stringify(proto_ir), ';'
 
     # Print a table of all the functions (not signatures) referenced.




More information about the mesa-commit mailing list