X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fprogramcompiler.cpp;h=7224df1efba672d4afb7ecb12923a0109ae9f6f6;hb=00be85f53c5bec0be00a7ed6271e1f5a38e0b534;hp=86ea8da93d7e6866590a563c150555393903cafe;hpb=57c1139e4fe21aeca7118b18eb3ba6fa43d7bf90;p=libs%2Fgl.git diff --git a/source/programcompiler.cpp b/source/programcompiler.cpp index 86ea8da9..7224df1e 100644 --- a/source/programcompiler.cpp +++ b/source/programcompiler.cpp @@ -165,14 +165,13 @@ void ProgramCompiler::generate(Stage &stage) apply(stage); apply(stage); apply(stage); + apply(stage); apply(stage); - apply(stage); } bool ProgramCompiler::optimize(Stage &stage) { apply(stage); - apply(stage); set unused = apply(stage); set unused2 = apply(stage); @@ -919,6 +918,45 @@ void ProgramCompiler::VariableRenamer::visit(VariableDeclaration &var) } +ProgramCompiler::DeclarationReorderer::DeclarationReorderer(): + kind(NO_DECLARATION) +{ } + +void ProgramCompiler::DeclarationReorderer::visit(Block &block) +{ + list >::iterator struct_insert_point = block.body.end(); + list >::iterator variable_insert_point = block.body.end(); + + for(list >::iterator i=block.body.begin(); i!=block.body.end(); ) + { + kind = NO_DECLARATION; + (*i)->visit(*this); + + bool moved = false; + if(kind==STRUCT && struct_insert_point!=block.body.end()) + { + block.body.insert(struct_insert_point, *i); + moved = true; + } + else if(kind>STRUCT && struct_insert_point==block.body.end()) + struct_insert_point = i; + + if(kind==VARIABLE && variable_insert_point!=block.body.end()) + { + block.body.insert(variable_insert_point, *i); + moved = true; + } + else if(kind>VARIABLE && variable_insert_point==block.body.end()) + variable_insert_point = i; + + if(moved) + block.body.erase(i++); + else + ++i; + } +} + + ProgramCompiler::ExpressionEvaluator::ExpressionEvaluator(): variable_values(0), result(0.0f),