Split slang_compile.c into several smaller files - it was just too big.
authorMichal Krol <mjkrol@gmail.org>
Mon, 30 Jan 2006 14:48:42 +0000 (14:48 +0000)
committerMichal Krol <mjkrol@gmail.org>
Mon, 30 Jan 2006 14:48:42 +0000 (14:48 +0000)
Minor fixes and cosmetic changes.

16 files changed:
src/mesa/shader/slang/slang_assemble.c
src/mesa/shader/slang/slang_assemble_assignment.c
src/mesa/shader/slang/slang_assemble_constructor.c
src/mesa/shader/slang/slang_assemble_typeinfo.c
src/mesa/shader/slang/slang_compile.c
src/mesa/shader/slang/slang_compile.h
src/mesa/shader/slang/slang_compile_function.c [new file with mode: 0644]
src/mesa/shader/slang/slang_compile_function.h [new file with mode: 0644]
src/mesa/shader/slang/slang_compile_operation.c [new file with mode: 0644]
src/mesa/shader/slang/slang_compile_operation.h [new file with mode: 0644]
src/mesa/shader/slang/slang_compile_struct.c [new file with mode: 0644]
src/mesa/shader/slang/slang_compile_struct.h [new file with mode: 0644]
src/mesa/shader/slang/slang_compile_variable.c [new file with mode: 0644]
src/mesa/shader/slang/slang_compile_variable.h [new file with mode: 0644]
src/mesa/shader/slang/slang_storage.c
src/mesa/shader/slang/slang_storage.h

index 6f928d7..a97da6b 100644 (file)
@@ -1,8 +1,8 @@
 /*\r
  * Mesa 3-D graphics library\r
- * Version:  6.3\r
+ * Version:  6.5\r
  *\r
- * Copyright (C) 2005  Brian Paul   All Rights Reserved.\r
+ * Copyright (C) 2005-2006  Brian Paul   All Rights Reserved.\r
  *\r
  * Permission is hereby granted, free of charge, to any person obtaining a\r
  * copy of this software and associated documentation files (the "Software"),\r
@@ -124,7 +124,7 @@ static int sizeof_variable (slang_type_specifier *spec, slang_type_qualifier qua
        slang_storage_aggregate agg;\r
 \r
        slang_storage_aggregate_construct (&agg);\r
-       if (!_slang_aggregate_variable (&agg, spec, array_size, space->funcs, space->structs))\r
+       if (!_slang_aggregate_variable (&agg, spec, array_size, space->funcs, space->structs, space->vars))\r
        {\r
                slang_storage_aggregate_destruct (&agg);\r
                return 0;\r
@@ -404,7 +404,7 @@ int dereference (slang_assembly_file *file, slang_operation *op,
        }\r
 \r
        slang_storage_aggregate_construct (&agg);\r
-       if (!_slang_aggregate_variable (&agg, &ti.spec, NULL, space->funcs, space->structs))\r
+       if (!_slang_aggregate_variable (&agg, &ti.spec, NULL, space->funcs, space->structs, space->vars))\r
        {\r
                slang_storage_aggregate_destruct (&agg);\r
                slang_assembly_typeinfo_destruct (&ti);\r
@@ -518,7 +518,7 @@ static int call_function_name_dummyint (slang_assembly_file *file, const char *n
        int result;\r
 \r
        p2[0] = *params;\r
-       if (!slang_operation_construct_a (p2 + 1))\r
+       if (!slang_operation_construct (p2 + 1))\r
                return 0;\r
        p2[1].type = slang_oper_literal_int;\r
        result = call_function_name (file, name, p2, 2, 0, space, info);\r
@@ -618,7 +618,8 @@ static int equality (slang_assembly_file *file, slang_operation *op,
 \r
        /* convert it to an aggregate */\r
        slang_storage_aggregate_construct (&agg);\r
-       if (!(result = _slang_aggregate_variable (&agg, &ti.spec, NULL, space->funcs, space->structs)))\r
+       if (!(result = _slang_aggregate_variable (&agg, &ti.spec, NULL, space->funcs, space->structs,\r
+                       space->vars)))\r
                goto end;\r
 \r
        /* compute the size of the agregate - there are two such aggregates on the stack */\r
index 551f5d9..d8821f0 100644 (file)
@@ -1,8 +1,8 @@
 /*\r
  * Mesa 3-D graphics library\r
- * Version:  6.3\r
+ * Version:  6.5\r
  *\r
- * Copyright (C) 2005  Brian Paul   All Rights Reserved.\r
+ * Copyright (C) 2005-2006  Brian Paul   All Rights Reserved.\r
  *\r
  * Permission is hereby granted, free of charge, to any person obtaining a\r
  * copy of this software and associated documentation files (the "Software"),\r
@@ -115,7 +115,7 @@ int _slang_assemble_assignment (slang_assembly_file *file, slang_operation *op,
        }\r
 \r
        slang_storage_aggregate_construct (&agg);\r
-       if (!_slang_aggregate_variable (&agg, &ti.spec, NULL, space->funcs, space->structs))\r
+       if (!_slang_aggregate_variable (&agg, &ti.spec, NULL, space->funcs, space->structs, space->vars))\r
        {\r
                slang_storage_aggregate_destruct (&agg);\r
                slang_assembly_typeinfo_destruct (&ti);\r
index 76a30f6..e62f88b 100644 (file)
@@ -1,8 +1,8 @@
 /*\r
  * Mesa 3-D graphics library\r
- * Version:  6.3\r
+ * Version:  6.5\r
  *\r
- * Copyright (C) 2005  Brian Paul   All Rights Reserved.\r
+ * Copyright (C) 2005-2006  Brian Paul   All Rights Reserved.\r
  *\r
  * Permission is hereby granted, free of charge, to any person obtaining a\r
  * copy of this software and associated documentation files (the "Software"),\r
@@ -158,7 +158,8 @@ static int constructor_aggregate (slang_assembly_file *file, const slang_storage
                goto end1;\r
 \r
        slang_storage_aggregate_construct (&agg);\r
-       if (!(result = _slang_aggregate_variable (&agg, &ti.spec, NULL, space->funcs, space->structs)))\r
+       if (!(result = _slang_aggregate_variable (&agg, &ti.spec, NULL, space->funcs, space->structs,\r
+                       space->vars)))\r
                goto end2;\r
 \r
        slang_storage_aggregate_construct (&flat_agg);\r
@@ -205,7 +206,8 @@ int _slang_assemble_constructor (slang_assembly_file *file, slang_operation *op,
                goto end1;\r
 \r
        slang_storage_aggregate_construct (&agg);\r
-       if (!(result = _slang_aggregate_variable (&agg, &ti.spec, NULL, space->funcs, space->structs)))\r
+       if (!(result = _slang_aggregate_variable (&agg, &ti.spec, NULL, space->funcs, space->structs,\r
+                       space->vars)))\r
                goto end2;\r
 \r
        size = _slang_sizeof_aggregate (&agg);\r
index ce78f66..f550556 100644 (file)
@@ -1,8 +1,8 @@
 /*\r
  * Mesa 3-D graphics library\r
- * Version:  6.3\r
+ * Version:  6.5\r
  *\r
- * Copyright (C) 2005  Brian Paul   All Rights Reserved.\r
+ * Copyright (C) 2005-2006  Brian Paul   All Rights Reserved.\r
  *\r
  * Permission is hereby granted, free of charge, to any person obtaining a\r
  * copy of this software and associated documentation files (the "Software"),\r
@@ -257,7 +257,7 @@ int _slang_typeof_operation (slang_operation *op, slang_assembly_name_space *spa
                                        ti->spec._struct = (slang_struct *) slang_alloc_malloc (sizeof (slang_struct));\r
                                        if (ti->spec._struct == NULL)\r
                                                return 0;\r
-                                       if (!slang_struct_construct_a (ti->spec._struct))\r
+                                       if (!slang_struct_construct (ti->spec._struct))\r
                                        {\r
                                                slang_alloc_free (ti->spec._struct);\r
                                                ti->spec._struct = NULL;\r
index 3418f6f..ce5653c 100644 (file)
@@ -1,8 +1,8 @@
 /*
  * Mesa 3-D graphics library
- * Version:  6.3
+ * Version:  6.5
  *
- * Copyright (C) 2005  Brian Paul   All Rights Reserved.
+ * Copyright (C) 2005-2006  Brian Paul   All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
        Lots of error-checking functionality is missing but every well-formed shader source should
        compile successfully and execute as expected. However, some semantically ill-formed shaders
        may be accepted resulting in undefined behaviour.
-*/
-
-static void slang_variable_construct (slang_variable *);
-static int slang_variable_copy (slang_variable *, const slang_variable *);
-static void slang_struct_destruct (slang_struct *);
-static int slang_struct_equal (const slang_struct *, const slang_struct *);
-static void slang_variable_destruct (slang_variable *);
-
-/* slang_type_specifier_type */
-
-/* these must match with slang_type_specifier_type enum */
-static const char *type_specifier_type_names[] = {
-       "void",
-       "bool",
-       "bvec2",
-       "bvec3",
-       "bvec4",
-       "int",
-       "ivec2",
-       "ivec3",
-       "ivec4",
-       "float",
-       "vec2",
-       "vec3",
-       "vec4",
-       "mat2",
-       "mat3",
-       "mat4",
-       "sampler1D",
-       "sampler2D",
-       "sampler3D",
-       "samplerCube",
-       "sampler1DShadow",
-       "sampler2DShadow",
-       NULL
-};
-
-slang_type_specifier_type slang_type_specifier_type_from_string (const char *name)
-{
-       const char **p = type_specifier_type_names;
-       while (*p != NULL)
-       {
-               if (slang_string_compare (*p, name) == 0)
-                       return (slang_type_specifier_type) (p - type_specifier_type_names);
-               p++;
-       }
-       return slang_spec_void;
-}
-
-/* slang_type_specifier */
-
-void slang_type_specifier_construct (slang_type_specifier *spec)
-{
-       spec->type = slang_spec_void;
-       spec->_struct = NULL;
-       spec->_array = NULL;
-}
-
-void slang_type_specifier_destruct (slang_type_specifier *spec)
-{
-       if (spec->_struct != NULL)
-       {
-               slang_struct_destruct (spec->_struct);
-               slang_alloc_free (spec->_struct);
-       }
-       if (spec->_array != NULL)
-       {
-               slang_type_specifier_destruct (spec->_array);
-               slang_alloc_free (spec->_array);
-       }
-}
-
-int slang_type_specifier_copy (slang_type_specifier *x, const slang_type_specifier *y)
-{
-       slang_type_specifier_destruct (x);
-       slang_type_specifier_construct (x);
-       x->type = y->type;
-       if (x->type == slang_spec_struct)
-       {
-               x->_struct = (slang_struct *) slang_alloc_malloc (sizeof (slang_struct));
-               if (x->_struct == NULL)
-                       return 0;
-               if (!slang_struct_construct_a (x->_struct))
-               {
-                       slang_alloc_free (x->_struct);
-                       x->_struct = NULL;
-                       return 0;
-               }
-               return slang_struct_copy (x->_struct, y->_struct);
-       }
-       if (x->type == slang_spec_array)
-       {
-               x->_array = (slang_type_specifier *) slang_alloc_malloc (sizeof (slang_type_specifier));
-               if (x->_array == NULL)
-                       return 0;
-               slang_type_specifier_construct (x->_array);
-               return slang_type_specifier_copy (x->_array, y->_array);
-       }
-       return 1;
-}
-
-int slang_type_specifier_equal (const slang_type_specifier *x, const slang_type_specifier *y)
-{
-       if (x->type != y->type)
-               return 0;
-       if (x->type == slang_spec_struct)
-               return slang_struct_equal (x->_struct, y->_struct);
-       if (x->type == slang_spec_array)
-               return slang_type_specifier_equal (x->_array, y->_array);
-       return 1;
-}
-
-/* slang_fully_specified_type */
-
-static void slang_fully_specified_type_construct (slang_fully_specified_type *type)
-{
-       type->qualifier = slang_qual_none;
-       slang_type_specifier_construct (&type->specifier);
-}
-
-static void slang_fully_specified_type_destruct (slang_fully_specified_type *type)
-{
-       slang_type_specifier_destruct (&type->specifier);
-}
-
-static int slang_fully_specified_type_copy (slang_fully_specified_type *x,
-       const slang_fully_specified_type *y)
-{
-       slang_fully_specified_type_construct (x);
-       slang_fully_specified_type_destruct (x);
-       x->qualifier = y->qualifier;
-       return slang_type_specifier_copy (&x->specifier, &y->specifier);
-}
-
-/* slang_variable_scope */
-
-static void slang_variable_scope_construct (slang_variable_scope *scope)
-{
-       scope->variables = NULL;
-       scope->num_variables = 0;
-       scope->outer_scope = NULL;
-}
-
-static void slang_variable_scope_destruct (slang_variable_scope *scope)
-{
-       unsigned int i;
-       for (i = 0; i < scope->num_variables; i++)
-               slang_variable_destruct (scope->variables + i);
-       slang_alloc_free (scope->variables);
-}
-
-static int slang_variable_scope_copy (slang_variable_scope *x, const slang_variable_scope *y)
-{
-       unsigned int i;
-       slang_variable_scope_destruct (x);
-       slang_variable_scope_construct (x);
-       x->variables = (slang_variable *) slang_alloc_malloc (y->num_variables * sizeof (
-               slang_variable));
-       if (x->variables == NULL)
-               return 0;
-       x->num_variables = y->num_variables;
-       for (i = 0; i < x->num_variables; i++)
-               slang_variable_construct (x->variables + i);
-       for (i = 0; i < x->num_variables; i++)
-               if (!slang_variable_copy (x->variables + i, y->variables + i))
-                       return 0;
-       x->outer_scope = y->outer_scope;
-       return 1;
-}
-
-/* slang_operation */
-
-int slang_operation_construct_a (slang_operation *oper)
-{
-       oper->type = slang_oper_none;
-       oper->children = NULL;
-       oper->num_children = 0;
-       oper->literal = (float) 0;
-       oper->identifier = NULL;
-       oper->locals = (slang_variable_scope *) slang_alloc_malloc (sizeof (slang_variable_scope));
-       if (oper->locals == NULL)
-               return 0;
-       slang_variable_scope_construct (oper->locals);
-       return 1;
-}
-
-void slang_operation_destruct (slang_operation *oper)
-{
-       unsigned int i;
-       for (i = 0; i < oper->num_children; i++)
-               slang_operation_destruct (oper->children + i);
-       slang_alloc_free (oper->children);
-       slang_alloc_free (oper->identifier);
-       slang_variable_scope_destruct (oper->locals);
-       slang_alloc_free (oper->locals);
-}
-
-static int slang_operation_copy (slang_operation *x, const slang_operation *y)
-{
-       unsigned int i;
-       for (i = 0; i < x->num_children; i++)
-               slang_operation_destruct (x->children + i);
-       slang_alloc_free (x->children);
-       x->num_children = 0;
-       slang_alloc_free (x->identifier);
-       x->identifier = NULL;
-       slang_variable_scope_destruct (x->locals);
-       slang_variable_scope_construct (x->locals);
-
-       x->type = y->type;
-       x->children = (slang_operation *) slang_alloc_malloc (y->num_children * sizeof (
-               slang_operation));
-       if (x->children == NULL)
-               return 0;
-       for (i = 0; i < y->num_children; i++)
-               if (!slang_operation_construct_a (x->children + i))
-               {
-                       unsigned int j;
-                       for (j = 0; j < i; j++)
-                               slang_operation_destruct (x->children + j);
-                       slang_alloc_free (x->children);
-                       x->children = NULL;
-                       return 0;
-               }
-       x->num_children = y->num_children;
-       for (i = 0; i < x->num_children; i++)
-               if (!slang_operation_copy (x->children + i, y->children + i))
-                       return 0;
-       x->literal = y->literal;
-       if (y->identifier != NULL)
-       {
-               x->identifier = slang_string_duplicate (y->identifier);
-               if (x->identifier == NULL)
-                       return 0;
-       }
-       if (!slang_variable_scope_copy (x->locals, y->locals))
-               return 0;
-       return 1;
-}
-
-/* slang_variable */
-
-static void slang_variable_construct (slang_variable *var)
-{
-       slang_fully_specified_type_construct (&var->type);
-       var->name = NULL;
-       var->array_size = NULL;
-       var->initializer = NULL;
-       var->address = ~0;
-}
-
-static void slang_variable_destruct (slang_variable *var)
-{
-       slang_fully_specified_type_destruct (&var->type);
-       slang_alloc_free (var->name);
-       if (var->array_size != NULL)
-       {
-               slang_operation_destruct (var->array_size);
-               slang_alloc_free (var->array_size);
-       }
-       if (var->initializer != NULL)
-       {
-               slang_operation_destruct (var->initializer);
-               slang_alloc_free (var->initializer);
-       }
-}
-
-static int slang_variable_copy (slang_variable *x, const slang_variable *y)
-{
-       slang_variable_destruct (x);
-       slang_variable_construct (x);
-       if (!slang_fully_specified_type_copy (&x->type, &y->type))
-               return 0;
-       if (y->name != NULL)
-       {
-               x->name = slang_string_duplicate (y->name);
-               if (x->name == NULL)
-                       return 0;
-       }
-       if (y->array_size != NULL)
-       {
-               x->array_size = (slang_operation *) slang_alloc_malloc (sizeof (slang_operation));
-               if (x->array_size == NULL)
-                       return 0;
-               if (!slang_operation_construct_a (x->array_size))
-               {
-                       slang_alloc_free (x->array_size);
-                       x->array_size = NULL;
-                       return 0;
-               }
-               if (!slang_operation_copy (x->array_size, y->array_size))
-                       return 0;
-       }
-       if (y->initializer != NULL)
-       {
-               x->initializer = (slang_operation *) slang_alloc_malloc (sizeof (slang_operation));
-               if (x->initializer == NULL)
-                       return 0;
-               if (!slang_operation_construct_a (x->initializer))
-               {
-                       slang_alloc_free (x->initializer);
-                       x->initializer = NULL;
-                       return 0;
-               }
-               if (!slang_operation_copy (x->initializer, y->initializer))
-                       return 0;
-       }
-       return 1;
-}
-
-slang_variable *_slang_locate_variable (slang_variable_scope *scope, const char *name, int all)
-{
-       unsigned int i;
-       for (i = 0; i < scope->num_variables; i++)
-               if (slang_string_compare (name, scope->variables[i].name) == 0)
-                       return scope->variables + i;
-       if (all && scope->outer_scope != NULL)
-               return _slang_locate_variable (scope->outer_scope, name, 1);
-       return NULL;
-}
-
-/* slang_struct_scope */
-
-static void slang_struct_scope_construct (slang_struct_scope *scope)
-{
-       scope->structs = NULL;
-       scope->num_structs = 0;
-       scope->outer_scope = NULL;
-}
-
-static void slang_struct_scope_destruct (slang_struct_scope *scope)
-{
-       unsigned int i;
-       for (i = 0; i < scope->num_structs; i++)
-               slang_struct_destruct (scope->structs + i);
-       slang_alloc_free (scope->structs);
-}
-
-static int slang_struct_scope_copy (slang_struct_scope *x, const slang_struct_scope *y)
-{
-       unsigned int i;
-       slang_struct_scope_destruct (x);
-       slang_struct_scope_construct (x);
-       x->structs = (slang_struct *) slang_alloc_malloc (y->num_structs * sizeof (slang_struct));
-       if (x->structs == NULL)
-               return 0;
-       x->num_structs = y->num_structs;
-       for (i = 0; i < x->num_structs; i++)
-       {
-               unsigned int j;
-               if (!slang_struct_construct_a (x->structs + i))
-               {
-                       for (j = 0; j < i; j++)
-                               slang_struct_destruct (x->structs + j);
-                       slang_alloc_free (x->structs);
-                       x->structs = NULL;
-                       return 0;
-               }
-       }
-       for (i = 0; i < x->num_structs; i++)
-               if (!slang_struct_copy (x->structs + i, y->structs + i))
-                       return 0;
-       x->outer_scope = y->outer_scope;
-       return 1;
-}
-
-slang_struct *slang_struct_scope_find (slang_struct_scope *stru, const char *name, int all_scopes)
-{
-       unsigned int i;
-       for (i = 0; i < stru->num_structs; i++)
-               if (slang_string_compare (name, stru->structs[i].name) == 0)
-                       return stru->structs + i;
-       if (all_scopes && stru->outer_scope != NULL)
-               return slang_struct_scope_find (stru->outer_scope, name, 1);
-       return NULL;
-}
-
-/* slang_struct */
-
-int slang_struct_construct_a (slang_struct *stru)
-{
-       stru->name = NULL;
-       stru->fields = (slang_variable_scope *) slang_alloc_malloc (sizeof (slang_variable_scope));
-       if (stru->fields == NULL)
-               return 0;
-       slang_variable_scope_construct (stru->fields);
-       stru->structs = (slang_struct_scope *) slang_alloc_malloc (sizeof (slang_struct_scope));
-       if (stru->structs == NULL)
-       {
-               slang_variable_scope_destruct (stru->fields);
-               slang_alloc_free (stru->fields);
-               return 0;
-       }
-       slang_struct_scope_construct (stru->structs);
-       return 1;
-}
-
-static void slang_struct_destruct (slang_struct *stru)
-{
-       slang_alloc_free (stru->name);
-       slang_variable_scope_destruct (stru->fields);
-       slang_alloc_free (stru->fields);
-       slang_struct_scope_destruct (stru->structs);
-       slang_alloc_free (stru->structs);
+*/\r
+\r
+/* slang_var_pool */\r
+\r
+static GLuint slang_var_pool_alloc (slang_var_pool *pool, unsigned int size)\r
+{\r
+       GLuint addr;\r
+\r
+       addr = pool->next_addr;\r
+       pool->next_addr += size;\r
+       return addr;\r
 }
 
-int slang_struct_copy (slang_struct *x, const slang_struct *y)
-{
-       slang_alloc_free (x->name);
-       x->name = NULL;
-       slang_variable_scope_destruct (x->fields);
-       slang_variable_scope_construct (x->fields);
-       slang_struct_scope_destruct (x->structs);
-       slang_struct_scope_construct (x->structs);
-       if (y->name != NULL)
-       {
-               x->name = slang_string_duplicate (y->name);
-               if (x->name == NULL)
-                       return 0;
-       }
-       if (!slang_variable_scope_copy (x->fields, y->fields))
-               return 0;
-       if (!slang_struct_scope_copy (x->structs, y->structs))
-               return 0;
-       return 1;
-}
+/* slang_translation_unit */
 
-static int slang_struct_equal (const slang_struct *x, const slang_struct *y)
+int slang_translation_unit_construct (slang_translation_unit *unit)
 {
-       unsigned int i;
-       if (x->fields->num_variables != y->fields->num_variables)
-               return 0;
-       for (i = 0; i < x->fields->num_variables; i++)
-       {
-               slang_variable *varx = x->fields->variables + i;
-               slang_variable *vary = y->fields->variables + i;
-               if (slang_string_compare (varx->name, vary->name) != 0)
-                       return 0;
-               if (!slang_type_specifier_equal (&varx->type.specifier, &vary->type.specifier))
-                       return 0;
-               if (varx->type.specifier.type == slang_spec_array)
-               {
-                       /* TODO compare array sizes */
-               }
+       if (!slang_variable_scope_construct (&unit->globals))\r
+               return 0;\r
+       if (!slang_function_scope_construct (&unit->functions))\r
+       {\r
+               slang_variable_scope_destruct (&unit->globals);\r
+               return 0;\r
        }
+       if (!slang_struct_scope_construct (&unit->structs))\r
+       {\r
+               slang_variable_scope_destruct (&unit->globals);\r
+               slang_function_scope_destruct (&unit->functions);\r
+               return 0;\r
+       }\r
+       unit->assembly = (slang_assembly_file *) slang_alloc_malloc (sizeof (slang_assembly_file));\r
+       if (unit->assembly == NULL)\r
+       {\r
+               slang_variable_scope_destruct (&unit->globals);\r
+               slang_function_scope_destruct (&unit->functions);\r
+               slang_struct_scope_destruct (&unit->structs);\r
+               return 0;\r
+       }\r
+       slang_assembly_file_construct (unit->assembly);\r
+       unit->global_pool.next_addr = 0;\r
        return 1;
 }
 
-/* slang_function */
-/* XXX mem! */
-static void slang_function_construct (slang_function *func)
-{
-       func->kind = slang_func_ordinary;
-       slang_variable_construct (&func->header);
-       func->parameters = (slang_variable_scope *) slang_alloc_malloc (sizeof (slang_variable_scope));
-       slang_variable_scope_construct (func->parameters);
-       func->body = NULL;
-       func->address = ~0;
-}
-
-static void slang_function_destruct (slang_function *func)
-{
-       slang_variable_destruct (&func->header);
-       slang_variable_scope_destruct (func->parameters);
-       slang_alloc_free (func->parameters);
-       if (func->body != NULL)
-       {
-               slang_operation_destruct (func->body);
-               slang_alloc_free (func->body);
-       }
-}
-
-/* slang_function_scope */
-
-static void slang_function_scope_construct (slang_function_scope *scope)
-{
-       scope->functions = NULL;
-       scope->num_functions = 0;
-       scope->outer_scope = NULL;
-}
-
-static void slang_function_scope_destruct (slang_function_scope *scope)
-{
-       unsigned int i;
-       for (i = 0; i < scope->num_functions; i++)
-               slang_function_destruct (scope->functions + i);
-       slang_alloc_free (scope->functions);
-}
-
-static int slang_function_scope_find_by_name (slang_function_scope *funcs, const char *name,
-       int all_scopes)
-{
-       unsigned int i;
-       for (i = 0; i < funcs->num_functions; i++)
-               if (slang_string_compare (name, funcs->functions[i].header.name) == 0)
-                       return 1;
-       if (all_scopes && funcs->outer_scope != NULL)
-               return slang_function_scope_find_by_name (funcs->outer_scope, name, 1);
-       return 0;
-}
-
-static slang_function *slang_function_scope_find (slang_function_scope *funcs, slang_function *fun,
-       int all_scopes)
-{
-       unsigned int i;
-       for (i = 0; i < funcs->num_functions; i++)
-       {
-               slang_function *f = funcs->functions + i;
-               unsigned int j;
-               if (slang_string_compare (fun->header.name, f->header.name) != 0)
-                       continue;
-               if (fun->param_count != f->param_count)
-                       continue;
-               for (j = 0; j < fun->param_count; j++)
-               {
-                       if (!slang_type_specifier_equal (&fun->parameters->variables[j].type.specifier,
-                               &f->parameters->variables[j].type.specifier))
-                       {
-                               break;
-                       }
-               }
-               if (j == fun->param_count)
-                       return f;
-       }
-       if (all_scopes && funcs->outer_scope != NULL)
-               return slang_function_scope_find (funcs->outer_scope, fun, 1);
-       return NULL;
-}
-
-/* slang_translation_unit */
-
-void slang_translation_unit_construct (slang_translation_unit *unit)
-{
-       slang_variable_scope_construct (&unit->globals);
-       slang_function_scope_construct (&unit->functions);
-       slang_struct_scope_construct (&unit->structs);
-}
-
 void slang_translation_unit_destruct (slang_translation_unit *unit)
 {
        slang_variable_scope_destruct (&unit->globals);
        slang_function_scope_destruct (&unit->functions);
-       slang_struct_scope_destruct (&unit->structs);
+       slang_struct_scope_destruct (&unit->structs);\r
+       slang_assembly_file_destruct (unit->assembly);\r
+       slang_alloc_free (unit->assembly);
 }
 
 /* slang_info_log */
@@ -605,20 +112,22 @@ void slang_info_log_destruct (slang_info_log *log)
 
 static int slang_info_log_message (slang_info_log *log, const char *prefix, const char *msg)
 {
-       unsigned int new_size;
+       unsigned int new_size;\r
+
        if (log->dont_free_text)
                return 0;
        new_size = slang_string_length (prefix) + 3 + slang_string_length (msg);
        if (log->text != NULL)
-       {
-               log->text = (char *) slang_alloc_realloc (log->text, slang_string_length (log->text) + 1,
-                       new_size + slang_string_length (log->text) + 1);
+       {\r
+               unsigned int text_len = slang_string_length (log->text);\r
+
+               log->text = (char *) slang_alloc_realloc (log->text, text_len + 1, new_size + text_len + 1);
        }
        else
        {
                log->text = (char *) slang_alloc_malloc (new_size + 1);
                if (log->text != NULL)
-                       *log->text = '\0';
+                       log->text[0] = '\0';
        }
        if (log->text == NULL)
                return 0;
@@ -672,8 +181,20 @@ typedef struct slang_parse_ctx_
 {
        const byte *I;
        slang_info_log *L;
-       int parsing_builtin;
-} slang_parse_ctx;
+       int parsing_builtin;\r
+       int global_scope;
+} slang_parse_ctx;\r
+\r
+/* slang_output_ctx */\r
+\r
+typedef struct slang_output_ctx_\r
+{\r
+       slang_variable_scope *vars;\r
+       slang_function_scope *funs;\r
+       slang_struct_scope *structs;\r
+       slang_assembly_file *assembly;\r
+       slang_var_pool *global_pool;\r
+} slang_output_ctx;
 
 /* _slang_compile() */
 
@@ -775,10 +296,144 @@ static int check_revision (slang_parse_ctx *C)
        return 1;
 }
 
-static int parse_statement (slang_parse_ctx *, slang_operation *, slang_variable_scope *,
-       slang_struct_scope *, slang_function_scope *);
-static int parse_expression (slang_parse_ctx *, slang_operation *, slang_variable_scope *,
-       slang_struct_scope *, slang_function_scope *);
+static int parse_statement (slang_parse_ctx *, slang_output_ctx *, slang_operation *);
+static int parse_expression (slang_parse_ctx *, slang_output_ctx *, slang_operation *);\r
+static int parse_type_specifier (slang_parse_ctx *, slang_output_ctx *, slang_type_specifier *);\r
+\r
+/* structure field */\r
+#define FIELD_NONE 0\r
+#define FIELD_NEXT 1\r
+#define FIELD_ARRAY 2\r
+\r
+static int parse_struct_field_var (slang_parse_ctx *C, slang_output_ctx *O, slang_variable *var)\r
+{\r
+       if (!parse_identifier (C, &var->name))\r
+               return 0;\r
+       switch (*C->I++)\r
+       {\r
+       case FIELD_NONE:\r
+               break;\r
+       case FIELD_ARRAY:\r
+               var->array_size = (slang_operation *) slang_alloc_malloc (sizeof (slang_operation));\r
+               if (var->array_size == NULL)\r
+               {\r
+                       slang_info_log_memory (C->L);\r
+                       return 0;\r
+               }\r
+               if (!slang_operation_construct (var->array_size))\r
+               {\r
+                       slang_alloc_free (var->array_size);\r
+                       var->array_size = NULL;\r
+                       return 0;\r
+               }\r
+               if (!parse_expression (C, O, var->array_size))\r
+                       return 0;\r
+               break;\r
+       default:\r
+               return 0;\r
+       }\r
+       return 1;\r
+}\r
+\r
+static int parse_struct_field (slang_parse_ctx *C, slang_output_ctx *O, slang_struct *st,\r
+       slang_type_specifier *sp)\r
+{\r
+       slang_output_ctx o = *O;\r
+\r
+       o.structs = st->structs;\r
+       if (!parse_type_specifier (C, &o, sp))\r
+               return 0;\r
+       do\r
+       {\r
+               slang_variable *var;\r
+\r
+               st->fields->variables = (slang_variable *) slang_alloc_realloc (st->fields->variables,\r
+                       st->fields->num_variables * sizeof (slang_variable),\r
+                       (st->fields->num_variables + 1) * sizeof (slang_variable));\r
+               if (st->fields->variables == NULL)\r
+               {\r
+                       slang_info_log_memory (C->L);\r
+                       return 0;\r
+               }\r
+               var = st->fields->variables + st->fields->num_variables;\r
+               if (!slang_variable_construct (var))\r
+                       return 0;\r
+               st->fields->num_variables++;\r
+               if (!slang_type_specifier_copy (&var->type.specifier, sp))\r
+                       return 0;\r
+               if (!parse_struct_field_var (C, &o, var))\r
+                       return 0;\r
+       }\r
+       while (*C->I++ != FIELD_NONE);\r
+       return 1;\r
+}\r
+\r
+static int parse_struct (slang_parse_ctx *C, slang_output_ctx *O, slang_struct **st)\r
+{\r
+       char *name;\r
+\r
+       if (!parse_identifier (C, &name))\r
+               return 0;\r
+       if (name[0] != '\0' && slang_struct_scope_find (O->structs, name, 0) != NULL)\r
+       {\r
+               slang_info_log_error (C->L, "%s: duplicate type name", name);\r
+               slang_alloc_free (name);\r
+               return 0;\r
+       }\r
+       *st = (slang_struct *) slang_alloc_malloc (sizeof (slang_struct));\r
+       if (*st == NULL)\r
+       {\r
+               slang_alloc_free (name);\r
+               slang_info_log_memory (C->L);\r
+               return 0;\r
+       }\r
+       if (!slang_struct_construct (*st))\r
+       {\r
+               slang_alloc_free (*st);\r
+               *st = NULL;\r
+               slang_alloc_free (name);\r
+               slang_info_log_memory (C->L);\r
+               return 0;\r
+       }\r
+       (**st).name = name;\r
+       (**st).structs->outer_scope = O->structs;\r
+\r
+       do\r
+       {\r
+               slang_type_specifier sp;\r
+\r
+               if (!slang_type_specifier_construct (&sp))\r
+                       return 0;\r
+               if (!parse_struct_field (C, O, *st, &sp))\r
+               {\r
+                       slang_type_specifier_destruct (&sp);\r
+                       return 0;\r
+               }\r
+       }\r
+       while (*C->I++ != FIELD_NONE);\r
+\r
+       if ((**st).name != '\0')\r
+       {\r
+               slang_struct *s;\r
+\r
+               O->structs->structs = (slang_struct *) slang_alloc_realloc (O->structs->structs,\r
+                               O->structs->num_structs * sizeof (slang_struct),\r
+                               (O->structs->num_structs + 1) * sizeof (slang_struct));\r
+               if (O->structs->structs == NULL)\r
+               {\r
+                       slang_info_log_memory (C->L);\r
+                       return 0;\r
+               }\r
+               s = &O->structs->structs[O->structs->num_structs];\r
+               if (!slang_struct_construct (s))\r
+                       return 0;\r
+               O->structs->num_structs++;\r
+               if (!slang_struct_copy (s, *st))\r
+                       return 0;\r
+       }\r
+\r
+       return 1;\r
+}
 
 /* type qualifier */
 #define TYPE_QUALIFIER_NONE 0
@@ -846,13 +501,7 @@ static int parse_type_qualifier (slang_parse_ctx *C, slang_type_qualifier *qual)
 #define TYPE_SPECIFIER_STRUCT 22
 #define TYPE_SPECIFIER_TYPENAME 23
 
-/* structure field */
-#define FIELD_NONE 0
-#define FIELD_NEXT 1
-#define FIELD_ARRAY 2
-
-static int parse_type_specifier (slang_parse_ctx *C, slang_type_specifier *spec,
-       slang_struct_scope *structs, slang_variable_scope *scope, slang_function_scope *funcs)
+static int parse_type_specifier (slang_parse_ctx *C, slang_output_ctx *O, slang_type_specifier *spec)
 {
        switch (*C->I++)
        {
@@ -923,122 +572,9 @@ static int parse_type_specifier (slang_parse_ctx *C, slang_type_specifier *spec,
                spec->type = slang_spec_sampler2DShadow;
                break;
        case TYPE_SPECIFIER_STRUCT:
-               spec->type = slang_spec_struct;
-               {
-                       char *name;
-                       if (!parse_identifier (C, &name))
-                               return 0;
-                       if (*name != '\0' && slang_struct_scope_find (structs, name, 0) != NULL)
-                       {
-                               slang_info_log_error (C->L, "%s: duplicate type name", name);
-                               slang_alloc_free (name);
-                               return 0;
-                       }
-                       spec->_struct = (slang_struct *) slang_alloc_malloc (sizeof (slang_struct));
-                       if (spec->_struct == NULL)
-                       {
-                               slang_alloc_free (name);
-                               slang_info_log_memory (C->L);
-                               return 0;
-                       }
-                       if (!slang_struct_construct_a (spec->_struct))
-                       {
-                               slang_alloc_free (spec->_struct);
-                               spec->_struct = NULL;
-                               slang_alloc_free (name);
-                               slang_info_log_memory (C->L);
-                               return 0;
-                       }
-                       spec->_struct->name = name;
-                       spec->_struct->structs->outer_scope = structs;
-               }
-               do
-               {
-                       slang_type_specifier sp;
-                       slang_type_specifier_construct (&sp);
-                       if (!parse_type_specifier (C, &sp, spec->_struct->structs, scope, funcs))
-                       {
-                               slang_type_specifier_destruct (&sp);
-                               return 0;
-                       }
-                       do
-                       {
-                               slang_variable *var;
-                               spec->_struct->fields->variables = (slang_variable *) slang_alloc_realloc (
-                                       spec->_struct->fields->variables,
-                                       spec->_struct->fields->num_variables * sizeof (slang_variable),
-                                       (spec->_struct->fields->num_variables + 1) * sizeof (slang_variable));
-                               if (spec->_struct->fields->variables == NULL)
-                               {
-                                       slang_type_specifier_destruct (&sp);
-                                       slang_info_log_memory (C->L);
-                                       return 0;
-                               }
-                               var = spec->_struct->fields->variables + spec->_struct->fields->num_variables;
-                               spec->_struct->fields->num_variables++;
-                               slang_variable_construct (var);
-                               if (!slang_type_specifier_copy (&var->type.specifier, &sp))
-                               {
-                                       slang_type_specifier_destruct (&sp);
-                                       return 0;
-                               }
-                               if (!parse_identifier (C, &var->name))
-                               {
-                                       slang_type_specifier_destruct (&sp);
-                                       return 0;
-                               }
-                               switch (*C->I++)
-                               {
-                               case FIELD_NONE:
-                                       break;
-                               case FIELD_ARRAY:
-                                       var->array_size = (slang_operation *) slang_alloc_malloc (sizeof (
-                                               slang_operation));
-                                       if (var->array_size == NULL)
-                                       {
-                                               slang_type_specifier_destruct (&sp);
-                                               slang_info_log_memory (C->L);
-                                               return 0;
-                                       }
-                                       if (!slang_operation_construct_a (var->array_size))
-                                       {
-                                               slang_alloc_free (var->array_size);
-                                               var->array_size = NULL;
-                                               slang_type_specifier_destruct (&sp);
-                                               slang_info_log_memory (C->L);
-                                               return 0;
-                                       }
-                                       if (!parse_expression (C, var->array_size, scope, structs, funcs))
-                                       {
-                                               slang_type_specifier_destruct (&sp);
-                                               return 0;
-                                       }
-                                       break;
-                               default:
-                                       return 0;
-                               }
-                       }
-                       while (*C->I++ != FIELD_NONE);
-               }
-               while (*C->I++ != FIELD_NONE);
-               if (*spec->_struct->name != '\0')
-               {
-                       slang_struct *s;
-                       structs->structs = (slang_struct *) slang_alloc_realloc (structs->structs,
-                               structs->num_structs * sizeof (slang_struct),
-                               (structs->num_structs + 1) * sizeof (slang_struct));
-                       if (structs->structs == NULL)
-                       {
-                               slang_info_log_memory (C->L);
-                               return 0;
-                       }
-                       s = structs->structs + structs->num_structs;
-                       if (!slang_struct_construct_a (s))
-                               return 0;
-                       structs->num_structs++;
-                       if (!slang_struct_copy (s, spec->_struct))
-                               return 0;
-               }
+               spec->type = slang_spec_struct;\r
+               if (!parse_struct (C, O, &spec->_struct))
+                       return 0;
                break;
        case TYPE_SPECIFIER_TYPENAME:
                spec->type = slang_spec_struct;
@@ -1047,7 +583,7 @@ static int parse_type_specifier (slang_parse_ctx *C, slang_type_specifier *spec,
                        slang_struct *stru;
                        if (!parse_identifier (C, &name))
                                return 0;
-                       stru = slang_struct_scope_find (structs, name, 1);
+                       stru = slang_struct_scope_find (O->structs, name, 1);
                        if (stru == NULL)
                        {
                                slang_info_log_error (C->L, "%s: undeclared type name", name);
@@ -1061,7 +597,7 @@ static int parse_type_specifier (slang_parse_ctx *C, slang_type_specifier *spec,
                                slang_info_log_memory (C->L);
                                return 0;
                        }
-                       if (!slang_struct_construct_a (spec->_struct))
+                       if (!slang_struct_construct (spec->_struct))
                        {
                                slang_alloc_free (spec->_struct);
                                spec->_struct = NULL;
@@ -1077,12 +613,12 @@ static int parse_type_specifier (slang_parse_ctx *C, slang_type_specifier *spec,
        return 1;
 }
 
-static int parse_fully_specified_type (slang_parse_ctx *C, slang_fully_specified_type *type,
-       slang_struct_scope *structs, slang_variable_scope *scope, slang_function_scope *funcs)
+static int parse_fully_specified_type (slang_parse_ctx *C, slang_output_ctx *O,\r
+       slang_fully_specified_type *type)
 {
        if (!parse_type_qualifier (C, &type->qualifier))
                return 0;
-       return parse_type_specifier (C, &type->specifier, structs, scope, funcs);
+       return parse_type_specifier (C, O, &type->specifier);
 }
 
 /* operation */
@@ -1149,8 +685,8 @@ static int parse_fully_specified_type (slang_parse_ctx *C, slang_fully_specified
 #define OP_POSTINCREMENT 60
 #define OP_POSTDECREMENT 61
 
-static int parse_child_operation (slang_parse_ctx *C, slang_operation *oper, int statement,
-       slang_variable_scope *scope, slang_struct_scope *structs, slang_function_scope *funcs)
+static int parse_child_operation (slang_parse_ctx *C, slang_output_ctx *O, slang_operation *oper,\r
+       int statement)
 {
        oper->children = (slang_operation *) slang_alloc_realloc (oper->children,
                oper->num_children * sizeof (slang_operation),
@@ -1160,50 +696,54 @@ static int parse_child_operation (slang_parse_ctx *C, slang_operation *oper, int
                slang_info_log_memory (C->L);
                return 0;
        }
-       if (!slang_operation_construct_a (oper->children + oper->num_children))
+       if (!slang_operation_construct (oper->children + oper->num_children))
        {
                slang_info_log_memory (C->L);
                return 0;
        }
        oper->num_children++;
        if (statement)
-               return parse_statement (C, oper->children + oper->num_children - 1, scope, structs, funcs);
-       return parse_expression (C, oper->children + oper->num_children - 1, scope, structs, funcs);
+               return parse_statement (C, O, &oper->children[oper->num_children - 1]);
+       return parse_expression (C, O, &oper->children[oper->num_children - 1]);
 }
 
-static int parse_declaration (slang_parse_ctx *C, slang_variable_scope *, slang_struct_scope *,
-       slang_function_scope *);
+static int parse_declaration (slang_parse_ctx *C, slang_output_ctx *O);
 
-static int parse_statement (slang_parse_ctx *C, slang_operation *oper, slang_variable_scope *scope,
-       slang_struct_scope *structs, slang_function_scope *funcs)
+static int parse_statement (slang_parse_ctx *C, slang_output_ctx *O, slang_operation *oper)
 {
-       oper->locals->outer_scope = scope;
+       oper->locals->outer_scope = O->vars;
        switch (*C->I++)
        {
        case OP_BLOCK_BEGIN_NO_NEW_SCOPE:
                oper->type = slang_oper_block_no_new_scope;
                while (*C->I != OP_END)
-                       if (!parse_child_operation (C, oper, 1, scope, structs, funcs))
+                       if (!parse_child_operation (C, O, oper, 1))
                                return 0;
                C->I++;
                break;
        case OP_BLOCK_BEGIN_NEW_SCOPE:
                oper->type = slang_oper_block_new_scope;
-               while (*C->I != OP_END)
-                       if (!parse_child_operation (C, oper, 1, oper->locals, structs, funcs))
-                               return 0;
+               while (*C->I != OP_END)\r
+               {\r
+                       slang_output_ctx o = *O;\r
+                       o.vars = oper->locals;
+                       if (!parse_child_operation (C, &o, oper, 1))
+                               return 0;\r
+               }
                C->I++;
                break;
        case OP_DECLARE:
                oper->type = slang_oper_variable_decl;
                {
-                       const unsigned int first_var = scope->num_variables;
-                       if (!parse_declaration (C, scope, structs, funcs))
+                       const unsigned int first_var = O->vars->num_variables;\r
+
+                       if (!parse_declaration (C, O))
                                return 0;
-                       if (first_var < scope->num_variables)
+                       if (first_var < O->vars->num_variables)
                        {
-                               const unsigned int num_vars = scope->num_variables - first_var;
-                               unsigned int i;
+                               const unsigned int num_vars = O->vars->num_variables - first_var;
+                               unsigned int i;\r
+
                                oper->children = (slang_operation *) slang_alloc_malloc (num_vars * sizeof (
                                        slang_operation));
                                if (oper->children == NULL)
@@ -1212,7 +752,7 @@ static int parse_statement (slang_parse_ctx *C, slang_operation *oper, slang_var
                                        return 0;
                                }
                                for (i = 0; i < num_vars; i++)
-                                       if (!slang_operation_construct_a (oper->children + i))
+                                       if (!slang_operation_construct (oper->children + i))
                                        {
                                                unsigned int j;
                                                for (j = 0; j < i; j++)
@@ -1223,12 +763,12 @@ static int parse_statement (slang_parse_ctx *C, slang_operation *oper, slang_var
                                                return 0;
                                        }
                                oper->num_children = num_vars;
-                               for (i = first_var; i < scope->num_variables; i++)
+                               for (i = first_var; i < O->vars->num_variables; i++)
                                {
                                        slang_operation *o = oper->children + i - first_var;
                                        o->type = slang_oper_identifier;
-                                       o->locals->outer_scope = scope;
-                                       o->identifier = slang_string_duplicate (scope->variables[i].name);
+                                       o->locals->outer_scope = O->vars;
+                                       o->identifier = slang_string_duplicate (O->vars->variables[i].name);
                                        if (o->identifier == NULL)
                                        {
                                                slang_info_log_memory (C->L);
@@ -1243,7 +783,7 @@ static int parse_statement (slang_parse_ctx *C, slang_operation *oper, slang_var
                if (!parse_identifier (C, &oper->identifier))
                        return 0;
                while (*C->I != OP_END)
-                       if (!parse_child_operation (C, oper, 0, scope, structs, funcs))
+                       if (!parse_child_operation (C, O, oper, 0))
                                return 0;
                C->I++;
                break;
@@ -1258,47 +798,55 @@ static int parse_statement (slang_parse_ctx *C, slang_operation *oper, slang_var
                break;
        case OP_RETURN:
                oper->type = slang_oper_return;
-               if (!parse_child_operation (C, oper, 0, scope, structs, funcs))
+               if (!parse_child_operation (C, O, oper, 0))
                        return 0;
                break;
        case OP_EXPRESSION:
                oper->type = slang_oper_expression;
-               if (!parse_child_operation (C, oper, 0, scope, structs, funcs))
+               if (!parse_child_operation (C, O, oper, 0))
                        return 0;
                break;
        case OP_IF:
                oper->type = slang_oper_if;
-               if (!parse_child_operation (C, oper, 0, scope, structs, funcs))
+               if (!parse_child_operation (C, O, oper, 0))
                        return 0;
-               if (!parse_child_operation (C, oper, 1, scope, structs, funcs))
+               if (!parse_child_operation (C, O, oper, 1))
                        return 0;
-               if (!parse_child_operation (C, oper, 1, scope, structs, funcs))
+               if (!parse_child_operation (C, O, oper, 1))
                        return 0;
                break;
        case OP_WHILE:
-               oper->type = slang_oper_while;
-               if (!parse_child_operation (C, oper, 1, oper->locals, structs, funcs))
-                       return 0;
-               if (!parse_child_operation (C, oper, 1, oper->locals, structs, funcs))
-                       return 0;
+               oper->type = slang_oper_while;\r
+               {\r
+                       slang_output_ctx o = *O;\r
+                       o.vars = oper->locals;
+                       if (!parse_child_operation (C, &o, oper, 1))
+                               return 0;
+                       if (!parse_child_operation (C, &o, oper, 1))
+                               return 0;\r
+               }
                break;
        case OP_DO:
                oper->type = slang_oper_do;
-               if (!parse_child_operation (C, oper, 1, scope, structs, funcs))
+               if (!parse_child_operation (C, O, oper, 1))
                        return 0;
-               if (!parse_child_operation (C, oper, 0, scope, structs, funcs))
+               if (!parse_child_operation (C, O, oper, 0))
                        return 0;
                break;
        case OP_FOR:
-               oper->type = slang_oper_for;
-               if (!parse_child_operation (C, oper, 1, oper->locals, structs, funcs))
-                       return 0;
-               if (!parse_child_operation (C, oper, 1, oper->locals, structs, funcs))
-                       return 0;
-               if (!parse_child_operation (C, oper, 0, oper->locals, structs, funcs))
-                       return 0;
-               if (!parse_child_operation (C, oper, 1, oper->locals, structs, funcs))
-                       return 0;
+               oper->type = slang_oper_for;\r
+               {\r
+                       slang_output_ctx o = *O;\r
+                       o.vars = oper->locals;
+                       if (!parse_child_operation (C, &o, oper, 1))
+                               return 0;
+                       if (!parse_child_operation (C, &o, oper, 1))
+                               return 0;
+                       if (!parse_child_operation (C, &o, oper, 0))
+                               return 0;
+                       if (!parse_child_operation (C, &o, oper, 1))
+                               return 0;\r
+               }
                break;
        default:
                return 0;
@@ -1385,8 +933,7 @@ static int is_constructor_name (const char *name, slang_struct_scope *structs)
        return slang_struct_scope_find (structs, name, 1) != NULL;
 }
 
-static int parse_expression (slang_parse_ctx *C, slang_operation *oper, slang_variable_scope *scope,
-       slang_struct_scope *structs, slang_function_scope *funcs)
+static int parse_expression (slang_parse_ctx *C, slang_output_ctx *O, slang_operation *oper)
 {
        slang_operation *ops = NULL;
        unsigned int num_ops = 0;
@@ -1404,13 +951,13 @@ static int parse_expression (slang_parse_ctx *C, slang_operation *oper, slang_va
                        return 0;
                }
                op = ops + num_ops;
-               if (!slang_operation_construct_a (op))
+               if (!slang_operation_construct (op))
                {
                        slang_info_log_memory (C->L);
                        return 0;
                }
                num_ops++;
-               op->locals->outer_scope = scope;
+               op->locals->outer_scope = O->vars;
                switch (op_code)
                {
                case OP_PUSH_VOID:
@@ -1586,12 +1133,12 @@ static int parse_expression (slang_parse_ctx *C, slang_operation *oper, slang_va
                        if (!parse_identifier (C, &op->identifier))
                                return 0;
                        while (*C->I != OP_END)
-                               if (!parse_child_operation (C, op, 0, scope, structs, funcs))
+                               if (!parse_child_operation (C, O, op, 0))
                                        return 0;
                        C->I++;
                        if (!C->parsing_builtin &&
-                               !slang_function_scope_find_by_name (funcs, op->identifier, 1) &&
-                               !is_constructor_name (op->identifier, structs))
+                               !slang_function_scope_find_by_name (O->funs, op->identifier, 1) &&
+                               !is_constructor_name (op->identifier, O->structs))
                        {
                                slang_info_log_error (C->L, "%s: undeclared function name", op->identifier);
                                return 0;
@@ -1633,8 +1180,8 @@ static int parse_expression (slang_parse_ctx *C, slang_operation *oper, slang_va
 #define PARAMETER_ARRAY_NOT_PRESENT 0
 #define PARAMETER_ARRAY_PRESENT 1
 
-static int parse_parameter_declaration (slang_parse_ctx *C, slang_variable *param,
-       slang_struct_scope *structs, slang_variable_scope *scope, slang_function_scope *funcs)
+static int parse_parameter_declaration (slang_parse_ctx *C, slang_output_ctx *O,\r
+       slang_variable *param)
 {
        slang_storage_aggregate agg;
        if (!parse_type_qualifier (C, &param->type.qualifier))
@@ -1669,7 +1216,7 @@ static int parse_parameter_declaration (slang_parse_ctx *C, slang_variable *para
        default:
                return 0;
        }
-       if (!parse_type_specifier (C, &param->type.specifier, structs, scope, funcs))
+       if (!parse_type_specifier (C, O, &param->type.specifier))
                return 0;
        if (!parse_identifier (C, &param->name))
                return 0;
@@ -1681,19 +1228,19 @@ static int parse_parameter_declaration (slang_parse_ctx *C, slang_variable *para
                        slang_info_log_memory (C->L);
                        return 0;
                }
-               if (!slang_operation_construct_a (param->array_size))
+               if (!slang_operation_construct (param->array_size))
                {
                        slang_alloc_free (param->array_size);
                        param->array_size = NULL;
                        slang_info_log_memory (C->L);
                        return 0;
                }
-               if (!parse_expression (C, param->array_size, scope, structs, funcs))
+               if (!parse_expression (C, O, param->array_size))
                        return 0;
        }
        slang_storage_aggregate_construct (&agg);
-       if (!_slang_aggregate_variable (&agg, &param->type.specifier, param->array_size, funcs,
-               structs))
+       if (!_slang_aggregate_variable (&agg, &param->type.specifier, param->array_size, O->funs,
+                       O->structs, O->vars))
        {
                slang_storage_aggregate_destruct (&agg);
                return 0;
@@ -1801,10 +1348,9 @@ static int parse_operator_name (slang_parse_ctx *C, char **pname)
        return 0;
 }
 
-static int parse_function_prototype (slang_parse_ctx *C, slang_function *func,
-       slang_struct_scope *structs, slang_variable_scope *scope, slang_function_scope *funcs)
+static int parse_function_prototype (slang_parse_ctx *C, slang_output_ctx *O, slang_function *func)
 {
-       if (!parse_fully_specified_type (C, &func->header.type, structs, scope, funcs))
+       if (!parse_fully_specified_type (C, O, &func->header.type))
                return 0;
        switch (*C->I++)
        {
@@ -1818,7 +1364,7 @@ static int parse_function_prototype (slang_parse_ctx *C, slang_function *func,
                if (func->header.type.specifier.type == slang_spec_struct)
                        return 0;
                func->header.name = slang_string_duplicate (
-                       type_specifier_type_names[func->header.type.specifier.type]);
+                       slang_type_specifier_type_to_string (func->header.type.specifier.type));
                if (func->header.name == NULL)
                {
                        slang_info_log_memory (C->L);
@@ -1833,7 +1379,7 @@ static int parse_function_prototype (slang_parse_ctx *C, slang_function *func,
        default:
                return 0;
        }\r
-       func->parameters->outer_scope = scope;
+       func->parameters->outer_scope = O->vars;
        while (*C->I++ == PARAMETER_NEXT)
        {
                func->parameters->variables = (slang_variable *) slang_alloc_realloc (
@@ -1847,18 +1393,19 @@ static int parse_function_prototype (slang_parse_ctx *C, slang_function *func,
                }
                slang_variable_construct (func->parameters->variables + func->parameters->num_variables);
                func->parameters->num_variables++;
-               if (!parse_parameter_declaration (C, func->parameters->variables +
-                       func->parameters->num_variables - 1, structs, scope, funcs))
+               if (!parse_parameter_declaration (C, O,\r
+                               &func->parameters->variables[func->parameters->num_variables - 1]))
                        return 0;
        }
        func->param_count = func->parameters->num_variables;
        return 1;
 }
 
-static int parse_function_definition (slang_parse_ctx *C, slang_function *func,
-       slang_struct_scope *structs, slang_variable_scope *scope, slang_function_scope *funcs)
-{
-       if (!parse_function_prototype (C, func, structs, scope, funcs))
+static int parse_function_definition (slang_parse_ctx *C, slang_output_ctx *O, slang_function *func)
+{\r
+       slang_output_ctx o = *O;\r
+
+       if (!parse_function_prototype (C, O, func))
                return 0;
        func->body = (slang_operation *) slang_alloc_malloc (sizeof (slang_operation));
        if (func->body == NULL)
@@ -1866,15 +1413,18 @@ static int parse_function_definition (slang_parse_ctx *C, slang_function *func,
                slang_info_log_memory (C->L);
                return 0;
        }
-       if (!slang_operation_construct_a (func->body))
+       if (!slang_operation_construct (func->body))
        {
                slang_alloc_free (func->body);
                func->body = NULL;
                slang_info_log_memory (C->L);
                return 0;
-       }
-       if (!parse_statement (C, func->body, func->parameters, structs, funcs))
-               return 0;
+       }\r
+       C->global_scope = 0;\r
+       o.vars = func->parameters;
+       if (!parse_statement (C, &o, func->body))
+               return 0;\r
+       C->global_scope = 1;
        return 1;
 }
 
@@ -1889,34 +1439,42 @@ static int parse_function_definition (slang_parse_ctx *C, slang_function *func,
 #define VARIABLE_ARRAY_EXPLICIT 3
 #define VARIABLE_ARRAY_UNKNOWN 4
 
-static int parse_init_declarator (slang_parse_ctx *C, const slang_fully_specified_type *type,
-       slang_variable_scope *vars, slang_struct_scope *structs, slang_function_scope *funcs)
+static int parse_init_declarator (slang_parse_ctx *C, slang_output_ctx *O,\r
+       const slang_fully_specified_type *type)
 {
        slang_variable *var;
-
+\r
+       /* empty init declatator, e.g. "float ;" */\r
        if (*C->I++ == VARIABLE_NONE)
-               return 1;
-       vars->variables = (slang_variable *) slang_alloc_realloc (vars->variables,
-               vars->num_variables * sizeof (slang_variable),
-               (vars->num_variables + 1) * sizeof (slang_variable));
-       if (vars->variables == NULL)
+               return 1;\r
+\r
+       /* make room for the new variable and initialize it */
+       O->vars->variables = (slang_variable *) slang_alloc_realloc (O->vars->variables,
+               O->vars->num_variables * sizeof (slang_variable),
+               (O->vars->num_variables + 1) * sizeof (slang_variable));
+       if (O->vars->variables == NULL)
        {
                slang_info_log_memory (C->L);
                return 0;
        }
-       var = vars->variables + vars->num_variables;
-       vars->num_variables++;
-       slang_variable_construct (var);
+       var = &O->vars->variables[O->vars->num_variables];
+       slang_variable_construct (var);\r
+       O->vars->num_variables++;\r
+\r
+       /* copy the declarator qualifier type, parse the identifier */
        var->type.qualifier = type->qualifier;
        if (!parse_identifier (C, &var->name))
-               return 0;
+               return 0;\r
+
        switch (*C->I++)
        {
-       case VARIABLE_NONE:
+       case VARIABLE_NONE:\r
+               /* simple variable declarator - just copy the specifier */
                if (!slang_type_specifier_copy (&var->type.specifier, &type->specifier))
                        return 0;
                break;
-       case VARIABLE_INITIALIZER:
+       case VARIABLE_INITIALIZER:\r
+               /* initialized variable - copy the specifier and parse the expression */
                if (!slang_type_specifier_copy (&var->type.specifier, &type->specifier))
                        return 0;
                var->initializer = (slang_operation *) slang_alloc_malloc (sizeof (slang_operation));
@@ -1925,17 +1483,18 @@ static int parse_init_declarator (slang_parse_ctx *C, const slang_fully_specifie
                        slang_info_log_memory (C->L);
                        return 0;
                }
-               if (!slang_operation_construct_a (var->initializer))
+               if (!slang_operation_construct (var->initializer))
                {
                        slang_alloc_free (var->initializer);
                        var->initializer = NULL;
                        slang_info_log_memory (C->L);
                        return 0;
                }
-               if (!parse_expression (C, var->initializer, vars, structs, funcs))
+               if (!parse_expression (C, O, var->initializer))
                        return 0;
                break;
-       case VARIABLE_ARRAY_UNKNOWN:
+       case VARIABLE_ARRAY_UNKNOWN:\r
+               /* unsized array - mark it as array and copy the specifier to the array element */
                var->type.specifier.type = slang_spec_array;
                var->type.specifier._array = (slang_type_specifier *) slang_alloc_malloc (sizeof (
                        slang_type_specifier));
@@ -1948,7 +1507,9 @@ static int parse_init_declarator (slang_parse_ctx *C, const slang_fully_specifie
                if (!slang_type_specifier_copy (var->type.specifier._array, &type->specifier))
                        return 0;
                break;
-       case VARIABLE_ARRAY_EXPLICIT:
+       case VARIABLE_ARRAY_EXPLICIT:\r
+               /* an array - mark it as array, copy the specifier to the array element and\r
+                * parse the expression */
                var->type.specifier.type = slang_spec_array;
                var->type.specifier._array = (slang_type_specifier *) slang_alloc_malloc (sizeof (
                        slang_type_specifier));
@@ -1966,49 +1527,51 @@ static int parse_init_declarator (slang_parse_ctx *C, const slang_fully_specifie
                        slang_info_log_memory (C->L);
                        return 0;
                }
-               if (!slang_operation_construct_a (var->array_size))
+               if (!slang_operation_construct (var->array_size))
                {
                        slang_alloc_free (var->array_size);
                        var->array_size = NULL;
                        slang_info_log_memory (C->L);
                        return 0;
                }
-               if (!parse_expression (C, var->array_size, vars, structs, funcs))
+               if (!parse_expression (C, O, var->array_size))
                        return 0;
                break;
        default:
                return 0;
-       }
-       if (!(var->type.specifier.type == slang_spec_array && var->array_size == NULL))
+       }\r
+\r
+       /* allocate global address space for a variable with a known size */
+       if (C->global_scope && !(var->type.specifier.type == slang_spec_array && var->array_size == NULL))
        {
                slang_storage_aggregate agg;
 
                slang_storage_aggregate_construct (&agg);
-               if (!_slang_aggregate_variable (&agg, &var->type.specifier, var->array_size, funcs,
-                       structs))
+               if (!_slang_aggregate_variable (&agg, &var->type.specifier, var->array_size, O->funs,
+                               O->structs, O->vars))
                {
                        slang_storage_aggregate_destruct (&agg);
                        return 0;
-               }
+               }\r
+               var->address = slang_var_pool_alloc (O->global_pool, _slang_sizeof_aggregate (&agg));
                slang_storage_aggregate_destruct (&agg);
        }
        return 1;
 }
 
-static int parse_init_declarator_list (slang_parse_ctx *C, slang_variable_scope *vars,
-       slang_struct_scope *structs, slang_function_scope *funcs)
+static int parse_init_declarator_list (slang_parse_ctx *C, slang_output_ctx *O)
 {
        slang_fully_specified_type type;
 
        slang_fully_specified_type_construct (&type);
-       if (!parse_fully_specified_type (C, &type, structs, vars, funcs))
+       if (!parse_fully_specified_type (C, O, &type))
        {
                slang_fully_specified_type_destruct (&type);
                return 0;
        }
        do
        {
-               if (!parse_init_declarator (C, &type, vars, structs, funcs))
+               if (!parse_init_declarator (C, O, &type))
                {
                        slang_fully_specified_type_destruct (&type);
                        return 0;
@@ -2019,16 +1582,17 @@ static int parse_init_declarator_list (slang_parse_ctx *C, slang_variable_scope
        return 1;
 }
 
-static int parse_function (slang_parse_ctx *C, int definition, slang_struct_scope *structs,
-       slang_function_scope *funcs, slang_variable_scope *scope, slang_function **parsed_func_ret)
+static int parse_function (slang_parse_ctx *C, slang_output_ctx *O, int definition,\r
+       slang_function **parsed_func_ret)
 {
        slang_function parsed_func, *found_func;
 
        /* parse function definition/declaration */
-       slang_function_construct (&parsed_func);
+       if (!slang_function_construct (&parsed_func))\r
+               return 0;
        if (definition)
        {
-               if (!parse_function_definition (C, &parsed_func, structs, scope, funcs))
+               if (!parse_function_definition (C, O, &parsed_func))
                {
                        slang_function_destruct (&parsed_func);
                        return 0;
@@ -2036,7 +1600,7 @@ static int parse_function (slang_parse_ctx *C, int definition, slang_struct_scop
        }
        else
        {
-               if (!parse_function_prototype (C, &parsed_func, structs, scope, funcs))
+               if (!parse_function_prototype (C, O, &parsed_func))
                {
                        slang_function_destruct (&parsed_func);
                        return 0;
@@ -2045,24 +1609,24 @@ static int parse_function (slang_parse_ctx *C, int definition, slang_struct_scop
 
        /* find a function with a prototype matching the parsed one - only the current scope
        is being searched to allow built-in function overriding */
-       found_func = slang_function_scope_find (funcs, &parsed_func, 0);
+       found_func = slang_function_scope_find (O->funs, &parsed_func, 0);
        if (found_func == NULL)
        {
                /* add the parsed function to the function list */
-               funcs->functions = (slang_function *) slang_alloc_realloc (funcs->functions,
-                       funcs->num_functions * sizeof (slang_function), (funcs->num_functions + 1) * sizeof (
-                       slang_function));
-               if (funcs->functions == NULL)
+               O->funs->functions = (slang_function *) slang_alloc_realloc (O->funs->functions,
+                       O->funs->num_functions * sizeof (slang_function),\r
+                       (O->funs->num_functions + 1) * sizeof (slang_function));
+               if (O->funs->functions == NULL)
                {
                        slang_info_log_memory (C->L);
                        slang_function_destruct (&parsed_func);
                        return 0;
                }
-               funcs->functions[funcs->num_functions] = parsed_func;
-               funcs->num_functions++;
+               O->funs->functions[O->funs->num_functions] = parsed_func;
+               O->funs->num_functions++;
 
                /* return the newly parsed function */
-               *parsed_func_ret = funcs->functions + funcs->num_functions - 1;
+               *parsed_func_ret = &O->funs->functions[O->funs->num_functions - 1];
        }
        else
        {
@@ -2093,20 +1657,15 @@ static int parse_function (slang_parse_ctx *C, int definition, slang_struct_scop
        /* assemble the parsed function */
        if (definition)
        {
-               slang_assembly_file file;
                slang_assembly_name_space space;
 \r
-               slang_assembly_file_construct (&file);
-               space.funcs = funcs;
-               space.structs = structs;
-               space.vars = scope;
+               space.funcs = O->funs;
+               space.structs = O->structs;
+               space.vars = O->vars;
 
-               (**parsed_func_ret).address = file.count;
-               if (!_slang_assemble_function (&file, *parsed_func_ret, &space))
-               {
-                       slang_assembly_file_destruct (&file);
-                       return 0;
-               }
+               (**parsed_func_ret).address = O->assembly->count;
+               /*if (!_slang_assemble_function (O->assembly, *parsed_func_ret, &space))
+                       return 0;*/
        }
        return 1;
 }
@@ -2115,19 +1674,18 @@ static int parse_function (slang_parse_ctx *C, int definition, slang_struct_scop
 #define DECLARATION_FUNCTION_PROTOTYPE 1
 #define DECLARATION_INIT_DECLARATOR_LIST 2
 
-static int parse_declaration (slang_parse_ctx *C, slang_variable_scope *scope,
-       slang_struct_scope *structs, slang_function_scope *funcs)
+static int parse_declaration (slang_parse_ctx *C, slang_output_ctx *O)
 {
        slang_function *dummy_func;
 
        switch (*C->I++)
        {
        case DECLARATION_INIT_DECLARATOR_LIST:
-               if (!parse_init_declarator_list (C, scope, structs, funcs))
+               if (!parse_init_declarator_list (C, O))
                        return 0;
                break;
        case DECLARATION_FUNCTION_PROTOTYPE:
-               if (!parse_function (C, 0, structs, funcs, scope, &dummy_func))
+               if (!parse_function (C, O, 0, &dummy_func))
                        return 0;
                break;
        default:
@@ -2142,19 +1700,27 @@ static int parse_declaration (slang_parse_ctx *C, slang_variable_scope *scope,
 #define EXTERNAL_DECLARATION 2
 
 static int parse_translation_unit (slang_parse_ctx *C, slang_translation_unit *unit)
-{
+{\r
+       slang_output_ctx o;\r
+\r
+       o.funs = &unit->functions;\r
+       o.structs = &unit->structs;\r
+       o.vars = &unit->globals;\r
+       o.assembly = unit->assembly;\r
+       o.global_pool = &unit->global_pool;\r
+
        while (*C->I != EXTERNAL_NULL)
-       {
-               slang_function *func;
+       {\r
+               slang_function *func;\r
 
                switch (*C->I++)
                {
                case EXTERNAL_FUNCTION_DEFINITION:
-                       if (!parse_function (C, 1, &unit->structs, &unit->functions, &unit->globals, &func))
+                       if (!parse_function (C, &o, 1, &func))
                                return 0;
                        break;
                case EXTERNAL_DECLARATION:
-                       if (!parse_declaration (C, &unit->globals, &unit->structs, &unit->functions))
+                       if (!parse_declaration (C, &o))
                                return 0;
                        break;
                default:
@@ -2163,7 +1729,12 @@ static int parse_translation_unit (slang_parse_ctx *C, slang_translation_unit *u
        }
        C->I++;
        return 1;
-}
+}\r
+\r
+#define BUILTIN_CORE 0\r
+#define BUILTIN_COMMON 1\r
+#define BUILTIN_TARGET 2\r
+#define BUILTIN_TOTAL 3
 
 static int compile_binary (const byte *prod, slang_translation_unit *unit, slang_unit_type type,
        slang_info_log *log, slang_translation_unit *builtins)
@@ -2173,7 +1744,8 @@ static int compile_binary (const byte *prod, slang_translation_unit *unit, slang
        /* set-up parse context */
        C.I = prod;
        C.L = log;
-       C.parsing_builtin = builtins == NULL;
+       C.parsing_builtin = builtins == NULL;\r
+       C.global_scope = 1;
 
        if (!check_revision (&C))
                return 0;
@@ -2185,16 +1757,16 @@ static int compile_binary (const byte *prod, slang_translation_unit *unit, slang
        if (builtins != NULL)
        {
                /* link to built-in functions */
-               builtins[1].functions.outer_scope = &builtins[0].functions;
-               builtins[2].functions.outer_scope = &builtins[1].functions;
-               unit->functions.outer_scope = &builtins[2].functions;
+               builtins[BUILTIN_COMMON].functions.outer_scope = &builtins[BUILTIN_CORE].functions;
+               builtins[BUILTIN_TARGET].functions.outer_scope = &builtins[BUILTIN_COMMON].functions;
+               unit->functions.outer_scope = &builtins[BUILTIN_TARGET].functions;
 
                /* link to built-in variables - core unit does not define any */
-               builtins[2].globals.outer_scope = &builtins[1].globals;
-               unit->globals.outer_scope = &builtins[2].globals;
+               builtins[BUILTIN_TARGET].globals.outer_scope = &builtins[BUILTIN_COMMON].globals;
+               unit->globals.outer_scope = &builtins[BUILTIN_TARGET].globals;
 
                /* link to built-in structure typedefs - only in common unit */
-               unit->structs.outer_scope = &builtins[1].structs;
+               unit->structs.outer_scope = &builtins[BUILTIN_COMMON].structs;
        }
 
        /* parse translation unit */
@@ -2257,7 +1829,7 @@ static const byte slang_vertex_builtin_gc[] = {
 #include "library/slang_vertex_builtin_gc.h"
 };\r
 \r
-int compile (grammar *id, slang_translation_unit builtin_units[3], int compiled[3],\r
+static int compile (grammar *id, slang_translation_unit *builtin_units, int *compiled,\r
        const char *source, slang_translation_unit *unit, slang_unit_type type, slang_info_log *log)\r
 {\r
        slang_translation_unit *builtins = NULL;\r
@@ -2286,29 +1858,29 @@ int compile (grammar *id, slang_translation_unit builtin_units[3], int compiled[
        /* if parsing user-specified shader, load built-in library */\r
        if (type == slang_unit_fragment_shader || type == slang_unit_vertex_shader)\r
        {\r
-               if (!compile_binary (slang_core_gc, &builtin_units[0], slang_unit_fragment_builtin, log,\r
-                               NULL))\r
+               if (!compile_binary (slang_core_gc, &builtin_units[BUILTIN_CORE],\r
+                               slang_unit_fragment_builtin, log, NULL))\r
                        return 0;\r
-               compiled[0] = 1;\r
+               compiled[BUILTIN_CORE] = 1;\r
 \r
-               if (!compile_binary (slang_common_builtin_gc, &builtin_units[1],\r
+               if (!compile_binary (slang_common_builtin_gc, &builtin_units[BUILTIN_COMMON],\r
                                slang_unit_fragment_builtin, log, NULL))\r
                        return 0;\r
-               compiled[1] = 1;\r
+               compiled[BUILTIN_COMMON] = 1;\r
 \r
                if (type == slang_unit_fragment_shader)\r
                {\r
-                       if (!compile_binary (slang_fragment_builtin_gc, &builtin_units[2],\r
+                       if (!compile_binary (slang_fragment_builtin_gc, &builtin_units[BUILTIN_TARGET],\r
                                        slang_unit_fragment_builtin, log, NULL))\r
                                return 0;\r
                }\r
                else if (type == slang_unit_vertex_shader)\r
                {\r
-                       if (!compile_binary (slang_vertex_builtin_gc, &builtin_units[2],\r
+                       if (!compile_binary (slang_vertex_builtin_gc, &builtin_units[BUILTIN_TARGET],\r
                                        slang_unit_vertex_builtin, log, NULL))\r
                                return 0;\r
                }\r
-               compiled[2] = 1;\r
+               compiled[BUILTIN_TARGET] = 1;\r
 \r
                /* disable language extensions */\r
                grammar_set_reg8 (*id, (const byte *) "parsing_builtin", 0);\r
@@ -2321,14 +1893,14 @@ int compile (grammar *id, slang_translation_unit builtin_units[3], int compiled[
 \r
        return 1;\r
 }
-
+\r
 int _slang_compile (const char *source, slang_translation_unit *unit, slang_unit_type type,
        slang_info_log *log)
 {\r
        int success;
        grammar id = 0;
-       slang_translation_unit builtin_units[3];\r
-       int compiled[3] = { 0 };
+       slang_translation_unit builtin_units[BUILTIN_TOTAL];\r
+       int compiled[BUILTIN_TOTAL] = { 0 };
 
        success = compile (&id, builtin_units, compiled, source, unit, type, log);
 
@@ -2337,7 +1909,7 @@ int _slang_compile (const char *source, slang_translation_unit *unit, slang_unit
        {\r
                int i;\r
 \r
-               for (i = 0; i < 3; i++)\r
+               for (i = 0; i < BUILTIN_TOTAL; i++)\r
                        if (compiled[i] != 0)
                                slang_translation_unit_destruct (&builtin_units[i]);
        }\r
index a9a075c..dd774dd 100644 (file)
@@ -1,8 +1,8 @@
 /*
  * Mesa 3-D graphics library
- * Version:  6.3
+ * Version:  6.5
  *
- * Copyright (C) 2005  Brian Paul   All Rights Reserved.
+ * Copyright (C) 2005-2006  Brian Paul   All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
  */
 
 #if !defined SLANG_COMPILE_H
-#define SLANG_COMPILE_H
+#define SLANG_COMPILE_H\r
+\r
+#include "slang_compile_variable.h"\r
+#include "slang_compile_struct.h"\r
+#include "slang_compile_operation.h"\r
+#include "slang_compile_function.h"
 
 #if defined __cplusplus
 extern "C" {
 #endif
 
-typedef enum slang_type_qualifier_
-{
-       slang_qual_none,
-       slang_qual_const,
-       slang_qual_attribute,
-       slang_qual_varying,
-       slang_qual_uniform,
-       slang_qual_out,
-       slang_qual_inout,
-       slang_qual_fixedoutput, /* internal */
-       slang_qual_fixedinput   /* internal */
-} slang_type_qualifier;
-
-typedef enum slang_type_specifier_type_
-{
-       slang_spec_void,
-       slang_spec_bool,
-       slang_spec_bvec2,
-       slang_spec_bvec3,
-       slang_spec_bvec4,
-       slang_spec_int,
-       slang_spec_ivec2,
-       slang_spec_ivec3,
-       slang_spec_ivec4,
-       slang_spec_float,
-       slang_spec_vec2,
-       slang_spec_vec3,
-       slang_spec_vec4,
-       slang_spec_mat2,
-       slang_spec_mat3,
-       slang_spec_mat4,
-       slang_spec_sampler1D,
-       slang_spec_sampler2D,
-       slang_spec_sampler3D,
-       slang_spec_samplerCube,
-       slang_spec_sampler1DShadow,
-       slang_spec_sampler2DShadow,
-       slang_spec_struct,
-       slang_spec_array
-} slang_type_specifier_type;\r
-\r
-slang_type_specifier_type slang_type_specifier_type_from_string (const char *);
-
-typedef struct slang_type_specifier_
-{
-       slang_type_specifier_type type;
-       struct slang_struct_ *_struct;          /* spec_struct */
-       struct slang_type_specifier_ *_array;   /* spec_array */
-} slang_type_specifier;\r
-\r
-void slang_type_specifier_construct (slang_type_specifier *);\r
-void slang_type_specifier_destruct (slang_type_specifier *);\r
-int slang_type_specifier_copy (slang_type_specifier *, const slang_type_specifier *);\r
-int slang_type_specifier_equal (const slang_type_specifier *, const slang_type_specifier *);
-
-typedef struct slang_fully_specified_type_
-{
-       slang_type_qualifier qualifier;
-       slang_type_specifier specifier;
-} slang_fully_specified_type;
-
-typedef struct slang_variable_scope_
-{
-       struct slang_variable_ *variables;
-       unsigned int num_variables;
-       struct slang_variable_scope_ *outer_scope;
-} slang_variable_scope;
-
-typedef enum slang_operation_type_
-{
-       slang_oper_none,
-       slang_oper_block_no_new_scope,
-       slang_oper_block_new_scope,
-       slang_oper_variable_decl,
-       slang_oper_asm,
-       slang_oper_break,
-       slang_oper_continue,
-       slang_oper_discard,
-       slang_oper_return,
-       slang_oper_expression,
-       slang_oper_if,
-       slang_oper_while,
-       slang_oper_do,
-       slang_oper_for,
-       slang_oper_void,
-       slang_oper_literal_bool,
-       slang_oper_literal_int,
-       slang_oper_literal_float,
-       slang_oper_identifier,
-       slang_oper_sequence,
-       slang_oper_assign,
-       slang_oper_addassign,
-       slang_oper_subassign,
-       slang_oper_mulassign,
-       slang_oper_divassign,
-       /*slang_oper_modassign,*/
-       /*slang_oper_lshassign,*/
-       /*slang_oper_rshassign,*/
-       /*slang_oper_orassign,*/
-       /*slang_oper_xorassign,*/
-       /*slang_oper_andassign,*/
-       slang_oper_select,
-       slang_oper_logicalor,
-       slang_oper_logicalxor,
-       slang_oper_logicaland,
-       /*slang_oper_bitor,*/
-       /*slang_oper_bitxor,*/
-       /*slang_oper_bitand,*/
-       slang_oper_equal,
-       slang_oper_notequal,
-       slang_oper_less,
-       slang_oper_greater,
-       slang_oper_lessequal,
-       slang_oper_greaterequal,
-       /*slang_oper_lshift,*/
-       /*slang_oper_rshift,*/
-       slang_oper_add,
-       slang_oper_subtract,
-       slang_oper_multiply,
-       slang_oper_divide,
-       /*slang_oper_modulus,*/
-       slang_oper_preincrement,
-       slang_oper_predecrement,
-       slang_oper_plus,
-       slang_oper_minus,
-       /*slang_oper_complement,*/
-       slang_oper_not,
-       slang_oper_subscript,
-       slang_oper_call,
-       slang_oper_field,
-       slang_oper_postincrement,
-       slang_oper_postdecrement
-} slang_operation_type;
-
-typedef struct slang_operation_
-{
-       slang_operation_type type;
-       struct slang_operation_ *children;
-       unsigned int num_children;
-       float literal;          /* bool, literal_int, literal_float */
-       char *identifier;       /* asm, identifier, call, field */
-       slang_variable_scope *locals;
-} slang_operation;\r
-\r
-int slang_operation_construct_a (slang_operation *);\r
-void slang_operation_destruct (slang_operation *);
-
-typedef struct slang_variable_
-{
-       slang_fully_specified_type type;
-       char *name;
-       slang_operation *array_size;    /* spec_array */
-       slang_operation *initializer;\r
-       unsigned int address;
-} slang_variable;\r
-\r
-slang_variable *_slang_locate_variable (slang_variable_scope *scope, const char *name, int all);
-
-typedef struct slang_struct_scope_
-{
-       struct slang_struct_ *structs;
-       unsigned int num_structs;
-       struct slang_struct_scope_ *outer_scope;
-} slang_struct_scope;\r
-\r
-struct slang_struct_ *slang_struct_scope_find (slang_struct_scope *, const char *, int);
-
-typedef struct slang_struct_
-{
-       char *name;
-       slang_variable_scope *fields;
-       slang_struct_scope *structs;
-} slang_struct;\r
-\r
-int slang_struct_construct_a (slang_struct *);\r
-int slang_struct_copy (slang_struct *, const slang_struct *);
-
-typedef enum slang_function_kind_
-{
-       slang_func_ordinary,
-       slang_func_constructor,
-       slang_func_operator
-} slang_function_kind;
-
-typedef struct slang_function_
-{
-       slang_function_kind kind;
-       slang_variable header;
-       slang_variable_scope *parameters;
-       unsigned int param_count;
-       slang_operation *body;\r
-       unsigned int address;
-} slang_function;
-
-typedef struct slang_function_scope_
-{
-       slang_function *functions;
-       unsigned int num_functions;
-       struct slang_function_scope_ *outer_scope;
-} slang_function_scope;
-
 typedef enum slang_unit_type_
 {
        slang_unit_fragment_shader,
        slang_unit_vertex_shader,
        slang_unit_fragment_builtin,
        slang_unit_vertex_builtin
-} slang_unit_type;
-       
+} slang_unit_type;\r
+\r
+typedef struct slang_var_pool_\r
+{\r
+       GLuint next_addr;\r
+} slang_var_pool;\r
+\r
 typedef struct slang_translation_unit_
 {
        slang_variable_scope globals;
        slang_function_scope functions;
        slang_struct_scope structs;
-       slang_unit_type type;
+       slang_unit_type type;\r
+       struct slang_assembly_file_ *assembly;\r
+       slang_var_pool global_pool;
 } slang_translation_unit;
 
-void slang_translation_unit_construct (slang_translation_unit *);
+int slang_translation_unit_construct (slang_translation_unit *);
 void slang_translation_unit_destruct (slang_translation_unit *);
 
 typedef struct slang_info_log_
diff --git a/src/mesa/shader/slang/slang_compile_function.c b/src/mesa/shader/slang/slang_compile_function.c
new file mode 100644 (file)
index 0000000..970c6fa
--- /dev/null
@@ -0,0 +1,133 @@
+/*\r
+ * Mesa 3-D graphics library\r
+ * Version:  6.5\r
+ *\r
+ * Copyright (C) 2005-2006  Brian Paul   All Rights Reserved.\r
+ *\r
+ * Permission is hereby granted, free of charge, to any person obtaining a\r
+ * copy of this software and associated documentation files (the "Software"),\r
+ * to deal in the Software without restriction, including without limitation\r
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
+ * and/or sell copies of the Software, and to permit persons to whom the\r
+ * Software is furnished to do so, subject to the following conditions:\r
+ *\r
+ * The above copyright notice and this permission notice shall be included\r
+ * in all copies or substantial portions of the Software.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL\r
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN\r
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+ */\r
+\r
+/**\r
+ * \file slang_compile_function.c\r
+ * slang front-end compiler\r
+ * \author Michal Krol\r
+ */\r
+\r
+#include "imports.h"\r
+#include "slang_utility.h"\r
+#include "slang_compile_variable.h"\r
+#include "slang_compile_struct.h"\r
+#include "slang_compile_operation.h"\r
+#include "slang_compile_function.h"\r
+\r
+/* slang_function */\r
+\r
+int slang_function_construct (slang_function *func)\r
+{\r
+       func->kind = slang_func_ordinary;\r
+       if (!slang_variable_construct (&func->header))\r
+               return 0;\r
+       func->parameters = (slang_variable_scope *) slang_alloc_malloc (sizeof (slang_variable_scope));\r
+       if (func->parameters == NULL)\r
+       {\r
+               slang_variable_destruct (&func->header);\r
+               return 0;\r
+       }\r
+       if (!slang_variable_scope_construct (func->parameters))\r
+       {\r
+               slang_alloc_free (func->parameters);\r
+               slang_variable_destruct (&func->header);\r
+               return 0;\r
+       }\r
+       func->param_count = 0;\r
+       func->body = NULL;\r
+       func->address = ~0;\r
+       return 1;\r
+}\r
+\r
+void slang_function_destruct (slang_function *func)\r
+{\r
+       slang_variable_destruct (&func->header);\r
+       slang_variable_scope_destruct (func->parameters);\r
+       slang_alloc_free (func->parameters);\r
+       if (func->body != NULL)\r
+       {\r
+               slang_operation_destruct (func->body);\r
+               slang_alloc_free (func->body);\r
+       }\r
+}\r
+\r
+/* slang_function_scope */\r
+\r
+int slang_function_scope_construct (slang_function_scope *scope)\r
+{\r
+       scope->functions = NULL;\r
+       scope->num_functions = 0;\r
+       scope->outer_scope = NULL;\r
+       return 1;\r
+}\r
+\r
+void slang_function_scope_destruct (slang_function_scope *scope)\r
+{\r
+       unsigned int i;\r
+\r
+       for (i = 0; i < scope->num_functions; i++)\r
+               slang_function_destruct (scope->functions + i);\r
+       slang_alloc_free (scope->functions);\r
+}\r
+\r
+int slang_function_scope_find_by_name (slang_function_scope *funcs, const char *name, int all_scopes)\r
+{\r
+       unsigned int i;\r
+\r
+       for (i = 0; i < funcs->num_functions; i++)\r
+               if (slang_string_compare (name, funcs->functions[i].header.name) == 0)\r
+                       return 1;\r
+       if (all_scopes && funcs->outer_scope != NULL)\r
+               return slang_function_scope_find_by_name (funcs->outer_scope, name, 1);\r
+       return 0;\r
+}\r
+\r
+slang_function *slang_function_scope_find (slang_function_scope *funcs, slang_function *fun,\r
+       int all_scopes)\r
+{\r
+       unsigned int i;\r
+\r
+       for (i = 0; i < funcs->num_functions; i++)\r
+       {\r
+               slang_function *f = funcs->functions + i;\r
+               unsigned int j;\r
+\r
+               if (slang_string_compare (fun->header.name, f->header.name) != 0)\r
+                       continue;\r
+               if (fun->param_count != f->param_count)\r
+                       continue;\r
+               for (j = 0; j < fun->param_count; j++)\r
+               {\r
+                       if (!slang_type_specifier_equal (&fun->parameters->variables[j].type.specifier,\r
+                                       &f->parameters->variables[j].type.specifier))\r
+                               break;\r
+               }\r
+               if (j == fun->param_count)\r
+                       return f;\r
+       }\r
+       if (all_scopes && funcs->outer_scope != NULL)\r
+               return slang_function_scope_find (funcs->outer_scope, fun, 1);\r
+       return NULL;\r
+}\r
+\r
diff --git a/src/mesa/shader/slang/slang_compile_function.h b/src/mesa/shader/slang/slang_compile_function.h
new file mode 100644 (file)
index 0000000..7f13bff
--- /dev/null
@@ -0,0 +1,69 @@
+/*\r
+ * Mesa 3-D graphics library\r
+ * Version:  6.5\r
+ *\r
+ * Copyright (C) 2005-2006  Brian Paul   All Rights Reserved.\r
+ *\r
+ * Permission is hereby granted, free of charge, to any person obtaining a\r
+ * copy of this software and associated documentation files (the "Software"),\r
+ * to deal in the Software without restriction, including without limitation\r
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
+ * and/or sell copies of the Software, and to permit persons to whom the\r
+ * Software is furnished to do so, subject to the following conditions:\r
+ *\r
+ * The above copyright notice and this permission notice shall be included\r
+ * in all copies or substantial portions of the Software.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL\r
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN\r
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+ */\r
+\r
+#if !defined SLANG_COMPILE_FUNCTION_H\r
+#define SLANG_COMPILE_FUNCTION_H\r
+\r
+#if defined __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+typedef enum slang_function_kind_\r
+{\r
+       slang_func_ordinary,\r
+       slang_func_constructor,\r
+       slang_func_operator\r
+} slang_function_kind;\r
+\r
+typedef struct slang_function_\r
+{\r
+       slang_function_kind kind;\r
+       slang_variable header;\r
+       slang_variable_scope *parameters;\r
+       unsigned int param_count;\r
+       slang_operation *body;\r
+       unsigned int address;\r
+} slang_function;\r
+\r
+int slang_function_construct (slang_function *);\r
+void slang_function_destruct (slang_function *);\r
+\r
+typedef struct slang_function_scope_\r
+{\r
+       slang_function *functions;\r
+       unsigned int num_functions;\r
+       struct slang_function_scope_ *outer_scope;\r
+} slang_function_scope;\r
+\r
+int slang_function_scope_construct (slang_function_scope *);\r
+void slang_function_scope_destruct (slang_function_scope *);\r
+int slang_function_scope_find_by_name (slang_function_scope *, const char *, int);\r
+slang_function *slang_function_scope_find (slang_function_scope *, slang_function *, int);\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+#endif\r
+\r
diff --git a/src/mesa/shader/slang/slang_compile_operation.c b/src/mesa/shader/slang/slang_compile_operation.c
new file mode 100644 (file)
index 0000000..f6d371a
--- /dev/null
@@ -0,0 +1,115 @@
+/*\r
+ * Mesa 3-D graphics library\r
+ * Version:  6.5\r
+ *\r
+ * Copyright (C) 2005-2006  Brian Paul   All Rights Reserved.\r
+ *\r
+ * Permission is hereby granted, free of charge, to any person obtaining a\r
+ * copy of this software and associated documentation files (the "Software"),\r
+ * to deal in the Software without restriction, including without limitation\r
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
+ * and/or sell copies of the Software, and to permit persons to whom the\r
+ * Software is furnished to do so, subject to the following conditions:\r
+ *\r
+ * The above copyright notice and this permission notice shall be included\r
+ * in all copies or substantial portions of the Software.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL\r
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN\r
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+ */\r
+\r
+/**\r
+ * \file slang_compile_operation.c\r
+ * slang front-end compiler\r
+ * \author Michal Krol\r
+ */\r
+\r
+#include "imports.h"\r
+#include "slang_utility.h"\r
+#include "slang_compile_variable.h"\r
+#include "slang_compile_struct.h"\r
+#include "slang_compile_operation.h"\r
+#include "slang_compile_function.h"\r
+\r
+/* slang_operation */\r
+\r
+int slang_operation_construct (slang_operation *oper)\r
+{\r
+       oper->type = slang_oper_none;\r
+       oper->children = NULL;\r
+       oper->num_children = 0;\r
+       oper->literal = (float) 0;\r
+       oper->identifier = NULL;\r
+       oper->locals = (slang_variable_scope *) slang_alloc_malloc (sizeof (slang_variable_scope));\r
+       if (oper->locals == NULL)\r
+               return 0;\r
+       if (!slang_variable_scope_construct (oper->locals))\r
+       {\r
+               slang_alloc_free (oper->locals);\r
+               return 0;\r
+       }\r
+       return 1;\r
+}\r
+\r
+void slang_operation_destruct (slang_operation *oper)\r
+{\r
+       unsigned int i;\r
+\r
+       for (i = 0; i < oper->num_children; i++)\r
+               slang_operation_destruct (oper->children + i);\r
+       slang_alloc_free (oper->children);\r
+       slang_alloc_free (oper->identifier);\r
+       slang_variable_scope_destruct (oper->locals);\r
+       slang_alloc_free (oper->locals);\r
+}\r
+\r
+int slang_operation_copy (slang_operation *x, const slang_operation *y)\r
+{\r
+       slang_operation z;\r
+       unsigned int i;\r
+\r
+       if (!slang_operation_construct (&z))\r
+               return 0;\r
+       z.type = y->type;\r
+       z.children = (slang_operation *) slang_alloc_malloc (y->num_children * sizeof (slang_operation));\r
+       if (z.children == NULL)\r
+       {\r
+               slang_operation_destruct (&z);\r
+               return 0;\r
+       }\r
+       for (z.num_children = 0; z.num_children < y->num_children; z.num_children++)\r
+               if (!slang_operation_construct (&z.children[z.num_children]))\r
+               {\r
+                       slang_operation_destruct (&z);\r
+                       return 0;\r
+               }\r
+       for (i = 0; i < z.num_children; i++)\r
+               if (!slang_operation_copy (&z.children[i], &y->children[i]))\r
+               {\r
+                       slang_operation_destruct (&z);\r
+                       return 0;\r
+               }\r
+       z.literal = y->literal;\r
+       if (y->identifier != NULL)\r
+       {\r
+               z.identifier = slang_string_duplicate (y->identifier);\r
+               if (z.identifier == NULL)\r
+               {\r
+                       slang_operation_destruct (&z);\r
+                       return 0;\r
+               }\r
+       }\r
+       if (!slang_variable_scope_copy (z.locals, y->locals))\r
+       {\r
+               slang_operation_destruct (&z);\r
+               return 0;\r
+       }\r
+       slang_operation_destruct (x);\r
+       *x = z;\r
+       return 1;\r
+}\r
+\r
diff --git a/src/mesa/shader/slang/slang_compile_operation.h b/src/mesa/shader/slang/slang_compile_operation.h
new file mode 100644 (file)
index 0000000..54b2d17
--- /dev/null
@@ -0,0 +1,117 @@
+/*\r
+ * Mesa 3-D graphics library\r
+ * Version:  6.5\r
+ *\r
+ * Copyright (C) 2005-2006  Brian Paul   All Rights Reserved.\r
+ *\r
+ * Permission is hereby granted, free of charge, to any person obtaining a\r
+ * copy of this software and associated documentation files (the "Software"),\r
+ * to deal in the Software without restriction, including without limitation\r
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
+ * and/or sell copies of the Software, and to permit persons to whom the\r
+ * Software is furnished to do so, subject to the following conditions:\r
+ *\r
+ * The above copyright notice and this permission notice shall be included\r
+ * in all copies or substantial portions of the Software.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL\r
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN\r
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+ */\r
+\r
+#if !defined SLANG_COMPILE_OPERATION_H\r
+#define SLANG_COMPILE_OPERATION_H\r
+\r
+#if defined __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+typedef enum slang_operation_type_\r
+{\r
+       slang_oper_none,\r
+       slang_oper_block_no_new_scope,\r
+       slang_oper_block_new_scope,\r
+       slang_oper_variable_decl,\r
+       slang_oper_asm,\r
+       slang_oper_break,\r
+       slang_oper_continue,\r
+       slang_oper_discard,\r
+       slang_oper_return,\r
+       slang_oper_expression,\r
+       slang_oper_if,\r
+       slang_oper_while,\r
+       slang_oper_do,\r
+       slang_oper_for,\r
+       slang_oper_void,\r
+       slang_oper_literal_bool,\r
+       slang_oper_literal_int,\r
+       slang_oper_literal_float,\r
+       slang_oper_identifier,\r
+       slang_oper_sequence,\r
+       slang_oper_assign,\r
+       slang_oper_addassign,\r
+       slang_oper_subassign,\r
+       slang_oper_mulassign,\r
+       slang_oper_divassign,\r
+       /*slang_oper_modassign,*/\r
+       /*slang_oper_lshassign,*/\r
+       /*slang_oper_rshassign,*/\r
+       /*slang_oper_orassign,*/\r
+       /*slang_oper_xorassign,*/\r
+       /*slang_oper_andassign,*/\r
+       slang_oper_select,\r
+       slang_oper_logicalor,\r
+       slang_oper_logicalxor,\r
+       slang_oper_logicaland,\r
+       /*slang_oper_bitor,*/\r
+       /*slang_oper_bitxor,*/\r
+       /*slang_oper_bitand,*/\r
+       slang_oper_equal,\r
+       slang_oper_notequal,\r
+       slang_oper_less,\r
+       slang_oper_greater,\r
+       slang_oper_lessequal,\r
+       slang_oper_greaterequal,\r
+       /*slang_oper_lshift,*/\r
+       /*slang_oper_rshift,*/\r
+       slang_oper_add,\r
+       slang_oper_subtract,\r
+       slang_oper_multiply,\r
+       slang_oper_divide,\r
+       /*slang_oper_modulus,*/\r
+       slang_oper_preincrement,\r
+       slang_oper_predecrement,\r
+       slang_oper_plus,\r
+       slang_oper_minus,\r
+       /*slang_oper_complement,*/\r
+       slang_oper_not,\r
+       slang_oper_subscript,\r
+       slang_oper_call,\r
+       slang_oper_field,\r
+       slang_oper_postincrement,\r
+       slang_oper_postdecrement\r
+} slang_operation_type;\r
+\r
+typedef struct slang_operation_\r
+{\r
+       slang_operation_type type;\r
+       struct slang_operation_ *children;\r
+       unsigned int num_children;\r
+       float literal;          /* type: bool, literal_int, literal_float */\r
+       char *identifier;       /* type: asm, identifier, call, field */\r
+       slang_variable_scope *locals;\r
+} slang_operation;\r
+\r
+int slang_operation_construct (slang_operation *);\r
+void slang_operation_destruct (slang_operation *);\r
+int slang_operation_copy (slang_operation *, const slang_operation *);\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+#endif\r
+\r
diff --git a/src/mesa/shader/slang/slang_compile_struct.c b/src/mesa/shader/slang/slang_compile_struct.c
new file mode 100644 (file)
index 0000000..bad58f4
--- /dev/null
@@ -0,0 +1,191 @@
+/*\r
+ * Mesa 3-D graphics library\r
+ * Version:  6.5\r
+ *\r
+ * Copyright (C) 2005-2006  Brian Paul   All Rights Reserved.\r
+ *\r
+ * Permission is hereby granted, free of charge, to any person obtaining a\r
+ * copy of this software and associated documentation files (the "Software"),\r
+ * to deal in the Software without restriction, including without limitation\r
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
+ * and/or sell copies of the Software, and to permit persons to whom the\r
+ * Software is furnished to do so, subject to the following conditions:\r
+ *\r
+ * The above copyright notice and this permission notice shall be included\r
+ * in all copies or substantial portions of the Software.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL\r
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN\r
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+ */\r
+\r
+/**\r
+ * \file slang_compile_struct.c\r
+ * slang front-end compiler\r
+ * \author Michal Krol\r
+ */\r
+\r
+#include "imports.h"\r
+#include "slang_utility.h"\r
+#include "slang_compile_variable.h"\r
+#include "slang_compile_struct.h"\r
+#include "slang_compile_operation.h"\r
+#include "slang_compile_function.h"\r
+\r
+/* slang_struct_scope */\r
+\r
+int slang_struct_scope_construct (slang_struct_scope *scope)\r
+{\r
+       scope->structs = NULL;\r
+       scope->num_structs = 0;\r
+       scope->outer_scope = NULL;\r
+       return 1;\r
+}\r
+\r
+void slang_struct_scope_destruct (slang_struct_scope *scope)\r
+{\r
+       unsigned int i;\r
+\r
+       for (i = 0; i < scope->num_structs; i++)\r
+               slang_struct_destruct (scope->structs + i);\r
+       slang_alloc_free (scope->structs);\r
+       /* do not free scope->outer_scope */\r
+}\r
+\r
+int slang_struct_scope_copy (slang_struct_scope *x, const slang_struct_scope *y)\r
+{\r
+       slang_struct_scope z;\r
+       unsigned int i;\r
+\r
+       if (!slang_struct_scope_construct (&z))\r
+               return 0;\r
+       z.structs = (slang_struct *) slang_alloc_malloc (y->num_structs * sizeof (slang_struct));\r
+       if (z.structs == NULL)\r
+       {\r
+               slang_struct_scope_destruct (&z);\r
+               return 0;\r
+       }\r
+       for (z.num_structs = 0; z.num_structs < y->num_structs; z.num_structs++)\r
+               if (!slang_struct_construct (&z.structs[z.num_structs]))\r
+               {\r
+                       slang_struct_scope_destruct (&z);\r
+                       return 0;\r
+               }\r
+       for (i = 0; i < z.num_structs; i++)\r
+               if (!slang_struct_copy (&z.structs[i], &y->structs[i]))\r
+               {\r
+                       slang_struct_scope_destruct (&z);\r
+                       return 0;\r
+               }\r
+       z.outer_scope = y->outer_scope;\r
+       slang_struct_scope_destruct (x);\r
+       *x = z;\r
+       return 1;\r
+}\r
+\r
+slang_struct *slang_struct_scope_find (slang_struct_scope *stru, const char *name, int all_scopes)\r
+{\r
+       unsigned int i;\r
+\r
+       for (i = 0; i < stru->num_structs; i++)\r
+               if (slang_string_compare (name, stru->structs[i].name) == 0)\r
+                       return stru->structs + i;\r
+       if (all_scopes && stru->outer_scope != NULL)\r
+               return slang_struct_scope_find (stru->outer_scope, name, 1);\r
+       return NULL;\r
+}\r
+\r
+/* slang_struct */\r
+\r
+int slang_struct_construct (slang_struct *stru)\r
+{\r
+       stru->name = NULL;\r
+       stru->fields = (slang_variable_scope *) slang_alloc_malloc (sizeof (slang_variable_scope));\r
+       if (stru->fields == NULL)\r
+               return 0;\r
+       if (!slang_variable_scope_construct (stru->fields))\r
+       {\r
+               slang_alloc_free (stru->fields);\r
+               return 0;\r
+       }\r
+       stru->structs = (slang_struct_scope *) slang_alloc_malloc (sizeof (slang_struct_scope));\r
+       if (stru->structs == NULL)\r
+       {\r
+               slang_variable_scope_destruct (stru->fields);\r
+               slang_alloc_free (stru->fields);\r
+               return 0;\r
+       }\r
+       if (!slang_struct_scope_construct (stru->structs))\r
+       {\r
+               slang_variable_scope_destruct (stru->fields);\r
+               slang_alloc_free (stru->fields);\r
+               slang_alloc_free (stru->structs);\r
+               return 0;\r
+       }\r
+       return 1;\r
+}\r
+\r
+void slang_struct_destruct (slang_struct *stru)\r
+{\r
+       slang_alloc_free (stru->name);\r
+       slang_variable_scope_destruct (stru->fields);\r
+       slang_alloc_free (stru->fields);\r
+       slang_struct_scope_destruct (stru->structs);\r
+       slang_alloc_free (stru->structs);\r
+}\r
+\r
+int slang_struct_copy (slang_struct *x, const slang_struct *y)\r
+{\r
+       slang_struct z;\r
+\r
+       if (!slang_struct_construct (&z))\r
+               return 0;\r
+       if (y->name != NULL)\r
+       {\r
+               z.name = slang_string_duplicate (y->name);\r
+               if (z.name == NULL)\r
+               {\r
+                       slang_struct_destruct (&z);\r
+                       return 0;\r
+               }\r
+       }\r
+       if (!slang_variable_scope_copy (z.fields, y->fields))\r
+       {\r
+               slang_struct_destruct (&z);\r
+               return 0;\r
+       }\r
+       if (!slang_struct_scope_copy (z.structs, y->structs))\r
+       {\r
+               slang_struct_destruct (&z);\r
+               return 0;\r
+       }\r
+       slang_struct_destruct (x);\r
+       *x = z;\r
+       return 1;\r
+}\r
+\r
+int slang_struct_equal (const slang_struct *x, const slang_struct *y)\r
+{\r
+       unsigned int i;\r
+\r
+       if (x->fields->num_variables != y->fields->num_variables)\r
+               return 0;\r
+       for (i = 0; i < x->fields->num_variables; i++)\r
+       {\r
+               slang_variable *varx = x->fields->variables + i;\r
+               slang_variable *vary = y->fields->variables + i;\r
+               if (slang_string_compare (varx->name, vary->name) != 0)\r
+                       return 0;\r
+               if (!slang_type_specifier_equal (&varx->type.specifier, &vary->type.specifier))\r
+                       return 0;\r
+               if (varx->type.specifier.type == slang_spec_array)\r
+               {\r
+                       /* TODO compare array sizes */\r
+               }\r
+       }\r
+       return 1;\r
+}\r
+\r
diff --git a/src/mesa/shader/slang/slang_compile_struct.h b/src/mesa/shader/slang/slang_compile_struct.h
new file mode 100644 (file)
index 0000000..10af980
--- /dev/null
@@ -0,0 +1,61 @@
+/*\r
+ * Mesa 3-D graphics library\r
+ * Version:  6.5\r
+ *\r
+ * Copyright (C) 2005-2006  Brian Paul   All Rights Reserved.\r
+ *\r
+ * Permission is hereby granted, free of charge, to any person obtaining a\r
+ * copy of this software and associated documentation files (the "Software"),\r
+ * to deal in the Software without restriction, including without limitation\r
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
+ * and/or sell copies of the Software, and to permit persons to whom the\r
+ * Software is furnished to do so, subject to the following conditions:\r
+ *\r
+ * The above copyright notice and this permission notice shall be included\r
+ * in all copies or substantial portions of the Software.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL\r
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN\r
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+ */\r
+\r
+#if !defined SLANG_COMPILE_STRUCT_H\r
+#define SLANG_COMPILE_STRUCT_H\r
+\r
+#if defined __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+typedef struct slang_struct_scope_\r
+{\r
+       struct slang_struct_ *structs;\r
+       unsigned int num_structs;\r
+       struct slang_struct_scope_ *outer_scope;\r
+} slang_struct_scope;\r
+\r
+int slang_struct_scope_construct (slang_struct_scope *);\r
+void slang_struct_scope_destruct (slang_struct_scope *);\r
+int slang_struct_scope_copy (slang_struct_scope *, const slang_struct_scope *);\r
+struct slang_struct_ *slang_struct_scope_find (slang_struct_scope *, const char *, int);\r
+\r
+typedef struct slang_struct_\r
+{\r
+       char *name;\r
+       struct slang_variable_scope_ *fields;\r
+       slang_struct_scope *structs;\r
+} slang_struct;\r
+\r
+int slang_struct_construct (slang_struct *);\r
+void slang_struct_destruct (slang_struct *);\r
+int slang_struct_copy (slang_struct *, const slang_struct *);\r
+int slang_struct_equal (const slang_struct *, const slang_struct *);\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+#endif\r
+\r
diff --git a/src/mesa/shader/slang/slang_compile_variable.c b/src/mesa/shader/slang/slang_compile_variable.c
new file mode 100644 (file)
index 0000000..39aabd8
--- /dev/null
@@ -0,0 +1,371 @@
+/*\r
+ * Mesa 3-D graphics library\r
+ * Version:  6.5\r
+ *\r
+ * Copyright (C) 2005-2006  Brian Paul   All Rights Reserved.\r
+ *\r
+ * Permission is hereby granted, free of charge, to any person obtaining a\r
+ * copy of this software and associated documentation files (the "Software"),\r
+ * to deal in the Software without restriction, including without limitation\r
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
+ * and/or sell copies of the Software, and to permit persons to whom the\r
+ * Software is furnished to do so, subject to the following conditions:\r
+ *\r
+ * The above copyright notice and this permission notice shall be included\r
+ * in all copies or substantial portions of the Software.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL\r
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN\r
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+ */\r
+\r
+/**\r
+ * \file slang_compile_variable.c\r
+ * slang front-end compiler\r
+ * \author Michal Krol\r
+ */\r
+\r
+#include "imports.h"\r
+#include "slang_utility.h"\r
+#include "slang_compile_variable.h"\r
+#include "slang_compile_struct.h"\r
+#include "slang_compile_operation.h"\r
+#include "slang_compile_function.h"\r
+\r
+/* slang_type_specifier_type */\r
+\r
+typedef struct\r
+{\r
+       const char *name;\r
+       slang_type_specifier_type type;\r
+} type_specifier_type_name;\r
+\r
+static type_specifier_type_name type_specifier_type_names[] = {\r
+       { "void", slang_spec_void },\r
+       { "bool", slang_spec_bool },\r
+       { "bvec2", slang_spec_bvec2 },\r
+       { "bvec3", slang_spec_bvec3 },\r
+       { "bvec4", slang_spec_bvec4 },\r
+       { "int", slang_spec_int },\r
+       { "ivec2", slang_spec_ivec2 },\r
+       { "ivec3", slang_spec_ivec3 },\r
+       { "ivec4", slang_spec_ivec4 },\r
+       { "float", slang_spec_float },\r
+       { "vec2", slang_spec_vec2 },\r
+       { "vec3", slang_spec_vec3 },\r
+       { "vec4", slang_spec_vec4 },\r
+       { "mat2", slang_spec_mat2 },\r
+       { "mat3", slang_spec_mat3 },\r
+       { "mat4", slang_spec_mat4 },\r
+       { "sampler1D", slang_spec_sampler1D },\r
+       { "sampler2D", slang_spec_sampler2D },\r
+       { "sampler3D", slang_spec_sampler3D },\r
+       { "samplerCube", slang_spec_samplerCube },\r
+       { "sampler1DShadow", slang_spec_sampler1DShadow },\r
+       { "sampler2DShadow", slang_spec_sampler2DShadow },\r
+       { NULL, slang_spec_void }\r
+};\r
+\r
+slang_type_specifier_type slang_type_specifier_type_from_string (const char *name)\r
+{\r
+       type_specifier_type_name *p = type_specifier_type_names;\r
+       while (p->name != NULL)\r
+       {\r
+               if (slang_string_compare (p->name, name) == 0)\r
+                       break;\r
+               p++;\r
+       }\r
+       return p->type;\r
+}\r
+\r
+const char *slang_type_specifier_type_to_string (slang_type_specifier_type type)\r
+{\r
+       type_specifier_type_name *p = type_specifier_type_names;\r
+       while (p->name != NULL)\r
+       {\r
+               if (p->type == type)\r
+                       break;\r
+               p++;\r
+       }\r
+       return p->name;\r
+}\r
+\r
+/* slang_type_specifier */\r
+\r
+int slang_type_specifier_construct (slang_type_specifier *spec)\r
+{\r
+       spec->type = slang_spec_void;\r
+       spec->_struct = NULL;\r
+       spec->_array = NULL;\r
+       return 1;\r
+}\r
+\r
+void slang_type_specifier_destruct (slang_type_specifier *spec)\r
+{\r
+       if (spec->_struct != NULL)\r
+       {\r
+               slang_struct_destruct (spec->_struct);\r
+               slang_alloc_free (spec->_struct);\r
+       }\r
+       if (spec->_array != NULL)\r
+       {\r
+               slang_type_specifier_destruct (spec->_array);\r
+               slang_alloc_free (spec->_array);\r
+       }\r
+}\r
+\r
+int slang_type_specifier_copy (slang_type_specifier *x, const slang_type_specifier *y)\r
+{\r
+       slang_type_specifier z;\r
+\r
+       if (!slang_type_specifier_construct (&z))\r
+               return 0;\r
+       z.type = y->type;\r
+       if (z.type == slang_spec_struct)\r
+       {\r
+               z._struct = (slang_struct *) slang_alloc_malloc (sizeof (slang_struct));\r
+               if (z._struct == NULL)\r
+               {\r
+                       slang_type_specifier_destruct (&z);\r
+                       return 0;\r
+               }\r
+               if (!slang_struct_construct (z._struct))\r
+               {\r
+                       slang_alloc_free (z._struct);\r
+                       slang_type_specifier_destruct (&z);\r
+                       return 0;\r
+               }\r
+               if (!slang_struct_copy (z._struct, y->_struct))\r
+               {\r
+                       slang_type_specifier_destruct (&z);\r
+                       return 0;\r
+               }\r
+       }\r
+       else if (z.type == slang_spec_array)\r
+       {\r
+               z._array = (slang_type_specifier *) slang_alloc_malloc (sizeof (slang_type_specifier));\r
+               if (z._array == NULL)\r
+               {\r
+                       slang_type_specifier_destruct (&z);\r
+                       return 0;\r
+               }\r
+               if (!slang_type_specifier_construct (z._array))\r
+               {\r
+                       slang_alloc_free (z._array);\r
+                       slang_type_specifier_destruct (&z);\r
+                       return 0;\r
+               }\r
+               if (!slang_type_specifier_copy (z._array, y->_array))\r
+               {\r
+                       slang_type_specifier_destruct (&z);\r
+                       return 0;\r
+               }\r
+       }\r
+       slang_type_specifier_destruct (x);\r
+       *x = z;\r
+       return 1;\r
+}\r
+\r
+int slang_type_specifier_equal (const slang_type_specifier *x, const slang_type_specifier *y)\r
+{\r
+       if (x->type != y->type)\r
+               return 0;\r
+       if (x->type == slang_spec_struct)\r
+               return slang_struct_equal (x->_struct, y->_struct);\r
+       if (x->type == slang_spec_array)\r
+               return slang_type_specifier_equal (x->_array, y->_array);\r
+       return 1;\r
+}\r
+\r
+/* slang_fully_specified_type */\r
+\r
+int slang_fully_specified_type_construct (slang_fully_specified_type *type)\r
+{\r
+       type->qualifier = slang_qual_none;\r
+       if (!slang_type_specifier_construct (&type->specifier))\r
+               return 0;\r
+       return 1;\r
+}\r
+\r
+void slang_fully_specified_type_destruct (slang_fully_specified_type *type)\r
+{\r
+       slang_type_specifier_destruct (&type->specifier);\r
+}\r
+\r
+int slang_fully_specified_type_copy (slang_fully_specified_type *x, const slang_fully_specified_type *y)\r
+{\r
+       slang_fully_specified_type z;\r
+\r
+       if (!slang_fully_specified_type_construct (&z))\r
+               return 0;\r
+       z.qualifier = y->qualifier;\r
+       if (!slang_type_specifier_copy (&z.specifier, &y->specifier))\r
+       {\r
+               slang_fully_specified_type_destruct (&z);\r
+               return 0;\r
+       }\r
+       slang_fully_specified_type_destruct (x);\r
+       *x = z;\r
+       return 1;\r
+}\r
+\r
+/* slang_variable_scope */\r
+\r
+int slang_variable_scope_construct (slang_variable_scope *scope)\r
+{\r
+       scope->variables = NULL;\r
+       scope->num_variables = 0;\r
+       scope->outer_scope = NULL;\r
+       return 1;\r
+}\r
+\r
+void slang_variable_scope_destruct (slang_variable_scope *scope)\r
+{\r
+       unsigned int i;\r
+\r
+       for (i = 0; i < scope->num_variables; i++)\r
+               slang_variable_destruct (scope->variables + i);\r
+       slang_alloc_free (scope->variables);\r
+       /* do not free scope->outer_scope */\r
+}\r
+\r
+int slang_variable_scope_copy (slang_variable_scope *x, const slang_variable_scope *y)\r
+{\r
+       slang_variable_scope z;\r
+       unsigned int i;\r
+\r
+       if (!slang_variable_scope_construct (&z))\r
+               return 0;\r
+       z.variables = (slang_variable *) slang_alloc_malloc (y->num_variables * sizeof (slang_variable));\r
+       if (z.variables == NULL)\r
+       {\r
+               slang_variable_scope_destruct (&z);\r
+               return 0;\r
+       }\r
+       for (z.num_variables = 0; z.num_variables < y->num_variables; z.num_variables++)\r
+               if (!slang_variable_construct (&z.variables[z.num_variables]))\r
+               {\r
+                       slang_variable_scope_destruct (&z);\r
+                       return 0;\r
+               }\r
+       for (i = 0; i < z.num_variables; i++)\r
+               if (!slang_variable_copy (&z.variables[i], &y->variables[i]))\r
+               {\r
+                       slang_variable_scope_destruct (&z);\r
+                       return 0;\r
+               }\r
+       z.outer_scope = y->outer_scope;\r
+       slang_variable_scope_destruct (x);\r
+       *x = z;\r
+       return 1;\r
+}\r
+\r
+/* slang_variable */\r
+\r
+int slang_variable_construct (slang_variable *var)\r
+{\r
+       if (!slang_fully_specified_type_construct (&var->type))\r
+               return 0;\r
+       var->name = NULL;\r
+       var->array_size = NULL;\r
+       var->initializer = NULL;\r
+       var->address = ~0;\r
+       return 1;\r
+}\r
+\r
+void slang_variable_destruct (slang_variable *var)\r
+{\r
+       slang_fully_specified_type_destruct (&var->type);\r
+       slang_alloc_free (var->name);\r
+       if (var->array_size != NULL)\r
+       {\r
+               slang_operation_destruct (var->array_size);\r
+               slang_alloc_free (var->array_size);\r
+       }\r
+       if (var->initializer != NULL)\r
+       {\r
+               slang_operation_destruct (var->initializer);\r
+               slang_alloc_free (var->initializer);\r
+       }\r
+}\r
+\r
+int slang_variable_copy (slang_variable *x, const slang_variable *y)\r
+{\r
+       slang_variable z;\r
+\r
+       if (!slang_variable_construct (&z))\r
+               return 0;\r
+       if (!slang_fully_specified_type_copy (&z.type, &y->type))\r
+       {\r
+               slang_variable_destruct (&z);\r
+               return 0;\r
+       }\r
+       if (y->name != NULL)\r
+       {\r
+               z.name = slang_string_duplicate (y->name);\r
+               if (z.name == NULL)\r
+               {\r
+                       slang_variable_destruct (&z);\r
+                       return 0;\r
+               }\r
+       }\r
+       if (y->array_size != NULL)\r
+       {\r
+               z.array_size = (slang_operation *) slang_alloc_malloc (sizeof (slang_operation));\r
+               if (z.array_size == NULL)\r
+               {\r
+                       slang_variable_destruct (&z);\r
+                       return 0;\r
+               }\r
+               if (!slang_operation_construct (z.array_size))\r
+               {\r
+                       slang_alloc_free (z.array_size);\r
+                       slang_variable_destruct (&z);\r
+                       return 0;\r
+               }\r
+               if (!slang_operation_copy (z.array_size, y->array_size))\r
+               {\r
+                       slang_variable_destruct (&z);\r
+                       return 0;\r
+               }\r
+       }\r
+       if (y->initializer != NULL)\r
+       {\r
+               z.initializer = (slang_operation *) slang_alloc_malloc (sizeof (slang_operation));\r
+               if (z.initializer == NULL)\r
+               {\r
+                       slang_variable_destruct (&z);\r
+                       return 0;\r
+               }\r
+               if (!slang_operation_construct (z.initializer))\r
+               {\r
+                       slang_alloc_free (z.initializer);\r
+                       slang_variable_destruct (&z);\r
+                       return 0;\r
+               }\r
+               if (!slang_operation_copy (z.initializer, y->initializer))\r
+               {\r
+                       slang_variable_destruct (&z);\r
+                       return 0;\r
+               }\r
+       }\r
+       slang_variable_destruct (x);\r
+       *x = z;\r
+       return 1;\r
+}\r
+\r
+slang_variable *_slang_locate_variable (slang_variable_scope *scope, const char *name, int all)\r
+{\r
+       unsigned int i;\r
+\r
+       for (i = 0; i < scope->num_variables; i++)\r
+               if (slang_string_compare (name, scope->variables[i].name) == 0)\r
+                       return scope->variables + i;\r
+       if (all && scope->outer_scope != NULL)\r
+               return _slang_locate_variable (scope->outer_scope, name, 1);\r
+       return NULL;\r
+}\r
+\r
diff --git a/src/mesa/shader/slang/slang_compile_variable.h b/src/mesa/shader/slang/slang_compile_variable.h
new file mode 100644 (file)
index 0000000..d82a661
--- /dev/null
@@ -0,0 +1,129 @@
+/*\r
+ * Mesa 3-D graphics library\r
+ * Version:  6.5\r
+ *\r
+ * Copyright (C) 2005-2006  Brian Paul   All Rights Reserved.\r
+ *\r
+ * Permission is hereby granted, free of charge, to any person obtaining a\r
+ * copy of this software and associated documentation files (the "Software"),\r
+ * to deal in the Software without restriction, including without limitation\r
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
+ * and/or sell copies of the Software, and to permit persons to whom the\r
+ * Software is furnished to do so, subject to the following conditions:\r
+ *\r
+ * The above copyright notice and this permission notice shall be included\r
+ * in all copies or substantial portions of the Software.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL\r
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN\r
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+ */\r
+\r
+#if !defined SLANG_COMPILE_VARIABLE_H\r
+#define SLANG_COMPILE_VARIABLE_H\r
+\r
+#if defined __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+typedef enum slang_type_qualifier_\r
+{\r
+       slang_qual_none,\r
+       slang_qual_const,\r
+       slang_qual_attribute,\r
+       slang_qual_varying,\r
+       slang_qual_uniform,\r
+       slang_qual_out,\r
+       slang_qual_inout,\r
+       slang_qual_fixedoutput, /* internal */\r
+       slang_qual_fixedinput   /* internal */\r
+} slang_type_qualifier;\r
+\r
+typedef enum slang_type_specifier_type_\r
+{\r
+       slang_spec_void,\r
+       slang_spec_bool,\r
+       slang_spec_bvec2,\r
+       slang_spec_bvec3,\r
+       slang_spec_bvec4,\r
+       slang_spec_int,\r
+       slang_spec_ivec2,\r
+       slang_spec_ivec3,\r
+       slang_spec_ivec4,\r
+       slang_spec_float,\r
+       slang_spec_vec2,\r
+       slang_spec_vec3,\r
+       slang_spec_vec4,\r
+       slang_spec_mat2,\r
+       slang_spec_mat3,\r
+       slang_spec_mat4,\r
+       slang_spec_sampler1D,\r
+       slang_spec_sampler2D,\r
+       slang_spec_sampler3D,\r
+       slang_spec_samplerCube,\r
+       slang_spec_sampler1DShadow,\r
+       slang_spec_sampler2DShadow,\r
+       slang_spec_struct,\r
+       slang_spec_array\r
+} slang_type_specifier_type;\r
+\r
+slang_type_specifier_type slang_type_specifier_type_from_string (const char *);\r
+const char *slang_type_specifier_type_to_string (slang_type_specifier_type);\r
+\r
+typedef struct slang_type_specifier_\r
+{\r
+       slang_type_specifier_type type;\r
+       struct slang_struct_ *_struct;                  /* type: spec_struct */\r
+       struct slang_type_specifier_ *_array;   /* type: spec_array */\r
+} slang_type_specifier;\r
+\r
+int slang_type_specifier_construct (slang_type_specifier *);\r
+void slang_type_specifier_destruct (slang_type_specifier *);\r
+int slang_type_specifier_copy (slang_type_specifier *, const slang_type_specifier *);\r
+int slang_type_specifier_equal (const slang_type_specifier *, const slang_type_specifier *);\r
+\r
+typedef struct slang_fully_specified_type_\r
+{\r
+       slang_type_qualifier qualifier;\r
+       slang_type_specifier specifier;\r
+} slang_fully_specified_type;\r
+\r
+int slang_fully_specified_type_construct (slang_fully_specified_type *);\r
+void slang_fully_specified_type_destruct (slang_fully_specified_type *);\r
+int slang_fully_specified_type_copy (slang_fully_specified_type *, const slang_fully_specified_type *);\r
+\r
+typedef struct slang_variable_scope_\r
+{\r
+       struct slang_variable_ *variables;\r
+       unsigned int num_variables;\r
+       struct slang_variable_scope_ *outer_scope;\r
+} slang_variable_scope;\r
+\r
+int slang_variable_scope_construct (slang_variable_scope *);\r
+void slang_variable_scope_destruct (slang_variable_scope *);\r
+int slang_variable_scope_copy (slang_variable_scope *, const slang_variable_scope *);\r
+\r
+typedef struct slang_variable_\r
+{\r
+       slang_fully_specified_type type;\r
+       char *name;\r
+       struct slang_operation_ *array_size;    /* type: spec_array */\r
+       struct slang_operation_ *initializer;\r
+       unsigned int address;\r
+} slang_variable;\r
+\r
+int slang_variable_construct (slang_variable *);\r
+void slang_variable_destruct (slang_variable *);\r
+int slang_variable_copy (slang_variable *, const slang_variable *);\r
+\r
+slang_variable *_slang_locate_variable (slang_variable_scope *scope, const char *name, int all);\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+#endif\r
+\r
index 3b2fda4..8a608c4 100644 (file)
@@ -1,8 +1,8 @@
 /*
  * Mesa 3-D graphics library
- * Version:  6.3
+ * Version:  6.5
  *
- * Copyright (C) 2005  Brian Paul   All Rights Reserved.
+ * Copyright (C) 2005-2006  Brian Paul   All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -112,19 +112,20 @@ static int aggregate_matrix (slang_storage_aggregate *agg, slang_storage_type ba
        return 1;
 }
 
-static int aggregate_variables (slang_storage_aggregate *agg, const slang_variable_scope *vars,
-       slang_function_scope *funcs, slang_struct_scope *structs)
+static int aggregate_variables (slang_storage_aggregate *agg, slang_variable_scope *vars,
+       slang_function_scope *funcs, slang_struct_scope *structs, slang_variable_scope *globals)
 {
        unsigned int i;
        for (i = 0; i < vars->num_variables; i++)
                if (!_slang_aggregate_variable (agg, &vars->variables[i].type.specifier,
-                       vars->variables[i].array_size, funcs, structs))
+                               vars->variables[i].array_size, funcs, structs, globals))
                        return 0;
        return 1;
 }
 
 int _slang_aggregate_variable (slang_storage_aggregate *agg, slang_type_specifier *spec,
-       slang_operation *array_size, slang_function_scope *funcs, slang_struct_scope *structs)
+       slang_operation *array_size, slang_function_scope *funcs, slang_struct_scope *structs,
+       slang_variable_scope *vars)
 {
        switch (spec->type)
        {
@@ -166,7 +167,7 @@ int _slang_aggregate_variable (slang_storage_aggregate *agg, slang_type_specifie
        case slang_spec_sampler2DShadow:
                return aggregate_vector (agg, slang_stor_int, 1);
        case slang_spec_struct:
-               return aggregate_variables (agg, spec->_struct->fields, funcs, structs);
+               return aggregate_variables (agg, spec->_struct->fields, funcs, structs, vars);
        case slang_spec_array:
                {
                        slang_storage_array *arr;
@@ -185,13 +186,12 @@ int _slang_aggregate_variable (slang_storage_aggregate *agg, slang_type_specifie
                        if (arr->aggregate == NULL)
                                return 0;
                        slang_storage_aggregate_construct (arr->aggregate);
-                       if (!_slang_aggregate_variable (arr->aggregate, spec->_array, NULL, funcs, structs))
+                       if (!_slang_aggregate_variable (arr->aggregate, spec->_array, NULL, funcs, structs, vars))
                                return 0;
                        slang_assembly_file_construct (&file);
                        space.funcs = funcs;
                        space.structs = structs;
-                       /* XXX: vars! */
-                       space.vars = NULL;
+                       space.vars = vars;
                        if (!_slang_assemble_operation (&file, array_size, 0, &flow, &space, &info, &stk))
                        {
                                slang_assembly_file_destruct (&file);
index 77962c1..b875ce6 100644 (file)
@@ -1,8 +1,8 @@
 /*
  * Mesa 3-D graphics library
- * Version:  6.3
+ * Version:  6.5
  *
- * Copyright (C) 2005  Brian Paul   All Rights Reserved.
+ * Copyright (C) 2005-2006  Brian Paul   All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -85,7 +85,8 @@ void slang_storage_aggregate_construct (slang_storage_aggregate *);
 void slang_storage_aggregate_destruct (slang_storage_aggregate *);
 
 int _slang_aggregate_variable (slang_storage_aggregate *, struct slang_type_specifier_ *,
-       struct slang_operation_ *, struct slang_function_scope_ *, slang_struct_scope *);
+       struct slang_operation_ *, struct slang_function_scope_ *, slang_struct_scope *,
+       slang_variable_scope *);
 
 /*
        returns total size (in machine units) of the given aggregate