summaryrefslogtreecommitdiff
path: root/src/mesa/shader/slang/slang_compile.c
diff options
context:
space:
mode:
authorMichal Krol <mjkrol@gmail.org>2006-09-26 16:01:11 +0000
committerMichal Krol <mjkrol@gmail.org>2006-09-26 16:01:11 +0000
commit27f660c16407d08e06fd0cc97bb247b41ae76f3b (patch)
treee9b66176d09fbd6fbc1ef102aaca67a3c3d11113 /src/mesa/shader/slang/slang_compile.c
parent4303d227396ab3a6f70c6c8318dcb9b30ca30755 (diff)
Add GLSL preprocessor.
Diffstat (limited to 'src/mesa/shader/slang/slang_compile.c')
-rw-r--r--src/mesa/shader/slang/slang_compile.c34
1 files changed, 22 insertions, 12 deletions
diff --git a/src/mesa/shader/slang/slang_compile.c b/src/mesa/shader/slang/slang_compile.c
index 46bdf830f9..357d61b246 100644
--- a/src/mesa/shader/slang/slang_compile.c
+++ b/src/mesa/shader/slang/slang_compile.c
@@ -1,6 +1,6 @@
/*
* Mesa 3-D graphics library
- * Version: 6.5
+ * Version: 6.6
*
* Copyright (C) 2005-2006 Brian Paul All Rights Reserved.
*
@@ -1918,10 +1918,11 @@ static GLboolean
compile_with_grammar (grammar id, const char *source, slang_code_unit *unit, slang_unit_type type,
slang_info_log *infolog, slang_code_unit *builtin)
{
- byte *prod;
+ byte *prod;
GLuint size, start, version;
+ slang_string preprocessed;
- /* retrieve version */
+ /* First retrieve the version number. */
if (!_slang_preprocess_version (source, &version, &start, infolog))
return GL_FALSE;
@@ -1930,22 +1931,31 @@ compile_with_grammar (grammar id, const char *source, slang_code_unit *unit, sla
return GL_FALSE;
}
- /* check the syntax and generate its binary representation */
- if (!grammar_fast_check (id, (const byte *) source + start, &prod, &size, 65536))
- {
- char buf[1024];
- unsigned int pos;
- grammar_get_last_error ( (unsigned char*) buf, 1024, (int*) &pos);
+ /* Now preprocess the source string. */
+ slang_string_init (&preprocessed);
+ if (!_slang_preprocess_directives (&preprocessed, &source[start], infolog)) {
+ slang_string_free (&preprocessed);
+ slang_info_log_error (infolog, "failed to preprocess the source.");
+ return GL_FALSE;
+ }
+
+ /* Finally check the syntax and generate its binary representation. */
+ if (!grammar_fast_check (id, (const byte *) (slang_string_cstr (&preprocessed)), &prod, &size, 65536)) {
+ char buf[1024];
+ GLint pos;
+
+ slang_string_free (&preprocessed);
+ grammar_get_last_error ((byte *) (buf), sizeof (buf), &pos);
slang_info_log_error (infolog, buf);
return GL_FALSE;
- }
+ }
+ slang_string_free (&preprocessed);
- /* syntax is okay - translate it to internal representation */
+ /* Syntax is okay - translate it to internal representation. */
if (!compile_binary (prod, unit, type, infolog, builtin, &builtin[SLANG_BUILTIN_TOTAL - 1])) {
grammar_alloc_free (prod);
return GL_FALSE;
}
-
grammar_alloc_free (prod);
return GL_TRUE;
}