[Mesa-dev,v2,8/9] glsl: test case generator cleanups

Submitted by Iago Toral Quiroga on Oct. 1, 2014, 6:35 a.m.

Details

Message ID 1412145345-3974-9-git-send-email-itoral@igalia.com
State New
Headers show

Not browsing as part of any series.

Commit Message

Iago Toral Quiroga Oct. 1, 2014, 6:35 a.m.
Mostly blank lines and comment formatting to ease readability as suggested by
Dylan Baker.
---
 src/glsl/tests/test_case_generator.py | 86 +++++++++++++++++++++++++++--------
 1 file changed, 66 insertions(+), 20 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/glsl/tests/test_case_generator.py b/src/glsl/tests/test_case_generator.py
index 5f550df..badbdbd 100644
--- a/src/glsl/tests/test_case_generator.py
+++ b/src/glsl/tests/test_case_generator.py
@@ -1,6 +1,6 @@ 
 # coding=utf-8
 #
-# Copyright © 2011 Intel Corporation
+# Copyright © 2011-2014 Intel Corporation
 #
 # Permission is hereby granted, free of charge, to any person obtaining a
 # copy of this software and associated documentation files (the "Software"),
@@ -36,6 +36,7 @@  def make_test_case(f_name, ret_type, body):
     Global declarations are automatically created for any undeclared
     variables that are referenced by the function.  All undeclared
     variables are assumed to be floats.
+
     """
     check_sexp(body)
     declarations = {}
@@ -67,7 +68,9 @@  def make_test_case(f_name, ret_type, body):
 # The following functions can be used to build expressions.
 
 def const_float(value):
-    """Create an expression representing the given floating point value."""
+    """Create an expression representing the given floating point value.
+
+    """
     return ['constant', 'float', ['{0:.6f}'.format(value)]]
 
 def const_bool(value):
@@ -75,31 +78,44 @@  def const_bool(value):
 
     If value is not a boolean, it is converted to a boolean.  So, for
     instance, const_bool(1) is equivalent to const_bool(True).
+
     """
     return ['constant', 'bool', ['{0}'.format(1 if value else 0)]]
 
 def const_vec4(val1, val2, val3, val4):
-    """Create an expression representing the given values as a vec4."""
+    """Create an expression representing the given values as a vec4.
+
+    """
     return ['constant', 'vec4', map(lambda x: '{0:.6f}'.format(x), [val1, val2, val3, val4])]
 
 def gt_zero(var_name):
-    """Create Construct the expression var_name > 0"""
+    """Create Construct the expression var_name > 0
+
+    """
     return ['expression', 'bool', '>', ['var_ref', var_name], const_float(0)]
 
 def min_(a, b, type):
-    """Create an expression min(a, b), of type 'type'"""
+    """Create an expression min(a, b), of type 'type'
+
+    """
     return ['expression', type, 'min', a, b]
 
 def max_(a, b, type):
-    """Create an expression max(a, b), of type 'type'"""
+    """Create an expression max(a, b), of type 'type'
+
+    """
     return ['expression', type, 'max', a, b]
 
 def minf(a, b):
-    """Helper function for min_(a, b, 'float')"""
+    """Helper function for min_(a, b, 'float')
+
+    """
     return min_(a, b, 'float')
 
 def maxf(a, b):
-    """Helper function for max_(a, b, 'float')"""
+    """Helper function for max_(a, b, 'float')
+
+    """
     return max_(a, b, 'float')
 
 # The following functions can be used to build complex control flow
@@ -108,18 +124,24 @@  def maxf(a, b):
 # be sequenced together using the '+' operator.
 
 def return_(value = None):
-    """Create a return statement."""
+    """Create a return statement.
+
+    """
     if value is not None:
         return [['return', value]]
     else:
         return [['return']]
 
 def break_():
-    """Create a break statement."""
+    """Create a break statement.
+
+    """
     return ['break']
 
 def continue_():
-    """Create a continue statement."""
+    """Create a continue statement.
+
+    """
     return ['continue']
 
 def simple_if(var_name, then_statements, else_statements = None):
@@ -132,6 +154,7 @@  def simple_if(var_name, then_statements, else_statements = None):
     }
 
     else_statements may be omitted.
+
     """
     if else_statements is None:
         else_statements = []
@@ -140,8 +163,8 @@  def simple_if(var_name, then_statements, else_statements = None):
     return [['if', gt_zero(var_name), then_statements, else_statements]]
 
 def loop(statements):
-    """Create a loop containing the given statements as its loop
-    body.
+    """Create a loop containing the given statements as its loop body.
+
     """
     check_sexp(statements)
     return [['loop', statements]]
@@ -150,6 +173,7 @@  def declare(var_type, var_name, decltype):
     """Create a declaration of the form
 
     (declare (<decltype>) <var_type> <var_name>)
+
     """
     return [['declare', [decltype], var_type, var_name]]
 
@@ -157,19 +181,24 @@  def declare_temp(var_type, var_name):
     """Create a declaration of the form
 
     (declare (temporary) <var_type> <var_name)
+
     """
     return declare(var_type, var_name, 'temporary')
 
 def assign(var_name, mask, value):
-    """Create a statement that assigns <value> to the variable <var_name>. The
-    assignment uses <mask> (a string) as the write mask.
+    """Create a statement that assigns <value> to the variable <var_name>.
+
+    The assignment uses <mask> (a string) as the write mask.
+
     """
     check_sexp(value)
     return [['assign', [mask], ['var_ref', var_name], value]]
 
 def assign_x(var_name, value):
-    """Create a statement that assigns <value> to the variable
-    <var_name>.  The assignment uses the mask (x).
+    """Create a statement that assigns <value> to the variable <var_name>.
+
+    The assignment uses the mask (x).
+
     """
     return assign(var_name, 'x', value)
 
@@ -189,6 +218,7 @@  def complex_if(var_prefix, statements):
 
     All variables used in the if statement are prefixed with
     var_prefix.  This can be used to ensure uniqueness.
+
     """
     check_sexp(statements)
     return simple_if(var_prefix + 'a', simple_if(var_prefix + 'b', statements))
@@ -196,6 +226,7 @@  def complex_if(var_prefix, statements):
 def declare_execute_flag():
     """Create the statements that lower_jumps.cpp uses to declare and
     initialize the temporary boolean execute_flag.
+
     """
     return declare_temp('bool', 'execute_flag') + \
         assign_x('execute_flag', const_bool(True))
@@ -203,20 +234,23 @@  def declare_execute_flag():
 def declare_return_flag():
     """Create the statements that lower_jumps.cpp uses to declare and
     initialize the temporary boolean return_flag.
+
     """
     return declare_temp('bool', 'return_flag') + \
         assign_x('return_flag', const_bool(False))
 
 def declare_return_value():
     """Create the statements that lower_jumps.cpp uses to declare and
-    initialize the temporary variable return_value.  Assume that
+    initialize the temporary variable return_value. Assume that
     return_value is a float.
+
     """
     return declare_temp('float', 'return_value')
 
 def declare_break_flag():
     """Create the statements that lower_jumps.cpp uses to declare and
     initialize the temporary boolean break_flag.
+
     """
     return declare_temp('bool', 'break_flag') + \
         assign_x('break_flag', const_bool(False))
@@ -225,6 +259,7 @@  def lowered_return_simple(value = None):
     """Create the statements that lower_jumps.cpp lowers a return
     statement to, in situations where it does not need to clear the
     execute flag.
+
     """
     if value:
         result = assign_x('return_value', value)
@@ -236,6 +271,7 @@  def lowered_return(value = None):
     """Create the statements that lower_jumps.cpp lowers a return
     statement to, in situations where it needs to clear the execute
     flag.
+
     """
     return lowered_return_simple(value) + \
         assign_x('execute_flag', const_bool(False))
@@ -243,6 +279,7 @@  def lowered_return(value = None):
 def lowered_continue():
     """Create the statement that lower_jumps.cpp lowers a continue
     statement to.
+
     """
     return assign_x('execute_flag', const_bool(False))
 
@@ -250,6 +287,7 @@  def lowered_break_simple():
     """Create the statement that lower_jumps.cpp lowers a break
     statement to, in situations where it does not need to clear the
     execute flag.
+
     """
     return assign_x('break_flag', const_bool(True))
 
@@ -257,12 +295,14 @@  def lowered_break():
     """Create the statement that lower_jumps.cpp lowers a break
     statement to, in situations where it needs to clear the execute
     flag.
+
     """
     return lowered_break_simple() + assign_x('execute_flag', const_bool(False))
 
 def if_execute_flag(statements):
     """Wrap statements in an if test so that they will only execute if
     execute_flag is True.
+
     """
     check_sexp(statements)
     return [['if', ['var_ref', 'execute_flag'], statements, []]]
@@ -270,6 +310,7 @@  def if_execute_flag(statements):
 def if_not_return_flag(statements):
     """Wrap statements in an if test so that they will only execute if
     return_flag is False.
+
     """
     check_sexp(statements)
     return [['if', ['var_ref', 'return_flag'], [], statements]]
@@ -277,18 +318,21 @@  def if_not_return_flag(statements):
 def final_return():
     """Create the return statement that lower_jumps.cpp places at the
     end of a function when lowering returns.
+
     """
     return [['return', ['var_ref', 'return_value']]]
 
 def final_break():
     """Create the conditional break statement that lower_jumps.cpp
     places at the end of a function when lowering breaks.
+
     """
     return [['if', ['var_ref', 'break_flag'], break_(), []]]
 
 def bash_quote(*args):
     """Quote the arguments appropriately so that bash will understand
     each argument as a single word.
+
     """
     def quote_word(word):
         for c in word:
@@ -299,11 +343,13 @@  def bash_quote(*args):
                 return "''"
             return word
         return "'{0}'".format(word.replace("'", "'\"'\"'"))
+
     return ' '.join(quote_word(word) for word in args)
 
 def create_test_case(doc_string, input_sexp, expected_sexp, test_name, optimization):
-    """Create a test case that verifies that the given optimization pass transforms
-    the given code in the expected way.
+    """Create a test case that verifies that the given optimization pass
+    transforms the given code in the expected way.
+
     """
     doc_lines = [line.strip() for line in doc_string.splitlines()]
     doc_string = ''.join('# {0}\n'.format(line) for line in doc_lines if line != '')