From 6deb59d884a51677ef28b0806effd0e45146cdd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Tue, 14 Nov 2017 15:37:42 +0100 Subject: [PATCH] Control / compiler - Fixed program initialization Program initialization returns an identifier, unlike the rest of the initializers which require an allocated GL ID. --- control.hh | 1 + opcomp.cc | 4 +++- ops.cc | 8 +++++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/control.hh b/control.hh index 48b1735..ca73896 100644 --- a/control.hh +++ b/control.hh @@ -22,6 +22,7 @@ enum E_OpType OP_DUP , // OP_LOAD , + OP_STORE , OP_SLOAD , OP_CONST , // diff --git a/opcomp.cc b/opcomp.cc index da28a47..706a4a1 100644 --- a/opcomp.cc +++ b/opcomp.cc @@ -456,12 +456,14 @@ bool T_CompilerImpl_::compileNode( case A_Node::OP_PROGRAM: if ( exit ) { auto& pn( (T_ProgramInstrNode&) node ); - processIdentifier( funcIndex , pn.id( ) , pn.idLocation( ) ); if ( !output->progNames.contains( pn.path( ) ) ) { output->progNames.add( pn.path( ) ); } + assert( locations.contains( pn.id( ) ) ); + addInstruction( OP_INIT_PROGRAM , output->progNames.indexOf( pn.path( ) ) , pn.location( ) ); + addInstruction( OP_STORE , *locations.get( pn.id( ) ) , pn.idLocation( ) ); } break; diff --git a/ops.cc b/ops.cc index b2098f2..b092a52 100644 --- a/ops.cc +++ b/ops.cc @@ -95,6 +95,7 @@ static T_KeyValueTable< E_OpType , T_OpInfo > OpInfoTable_{ ([]() { infos.add( E_OpType::OP_DUP , T_OpInfo{ "dup" , 1 , OpStackMain{ 1 } } ); // infos.add( E_OpType::OP_LOAD , T_OpInfo{ "load" , 1 } ); + infos.add( E_OpType::OP_STORE , T_OpInfo{ "store" , 1 } ); infos.add( E_OpType::OP_SLOAD , T_OpInfo{ "load-stack" , 1 } ); infos.add( E_OpType::OP_CONST , T_OpInfo{ "const" , 1 } ); // @@ -122,7 +123,7 @@ static T_KeyValueTable< E_OpType , T_OpInfo > OpInfoTable_{ ([]() { infos.add( E_OpType::OP_FP_LN , T_OpInfo{ "fp-ln" , 0 } ); // infos.add( E_OpType::OP_INIT_PIPELINE , T_OpInfo{ "pipeline" , 1 , OpStackMain{ -1 } } ); - infos.add( E_OpType::OP_INIT_PROGRAM , T_OpInfo{ "program" , 1 , OpStackMain{ -1 } } ); + infos.add( E_OpType::OP_INIT_PROGRAM , T_OpInfo{ "program" , 1 } ); infos.add( E_OpType::OP_INIT_TEXTURE , T_OpInfo{ "texture" , 2 , OpStackMain{ -3 } } ); infos.add( E_OpType::OP_INIT_SAMPLER , T_OpInfo{ "sampler" , 2 , OpStackMain{ -3 } } ); infos.add( E_OpType::OP_FB_ATTACH , T_OpInfo{ "fb-attach" , 2 , OpStackMain{ -1 } } ); @@ -312,6 +313,11 @@ void T_OpContext::run( wreg = values[ instr.args[ 0 ] ]; break; + case OP_STORE: + checkAddress( instr , instr.args[ 0 ] ); + values[ instr.args[ 0 ] ] = wreg; + break; + case OP_SLOAD: ensureStack( instr , instr.args[ 0 ] + 1 ); wreg = stack[ stack.size( ) - instr.args[ 0 ] - 1 ];