remove stray tab
[mesa.git] / src / mesa / shader / slang / slang_compile.c
index efb23255f94e91ddbf08b7d6818ac93fcbac6b4e..c459eb29e744a72baea680004c666cc59bf3a7f0 100644 (file)
@@ -38,6 +38,8 @@
 #include "slang_preprocess.h"
 #include "slang_storage.h"
 #include "slang_error.h"
+#include "slang_emit.h"
+#include "slang_vartable.h"
 
 #include "slang_print.h"
 
@@ -97,7 +99,9 @@ _slang_code_object_ctr(slang_code_object * self)
    for (i = 0; i < SLANG_BUILTIN_TOTAL; i++)
       _slang_code_unit_ctr(&self->builtin[i], self);
    _slang_code_unit_ctr(&self->unit, self);
+#if 01
    _slang_assembly_file_ctr(&self->assembly);
+#endif
    slang_machine_ctr(&self->machine);
    self->varpool.next_addr = 0;
    slang_atom_pool_construct(&self->atompool);
@@ -115,7 +119,9 @@ _slang_code_object_dtr(slang_code_object * self)
    for (i = 0; i < SLANG_BUILTIN_TOTAL; i++)
       _slang_code_unit_dtr(&self->builtin[i]);
    _slang_code_unit_dtr(&self->unit);
+#if 01
    slang_assembly_file_destruct(&self->assembly);
+#endif
    slang_machine_dtr(&self->machine);
    slang_atom_pool_destruct(&self->atompool);
    slang_export_data_table_dtr(&self->expdata);
@@ -247,6 +253,7 @@ typedef struct slang_output_ctx_
    slang_var_pool *global_pool;
    slang_machine *machine;
    struct gl_program *program;
+   slang_var_table *vartable;
 } slang_output_ctx;
 
 /* _slang_compile() */
@@ -866,7 +873,7 @@ parse_statement(slang_parse_ctx * C, slang_output_ctx * O,
                slang_operation *o = &oper->children[i - first_var];
                o->type = slang_oper_variable_decl;
                o->locals->outer_scope = O->vars;
-               o->a_id = O->vars->variables[i].a_name;
+               o->a_id = O->vars->variables[i]->a_name;
             }
          }
       }
@@ -877,9 +884,6 @@ parse_statement(slang_parse_ctx * C, slang_output_ctx * O,
        */
       oper->type = slang_oper_asm;
       oper->a_id = parse_identifier(C);
-      if (strcmp((char*)oper->a_id, "dot") == 0) {
-         printf("Assemble dot! **************************\n");
-      }
       if (oper->a_id == SLANG_ATOM_NULL)
          return 0;
       while (*C->I != OP_END) {
@@ -1545,15 +1549,19 @@ parse_function_definition(slang_parse_ctx * C, slang_output_ctx * O,
 static GLboolean
 initialize_global(slang_assemble_ctx * A, slang_variable * var)
 {
+#if 01
    slang_assembly_file_restore_point point;
+#endif
    slang_machine mach;
    slang_assembly_local_info save_local = A->local;
    slang_operation op_id, op_assign;
    GLboolean result;
 
+#if 01
    /* save the current assembly */
    if (!slang_assembly_file_restore_point_save(A->file, &point))
       return GL_FALSE;
+#endif
 
    /* setup the machine */
    mach = *A->mach;
@@ -1576,13 +1584,13 @@ initialize_global(slang_assemble_ctx * A, slang_variable * var)
 
    /* put the variable into operation's scope */
    op_id.locals->variables =
-      (slang_variable *) slang_alloc_malloc(sizeof(slang_variable));
+      (slang_variable **) slang_alloc_malloc(sizeof(slang_variable *));
    if (op_id.locals->variables == NULL) {
       slang_operation_destruct(&op_id);
       return GL_FALSE;
    }
    op_id.locals->num_variables = 1;
-   op_id.locals->variables[0] = *var;
+   op_id.locals->variables[0] = var;
 
    /* construct the assignment expression */
    if (!slang_operation_construct(&op_assign)) {
@@ -1603,8 +1611,12 @@ initialize_global(slang_assemble_ctx * A, slang_variable * var)
    op_assign.children[0] = op_id;
    op_assign.children[1] = *var->initializer;
 
+#if 0 /* this should go away */
    /* insert the actual expression */
    result = _slang_assemble_operation(A, &op_assign, slang_ref_forbid);
+#else
+   result = 1;
+#endif
 
    /* carefully destroy the operations */
    op_assign.num_children = 0;
@@ -1620,12 +1632,16 @@ initialize_global(slang_assemble_ctx * A, slang_variable * var)
       return GL_FALSE;
 
    /* execute the expression */
+#if 0
    if (!_slang_execute2(A->file, &mach))
       return GL_FALSE;
+#endif
 
+#if 01
    /* restore the old assembly */
    if (!slang_assembly_file_restore_point_load(A->file, &point))
       return GL_FALSE;
+#endif
    A->local = save_local;
 
    /* now we copy the contents of the initialized variable back to the original machine */
@@ -1719,8 +1735,23 @@ parse_init_declarator(slang_parse_ctx * C, slang_output_ctx * O,
    }
 
 #if 1
-   if (C->global_scope /*&& O->program*/)
-      _slang_codegen_global_variable(var, O->program, C->type);
+   if (C->global_scope) {
+      slang_assemble_ctx A;
+
+      A.file = O->assembly;
+      A.mach = O->machine;
+      A.atoms = C->atoms;
+      A.space.funcs = O->funs;
+      A.space.structs = O->structs;
+      A.space.vars = O->vars;
+      A.program = O->program;
+#if 0
+      A.codegen = O->codegen;
+#endif
+      A.vartable = O->vartable;
+
+      _slang_codegen_global_variable(&A, var, C->type);
+   }
 #endif
 
    /* allocate global address space for a variable with a known size */
@@ -1880,6 +1911,10 @@ parse_function(slang_parse_ctx * C, slang_output_ctx * O, int definition,
       A.space.structs = O->structs;
       A.space.vars = O->vars;
       A.program = O->program;
+#if 0
+      A.codegen = O->codegen;
+#endif
+      A.vartable = O->vartable;
 
       _slang_reset_error();
 
@@ -1889,14 +1924,14 @@ parse_function(slang_parse_ctx * C, slang_output_ctx * O, int definition,
                             (*parsed_func_ret)->param_count);
 #endif
 
-
+#if 0
       if (!_slang_assemble_function(&A, *parsed_func_ret)) {
          /* propogate the error message back through the info log */
          C->L->text = _mesa_strdup(_slang_error_text());
          C->L->dont_free_text = GL_FALSE;
          return GL_FALSE;
       }
-
+#endif
 
 #if 0
       printf("**************************************\n");
@@ -1944,6 +1979,7 @@ parse_code_unit(slang_parse_ctx * C, slang_code_unit * unit,
                 struct gl_program *program)
 {
    slang_output_ctx o;
+   GLboolean success;
 
    /* setup output context */
    o.funs = &unit->funs;
@@ -1953,6 +1989,7 @@ parse_code_unit(slang_parse_ctx * C, slang_code_unit * unit,
    o.global_pool = &unit->object->varpool;
    o.machine = &unit->object->machine;
    o.program = program;
+   o.vartable = _slang_push_var_table(NULL);
 
    /* parse individual functions and declarations */
    while (*C->I != EXTERNAL_NULL) {
@@ -1960,20 +1997,25 @@ parse_code_unit(slang_parse_ctx * C, slang_code_unit * unit,
       case EXTERNAL_FUNCTION_DEFINITION:
          {
             slang_function *func;
-
-            if (!parse_function(C, &o, 1, &func))
-               return GL_FALSE;
+            success = parse_function(C, &o, 1, &func);
          }
          break;
       case EXTERNAL_DECLARATION:
-         if (!parse_declaration(C, &o))
-            return GL_FALSE;
+         success = parse_declaration(C, &o);
          break;
       default:
+         success = GL_FALSE;
+      }
+
+      if (!success) {
+         /* xxx free codegen */
+         _slang_pop_var_table(o.vartable);
          return GL_FALSE;
       }
    }
    C->I++;
+
+   _slang_pop_var_table(o.vartable);
    return GL_TRUE;
 }
 
@@ -2260,6 +2302,7 @@ _slang_compile(GLcontext *ctx, struct gl_shader *shader)
 
       shader->Programs[0]->Parameters = _mesa_new_parameter_list();
       shader->Programs[0]->Varying = _mesa_new_parameter_list();
+      shader->Programs[0]->Attributes = _mesa_new_parameter_list();
    }
 
    slang_info_log_construct(&info_log);