From 8a48f3557424cfa67269ae5e4dca100ae2a0ddda Mon Sep 17 00:00:00 2001 From: Brian Date: Wed, 10 Jan 2007 12:18:50 -0700 Subject: [PATCH] assorted code clean-ups --- src/mesa/shader/shader_api.c | 3 +-- src/mesa/shader/slang/slang_codegen.c | 33 +++++++++++++++++++-------- src/mesa/shader/slang/slang_emit.c | 27 +++++++++------------- 3 files changed, 35 insertions(+), 28 deletions(-) diff --git a/src/mesa/shader/shader_api.c b/src/mesa/shader/shader_api.c index 101c6f1e7e3..69314b225a4 100644 --- a/src/mesa/shader/shader_api.c +++ b/src/mesa/shader/shader_api.c @@ -849,7 +849,6 @@ _mesa_use_program(GLcontext *ctx, GLuint program) ctx->Shader.CurrentProgram = NULL; } - /* XXXX need to handle reference counting here! */ if (program) { struct gl_shader_program *shProg; shProg = _mesa_lookup_shader_program(ctx, program); @@ -916,7 +915,7 @@ _mesa_uniform(GLcontext *ctx, GLint location, GLsizei count, } } else { - const GLfloat *fValues = (const GLfloat *) values; /* XXX */ + const GLfloat *fValues = (const GLfloat *) values; switch (type) { case GL_FLOAT_VEC4: uniformVal[3] = fValues[3]; diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c index 91e117367e2..07ca8107c0a 100644 --- a/src/mesa/shader/slang/slang_codegen.c +++ b/src/mesa/shader/slang/slang_codegen.c @@ -541,6 +541,11 @@ _slang_codegen_global_variable(slang_variable *var, struct gl_program *prog, else if (var->type.qualifier == slang_qual_const) { if (prog) { /* user-defined constant */ + const GLint size = _slang_sizeof_type_specifier(&var->type.specifier); + /* + const GLint index = _mesa_add_named_constant(prog->Parameters); + */ + printf("Global user constant\n"); abort(); /* XXX fix */ } else { @@ -591,7 +596,10 @@ _slang_codegen_global_variable(slang_variable *var, struct gl_program *prog, if (dbg) printf("OUTPUT "); } else { + /* ordinary variable */ + assert(prog); /* shouldn't be any pre-defined, unqualified vars */ if (dbg) printf("other "); + abort(); } if (dbg) printf("GLOBAL VAR %s idx %d\n", (char*) var->a_name, store?store->Index:-2); @@ -2104,20 +2112,24 @@ _slang_gen_operation(slang_assemble_ctx * A, slang_operation *oper) /** * Produce an IR tree from a function AST. - * Then call the code emitter to convert the IR tree into a gl_program. + * Then call the code emitter to convert the IR tree into gl_program + * instructions. */ struct slang_ir_node_ * _slang_codegen_function(slang_assemble_ctx * A, slang_function * fun) { slang_ir_node *n, *endLabel; + GLboolean success; - if (_mesa_strcmp((char *) fun->header.a_name, "main") != 0 && - _mesa_strcmp((char *) fun->header.a_name, "foo") != 0 && - _mesa_strcmp((char *) fun->header.a_name, "bar") != 0) + if (_mesa_strcmp((char *) fun->header.a_name, "main") != 0) { + /* we only really generate code for main, all other functions get + * inlined. + */ return 0; + } - printf("\n*********** Assemble function2(%s)\n", (char*)fun->header.a_name); #if 1 + printf("\n*********** codegen_function %s\n", (char *) fun->header.a_name); slang_print_function(fun, 1); #endif @@ -2133,6 +2145,7 @@ _slang_codegen_function(slang_assemble_ctx * A, slang_function * fun) CurFunction = fun; + /* Create an end-of-function label */ if (!CurFunction->end_label) CurFunction->end_label = slang_atom_pool_gen(A->atoms, "__endOfFunc_main_"); @@ -2147,17 +2160,17 @@ _slang_codegen_function(slang_assemble_ctx * A, slang_function * fun) #if 1 - printf("************* New body for %s *****\n", (char*)fun->header.a_name); + printf("************* New AST for %s *****\n", (char*)fun->header.a_name); slang_print_function(fun, 1); - printf("************* IR for %s *******\n", (char*)fun->header.a_name); slang_print_ir(n, 0); printf("************* End assemble function2 ************\n\n"); #endif - if (_mesa_strcmp((char*) fun->header.a_name, "main") == 0) { - _slang_emit_code(n, A->codegen, A->program); - } + success = _slang_emit_code(n, A->codegen, A->program); + + /* free codegen context */ + _mesa_free(A->codegen); return n; } diff --git a/src/mesa/shader/slang/slang_emit.c b/src/mesa/shader/slang/slang_emit.c index 87a3f3f337c..6c80c1e015a 100644 --- a/src/mesa/shader/slang/slang_emit.c +++ b/src/mesa/shader/slang/slang_emit.c @@ -751,7 +751,7 @@ emit(slang_gen_context *gc, slang_ir_node *n, struct gl_program *prog) case IR_CJUMP: return emit_cjump(n->Target, prog); default: - printf("emit: ?\n"); + _mesa_problem(NULL, "Unexpected IR opcode in emit()\n"); abort(); } return NULL; @@ -771,29 +771,24 @@ GLboolean _slang_emit_code(slang_ir_node *n, slang_gen_context *gc, struct gl_program *prog) { - /*GET_CURRENT_CONTEXT(ctx);*/ + GLboolean success; - /* - gc = _slang_new_codegen_context(); - */ - - printf("************ Begin generate code\n"); - - (void) emit(gc, n, prog); - - { + if (emit(gc, n, prog)) { + /* finish up by addeing the END opcode to program */ struct prog_instruction *inst; inst = new_instruction(prog, OPCODE_END); + success = GL_TRUE; + } + else { + /* record an error? */ + success = GL_FALSE; } - - printf("************ End generate code (%u inst):\n", prog->NumInstructions); #if 0 + printf("*********** End generate code (%u inst):\n", prog->NumInstructions); _mesa_print_program(prog); _mesa_print_program_parameters(ctx,prog); #endif - _mesa_free(gc); - - return GL_FALSE; + return success; } -- 2.30.2