void
_mesa_glsl_read_ir(_mesa_glsl_parse_state *state, exec_list *instructions,
- const char *src)
+ const char *src, bool scan_for_protos)
{
s_expression *expr = s_expression::read_expression(state, src);
if (expr == NULL) {
return;
}
- scan_for_prototypes(state, instructions, expr);
- if (state->error)
- return;
+ if (scan_for_protos) {
+ scan_for_prototypes(state, instructions, expr);
+ if (state->error)
+ return;
+ }
read_instructions(state, instructions, expr, NULL);
talloc_free(expr);
return NULL;
}
- return glsl_type::get_array_instance(st, base_type, size->value());
+ return glsl_type::get_array_instance(base_type, size->value());
} else if (strcmp(type_sym->value(), "struct") == 0) {
assert(false); // FINISHME
} else {
read_function(_mesa_glsl_parse_state *st, s_list *list, bool skip_body)
{
void *ctx = st;
+ bool added = false;
if (list->length() < 3) {
ir_read_error(st, list, "Expected (function <name> (signature ...) ...)");
return NULL;
ir_function *f = st->symbols->get_function(name->value());
if (f == NULL) {
f = new(ctx) ir_function(name->value());
- bool added = st->symbols->add_function(f->name, f);
+ f->is_builtin = true;
+ added = st->symbols->add_function(f->name, f);
assert(added);
}
read_function_sig(st, f, siglist, skip_body);
}
- return f;
+ return added ? f : NULL;
}
static void
}
ir_function_signature *sig = f->exact_matching_signature(&hir_parameters);
- if (sig != NULL) {
+ if (sig == NULL && skip_body) {
+ /* If scanning for prototypes, generate a new signature. */
+ sig = new(ctx) ir_function_signature(return_type);
+ f->add_signature(sig);
+ } else if (sig != NULL) {
const char *badvar = sig->qualifiers_match(&hir_parameters);
if (badvar != NULL) {
ir_read_error(st, list, "function `%s' parameter `%s' qualifiers "
return;
}
} else {
- sig = new(ctx) ir_function_signature(return_type);
- f->add_signature(sig);
+ /* No prototype for this body exists - skip it. */
+ st->symbols->pop_scope();
+ return;
}
+ assert(sig != NULL);
sig->replace_parameters(&hir_parameters);
- if (!skip_body) {
+ if (!skip_body && !body_list->subexpressions.is_empty()) {
if (sig->is_defined) {
ir_read_error(st, list, "function %s redefined", f->name);
return;
foreach_iter(exec_list_iterator, it, list->subexpressions) {
s_expression *sub = (s_expression*) it.get();
ir_instruction *ir = read_instruction(st, sub, loop_ctx);
- if (ir == NULL) {
- ir_read_error(st, sub, "Invalid instruction.\n");
- return;
- }
- instructions->push_tail(ir);
+ if (ir != NULL)
+ instructions->push_tail(ir);
}
}
}
s_list *list = SX_AS_LIST(expr);
- if (list == NULL || list->subexpressions.is_empty())
+ if (list == NULL || list->subexpressions.is_empty()) {
+ ir_read_error(st, expr, "Invalid instruction.\n");
return NULL;
+ }
s_symbol *tag = SX_AS_SYMBOL(list->subexpressions.get_head());
if (tag == NULL) {
ir_instruction *inst = NULL;
if (strcmp(tag->value(), "declare") == 0) {
inst = read_declaration(st, list);
+ } else if (strcmp(tag->value(), "assign") == 0) {
+ inst = read_assignment(st, list);
} else if (strcmp(tag->value(), "if") == 0) {
inst = read_if(st, list, loop_ctx);
} else if (strcmp(tag->value(), "loop") == 0) {
return NULL;
}
- ir_variable *var = new(ctx) ir_variable(type, var_name->value());
+ ir_variable *var = new(ctx) ir_variable(type, var_name->value(),
+ ir_var_auto);
foreach_iter(exec_list_iterator, it, quals->subexpressions) {
s_symbol *qualifier = SX_AS_SYMBOL(it.get());
return rvalue;
else if (strcmp(tag->value(), "swiz") == 0) {
rvalue = read_swizzle(st, list);
- } else if (strcmp(tag->value(), "assign") == 0) {
- rvalue = read_assignment(st, list);
} else if (strcmp(tag->value(), "expression") == 0) {
rvalue = read_expression(st, list);
} else if (strcmp(tag->value(), "call") == 0) {
return NULL;
}
- const ir_function_signature *callee = f->matching_signature(¶meters);
+ ir_function_signature *callee = f->matching_signature(¶meters);
if (callee == NULL) {
ir_read_error(st, list, "couldn't find matching signature for function "
"%s", name->value());
{
void *ctx = st;
if (list->length() != 3) {
- ir_read_error(st, list, "expected (constant <type> (<num> ... <num>))");
+ ir_read_error(st, list, "expected (constant <type> (...))");
return NULL;
}
s_list *values = SX_AS_LIST(type_expr->next);
if (values == NULL) {
- ir_read_error(st, list, "expected (constant <type> (<num> ... <num>))");
+ ir_read_error(st, list, "expected (constant <type> (...))");
return NULL;
}
+ if (type->is_array()) {
+ const unsigned elements_supplied = values->length();
+ if (elements_supplied != type->length) {
+ ir_read_error(st, values, "expected exactly %u array elements, "
+ "given %u", type->length, elements_supplied);
+ return NULL;
+ }
+
+ exec_list elements;
+ foreach_iter(exec_list_iterator, it, values->subexpressions) {
+ s_expression *expr = (s_expression *) it.get();
+ s_list *elt = SX_AS_LIST(expr);
+ if (elt == NULL) {
+ ir_read_error(st, expr, "expected (constant ...) array element");
+ return NULL;
+ }
+
+ ir_constant *ir_elt = read_constant(st, elt);
+ if (ir_elt == NULL)
+ return NULL;
+ elements.push_tail(ir_elt);
+ }
+ return new(ctx) ir_constant(type, &elements);
+ }
+
const glsl_type *const base_type = type->get_base_type();
- ir_constant_data data;
+ ir_constant_data data = { { 0 } };
// Read in list of values (at most 16).
int k = 0;