Compiler - OP_{TEXTURE,PROFILE,CLEAR}
This commit is contained in:
parent
415d565d72
commit
057033f2e3
5 changed files with 159 additions and 69 deletions
|
@ -38,9 +38,14 @@ enum E_OpType
|
|||
OP_FP_INV ,
|
||||
//
|
||||
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 );
|
||||
|
|
18
opast.cc
18
opast.cc
|
@ -125,10 +125,12 @@ A_Node* opast::ASTVisitorBrowser(
|
|||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// Argument node
|
||||
case A_Node::TN_ARG:
|
||||
{
|
||||
if ( child == 0 ) {
|
||||
return &( (T_CallInstrNode::T_Argument&) node ).expression( );
|
||||
return &( (T_ArgumentNode&) node ).expression( );
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -137,8 +139,9 @@ A_Node* opast::ASTVisitorBrowser(
|
|||
case A_Node::OP_CLEAR:
|
||||
{
|
||||
auto& n( (T_ClearInstrNode&) node );
|
||||
if ( child < n.components( ) ) {
|
||||
return &n.component( child );
|
||||
const auto nArgs( n.components( ) );
|
||||
if ( child < nArgs ) {
|
||||
return &n.component( nArgs - child - 1 );
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -197,9 +200,9 @@ A_Node* opast::ASTVisitorBrowser(
|
|||
{
|
||||
auto& n( (T_TextureInstrNode&) node );
|
||||
auto c = child;
|
||||
if ( n.hasWidth( ) ) {
|
||||
if ( n.lods( ) ) {
|
||||
if ( c == 0 ) {
|
||||
return &n.width( );
|
||||
return n.lods( );
|
||||
}
|
||||
c --;
|
||||
}
|
||||
|
@ -209,7 +212,10 @@ A_Node* opast::ASTVisitorBrowser(
|
|||
}
|
||||
c --;
|
||||
}
|
||||
return c == 0 ? n.lods( ) : nullptr;
|
||||
if ( n.hasWidth( ) && c == 0 ) {
|
||||
return &n.width( );
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Framebuffer definition; may have LOD expressions
|
||||
|
|
112
opast.hh
112
opast.hh
|
@ -193,6 +193,30 @@ class A_ExpressionNode : public A_Node
|
|||
};
|
||||
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 =================================================*/
|
||||
|
||||
|
@ -376,29 +400,10 @@ class T_FuncNode : public A_FuncNode
|
|||
// Function call
|
||||
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:
|
||||
T_String id_;
|
||||
T_SRDLocation idLocation_;
|
||||
T_AutoArray< T_OwnPtr< T_Argument > , 8 > arguments_;
|
||||
T_AutoArray< P_ArgumentNode , 8 > arguments_;
|
||||
|
||||
public:
|
||||
T_CallInstrNode( T_InstrListNode& parent ,
|
||||
|
@ -411,7 +416,7 @@ class T_CallInstrNode : public A_InstructionNode
|
|||
void addArgument( P_ExpressionNode expr ) noexcept
|
||||
{
|
||||
if ( expr ) {
|
||||
arguments_.add( NewOwned< T_Argument >(
|
||||
arguments_.add( NewOwned< T_ArgumentNode >(
|
||||
*this , std::move( expr ) ) );
|
||||
}
|
||||
}
|
||||
|
@ -423,7 +428,7 @@ class T_CallInstrNode : public A_InstructionNode
|
|||
|
||||
uint32_t arguments( ) const noexcept
|
||||
{ return arguments_.size( ); }
|
||||
T_Argument& argument( const uint32_t index ) const noexcept
|
||||
T_ArgumentNode& argument( const uint32_t index ) const noexcept
|
||||
{ return *arguments_[ index ]; }
|
||||
};
|
||||
|
||||
|
@ -840,9 +845,9 @@ class T_TextureInstrNode : public A_ResourceDefInstrNode
|
|||
{
|
||||
private:
|
||||
E_TexType type_;
|
||||
P_ExpressionNode width_;
|
||||
P_ExpressionNode height_;
|
||||
P_ExpressionNode lods_;
|
||||
P_ArgumentNode width_;
|
||||
P_ArgumentNode height_;
|
||||
P_ArgumentNode lods_;
|
||||
|
||||
public:
|
||||
T_TextureInstrNode(
|
||||
|
@ -854,23 +859,44 @@ class T_TextureInstrNode : public A_ResourceDefInstrNode
|
|||
type_( type )
|
||||
{ }
|
||||
|
||||
E_TexType texType( ) const noexcept
|
||||
{ return type_; }
|
||||
|
||||
void setWidth( P_ExpressionNode width ) noexcept
|
||||
{ width_ = std::move( width ); }
|
||||
bool hasWidth( ) const noexcept
|
||||
{ return bool( width_ ); }
|
||||
A_ExpressionNode& width( ) const noexcept
|
||||
{ return *width_; }
|
||||
{
|
||||
if ( width ) {
|
||||
width_ = NewOwned< T_ArgumentNode >(
|
||||
*this , std::move( width ) );
|
||||
}
|
||||
}
|
||||
|
||||
void setHeight( P_ExpressionNode height ) noexcept
|
||||
{ height_ = std::move( height ); }
|
||||
bool hasHeight( ) const noexcept
|
||||
{ return bool( height_ ); }
|
||||
A_ExpressionNode& height( ) const noexcept
|
||||
{ return *height_; }
|
||||
{
|
||||
if ( height ) {
|
||||
height_ = NewOwned< T_ArgumentNode >(
|
||||
*this , std::move( height ) );
|
||||
}
|
||||
}
|
||||
|
||||
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( ); }
|
||||
};
|
||||
|
||||
|
@ -944,7 +970,7 @@ class T_ProfileInstrNode : public A_InstructionNode
|
|||
class T_ClearInstrNode : public A_InstructionNode
|
||||
{
|
||||
private:
|
||||
T_StaticArray< P_ExpressionNode , 4 > components_;
|
||||
T_StaticArray< P_ArgumentNode , 4 > components_;
|
||||
|
||||
public:
|
||||
T_ClearInstrNode( T_InstrListNode& parent ) noexcept
|
||||
|
@ -953,12 +979,16 @@ class T_ClearInstrNode : public A_InstructionNode
|
|||
{ }
|
||||
|
||||
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
|
||||
{ return components_.size( ); }
|
||||
|
||||
A_ExpressionNode& component( const uint32_t index ) const noexcept
|
||||
T_ArgumentNode& component( const uint32_t index ) const noexcept
|
||||
{ return *components_[ index ]; }
|
||||
};
|
||||
|
||||
|
|
80
opcomp.cc
80
opcomp.cc
|
@ -330,6 +330,7 @@ bool T_CompilerImpl_::compileNode(
|
|||
break;
|
||||
}
|
||||
|
||||
|
||||
//- GENERAL / FLOW CONTROL INSTRUCTIONS -----------------------------------------------
|
||||
|
||||
case A_Node::OP_CALL:
|
||||
|
@ -346,23 +347,6 @@ bool T_CompilerImpl_::compileNode(
|
|||
sdMain -= args;
|
||||
}
|
||||
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:
|
||||
if ( exit ) {
|
||||
|
@ -465,11 +449,26 @@ bool T_CompilerImpl_::compileNode(
|
|||
if ( !output->progNames.contains( 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( ) );
|
||||
}
|
||||
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 -------------------------------------------------------------------------
|
||||
|
||||
case A_Node::OP_FULLSCREEN:
|
||||
|
@ -478,6 +477,50 @@ bool T_CompilerImpl_::compileNode(
|
|||
}
|
||||
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 -----------------------------------------------------------
|
||||
|
||||
case A_Node::EXPR_CMP_EQ: case A_Node::EXPR_CMP_NE:
|
||||
|
@ -511,6 +554,7 @@ bool T_CompilerImpl_::compileNode(
|
|||
}
|
||||
break;
|
||||
|
||||
|
||||
//- EXPRESSIONS - TERMINAL NODES ------------------------------------------------------
|
||||
|
||||
case A_Node::EXPR_CONST:
|
||||
|
|
9
ops.cc
9
ops.cc
|
@ -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_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_LOAD_PROGRAM , T_OpInfo{ "load-program" , 1 , OpStackMain{ -1 } } );
|
||||
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_TEXTURE , T_OpInfo{ "texture" , 2 , OpStackMain{ -3 } } );
|
||||
//
|
||||
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;
|
||||
})( ) };
|
||||
|
|
Loading…
Reference in a new issue