*/\r
\r
#include "imports.h"\r
-#include "slang_utility.h"\r
-#include "slang_assemble_constructor.h"\r
-#include "slang_assemble_typeinfo.h"\r
+#include "slang_assemble.h"\r
#include "slang_storage.h"\r
\r
/* _slang_is_swizzle() */\r
\r
-int _slang_is_swizzle (const char *field, unsigned int rows, slang_swizzle *swz)\r
+GLboolean _slang_is_swizzle (const char *field, GLuint rows, slang_swizzle *swz)\r
{\r
- unsigned int i;\r
- int xyzw = 0, rgba = 0, stpq = 0;\r
+ GLuint i;\r
+ GLboolean xyzw = GL_FALSE, rgba = GL_FALSE, stpq = GL_FALSE;\r
\r
/* the swizzle can be at most 4-component long */\r
swz->num_components = slang_string_length (field);\r
if (swz->num_components > 4)\r
- return 0;\r
+ return GL_FALSE;\r
\r
for (i = 0; i < swz->num_components; i++)\r
{\r
case 'y':\r
case 'z':\r
case 'w':\r
- xyzw = 1;\r
+ xyzw = GL_TRUE;\r
break;\r
case 'r':\r
case 'g':\r
case 'b':\r
case 'a':\r
- rgba = 1;\r
+ rgba = GL_TRUE;\r
break;\r
case 's':\r
case 't':\r
case 'p':\r
case 'q':\r
- stpq = 1;\r
+ stpq = GL_TRUE;\r
break;\r
default:\r
- return 0;\r
+ return GL_FALSE;\r
}\r
\r
/* collect swizzle component */\r
case 'y':\r
case 'g':\r
case 't':\r
- if (rows < 2)\r
- return 0;\r
swz->swizzle[i] = 1;\r
break;\r
case 'z':\r
case 'b':\r
case 'p':\r
- if (rows < 3)\r
- return 0;\r
swz->swizzle[i] = 2;\r
break;\r
case 'w':\r
case 'a':\r
case 'q':\r
- if (rows < 4)\r
- return 0;\r
swz->swizzle[i] = 3;\r
break;\r
}\r
+\r
+ /* check if the component is valid for given vector's row count */\r
+ if (rows <= swz->swizzle[i])\r
+ return GL_FALSE;\r
}\r
\r
/* only one swizzle group can be used */\r
if ((xyzw && rgba) || (xyzw && stpq) || (rgba && stpq))\r
- return 0;\r
+ return GL_FALSE;\r
\r
- return 1;\r
+ return GL_TRUE;\r
}\r
\r
/* _slang_is_swizzle_mask() */\r
\r
-int _slang_is_swizzle_mask (const slang_swizzle *swz, unsigned int rows)\r
+GLboolean _slang_is_swizzle_mask (const slang_swizzle *swz, GLuint rows)\r
{\r
- unsigned int c, i;\r
+ GLuint i, c = 0;\r
\r
+ /* the swizzle may not be longer than the vector dim */\r
if (swz->num_components > rows)\r
- return 0;\r
- c = swz->swizzle[0];\r
- for (i = 1; i < swz->num_components; i++)\r
+ return GL_FALSE;\r
+\r
+ /* the swizzle components cannot be duplicated */\r
+ for (i = 0; i < swz->num_components; i++)\r
{\r
- if (swz->swizzle[i] <= c)\r
- return 0;\r
- c = swz->swizzle[i];\r
+ if ((c & (1 << swz->swizzle[i])) != 0)\r
+ return GL_FALSE;\r
+ c |= 1 << swz->swizzle[i];\r
}\r
- return 1;\r
+\r
+ return GL_TRUE;\r
}\r
\r
/* _slang_multiply_swizzles() */\r
\r
-void _slang_multiply_swizzles (slang_swizzle *dst, const slang_swizzle *left,\r
+GLvoid _slang_multiply_swizzles (slang_swizzle *dst, const slang_swizzle *left,\r
const slang_swizzle *right)\r
{\r
- unsigned int i;\r
+ GLuint i;\r
+\r
dst->num_components = right->num_components;\r
for (i = 0; i < right->num_components; i++)\r
dst->swizzle[i] = left->swizzle[right->swizzle[i]];\r
\r
/* _slang_assemble_constructor() */\r
\r
-static int constructor_aggregate (slang_assembly_file *file, const slang_storage_aggregate *flat,\r
- unsigned int *index, slang_operation *op, unsigned int size, slang_assembly_flow_control *flow,\r
- slang_assembly_name_space *space, slang_assembly_local_info *info)\r
+static GLboolean constructor_aggregate (slang_assemble_ctx *A, const slang_storage_aggregate *flat,\r
+ GLuint *index, slang_operation *op, GLuint size)\r
{\r
slang_assembly_typeinfo ti;\r
- int result;\r
+ GLboolean result = GL_FALSE;\r
slang_storage_aggregate agg, flat_agg;\r
- slang_assembly_stack_info stk;\r
- unsigned int i;\r
+ GLuint i;\r
\r
- slang_assembly_typeinfo_construct (&ti);\r
- if (!(result = _slang_typeof_operation (op, space, &ti)))\r
+ if (!slang_assembly_typeinfo_construct (&ti))\r
+ return GL_FALSE;\r
+ if (!_slang_typeof_operation (A, op, &ti))\r
goto end1;\r
\r
- slang_storage_aggregate_construct (&agg);\r
- if (!(result = _slang_aggregate_variable (&agg, &ti.spec, NULL, space->funcs, space->structs,\r
- space->vars)))\r
+ if (!slang_storage_aggregate_construct (&agg))\r
+ goto end1;\r
+ if (!_slang_aggregate_variable (&agg, &ti.spec, 0, A->space.funcs, A->space.structs,\r
+ A->space.vars, A->mach, A->file, A->atoms))\r
goto end2;\r
\r
- slang_storage_aggregate_construct (&flat_agg);\r
- if (!(result = _slang_flatten_aggregate (&flat_agg, &agg)))\r
+ if (!slang_storage_aggregate_construct (&flat_agg))\r
+ goto end2;\r
+ if (!_slang_flatten_aggregate (&flat_agg, &agg))\r
goto end;\r
\r
- if (!(result = _slang_assemble_operation (file, op, 0, flow, space, info, &stk)))\r
+ if (!_slang_assemble_operation (A, op, slang_ref_forbid))\r
goto end;\r
\r
for (i = 0; i < flat_agg.count; i++)\r
{\r
- const slang_storage_array *arr1 = flat_agg.arrays + i;\r
- const slang_storage_array *arr2 = flat->arrays + *index;\r
+ const slang_storage_array *arr1 = &flat_agg.arrays[i];\r
+ const slang_storage_array *arr2 = &flat->arrays[*index];\r
\r
if (arr1->type != arr2->type)\r
{\r
/* TODO: watch the index, if it reaches the size, pop off the stack subsequent values */\r
}\r
\r
- result = 1;\r
+ result = GL_TRUE;\r
end:\r
slang_storage_aggregate_destruct (&flat_agg);\r
end2:\r
slang_assembly_typeinfo_destruct (&ti);\r
return result;\r
}\r
-/* XXX: general swizzle! */\r
-int _slang_assemble_constructor (slang_assembly_file *file, slang_operation *op,\r
- slang_assembly_flow_control *flow, slang_assembly_name_space *space,\r
- slang_assembly_local_info *info)\r
+\r
+GLboolean _slang_assemble_constructor (slang_assemble_ctx *A, slang_operation *op)\r
{\r
slang_assembly_typeinfo ti;\r
- int result;\r
+ GLboolean result = GL_FALSE;\r
slang_storage_aggregate agg, flat;\r
- unsigned int size, index, i;\r
+ GLuint size, index, i;\r
\r
- slang_assembly_typeinfo_construct (&ti);\r
- if (!(result = _slang_typeof_operation (op, space, &ti)))\r
+ /* get typeinfo of the constructor (the result of constructor expression) */\r
+ if (!slang_assembly_typeinfo_construct (&ti))\r
+ return GL_FALSE;\r
+ if (!_slang_typeof_operation (A, op, &ti))\r
goto end1;\r
\r
- slang_storage_aggregate_construct (&agg);\r
- if (!(result = _slang_aggregate_variable (&agg, &ti.spec, NULL, space->funcs, space->structs,\r
- space->vars)))\r
+ /* create an aggregate of the constructor */\r
+ if (!slang_storage_aggregate_construct (&agg))\r
+ goto end1;\r
+ if (!_slang_aggregate_variable (&agg, &ti.spec, 0, A->space.funcs, A->space.structs,\r
+ A->space.vars, A->mach, A->file, A->atoms))\r
goto end2;\r
\r
+ /* calculate size of the constructor */\r
size = _slang_sizeof_aggregate (&agg);\r
\r
- slang_storage_aggregate_construct (&flat);\r
- if (!(result = _slang_flatten_aggregate (&flat, &agg)))\r
+ /* flatten the constructor */\r
+ if (!slang_storage_aggregate_construct (&flat))\r
+ goto end2;\r
+ if (!_slang_flatten_aggregate (&flat, &agg))\r
goto end;\r
\r
+ /* XXX: The children operations are traversed in a reversed order, so it poses a\r
+ * problem when there is more data than the constructor needs. We must fix it! */\r
+\r
+ /* traverse the children that form the constructor expression */\r
index = 0;\r
- for (i = 0; i < op->num_children; i++)\r
+ for (i = op->num_children; i > 0; i--)\r
{\r
- if (!(result = constructor_aggregate (file, &flat, &index, op->children + i, size, flow,\r
- space, info)))\r
+ if (!constructor_aggregate (A, &flat, &index, &op->children[i - 1], size))\r
goto end;\r
/* TODO: watch the index, if it reaches the size, raise an error */\r
}\r
\r
- result = 1;\r
+ result = GL_TRUE;\r
end:\r
slang_storage_aggregate_destruct (&flat);\r
end2:\r
}\r
\r
/* _slang_assemble_constructor_from_swizzle() */\r
-/* XXX: wrong */\r
-int _slang_assemble_constructor_from_swizzle (slang_assembly_file *file, const slang_swizzle *swz,\r
- slang_type_specifier *spec, slang_type_specifier *master_spec, slang_assembly_local_info *info)\r
+\r
+GLboolean _slang_assemble_constructor_from_swizzle (slang_assemble_ctx *A, const slang_swizzle *swz,\r
+ slang_type_specifier *spec, slang_type_specifier *master_spec)\r
{\r
- unsigned int master_rows, i;\r
- switch (master_spec->type)\r
- {\r
- case slang_spec_bool:\r
- case slang_spec_int:\r
- case slang_spec_float:\r
- master_rows = 1;\r
- break;\r
- case slang_spec_bvec2:\r
- case slang_spec_ivec2:\r
- case slang_spec_vec2:\r
- master_rows = 2;\r
- break;\r
- case slang_spec_bvec3:\r
- case slang_spec_ivec3:\r
- case slang_spec_vec3:\r
- master_rows = 3;\r
- break;\r
- case slang_spec_bvec4:\r
- case slang_spec_ivec4:\r
- case slang_spec_vec4:\r
- master_rows = 4;\r
- break;\r
- default:\r
- break;\r
- }\r
+ GLuint master_rows, i;\r
+\r
+ master_rows = _slang_type_dim (master_spec->type);\r
for (i = 0; i < master_rows; i++)\r
{\r
- switch (master_spec->type)\r
+ switch (_slang_type_base (master_spec->type))\r
{\r
case slang_spec_bool:\r
- case slang_spec_bvec2:\r
- case slang_spec_bvec3:\r
- case slang_spec_bvec4:\r
- if (!slang_assembly_file_push_label2 (file, slang_asm_bool_copy, (master_rows - i) * 4,\r
- i * 4))\r
- return 0;\r
+ if (!slang_assembly_file_push_label2 (A->file, slang_asm_bool_copy,\r
+ (master_rows - i) * 4, i * 4))\r
+ return GL_FALSE;\r
break;\r
case slang_spec_int:\r
- case slang_spec_ivec2:\r
- case slang_spec_ivec3:\r
- case slang_spec_ivec4:\r
- if (!slang_assembly_file_push_label2 (file, slang_asm_int_copy, (master_rows - i) * 4,\r
- i * 4))\r
- return 0;\r
+ if (!slang_assembly_file_push_label2 (A->file, slang_asm_int_copy,\r
+ (master_rows - i) * 4, i * 4))\r
+ return GL_FALSE;\r
break;\r
case slang_spec_float:\r
- case slang_spec_vec2:\r
- case slang_spec_vec3:\r
- case slang_spec_vec4:\r
- if (!slang_assembly_file_push_label2 (file, slang_asm_float_copy,\r
- (master_rows - i) * 4, i * 4))\r
- return 0;\r
+ if (!slang_assembly_file_push_label2 (A->file, slang_asm_float_copy,\r
+ (master_rows - i) * 4, i * 4))\r
+ return GL_FALSE;\r
break;\r
default:\r
- break;\r
+ break;\r
}\r
}\r
- if (!slang_assembly_file_push_label (file, slang_asm_local_free, 4))\r
- return 0;\r
+ if (!slang_assembly_file_push_label (A->file, slang_asm_local_free, 4))\r
+ return GL_FALSE;\r
for (i = swz->num_components; i > 0; i--)\r
{\r
- unsigned int n = i - 1;\r
- if (!slang_assembly_file_push_label2 (file, slang_asm_local_addr, info->swizzle_tmp, 16))\r
- return 0;\r
- if (!slang_assembly_file_push_label (file, slang_asm_addr_push, swz->swizzle[n] * 4))\r
- return 0;\r
- if (!slang_assembly_file_push (file, slang_asm_addr_add))\r
- return 0;\r
- switch (master_spec->type)\r
+ GLuint n = i - 1;\r
+\r
+ if (!slang_assembly_file_push_label2 (A->file, slang_asm_local_addr, A->local.swizzle_tmp, 16))\r
+ return GL_FALSE;\r
+ if (!slang_assembly_file_push_label (A->file, slang_asm_addr_push, swz->swizzle[n] * 4))\r
+ return GL_FALSE;\r
+ if (!slang_assembly_file_push (A->file, slang_asm_addr_add))\r
+ return GL_FALSE;\r
+ switch (_slang_type_base (master_spec->type))\r
{\r
case slang_spec_bool:\r
- case slang_spec_bvec2:\r
- case slang_spec_bvec3:\r
- case slang_spec_bvec4:\r
- if (!slang_assembly_file_push (file, slang_asm_bool_deref))\r
- return 0;\r
+ if (!slang_assembly_file_push (A->file, slang_asm_bool_deref))\r
+ return GL_FALSE;\r
break;\r
case slang_spec_int:\r
- case slang_spec_ivec2:\r
- case slang_spec_ivec3:\r
- case slang_spec_ivec4:\r
- if (!slang_assembly_file_push (file, slang_asm_int_deref))\r
- return 0;\r
+ if (!slang_assembly_file_push (A->file, slang_asm_int_deref))\r
+ return GL_FALSE;\r
break;\r
case slang_spec_float:\r
- case slang_spec_vec2:\r
- case slang_spec_vec3:\r
- case slang_spec_vec4:\r
- if (!slang_assembly_file_push (file, slang_asm_float_deref))\r
- return 0;\r
+ if (!slang_assembly_file_push (A->file, slang_asm_float_deref))\r
+ return GL_FALSE;\r
break;\r
default:\r
- break;\r
+ break;\r
}\r
}\r
- return 1;\r
+\r
+ return GL_TRUE;\r
}\r
\r