static slang_ir_node *
_slang_gen_function_call(slang_assemble_ctx *A, slang_function *fun,
- slang_operation *oper, slang_operation *dest)
+ slang_operation *oper, slang_operation *dest)
{
slang_ir_node *n;
slang_operation *inlined;
slang_operation_copy(&select->children[1], &oper->children[1]);
select->children[2].type = slang_oper_literal_bool;
ASSIGN_4V(select->children[2].literal, 0, 0, 0, 0);
+ select->children[2].literal_size = 2;
n = _slang_gen_select(A, select);
select->children[1].type = slang_oper_literal_bool;
ASSIGN_4V(select->children[2].literal, 1, 1, 1, 1);
slang_operation_copy(&select->children[2], &oper->children[1]);
+ select->children[2].literal_size = 2;
n = _slang_gen_select(A, select);
if (!var) {
RETURN_ERROR2("Undefined variable:", varName, 0);
}
+#if 0
/* XXX make copy of this initializer? */
+ {
+ slang_operation dup;
+ slang_operation_construct(&dup);
+ slang_operation_copy(&dup, v->initializer);
+ _slang_simplify(&dup, &A->space, A->atoms);
+ rhs = _slang_gen_operation(A, &dup);
+ }
+#else
_slang_simplify(v->initializer, &A->space, A->atoms);
rhs = _slang_gen_operation(A, v->initializer);
+#endif
assert(rhs);
init = new_node(IR_MOVE, var, rhs);
/*
isBool[i] = (oper->children[i].type == slang_oper_literal_bool);
}
- if (n == 2 && isFloat[0] && isFloat[1]) {
+ if (oper->num_children == 2 && isFloat[0] && isFloat[1]) {
/* probably simple arithmetic */
switch (oper->type) {
case slang_oper_add:
oper->literal[i]
= oper->children[0].literal[i] + oper->children[1].literal[i];
}
+ oper->literal_size = oper->children[0].literal_size;
slang_operation_destruct(oper);
oper->type = slang_oper_literal_float;
return;
oper->literal[i]
= oper->children[0].literal[i] - oper->children[1].literal[i];
}
+ oper->literal_size = oper->children[0].literal_size;
slang_operation_destruct(oper);
oper->type = slang_oper_literal_float;
return;
oper->literal[i]
= oper->children[0].literal[i] * oper->children[1].literal[i];
}
+ oper->literal_size = oper->children[0].literal_size;
slang_operation_destruct(oper);
oper->type = slang_oper_literal_float;
return;
oper->literal[i]
= oper->children[0].literal[i] / oper->children[1].literal[i];
}
+ oper->literal_size = oper->children[0].literal_size;
slang_operation_destruct(oper);
oper->type = slang_oper_literal_float;
return;
}
}
- if (n == 1 && isFloat[0]) {
+ if (oper->num_children == 1 && isFloat[0]) {
switch (oper->type) {
case slang_oper_minus:
for (i = 0; i < 4; i++) {
oper->literal[i] = -oper->children[0].literal[i];
}
+ oper->literal_size = oper->children[0].literal_size;
slang_operation_destruct(oper);
oper->type = slang_oper_literal_float;
return;
case slang_oper_plus:
COPY_4V(oper->literal, oper->children[0].literal);
+ oper->literal_size = oper->children[0].literal_size;
slang_operation_destruct(oper);
oper->type = slang_oper_literal_float;
return;
}
}
- if (n == 2 && isBool[0] && isBool[1]) {
+ if (oper->num_children == 2 && isBool[0] && isBool[1]) {
/* simple boolean expression */
switch (oper->type) {
case slang_oper_logicaland:
const GLint b = oper->children[1].literal[i] ? 1 : 0;
oper->literal[i] = (GLfloat) (a && b);
}
+ oper->literal_size = oper->children[0].literal_size;
slang_operation_destruct(oper);
oper->type = slang_oper_literal_bool;
return;
const GLint b = oper->children[1].literal[i] ? 1 : 0;
oper->literal[i] = (GLfloat) (a || b);
}
+ oper->literal_size = oper->children[0].literal_size;
slang_operation_destruct(oper);
oper->type = slang_oper_literal_bool;
return;
const GLint b = oper->children[1].literal[i] ? 1 : 0;
oper->literal[i] = (GLfloat) (a ^ b);
}
+ oper->literal_size = oper->children[0].literal_size;
slang_operation_destruct(oper);
oper->type = slang_oper_literal_bool;
return;
}
}
- if (n == 4 && isFloat[0] && isFloat[1] && isFloat[2] && isFloat[3]) {
+ if (oper->num_children == 4
+ && isFloat[0] && isFloat[1] && isFloat[2] && isFloat[3]) {
/* vec4(flt, flt, flt, flt) constructor */
if (oper->type == slang_oper_call) {
if (strcmp((char *) oper->a_id, "vec4") == 0) {
oper->literal[1] = oper->children[1].literal[0];
oper->literal[2] = oper->children[2].literal[0];
oper->literal[3] = oper->children[3].literal[0];
+ oper->literal_size = 4;
slang_operation_destruct(oper);
oper->type = slang_oper_literal_float;
return;
}
}
- if (n == 3 && isFloat[0] && isFloat[1] && isFloat[2]) {
+ if (oper->num_children == 3 && isFloat[0] && isFloat[1] && isFloat[2]) {
/* vec3(flt, flt, flt) constructor */
if (oper->type == slang_oper_call) {
if (strcmp((char *) oper->a_id, "vec3") == 0) {
oper->literal[1] = oper->children[1].literal[0];
oper->literal[2] = oper->children[2].literal[0];
oper->literal[3] = oper->literal[2];
+ oper->literal_size = 3;
slang_operation_destruct(oper);
oper->type = slang_oper_literal_float;
return;
}
}
- if (n == 2 && isFloat[0] && isFloat[1]) {
- /* vec4(flt, flt) constructor */
+ if (oper->num_children == 2 && isFloat[0] && isFloat[1]) {
+ /* vec2(flt, flt) constructor */
if (oper->type == slang_oper_call) {
if (strcmp((char *) oper->a_id, "vec2") == 0) {
+ printf("SIMPLIFY vec2 constructor scope = %p\n",
+ (void*) oper->locals);
oper->literal[0] = oper->children[0].literal[0];
oper->literal[1] = oper->children[1].literal[0];
oper->literal[2] = oper->literal[1];
oper->literal[3] = oper->literal[1];
+ oper->literal_size = 2;
slang_operation_destruct(oper); /* XXX oper->locals goes NULL! */
oper->type = slang_oper_literal_float;
+ assert(oper->num_children == 0);
return;
}
}
return GL_FALSE;
break;
case slang_oper_literal_bool:
+ if (op->literal_size == 1)
+ ti->spec.type = slang_spec_bool;
+ else if (op->literal_size == 2)
+ ti->spec.type = slang_spec_bvec2;
+ else if (op->literal_size == 3)
+ ti->spec.type = slang_spec_bvec3;
+ else if (op->literal_size == 4)
+ ti->spec.type = slang_spec_bvec4;
+ else {
+ _mesa_problem(NULL,
+ "Unexpected bool literal_size %d in _slang_typeof_operation()",
+ op->literal_size);
+ ti->spec.type = slang_spec_bool;
+ }
+ break;
case slang_oper_logicalor:
case slang_oper_logicalxor:
case slang_oper_logicaland:
ti->spec.type = slang_spec_bool;
break;
case slang_oper_literal_int:
- ti->spec.type = slang_spec_int;
+ if (op->literal_size == 1)
+ ti->spec.type = slang_spec_int;
+ else if (op->literal_size == 2)
+ ti->spec.type = slang_spec_ivec2;
+ else if (op->literal_size == 3)
+ ti->spec.type = slang_spec_ivec3;
+ else if (op->literal_size == 4)
+ ti->spec.type = slang_spec_ivec4;
+ else {
+ _mesa_problem(NULL,
+ "Unexpected int literal_size %d in _slang_typeof_operation()",
+ op->literal_size);
+ ti->spec.type = slang_spec_int;
+ }
break;
case slang_oper_literal_float:
- ti->spec.type = slang_spec_float;
+ if (op->literal_size == 1)
+ ti->spec.type = slang_spec_float;
+ else if (op->literal_size == 2)
+ ti->spec.type = slang_spec_vec2;
+ else if (op->literal_size == 3)
+ ti->spec.type = slang_spec_vec3;
+ else if (op->literal_size == 4)
+ ti->spec.type = slang_spec_vec4;
+ else {
+ _mesa_problem(NULL,
+ "Unexpected float literal_size %d in _slang_typeof_operation()",
+ op->literal_size);
+ ti->spec.type = slang_spec_float;
+ }
break;
case slang_oper_identifier:
{