Parser - Texture declaration instruction
This commit is contained in:
parent
a23dc75ec4
commit
9ee16f6989
2 changed files with 124 additions and 31 deletions
100
opast.cc
100
opast.cc
|
@ -1,3 +1,4 @@
|
||||||
|
#include "externals.hh"
|
||||||
#include "opast.hh"
|
#include "opast.hh"
|
||||||
|
|
||||||
using namespace ebcl;
|
using namespace ebcl;
|
||||||
|
@ -190,6 +191,19 @@ T_SetInstrNode::T_SetInstrNode(
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
|
||||||
|
/*= T_TextureInstrNode =======================================================*/
|
||||||
|
|
||||||
|
T_TextureInstrNode::T_TextureInstrNode(
|
||||||
|
T_InstrListNode& parent ,
|
||||||
|
T_SRDToken const& idToken ,
|
||||||
|
const E_TexType type ) noexcept
|
||||||
|
: A_InstructionNode( OP_PROGRAM , parent ) ,
|
||||||
|
id_( idToken.stringValue( ) ) ,
|
||||||
|
idLocation_( idToken.location( ) ) ,
|
||||||
|
type_( type )
|
||||||
|
{ }
|
||||||
|
|
||||||
|
|
||||||
/*= T_ConstantExprNode =======================================================*/
|
/*= T_ConstantExprNode =======================================================*/
|
||||||
|
|
||||||
T_ConstantExprNode::T_ConstantExprNode(
|
T_ConstantExprNode::T_ConstantExprNode(
|
||||||
|
@ -293,6 +307,7 @@ struct T_ParserImpl_
|
||||||
PROFILE ,
|
PROFILE ,
|
||||||
PROGRAM ,
|
PROGRAM ,
|
||||||
SET ,
|
SET ,
|
||||||
|
TEXTURE ,
|
||||||
};
|
};
|
||||||
|
|
||||||
const T_KeyValueTable< T_String , E_InstrType > instrMap{ ([]() {
|
const T_KeyValueTable< T_String , E_InstrType > instrMap{ ([]() {
|
||||||
|
@ -306,6 +321,7 @@ struct T_ParserImpl_
|
||||||
add( "profiling" , E_InstrType::PROFILE );
|
add( "profiling" , E_InstrType::PROFILE );
|
||||||
add( "program" , E_InstrType::PROGRAM );
|
add( "program" , E_InstrType::PROGRAM );
|
||||||
add( "set" , E_InstrType::SET );
|
add( "set" , E_InstrType::SET );
|
||||||
|
add( "texture" , E_InstrType::TEXTURE );
|
||||||
|
|
||||||
return temp;
|
return temp;
|
||||||
})( ) };
|
})( ) };
|
||||||
|
@ -330,6 +346,23 @@ struct T_ParserImpl_
|
||||||
return temp;
|
return temp;
|
||||||
})( ) };
|
})( ) };
|
||||||
|
|
||||||
|
const T_KeyValueTable< T_String , E_TexType > texTypeMap{ ([]() {
|
||||||
|
T_KeyValueTable< T_String , E_TexType > temp{ 64 , 16 , 16 };
|
||||||
|
const auto add{ [&temp]( char const* name ,
|
||||||
|
const E_TexType it ) {
|
||||||
|
temp.add( T_String::Pooled( name ) , it );
|
||||||
|
} };
|
||||||
|
|
||||||
|
add( "rgba-nu8" , E_TexType::RGBA8 );
|
||||||
|
add( "rgba-f16" , E_TexType::RGBA16F );
|
||||||
|
add( "rgb-nu8" , E_TexType::RGB8 );
|
||||||
|
add( "rgb-f16" , E_TexType::RGB16F );
|
||||||
|
add( "r-nu8" , E_TexType::R8 );
|
||||||
|
add( "r-f16" , E_TexType::R16F );
|
||||||
|
|
||||||
|
return temp;
|
||||||
|
})( ) };
|
||||||
|
|
||||||
const T_KeyValueTable< T_String , T_BinaryOperatorNode::E_Operator > binOpMap{ ([]() {
|
const T_KeyValueTable< T_String , T_BinaryOperatorNode::E_Operator > binOpMap{ ([]() {
|
||||||
T_KeyValueTable< T_String , T_BinaryOperatorNode::E_Operator > temp{ 64 , 32 , 32 };
|
T_KeyValueTable< T_String , T_BinaryOperatorNode::E_Operator > temp{ 64 , 32 , 32 };
|
||||||
const auto add{ [&temp]( char const* name ,
|
const auto add{ [&temp]( char const* name ,
|
||||||
|
@ -394,6 +427,9 @@ struct T_ParserImpl_
|
||||||
void parseSetInstruction(
|
void parseSetInstruction(
|
||||||
T_InstrListNode& instructions ,
|
T_InstrListNode& instructions ,
|
||||||
T_SRDList const& input ) noexcept;
|
T_SRDList const& input ) noexcept;
|
||||||
|
void parseTextureInstruction(
|
||||||
|
T_InstrListNode& instructions ,
|
||||||
|
T_SRDList const& input ) noexcept;
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -531,23 +567,16 @@ void T_ParserImpl_::parseInstructions(
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define M_CASE_( NAME , FNAME ) case E_InstrType::NAME: parse##FNAME##Instruction( instructions , ilist ); break
|
||||||
switch ( *instrMap.get( iword ) ) {
|
switch ( *instrMap.get( iword ) ) {
|
||||||
case E_InstrType::IF:
|
M_CASE_( IF , If );
|
||||||
parseIfInstruction( instructions , ilist );
|
M_CASE_( PIPELINE , Pipeline );
|
||||||
break;
|
M_CASE_( PROFILE , Profile );
|
||||||
case E_InstrType::PIPELINE:
|
M_CASE_( PROGRAM , Program );
|
||||||
parsePipelineInstruction( instructions , ilist );
|
M_CASE_( SET , Set );
|
||||||
break;
|
M_CASE_( TEXTURE , Texture );
|
||||||
case E_InstrType::PROFILE:
|
|
||||||
parseProfileInstruction( instructions , ilist );
|
|
||||||
break;
|
|
||||||
case E_InstrType::PROGRAM:
|
|
||||||
parseProgramInstruction( instructions , ilist );
|
|
||||||
break;
|
|
||||||
case E_InstrType::SET:
|
|
||||||
parseSetInstruction( instructions , ilist );
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
#undef M_CASE_
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -741,6 +770,47 @@ void T_ParserImpl_::parseSetInstruction(
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
void T_ParserImpl_::parseTextureInstruction(
|
||||||
|
T_InstrListNode& instructions ,
|
||||||
|
T_SRDList const& input ) noexcept
|
||||||
|
{
|
||||||
|
if ( input.size( ) < 2 || input[ 1 ].type( ) != E_SRDTokenType::WORD ) {
|
||||||
|
errors.addNew( "texture identifier expected" ,
|
||||||
|
( input.size( ) < 2 ? input[ 0 ] : input[ 1 ] ).location( ) );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ( input.size( ) < 3 || input[ 2 ].type( ) != E_SRDTokenType::WORD ) {
|
||||||
|
errors.addNew( "texture type expected" ,
|
||||||
|
( input.size( ) < 3 ? input[ 0 ] : input[ 2 ] ).location( ) );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto const* const ttt( texTypeMap.get( input[ 2 ].stringValue( ) ) );
|
||||||
|
if ( !ttt ) {
|
||||||
|
errors.addNew( "invalid texture type" ,
|
||||||
|
( input.size( ) < 3 ? input[ 0 ] : input[ 2 ] ).location( ) );
|
||||||
|
}
|
||||||
|
const auto tt( ttt ? *ttt : E_TexType::RGB8 );
|
||||||
|
|
||||||
|
auto& instr{ instructions.add< T_TextureInstrNode >( input[ 1 ] , tt ) };
|
||||||
|
instr.location( ) = input[ 0 ].location( );
|
||||||
|
if ( input.size( ) > 4 ) {
|
||||||
|
instr.setWidth( parseExpression( instr , input[ 3 ] ) );
|
||||||
|
} else {
|
||||||
|
errors.addNew( "width expected" , input[ 0 ].location( ) );
|
||||||
|
}
|
||||||
|
if ( input.size( ) > 4 ) {
|
||||||
|
instr.setHeight( parseExpression( instr , input[ 3 ] ) );
|
||||||
|
} else {
|
||||||
|
errors.addNew( "height expected" , input[ 0 ].location( ) );
|
||||||
|
}
|
||||||
|
if ( input.size( ) > 5 ) {
|
||||||
|
errors.addNew( "too many arguments" , input[ 5 ].location( ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
P_ExpressionNode T_ParserImpl_::parseExpression(
|
P_ExpressionNode T_ParserImpl_::parseExpression(
|
||||||
A_Node& parent ,
|
A_Node& parent ,
|
||||||
T_SRDToken const& token ) noexcept
|
T_SRDToken const& token ) noexcept
|
||||||
|
|
55
opast.hh
55
opast.hh
|
@ -1,8 +1,8 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
//#ifndef REAL_BUILD
|
#ifndef REAL_BUILD
|
||||||
# include "externals.hh"
|
# include "externals.hh"
|
||||||
//#endif
|
#endif
|
||||||
|
#include "texture.hh"
|
||||||
#include <ebcl/SRDData.hh>
|
#include <ebcl/SRDData.hh>
|
||||||
|
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@ class A_Node
|
||||||
OP_PROFILE , // Profiling block
|
OP_PROFILE , // Profiling block
|
||||||
OP_PROGRAM , // Shader program declaration
|
OP_PROGRAM , // Shader program declaration
|
||||||
OP_SET , // Set instruction
|
OP_SET , // Set instruction
|
||||||
|
OP_TEXTURE , // Define texture
|
||||||
// Unary operators
|
// Unary operators
|
||||||
EXPR_NEG , EXPR_INV , EXPR_NOT ,
|
EXPR_NEG , EXPR_INV , EXPR_NOT ,
|
||||||
EXPR_SIN , EXPR_COS , EXPR_TAN ,
|
EXPR_SIN , EXPR_COS , EXPR_TAN ,
|
||||||
|
@ -248,9 +249,7 @@ class T_CondInstrNode : public A_InstructionNode
|
||||||
{ expression_ = std::move( expression ); }
|
{ expression_ = std::move( expression ); }
|
||||||
bool hasExpression( ) const noexcept
|
bool hasExpression( ) const noexcept
|
||||||
{ return bool( expression_ ); }
|
{ return bool( expression_ ); }
|
||||||
A_ExpressionNode& expression( ) noexcept
|
A_ExpressionNode& expression( ) const noexcept
|
||||||
{ return *expression_; }
|
|
||||||
A_ExpressionNode const& expression( ) const noexcept
|
|
||||||
{ return *expression_; }
|
{ return *expression_; }
|
||||||
|
|
||||||
void setCase( const int64_t value ,
|
void setCase( const int64_t value ,
|
||||||
|
@ -268,18 +267,14 @@ class T_CondInstrNode : public A_InstructionNode
|
||||||
{ return cases_.keys( ); }
|
{ return cases_.keys( ); }
|
||||||
bool hasCase( const int64_t value ) const noexcept
|
bool hasCase( const int64_t value ) const noexcept
|
||||||
{ return cases_.contains( value ); }
|
{ return cases_.contains( value ); }
|
||||||
T_InstrListNode& getCase( const int64_t value ) noexcept
|
T_InstrListNode& getCase( const int64_t value ) const noexcept
|
||||||
{ return **cases_.get( value ); }
|
|
||||||
T_InstrListNode const& getCase( const int64_t value ) const noexcept
|
|
||||||
{ return **cases_.get( value ); }
|
{ return **cases_.get( value ); }
|
||||||
|
|
||||||
void setDefaultCase( P_InstrListNode defaultCase ) noexcept
|
void setDefaultCase( P_InstrListNode defaultCase ) noexcept
|
||||||
{ defaultCase_ = std::move( defaultCase ); }
|
{ defaultCase_ = std::move( defaultCase ); }
|
||||||
bool hasDefaultCase( ) const noexcept
|
bool hasDefaultCase( ) const noexcept
|
||||||
{ return bool( defaultCase_ ); }
|
{ return bool( defaultCase_ ); }
|
||||||
T_InstrListNode& defaultCase( ) noexcept
|
T_InstrListNode& defaultCase( ) const noexcept
|
||||||
{ return *defaultCase_; }
|
|
||||||
T_InstrListNode const& defaultCase( ) const noexcept
|
|
||||||
{ return *defaultCase_; }
|
{ return *defaultCase_; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -371,15 +366,43 @@ class T_SetInstrNode : public A_InstructionNode
|
||||||
|
|
||||||
void setExpression( P_ExpressionNode expression ) noexcept
|
void setExpression( P_ExpressionNode expression ) noexcept
|
||||||
{ expression_ = std::move( expression ); }
|
{ expression_ = std::move( expression ); }
|
||||||
|
|
||||||
bool hasExpression( ) const noexcept
|
bool hasExpression( ) const noexcept
|
||||||
{ return bool( expression_ ); }
|
{ return bool( expression_ ); }
|
||||||
A_ExpressionNode const& expression( ) const noexcept
|
A_ExpressionNode& expression( ) const noexcept
|
||||||
{ return *expression_; }
|
|
||||||
A_ExpressionNode& expression( ) noexcept
|
|
||||||
{ return *expression_; }
|
{ return *expression_; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Texture definition
|
||||||
|
class T_TextureInstrNode : public A_InstructionNode
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
T_String id_;
|
||||||
|
T_SRDLocation idLocation_;
|
||||||
|
E_TexType type_;
|
||||||
|
P_ExpressionNode width_;
|
||||||
|
P_ExpressionNode height_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
T_TextureInstrNode(
|
||||||
|
T_InstrListNode& parent ,
|
||||||
|
T_SRDToken const& id ,
|
||||||
|
E_TexType type ) noexcept;
|
||||||
|
|
||||||
|
void setWidth( P_ExpressionNode width ) noexcept
|
||||||
|
{ width_ = std::move( width ); }
|
||||||
|
bool hasWidth( ) const noexcept
|
||||||
|
{ return bool( width_ ); }
|
||||||
|
A_ExpressionNode& width( ) const noexcept
|
||||||
|
{ return *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_; }
|
||||||
|
};
|
||||||
|
|
||||||
/*============================================================================*/
|
/*============================================================================*/
|
||||||
|
|
||||||
// A constant value
|
// A constant value
|
||||||
|
|
Loading…
Reference in a new issue