Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Copyright © 2008, 2009 Intel Corporation
  3.  *
  4.  * Permission is hereby granted, free of charge, to any person obtaining a
  5.  * copy of this software and associated documentation files (the "Software"),
  6.  * to deal in the Software without restriction, including without limitation
  7.  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8.  * and/or sell copies of the Software, and to permit persons to whom the
  9.  * Software is furnished to do so, subject to the following conditions:
  10.  *
  11.  * The above copyright notice and this permission notice (including the next
  12.  * paragraph) shall be included in all copies or substantial portions of the
  13.  * Software.
  14.  *
  15.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16.  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  18.  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19.  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20.  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  21.  * DEALINGS IN THE SOFTWARE.
  22.  */
  23. #include <stdio.h>
  24. #include <stdarg.h>
  25. #include <string.h>
  26. #include <assert.h>
  27.  
  28. extern "C" {
  29. #include "main/core.h" /* for struct gl_context */
  30. }
  31.  
  32. #include "ralloc.h"
  33. #include "ast.h"
  34. #include "glsl_parser_extras.h"
  35. #include "glsl_parser.h"
  36. #include "ir_optimization.h"
  37. #include "loop_analysis.h"
  38.  
  39. _mesa_glsl_parse_state::_mesa_glsl_parse_state(struct gl_context *ctx,
  40.                                                GLenum target, void *mem_ctx)
  41. {
  42.    switch (target) {
  43.    case GL_VERTEX_SHADER:   this->target = vertex_shader; break;
  44.    case GL_FRAGMENT_SHADER: this->target = fragment_shader; break;
  45.    case GL_GEOMETRY_SHADER: this->target = geometry_shader; break;
  46.    }
  47.  
  48.    this->scanner = NULL;
  49.    this->translation_unit.make_empty();
  50.    this->symbols = new(mem_ctx) glsl_symbol_table;
  51.    this->info_log = ralloc_strdup(mem_ctx, "");
  52.    this->error = false;
  53.    this->loop_or_switch_nesting = NULL;
  54.  
  55.    /* Set default language version and extensions */
  56.    this->language_version = 110;
  57.    this->es_shader = false;
  58.    this->ARB_texture_rectangle_enable = true;
  59.  
  60.    /* OpenGL ES 2.0 has different defaults from desktop GL. */
  61.    if (ctx->API == API_OPENGLES2) {
  62.       this->language_version = 100;
  63.       this->es_shader = true;
  64.       this->ARB_texture_rectangle_enable = false;
  65.    }
  66.  
  67.    this->extensions = &ctx->Extensions;
  68.  
  69.    this->Const.MaxLights = ctx->Const.MaxLights;
  70.    this->Const.MaxClipPlanes = ctx->Const.MaxClipPlanes;
  71.    this->Const.MaxTextureUnits = ctx->Const.MaxTextureUnits;
  72.    this->Const.MaxTextureCoords = ctx->Const.MaxTextureCoordUnits;
  73.    this->Const.MaxVertexAttribs = ctx->Const.VertexProgram.MaxAttribs;
  74.    this->Const.MaxVertexUniformComponents = ctx->Const.VertexProgram.MaxUniformComponents;
  75.    this->Const.MaxVaryingFloats = ctx->Const.MaxVarying * 4;
  76.    this->Const.MaxVertexTextureImageUnits = ctx->Const.MaxVertexTextureImageUnits;
  77.    this->Const.MaxCombinedTextureImageUnits = ctx->Const.MaxCombinedTextureImageUnits;
  78.    this->Const.MaxTextureImageUnits = ctx->Const.MaxTextureImageUnits;
  79.    this->Const.MaxFragmentUniformComponents = ctx->Const.FragmentProgram.MaxUniformComponents;
  80.  
  81.    this->Const.MaxDrawBuffers = ctx->Const.MaxDrawBuffers;
  82.  
  83.    /* Note: Once the OpenGL 3.0 'forward compatible' context or the OpenGL 3.2
  84.     * Core context is supported, this logic will need change.  Older versions of
  85.     * GLSL are no longer supported outside the compatibility contexts of 3.x.
  86.     */
  87.    this->Const.GLSL_100ES = (ctx->API == API_OPENGLES2)
  88.       || ctx->Extensions.ARB_ES2_compatibility;
  89.    this->Const.GLSL_110 = (ctx->API == API_OPENGL);
  90.    this->Const.GLSL_120 = (ctx->API == API_OPENGL)
  91.       && (ctx->Const.GLSLVersion >= 120);
  92.    this->Const.GLSL_130 = (ctx->API == API_OPENGL)
  93.       && (ctx->Const.GLSLVersion >= 130);
  94.  
  95.    const unsigned lowest_version =
  96.       (ctx->API == API_OPENGLES2) || ctx->Extensions.ARB_ES2_compatibility
  97.       ? 100 : 110;
  98.    const unsigned highest_version =
  99.       (ctx->API == API_OPENGL) ? ctx->Const.GLSLVersion : 100;
  100.    char *supported = (char *) ralloc_context(this);
  101.  
  102.    for (unsigned ver = lowest_version; ver <= highest_version; ver += 10) {
  103.       const char *const prefix = (ver == lowest_version)
  104.          ? ""
  105.          : ((ver == highest_version) ? ", and " : ", ");
  106.  
  107.       ralloc_asprintf_append(& supported, "%s%d.%02d%s",
  108.                              prefix,
  109.                              ver / 100, ver % 100,
  110.                              (ver == 100) ? " ES" : "");
  111.    }
  112.  
  113.    this->supported_version_string = supported;
  114. }
  115.  
  116. const char *
  117. _mesa_glsl_shader_target_name(enum _mesa_glsl_parser_targets target)
  118. {
  119.    switch (target) {
  120.    case vertex_shader:   return "vertex";
  121.    case fragment_shader: return "fragment";
  122.    case geometry_shader: return "geometry";
  123.    }
  124.  
  125.    assert(!"Should not get here.");
  126.    return "unknown";
  127. }
  128.  
  129.  
  130. void
  131. _mesa_glsl_error(YYLTYPE *locp, _mesa_glsl_parse_state *state,
  132.                  const char *fmt, ...)
  133. {
  134.    va_list ap;
  135.  
  136.    state->error = true;
  137.  
  138.    assert(state->info_log != NULL);
  139.    ralloc_asprintf_append(&state->info_log, "%u:%u(%u): error: ",
  140.                                             locp->source,
  141.                                             locp->first_line,
  142.                                             locp->first_column);
  143.    va_start(ap, fmt);
  144.    ralloc_vasprintf_append(&state->info_log, fmt, ap);
  145.    va_end(ap);
  146.    ralloc_strcat(&state->info_log, "\n");
  147. }
  148.  
  149.  
  150. void
  151. _mesa_glsl_warning(const YYLTYPE *locp, _mesa_glsl_parse_state *state,
  152.                    const char *fmt, ...)
  153. {
  154.    va_list ap;
  155.  
  156.    assert(state->info_log != NULL);
  157.    ralloc_asprintf_append(&state->info_log, "%u:%u(%u): warning: ",
  158.                                             locp->source,
  159.                                             locp->first_line,
  160.                                             locp->first_column);
  161.    va_start(ap, fmt);
  162.    ralloc_vasprintf_append(&state->info_log, fmt, ap);
  163.    va_end(ap);
  164.    ralloc_strcat(&state->info_log, "\n");
  165. }
  166.  
  167.  
  168. bool
  169. _mesa_glsl_process_extension(const char *name, YYLTYPE *name_locp,
  170.                              const char *behavior, YYLTYPE *behavior_locp,
  171.                              _mesa_glsl_parse_state *state)
  172. {
  173.    enum {
  174.       extension_disable,
  175.       extension_enable,
  176.       extension_require,
  177.       extension_warn
  178.    } ext_mode;
  179.  
  180.    if (strcmp(behavior, "warn") == 0) {
  181.       ext_mode = extension_warn;
  182.    } else if (strcmp(behavior, "require") == 0) {
  183.       ext_mode = extension_require;
  184.    } else if (strcmp(behavior, "enable") == 0) {
  185.       ext_mode = extension_enable;
  186.    } else if (strcmp(behavior, "disable") == 0) {
  187.       ext_mode = extension_disable;
  188.    } else {
  189.       _mesa_glsl_error(behavior_locp, state,
  190.                        "Unknown extension behavior `%s'",
  191.                        behavior);
  192.       return false;
  193.    }
  194.  
  195.    bool unsupported = false;
  196.  
  197.    if (strcmp(name, "all") == 0) {
  198.       if ((ext_mode == extension_enable) || (ext_mode == extension_require)) {
  199.          _mesa_glsl_error(name_locp, state, "Cannot %s all extensions",
  200.                           (ext_mode == extension_enable)
  201.                           ? "enable" : "require");
  202.          return false;
  203.       }
  204.    } else if (strcmp(name, "GL_ARB_draw_buffers") == 0) {
  205.       /* This extension is only supported in fragment shaders.
  206.        */
  207.       if (state->target != fragment_shader) {
  208.          unsupported = true;
  209.       } else {
  210.          state->ARB_draw_buffers_enable = (ext_mode != extension_disable);
  211.          state->ARB_draw_buffers_warn = (ext_mode == extension_warn);
  212.       }
  213.    } else if (strcmp(name, "GL_ARB_explicit_attrib_location") == 0) {
  214.       state->ARB_explicit_attrib_location_enable =
  215.          (ext_mode != extension_disable);
  216.       state->ARB_explicit_attrib_location_warn =
  217.          (ext_mode == extension_warn);
  218.  
  219.       unsupported = !state->extensions->ARB_explicit_attrib_location;
  220.    } else if (strcmp(name, "GL_ARB_fragment_coord_conventions") == 0) {
  221.       state->ARB_fragment_coord_conventions_enable =
  222.          (ext_mode != extension_disable);
  223.       state->ARB_fragment_coord_conventions_warn =
  224.          (ext_mode == extension_warn);
  225.  
  226.       unsupported = !state->extensions->ARB_fragment_coord_conventions;
  227.    } else if (strcmp(name, "GL_ARB_texture_rectangle") == 0) {
  228.       state->ARB_texture_rectangle_enable = (ext_mode != extension_disable);
  229.       state->ARB_texture_rectangle_warn = (ext_mode == extension_warn);
  230.    } else if (strcmp(name, "GL_EXT_texture_array") == 0) {
  231.       state->EXT_texture_array_enable = (ext_mode != extension_disable);
  232.       state->EXT_texture_array_warn = (ext_mode == extension_warn);
  233.  
  234.       unsupported = !state->extensions->EXT_texture_array;
  235.    } else if (strcmp(name, "GL_ARB_shader_stencil_export") == 0) {
  236.       if (state->target != fragment_shader) {
  237.          unsupported = true;
  238.       } else {
  239.          state->ARB_shader_stencil_export_enable = (ext_mode != extension_disable);
  240.          state->ARB_shader_stencil_export_warn = (ext_mode == extension_warn);
  241.          unsupported = !state->extensions->ARB_shader_stencil_export;
  242.       }
  243.    } else {
  244.       unsupported = true;
  245.    }
  246.  
  247.    if (unsupported) {
  248.       static const char *const fmt = "extension `%s' unsupported in %s shader";
  249.  
  250.       if (ext_mode == extension_require) {
  251.          _mesa_glsl_error(name_locp, state, fmt,
  252.                           name, _mesa_glsl_shader_target_name(state->target));
  253.          return false;
  254.       } else {
  255.          _mesa_glsl_warning(name_locp, state, fmt,
  256.                             name, _mesa_glsl_shader_target_name(state->target));
  257.       }
  258.    }
  259.  
  260.    return true;
  261. }
  262.  
  263. void
  264. _mesa_ast_type_qualifier_print(const struct ast_type_qualifier *q)
  265. {
  266.    if (q->flags.q.constant)
  267.       printf("const ");
  268.  
  269.    if (q->flags.q.invariant)
  270.       printf("invariant ");
  271.  
  272.    if (q->flags.q.attribute)
  273.       printf("attribute ");
  274.  
  275.    if (q->flags.q.varying)
  276.       printf("varying ");
  277.  
  278.    if (q->flags.q.in && q->flags.q.out)
  279.       printf("inout ");
  280.    else {
  281.       if (q->flags.q.in)
  282.          printf("in ");
  283.  
  284.       if (q->flags.q.out)
  285.          printf("out ");
  286.    }
  287.  
  288.    if (q->flags.q.centroid)
  289.       printf("centroid ");
  290.    if (q->flags.q.uniform)
  291.       printf("uniform ");
  292.    if (q->flags.q.smooth)
  293.       printf("smooth ");
  294.    if (q->flags.q.flat)
  295.       printf("flat ");
  296.    if (q->flags.q.noperspective)
  297.       printf("noperspective ");
  298. }
  299.  
  300.  
  301. void
  302. ast_node::print(void) const
  303. {
  304.    printf("unhandled node ");
  305. }
  306.  
  307.  
  308. ast_node::ast_node(void)
  309. {
  310.    this->location.source = 0;
  311.    this->location.line = 0;
  312.    this->location.column = 0;
  313. }
  314.  
  315.  
  316. static void
  317. ast_opt_array_size_print(bool is_array, const ast_expression *array_size)
  318. {
  319.    if (is_array) {
  320.       printf("[ ");
  321.  
  322.       if (array_size)
  323.          array_size->print();
  324.  
  325.       printf("] ");
  326.    }
  327. }
  328.  
  329.  
  330. void
  331. ast_compound_statement::print(void) const
  332. {
  333.    printf("{\n");
  334.    
  335.    foreach_list_const(n, &this->statements) {
  336.       ast_node *ast = exec_node_data(ast_node, n, link);
  337.       ast->print();
  338.    }
  339.  
  340.    printf("}\n");
  341. }
  342.  
  343.  
  344. ast_compound_statement::ast_compound_statement(int new_scope,
  345.                                                ast_node *statements)
  346. {
  347.    this->new_scope = new_scope;
  348.  
  349.    if (statements != NULL) {
  350.       this->statements.push_degenerate_list_at_head(&statements->link);
  351.    }
  352. }
  353.  
  354.  
  355. void
  356. ast_expression::print(void) const
  357. {
  358.    switch (oper) {
  359.    case ast_assign:
  360.    case ast_mul_assign:
  361.    case ast_div_assign:
  362.    case ast_mod_assign:
  363.    case ast_add_assign:
  364.    case ast_sub_assign:
  365.    case ast_ls_assign:
  366.    case ast_rs_assign:
  367.    case ast_and_assign:
  368.    case ast_xor_assign:
  369.    case ast_or_assign:
  370.       subexpressions[0]->print();
  371.       printf("%s ", operator_string(oper));
  372.       subexpressions[1]->print();
  373.       break;
  374.  
  375.    case ast_field_selection:
  376.       subexpressions[0]->print();
  377.       printf(". %s ", primary_expression.identifier);
  378.       break;
  379.  
  380.    case ast_plus:
  381.    case ast_neg:
  382.    case ast_bit_not:
  383.    case ast_logic_not:
  384.    case ast_pre_inc:
  385.    case ast_pre_dec:
  386.       printf("%s ", operator_string(oper));
  387.       subexpressions[0]->print();
  388.       break;
  389.  
  390.    case ast_post_inc:
  391.    case ast_post_dec:
  392.       subexpressions[0]->print();
  393.       printf("%s ", operator_string(oper));
  394.       break;
  395.  
  396.    case ast_conditional:
  397.       subexpressions[0]->print();
  398.       printf("? ");
  399.       subexpressions[1]->print();
  400.       printf(": ");
  401.       subexpressions[1]->print();
  402.       break;
  403.  
  404.    case ast_array_index:
  405.       subexpressions[0]->print();
  406.       printf("[ ");
  407.       subexpressions[1]->print();
  408.       printf("] ");
  409.       break;
  410.  
  411.    case ast_function_call: {
  412.       subexpressions[0]->print();
  413.       printf("( ");
  414.  
  415.       foreach_list_const (n, &this->expressions) {
  416.          if (n != this->expressions.get_head())
  417.             printf(", ");
  418.  
  419.          ast_node *ast = exec_node_data(ast_node, n, link);
  420.          ast->print();
  421.       }
  422.  
  423.       printf(") ");
  424.       break;
  425.    }
  426.  
  427.    case ast_identifier:
  428.       printf("%s ", primary_expression.identifier);
  429.       break;
  430.  
  431.    case ast_int_constant:
  432.       printf("%d ", primary_expression.int_constant);
  433.       break;
  434.  
  435.    case ast_uint_constant:
  436.       printf("%u ", primary_expression.uint_constant);
  437.       break;
  438.  
  439.    case ast_float_constant:
  440.       printf("%f ", primary_expression.float_constant);
  441.       break;
  442.  
  443.    case ast_bool_constant:
  444.       printf("%s ",
  445.              primary_expression.bool_constant
  446.              ? "true" : "false");
  447.       break;
  448.  
  449.    case ast_sequence: {
  450.       printf("( ");
  451.       foreach_list_const(n, & this->expressions) {
  452.          if (n != this->expressions.get_head())
  453.             printf(", ");
  454.  
  455.          ast_node *ast = exec_node_data(ast_node, n, link);
  456.          ast->print();
  457.       }
  458.       printf(") ");
  459.       break;
  460.    }
  461.  
  462.    default:
  463.       assert(0);
  464.       break;
  465.    }
  466. }
  467.  
  468. ast_expression::ast_expression(int oper,
  469.                                ast_expression *ex0,
  470.                                ast_expression *ex1,
  471.                                ast_expression *ex2)
  472. {
  473.    this->oper = ast_operators(oper);
  474.    this->subexpressions[0] = ex0;
  475.    this->subexpressions[1] = ex1;
  476.    this->subexpressions[2] = ex2;
  477. }
  478.  
  479.  
  480. void
  481. ast_expression_statement::print(void) const
  482. {
  483.    if (expression)
  484.       expression->print();
  485.  
  486.    printf("; ");
  487. }
  488.  
  489.  
  490. ast_expression_statement::ast_expression_statement(ast_expression *ex) :
  491.    expression(ex)
  492. {
  493.    /* empty */
  494. }
  495.  
  496.  
  497. void
  498. ast_function::print(void) const
  499. {
  500.    return_type->print();
  501.    printf(" %s (", identifier);
  502.  
  503.    foreach_list_const(n, & this->parameters) {
  504.       ast_node *ast = exec_node_data(ast_node, n, link);
  505.       ast->print();
  506.    }
  507.  
  508.    printf(")");
  509. }
  510.  
  511.  
  512. ast_function::ast_function(void)
  513.    : is_definition(false), signature(NULL)
  514. {
  515.    /* empty */
  516. }
  517.  
  518.  
  519. void
  520. ast_fully_specified_type::print(void) const
  521. {
  522.    _mesa_ast_type_qualifier_print(& qualifier);
  523.    specifier->print();
  524. }
  525.  
  526.  
  527. void
  528. ast_parameter_declarator::print(void) const
  529. {
  530.    type->print();
  531.    if (identifier)
  532.       printf("%s ", identifier);
  533.    ast_opt_array_size_print(is_array, array_size);
  534. }
  535.  
  536.  
  537. void
  538. ast_function_definition::print(void) const
  539. {
  540.    prototype->print();
  541.    body->print();
  542. }
  543.  
  544.  
  545. void
  546. ast_declaration::print(void) const
  547. {
  548.    printf("%s ", identifier);
  549.    ast_opt_array_size_print(is_array, array_size);
  550.  
  551.    if (initializer) {
  552.       printf("= ");
  553.       initializer->print();
  554.    }
  555. }
  556.  
  557.  
  558. ast_declaration::ast_declaration(char *identifier, int is_array,
  559.                                  ast_expression *array_size,
  560.                                  ast_expression *initializer)
  561. {
  562.    this->identifier = identifier;
  563.    this->is_array = is_array;
  564.    this->array_size = array_size;
  565.    this->initializer = initializer;
  566. }
  567.  
  568.  
  569. void
  570. ast_declarator_list::print(void) const
  571. {
  572.    assert(type || invariant);
  573.  
  574.    if (type)
  575.       type->print();
  576.    else
  577.       printf("invariant ");
  578.  
  579.    foreach_list_const (ptr, & this->declarations) {
  580.       if (ptr != this->declarations.get_head())
  581.          printf(", ");
  582.  
  583.       ast_node *ast = exec_node_data(ast_node, ptr, link);
  584.       ast->print();
  585.    }
  586.  
  587.    printf("; ");
  588. }
  589.  
  590.  
  591. ast_declarator_list::ast_declarator_list(ast_fully_specified_type *type)
  592. {
  593.    this->type = type;
  594.    this->invariant = false;
  595. }
  596.  
  597. void
  598. ast_jump_statement::print(void) const
  599. {
  600.    switch (mode) {
  601.    case ast_continue:
  602.       printf("continue; ");
  603.       break;
  604.    case ast_break:
  605.       printf("break; ");
  606.       break;
  607.    case ast_return:
  608.       printf("return ");
  609.       if (opt_return_value)
  610.          opt_return_value->print();
  611.  
  612.       printf("; ");
  613.       break;
  614.    case ast_discard:
  615.       printf("discard; ");
  616.       break;
  617.    }
  618. }
  619.  
  620.  
  621. ast_jump_statement::ast_jump_statement(int mode, ast_expression *return_value)
  622. {
  623.    this->mode = ast_jump_modes(mode);
  624.  
  625.    if (mode == ast_return)
  626.       opt_return_value = return_value;
  627. }
  628.  
  629.  
  630. void
  631. ast_selection_statement::print(void) const
  632. {
  633.    printf("if ( ");
  634.    condition->print();
  635.    printf(") ");
  636.  
  637.    then_statement->print();
  638.  
  639.    if (else_statement) {
  640.       printf("else ");
  641.       else_statement->print();
  642.    }
  643.    
  644. }
  645.  
  646.  
  647. ast_selection_statement::ast_selection_statement(ast_expression *condition,
  648.                                                  ast_node *then_statement,
  649.                                                  ast_node *else_statement)
  650. {
  651.    this->condition = condition;
  652.    this->then_statement = then_statement;
  653.    this->else_statement = else_statement;
  654. }
  655.  
  656.  
  657. void
  658. ast_iteration_statement::print(void) const
  659. {
  660.    switch (mode) {
  661.    case ast_for:
  662.       printf("for( ");
  663.       if (init_statement)
  664.          init_statement->print();
  665.       printf("; ");
  666.  
  667.       if (condition)
  668.          condition->print();
  669.       printf("; ");
  670.  
  671.       if (rest_expression)
  672.          rest_expression->print();
  673.       printf(") ");
  674.  
  675.       body->print();
  676.       break;
  677.  
  678.    case ast_while:
  679.       printf("while ( ");
  680.       if (condition)
  681.          condition->print();
  682.       printf(") ");
  683.       body->print();
  684.       break;
  685.  
  686.    case ast_do_while:
  687.       printf("do ");
  688.       body->print();
  689.       printf("while ( ");
  690.       if (condition)
  691.          condition->print();
  692.       printf("); ");
  693.       break;
  694.    }
  695. }
  696.  
  697.  
  698. ast_iteration_statement::ast_iteration_statement(int mode,
  699.                                                  ast_node *init,
  700.                                                  ast_node *condition,
  701.                                                  ast_expression *rest_expression,
  702.                                                  ast_node *body)
  703. {
  704.    this->mode = ast_iteration_modes(mode);
  705.    this->init_statement = init;
  706.    this->condition = condition;
  707.    this->rest_expression = rest_expression;
  708.    this->body = body;
  709. }
  710.  
  711.  
  712. void
  713. ast_struct_specifier::print(void) const
  714. {
  715.    printf("struct %s { ", name);
  716.    foreach_list_const(n, &this->declarations) {
  717.       ast_node *ast = exec_node_data(ast_node, n, link);
  718.       ast->print();
  719.    }
  720.    printf("} ");
  721. }
  722.  
  723.  
  724. ast_struct_specifier::ast_struct_specifier(char *identifier,
  725.                                            ast_node *declarator_list)
  726. {
  727.    if (identifier == NULL) {
  728.       static unsigned anon_count = 1;
  729.       identifier = ralloc_asprintf(this, "#anon_struct_%04x", anon_count);
  730.       anon_count++;
  731.    }
  732.    name = identifier;
  733.    this->declarations.push_degenerate_list_at_head(&declarator_list->link);
  734. }
  735.  
  736. bool
  737. do_common_optimization(exec_list *ir, bool linked, unsigned max_unroll_iterations)
  738. {
  739.    GLboolean progress = GL_FALSE;
  740.  
  741.    progress = lower_instructions(ir, SUB_TO_ADD_NEG) || progress;
  742.  
  743.    if (linked) {
  744.       progress = do_function_inlining(ir) || progress;
  745.       progress = do_dead_functions(ir) || progress;
  746.    }
  747.    progress = do_structure_splitting(ir) || progress;
  748.    progress = do_if_simplification(ir) || progress;
  749.    progress = do_discard_simplification(ir) || progress;
  750.    progress = do_copy_propagation(ir) || progress;
  751.    if (linked)
  752.       progress = do_dead_code(ir) || progress;
  753.    else
  754.       progress = do_dead_code_unlinked(ir) || progress;
  755.    progress = do_dead_code_local(ir) || progress;
  756.    progress = do_tree_grafting(ir) || progress;
  757.    progress = do_constant_propagation(ir) || progress;
  758.    if (linked)
  759.       progress = do_constant_variable(ir) || progress;
  760.    else
  761.       progress = do_constant_variable_unlinked(ir) || progress;
  762.    progress = do_constant_folding(ir) || progress;
  763.    progress = do_algebraic(ir) || progress;
  764.    progress = do_lower_jumps(ir) || progress;
  765.    progress = do_vec_index_to_swizzle(ir) || progress;
  766.    progress = do_swizzle_swizzle(ir) || progress;
  767.    progress = do_noop_swizzle(ir) || progress;
  768.  
  769.    progress = optimize_redundant_jumps(ir) || progress;
  770.  
  771.    loop_state *ls = analyze_loop_variables(ir);
  772.    progress = set_loop_controls(ir, ls) || progress;
  773.    progress = unroll_loops(ir, ls, max_unroll_iterations) || progress;
  774.    delete ls;
  775.  
  776.    return progress;
  777. }
  778.  
  779. extern "C" {
  780.  
  781. /**
  782.  * To be called at GL teardown time, this frees compiler datastructures.
  783.  *
  784.  * After calling this, any previously compiled shaders and shader
  785.  * programs would be invalid.  So this should happen at approximately
  786.  * program exit.
  787.  */
  788. void
  789. _mesa_destroy_shader_compiler(void)
  790. {
  791.    _mesa_destroy_shader_compiler_caches();
  792.  
  793.    _mesa_glsl_release_types();
  794. }
  795.  
  796. /**
  797.  * Releases compiler caches to trade off performance for memory.
  798.  *
  799.  * Intended to be used with glReleaseShaderCompiler().
  800.  */
  801. void
  802. _mesa_destroy_shader_compiler_caches(void)
  803. {
  804.    _mesa_glsl_release_functions();
  805. }
  806.  
  807. }
  808.