*/\r
\r
#include "imports.h"\r
-#include "slang_utility.h"\r
#include "slang_assemble.h"\r
-/*#include "slang_compile.h"*/\r
+#include "slang_compile.h"\r
#include "slang_storage.h"\r
-/*#include "slang_assemble_constructor.h"*/\r
-#include "slang_assemble_typeinfo.h"\r
-#include "slang_assemble_conditional.h"\r
-#include "slang_assemble_assignment.h"\r
-#include "slang_execute.h"\r
\r
/* slang_assembly */\r
\r
-static int slang_assembly_construct (slang_assembly *assem)\r
+static GLboolean slang_assembly_construct (slang_assembly *assem)\r
{\r
assem->type = slang_asm_none;\r
- return 1;\r
+ return GL_TRUE;\r
}\r
\r
-static void slang_assembly_destruct (slang_assembly *assem)\r
+static GLvoid slang_assembly_destruct (slang_assembly *assem)\r
{\r
}\r
\r
/* slang_assembly_file */\r
\r
-int slang_assembly_file_construct (slang_assembly_file *file)\r
+GLboolean slang_assembly_file_construct (slang_assembly_file *file)\r
{\r
file->code = NULL;\r
file->count = 0;\r
file->capacity = 0;\r
- return 1;\r
+ return GL_TRUE;\r
}\r
\r
-void slang_assembly_file_destruct (slang_assembly_file *file)\r
+GLvoid slang_assembly_file_destruct (slang_assembly_file *file)\r
{\r
- unsigned int i;\r
+ GLuint i;\r
\r
for (i = 0; i < file->count; i++)\r
slang_assembly_destruct (&file->code[i]);\r
slang_alloc_free (file->code);\r
}\r
\r
-static int push_new (slang_assembly_file *file)\r
+static GLboolean push_new (slang_assembly_file *file)\r
{\r
if (file->count == file->capacity)\r
{\r
- unsigned int n;\r
+ GLuint n;\r
\r
if (file->capacity == 0)\r
n = 256;\r
file->code = (slang_assembly *) slang_alloc_realloc (file->code,\r
file->capacity * sizeof (slang_assembly), n * sizeof (slang_assembly));\r
if (file->code == NULL)\r
- return 0;\r
+ return GL_FALSE;\r
file->capacity = n;\r
}\r
if (!slang_assembly_construct (&file->code[file->count]))\r
- return 0;\r
+ return GL_FALSE;\r
file->count++;\r
- return 1;\r
+ return GL_TRUE;\r
}\r
\r
-static int push_gen (slang_assembly_file *file, slang_assembly_type type, GLfloat literal,\r
+static GLboolean push_gen (slang_assembly_file *file, slang_assembly_type type, GLfloat literal,\r
GLuint label, GLuint size)\r
{\r
slang_assembly *assem;\r
\r
if (!push_new (file))\r
- return 0;\r
+ return GL_FALSE;\r
assem = &file->code[file->count - 1];\r
assem->type = type;\r
assem->literal = literal;\r
assem->param[0] = label;\r
assem->param[1] = size;\r
- return 1;\r
+ return GL_TRUE;\r
}\r
\r
-int slang_assembly_file_push (slang_assembly_file *file, slang_assembly_type type)\r
+GLboolean slang_assembly_file_push (slang_assembly_file *file, slang_assembly_type type)\r
{\r
return push_gen (file, type, (GLfloat) 0, 0, 0);\r
}\r
\r
-int slang_assembly_file_push_label (slang_assembly_file *file, slang_assembly_type type,\r
+GLboolean slang_assembly_file_push_label (slang_assembly_file *file, slang_assembly_type type,\r
GLuint label)\r
{\r
return push_gen (file, type, (GLfloat) 0, label, 0);\r
}\r
\r
-int slang_assembly_file_push_label2 (slang_assembly_file *file, slang_assembly_type type,\r
+GLboolean slang_assembly_file_push_label2 (slang_assembly_file *file, slang_assembly_type type,\r
GLuint label1, GLuint label2)\r
{\r
return push_gen (file, type, (GLfloat) 0, label1, label2);\r
}\r
\r
-int slang_assembly_file_push_literal (slang_assembly_file *file, slang_assembly_type type,\r
+GLboolean slang_assembly_file_push_literal (slang_assembly_file *file, slang_assembly_type type,\r
GLfloat literal)\r
{\r
return push_gen (file, type, literal, 0, 0);\r
\r
/* slang_assembly_file_restore_point */\r
\r
-int slang_assembly_file_restore_point_save (slang_assembly_file *file,\r
+GLboolean slang_assembly_file_restore_point_save (slang_assembly_file *file,\r
slang_assembly_file_restore_point *point)\r
{\r
point->count = file->count;\r
- return 1;\r
+ return GL_TRUE;\r
}\r
\r
-int slang_assembly_file_restore_point_load (slang_assembly_file *file,\r
+GLboolean slang_assembly_file_restore_point_load (slang_assembly_file *file,\r
slang_assembly_file_restore_point *point)\r
{\r
- unsigned int i;\r
+ GLuint i;\r
\r
for (i = point->count; i < file->count; i++)\r
slang_assembly_destruct (&file->code[i]);\r
file->count = point->count;\r
- return 1;\r
+ return GL_TRUE;\r
}\r
\r
/* utility functions */\r
\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
- slang_machine *mach, slang_assembly_file *pfile, slang_atom_pool *atoms)\r
+static GLboolean sizeof_variable (slang_assemble_ctx *A, slang_type_specifier *spec,\r
+ slang_type_qualifier qual, GLuint array_len, GLuint *size)\r
{\r
slang_storage_aggregate agg;\r
\r
/* calculate the size of the variable's aggregate */\r
if (!slang_storage_aggregate_construct (&agg))\r
- return 0;\r
- if (!_slang_aggregate_variable (&agg, spec, array_size, space->funcs, space->structs,\r
- space->vars, mach, pfile, atoms))\r
+ return GL_FALSE;\r
+ if (!_slang_aggregate_variable (&agg, spec, array_len, A->space.funcs, A->space.structs,\r
+ A->space.vars, A->mach, A->file, A->atoms))\r
{\r
slang_storage_aggregate_destruct (&agg);\r
- return 0;\r
+ return GL_FALSE;\r
}\r
*size += _slang_sizeof_aggregate (&agg);\r
slang_storage_aggregate_destruct (&agg);\r
/* for reference variables consider the additional address overhead */\r
if (qual == slang_qual_out || qual == slang_qual_inout)\r
*size += 4;\r
- return 1;\r
+\r
+ return GL_TRUE;\r
}\r
\r
-static int sizeof_variable2 (slang_variable *var, slang_assembly_name_space *space,\r
- unsigned int *size, slang_machine *mach, slang_assembly_file *pfile, slang_atom_pool *atoms)\r
+static GLboolean sizeof_variable2 (slang_assemble_ctx *A, slang_variable *var, GLuint *size)\r
{\r
var->address = *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, mach, pfile, atoms);\r
+ return sizeof_variable (A, &var->type.specifier, var->type.qualifier, var->array_len, size);\r
}\r
\r
-static int sizeof_variables (slang_variable_scope *vars, unsigned int start, unsigned int stop,\r
- slang_assembly_name_space *space, unsigned int *size, slang_machine *mach,\r
- slang_assembly_file *pfile, slang_atom_pool *atoms)\r
+static GLboolean sizeof_variables (slang_assemble_ctx *A, slang_variable_scope *vars, GLuint start,\r
+ GLuint stop, GLuint *size)\r
{\r
- unsigned int i;\r
+ GLuint i;\r
\r
for (i = start; i < stop; i++)\r
- if (!sizeof_variable2 (&vars->variables[i], space, size, mach, pfile, atoms))\r
- return 0;\r
- return 1;\r
+ if (!sizeof_variable2 (A, &vars->variables[i], size))\r
+ return GL_FALSE;\r
+ return GL_TRUE;\r
}\r
\r
-static int collect_locals (slang_operation *op, slang_assembly_name_space *space,\r
- unsigned int *size, slang_machine *mach, slang_assembly_file *pfile, slang_atom_pool *atoms)\r
+static GLboolean collect_locals (slang_assemble_ctx *A, slang_operation *op, GLuint *size)\r
{\r
- unsigned int i;\r
+ GLuint i;\r
\r
- if (!sizeof_variables (op->locals, 0, op->locals->num_variables, space, size, mach, pfile,\r
- atoms))\r
- return 0;\r
+ if (!sizeof_variables (A, op->locals, 0, op->locals->num_variables, size))\r
+ return GL_FALSE;\r
for (i = 0; i < op->num_children; i++)\r
- if (!collect_locals (&op->children[i], space, size, mach, pfile, atoms))\r
- return 0;\r
- return 1;\r
+ if (!collect_locals (A, &op->children[i], size))\r
+ return GL_FALSE;\r
+ return GL_TRUE;\r
}\r
\r
/* _slang_locate_function() */\r
\r
slang_function *_slang_locate_function (slang_function_scope *funcs, slang_atom a_name,\r
- slang_operation *params, unsigned int num_params, slang_assembly_name_space *space,\r
+ slang_operation *params, GLuint num_params, slang_assembly_name_space *space,\r
slang_atom_pool *atoms)\r
{\r
- unsigned int i;\r
+ GLuint i;\r
\r
for (i = 0; i < funcs->num_functions; i++)\r
{\r
- unsigned int j;\r
+ GLuint j;\r
slang_function *f = &funcs->functions[i];\r
\r
if (a_name != f->header.a_name)\r
slang_assembly_typeinfo ti;\r
\r
if (!slang_assembly_typeinfo_construct (&ti))\r
- return 0;\r
- if (!_slang_typeof_operation (¶ms[j], space, &ti, atoms))\r
+ return NULL;\r
+ if (!_slang_typeof_operation_ (¶ms[j], space, &ti, atoms))\r
{\r
slang_assembly_typeinfo_destruct (&ti);\r
- return 0;\r
+ return NULL;\r
}\r
if (!slang_type_specifier_equal (&ti.spec, &f->parameters->variables[j].type.specifier))\r
{\r
\r
/* _slang_assemble_function() */\r
\r
-int _slang_assemble_function (slang_assemble_ctx *A, slang_function *fun)\r
+GLboolean _slang_assemble_function (slang_assemble_ctx *A, slang_function *fun)\r
{\r
- unsigned int param_size, local_size;\r
- unsigned int skip, cleanup;\r
+ GLuint param_size, local_size;\r
+ GLuint skip, cleanup;\r
\r
fun->address = A->file->count;\r
\r
fun->fixups.table = (GLuint *) slang_alloc_realloc (fun->fixups.table,\r
fun->fixups.count * sizeof (GLuint), (fun->fixups.count + 1) * sizeof (GLuint));\r
if (fun->fixups.table == NULL)\r
- return 0;\r
+ return GL_FALSE;\r
fun->fixups.table[fun->fixups.count] = fun->address;\r
fun->fixups.count++;\r
if (!PUSH (A->file, slang_asm_jump))\r
- return 0;\r
- return 1;\r
+ return GL_FALSE;\r
+ return GL_TRUE;\r
}\r
else\r
{\r
/* calculate return value size */\r
param_size = 0;\r
if (fun->header.type.specifier.type != slang_spec_void)\r
- if (!sizeof_variable (&fun->header.type.specifier, slang_qual_none, NULL, &A->space,\r
- ¶m_size, A->mach, A->file, A->atoms))\r
- return 0;\r
+ if (!sizeof_variable (A, &fun->header.type.specifier, slang_qual_none, 0, ¶m_size))\r
+ return GL_FALSE;\r
A->local.ret_size = param_size;\r
\r
/* calculate formal parameter list size */\r
- if (!sizeof_variables (fun->parameters, 0, fun->param_count, &A->space, ¶m_size, A->mach, A->file,\r
- A->atoms))\r
- return 0;\r
+ if (!sizeof_variables (A, fun->parameters, 0, fun->param_count, ¶m_size))\r
+ return GL_FALSE;\r
\r
/* calculate local variables size - take into account the four-byte return address and\r
* temporaries for various tasks (4 for addr and 16 for swizzle temporaries).\r
A->local.addr_tmp = param_size + 4;\r
A->local.swizzle_tmp = param_size + 4 + 4;\r
local_size = param_size + 4 + 4 + 16;\r
- if (!sizeof_variables (fun->parameters, fun->param_count, fun->parameters->num_variables, &A->space,\r
- &local_size, A->mach, A->file, A->atoms))\r
- return 0;\r
- if (!collect_locals (fun->body, &A->space, &local_size, A->mach, A->file, A->atoms))\r
- return 0;\r
+ if (!sizeof_variables (A, fun->parameters, fun->param_count, fun->parameters->num_variables,\r
+ &local_size))\r
+ return GL_FALSE;\r
+ if (!collect_locals (A, fun->body, &local_size))\r
+ return GL_FALSE;\r
\r
/* allocate local variable storage */\r
if (!PLAB (A->file, slang_asm_local_alloc, local_size - param_size - 4))\r
- return 0;\r
+ return GL_FALSE;\r
\r
/* mark a new frame for function variable storage */\r
if (!PLAB (A->file, slang_asm_enter, local_size))\r
- return 0;\r
+ return GL_FALSE;\r
\r
/* jump directly to the actual code */\r
skip = A->file->count;\r
if (!push_new (A->file))\r
- return 0;\r
+ return GL_FALSE;\r
A->file->code[skip].type = slang_asm_jump;\r
\r
/* all "return" statements will be directed here */\r
A->flow.function_end = A->file->count;\r
cleanup = A->file->count;\r
if (!push_new (A->file))\r
- return 0;\r
+ return GL_FALSE;\r
A->file->code[cleanup].type = slang_asm_jump;\r
\r
/* execute the function body */\r
A->file->code[skip].param[0] = A->file->count;\r
- if (!_slang_assemble_operation_ (A, fun->body, slang_ref_freelance))\r
- return 0;\r
+ if (!_slang_assemble_operation (A, fun->body, /*slang_ref_freelance*/slang_ref_forbid))\r
+ return GL_FALSE;\r
\r
/* this is the end of the function - restore the old function frame */\r
A->file->code[cleanup].param[0] = A->file->count;\r
if (!PUSH (A->file, slang_asm_leave))\r
- return 0;\r
+ return GL_FALSE;\r
\r
/* free local variable storage */\r
if (!PLAB (A->file, slang_asm_local_free, local_size - param_size - 4))\r
- return 0;\r
+ return GL_FALSE;\r
\r
/* return from the function */\r
if (!PUSH (A->file, slang_asm_return))\r
- return 0;\r
- return 1;\r
-}\r
-\r
-int _slang_cleanup_stack (slang_assembly_file *file, slang_operation *op, int ref,\r
- slang_assembly_name_space *space, struct slang_machine_ *mach, slang_atom_pool *atoms)\r
-{\r
- slang_assemble_ctx A;\r
+ return GL_FALSE;\r
\r
- A.file = file;\r
- A.mach = mach;\r
- A.atoms = atoms;\r
- A.space = *space;\r
- return _slang_cleanup_stack_ (&A, op);\r
+ return GL_TRUE;\r
}\r
\r
-int _slang_cleanup_stack_ (slang_assemble_ctx *A, slang_operation *op)\r
+GLboolean _slang_cleanup_stack (slang_assemble_ctx *A, slang_operation *op)\r
{\r
slang_assembly_typeinfo ti;\r
- unsigned int size = 0;\r
+ GLuint size = 0;\r
\r
/* get type info of the operation and calculate its size */\r
if (!slang_assembly_typeinfo_construct (&ti))\r
- return 0;\r
- if (!_slang_typeof_operation (op, &A->space, &ti, A->atoms))\r
+ return GL_FALSE;\r
+ if (!_slang_typeof_operation (A, op, &ti))\r
{\r
slang_assembly_typeinfo_destruct (&ti);\r
- return 0;\r
+ return GL_FALSE;\r
}\r
- if (A->ref == slang_ref_force)\r
- size = 4;\r
- else if (ti.spec.type != slang_spec_void)\r
- if (!sizeof_variable (&ti.spec, slang_qual_none, NULL, &A->space, &size, A->mach, A->file, A->atoms))\r
+ if (ti.spec.type != slang_spec_void) {\r
+ if (A->ref == slang_ref_force) {\r
+ size = 4;\r
+ }\r
+ else if (!sizeof_variable (A, &ti.spec, slang_qual_none, 0, &size))\r
{\r
slang_assembly_typeinfo_destruct (&ti);\r
- return 0;\r
+ return GL_FALSE;\r
}\r
+ }\r
slang_assembly_typeinfo_destruct (&ti);\r
\r
/* if nonzero, free it from the stack */\r
if (size != 0)\r
{\r
if (!PLAB (A->file, slang_asm_local_free, size))\r
- return 0;\r
+ return GL_FALSE;\r
}\r
- return 1;\r
+\r
+ return GL_TRUE;\r
}\r
\r
/* _slang_assemble_operation() */\r
\r
-static int dereference_aggregate (slang_assembly_file *file, const slang_storage_aggregate *agg,\r
- unsigned int *size, slang_assembly_local_info *info, slang_swizzle *swz, int is_swizzled)\r
+static GLboolean dereference_aggregate (slang_assemble_ctx *A, const slang_storage_aggregate *agg,\r
+ GLuint *size, slang_swizzle *swz, GLboolean is_swizzled)\r
{\r
- unsigned int i;\r
+ GLuint i;\r
\r
for (i = agg->count; i > 0; i--)\r
{\r
const slang_storage_array *arr = &agg->arrays[i - 1];\r
- unsigned int j;\r
+ GLuint j;\r
\r
for (j = arr->length; j > 0; j--)\r
{\r
if (arr->type == slang_stor_aggregate)\r
{\r
- if (!dereference_aggregate (file, arr->aggregate, size, info, swz, is_swizzled))\r
- return 0;\r
+ if (!dereference_aggregate (A, arr->aggregate, size, swz, is_swizzled))\r
+ return GL_FALSE;\r
}\r
else\r
{\r
- unsigned int src_offset;\r
+ GLuint src_offset;\r
slang_assembly_type ty;\r
\r
*size -= 4;\r
}\r
\r
/* dereference data slot of a basic type */\r
- if (!PLAB2 (file, slang_asm_local_addr, info->addr_tmp, 4))\r
- return 0;\r
- if (!PUSH (file, slang_asm_addr_deref))\r
- return 0;\r
- if (!PLAB (file, slang_asm_addr_push, src_offset))\r
- return 0;\r
- if (!PUSH (file, slang_asm_addr_add))\r
- return 0;\r
+ if (!PLAB2 (A->file, slang_asm_local_addr, A->local.addr_tmp, 4))\r
+ return GL_FALSE;\r
+ if (!PUSH (A->file, slang_asm_addr_deref))\r
+ return GL_FALSE;\r
+ if (!PLAB (A->file, slang_asm_addr_push, src_offset))\r
+ return GL_FALSE;\r
+ if (!PUSH (A->file, slang_asm_addr_add))\r
+ return GL_FALSE;\r
\r
switch (arr->type)\r
{\r
_mesa_problem(NULL, "Unexpected arr->type in dereference_aggregate");\r
ty = slang_asm_none;\r
}\r
- if (!PUSH (file, ty))\r
- return 0;\r
+ if (!PUSH (A->file, ty))\r
+ return GL_FALSE;\r
}\r
}\r
}\r
- return 1;\r
+\r
+ return GL_TRUE;\r
}\r
\r
-int _slang_dereference (slang_assembly_file *file, slang_operation *op,\r
- slang_assembly_name_space *space, slang_assembly_local_info *info, slang_machine *mach,\r
- slang_atom_pool *atoms)\r
+GLboolean _slang_dereference (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;\r
- unsigned int size;\r
+ GLuint size;\r
\r
/* get type information of the given operation */\r
if (!slang_assembly_typeinfo_construct (&ti))\r
- return 0;\r
- if (!_slang_typeof_operation (op, space, &ti, atoms))\r
- {\r
- slang_assembly_typeinfo_destruct (&ti);\r
- return 0;\r
- }\r
+ return GL_FALSE;\r
+ if (!_slang_typeof_operation (A, op, &ti))\r
+ goto end1;\r
\r
/* construct aggregate from the type info */\r
if (!slang_storage_aggregate_construct (&agg))\r
- {\r
- slang_assembly_typeinfo_destruct (&ti);\r
- return 0;\r
- }\r
- if (!_slang_aggregate_variable (&agg, &ti.spec, ti.array_size, space->funcs, space->structs,\r
- space->vars, mach, file, atoms))\r
- {\r
- slang_storage_aggregate_destruct (&agg);\r
- slang_assembly_typeinfo_destruct (&ti);\r
- return 0;\r
- }\r
+ goto end1;\r
+ if (!_slang_aggregate_variable (&agg, &ti.spec, ti.array_len, A->space.funcs, A->space.structs,\r
+ A->space.vars, A->mach, A->file, A->atoms))\r
+ goto end;\r
\r
/* dereference the resulting aggregate */\r
size = _slang_sizeof_aggregate (&agg);\r
- result = dereference_aggregate (file, &agg, &size, info, &ti.swz, ti.is_swizzled);\r
+ result = dereference_aggregate (A, &agg, &size, &ti.swz, ti.is_swizzled);\r
\r
+end:\r
slang_storage_aggregate_destruct (&agg);\r
+end1:\r
slang_assembly_typeinfo_destruct (&ti);\r
return result;\r
}\r
\r
-int _slang_assemble_function_call (slang_assemble_ctx *A, slang_function *fun,\r
+GLboolean _slang_assemble_function_call (slang_assemble_ctx *A, slang_function *fun,\r
slang_operation *params, GLuint param_count, GLboolean assignment)\r
{\r
- unsigned int i;\r
- slang_assembly_stack_info p_stk[64];\r
+ GLuint i;\r
+ slang_swizzle p_swz[64];\r
+ slang_ref_type p_ref[64];\r
\r
/* TODO: fix this, allocate dynamically */\r
if (param_count > 64)\r
- return 0;\r
+ return GL_FALSE;\r
\r
/* make room for the return value, if any */\r
if (fun->header.type.specifier.type != slang_spec_void)\r
{\r
- unsigned int ret_size = 0;\r
+ GLuint ret_size = 0;\r
\r
- if (!sizeof_variable (&fun->header.type.specifier, slang_qual_none, NULL, &A->space,\r
- &ret_size, A->mach, A->file, A->atoms))\r
- return 0;\r
+ if (!sizeof_variable (A, &fun->header.type.specifier, slang_qual_none, 0, &ret_size))\r
+ return GL_FALSE;\r
if (!PLAB (A->file, slang_asm_local_alloc, ret_size))\r
- return 0;\r
+ return GL_FALSE;\r
}\r
\r
/* push the actual parameters on the stack */\r
fun->parameters->variables[i].type.qualifier == slang_qual_out)\r
{\r
if (!PLAB2 (A->file, slang_asm_local_addr, A->local.addr_tmp, 4))\r
- return 0;\r
+ return GL_FALSE;\r
/* TODO: optimize the "out" parameter case */\r
- if (!_slang_assemble_operation_ (A, ¶ms[i], slang_ref_force))\r
- return 0;\r
- p_stk[i] = A->swz;\r
+ if (!_slang_assemble_operation (A, ¶ms[i], slang_ref_force))\r
+ return GL_FALSE;\r
+ p_swz[i] = A->swz;\r
+ p_ref[i] = A->ref;\r
if (!PUSH (A->file, slang_asm_addr_copy))\r
- return 0;\r
+ return GL_FALSE;\r
if (!PUSH (A->file, slang_asm_addr_deref))\r
- return 0;\r
+ return GL_FALSE;\r
if (i == 0 && assignment)\r
{\r
/* duplicate the resulting address */\r
if (!PLAB2 (A->file, slang_asm_local_addr, A->local.addr_tmp, 4))\r
- return 0;\r
+ return GL_FALSE;\r
if (!PUSH (A->file, slang_asm_addr_deref))\r
- return 0;\r
+ return GL_FALSE;\r
}\r
- if (!_slang_dereference (A->file, ¶ms[i], &A->space, &A->local, A->mach, A->atoms))\r
- return 0;\r
+ if (!_slang_dereference (A, ¶ms[i]))\r
+ return GL_FALSE;\r
}\r
else\r
{\r
- if (!_slang_assemble_operation_ (A, ¶ms[i], slang_ref_forbid))\r
- return 0;\r
- p_stk[i] = A->swz;\r
+ if (!_slang_assemble_operation (A, ¶ms[i], slang_ref_forbid))\r
+ return GL_FALSE;\r
+ p_swz[i] = A->swz;\r
+ p_ref[i] = A->ref;\r
}\r
}\r
\r
/* call the function */\r
if (!PLAB (A->file, slang_asm_call, fun->address))\r
- return 0;\r
+ return GL_FALSE;\r
\r
/* pop the parameters from the stack */\r
for (i = param_count; i > 0; i--)\r
{\r
- unsigned int j = i - 1;\r
+ GLuint j = i - 1;\r
\r
+ A->swz = p_swz[j];\r
+ A->ref = p_ref[j];\r
if (fun->parameters->variables[j].type.qualifier == slang_qual_inout ||\r
fun->parameters->variables[j].type.qualifier == slang_qual_out)\r
{\r
/* for output parameter copy the contents of the formal parameter\r
* back to the original actual parameter */\r
- A->swz = p_stk[j];\r
if (!_slang_assemble_assignment (A, ¶ms[j]))\r
- return 0;\r
+ return GL_FALSE;\r
/* pop the actual parameter's address */\r
if (!PLAB (A->file, slang_asm_local_free, 4))\r
- return 0;\r
+ return GL_FALSE;\r
}\r
else\r
{\r
/* pop the value of the parameter */\r
- if (!_slang_cleanup_stack_ (A, ¶ms[j]))\r
- return 0;\r
+ if (!_slang_cleanup_stack (A, ¶ms[j]))\r
+ return GL_FALSE;\r
}\r
}\r
\r
- return 1;\r
+ return GL_TRUE;\r
}\r
\r
-int _slang_assemble_function_call_name (slang_assemble_ctx *A, const char *name,\r
+GLboolean _slang_assemble_function_call_name (slang_assemble_ctx *A, const char *name,\r
slang_operation *params, GLuint param_count, GLboolean assignment)\r
{\r
slang_atom atom;\r
\r
atom = slang_atom_pool_atom (A->atoms, name);\r
if (atom == SLANG_ATOM_NULL)\r
- return 0;\r
+ return GL_FALSE;\r
fun = _slang_locate_function (A->space.funcs, atom, params, param_count, &A->space, A->atoms);\r
if (fun == NULL)\r
- return 0;\r
+ return GL_FALSE;\r
return _slang_assemble_function_call (A, fun, params, param_count, assignment);\r
}\r
\r
-static int assemble_function_call_name_dummyint (slang_assemble_ctx *A, const char *name,\r
+static GLboolean assemble_function_call_name_dummyint (slang_assemble_ctx *A, const char *name,\r
slang_operation *params)\r
{\r
slang_operation p[2];\r
- int result;\r
+ GLboolean result;\r
\r
p[0] = params[0];\r
if (!slang_operation_construct (&p[1]))\r
- return 0;\r
+ return GL_FALSE;\r
p[1].type = slang_oper_literal_int;\r
result = _slang_assemble_function_call_name (A, name, p, 2, GL_FALSE);\r
slang_operation_destruct (&p[1]);\r
{ "float_log2", slang_asm_float_log2, slang_asm_float_copy },\r
{ "float_floor", slang_asm_float_floor, slang_asm_float_copy },\r
{ "float_ceil", slang_asm_float_ceil, slang_asm_float_copy },\r
+ { "float_noise1", slang_asm_float_noise1, slang_asm_float_copy },\r
+ { "float_noise2", slang_asm_float_noise2, slang_asm_float_copy },\r
+ { "float_noise3", slang_asm_float_noise3, slang_asm_float_copy },\r
+ { "float_noise4", slang_asm_float_noise4, slang_asm_float_copy },\r
{ "int_to_float", slang_asm_int_to_float, slang_asm_float_copy },\r
+ { "vec4_tex1d", slang_asm_vec4_tex1d, slang_asm_none },\r
+ { "vec4_tex2d", slang_asm_vec4_tex2d, slang_asm_none },\r
+ { "vec4_tex3d", slang_asm_vec4_tex3d, slang_asm_none },\r
+ { "vec4_texcube", slang_asm_vec4_texcube, slang_asm_none },\r
+ { "vec4_shad1d", slang_asm_vec4_shad1d, slang_asm_none },\r
+ { "vec4_shad2d", slang_asm_vec4_shad2d, slang_asm_none },\r
/* mesa-specific extensions */\r
{ "float_print", slang_asm_float_deref, slang_asm_float_print },\r
{ "int_print", slang_asm_int_deref, slang_asm_int_print },\r
{ NULL, slang_asm_none, slang_asm_none }\r
};\r
\r
-static int call_asm_instruction (slang_assembly_file *file, slang_atom a_name, slang_atom_pool *atoms)\r
+static GLboolean call_asm_instruction (slang_assemble_ctx *A, slang_atom a_name)\r
{\r
const char *id;\r
- unsigned int i;\r
+ GLuint i;\r
\r
- id = slang_atom_pool_id (atoms, a_name);\r
+ id = slang_atom_pool_id (A->atoms, a_name);\r
\r
for (i = 0; inst[i].name != NULL; i++)\r
if (slang_string_compare (id, inst[i].name) == 0)\r
break;\r
if (inst[i].name == NULL)\r
- return 0;\r
+ return GL_FALSE;\r
\r
- if (!PLAB2 (file, inst[i].code1, 4, 0))\r
- return 0;\r
+ if (!PLAB2 (A->file, inst[i].code1, 4, 0))\r
+ return GL_FALSE;\r
if (inst[i].code2 != slang_asm_none)\r
- if (!PLAB2 (file, inst[i].code2, 4, 0))\r
- return 0;\r
+ if (!PLAB2 (A->file, inst[i].code2, 4, 0))\r
+ return GL_FALSE;\r
\r
/* clean-up the stack from the remaining dst address */\r
- if (!PLAB (file, slang_asm_local_free, 4))\r
- return 0;\r
+ if (!PLAB (A->file, slang_asm_local_free, 4))\r
+ return GL_FALSE;\r
\r
- return 1;\r
+ return GL_TRUE;\r
}\r
\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
+static GLboolean equality_aggregate (slang_assemble_ctx *A, const slang_storage_aggregate *agg,\r
+ GLuint *index, GLuint size, GLuint z_label)\r
{\r
- unsigned int i;\r
+ GLuint 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
+ GLuint j;\r
\r
for (j = 0; j < arr->length; j++)\r
{\r
if (arr->type == slang_stor_aggregate)\r
{\r
- if (!equality_aggregate (file, arr->aggregate, index, size, info, z_label))\r
- return 0;\r
+ if (!equality_aggregate (A, arr->aggregate, index, size, z_label))\r
+ return GL_FALSE;\r
}\r
else\r
{\r
- if (!PLAB2 (file, slang_asm_float_equal_int, size + *index, *index))\r
- return 0;\r
+ if (!PLAB2 (A->file, slang_asm_float_equal_int, size + *index, *index))\r
+ return GL_FALSE;\r
*index += 4;\r
- if (!PLAB (file, slang_asm_jump_if_zero, z_label))\r
- return 0;\r
+ if (!PLAB (A->file, slang_asm_jump_if_zero, z_label))\r
+ return GL_FALSE;\r
}\r
}\r
}\r
- return 1;\r
+\r
+ return GL_TRUE;\r
}\r
\r
-static int equality (slang_assembly_file *file, slang_operation *op,\r
- slang_assembly_name_space *space, slang_assembly_local_info *info, int equal,\r
- slang_machine *mach, slang_atom_pool *atoms)\r
+static GLboolean equality (slang_assemble_ctx *A, slang_operation *op, GLboolean equal)\r
{\r
slang_assembly_typeinfo ti;\r
- int result = 0;\r
+ GLboolean result = GL_FALSE;\r
slang_storage_aggregate agg;\r
- unsigned int index, size;\r
- unsigned int skip_jump, true_label, true_jump, false_label, false_jump;\r
+ GLuint index, size;\r
+ GLuint skip_jump, true_label, true_jump, false_label, false_jump;\r
\r
/* get type of operation */\r
if (!slang_assembly_typeinfo_construct (&ti))\r
- return 0;\r
- if (!_slang_typeof_operation (op, space, &ti, atoms))\r
+ return GL_FALSE;\r
+ if (!_slang_typeof_operation (A, op, &ti))\r
goto end1;\r
\r
/* convert it to an aggregate */\r
if (!slang_storage_aggregate_construct (&agg))\r
goto end1;\r
- if (!_slang_aggregate_variable (&agg, &ti.spec, NULL, space->funcs, space->structs,\r
- space->vars, mach, file, atoms))\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 end;\r
\r
/* compute the size of the agregate - there are two such aggregates on the stack */\r
size = _slang_sizeof_aggregate (&agg);\r
\r
/* jump to the actual data-comparison code */\r
- skip_jump = file->count;\r
- if (!PUSH (file, slang_asm_jump))\r
+ skip_jump = A->file->count;\r
+ if (!PUSH (A->file, slang_asm_jump))\r
goto end;\r
\r
/* pop off the stack the compared data and push 1 */\r
- true_label = file->count;\r
- if (!PLAB (file, slang_asm_local_free, size * 2))\r
+ true_label = A->file->count;\r
+ if (!PLAB (A->file, slang_asm_local_free, size * 2))\r
goto end;\r
- if (!PLIT (file, slang_asm_bool_push, (GLfloat) 1))\r
+ if (!PLIT (A->file, slang_asm_bool_push, (GLfloat) 1))\r
goto end;\r
- true_jump = file->count;\r
- if (!PUSH (file, slang_asm_jump))\r
+ true_jump = A->file->count;\r
+ if (!PUSH (A->file, slang_asm_jump))\r
goto end;\r
\r
- false_label = file->count;\r
- if (!PLAB (file, slang_asm_local_free, size * 2))\r
+ false_label = A->file->count;\r
+ if (!PLAB (A->file, slang_asm_local_free, size * 2))\r
goto end;\r
- if (!PLIT (file, slang_asm_bool_push, (GLfloat) 0))\r
+ if (!PLIT (A->file, slang_asm_bool_push, (GLfloat) 0))\r
goto end;\r
- false_jump = file->count;\r
- if (!PUSH (file, slang_asm_jump))\r
+ false_jump = A->file->count;\r
+ if (!PUSH (A->file, slang_asm_jump))\r
goto end;\r
\r
- file->code[skip_jump].param[0] = file->count;\r
+ A->file->code[skip_jump].param[0] = A->file->count;\r
\r
/* compare the data on stack, it will eventually jump either to true or false label */\r
index = 0;\r
- if (!equality_aggregate (file, &agg, &index, size, info, equal ? false_label : true_label))\r
+ if (!equality_aggregate (A, &agg, &index, size, equal ? false_label : true_label))\r
goto end;\r
- if (!PLAB (file, slang_asm_jump, equal ? true_label : false_label))\r
+ if (!PLAB (A->file, slang_asm_jump, equal ? true_label : false_label))\r
goto end;\r
\r
- file->code[true_jump].param[0] = file->count;\r
- file->code[false_jump].param[0] = file->count;\r
+ A->file->code[true_jump].param[0] = A->file->count;\r
+ A->file->code[false_jump].param[0] = A->file->count;\r
\r
- result = 1;\r
+ result = GL_TRUE;\r
end:\r
slang_storage_aggregate_destruct (&agg);\r
end1:\r
return result;\r
}\r
\r
-static int handle_subscript (slang_assembly_typeinfo *tie, slang_assembly_typeinfo *tia,\r
- slang_assembly_file *file, slang_operation *op, int reference, slang_assembly_flow_control *flow,\r
- slang_assembly_name_space *space, slang_assembly_local_info *info, slang_machine *mach,\r
- slang_atom_pool *atoms)\r
+static GLboolean handle_subscript (slang_assemble_ctx *A, slang_assembly_typeinfo *tie,\r
+ slang_assembly_typeinfo *tia, slang_operation *op, slang_ref_type ref)\r
{\r
- unsigned int asize = 0, esize = 0;\r
- slang_assembly_stack_info _stk;\r
+ GLuint asize = 0, esize = 0;\r
\r
/* get type info of the master expression (matrix, vector or an array */\r
- if (!_slang_typeof_operation (&op->children[0], space, tia, atoms))\r
- return 0;\r
- if (!sizeof_variable (&tia->spec, slang_qual_none, tia->array_size, space, &asize, mach, file,\r
- atoms))\r
- return 0;\r
+ if (!_slang_typeof_operation (A, &op->children[0], tia))\r
+ return GL_FALSE;\r
+ if (!sizeof_variable (A, &tia->spec, slang_qual_none, tia->array_len, &asize))\r
+ return GL_FALSE;\r
\r
/* get type info of the result (matrix column, vector row or array element) */\r
- if (!_slang_typeof_operation (op, space, tie, atoms))\r
- return 0;\r
- if (!sizeof_variable (&tie->spec, slang_qual_none, NULL, space, &esize, mach, file, atoms))\r
- return 0;\r
+ if (!_slang_typeof_operation (A, op, tie))\r
+ return GL_FALSE;\r
+ if (!sizeof_variable (A, &tie->spec, slang_qual_none, 0, &esize))\r
+ return GL_FALSE;\r
\r
/* assemble the master expression */\r
- if (!_slang_assemble_operation (file, &op->children[0], reference, flow, space, info, &_stk,\r
- mach, atoms))\r
- return 0;\r
- /* ignre the _stk */\r
+ if (!_slang_assemble_operation (A, &op->children[0], ref))\r
+ return GL_FALSE;\r
\r
/* when indexing an l-value swizzle, push the swizzle_tmp */\r
- if (reference && tia->is_swizzled)\r
- {\r
- if (!PLAB2 (file, slang_asm_local_addr, info->swizzle_tmp, 16))\r
- return 0;\r
- }\r
+ if (ref == slang_ref_force && tia->is_swizzled)\r
+ if (!PLAB2 (A->file, slang_asm_local_addr, A->local.swizzle_tmp, 16))\r
+ return GL_FALSE;\r
\r
/* assemble the subscript expression */\r
- if (!_slang_assemble_operation (file, &op->children[1], 0, flow, space, info, &_stk, mach, atoms))\r
- return 0;\r
- /* ignore the _stk */\r
+ if (!_slang_assemble_operation (A, &op->children[1], slang_ref_forbid))\r
+ return GL_FALSE;\r
\r
- if (reference && tia->is_swizzled)\r
+ if (ref == slang_ref_force && tia->is_swizzled)\r
{\r
- unsigned int i;\r
+ GLuint i;\r
\r
/* copy the swizzle indexes to the swizzle_tmp */\r
for (i = 0; i < tia->swz.num_components; i++)\r
{\r
- if (!PLAB2 (file, slang_asm_local_addr, info->swizzle_tmp, 16))\r
- return 0;\r
- if (!PLAB (file, slang_asm_addr_push, i * 4))\r
- return 0;\r
- if (!PUSH (file, slang_asm_addr_add))\r
- return 0;\r
- if (!PLAB (file, slang_asm_addr_push, tia->swz.swizzle[i]))\r
- return 0;\r
- if (!PUSH (file, slang_asm_addr_copy))\r
- return 0;\r
- if (!PLAB (file, slang_asm_local_free, 4))\r
- return 0;\r
+ if (!PLAB2 (A->file, slang_asm_local_addr, A->local.swizzle_tmp, 16))\r
+ return GL_FALSE;\r
+ if (!PLAB (A->file, slang_asm_addr_push, i * 4))\r
+ return GL_FALSE;\r
+ if (!PUSH (A->file, slang_asm_addr_add))\r
+ return GL_FALSE;\r
+ if (!PLAB (A->file, slang_asm_addr_push, tia->swz.swizzle[i]))\r
+ return GL_FALSE;\r
+ if (!PUSH (A->file, slang_asm_addr_copy))\r
+ return GL_FALSE;\r
+ if (!PLAB (A->file, slang_asm_local_free, 4))\r
+ return GL_FALSE;\r
}\r
\r
/* offset the pushed swizzle_tmp address and dereference it */\r
- if (!PUSH (file, slang_asm_int_to_addr))\r
- return 0;\r
- if (!PLAB (file, slang_asm_addr_push, 4))\r
- return 0;\r
- if (!PUSH (file, slang_asm_addr_multiply))\r
- return 0;\r
- if (!PUSH (file, slang_asm_addr_add))\r
- return 0;\r
- if (!PUSH (file, slang_asm_addr_deref))\r
- return 0;\r
+ if (!PUSH (A->file, slang_asm_int_to_addr))\r
+ return GL_FALSE;\r
+ if (!PLAB (A->file, slang_asm_addr_push, 4))\r
+ return GL_FALSE;\r
+ if (!PUSH (A->file, slang_asm_addr_multiply))\r
+ return GL_FALSE;\r
+ if (!PUSH (A->file, slang_asm_addr_add))\r
+ return GL_FALSE;\r
+ if (!PUSH (A->file, slang_asm_addr_deref))\r
+ return GL_FALSE;\r
}\r
else\r
{\r
/* convert the integer subscript to a relative address */\r
- if (!PUSH (file, slang_asm_int_to_addr))\r
- return 0;\r
+ if (!PUSH (A->file, slang_asm_int_to_addr))\r
+ return GL_FALSE;\r
}\r
\r
- if (!PLAB (file, slang_asm_addr_push, esize))\r
- return 0;\r
- if (!PUSH (file, slang_asm_addr_multiply))\r
- return 0;\r
+ if (!PLAB (A->file, slang_asm_addr_push, esize))\r
+ return GL_FALSE;\r
+ if (!PUSH (A->file, slang_asm_addr_multiply))\r
+ return GL_FALSE;\r
\r
- if (reference)\r
+ if (ref == slang_ref_force)\r
{\r
/* offset the base address with the relative address */\r
- if (!PUSH (file, slang_asm_addr_add))\r
- return 0;\r
+ if (!PUSH (A->file, slang_asm_addr_add))\r
+ return GL_FALSE;\r
}\r
else\r
{\r
- unsigned int i;\r
+ GLuint i;\r
\r
/* move the selected element to the beginning of the master expression */\r
for (i = 0; i < esize; i += 4)\r
- if (!PLAB2 (file, slang_asm_float_move, asize - esize + i + 4, i + 4))\r
- return 0;\r
- if (!PLAB (file, slang_asm_local_free, 4))\r
- return 0;\r
+ if (!PLAB2 (A->file, slang_asm_float_move, asize - esize + i + 4, i + 4))\r
+ return GL_FALSE;\r
+ if (!PLAB (A->file, slang_asm_local_free, 4))\r
+ return GL_FALSE;\r
\r
/* free the rest of the master expression */\r
- if (!PLAB (file, slang_asm_local_free, asize - esize))\r
- return 0;\r
+ if (!PLAB (A->file, slang_asm_local_free, asize - esize))\r
+ return GL_FALSE;\r
}\r
- return 1;\r
+\r
+ return GL_TRUE;\r
}\r
\r
-static int handle_field (slang_assembly_typeinfo *tia, slang_assembly_typeinfo *tib,\r
- slang_assembly_file *file, slang_operation *op, int reference, slang_assembly_flow_control *flow,\r
- slang_assembly_name_space *space, slang_assembly_local_info *info, slang_assembly_stack_info *stk,\r
- slang_machine *mach, slang_atom_pool *atoms)\r
+static GLboolean handle_field (slang_assemble_ctx *A, slang_assembly_typeinfo *tia,\r
+ slang_assembly_typeinfo *tib, slang_operation *op, slang_ref_type ref)\r
{\r
- slang_assembly_stack_info _stk;\r
-\r
/* get type info of the result (field or swizzle) */\r
- if (!_slang_typeof_operation (op, space, tia, atoms))\r
- return 0;\r
+ if (!_slang_typeof_operation (A, op, tia))\r
+ return GL_FALSE;\r
\r
/* get type info of the master expression being accessed (struct or vector) */\r
- if (!_slang_typeof_operation (&op->children[0], space, tib, atoms))\r
- return 0;\r
+ if (!_slang_typeof_operation (A, &op->children[0], tib))\r
+ return GL_FALSE;\r
\r
/* if swizzling a vector in-place, the swizzle temporary is needed */\r
- if (!reference && tia->is_swizzled)\r
- if (!PLAB2 (file, slang_asm_local_addr, info->swizzle_tmp, 16))\r
- return 0;\r
+ if (ref == slang_ref_forbid && tia->is_swizzled)\r
+ if (!PLAB2 (A->file, slang_asm_local_addr, A->local.swizzle_tmp, 16))\r
+ return GL_FALSE;\r
\r
/* assemble the master expression */\r
- if (!_slang_assemble_operation (file, &op->children[0], reference, flow, space, info, &_stk,\r
- mach, atoms))\r
- return 0;\r
- /* ignore _stk.swizzle - we'll have it in tia->swz */\r
+ if (!_slang_assemble_operation (A, &op->children[0], ref))\r
+ return GL_FALSE;\r
\r
/* assemble the field expression */\r
if (tia->is_swizzled)\r
{\r
- if (reference)\r
+ if (ref == slang_ref_force)\r
{\r
#if 0\r
if (tia->swz.num_components == 1)\r
/* two or more vector components are being referenced - the so-called write mask\r
* must be passed to the upper operations and applied when assigning value\r
* to this swizzle */\r
- stk->swizzle = tia->swz;\r
+ A->swz = tia->swz;\r
}\r
}\r
else\r
{\r
/* swizzle the vector in-place using the swizzle temporary */\r
- if (!_slang_assemble_constructor_from_swizzle (file, &tia->swz, &tia->spec, &tib->spec,\r
- info))\r
- return 0;\r
+ if (!_slang_assemble_constructor_from_swizzle (A, &tia->swz, &tia->spec, &tib->spec))\r
+ return GL_FALSE;\r
}\r
}\r
else\r
{\r
GLuint i, struct_size = 0, field_offset = 0, field_size = 0;\r
+ GLboolean relocate, shrink;\r
\r
+ /* calculate struct size, field offset and field size */\r
for (i = 0; i < tib->spec._struct->fields->num_variables; i++)\r
{\r
slang_variable *field;\r
\r
field = &tib->spec._struct->fields->variables[i];\r
if (!slang_storage_aggregate_construct (&agg))\r
- return 0;\r
- if (!_slang_aggregate_variable (&agg, &field->type.specifier, field->array_size,\r
- space->funcs, space->structs, space->vars, mach, file, atoms))\r
+ return GL_FALSE;\r
+ if (!_slang_aggregate_variable (&agg, &field->type.specifier, field->array_len,\r
+ A->space.funcs, A->space.structs, A->space.vars, A->mach, A->file, A->atoms))\r
{\r
slang_storage_aggregate_destruct (&agg);\r
- return 0;\r
+ return GL_FALSE;\r
}\r
size = _slang_sizeof_aggregate (&agg);\r
slang_storage_aggregate_destruct (&agg);\r
field_offset += size;\r
}\r
\r
- if (!PLAB (file, slang_asm_addr_push, field_offset))\r
- return 0;\r
+ /*\r
+ * OPTIMIZATION: If selecting the last field, no relocation is needed.\r
+ */\r
+ relocate = field_offset != struct_size - field_size;\r
+\r
+ /*\r
+ * OPTIMIZATION: If field and struct sizes are equal, no partial free is needed.\r
+ */\r
+ shrink = field_size != struct_size;\r
\r
- if (reference)\r
+ if (relocate)\r
{\r
- if (!PUSH (file, slang_asm_addr_add))\r
- return 0;\r
+ if (!PLAB (A->file, slang_asm_addr_push, field_offset))\r
+ return GL_FALSE;\r
+ }\r
+\r
+ if (ref == slang_ref_force)\r
+ {\r
+ if (relocate)\r
+ {\r
+ if (!PUSH (A->file, slang_asm_addr_add))\r
+ return GL_FALSE;\r
+ }\r
}\r
else\r
{\r
- unsigned int i;\r
+ GLuint free_b = 0;\r
\r
- /* move the selected element to the beginning of the master expression */\r
- for (i = 0; i < field_size; i += 4)\r
- if (!PLAB2 (file, slang_asm_float_move, struct_size - field_size + i + 4, i + 4))\r
- return 0;\r
- if (!PLAB (file, slang_asm_local_free, 4))\r
- return 0;\r
+ if (relocate)\r
+ {\r
+ GLuint i;\r
+\r
+ /* move the selected element to the beginning of the master expression */\r
+ for (i = 0; i < field_size; i += 4)\r
+ if (!PLAB2 (A->file, slang_asm_float_move, struct_size - field_size + i + 4, i + 4))\r
+ return GL_FALSE;\r
+ free_b += 4;\r
+ }\r
+\r
+ if (shrink)\r
+ {\r
+ /* free the rest of the master expression */\r
+ free_b += struct_size - field_size;\r
+ }\r
\r
- /* free the rest of the master expression */\r
- if (!PLAB (file, slang_asm_local_free, struct_size - field_size))\r
- return 0;\r
+ if (free_b)\r
+ {\r
+ if (!PLAB (A->file, slang_asm_local_free, free_b))\r
+ return GL_FALSE;\r
+ }\r
}\r
}\r
- return 1;\r
-}\r
\r
-int _slang_assemble_operation (slang_assembly_file *file, struct slang_operation_ *op, int reference,\r
- slang_assembly_flow_control *flow, slang_assembly_name_space *space, slang_assembly_local_info *info,\r
- slang_assembly_stack_info *stk, struct slang_machine_ *mach, slang_atom_pool *atoms)\r
-{\r
- slang_assemble_ctx A;\r
-\r
- A.file = file;\r
- A.mach = mach;\r
- A.atoms = atoms;\r
- A.space = *space;\r
- A.flow = *flow;\r
- A.local = *info;\r
- if (!_slang_assemble_operation_ (&A, op, reference ? slang_ref_force : slang_ref_forbid))\r
- return 0;\r
- *stk = A.swz;\r
- return 1;\r
+ return GL_TRUE;\r
}\r
\r
-int _slang_assemble_operation_ (slang_assemble_ctx *A, slang_operation *op, slang_ref_type ref)\r
+GLboolean _slang_assemble_operation (slang_assemble_ctx *A, slang_operation *op, slang_ref_type ref)\r
{\r
- unsigned int assem;\r
- slang_assembly_stack_info swz;\r
-\r
- assem = A->file->count;\r
- if (!push_new (A->file))\r
- return 0;\r
-\r
-if (ref == slang_ref_freelance)\r
-ref = slang_ref_forbid;\r
-\r
/* set default results */\r
- A->ref = (ref == slang_ref_freelance) ? slang_ref_force : ref;\r
- swz.swizzle.num_components = 0;\r
+ A->ref = /*(ref == slang_ref_freelance) ? slang_ref_force : */ref;\r
+ A->swz.num_components = 0;\r
\r
switch (op->type)\r
{\r
case slang_oper_block_no_new_scope:\r
case slang_oper_block_new_scope:\r
{\r
- unsigned int i;\r
+ GLuint i;\r
\r
for (i = 0; i < op->num_children; i++)\r
{\r
- if (!_slang_assemble_operation_ (A, &op->children[i], slang_ref_freelance))\r
- return 0;\r
- if (!_slang_cleanup_stack_ (A, &op->children[i]))\r
- return 0;\r
+ if (!_slang_assemble_operation (A, &op->children[i], slang_ref_forbid/*slang_ref_freelance*/))\r
+ return GL_FALSE;\r
+ if (!_slang_cleanup_stack (A, &op->children[i]))\r
+ return GL_FALSE;\r
}\r
}\r
break;\r
case slang_oper_variable_decl:\r
{\r
- unsigned int i;\r
+ GLuint i;\r
\r
for (i = 0; i < op->num_children; i++)\r
{\r
break;\r
case slang_oper_asm:\r
{\r
- unsigned int i;\r
+ GLuint i;\r
\r
- if (!_slang_assemble_operation_ (A, &op->children[0], slang_ref_force))\r
- return 0;\r
+ if (!_slang_assemble_operation (A, &op->children[0], slang_ref_force))\r
+ return GL_FALSE;\r
for (i = 1; i < op->num_children; i++)\r
- if (!_slang_assemble_operation_ (A, &op->children[i], slang_ref_forbid))\r
- return 0;\r
- if (!call_asm_instruction (A->file, op->a_id, A->atoms))\r
- return 0;\r
+ if (!_slang_assemble_operation (A, &op->children[i], slang_ref_forbid))\r
+ return GL_FALSE;\r
+ if (!call_asm_instruction (A, op->a_id))\r
+ return GL_FALSE;\r
}\r
break;\r
case slang_oper_break:\r
- A->file->code[assem].type = slang_asm_jump;\r
- A->file->code[assem].param[0] = A->flow.loop_end;\r
+ if (!PLAB (A->file, slang_asm_jump, A->flow.loop_end))\r
+ return GL_FALSE;\r
break;\r
case slang_oper_continue:\r
- A->file->code[assem].type = slang_asm_jump;\r
- A->file->code[assem].param[0] = A->flow.loop_start;\r
+ if (!PLAB (A->file, slang_asm_jump, A->flow.loop_start))\r
+ return GL_FALSE;\r
break;\r
case slang_oper_discard:\r
- A->file->code[assem].type = slang_asm_discard;\r
+ if (!PUSH (A->file, slang_asm_discard))\r
+ return GL_FALSE;\r
if (!PUSH (A->file, slang_asm_exit))\r
- return 0;\r
+ return GL_FALSE;\r
break;\r
case slang_oper_return:\r
if (A->local.ret_size != 0)\r
{\r
/* push the result's address */\r
if (!PLAB2 (A->file, slang_asm_local_addr, 0, A->local.ret_size))\r
- return 0;\r
- if (!_slang_assemble_operation_ (A, &op->children[0], slang_ref_forbid))\r
- return 0;\r
+ return GL_FALSE;\r
+ if (!_slang_assemble_operation (A, &op->children[0], slang_ref_forbid))\r
+ return GL_FALSE;\r
\r
- A->swz.swizzle.num_components = 0;\r
+ A->swz.num_components = 0;\r
/* assign the operation to the function result (it was reserved on the stack) */\r
if (!_slang_assemble_assignment (A, op->children))\r
- return 0;\r
+ return GL_FALSE;\r
\r
if (!PLAB (A->file, slang_asm_local_free, 4))\r
- return 0;\r
+ return GL_FALSE;\r
}\r
if (!PLAB (A->file, slang_asm_jump, A->flow.function_end))\r
- return 0;\r
+ return GL_FALSE;\r
break;\r
case slang_oper_expression:\r
if (ref == slang_ref_force)\r
- return 0;\r
- if (!_slang_assemble_operation_ (A, &op->children[0], ref))\r
- return 0;\r
+ return GL_FALSE;\r
+ if (!_slang_assemble_operation (A, &op->children[0], ref))\r
+ return GL_FALSE;\r
break;\r
case slang_oper_if:\r
- if (!_slang_assemble_if (A->file, op, &A->flow, &A->space, &A->local, A->mach, A->atoms))\r
- return 0;\r
+ if (!_slang_assemble_if (A, op))\r
+ return GL_FALSE;\r
break;\r
case slang_oper_while:\r
- if (!_slang_assemble_while (A->file, op, &A->flow, &A->space, &A->local, A->mach, A->atoms))\r
- return 0;\r
+ if (!_slang_assemble_while (A, op))\r
+ return GL_FALSE;\r
break;\r
case slang_oper_do:\r
- if (!_slang_assemble_do (A->file, op, &A->flow, &A->space, &A->local, A->mach, A->atoms))\r
- return 0;\r
+ if (!_slang_assemble_do (A, op))\r
+ return GL_FALSE;\r
break;\r
case slang_oper_for:\r
- if (!_slang_assemble_for (A->file, op, &A->flow, &A->space, &A->local, A->mach, A->atoms))\r
- return 0;\r
+ if (!_slang_assemble_for (A, op))\r
+ return GL_FALSE;\r
break;\r
case slang_oper_void:\r
break;\r
case slang_oper_literal_bool:\r
if (ref == slang_ref_force)\r
- return 0;\r
- A->file->code[assem].type = slang_asm_bool_push;\r
- A->file->code[assem].literal = op->literal;\r
+ return GL_FALSE;\r
+ if (!PLIT (A->file, slang_asm_bool_push, op->literal))\r
+ return GL_FALSE;\r
A->ref = slang_ref_forbid;\r
break;\r
case slang_oper_literal_int:\r
if (ref == slang_ref_force)\r
- return 0;\r
- A->file->code[assem].type = slang_asm_int_push;\r
- A->file->code[assem].literal = op->literal;\r
+ return GL_FALSE;\r
+ if (!PLIT (A->file, slang_asm_int_push, op->literal))\r
+ return GL_FALSE;\r
A->ref = slang_ref_forbid;\r
break;\r
case slang_oper_literal_float:\r
if (ref == slang_ref_force)\r
- return 0;\r
- A->file->code[assem].type = slang_asm_float_push;\r
- A->file->code[assem].literal = op->literal;\r
+ return GL_FALSE;\r
+ if (!PLIT (A->file, slang_asm_float_push, op->literal))\r
+ return GL_FALSE;\r
A->ref = slang_ref_forbid;\r
break;\r
case slang_oper_identifier:\r
{\r
slang_variable *var;\r
- unsigned int size;\r
+ GLuint size;\r
\r
/* find the variable and calculate its size */\r
- var = _slang_locate_variable (op->locals, op->a_id, 1);\r
+ var = _slang_locate_variable (op->locals, op->a_id, GL_TRUE);\r
if (var == NULL)\r
- return 0;\r
+ return GL_FALSE;\r
size = 0;\r
- if (!sizeof_variable (&var->type.specifier, slang_qual_none, var->array_size, &A->space,\r
- &size, A->mach, A->file, A->atoms))\r
- return 0;\r
+ if (!sizeof_variable (A, &var->type.specifier, slang_qual_none, var->array_len, &size))\r
+ return GL_FALSE;\r
\r
/* prepare stack for dereferencing */\r
if (ref == slang_ref_forbid)\r
if (!PLAB2 (A->file, slang_asm_local_addr, A->local.addr_tmp, 4))\r
- return 0;\r
+ return GL_FALSE;\r
\r
/* push the variable's address */\r
if (var->global)\r
{\r
- if (!PLAB (A->file, slang_asm_addr_push, var->address))\r
- return 0;\r
+ if (!PLAB (A->file, slang_asm_global_addr, var->address))\r
+ return GL_FALSE;\r
}\r
else\r
{\r
if (!PLAB2 (A->file, slang_asm_local_addr, var->address, size))\r
- return 0;\r
+ return GL_FALSE;\r
}\r
\r
/* perform the dereference */\r
if (ref == slang_ref_forbid)\r
{\r
if (!PUSH (A->file, slang_asm_addr_copy))\r
- return 0;\r
+ return GL_FALSE;\r
if (!PLAB (A->file, slang_asm_local_free, 4))\r
- return 0;\r
- if (!_slang_dereference (A->file, op, &A->space, &A->local, A->mach, A->atoms))\r
- return 0;\r
+ return GL_FALSE;\r
+ if (!_slang_dereference (A, op))\r
+ return GL_FALSE;\r
}\r
}\r
break;\r
case slang_oper_sequence:\r
if (ref == slang_ref_force)\r
- return 0;\r
- if (!_slang_assemble_operation_ (A, &op->children[0], slang_ref_freelance))\r
- return 0;\r
- if (!_slang_cleanup_stack_ (A, &op->children[0]))\r
- return 0;\r
- if (!_slang_assemble_operation_ (A, &op->children[1], slang_ref_forbid))\r
- return 0;\r
+ return GL_FALSE;\r
+ if (!_slang_assemble_operation (A, &op->children[0], slang_ref_forbid/*slang_ref_freelance*/))\r
+ return GL_FALSE;\r
+ if (!_slang_cleanup_stack (A, &op->children[0]))\r
+ return GL_FALSE;\r
+ if (!_slang_assemble_operation (A, &op->children[1], slang_ref_forbid))\r
+ return GL_FALSE;\r
A->ref = slang_ref_forbid;\r
break;\r
case slang_oper_assign:\r
if (!_slang_assemble_assign (A, op, "=", ref))\r
- return 0;\r
+ return GL_FALSE;\r
break;\r
case slang_oper_addassign:\r
if (!_slang_assemble_assign (A, op, "+=", ref))\r
- return 0;\r
+ return GL_FALSE;\r
+ A->ref = ref;\r
break;\r
case slang_oper_subassign:\r
if (!_slang_assemble_assign (A, op, "-=", ref))\r
- return 0;\r
+ return GL_FALSE;\r
+ A->ref = ref;\r
break;\r
case slang_oper_mulassign:\r
if (!_slang_assemble_assign (A, op, "*=", ref))\r
- return 0;\r
+ return GL_FALSE;\r
+ A->ref = ref;\r
break;\r
/*case slang_oper_modassign:*/\r
/*case slang_oper_lshassign:*/\r
/*case slang_oper_andassign:*/\r
case slang_oper_divassign:\r
if (!_slang_assemble_assign (A, op, "/=", ref))\r
- return 0;\r
+ return GL_FALSE;\r
+ A->ref = ref;\r
break;\r
case slang_oper_select:\r
- if (!_slang_assemble_select (A->file, op, &A->flow, &A->space, &A->local, A->mach, A->atoms))\r
- return 0;\r
+ if (!_slang_assemble_select (A, op))\r
+ return GL_FALSE;\r
A->ref = slang_ref_forbid;\r
break;\r
case slang_oper_logicalor:\r
- if (!_slang_assemble_logicalor (A->file, op, &A->flow, &A->space, &A->local, A->mach, A->atoms))\r
- return 0;\r
+ if (!_slang_assemble_logicalor (A, op))\r
+ return GL_FALSE;\r
A->ref = slang_ref_forbid;\r
break;\r
case slang_oper_logicaland:\r
- if (!_slang_assemble_logicaland (A->file, op, &A->flow, &A->space, &A->local, A->mach, A->atoms))\r
- return 0;\r
+ if (!_slang_assemble_logicaland (A, op))\r
+ return GL_FALSE;\r
A->ref = slang_ref_forbid;\r
break;\r
case slang_oper_logicalxor:\r
if (!_slang_assemble_function_call_name (A, "^^", op->children, 2, GL_FALSE))\r
- return 0;\r
+ return GL_FALSE;\r
A->ref = slang_ref_forbid;\r
break;\r
/*case slang_oper_bitor:*/\r
/*case slang_oper_bitand:*/\r
case slang_oper_less:\r
if (!_slang_assemble_function_call_name (A, "<", op->children, 2, GL_FALSE))\r
- return 0;\r
+ return GL_FALSE;\r
A->ref = slang_ref_forbid;\r
break;\r
case slang_oper_greater:\r
if (!_slang_assemble_function_call_name (A, ">", op->children, 2, GL_FALSE))\r
- return 0;\r
+ return GL_FALSE;\r
A->ref = slang_ref_forbid;\r
break;\r
case slang_oper_lessequal:\r
if (!_slang_assemble_function_call_name (A, "<=", op->children, 2, GL_FALSE))\r
- return 0;\r
+ return GL_FALSE;\r
A->ref = slang_ref_forbid;\r
break;\r
case slang_oper_greaterequal:\r
if (!_slang_assemble_function_call_name (A, ">=", op->children, 2, GL_FALSE))\r
- return 0;\r
+ return GL_FALSE;\r
A->ref = slang_ref_forbid;\r
break;\r
/*case slang_oper_lshift:*/\r
/*case slang_oper_rshift:*/\r
case slang_oper_add:\r
if (!_slang_assemble_function_call_name (A, "+", op->children, 2, GL_FALSE))\r
- return 0;\r
+ return GL_FALSE;\r
A->ref = slang_ref_forbid;\r
break;\r
case slang_oper_subtract:\r
if (!_slang_assemble_function_call_name (A, "-", op->children, 2, GL_FALSE))\r
- return 0;\r
+ return GL_FALSE;\r
A->ref = slang_ref_forbid;\r
break;\r
case slang_oper_multiply:\r
if (!_slang_assemble_function_call_name (A, "*", op->children, 2, GL_FALSE))\r
- return 0;\r
+ return GL_FALSE;\r
A->ref = slang_ref_forbid;\r
break;\r
/*case slang_oper_modulus:*/\r
case slang_oper_divide:\r
if (!_slang_assemble_function_call_name (A, "/", op->children, 2, GL_FALSE))\r
- return 0;\r
+ return GL_FALSE;\r
A->ref = slang_ref_forbid;\r
break;\r
case slang_oper_equal:\r
- if (!_slang_assemble_operation_ (A, &op->children[0], slang_ref_forbid))\r
- return 0;\r
- if (!_slang_assemble_operation_ (A, &op->children[1], slang_ref_forbid))\r
- return 0;\r
- if (!equality (A->file, op->children, &A->space, &A->local, 1, A->mach, A->atoms))\r
- return 0;\r
+ if (!_slang_assemble_operation (A, &op->children[0], slang_ref_forbid))\r
+ return GL_FALSE;\r
+ if (!_slang_assemble_operation (A, &op->children[1], slang_ref_forbid))\r
+ return GL_FALSE;\r
+ if (!equality (A, op->children, GL_TRUE))\r
+ return GL_FALSE;\r
A->ref = slang_ref_forbid;\r
break;\r
case slang_oper_notequal:\r
- if (!_slang_assemble_operation_ (A, &op->children[0], slang_ref_forbid))\r
- return 0;\r
- if (!_slang_assemble_operation_ (A, &op->children[1], slang_ref_forbid))\r
- return 0;\r
- if (!equality (A->file, op->children, &A->space, &A->local, 0, A->mach, A->atoms))\r
- return 0;\r
+ if (!_slang_assemble_operation (A, &op->children[0], slang_ref_forbid))\r
+ return GL_FALSE;\r
+ if (!_slang_assemble_operation (A, &op->children[1], slang_ref_forbid))\r
+ return GL_FALSE;\r
+ if (!equality (A, op->children, GL_FALSE))\r
+ return GL_FALSE;\r
A->ref = slang_ref_forbid;\r
break;\r
case slang_oper_preincrement:\r
if (!_slang_assemble_assign (A, op, "++", ref))\r
- return 0;\r
+ return GL_FALSE;\r
+ A->ref = ref;\r
break;\r
case slang_oper_predecrement:\r
if (!_slang_assemble_assign (A, op, "--", ref))\r
- return 0;\r
+ return GL_FALSE;\r
+ A->ref = ref;\r
break;\r
case slang_oper_plus:\r
- if (!_slang_dereference (A->file, op, &A->space, &A->local, A->mach, A->atoms))\r
- return 0;\r
+ if (!_slang_dereference (A, op))\r
+ return GL_FALSE;\r
A->ref = slang_ref_forbid;\r
break;\r
case slang_oper_minus:\r
if (!_slang_assemble_function_call_name (A, "-", op->children, 1, GL_FALSE))\r
- return 0;\r
+ return GL_FALSE;\r
A->ref = slang_ref_forbid;\r
break;\r
/*case slang_oper_complement:*/\r
case slang_oper_not:\r
if (!_slang_assemble_function_call_name (A, "!", op->children, 1, GL_FALSE))\r
- return 0;\r
+ return GL_FALSE;\r
A->ref = slang_ref_forbid;\r
break;\r
case slang_oper_subscript:\r
slang_assembly_typeinfo ti_arr, ti_elem;\r
\r
if (!slang_assembly_typeinfo_construct (&ti_arr))\r
- return 0;\r
+ return GL_FALSE;\r
if (!slang_assembly_typeinfo_construct (&ti_elem))\r
{\r
slang_assembly_typeinfo_destruct (&ti_arr);\r
- return 0;\r
+ return GL_FALSE;\r
}\r
- if (!handle_subscript (&ti_elem, &ti_arr, A->file, op, ref != slang_ref_forbid, &A->flow, &A->space, &A->local,\r
- A->mach, A->atoms))\r
+ if (!handle_subscript (A, &ti_elem, &ti_arr, op, ref))\r
{\r
slang_assembly_typeinfo_destruct (&ti_arr);\r
slang_assembly_typeinfo_destruct (&ti_elem);\r
- return 0;\r
+ return GL_FALSE;\r
}\r
slang_assembly_typeinfo_destruct (&ti_arr);\r
slang_assembly_typeinfo_destruct (&ti_elem);\r
&A->space, A->atoms);\r
if (fun == NULL)\r
{\r
-/* if (!_slang_assemble_constructor (file, op, flow, space, info, mach))\r
-*/ return 0;\r
+ if (!_slang_assemble_constructor (A, op))\r
+ return GL_FALSE;\r
}\r
else\r
{\r
if (!_slang_assemble_function_call (A, fun, op->children, op->num_children, GL_FALSE))\r
- return 0;\r
+ return GL_FALSE;\r
}\r
A->ref = slang_ref_forbid;\r
}\r
slang_assembly_typeinfo ti_after, ti_before;\r
\r
if (!slang_assembly_typeinfo_construct (&ti_after))\r
- return 0;\r
+ return GL_FALSE;\r
if (!slang_assembly_typeinfo_construct (&ti_before))\r
{\r
slang_assembly_typeinfo_destruct (&ti_after);\r
- return 0;\r
+ return GL_FALSE;\r
}\r
- if (!handle_field (&ti_after, &ti_before, A->file, op, ref != slang_ref_forbid, &A->flow, &A->space, &A->local, &swz,\r
- A->mach, A->atoms))\r
+ if (!handle_field (A, &ti_after, &ti_before, op, ref))\r
{\r
slang_assembly_typeinfo_destruct (&ti_after);\r
slang_assembly_typeinfo_destruct (&ti_before);\r
- return 0;\r
+ return GL_FALSE;\r
}\r
slang_assembly_typeinfo_destruct (&ti_after);\r
slang_assembly_typeinfo_destruct (&ti_before);\r
break;\r
case slang_oper_postincrement:\r
if (!assemble_function_call_name_dummyint (A, "++", op->children))\r
- return 0;\r
+ return GL_FALSE;\r
A->ref = slang_ref_forbid;\r
break;\r
case slang_oper_postdecrement:\r
if (!assemble_function_call_name_dummyint (A, "--", op->children))\r
- return 0;\r
+ return GL_FALSE;\r
A->ref = slang_ref_forbid;\r
break;\r
default:\r
- return 0;\r
+ return GL_FALSE;\r
}\r
\r
- A->swz = swz;\r
-\r
- return 1;\r
+ return GL_TRUE;\r
}\r
\r