From: Ian Romanick Date: Mon, 29 Mar 2010 22:20:42 +0000 (-0700) Subject: Add generate_temporary to generate an anonymous temporary X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=5185a5f7d5654c9202c226015c4daeee43d9b897;p=mesa.git Add generate_temporary to generate an anonymous temporary --- diff --git a/ast_to_hir.cpp b/ast_to_hir.cpp index 4674cfcdd52..80489d37198 100644 --- a/ast_to_hir.cpp +++ b/ast_to_hir.cpp @@ -388,6 +388,26 @@ do_assignment(exec_list *instructions, struct _mesa_glsl_parse_state *state, return rhs; } + +/** + * Generate a new temporary and add its declaration to the instruction stream + */ +static ir_variable * +generate_temporary(const glsl_type *type, exec_list *instructions, + struct _mesa_glsl_parse_state *state) +{ + char *name = (char *) malloc(sizeof(char) * 13); + + snprintf(name, 13, "tmp_%08X", state->temp_index); + state->temp_index++; + + ir_variable *const var = new ir_variable(type, name); + instructions->push_tail(var); + + return var; +} + + static ir_rvalue * get_lvalue_copy(exec_list *instructions, struct _mesa_glsl_parse_state *state, ir_rvalue *lvalue, YYLTYPE loc) diff --git a/glsl_parser_extras.cpp b/glsl_parser_extras.cpp index d57a68efb75..1ddc2ee9ddd 100644 --- a/glsl_parser_extras.cpp +++ b/glsl_parser_extras.cpp @@ -634,6 +634,7 @@ main(int argc, char **argv) make_empty_list(& state.translation_unit); state.symbols = new glsl_symbol_table; state.error = false; + state.temp_index = 0; _mesa_glsl_lexer_ctor(& state, shader, shader_len); _mesa_glsl_parse(& state); diff --git a/glsl_parser_extras.h b/glsl_parser_extras.h index dbe7c17302a..96c975ba117 100644 --- a/glsl_parser_extras.h +++ b/glsl_parser_extras.h @@ -53,6 +53,9 @@ struct _mesa_glsl_parse_state { /** Was there an error during compilation? */ bool error; + + /** Index of last generated anonymous temporary. */ + unsigned temp_index; }; typedef struct YYLTYPE {