Compiler - OP_{TEXTURE,PROFILE,CLEAR}

This commit is contained in:
Emmanuel BENOîT 2017-11-13 10:02:16 +01:00
parent 415d565d72
commit 057033f2e3
5 changed files with 159 additions and 69 deletions

View file

@ -38,9 +38,14 @@ enum E_OpType
OP_FP_INV , OP_FP_INV ,
// //
OP_INIT_PIPELINE , OP_INIT_PIPELINE ,
OP_LOAD_PROGRAM , OP_INIT_PROGRAM ,
OP_INIT_TEXTURE ,
// //
OP_FULLSCREEN OP_FULLSCREEN ,
OP_CLEAR ,
//
OP_UI_PENTER ,
OP_UI_PEXIT ,
}; };
M_LSHIFT_OP( T_StringBuilder , E_OpType ); M_LSHIFT_OP( T_StringBuilder , E_OpType );

View file

@ -125,10 +125,12 @@ A_Node* opast::ASTVisitorBrowser(
} }
break; break;
} }
// Argument node
case A_Node::TN_ARG: case A_Node::TN_ARG:
{ {
if ( child == 0 ) { if ( child == 0 ) {
return &( (T_CallInstrNode::T_Argument&) node ).expression( ); return &( (T_ArgumentNode&) node ).expression( );
} }
break; break;
} }
@ -137,8 +139,9 @@ A_Node* opast::ASTVisitorBrowser(
case A_Node::OP_CLEAR: case A_Node::OP_CLEAR:
{ {
auto& n( (T_ClearInstrNode&) node ); auto& n( (T_ClearInstrNode&) node );
if ( child < n.components( ) ) { const auto nArgs( n.components( ) );
return &n.component( child ); if ( child < nArgs ) {
return &n.component( nArgs - child - 1 );
} }
break; break;
} }
@ -197,9 +200,9 @@ A_Node* opast::ASTVisitorBrowser(
{ {
auto& n( (T_TextureInstrNode&) node ); auto& n( (T_TextureInstrNode&) node );
auto c = child; auto c = child;
if ( n.hasWidth( ) ) { if ( n.lods( ) ) {
if ( c == 0 ) { if ( c == 0 ) {
return &n.width( ); return n.lods( );
} }
c --; c --;
} }
@ -209,7 +212,10 @@ A_Node* opast::ASTVisitorBrowser(
} }
c --; c --;
} }
return c == 0 ? n.lods( ) : nullptr; if ( n.hasWidth( ) && c == 0 ) {
return &n.width( );
}
return nullptr;
} }
// Framebuffer definition; may have LOD expressions // Framebuffer definition; may have LOD expressions

112
opast.hh
View file

@ -193,6 +193,30 @@ class A_ExpressionNode : public A_Node
}; };
using P_ExpressionNode = T_OwnPtr< A_ExpressionNode >; using P_ExpressionNode = T_OwnPtr< A_ExpressionNode >;
// Technical node used for the arguments of various instructions
class T_ArgumentNode : public A_Node
{
private:
P_ExpressionNode expr_;
public:
T_ArgumentNode( A_Node& parent ,
P_ExpressionNode expr ) noexcept
: A_Node( TN_ARG , &parent ) ,
expr_( std::move( expr ) )
{
if ( expr_ ) {
location( ) = expr_->location( );
}
}
A_ExpressionNode& expression( ) const noexcept
{ return *expr_; }
bool isIdentifier( ) const noexcept
{ return expr_->type( ) == EXPR_ID; }
};
using P_ArgumentNode = T_OwnPtr< T_ArgumentNode >;
/*= FUNCTIONS AND ROOT NODES =================================================*/ /*= FUNCTIONS AND ROOT NODES =================================================*/
@ -376,29 +400,10 @@ class T_FuncNode : public A_FuncNode
// Function call // Function call
class T_CallInstrNode : public A_InstructionNode class T_CallInstrNode : public A_InstructionNode
{ {
public:
class T_Argument : public A_Node
{
private:
P_ExpressionNode expr_;
public:
T_Argument( T_CallInstrNode& parent ,
P_ExpressionNode expr ) noexcept
: A_Node( TN_ARG , &parent ) ,
expr_( std::move( expr ) )
{ }
A_ExpressionNode& expression( ) const noexcept
{ return *expr_; }
bool isIdentifier( ) const noexcept
{ return expr_->type( ) == EXPR_ID; }
};
private: private:
T_String id_; T_String id_;
T_SRDLocation idLocation_; T_SRDLocation idLocation_;
T_AutoArray< T_OwnPtr< T_Argument > , 8 > arguments_; T_AutoArray< P_ArgumentNode , 8 > arguments_;
public: public:
T_CallInstrNode( T_InstrListNode& parent , T_CallInstrNode( T_InstrListNode& parent ,
@ -411,7 +416,7 @@ class T_CallInstrNode : public A_InstructionNode
void addArgument( P_ExpressionNode expr ) noexcept void addArgument( P_ExpressionNode expr ) noexcept
{ {
if ( expr ) { if ( expr ) {
arguments_.add( NewOwned< T_Argument >( arguments_.add( NewOwned< T_ArgumentNode >(
*this , std::move( expr ) ) ); *this , std::move( expr ) ) );
} }
} }
@ -423,7 +428,7 @@ class T_CallInstrNode : public A_InstructionNode
uint32_t arguments( ) const noexcept uint32_t arguments( ) const noexcept
{ return arguments_.size( ); } { return arguments_.size( ); }
T_Argument& argument( const uint32_t index ) const noexcept T_ArgumentNode& argument( const uint32_t index ) const noexcept
{ return *arguments_[ index ]; } { return *arguments_[ index ]; }
}; };
@ -840,9 +845,9 @@ class T_TextureInstrNode : public A_ResourceDefInstrNode
{ {
private: private:
E_TexType type_; E_TexType type_;
P_ExpressionNode width_; P_ArgumentNode width_;
P_ExpressionNode height_; P_ArgumentNode height_;
P_ExpressionNode lods_; P_ArgumentNode lods_;
public: public:
T_TextureInstrNode( T_TextureInstrNode(
@ -854,23 +859,44 @@ class T_TextureInstrNode : public A_ResourceDefInstrNode
type_( type ) type_( type )
{ } { }
E_TexType texType( ) const noexcept
{ return type_; }
void setWidth( P_ExpressionNode width ) noexcept void setWidth( P_ExpressionNode width ) noexcept
{ width_ = std::move( width ); } {
bool hasWidth( ) const noexcept if ( width ) {
{ return bool( width_ ); } width_ = NewOwned< T_ArgumentNode >(
A_ExpressionNode& width( ) const noexcept *this , std::move( width ) );
{ return *width_; } }
}
void setHeight( P_ExpressionNode height ) noexcept void setHeight( P_ExpressionNode height ) noexcept
{ height_ = std::move( height ); } {
bool hasHeight( ) const noexcept if ( height ) {
{ return bool( height_ ); } height_ = NewOwned< T_ArgumentNode >(
A_ExpressionNode& height( ) const noexcept *this , std::move( height ) );
{ return *height_; } }
}
void setLODs( P_ExpressionNode lods ) noexcept void setLODs( P_ExpressionNode lods ) noexcept
{ lods_ = std::move( lods ); } {
A_ExpressionNode* lods( ) const noexcept if ( lods ) {
lods_ = NewOwned< T_ArgumentNode >(
*this , std::move( lods ) );
}
}
bool hasWidth( ) const noexcept
{ return bool( width_ ); }
T_ArgumentNode& width( ) const noexcept
{ return *width_; }
bool hasHeight( ) const noexcept
{ return bool( height_ ); }
T_ArgumentNode& height( ) const noexcept
{ return *height_; }
T_ArgumentNode* lods( ) const noexcept
{ return lods_.get( ); } { return lods_.get( ); }
}; };
@ -944,7 +970,7 @@ class T_ProfileInstrNode : public A_InstructionNode
class T_ClearInstrNode : public A_InstructionNode class T_ClearInstrNode : public A_InstructionNode
{ {
private: private:
T_StaticArray< P_ExpressionNode , 4 > components_; T_StaticArray< P_ArgumentNode , 4 > components_;
public: public:
T_ClearInstrNode( T_InstrListNode& parent ) noexcept T_ClearInstrNode( T_InstrListNode& parent ) noexcept
@ -953,12 +979,16 @@ class T_ClearInstrNode : public A_InstructionNode
{ } { }
void addComponent( P_ExpressionNode expr ) noexcept void addComponent( P_ExpressionNode expr ) noexcept
{ if ( expr ) { components_.add( std::move( expr ) ); } } {
if ( expr ) {
components_.add( NewOwned< T_ArgumentNode >(
*this , std::move( expr ) ) );
}
}
uint32_t components( ) const noexcept uint32_t components( ) const noexcept
{ return components_.size( ); } { return components_.size( ); }
T_ArgumentNode& component( const uint32_t index ) const noexcept
A_ExpressionNode& component( const uint32_t index ) const noexcept
{ return *components_[ index ]; } { return *components_[ index ]; }
}; };

View file

@ -330,6 +330,7 @@ bool T_CompilerImpl_::compileNode(
break; break;
} }
//- GENERAL / FLOW CONTROL INSTRUCTIONS ----------------------------------------------- //- GENERAL / FLOW CONTROL INSTRUCTIONS -----------------------------------------------
case A_Node::OP_CALL: case A_Node::OP_CALL:
@ -346,23 +347,6 @@ bool T_CompilerImpl_::compileNode(
sdMain -= args; sdMain -= args;
} }
break; break;
case A_Node::TN_ARG:
{
auto& n( (T_CallInstrNode::T_Argument&)node );
if ( n.isIdentifier( ) && !exit ) {
const bool main{ processIdentifier( funcIndex ,
(T_IdentifierExprNode&) n.expression( ) ) };
if ( !main ) {
addInstruction( OP_PUSH , node.location( ) );
addInstruction( OP_FP_SSTORE , 0 , node.location( ) );
}
return false;
} else if ( exit && !n.isIdentifier( ) ) {
addInstruction( OP_PUSH , node.location( ) );
addInstruction( OP_FP_SSTORE , 0 , node.location( ) );
}
break;
}
case A_Node::OP_SET: case A_Node::OP_SET:
if ( exit ) { if ( exit ) {
@ -465,11 +449,26 @@ bool T_CompilerImpl_::compileNode(
if ( !output->progNames.contains( pn.path( ) ) ) { if ( !output->progNames.contains( pn.path( ) ) ) {
output->progNames.add( pn.path( ) ); output->progNames.add( pn.path( ) );
} }
addInstruction( OP_LOAD_PROGRAM , output->progNames.indexOf( pn.path( ) ) , addInstruction( OP_INIT_PROGRAM , output->progNames.indexOf( pn.path( ) ) ,
pn.location( ) ); pn.location( ) );
} }
break; break;
case A_Node::OP_TEXTURE:
if ( exit ) {
auto& tn( (T_TextureInstrNode&) node );
const auto hasLOD( tn.lods( ) );
processIdentifier( funcIndex , tn.id( ) , tn.idLocation( ) );
addInstruction( OP_INIT_TEXTURE , {
uint32_t( tn.texType( ) ) , hasLOD ? 1u : 0u
} , tn.location( ) );
if ( hasLOD ) {
sdMain --;
}
}
break;
//- RENDERING ------------------------------------------------------------------------- //- RENDERING -------------------------------------------------------------------------
case A_Node::OP_FULLSCREEN: case A_Node::OP_FULLSCREEN:
@ -478,6 +477,50 @@ bool T_CompilerImpl_::compileNode(
} }
break; break;
case A_Node::OP_CLEAR:
if ( exit ) {
addInstruction( OP_CLEAR , node.location( ) );
}
break;
//- DEBUGGING / UI CONTROLS -----------------------------------------------------------
case A_Node::OP_PROFILE:
if ( exit ) {
addInstruction( OP_UI_PEXIT , node.location( ) );
} else {
auto& pn( (T_ProfileInstrNode&) node );
if ( ! output->uiStrings.contains( pn.text( ) ) ) {
output->uiStrings.add( pn.text( ) );
}
addInstruction( OP_UI_PENTER , output->uiStrings.indexOf( pn.text( ) ) ,
pn.location( ) );
}
break;
//- EXPRESSIONS - ARGUMENTS -----------------------------------------------------------
case A_Node::TN_ARG:
{
auto& n( (T_ArgumentNode&)node );
if ( n.isIdentifier( ) && !exit ) {
const bool main{ processIdentifier( funcIndex ,
(T_IdentifierExprNode&) n.expression( ) ) };
if ( !main ) {
addInstruction( OP_PUSH , node.location( ) );
addInstruction( OP_FP_SSTORE , 0 , node.location( ) );
}
return false;
} else if ( exit && !n.isIdentifier( ) ) {
addInstruction( OP_PUSH , node.location( ) );
addInstruction( OP_FP_SSTORE , 0 , node.location( ) );
}
break;
}
//- EXPRESSIONS - OPERATORS ----------------------------------------------------------- //- EXPRESSIONS - OPERATORS -----------------------------------------------------------
case A_Node::EXPR_CMP_EQ: case A_Node::EXPR_CMP_NE: case A_Node::EXPR_CMP_EQ: case A_Node::EXPR_CMP_NE:
@ -511,6 +554,7 @@ bool T_CompilerImpl_::compileNode(
} }
break; break;
//- EXPRESSIONS - TERMINAL NODES ------------------------------------------------------ //- EXPRESSIONS - TERMINAL NODES ------------------------------------------------------
case A_Node::EXPR_CONST: case A_Node::EXPR_CONST:

9
ops.cc
View file

@ -109,10 +109,15 @@ static T_KeyValueTable< E_OpType , T_OpInfo > OpInfoTable_{ ([]() {
infos.add( E_OpType::OP_FP_MUL , T_OpInfo{ "fp-neg" , 0 } ); infos.add( E_OpType::OP_FP_MUL , T_OpInfo{ "fp-neg" , 0 } );
infos.add( E_OpType::OP_FP_DIV , T_OpInfo{ "fp-inv" , 0 } ); infos.add( E_OpType::OP_FP_DIV , T_OpInfo{ "fp-inv" , 0 } );
// //
infos.add( E_OpType::OP_INIT_PIPELINE , T_OpInfo{ "init-pipeline" , 1 , OpStackMain{ -1 } } ); infos.add( E_OpType::OP_INIT_PIPELINE , T_OpInfo{ "pipeline" , 1 , OpStackMain{ -1 } } );
infos.add( E_OpType::OP_LOAD_PROGRAM , T_OpInfo{ "load-program" , 1 , OpStackMain{ -1 } } ); infos.add( E_OpType::OP_INIT_PROGRAM , T_OpInfo{ "program" , 1 , OpStackMain{ -1 } } );
infos.add( E_OpType::OP_INIT_TEXTURE , T_OpInfo{ "texture" , 2 , OpStackMain{ -3 } } );
// //
infos.add( E_OpType::OP_FULLSCREEN , T_OpInfo{ "fullscreen" } ); infos.add( E_OpType::OP_FULLSCREEN , T_OpInfo{ "fullscreen" } );
infos.add( E_OpType::OP_CLEAR , T_OpInfo{ "clear" , 0 , OpStackMain{ -4 } } );
//
infos.add( E_OpType::OP_UI_PENTER , T_OpInfo{ "ui-prof-enter" , 1 } );
infos.add( E_OpType::OP_UI_PEXIT , T_OpInfo{ "ui-prof-exit" } );
return infos; return infos;
})( ) }; })( ) };