summaryrefslogtreecommitdiff
path: root/builtins
diff options
context:
space:
mode:
authorKenneth Graunke <kenneth@whitecape.org>2010-04-28 23:00:43 -0700
committerIan Romanick <ian.d.romanick@intel.com>2010-05-14 16:34:46 -0700
commit4c7367b3f99236dc664d547b7806680ffcf89d15 (patch)
treed0d4479068a7c7218a96bf96f1cd331e1ffce9d4 /builtins
parenta40e68b256c428d8dcaf8b9b1dfb79316af7c050 (diff)
Add a perl script to generate builtin_function.cpp.
Usage: ./builtins/tools/generate_builtins.pl > builtin_function.cpp
Diffstat (limited to 'builtins')
-rwxr-xr-xbuiltins/tools/generate_builtins.pl108
1 files changed, 108 insertions, 0 deletions
diff --git a/builtins/tools/generate_builtins.pl b/builtins/tools/generate_builtins.pl
new file mode 100755
index 0000000000..e7ec8ef56f
--- /dev/null
+++ b/builtins/tools/generate_builtins.pl
@@ -0,0 +1,108 @@
+#!/usr/bin/env perl
+
+
+sub process_version {
+ my ($version) = @_;
+ my @vars;
+ print "/* Version $version builtins */\n\n";
+
+ my @files = <builtins/$version/*>;
+ foreach $file (@files) {
+ push(@vars, process_file($file));
+ }
+
+ print "static const char *functions_for_$version [] = {\n";
+ foreach $var (@vars) {
+ print " $var,\n";
+ }
+ print "};\n\n"
+}
+
+sub process_file {
+ my ($file) = @_;
+
+ # Change from builtins/110/foo to builtins_110_foo
+ my $var = $file; $var =~ s!/!_!g;
+
+ print "static const char *$var = {\n";
+ open SRC, "<", "$file" or die $!;
+ while (<SRC>) {
+ s/\\/\\\\/g;
+ s/\"/\\\"/g;
+ s/\n/\\n/g;
+ print " \"$_\"\n";
+ }
+ print "};\n\n";
+ close SRC or die $!;
+ return $var;
+}
+
+print << 'EOF';
+/* DO NOT MODIFY - automatically generated by generate_builtins.pl */
+/*
+ * Copyright © 2010 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include <stdio.h>
+#include "glsl_parser_extras.h"
+#include "ir_reader.h"
+
+void
+read_builtins(_mesa_glsl_parse_state *st, exec_list *instructions,
+ const char **functions, unsigned count)
+{
+ if (st->error)
+ return;
+
+ for (unsigned i = 0; i < count; i++) {
+ _mesa_glsl_read_ir(st, instructions, functions[i]);
+
+ if (st->error) {
+ printf("error reading builtin: %.35s ...\n", functions[i]);
+ return;
+ }
+ }
+}
+
+EOF
+
+@versions = sort(<builtins/[1-9][0-9][0-9]>);
+foreach $version (@versions) {
+ $version =~ s!builtins/!!g;
+ process_version($version);
+}
+
+print << 'EOF';
+void
+_mesa_glsl_initialize_functions(exec_list *instructions,
+ struct _mesa_glsl_parse_state *state)
+{
+EOF
+
+foreach $version (@versions) {
+ print " if (state->language_version >= $version)\n";
+ print " read_builtins(state, instructions, functions_for_$version,\n";
+ print " sizeof(functions_for_$version) / ";
+ print "sizeof(const char *));\n\n"
+}
+
+print "}\n";