[Mesa-dev] [PATCH 0/6] glsl: Add support for switch statements
zen3d.linux at gmail.com
Tue Jun 28 18:06:13 PDT 2011
Comments at the end (where they are supposed to be :).
On 06/17/2011 05:54 PM, Dan McCabe wrote:
> There are three changes from the patch set I published on 6/15:
> 1) Removed IR pointers from AST classes and moved them to
> 2) Manage the new IR in a stack-like manner to properly handle
> nesting, and
> 3) Squash 6/7 and 7/7 together, since both deal with IR generation
> #1 was in response to the concerns Kenneth expressed from his code
> review on 6/15 about embedding IR data into AST structures.
> #2 was need as a consequence of #1 to support nested switch statements
> #3 is a minor cosmetic change that merges the final implicit break IR
> insertion into the larger collection of IR changes.
> cheers, danm
> On 06/17/2011 05:43 PM, Dan McCabe wrote:
>> This patch set adds support for switch statements to the GLSL
>> compiler. We
>> modify the grammar for the compiler with productions for switch
>> and case labels, while adding supporting supporting productions not
>> present. New AST classes are defined to support those productions.
>> with our apporach no new IR is needed, allowing us to leverage all
>> optimizations and code generation.
A foolish inconsistency is the hobgoblin of small minds.
Anyway, I just sent out pass 3 of this patch set. It now consists of 5
(not 6) pieces. Parts 4/6 and 5/6 got mashed together into 4/5, but
that's not a big deal since the former part 5/6 was simply fleshing out
print support for the AST.
This change set has mostly minor, cosmetic changes. UNTIL part 5/5. The
major issue that idr identified concerning nested loops should now be
resolved. Basically, the loop model for switch statements got tossed
into the waste basket. The reason I used loops in the first place was to
leverage code generation for break statements. Bad idea. I now generate
different code for break statements that are under the influence of a
Now, the switch statement is translated into straightforward
In addition to maintaining internal state for the cached test value and
the fall through state, I now additionally maintain a break state, which
is initialized to false and set to true whenever a break stmt is
executed. Prior to executing any case statements (the statements
following a case label), the fallthru state is reset if the break state
is enabled, inhibiting entry of the case statement block (which is
guarded by the fallthru state).
A couple of other changes were replacing the if/then/elses used to
maintain the fallthru and break states with conditional assignments.
This actually simplified both the src code and the generated code.
As always, feedback is requested.
More information about the mesa-dev