Parser - Fixed problem with unused functions

This commit is contained in:
Emmanuel BENOîT 2017-11-30 17:56:37 +01:00
parent 3aeac7980e
commit 59b23de5ed
3 changed files with 11 additions and 4 deletions

2
TODO
View file

@ -7,8 +7,6 @@ Post-processing:
* Lens dirt * Lens dirt
Scripting: Scripting:
* Eliminate functions that are not called / prevent them from causing
type errors
* Spill values in the FPU stack runs out * Spill values in the FPU stack runs out
* More checks in the execution engine * More checks in the execution engine
* Overrides * Overrides

View file

@ -363,6 +363,9 @@ class T_RootNode : public A_Node
{ return functions_.indexOf( name ); } { return functions_.indexOf( name ); }
A_FuncNode& function( const uint32_t index ) const noexcept A_FuncNode& function( const uint32_t index ) const noexcept
{ return *functions_.values( )[ index ]; } { return *functions_.values( )[ index ]; }
void removeFunction( T_String const& name ) noexcept
{ functions_.remove( name ); }
}; };
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/

View file

@ -392,7 +392,7 @@ bool T_ParserImpl_::checkCalls( ) noexcept
/* Go through the call graph, determine whether functions are called from the /* Go through the call graph, determine whether functions are called from the
* initialisation block, the frame rendering block, or both, and then enforce * initialisation block, the frame rendering block, or both, and then enforce
* restrictions on instructions. * restrictions on instructions. Also, remove functions that are never called.
*/ */
bool T_ParserImpl_::checkInstructionRestrictions( ) noexcept bool T_ParserImpl_::checkInstructionRestrictions( ) noexcept
{ {
@ -415,7 +415,12 @@ bool T_ParserImpl_::checkInstructionRestrictions( ) noexcept
callInfo[ id ] |= E_InstrRestriction::FRAME; callInfo[ id ] |= E_InstrRestriction::FRAME;
return true; return true;
} ); } );
for ( auto i = 0u ; i < output->root.nFunctions( ) ; i ++ ) { for ( auto i = 0u ; i < output->root.nFunctions( ) ; ) {
if ( !callInfo[ i ] ) {
output->root.removeFunction( output->root.function( i ).name( ) );
callInfo.removeSwap( i );
continue;
}
visitor.visit( output->root.function( i ) , [&]( A_Node& node , bool exit ) { visitor.visit( output->root.function( i ) , [&]( A_Node& node , bool exit ) {
if ( exit ) { if ( exit ) {
return false; return false;
@ -430,6 +435,7 @@ bool T_ParserImpl_::checkInstructionRestrictions( ) noexcept
} }
return true; return true;
} ); } );
i ++;
} }
return errors.empty( ); return errors.empty( );
} }