summaryrefslogtreecommitdiff
path: root/src/mesa/shader/slang
diff options
context:
space:
mode:
authorBrian Paul <brianp@vmware.com>2009-06-23 16:55:10 -0600
committerBrian Paul <brianp@vmware.com>2009-06-26 13:16:33 -0600
commitf4b1a69b7d53d88e12d9baac419b48bbf8e32989 (patch)
treec31b7ba6e2610fc5ca3a37f0f7a0aa10e8dab63b /src/mesa/shader/slang
parent454a717d94f51504664b6b2e6463dd14ef2c4f7c (diff)
glsl: use slang_generate_declaration() to consolidate some code
Diffstat (limited to 'src/mesa/shader/slang')
-rw-r--r--src/mesa/shader/slang/slang_codegen.c68
1 files changed, 37 insertions, 31 deletions
diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c
index 7ab2135c85..d594650c5b 100644
--- a/src/mesa/shader/slang/slang_codegen.c
+++ b/src/mesa/shader/slang/slang_codegen.c
@@ -836,6 +836,37 @@ _slang_is_tail_return(const slang_operation *oper)
}
+/**
+ * Generate a variable declaration opeartion.
+ * I.e.: generate AST code for "bool flag = false;"
+ */
+static void
+slang_generate_declaration(slang_assemble_ctx *A,
+ slang_variable_scope *scope,
+ slang_operation *decl,
+ slang_type_specifier_type type,
+ const char *name,
+ GLint initValue)
+{
+ slang_variable *var;
+
+ assert(type == SLANG_SPEC_BOOL ||
+ type == SLANG_SPEC_INT);
+
+ decl->type = SLANG_OPER_VARIABLE_DECL;
+
+ var = slang_variable_scope_grow(scope);
+
+ slang_fully_specified_type_construct(&var->type);
+
+ var->type.specifier.type = type;
+ var->a_name = slang_atom_pool_atom(A->atoms, name);
+ decl->a_id = var->a_name;
+ var->initializer = slang_operation_new(1);
+ slang_operation_literal_bool(var->initializer, initValue);
+}
+
+
static void
slang_resolve_variable(slang_operation *oper)
{
@@ -2513,16 +2544,8 @@ _slang_gen_while_without_continue(slang_assemble_ctx *A, slang_operation *oper)
/* declare: bool _notBreakFlag = true */
{
slang_operation *condDecl = slang_oper_child(top, 0);
- slang_variable *var;
-
- condDecl->type = SLANG_OPER_VARIABLE_DECL;
- var = slang_variable_scope_grow(top->locals);
- slang_fully_specified_type_construct(&var->type);
- var->type.specifier.type = SLANG_SPEC_BOOL;
- var->a_name = slang_atom_pool_atom(A->atoms, "_notBreakFlag");
- condDecl->a_id = var->a_name;
- var->initializer = slang_operation_new(1);
- slang_operation_literal_bool(var->initializer, GL_TRUE);
+ slang_generate_declaration(A, top->locals, condDecl,
+ SLANG_SPEC_BOOL, "_notBreakFlag", GL_TRUE);
}
/* build outer while-loop: while (_notBreakFlag && LOOPCOND) { ... } */
@@ -2703,16 +2726,8 @@ _slang_gen_do_without_continue(slang_assemble_ctx *A, slang_operation *oper)
/* declare: bool _notBreakFlag = true */
{
slang_operation *condDecl = slang_oper_child(top, 0);
- slang_variable *var;
-
- condDecl->type = SLANG_OPER_VARIABLE_DECL;
- var = slang_variable_scope_grow(top->locals);
- slang_fully_specified_type_construct(&var->type);
- var->type.specifier.type = SLANG_SPEC_BOOL;
- var->a_name = slang_atom_pool_atom(A->atoms, "_notBreakFlag");
- condDecl->a_id = var->a_name;
- var->initializer = slang_operation_new(1);
- slang_operation_literal_bool(var->initializer, GL_TRUE);
+ slang_generate_declaration(A, top->locals, condDecl,
+ SLANG_SPEC_BOOL, "_notBreakFlag", GL_TRUE);
}
/* build outer do-loop: do { ... } while (_notBreakFlag && LOOPCOND) */
@@ -3124,17 +3139,8 @@ _slang_gen_for_without_continue(slang_assemble_ctx *A, slang_operation *oper)
/* declare: bool _condFlag = true */
{
slang_operation *condDecl;
- slang_variable *var;
-
- condDecl = slang_oper_child(top, 0);
- condDecl->type = SLANG_OPER_VARIABLE_DECL;
- var = slang_variable_scope_grow(top->locals);
- slang_fully_specified_type_construct(&var->type);
- var->type.specifier.type = SLANG_SPEC_BOOL;
- var->a_name = slang_atom_pool_atom(A->atoms, "_condFlag");
- condDecl->a_id = var->a_name;
- var->initializer = slang_operation_new(1);
- slang_operation_literal_bool(var->initializer, GL_TRUE);
+ slang_generate_declaration(A, top->locals, condDecl,
+ SLANG_SPEC_BOOL, "_condFlag", GL_TRUE);
}
/* build outer loop: for (INIT; _condFlag; ) { */