Add generate_temporary to generate an anonymous temporary

This commit is contained in:
Ian Romanick 2010-03-29 15:20:42 -07:00
parent 6e659caaa9
commit 5185a5f7d5
3 changed files with 24 additions and 0 deletions

View file

@ -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)

View file

@ -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);

View file

@ -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 {