more slang code
authorMichal Krol <mjkrol@gmail.org>
Wed, 25 May 2005 14:23:00 +0000 (14:23 +0000)
committerMichal Krol <mjkrol@gmail.org>
Wed, 25 May 2005 14:23:00 +0000 (14:23 +0000)
src/mesa/shader/slang/slang_assemble.c
src/mesa/shader/slang/slang_assemble.h
src/mesa/shader/slang/slang_assemble_assignment.c [new file with mode: 0644]
src/mesa/shader/slang/slang_assemble_assignment.h [new file with mode: 0644]
src/mesa/shader/slang/slang_compile.c
src/mesa/shader/slang/slang_storage.c

index 03672b2fca3aaaad42dc7f2e8bf08e34720e6306..d4f635cd0fb1fad88489ea7e0e7e48cddd54edf4 100644 (file)
@@ -36,6 +36,7 @@
 #include "slang_assemble_constructor.h"\r
 #include "slang_assemble_typeinfo.h"\r
 #include "slang_assemble_conditional.h"\r
+#include "slang_assemble_assignment.h"\r
 \r
 /* slang_assembly */\r
 \r
@@ -117,8 +118,8 @@ int slang_assembly_file_push_literal (slang_assembly_file *file, slang_assembly_
 \r
 /* utility functions */\r
 \r
-static int sizeof_variable (slang_type_specifier *spec, slang_operation *array_size,\r
-       slang_assembly_name_space *space, unsigned int *size)\r
+static int sizeof_variable (slang_type_specifier *spec, slang_type_qualifier qual,\r
+       slang_operation *array_size, slang_assembly_name_space *space, unsigned int *size)\r
 {\r
        slang_storage_aggregate agg;\r
 \r
@@ -129,6 +130,8 @@ static int sizeof_variable (slang_type_specifier *spec, slang_operation *array_s
                return 0;\r
        }\r
        *size += _slang_sizeof_aggregate (&agg);\r
+       if (qual == slang_qual_out || qual == slang_qual_inout)\r
+               *size += 4;\r
        slang_storage_aggregate_destruct (&agg);\r
        return 1;\r
 }\r
@@ -137,7 +140,10 @@ static int sizeof_variable2 (slang_variable *var, slang_assembly_name_space *spa
        unsigned int *size)\r
 {\r
        var->address = *size;\r
-       return sizeof_variable (&var->type.specifier, var->array_size, space, size);\r
+       if (var->type.qualifier == slang_qual_out || var->type.qualifier == slang_qual_inout)\r
+               var->address += 4;\r
+       return sizeof_variable (&var->type.specifier, var->type.qualifier, var->array_size, space,\r
+               size);\r
 }\r
 \r
 static int sizeof_variables (slang_variable_scope *vars, unsigned int start, unsigned int stop,\r
@@ -197,8 +203,8 @@ slang_function *_slang_locate_function (const char *name, slang_operation *param
                        slang_assembly_typeinfo_destruct (&ti);\r
                        /* "out" and "inout" formal parameter requires the actual parameter to be l-value */\r
                        if (!ti.can_be_referenced &&\r
-                               f->parameters->variables[j].type.qualifier != slang_qual_out &&\r
-                               f->parameters->variables[j].type.qualifier != slang_qual_inout)\r
+                               (f->parameters->variables[j].type.qualifier == slang_qual_out ||\r
+                               f->parameters->variables[j].type.qualifier == slang_qual_inout))\r
                                break;\r
                }\r
                if (j == num_params)\r
@@ -235,7 +241,8 @@ int _slang_assemble_function (slang_assembly_file *file, slang_function *fun,
        /* calculate return value and parameters size */\r
        param_size = 0;\r
        if (fun->header.type.specifier.type != slang_spec_void)\r
-               if (!sizeof_variable (&fun->header.type.specifier, NULL, space, &param_size))\r
+               if (!sizeof_variable (&fun->header.type.specifier, slang_qual_none, NULL, space,\r
+                       &param_size))\r
                        return 0;\r
        info.ret_size = param_size;\r
        if (!sizeof_variables (fun->parameters, 0, fun->param_count, space, &param_size))\r
@@ -312,7 +319,7 @@ int _slang_cleanup_stack (slang_assembly_file *file, slang_operation *op, int re
        else\r
        {\r
                size = 0;\r
-               if (!sizeof_variable (&ti.spec, NULL, space, &size))\r
+               if (!sizeof_variable (&ti.spec, slang_qual_none, NULL, space, &size))\r
                {\r
                        slang_assembly_typeinfo_destruct (&ti);\r
                        return 0;\r
@@ -381,7 +388,7 @@ static int dereference_aggregate (slang_assembly_file *file, const slang_storage
        return 1;\r
 }\r
 /* XXX: general swizzle! */\r
-static int dereference (slang_assembly_file *file, slang_operation *op,\r
+int dereference (slang_assembly_file *file, slang_operation *op,\r
        slang_assembly_name_space *space, slang_assembly_local_info *info)\r
 {\r
        slang_assembly_typeinfo ti;\r
@@ -416,15 +423,15 @@ static int call_function (slang_assembly_file *file, slang_function *fun, slang_
        unsigned int param_count, int assignment, slang_assembly_name_space *space,\r
        slang_assembly_local_info *info)\r
 {\r
-       unsigned int ret_size, i;\r
+       unsigned int i;\r
        slang_assembly_stack_info stk;\r
 \r
        /* make room for the return value, if any */\r
-       ret_size = 0;\r
-       if (!sizeof_variable (&fun->header.type.specifier, NULL, space, &ret_size))\r
-               return 0;\r
-       if (ret_size > 0)\r
+       if (fun->header.type.specifier.type != slang_spec_void)\r
        {\r
+               unsigned int ret_size = 0;\r
+               if (!sizeof_variable (&fun->header.type.specifier, slang_qual_none, NULL, space, &ret_size))\r
+                       return 0;\r
                if (!slang_assembly_file_push_label (file, slang_asm_local_alloc, ret_size))\r
                        return 0;\r
        }\r
@@ -434,22 +441,27 @@ static int call_function (slang_assembly_file *file, slang_function *fun, slang_
        {\r
                slang_assembly_flow_control flow;\r
 \r
-               if (i == 0 && assignment)\r
+               if (fun->parameters->variables[i].type.qualifier == slang_qual_inout ||\r
+                       fun->parameters->variables[i].type.qualifier == slang_qual_out)\r
                {\r
                        if (!slang_assembly_file_push_label2 (file, slang_asm_local_addr, info->addr_tmp, 4))\r
                                return 0;\r
                        /* TODO: optimize the "out" parameter case */\r
                        /* TODO: inspect stk */\r
-                       if (!_slang_assemble_operation (file, params, 1, &flow, space, info, &stk))\r
+                       if (!_slang_assemble_operation (file, params + i, 1, &flow, space, info, &stk))\r
                                return 0;\r
                        if (!slang_assembly_file_push (file, slang_asm_addr_copy))\r
                                return 0;\r
                        if (!slang_assembly_file_push (file, slang_asm_addr_deref))\r
                                return 0;\r
-                       if (!slang_assembly_file_push_label2 (file, slang_asm_local_addr, info->addr_tmp, 4))\r
-                               return 0;\r
-                       if (!slang_assembly_file_push (file, slang_asm_addr_deref))\r
-                               return 0;\r
+                       if (i == 0 && assignment)\r
+                       {\r
+                               if (!slang_assembly_file_push_label2 (file, slang_asm_local_addr, info->addr_tmp,\r
+                                       4))\r
+                                       return 0;\r
+                               if (!slang_assembly_file_push (file, slang_asm_addr_deref))\r
+                                       return 0;\r
+                       }\r
                        if (!dereference (file, params, space, info))\r
                                return 0;\r
                }\r
@@ -470,15 +482,26 @@ static int call_function (slang_assembly_file *file, slang_function *fun, slang_
        /* pop the parameters from the stack */\r
        for (i = param_count; i > 0; i--)\r
        {\r
-               /* XXX: copy inout/out params back to the actual variables */\r
-               if (!_slang_cleanup_stack (file, params + i - 1, 0, space))\r
-                       return 0;\r
+               unsigned int j = i - 1;\r
+               if (fun->parameters->variables[j].type.qualifier == slang_qual_inout ||\r
+                       fun->parameters->variables[j].type.qualifier == slang_qual_out)\r
+               {\r
+                       if (!_slang_assemble_assignment (file, params + j, space, info))\r
+                               return 0;\r
+                       if (!slang_assembly_file_push_label (file, slang_asm_local_free, 4))\r
+                               return 0;\r
+               }\r
+               else\r
+               {\r
+                       if (!_slang_cleanup_stack (file, params + j, 0, space))\r
+                               return 0;\r
+               }\r
        }\r
 \r
        return 1;\r
 }\r
 \r
-static int call_function_name (slang_assembly_file *file, const char *name, slang_operation *params,\r
+int call_function_name (slang_assembly_file *file, const char *name, slang_operation *params,\r
        unsigned int param_count, int assignment, slang_assembly_name_space *space,\r
        slang_assembly_local_info *info)\r
 {\r
@@ -543,82 +566,7 @@ static int call_asm_instruction (slang_assembly_file *file, const char *name)
 \r
        return 1;\r
 }\r
-/* XXX: general swizzle! */\r
-static int assign_aggregate (slang_assembly_file *file, const slang_storage_aggregate *agg,\r
-       unsigned int *index, unsigned int size, slang_assembly_local_info *info)\r
-{\r
-       unsigned int i;\r
 \r
-       for (i = 0; i < agg->count; i++)\r
-       {\r
-               const slang_storage_array *arr = agg->arrays + i;\r
-               unsigned int j;\r
-\r
-               for (j = 0; j < arr->length; j++)\r
-               {\r
-                       if (arr->type == slang_stor_aggregate)\r
-                       {\r
-                               if (!assign_aggregate (file, arr->aggregate, index, size, info))\r
-                                       return 0;\r
-                       }\r
-                       else\r
-                       {\r
-                               switch (arr->type)\r
-                               {\r
-                               case slang_stor_bool:\r
-                                       if (!slang_assembly_file_push_label2 (file, slang_asm_bool_copy,\r
-                                               size - *index, *index))\r
-                                               return 0;\r
-                                       break;\r
-                               case slang_stor_int:\r
-                                       if (!slang_assembly_file_push_label2 (file, slang_asm_int_copy,\r
-                                               size - *index, *index))\r
-                                               return 0;\r
-                                       break;\r
-                               case slang_stor_float:\r
-                                       if (!slang_assembly_file_push_label2 (file, slang_asm_float_copy,\r
-                                               size - *index, *index))\r
-                                               return 0;\r
-                                       break;\r
-                               }\r
-                               *index += 4;\r
-                       }\r
-               }\r
-       }\r
-       return 1;\r
-}\r
-/* XXX: general swizzle! */\r
-static int assignment (slang_assembly_file *file, slang_operation *op,\r
-       slang_assembly_name_space *space, slang_assembly_local_info *info)\r
-{\r
-       slang_assembly_typeinfo ti;\r
-       int result;\r
-       slang_storage_aggregate agg;\r
-       unsigned int index, size;\r
-\r
-       slang_assembly_typeinfo_construct (&ti);\r
-       if (!_slang_typeof_operation (op, space, &ti))\r
-       {\r
-               slang_assembly_typeinfo_destruct (&ti);\r
-               return 0;\r
-       }\r
-\r
-       slang_storage_aggregate_construct (&agg);\r
-       if (!_slang_aggregate_variable (&agg, &ti.spec, NULL, space->funcs, space->structs))\r
-       {\r
-               slang_storage_aggregate_destruct (&agg);\r
-               slang_assembly_typeinfo_destruct (&ti);\r
-               return 0;\r
-       }\r
-\r
-       index = 0;\r
-       size = _slang_sizeof_aggregate (&agg);\r
-       result = assign_aggregate (file, &agg, &index, size, info);\r
-\r
-       slang_storage_aggregate_destruct (&agg);\r
-       slang_assembly_typeinfo_destruct (&ti);\r
-       return result;\r
-}\r
 /* XXX: general swizzle! */\r
 static int equality_aggregate (slang_assembly_file *file, const slang_storage_aggregate *agg,\r
        unsigned int *index, unsigned int size, slang_assembly_local_info *info, unsigned int z_label)\r
@@ -798,7 +746,7 @@ int _slang_assemble_operation (slang_assembly_file *file, slang_operation *op, i
                        if (!_slang_assemble_operation (file, op->children, 0, flow, space, info, &stk))\r
                                return 0;\r
                        /* TODO: inspect stk */\r
-                       if (!assignment (file, op->children, space, info))\r
+                       if (!_slang_assemble_assignment (file, op->children, space, info))\r
                                return 0;\r
                        if (!slang_assembly_file_push_label (file, slang_asm_local_free, 4))\r
                                return 0;\r
@@ -852,7 +800,8 @@ int _slang_assemble_operation (slang_assembly_file *file, slang_operation *op, i
                        if (var == NULL)\r
                                return 0;\r
                        size = 0;\r
-                       if (!sizeof_variable (&var->type.specifier, var->array_size, space, &size))\r
+                       if (!sizeof_variable (&var->type.specifier, slang_qual_none, var->array_size, space,\r
+                               &size))\r
                                return 0;\r
                        if (var->initializer != NULL)\r
                        {\r
@@ -897,75 +846,20 @@ int _slang_assemble_operation (slang_assembly_file *file, slang_operation *op, i
                }\r
                break;\r
        case slang_oper_assign:\r
-               {\r
-                       slang_assembly_stack_info stk;\r
-                       if (!reference)\r
-                               if (!slang_assembly_file_push_label2 (file, slang_asm_local_addr, info->addr_tmp,\r
-                                       4))\r
-                                       return 0;\r
-                       if (!_slang_assemble_operation (file, op->children, 1, flow, space, info, &stk))\r
-                               return 0;\r
-                       /* TODO: inspect stk */\r
-                       if (!_slang_assemble_operation (file, op->children + 1, 0, flow, space, info, &stk))\r
-                               return 0;\r
-                       /* TODO: inspect stk */\r
-                       if (!assignment (file, op->children, space, info))\r
-                               return 0;\r
-                       if (!reference)\r
-                       {\r
-                               if (!slang_assembly_file_push (file, slang_asm_addr_copy))\r
-                                       return 0;\r
-                               if (!slang_assembly_file_push_label (file, slang_asm_local_free, 4))\r
-                                       return 0;\r
-                               if (!dereference (file, op->children, space, info))\r
-                                       return 0;\r
-                       }\r
-               }\r
+               if (!_slang_assemble_assign (file, op, "=", reference, space, info))\r
+                       return 0;\r
                break;\r
        case slang_oper_addassign:\r
-               /* TODO: posprawdzaj czy zadzia³a dereferencja */\r
-               if (!call_function_name (file, "+=", op->children, 2, 1, space, info))\r
+               if (!_slang_assemble_assign (file, op, "+=", reference, space, info))\r
                        return 0;\r
-               if (reference)\r
-               {\r
-                       /* TODO: stack is address */\r
-               }\r
-               else\r
-               {\r
-                       if (!dereference (file, op->children, space, info))\r
-                               return 0;\r
-                       /* TODO: stack is operation type */\r
-               }\r
                break;\r
        case slang_oper_subassign:\r
-               /* TODO: posprawdzaj czy zadzia³a dereferencja */\r
-               if (!call_function_name (file, "-=", op->children, 2, 1, space, info))\r
+               if (!_slang_assemble_assign (file, op, "-=", reference, space, info))\r
                        return 0;\r
-               if (reference)\r
-               {\r
-                       /* TODO: stack is address */\r
-               }\r
-               else\r
-               {\r
-                       if (!dereference (file, op->children, space, info))\r
-                               return 0;\r
-                       /* TODO: stack is operation type */\r
-               }\r
                break;\r
        case slang_oper_mulassign:\r
-               /* TODO: posprawdzaj czy zadzia³a dereferencja */\r
-               if (!call_function_name (file, "*=", op->children, 2, 1, space, info))\r
+               if (!_slang_assemble_assign (file, op, "*=", reference, space, info))\r
                        return 0;\r
-               if (reference)\r
-               {\r
-                       /* TODO: stack is address */\r
-               }\r
-               else\r
-               {\r
-                       if (!dereference (file, op->children, space, info))\r
-                               return 0;\r
-                       /* TODO: stack is operation type */\r
-               }\r
                break;\r
        /*case slang_oper_modassign:*/\r
        /*case slang_oper_lshassign:*/\r
@@ -974,19 +868,8 @@ int _slang_assemble_operation (slang_assembly_file *file, slang_operation *op, i
        /*case slang_oper_xorassign:*/\r
        /*case slang_oper_andassign:*/\r
        case slang_oper_divassign:\r
-               /* TODO: posprawdzaj czy zadzia³a dereferencja */\r
-               if (!call_function_name (file, "/=", op->children, 2, 1, space, info))\r
+               if (!_slang_assemble_assign (file, op, "/=", reference, space, info))\r
                        return 0;\r
-               if (reference)\r
-               {\r
-                       /* TODO: stack is address */\r
-               }\r
-               else\r
-               {\r
-                       if (!dereference (file, op->children, space, info))\r
-                               return 0;\r
-                       /* TODO: stack is operation type */\r
-               }\r
                break;\r
        case slang_oper_select:\r
                if (!_slang_assemble_select (file, op, flow, space, info))\r
@@ -1069,32 +952,12 @@ int _slang_assemble_operation (slang_assembly_file *file, slang_operation *op, i
                }\r
                break;\r
        case slang_oper_preincrement:\r
-               /* TODO: posprawdzaj czy zadzia³a dereferencja */\r
-               if (!call_function_name (file, "++", op->children, 1, 1, space, info))\r
+               if (!_slang_assemble_assign (file, op, "++", reference, space, info))\r
                        return 0;\r
-               if (reference)\r
-               {\r
-                       /* TODO: stack is address */\r
-               }\r
-               else\r
-               {\r
-                       /* TODO: dereference */\r
-                       /* TODO: stack is operation type */\r
-               }\r
                break;\r
        case slang_oper_predecrement:\r
-               /* TODO: posprawdzaj czy zadzia³a dereferencja */\r
-               if (!call_function_name (file, "--", op->children, 1, 1, space, info))\r
+               if (!_slang_assemble_assign (file, op, "--", reference, space, info))\r
                        return 0;\r
-               if (reference)\r
-               {\r
-                       /* TODO: stack is address */\r
-               }\r
-               else\r
-               {\r
-                       /* TODO: dereference */\r
-                       /* TODO: stack is operation type */\r
-               }\r
                break;\r
        case slang_oper_plus:\r
                if (!call_function_name (file, "+", op->children, 1, 0, space, info))\r
@@ -1125,7 +988,7 @@ int _slang_assemble_operation (slang_assembly_file *file, slang_operation *op, i
                                slang_assembly_typeinfo_destruct (&ti_arr);\r
                                return 0;\r
                        }\r
-                       if (!sizeof_variable (&ti_arr.spec, NULL, space, &arr_size))\r
+                       if (!sizeof_variable (&ti_arr.spec, slang_qual_none, NULL, space, &arr_size))\r
                        {\r
                                slang_assembly_typeinfo_destruct (&ti_arr);\r
                                return 0;\r
@@ -1137,7 +1000,7 @@ int _slang_assemble_operation (slang_assembly_file *file, slang_operation *op, i
                                slang_assembly_typeinfo_destruct (&ti_elem);\r
                                return 0;\r
                        }\r
-                       if (!sizeof_variable (&ti_elem.spec, NULL, space, &elem_size))\r
+                       if (!sizeof_variable (&ti_elem.spec, slang_qual_none, NULL, space, &elem_size))\r
                        {\r
                                slang_assembly_typeinfo_destruct (&ti_arr);\r
                                slang_assembly_typeinfo_destruct (&ti_elem);\r
@@ -1336,50 +1199,10 @@ void xxx_first (slang_assembly_file *file)
        slang_assembly_file_push (file, slang_asm_jump);\r
 }\r
 \r
-void xxx_prolog (slang_assembly_file *file)\r
+void xxx_prolog (slang_assembly_file *file, unsigned int addr)\r
 {\r
        file->code[0].param[0] = file->count;\r
-\r
-       /* allocate local storage for inout/out params */\r
-       slang_assembly_file_push_literal (file, slang_asm_int_push, 777.777f);\r
-       slang_assembly_file_push_label (file, slang_asm_enter, 4);\r
-\r
-/*     slang_assembly_file_push_literal (file, slang_asm_int_push, 777.777f);\r
-       slang_assembly_file_push_literal (file, slang_asm_int_push, 777.777f);\r
-       slang_assembly_file_push_literal (file, slang_asm_int_push, 777.777f);\r
-       slang_assembly_file_push_literal (file, slang_asm_int_push, 777.777f);\r
-       slang_assembly_file_push_literal (file, slang_asm_int_push, 777.777f);\r
-       slang_assembly_file_push_literal (file, slang_asm_int_push, 777.777f);\r
-       slang_assembly_file_push_literal (file, slang_asm_int_push, 777.777f);\r
-       slang_assembly_file_push_literal (file, slang_asm_int_push, 777.777f);\r
-       slang_assembly_file_push_literal (file, slang_asm_int_push, 777.777f);\r
-       slang_assembly_file_push_literal (file, slang_asm_int_push, 777.777f);\r
-       slang_assembly_file_push_literal (file, slang_asm_int_push, 777.777f);\r
-       slang_assembly_file_push_literal (file, slang_asm_int_push, 777.777f);\r
-       slang_assembly_file_push_literal (file, slang_asm_int_push, 777.777f);\r
-       slang_assembly_file_push_literal (file, slang_asm_int_push, 777.777f);\r
-       slang_assembly_file_push_literal (file, slang_asm_int_push, 777.777f);*/\r
-       slang_assembly_file_push_literal (file, slang_asm_int_push, 777.777f);\r
-/*     slang_assembly_file_push_literal (file, slang_asm_float_push, 16.16f);\r
-       slang_assembly_file_push_literal (file, slang_asm_float_push, 15.15f);\r
-       slang_assembly_file_push_literal (file, slang_asm_float_push, 14.14f);\r
-       slang_assembly_file_push_literal (file, slang_asm_float_push, 13.13f);\r
-       slang_assembly_file_push_literal (file, slang_asm_float_push, 12.12f);\r
-       slang_assembly_file_push_literal (file, slang_asm_float_push, 11.11f);\r
-       slang_assembly_file_push_literal (file, slang_asm_float_push, 10.10f);\r
-       slang_assembly_file_push_literal (file, slang_asm_float_push, 9.9f);\r
-       slang_assembly_file_push_literal (file, slang_asm_float_push, 8.8f);\r
-       slang_assembly_file_push_literal (file, slang_asm_float_push, 7.7f);\r
-       slang_assembly_file_push_literal (file, slang_asm_float_push, 6.6f);\r
-       slang_assembly_file_push_literal (file, slang_asm_float_push, 5.5f);\r
-       slang_assembly_file_push_literal (file, slang_asm_float_push, 4.4f);\r
-       slang_assembly_file_push_literal (file, slang_asm_float_push, 3.3f);\r
-       slang_assembly_file_push_literal (file, slang_asm_float_push, 2.2f);*/\r
-       slang_assembly_file_push_literal (file, slang_asm_float_push, 1.1f);\r
-\r
-       slang_assembly_file_push_label (file, slang_asm_call, file->count + 3);\r
-       slang_assembly_file_push_label (file, slang_asm_local_free, 4);\r
-\r
+       slang_assembly_file_push_label (file, slang_asm_call, addr);\r
        slang_assembly_file_push (file, slang_asm_exit);\r
 }\r
 \r
index 21721c4273240be679e2b9b73a508d91b826b50f..69e81d6af6ecf83b164ef634092971748ec2cb68 100644 (file)
@@ -135,7 +135,7 @@ int _slang_assemble_operation (slang_assembly_file *, struct slang_operation_ *,
        slang_assembly_stack_info *);\r
 \r
 void xxx_first (slang_assembly_file *);\r
-void xxx_prolog (slang_assembly_file *);\r
+void xxx_prolog (slang_assembly_file *, unsigned int);\r
 \r
 #ifdef __cplusplus\r
 }\r
diff --git a/src/mesa/shader/slang/slang_assemble_assignment.c b/src/mesa/shader/slang/slang_assemble_assignment.c
new file mode 100644 (file)
index 0000000..fdd4355
--- /dev/null
@@ -0,0 +1,185 @@
+/*\r
+ * Mesa 3-D graphics library\r
+ * Version:  6.3\r
+ *\r
+ * Copyright (C) 2005  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_assemble_assignment.c\r
+ * slang assignment expressions assembler\r
+ * \author Michal Krol\r
+ */\r
+\r
+#include "imports.h"\r
+#include "slang_assemble_assignment.h"\r
+#include "slang_assemble_typeinfo.h"\r
+#include "slang_storage.h"\r
+#include "slang_utility.h"\r
+\r
+/*\r
+       _slang_assemble_assignment()\r
+\r
+       copies values on the stack (<component 0> to <component N-1>) to a memory\r
+       location pointed by <addr of variable>;\r
+\r
+       in:\r
+               +------------------+\r
+               | addr of variable |\r
+               +------------------+\r
+               | component N-1    |\r
+               | ...              |\r
+               | component 0      |\r
+               +------------------+\r
+\r
+       out:\r
+               +------------------+\r
+               | addr of variable |\r
+               +------------------+\r
+*/\r
+/* TODO: add support for swizzle mask */\r
+static int assign_aggregate (slang_assembly_file *file, const slang_storage_aggregate *agg,\r
+       unsigned int *index, unsigned int size, slang_assembly_local_info *info)\r
+{\r
+       unsigned int i;\r
+\r
+       for (i = 0; i < agg->count; i++)\r
+       {\r
+               const slang_storage_array *arr = agg->arrays + i;\r
+               unsigned int j;\r
+\r
+               for (j = 0; j < arr->length; j++)\r
+               {\r
+                       if (arr->type == slang_stor_aggregate)\r
+                       {\r
+                               if (!assign_aggregate (file, arr->aggregate, index, size, info))\r
+                                       return 0;\r
+                       }\r
+                       else\r
+                       {\r
+                               slang_assembly_type ty;\r
+\r
+                               switch (arr->type)\r
+                               {\r
+                               case slang_stor_bool:\r
+                                       ty = slang_asm_bool_copy;\r
+                                       break;\r
+                               case slang_stor_int:\r
+                                       ty = slang_asm_int_copy;\r
+                                       break;\r
+                               case slang_stor_float:\r
+                                       ty = slang_asm_float_copy;\r
+                                       break;\r
+                               }\r
+                               if (!slang_assembly_file_push_label2 (file, ty, size - *index, *index))\r
+                                       return 0;\r
+                               *index += 4;\r
+                       }\r
+               }\r
+       }\r
+       return 1;\r
+}\r
+\r
+int _slang_assemble_assignment (slang_assembly_file *file, slang_operation *op,\r
+       slang_assembly_name_space *space, slang_assembly_local_info *info)\r
+{\r
+       slang_assembly_typeinfo ti;\r
+       int result;\r
+       slang_storage_aggregate agg;\r
+       unsigned int index, size;\r
+\r
+       slang_assembly_typeinfo_construct (&ti);\r
+       if (!_slang_typeof_operation (op, space, &ti))\r
+       {\r
+               slang_assembly_typeinfo_destruct (&ti);\r
+               return 0;\r
+       }\r
+\r
+       slang_storage_aggregate_construct (&agg);\r
+       if (!_slang_aggregate_variable (&agg, &ti.spec, NULL, space->funcs, space->structs))\r
+       {\r
+               slang_storage_aggregate_destruct (&agg);\r
+               slang_assembly_typeinfo_destruct (&ti);\r
+               return 0;\r
+       }\r
+\r
+       index = 0;\r
+       size = _slang_sizeof_aggregate (&agg);\r
+       result = assign_aggregate (file, &agg, &index, size, info);\r
+\r
+       slang_storage_aggregate_destruct (&agg);\r
+       slang_assembly_typeinfo_destruct (&ti);\r
+       return result;\r
+}\r
+\r
+/*\r
+       _slang_assemble_assign()\r
+\r
+       performs unary (pre ++ and --) or binary (=, +=, -=, *=, /=) assignment on the operation's\r
+       children\r
+*/\r
+\r
+int dereference (slang_assembly_file *file, slang_operation *op,\r
+       slang_assembly_name_space *space, slang_assembly_local_info *info);\r
+\r
+int call_function_name (slang_assembly_file *file, const char *name, slang_operation *params,\r
+       unsigned int param_count, int assignment, slang_assembly_name_space *space,\r
+       slang_assembly_local_info *info);\r
+\r
+int _slang_assemble_assign (slang_assembly_file *file, slang_operation *op, const char *oper,\r
+       int ref, slang_assembly_name_space *space, slang_assembly_local_info *info)\r
+{\r
+       slang_assembly_stack_info stk;\r
+       slang_assembly_flow_control flow;\r
+\r
+       if (!ref)\r
+       {\r
+               if (!slang_assembly_file_push_label2 (file, slang_asm_local_addr, info->addr_tmp, 4))\r
+                       return 0;\r
+       }\r
+\r
+       if (slang_string_compare ("=", oper) == 0)\r
+       {\r
+               if (!_slang_assemble_operation (file, op->children, 1, &flow, space, info, &stk))\r
+                       return 0;\r
+               if (!_slang_assemble_operation (file, op->children + 1, 0, &flow, space, info, &stk))\r
+                       return 0;\r
+               if (!_slang_assemble_assignment (file, op->children, space, info))\r
+                       return 0;\r
+       }\r
+       else\r
+       {\r
+               if (!call_function_name (file, oper, op->children, op->num_children, 1, space, info))\r
+                       return 0;\r
+       }\r
+\r
+       if (!ref)\r
+       {\r
+               if (!slang_assembly_file_push (file, slang_asm_addr_copy))\r
+                       return 0;\r
+               if (!slang_assembly_file_push_label (file, slang_asm_local_free, 4))\r
+                       return 0;\r
+               if (!dereference (file, op->children, space, info))\r
+                       return 0;\r
+       }\r
+\r
+       return 1;\r
+}\r
+\r
diff --git a/src/mesa/shader/slang/slang_assemble_assignment.h b/src/mesa/shader/slang/slang_assemble_assignment.h
new file mode 100644 (file)
index 0000000..06972ad
--- /dev/null
@@ -0,0 +1,45 @@
+/*\r
+ * Mesa 3-D graphics library\r
+ * Version:  6.3\r
+ *\r
+ * Copyright (C) 2005  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_ASSEMBLE_ASSIGNMENT_H\r
+#define SLANG_ASSEMBLE_ASSIGNMENT_H\r
+\r
+#include "slang_assemble.h"\r
+\r
+#if defined __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+int _slang_assemble_assignment (slang_assembly_file *, slang_operation *,\r
+       slang_assembly_name_space *, slang_assembly_local_info *);\r
+\r
+int _slang_assemble_assign (slang_assembly_file *, slang_operation *, const char *, int ref,\r
+       slang_assembly_name_space *, slang_assembly_local_info *);\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+#endif\r
+\r
index 6835adea6d8253a73b1e59dbb2cd32f7c32a32a5..ed82712b20f3aea95c14128cd8eb2209445b89a6 100644 (file)
@@ -2093,7 +2093,6 @@ static int parse_function (slang_parse_ctx *C, int definition, slang_struct_scop
        if (definition)
        {
 static int x = 0;
-const int y = 61;      /* core 437 */
 static
                slang_assembly_file file;
                slang_assembly_name_space space;
@@ -2104,16 +2103,16 @@ if (x == 1)
                space.structs = structs;
                space.vars = scope;
 if (x == 1)
-       xxx_first (&file);
-if (x == y)
-       xxx_prolog (&file);
+xxx_first (&file);\r
+               (**parsed_func_ret).address = file.count;
                if (!_slang_assemble_function (&file, *parsed_func_ret, &space))
                {
                        slang_assembly_file_destruct (&file);
                        return 0;
                }
-if (x == y)
-{
+if (slang_string_compare ("main", (**parsed_func_ret).header.name) == 0)
+{\r
+xxx_prolog (&file, (**parsed_func_ret).address);
 _slang_execute (&file);
 slang_assembly_file_destruct (&file);
 exit (0);
@@ -2251,10 +2250,13 @@ static int compile_with_grammar (grammar id, const char *source, slang_translati
 static const char *slang_shader_syn =
 #include "library/slang_shader_syn.h"
 ;
-
+/*
 static const byte slang_core_gc_bin[] = {
 #include "library/slang_core_gc_bin.h"
-};
+};*/
+static const byte slang_core_gc[] = {\r
+#include "library/slang_core_gc.h"\r
+};\r
 
 static const byte slang_common_builtin_gc_bin[] = {
 #include "library/slang_common_builtin_gc_bin.h"
@@ -2267,7 +2269,7 @@ static const byte slang_fragment_builtin_gc_bin[] = {
 static const byte slang_vertex_builtin_gc_bin[] = {
 #include "library/slang_vertex_builtin_gc_bin.h"
 };
-
+\r
 int _slang_compile (const char *source, slang_translation_unit *unit, slang_unit_type type,
        slang_info_log *log)
 {
@@ -2298,8 +2300,10 @@ int _slang_compile (const char *source, slang_translation_unit *unit, slang_unit
        /* if parsing user-specified shader, load built-in library */
        if (type == slang_unit_fragment_shader || type == slang_unit_vertex_shader)
        {
-               if (!compile_binary (slang_core_gc_bin, builtin_units,
-                       slang_unit_fragment_builtin, log, NULL))
+               /*if (!compile_binary (slang_core_gc_bin, builtin_units,
+                       slang_unit_fragment_builtin, log, NULL))*/\r
+               if (!compile_with_grammar (id, slang_core_gc, builtin_units, slang_unit_fragment_builtin,\r
+                       log, NULL))
                {
                        grammar_destroy (id);
                        return 0;
@@ -2314,7 +2318,7 @@ int _slang_compile (const char *source, slang_translation_unit *unit, slang_unit
                if (type == slang_unit_fragment_shader)
                {
                        if (!compile_binary (slang_fragment_builtin_gc_bin, builtin_units + 2,
-                               slang_unit_fragment_builtin, log, NULL))
+                               slang_unit_fragment_builtin, log, NULL))\r
                        {
                                slang_translation_unit_destruct (builtin_units);
                                slang_translation_unit_destruct (builtin_units + 1);
@@ -2325,7 +2329,7 @@ int _slang_compile (const char *source, slang_translation_unit *unit, slang_unit
                else if (type == slang_unit_vertex_shader)
                {
                        if (!compile_binary (slang_vertex_builtin_gc_bin, builtin_units + 2,
-                               slang_unit_vertex_builtin, log, NULL))
+                               slang_unit_vertex_builtin, log, NULL))\r
                        {
                                slang_translation_unit_destruct (builtin_units);
                                slang_translation_unit_destruct (builtin_units + 1);
index 84af8d575c8b2ea61ac81ff6d9bf6ec7e81ef8bf..f06147556e3fff48d3beb82283e575ee507e4639 100644 (file)
@@ -95,19 +95,19 @@ static int aggregate_vector (slang_storage_aggregate *agg, slang_storage_type ba
 }\r
 \r
 static int aggregate_matrix (slang_storage_aggregate *agg, slang_storage_type basic_type,\r
-       unsigned int order)\r
+       unsigned int dimension)\r
 {\r
        slang_storage_array *arr = slang_storage_aggregate_push_new (agg);\r
        if (arr == NULL)\r
                return 0;\r
        arr->type = slang_stor_aggregate;\r
-       arr->length = order;\r
+       arr->length = dimension;\r
        arr->aggregate = (slang_storage_aggregate *) slang_alloc_malloc (sizeof (\r
                slang_storage_aggregate));\r
        if (arr->aggregate == NULL)\r
                return 0;\r
        slang_storage_aggregate_construct (arr->aggregate);\r
-       if (!aggregate_vector (arr->aggregate, basic_type, order))\r
+       if (!aggregate_vector (arr->aggregate, basic_type, dimension))\r
                return 0;\r
        return 1;\r
 }\r