Parser - Call instruction
This commit is contained in:
parent
9ee16f6989
commit
3f32dd7f6f
2 changed files with 58 additions and 0 deletions
24
opast.cc
24
opast.cc
|
@ -302,6 +302,7 @@ namespace {
|
||||||
struct T_ParserImpl_
|
struct T_ParserImpl_
|
||||||
{
|
{
|
||||||
enum class E_InstrType {
|
enum class E_InstrType {
|
||||||
|
CALL ,
|
||||||
IF ,
|
IF ,
|
||||||
PIPELINE ,
|
PIPELINE ,
|
||||||
PROFILE ,
|
PROFILE ,
|
||||||
|
@ -316,6 +317,7 @@ struct T_ParserImpl_
|
||||||
temp.add( T_String::Pooled( name ) , it );
|
temp.add( T_String::Pooled( name ) , it );
|
||||||
} };
|
} };
|
||||||
|
|
||||||
|
add( "call" , E_InstrType::CALL );
|
||||||
add( "if" , E_InstrType::IF );
|
add( "if" , E_InstrType::IF );
|
||||||
add( "pipeline" , E_InstrType::PIPELINE );
|
add( "pipeline" , E_InstrType::PIPELINE );
|
||||||
add( "profiling" , E_InstrType::PROFILE );
|
add( "profiling" , E_InstrType::PROFILE );
|
||||||
|
@ -412,6 +414,9 @@ struct T_ParserImpl_
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
void parseCallInstruction(
|
||||||
|
T_InstrListNode& instructions ,
|
||||||
|
T_SRDList const& input ) noexcept;
|
||||||
void parseIfInstruction(
|
void parseIfInstruction(
|
||||||
T_InstrListNode& instructions ,
|
T_InstrListNode& instructions ,
|
||||||
T_SRDList const& input ) noexcept;
|
T_SRDList const& input ) noexcept;
|
||||||
|
@ -569,6 +574,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_( IF , If );
|
M_CASE_( IF , If );
|
||||||
M_CASE_( PIPELINE , Pipeline );
|
M_CASE_( PIPELINE , Pipeline );
|
||||||
M_CASE_( PROFILE , Profile );
|
M_CASE_( PROFILE , Profile );
|
||||||
|
@ -597,6 +603,24 @@ P_InstrListNode T_ParserImpl_::parseBlock(
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
void T_ParserImpl_::parseCallInstruction(
|
||||||
|
T_InstrListNode& instructions ,
|
||||||
|
T_SRDList const& input ) noexcept
|
||||||
|
{
|
||||||
|
if ( input.size( ) == 1 || input[ 1 ].type( ) != E_SRDTokenType::WORD ) {
|
||||||
|
errors.addNew( "function identifier expected" ,
|
||||||
|
input[ input.size( ) == 1 ? 0 : 1 ].location( ) );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto& instr{ instructions.add< T_CallInstrNode >( input[ 1 ] ) };
|
||||||
|
for ( auto it = input.begin( ) + 2 ; it.valid( ) ; ++it ) {
|
||||||
|
instr.addArgument( parseExpression( instr , *it ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
void T_ParserImpl_::parseIfInstruction(
|
void T_ParserImpl_::parseIfInstruction(
|
||||||
T_InstrListNode& instructions ,
|
T_InstrListNode& instructions ,
|
||||||
T_SRDList const& input ) noexcept
|
T_SRDList const& input ) noexcept
|
||||||
|
|
34
opast.hh
34
opast.hh
|
@ -23,6 +23,7 @@ class A_Node
|
||||||
DECL_FRAME , // Frame block
|
DECL_FRAME , // Frame block
|
||||||
DECL_FN , // Function
|
DECL_FN , // Function
|
||||||
//
|
//
|
||||||
|
OP_CALL , // Function call
|
||||||
OP_COND , // Conditional instruction
|
OP_COND , // Conditional instruction
|
||||||
OP_PIPELINE , // Shader pipeline declaration
|
OP_PIPELINE , // Shader pipeline declaration
|
||||||
OP_PROFILE , // Profiling block
|
OP_PROFILE , // Profiling block
|
||||||
|
@ -232,6 +233,39 @@ using P_ExpressionNode = T_OwnPtr< A_ExpressionNode >;
|
||||||
|
|
||||||
/*============================================================================*/
|
/*============================================================================*/
|
||||||
|
|
||||||
|
class T_CallInstrNode : public A_InstructionNode
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
T_String id_;
|
||||||
|
T_SRDLocation idLocation_;
|
||||||
|
T_AutoArray< P_ExpressionNode , 8 > arguments_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
T_CallInstrNode( T_InstrListNode& parent ,
|
||||||
|
T_SRDToken const& idToken ) noexcept
|
||||||
|
: A_InstructionNode( OP_CALL , parent ) ,
|
||||||
|
id_( idToken.stringValue( ) ) ,
|
||||||
|
idLocation_( idToken.location( ) )
|
||||||
|
{ }
|
||||||
|
|
||||||
|
void addArgument( P_ExpressionNode expr ) noexcept
|
||||||
|
{
|
||||||
|
if ( expr ) {
|
||||||
|
arguments_.add( std::move( expr ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
T_String const& id( ) const noexcept
|
||||||
|
{ return id_; }
|
||||||
|
T_SRDLocation const& idLocation( ) const noexcept
|
||||||
|
{ return idLocation_; }
|
||||||
|
|
||||||
|
uint32_t arguments( ) const noexcept
|
||||||
|
{ return arguments_.size( ); }
|
||||||
|
A_ExpressionNode& argument( const uint32_t index ) const noexcept
|
||||||
|
{ return *arguments_[ index ]; }
|
||||||
|
};
|
||||||
|
|
||||||
// Conditional instruction
|
// Conditional instruction
|
||||||
class T_CondInstrNode : public A_InstructionNode
|
class T_CondInstrNode : public A_InstructionNode
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue