Parser - clear instruction

This commit is contained in:
Emmanuel BENOîT 2017-11-10 22:09:24 +01:00
parent a455f2ad40
commit b98c2247ae
4 changed files with 55 additions and 3 deletions

View file

@ -45,7 +45,7 @@ syn keyword srdKWDebug profiling odbg ui-overrides
syn keyword srdKWState use-texture use-framebuffer use-program use-pipeline syn keyword srdKWState use-texture use-framebuffer use-program use-pipeline
syn keyword srdKWState uniforms uniforms-i viewport main-output syn keyword srdKWState uniforms uniforms-i viewport main-output
syn keyword srdKWDraw fullscreen syn keyword srdKWDraw clear fullscreen
syn keyword srdKWExpr add sub mul div pow syn keyword srdKWExpr add sub mul div pow
syn keyword srdKWExpr cmp-eq cmp-ne cmp-gt cmp-ge cmp-lt cmp-le syn keyword srdKWExpr cmp-eq cmp-ne cmp-gt cmp-ge cmp-lt cmp-le

View file

@ -125,6 +125,16 @@ A_Node* opast::ASTVisitorBrowser(
break; break;
} }
// Clear instruction
case A_Node::OP_CLEAR:
{
auto& n( (T_ClearInstrNode&) node );
if ( child < n.components( ) ) {
return &n.component( child );
}
break;
}
// Conditional instruction // Conditional instruction
case A_Node::OP_COND: case A_Node::OP_COND:
{ {

View file

@ -21,6 +21,7 @@ class A_Node
DECL_FN , // Function DECL_FN , // Function
// //
OP_CALL , // Function call OP_CALL , // Function call
OP_CLEAR , // Clear buffer
OP_COND , // Conditional instruction OP_COND , // Conditional instruction
OP_FRAMEBUFFER ,// Define framebuffer OP_FRAMEBUFFER ,// Define framebuffer
OP_FULLSCREEN , // Draw a fullscreen quad OP_FULLSCREEN , // Draw a fullscreen quad
@ -326,6 +327,27 @@ class T_CallInstrNode : public A_InstructionNode
{ return *arguments_[ index ]; } { return *arguments_[ index ]; }
}; };
// Clear instruction
class T_ClearInstrNode : public A_InstructionNode
{
private:
T_StaticArray< P_ExpressionNode , 4 > components_;
public:
T_ClearInstrNode( T_InstrListNode& parent ) noexcept
: A_InstructionNode( OP_CLEAR , parent )
{ }
void addComponent( P_ExpressionNode expr ) noexcept
{ if ( expr ) { components_.add( std::move( expr ) ); } }
uint32_t components( ) const noexcept
{ return components_.size( ); }
A_ExpressionNode& component( const uint32_t index ) const noexcept
{ return *components_[ index ]; }
};
// Conditional instruction // Conditional instruction
class T_CondInstrNode : public A_InstructionNode class T_CondInstrNode : public A_InstructionNode
{ {
@ -940,8 +962,7 @@ class T_ViewportInstrNode : public A_InstructionNode
public: public:
T_ViewportInstrNode( T_InstrListNode& parent ) noexcept T_ViewportInstrNode( T_InstrListNode& parent ) noexcept
: A_InstructionNode( OP_VIEWPORT , parent , : A_InstructionNode( OP_VIEWPORT , parent )
E_InstrRestriction::INIT )
{ } { }
void setParameter( const E_Parameter p , P_ExpressionNode height ) noexcept void setParameter( const E_Parameter p , P_ExpressionNode height ) noexcept

View file

@ -14,6 +14,7 @@ struct T_ParserImpl_
{ {
enum class E_InstrType { enum class E_InstrType {
CALL , CALL ,
CLEAR ,
FRAMEBUFFER , FRAMEBUFFER ,
FULLSCREEN , FULLSCREEN ,
IF , IF ,
@ -43,6 +44,7 @@ struct T_ParserImpl_
} }; } };
add( "call" , E_InstrType::CALL ); add( "call" , E_InstrType::CALL );
add( "clear" , E_InstrType::CLEAR );
add( "framebuffer" , E_InstrType::FRAMEBUFFER ); add( "framebuffer" , E_InstrType::FRAMEBUFFER );
add( "fullscreen" , E_InstrType::FULLSCREEN ); add( "fullscreen" , E_InstrType::FULLSCREEN );
add( "if" , E_InstrType::IF ); add( "if" , E_InstrType::IF );
@ -187,6 +189,7 @@ struct T_ParserImpl_
T_SRDList const& input ) noexcept T_SRDList const& input ) noexcept
M_DPARSER_( Call ); M_DPARSER_( Call );
M_DPARSER_( Clear );
M_DPARSER_( Framebuffer ); M_DPARSER_( Framebuffer );
bool parseFramebufferEntry( bool parseFramebufferEntry(
@ -488,6 +491,7 @@ void T_ParserImpl_::parseInstructions(
#define M_CASE_( NAME , FNAME ) case E_InstrType::NAME: parse##FNAME##Instruction( instructions , ilist ); break #define M_CASE_( NAME , FNAME ) case E_InstrType::NAME: parse##FNAME##Instruction( instructions , ilist ); break
switch ( *instrMap.get( iword ) ) { switch ( *instrMap.get( iword ) ) {
M_CASE_( CALL , Call ); M_CASE_( CALL , Call );
M_CASE_( CLEAR , Clear );
M_CASE_( FRAMEBUFFER , Framebuffer ); M_CASE_( FRAMEBUFFER , Framebuffer );
M_CASE_( IF , If ); M_CASE_( IF , If );
M_CASE_( INPUT , Input ); M_CASE_( INPUT , Input );
@ -564,6 +568,23 @@ M_INSTR_( Call )
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
M_INSTR_( Clear )
{
if ( input.size( ) < 5 ) {
errors.addNew( "not enough arguments" , input[ 0 ].location( ) );
} else if ( input.size( ) > 5 ) {
errors.addNew( "too many arguments" , input[ 0 ].location( ) );
}
auto& instr{ instructions.add< T_ClearInstrNode >( ) };
instr.location( ) = input[ 0 ].location( );
for ( auto i = 1u ; i < std::max( 5u , input.size( ) ) ; i ++ ) {
instr.addComponent( parseExpression( instr , input[ i ] ) );
}
}
/*----------------------------------------------------------------------------*/
M_INSTR_( Framebuffer ) M_INSTR_( Framebuffer )
{ {
if ( input.size( ) == 1 || input[ 1 ].type( ) != E_SRDTokenType::WORD ) { if ( input.size( ) == 1 || input[ 1 ].type( ) != E_SRDTokenType::WORD ) {