glsl: Use a new foreach_two_lists macro for walking two lists at once.

When handling function calls, we often want to walk through the list of
formal parameters and list of actual parameters at the same time.
(Both are guaranteed to be the same length.)

Previously, we used a pattern of:

   exec_list_iterator 1st_iter = <1st list>.iterator();
   foreach_iter(exec_list_iterator, 2nd_iter, <2nd list>) {
      ...
      1st_iter.next();
   }

This was awkward, since you had to manually iterate through one of
the two lists.

This patch introduces a foreach_two_lists macro which safely walks
through two lists at the same time, so you can simply do:

   foreach_two_lists(1st_node, <1st list>, 2nd_node, <2nd list>) {
      ...
   }

v2: Rename macro from foreach_list2 to foreach_two_lists, as suggested
    by Ian Romanick.

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Matt Turner <mattst88@gmail.com>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
This commit is contained in:
Kenneth Graunke
2014-01-10 16:39:17 -08:00
parent 02ff2a2758
commit 48d0faaa43
12 changed files with 73 additions and 92 deletions

View File

@@ -293,15 +293,10 @@ generate_call(exec_list *instructions, ir_function_signature *sig,
* call takes place. Since we haven't emitted the call yet, we'll place
* the post-call conversions in a temporary exec_list, and emit them later.
*/
exec_list_iterator actual_iter = actual_parameters->iterator();
exec_list_iterator formal_iter = sig->parameters.iterator();
while (actual_iter.has_next()) {
ir_rvalue *actual = (ir_rvalue *) actual_iter.get();
ir_variable *formal = (ir_variable *) formal_iter.get();
assert(actual != NULL);
assert(formal != NULL);
foreach_two_lists(formal_node, &sig->parameters,
actual_node, actual_parameters) {
ir_rvalue *actual = (ir_rvalue *) actual_node;
ir_variable *formal = (ir_variable *) formal_node;
if (formal->type->is_numeric() || formal->type->is_boolean()) {
switch (formal->data.mode) {
@@ -323,9 +318,6 @@ generate_call(exec_list *instructions, ir_function_signature *sig,
break;
}
}
actual_iter.next();
formal_iter.next();
}
/* If the function call is a constant expression, don't generate any