Parser/compiler - Some refactoring

This commit is contained in:
Emmanuel BENOîT 2017-11-15 18:44:34 +01:00
parent b7f79c11b0
commit 0c9ca6c04e
7 changed files with 135 additions and 137 deletions

View file

@ -6,8 +6,6 @@ struct T_Rendertarget;
namespace ops { namespace ops {
using namespace ebcl;
enum E_OpType enum E_OpType
{ {
OP_END , OP_END ,
@ -89,18 +87,18 @@ struct T_Op
static constexpr int MAX_ARGS = 2; static constexpr int MAX_ARGS = 2;
E_OpType op; E_OpType op;
T_SRDLocation location; ebcl::T_SRDLocation location;
uint32_t args[ MAX_ARGS ]; uint32_t args[ MAX_ARGS ];
T_Op( const E_OpType op , T_Op( const E_OpType op ,
T_SRDLocation const& location , ebcl::T_SRDLocation const& location ,
const uint32_t arg0 = 0 ) noexcept const uint32_t arg0 = 0 ) noexcept
: op( op ) , location( location ) , : op( op ) , location( location ) ,
args{ arg0 } args{ arg0 }
{ } { }
T_Op( const E_OpType op , T_Op( const E_OpType op ,
T_SRDLocation const& location , ebcl::T_SRDLocation const& location ,
std::initializer_list< uint32_t > a ) noexcept std::initializer_list< uint32_t > a ) noexcept
: op( op ) , location( location ) : op( op ) , location( location )
{ {
@ -147,15 +145,6 @@ struct T_OpProgram
}; };
using P_OpProgram = T_OwnPtr< T_OpProgram >; using P_OpProgram = T_OwnPtr< T_OpProgram >;
class T_Compiler : public A_PrivateImplementation
{
public:
T_Compiler( ) noexcept;
P_OpProgram compile(
opast::T_ParserOutput const& input ) noexcept;
};
struct T_OpContext struct T_OpContext
{ {
@ -228,3 +217,12 @@ class X_OpFailure : public std::exception
}; };
} // namespace ops } // namespace ops
class T_OpsCompiler : public ebcl::A_PrivateImplementation
{
public:
T_OpsCompiler( ) noexcept;
ops::P_OpProgram compile( T_OpsParserOutput const& input ) noexcept;
};

View file

@ -133,10 +133,10 @@ bool T_Demo::loadProgram( )
} }
// Parse the fuck // Parse the fuck
opast::T_Parser parser; T_OpsParser parser;
if ( parser.parse( srdOut.list( ) ) ) { if ( parser.parse( srdOut.list( ) ) ) {
printf( "Parser successful. Compiling...\n" ); printf( "Parser successful. Compiling...\n" );
ops::T_Compiler compiler; T_OpsCompiler compiler;
program = compiler.compile( *parser.result( ) ); program = compiler.compile( *parser.result( ) );
return true; return true;
} }

View file

@ -42,12 +42,15 @@ using ebcl::NewOwned;
using ebcl::T_SharedPtr; using ebcl::T_SharedPtr;
using ebcl::NewShared; using ebcl::NewShared;
using ebcl::T_Flags;
using ebcl::T_Optional; using ebcl::T_Optional;
using ebcl::T_Union; using ebcl::T_Union;
using ebcl::T_Variant; using ebcl::T_Variant;
using ebcl::T_Array; using ebcl::T_Array;
using ebcl::T_AutoArray; using ebcl::T_AutoArray;
using ebcl::T_StaticArray;
using ebcl::T_MultiArray;
using ebcl::T_String; using ebcl::T_String;
using ebcl::T_StringBuilder; using ebcl::T_StringBuilder;

206
opast.hh
View file

@ -6,8 +6,6 @@
namespace opast { namespace opast {
using namespace ebcl;
/*= BASE CLASS FOR AST NODES ===================================================*/ /*= BASE CLASS FOR AST NODES ===================================================*/
@ -73,7 +71,7 @@ class A_Node
private: private:
const E_Type type_; const E_Type type_;
A_Node* const parent_; A_Node* const parent_;
T_SRDLocation location_; ebcl::T_SRDLocation location_;
protected: protected:
explicit A_Node( const E_Type type , explicit A_Node( const E_Type type ,
@ -85,9 +83,9 @@ class A_Node
E_Type type( ) const noexcept E_Type type( ) const noexcept
{ return type_; } { return type_; }
T_SRDLocation& location( ) noexcept ebcl::T_SRDLocation& location( ) noexcept
{ return location_; } { return location_; }
T_SRDLocation const& location( ) const noexcept ebcl::T_SRDLocation const& location( ) const noexcept
{ return location_; } { return location_; }
A_Node& parent( ) const noexcept A_Node& parent( ) const noexcept
@ -232,12 +230,12 @@ class A_FuncNode : public A_Node
struct T_Local_ struct T_Local_
{ {
T_String name; T_String name;
T_SRDLocation location; ebcl::T_SRDLocation location;
bool argument; bool argument;
E_DataType type{ E_DataType::UNKNOWN }; E_DataType type{ E_DataType::UNKNOWN };
T_Local_( T_String const& name , T_Local_( T_String const& name ,
T_SRDLocation const& location , ebcl::T_SRDLocation const& location ,
const bool argument ) noexcept const bool argument ) noexcept
: name{ name } , location{ location } , : name{ name } , location{ location } ,
argument{ argument } argument{ argument }
@ -271,9 +269,9 @@ class A_FuncNode : public A_Node
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
T_Optional< T_SRDLocation > addLocalVariable( T_Optional< ebcl::T_SRDLocation > addLocalVariable(
T_String const& name , T_String const& name ,
T_SRDLocation const& location ) noexcept; ebcl::T_SRDLocation const& location ) noexcept;
uint32_t locals( ) const noexcept uint32_t locals( ) const noexcept
{ return locals_.size( ); } { return locals_.size( ); }
@ -329,14 +327,14 @@ class T_RootNode : public A_Node
struct T_AddFunctionResult struct T_AddFunctionResult
{ {
A_FuncNode& function; A_FuncNode& function;
T_Optional< T_SRDLocation > dupLocation; T_Optional< ebcl::T_SRDLocation > dupLocation;
T_AddFunctionResult( A_FuncNode& function ) noexcept T_AddFunctionResult( A_FuncNode& function ) noexcept
: function{ function } , dupLocation{} : function{ function } , dupLocation{}
{} {}
T_AddFunctionResult( A_FuncNode& function , T_AddFunctionResult( A_FuncNode& function ,
T_SRDLocation const& dupLocation ) noexcept ebcl::T_SRDLocation const& dupLocation ) noexcept
: function{ function } , dupLocation{ dupLocation } : function{ function } , dupLocation{ dupLocation }
{} {}
}; };
@ -389,8 +387,8 @@ class T_FuncNode : public A_FuncNode
// Add an argument. If the argument is a duplicate, return the location // Add an argument. If the argument is a duplicate, return the location
// of the initial argument. // of the initial argument.
T_Optional< T_SRDLocation > addArgument( T_Optional< ebcl::T_SRDLocation > addArgument(
T_SRDToken const& token ) noexcept; ebcl::T_SRDToken const& token ) noexcept;
uint32_t arguments( ) const noexcept; uint32_t arguments( ) const noexcept;
}; };
@ -403,12 +401,12 @@ class T_CallInstrNode : public A_InstructionNode
{ {
private: private:
T_String id_; T_String id_;
T_SRDLocation idLocation_; ebcl::T_SRDLocation idLocation_;
T_AutoArray< P_ArgumentNode , 8 > arguments_; T_AutoArray< P_ArgumentNode , 8 > arguments_;
public: public:
T_CallInstrNode( T_InstrListNode& parent , T_CallInstrNode( T_InstrListNode& parent ,
T_SRDToken const& idToken ) noexcept ebcl::T_SRDToken const& idToken ) noexcept
: A_InstructionNode( OP_CALL , parent ) , : A_InstructionNode( OP_CALL , parent ) ,
id_( idToken.stringValue( ) ) , id_( idToken.stringValue( ) ) ,
idLocation_( idToken.location( ) ) idLocation_( idToken.location( ) )
@ -424,7 +422,7 @@ class T_CallInstrNode : public A_InstructionNode
T_String const& id( ) const noexcept T_String const& id( ) const noexcept
{ return id_; } { return id_; }
T_SRDLocation const& idLocation( ) const noexcept ebcl::T_SRDLocation const& idLocation( ) const noexcept
{ return idLocation_; } { return idLocation_; }
uint32_t arguments( ) const noexcept uint32_t arguments( ) const noexcept
@ -539,15 +537,15 @@ class T_LocalsInstrNode : public A_InstructionNode
{ {
private: private:
T_AutoArray< T_String , 8 > vars_; T_AutoArray< T_String , 8 > vars_;
T_AutoArray< T_SRDLocation , 8 > varLocs_; T_AutoArray< ebcl::T_SRDLocation , 8 > varLocs_;
public: public:
T_LocalsInstrNode( T_InstrListNode& parent ) noexcept T_LocalsInstrNode( T_InstrListNode& parent ) noexcept
: A_InstructionNode( OP_LOCALS , parent ) : A_InstructionNode( OP_LOCALS , parent )
{ } { }
T_Optional< T_SRDLocation > addVariable( T_Optional< ebcl::T_SRDLocation > addVariable(
T_SRDToken const& token ) noexcept; ebcl::T_SRDToken const& token ) noexcept;
uint32_t variables( ) const noexcept uint32_t variables( ) const noexcept
{ return vars_.size( ); } { return vars_.size( ); }
@ -556,7 +554,7 @@ class T_LocalsInstrNode : public A_InstructionNode
const uint32_t index ) const noexcept const uint32_t index ) const noexcept
{ return vars_[ index ]; } { return vars_[ index ]; }
T_SRDLocation const& varLocation( ebcl::T_SRDLocation const& varLocation(
const uint32_t index ) const noexcept const uint32_t index ) const noexcept
{ return varLocs_[ index ]; } { return varLocs_[ index ]; }
}; };
@ -566,12 +564,12 @@ class T_SetInstrNode : public A_InstructionNode
{ {
private: private:
T_String id_; T_String id_;
T_SRDLocation idLocation_; ebcl::T_SRDLocation idLocation_;
P_ExpressionNode expression_; P_ExpressionNode expression_;
public: public:
T_SetInstrNode( T_InstrListNode& parent , T_SetInstrNode( T_InstrListNode& parent ,
T_SRDToken const& idToken ) noexcept ebcl::T_SRDToken const& idToken ) noexcept
: A_InstructionNode( OP_SET , parent ) , : A_InstructionNode( OP_SET , parent ) ,
id_( idToken.stringValue( ) ) , id_( idToken.stringValue( ) ) ,
idLocation_( idToken.location( ) ) idLocation_( idToken.location( ) )
@ -579,7 +577,7 @@ class T_SetInstrNode : public A_InstructionNode
T_String const& id( ) const noexcept T_String const& id( ) const noexcept
{ return id_; } { return id_; }
T_SRDLocation const& idLocation( ) const noexcept ebcl::T_SRDLocation const& idLocation( ) const noexcept
{ return idLocation_; } { return idLocation_; }
void setExpression( P_ExpressionNode expression ) noexcept void setExpression( P_ExpressionNode expression ) noexcept
@ -598,14 +596,14 @@ class A_ResourceDefInstrNode : public A_InstructionNode
{ {
private: private:
T_String id_; T_String id_;
T_SRDLocation idLocation_; ebcl::T_SRDLocation idLocation_;
E_DataType dataType_; E_DataType dataType_;
protected: protected:
A_ResourceDefInstrNode( A_ResourceDefInstrNode(
const E_Type type , const E_Type type ,
T_InstrListNode& parent , T_InstrListNode& parent ,
T_SRDToken const& identifier , ebcl::T_SRDToken const& identifier ,
const E_DataType dataType ) noexcept const E_DataType dataType ) noexcept
: A_InstructionNode( type , parent , E_InstrRestriction::FRAME ) , : A_InstructionNode( type , parent , E_InstrRestriction::FRAME ) ,
id_( identifier.stringValue( ) ) , id_( identifier.stringValue( ) ) ,
@ -616,7 +614,7 @@ class A_ResourceDefInstrNode : public A_InstructionNode
public: public:
T_String const& id( ) const noexcept T_String const& id( ) const noexcept
{ return id_; } { return id_; }
T_SRDLocation const& idLocation( ) const noexcept ebcl::T_SRDLocation const& idLocation( ) const noexcept
{ return idLocation_; } { return idLocation_; }
E_DataType dataType( ) const noexcept E_DataType dataType( ) const noexcept
@ -639,7 +637,7 @@ class T_FramebufferInstrNode : public A_ResourceDefInstrNode
public: public:
T_Attachment( T_FramebufferInstrNode& parent , T_Attachment( T_FramebufferInstrNode& parent ,
const bool depth , const bool depth ,
T_SRDToken const& texId , ebcl::T_SRDToken const& texId ,
P_ExpressionNode lod = { } ) noexcept P_ExpressionNode lod = { } ) noexcept
: A_Node( TN_FBATT , &parent ) , : A_Node( TN_FBATT , &parent ) ,
depth_( depth ) , depth_( depth ) ,
@ -670,14 +668,14 @@ class T_FramebufferInstrNode : public A_ResourceDefInstrNode
public: public:
T_FramebufferInstrNode( T_InstrListNode& parent , T_FramebufferInstrNode( T_InstrListNode& parent ,
T_SRDToken const& identifier ) noexcept ebcl::T_SRDToken const& identifier ) noexcept
: A_ResourceDefInstrNode( OP_FRAMEBUFFER , parent , : A_ResourceDefInstrNode( OP_FRAMEBUFFER , parent ,
identifier , E_DataType::FRAMEBUFFER ) identifier , E_DataType::FRAMEBUFFER )
{ } { }
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
bool addColorAttachment( T_SRDToken const& id , bool addColorAttachment( ebcl::T_SRDToken const& id ,
P_ExpressionNode lod = {} ) noexcept; P_ExpressionNode lod = {} ) noexcept;
uint32_t colorAttachments( ) const noexcept uint32_t colorAttachments( ) const noexcept
@ -689,7 +687,7 @@ class T_FramebufferInstrNode : public A_ResourceDefInstrNode
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
bool setDepthAttachment( T_SRDToken const& token , bool setDepthAttachment( ebcl::T_SRDToken const& token ,
P_ExpressionNode lod = {} ) noexcept; P_ExpressionNode lod = {} ) noexcept;
T_Attachment* depthAttachment( ) const noexcept T_Attachment* depthAttachment( ) const noexcept
@ -701,18 +699,18 @@ class T_InputInstrNode : public A_ResourceDefInstrNode
{ {
private: private:
float defValue_; float defValue_;
T_SRDLocation dvLocation_; ebcl::T_SRDLocation dvLocation_;
public: public:
T_InputInstrNode( T_InstrListNode& parent , T_InputInstrNode( T_InstrListNode& parent ,
T_SRDToken const& tName ) noexcept ebcl::T_SRDToken const& tName ) noexcept
: A_ResourceDefInstrNode( OP_INPUT , parent , : A_ResourceDefInstrNode( OP_INPUT , parent ,
tName , E_DataType::INPUT ) tName , E_DataType::INPUT )
{} {}
T_InputInstrNode( T_InstrListNode& parent , T_InputInstrNode( T_InstrListNode& parent ,
T_SRDToken const& tName , ebcl::T_SRDToken const& tName ,
T_SRDToken const& tDefault ) noexcept ebcl::T_SRDToken const& tDefault ) noexcept
: A_ResourceDefInstrNode( OP_INPUT , parent , : A_ResourceDefInstrNode( OP_INPUT , parent ,
tName , E_DataType::INPUT ) , tName , E_DataType::INPUT ) ,
defValue_( tDefault.floatValue( ) ) , dvLocation_( tDefault.location( ) ) defValue_( tDefault.floatValue( ) ) , dvLocation_( tDefault.location( ) )
@ -720,7 +718,7 @@ class T_InputInstrNode : public A_ResourceDefInstrNode
float defValue( ) const noexcept float defValue( ) const noexcept
{ return defValue_; } { return defValue_; }
T_SRDLocation const& defValueLocation( ) const noexcept ebcl::T_SRDLocation const& defValueLocation( ) const noexcept
{ return dvLocation_; } { return dvLocation_; }
}; };
@ -729,12 +727,12 @@ class T_PipelineInstrNode : public A_ResourceDefInstrNode
{ {
private: private:
T_StaticArray< T_String , 6 > pids_; T_StaticArray< T_String , 6 > pids_;
T_StaticArray< T_SRDLocation , 6 > pidLocations_; T_StaticArray< ebcl::T_SRDLocation , 6 > pidLocations_;
public: public:
T_PipelineInstrNode( T_PipelineInstrNode(
T_InstrListNode& parent , T_InstrListNode& parent ,
T_SRDToken const& idToken ) noexcept ebcl::T_SRDToken const& idToken ) noexcept
: A_ResourceDefInstrNode( OP_PIPELINE , parent , : A_ResourceDefInstrNode( OP_PIPELINE , parent ,
idToken , E_DataType::PIPELINE ) idToken , E_DataType::PIPELINE )
{ } { }
@ -743,15 +741,15 @@ class T_PipelineInstrNode : public A_ResourceDefInstrNode
// and the list of programs is assumed not to be full. If the identifer // and the list of programs is assumed not to be full. If the identifer
// is already in the pipeline's list, the location of the first // is already in the pipeline's list, the location of the first
// occurrence will be returned. // occurrence will be returned.
T_Optional< T_SRDLocation > addProgram( T_Optional< ebcl::T_SRDLocation > addProgram(
T_SRDToken const& pidToken ) noexcept; ebcl::T_SRDToken const& pidToken ) noexcept;
uint32_t size( ) const noexcept uint32_t size( ) const noexcept
{ return pids_.size( ); } { return pids_.size( ); }
T_String const& program( const uint32_t index ) const noexcept T_String const& program( const uint32_t index ) const noexcept
{ return pids_[ index ]; } { return pids_[ index ]; }
T_SRDLocation const& pLocation( const uint32_t index ) const noexcept ebcl::T_SRDLocation const& pLocation( const uint32_t index ) const noexcept
{ return pidLocations_[ index ]; } { return pidLocations_[ index ]; }
}; };
@ -760,13 +758,13 @@ class T_ProgramInstrNode : public A_ResourceDefInstrNode
{ {
private: private:
T_String path_; T_String path_;
T_SRDLocation pathLocation_; ebcl::T_SRDLocation pathLocation_;
public: public:
T_ProgramInstrNode( T_ProgramInstrNode(
T_InstrListNode& parent , T_InstrListNode& parent ,
T_SRDToken const& idToken , ebcl::T_SRDToken const& idToken ,
T_SRDToken const& pathToken ) noexcept ebcl::T_SRDToken const& pathToken ) noexcept
: A_ResourceDefInstrNode( OP_PROGRAM , parent , : A_ResourceDefInstrNode( OP_PROGRAM , parent ,
idToken , E_DataType::PROGRAM ) , idToken , E_DataType::PROGRAM ) ,
path_( pathToken.stringValue( ) ) , path_( pathToken.stringValue( ) ) ,
@ -775,7 +773,7 @@ class T_ProgramInstrNode : public A_ResourceDefInstrNode
T_String const& path( ) const noexcept T_String const& path( ) const noexcept
{ return path_; } { return path_; }
T_SRDLocation const& pathLocation( ) const noexcept ebcl::T_SRDLocation const& pathLocation( ) const noexcept
{ return pathLocation_; } { return pathLocation_; }
}; };
@ -785,25 +783,25 @@ class T_SamplerInstrNode : public A_ResourceDefInstrNode
private: private:
struct T_Sampling_ struct T_Sampling_
{ {
T_SRDLocation location; ebcl::T_SRDLocation location;
E_TexSampling mode; E_TexSampling mode;
}; };
struct T_Mipmaps_ struct T_Mipmaps_
{ {
T_SRDLocation location; ebcl::T_SRDLocation location;
T_Optional< E_TexSampling > mode; T_Optional< E_TexSampling > mode;
}; };
struct T_Wrapping_ struct T_Wrapping_
{ {
T_SRDLocation location; ebcl::T_SRDLocation location;
E_TexWrap mode; E_TexWrap mode;
}; };
struct T_LOD_ struct T_LOD_
{ {
T_SRDLocation location; ebcl::T_SRDLocation location;
P_ArgumentNode min; P_ArgumentNode min;
P_ArgumentNode max; P_ArgumentNode max;
}; };
@ -816,7 +814,7 @@ class T_SamplerInstrNode : public A_ResourceDefInstrNode
public: public:
T_SamplerInstrNode( T_SamplerInstrNode(
T_InstrListNode& parent , T_InstrListNode& parent ,
T_SRDToken const& id ) noexcept ebcl::T_SRDToken const& id ) noexcept
: A_ResourceDefInstrNode( OP_SAMPLER , parent , : A_ResourceDefInstrNode( OP_SAMPLER , parent ,
id , E_DataType::SAMPLER ) id , E_DataType::SAMPLER )
{ } { }
@ -824,19 +822,19 @@ class T_SamplerInstrNode : public A_ResourceDefInstrNode
// Attempt to set sampling mode, mipmap mode, wrapping mode or // Attempt to set sampling mode, mipmap mode, wrapping mode or
// LOD minimal/maximal, returning the location of the previous // LOD minimal/maximal, returning the location of the previous
// definition if there was one. // definition if there was one.
T_Optional< T_SRDLocation > setSampling( T_Optional< ebcl::T_SRDLocation > setSampling(
E_TexSampling mode , E_TexSampling mode ,
T_SRDLocation const& location ) noexcept; ebcl::T_SRDLocation const& location ) noexcept;
T_Optional< T_SRDLocation > setMipmapSampling( T_Optional< ebcl::T_SRDLocation > setMipmapSampling(
E_TexSampling mode , E_TexSampling mode ,
T_SRDLocation const& location ) noexcept; ebcl::T_SRDLocation const& location ) noexcept;
T_Optional< T_SRDLocation > setNoMipmap( T_Optional< ebcl::T_SRDLocation > setNoMipmap(
T_SRDLocation const& location ) noexcept; ebcl::T_SRDLocation const& location ) noexcept;
T_Optional< T_SRDLocation > setWrapping( T_Optional< ebcl::T_SRDLocation > setWrapping(
E_TexWrap mode , E_TexWrap mode ,
T_SRDLocation const& location ) noexcept; ebcl::T_SRDLocation const& location ) noexcept;
T_Optional< T_SRDLocation > setLOD( T_Optional< ebcl::T_SRDLocation > setLOD(
T_SRDLocation const& location , ebcl::T_SRDLocation const& location ,
P_ExpressionNode min , P_ExpressionNode min ,
P_ExpressionNode max ) noexcept; P_ExpressionNode max ) noexcept;
@ -865,7 +863,7 @@ class T_TextureInstrNode : public A_ResourceDefInstrNode
public: public:
T_TextureInstrNode( T_TextureInstrNode(
T_InstrListNode& parent , T_InstrListNode& parent ,
T_SRDToken const& id , ebcl::T_SRDToken const& id ,
E_TexType type ) noexcept E_TexType type ) noexcept
: A_ResourceDefInstrNode( OP_TEXTURE , parent , : A_ResourceDefInstrNode( OP_TEXTURE , parent ,
id , E_DataType::TEXTURE ) , id , E_DataType::TEXTURE ) ,
@ -921,33 +919,33 @@ class T_OutputDebugInstrNode : public A_InstructionNode
{ {
private: private:
T_String idTexture_; T_String idTexture_;
T_SRDLocation locTexture_; ebcl::T_SRDLocation locTexture_;
E_ODbgMode mode_; E_ODbgMode mode_;
T_SRDLocation locMode_; ebcl::T_SRDLocation locMode_;
T_String description_; T_String description_;
T_SRDLocation locDescription_; ebcl::T_SRDLocation locDescription_;
public: public:
T_OutputDebugInstrNode( T_OutputDebugInstrNode(
T_InstrListNode& parent , T_InstrListNode& parent ,
T_SRDToken const& texture , ebcl::T_SRDToken const& texture ,
const E_ODbgMode mode , const E_ODbgMode mode ,
T_SRDLocation const& modeLocation , ebcl::T_SRDLocation const& modeLocation ,
T_SRDToken const& description ) noexcept; ebcl::T_SRDToken const& description ) noexcept;
T_String const& texture( ) const noexcept T_String const& texture( ) const noexcept
{ return idTexture_; } { return idTexture_; }
T_SRDLocation const& textureLocation( ) const noexcept ebcl::T_SRDLocation const& textureLocation( ) const noexcept
{ return locTexture_; } { return locTexture_; }
E_ODbgMode mode( ) const noexcept E_ODbgMode mode( ) const noexcept
{ return mode_; } { return mode_; }
T_SRDLocation const& modeLocation( ) const noexcept ebcl::T_SRDLocation const& modeLocation( ) const noexcept
{ return locMode_; } { return locMode_; }
T_String const& description( ) const noexcept T_String const& description( ) const noexcept
{ return description_; } { return description_; }
T_SRDLocation const& descriptionLocation( ) const noexcept ebcl::T_SRDLocation const& descriptionLocation( ) const noexcept
{ return locDescription_; } { return locDescription_; }
}; };
@ -1029,16 +1027,16 @@ class T_UniformsInstrNode : public A_InstructionNode
private: private:
bool integers_; bool integers_;
T_String progId_; T_String progId_;
T_SRDLocation progIdLocation_; ebcl::T_SRDLocation progIdLocation_;
uint32_t uloc_; uint32_t uloc_;
T_SRDLocation ulocLocation_; ebcl::T_SRDLocation ulocLocation_;
T_StaticArray< P_ArgumentNode , 4 > values_; T_StaticArray< P_ArgumentNode , 4 > values_;
public: public:
T_UniformsInstrNode( T_InstrListNode& parent , T_UniformsInstrNode( T_InstrListNode& parent ,
const bool integers , const bool integers ,
T_SRDToken const& prog , ebcl::T_SRDToken const& prog ,
T_SRDToken const& loc ) noexcept ebcl::T_SRDToken const& loc ) noexcept
: A_InstructionNode( OP_UNIFORMS , parent ) , integers_( integers ) , : A_InstructionNode( OP_UNIFORMS , parent ) , integers_( integers ) ,
progId_( prog.stringValue( ) ) , progIdLocation_( prog.location( ) ) , progId_( prog.stringValue( ) ) , progIdLocation_( prog.location( ) ) ,
uloc_( loc.longValue( ) ) , ulocLocation_( loc.location( ) ) uloc_( loc.longValue( ) ) , ulocLocation_( loc.location( ) )
@ -1049,12 +1047,12 @@ class T_UniformsInstrNode : public A_InstructionNode
T_String const& progId( ) const noexcept T_String const& progId( ) const noexcept
{ return progId_; } { return progId_; }
T_SRDLocation const& progIdLocation( ) const noexcept ebcl::T_SRDLocation const& progIdLocation( ) const noexcept
{ return progIdLocation_; } { return progIdLocation_; }
uint32_t uloc( ) const noexcept uint32_t uloc( ) const noexcept
{ return uloc_; } { return uloc_; }
T_SRDLocation const& ulocLocation( ) const noexcept ebcl::T_SRDLocation const& ulocLocation( ) const noexcept
{ return ulocLocation_; } { return ulocLocation_; }
void addValue( P_ExpressionNode value ) noexcept void addValue( P_ExpressionNode value ) noexcept
@ -1082,12 +1080,12 @@ class T_UseInstrNode : public A_InstructionNode
private: private:
T_String id_; T_String id_;
T_SRDLocation idLocation_; ebcl::T_SRDLocation idLocation_;
public: public:
T_UseInstrNode( T_InstrListNode& parent , T_UseInstrNode( T_InstrListNode& parent ,
const E_Type type , const E_Type type ,
T_SRDToken const& identifier ) noexcept ebcl::T_SRDToken const& identifier ) noexcept
: A_InstructionNode( ([type]() { : A_InstructionNode( ([type]() {
switch ( type ) { switch ( type ) {
case FRAMEBUFFER: return OP_USE_FRAMEBUFFER; case FRAMEBUFFER: return OP_USE_FRAMEBUFFER;
@ -1103,7 +1101,7 @@ class T_UseInstrNode : public A_InstructionNode
T_String const& id( ) const noexcept T_String const& id( ) const noexcept
{ return id_; } { return id_; }
T_SRDLocation const& idLocation( ) const noexcept ebcl::T_SRDLocation const& idLocation( ) const noexcept
{ return idLocation_; } { return idLocation_; }
}; };
@ -1112,15 +1110,15 @@ class T_UseTextureInstrNode : public T_UseInstrNode
{ {
private: private:
uint32_t bank_; uint32_t bank_;
T_SRDLocation bankLocation_; ebcl::T_SRDLocation bankLocation_;
T_String samplerId_; T_String samplerId_;
T_SRDLocation samplerIdLocation_; ebcl::T_SRDLocation samplerIdLocation_;
public: public:
T_UseTextureInstrNode( T_InstrListNode& parent , T_UseTextureInstrNode( T_InstrListNode& parent ,
T_SRDToken const& bank , ebcl::T_SRDToken const& bank ,
T_SRDToken const& identifier , ebcl::T_SRDToken const& identifier ,
T_SRDToken const& sampler ) noexcept ebcl::T_SRDToken const& sampler ) noexcept
: T_UseInstrNode( parent , TEXTURE , identifier ) , : T_UseInstrNode( parent , TEXTURE , identifier ) ,
bank_( bank.longValue( ) ) , bank_( bank.longValue( ) ) ,
bankLocation_( bank.location( ) ) , bankLocation_( bank.location( ) ) ,
@ -1130,12 +1128,12 @@ class T_UseTextureInstrNode : public T_UseInstrNode
uint32_t bank( ) const noexcept uint32_t bank( ) const noexcept
{ return bank_; } { return bank_; }
T_SRDLocation const& bankLocation( ) const noexcept ebcl::T_SRDLocation const& bankLocation( ) const noexcept
{ return bankLocation_; } { return bankLocation_; }
T_String const& samplerId( ) const noexcept T_String const& samplerId( ) const noexcept
{ return samplerId_; } { return samplerId_; }
T_SRDLocation const& samplerIdLocation( ) const noexcept ebcl::T_SRDLocation const& samplerIdLocation( ) const noexcept
{ return samplerIdLocation_; } { return samplerIdLocation_; }
}; };
@ -1183,9 +1181,9 @@ class T_ConstantExprNode : public A_ExpressionNode
public: public:
T_ConstantExprNode( A_Node& parent , T_ConstantExprNode( A_Node& parent ,
T_SRDToken const& token ) noexcept ebcl::T_SRDToken const& token ) noexcept
: A_ExpressionNode( EXPR_CONST , parent ) , : A_ExpressionNode( EXPR_CONST , parent ) ,
wasFloat_( token.type( ) == E_SRDTokenType::FLOAT ) , wasFloat_( token.type( ) == ebcl::E_SRDTokenType::FLOAT ) ,
vFloat_( token.floatValue( ) ) , vFloat_( token.floatValue( ) ) ,
vInt_( token.longValue( ) ) vInt_( token.longValue( ) )
{ location( ) = token.location( ); } { location( ) = token.location( ); }
@ -1218,7 +1216,7 @@ class T_IdentifierExprNode : public A_ExpressionNode
public: public:
T_IdentifierExprNode( A_Node& parent , T_IdentifierExprNode( A_Node& parent ,
T_SRDToken const& token ) noexcept ebcl::T_SRDToken const& token ) noexcept
: T_IdentifierExprNode( parent , token.stringValue( ) ) : T_IdentifierExprNode( parent , token.stringValue( ) )
{ location( ) = token.location( ); } { location( ) = token.location( ); }
@ -1236,11 +1234,11 @@ class T_InputExprNode : public A_ExpressionNode
{ {
private: private:
T_String id_; T_String id_;
T_SRDLocation idLocation_; ebcl::T_SRDLocation idLocation_;
public: public:
T_InputExprNode( A_Node& parent , T_InputExprNode( A_Node& parent ,
T_SRDToken const& token ) noexcept ebcl::T_SRDToken const& token ) noexcept
: A_ExpressionNode( EXPR_INPUT , parent ) , : A_ExpressionNode( EXPR_INPUT , parent ) ,
id_( token.stringValue( ) ) , id_( token.stringValue( ) ) ,
idLocation_( token.location( ) ) idLocation_( token.location( ) )
@ -1248,7 +1246,7 @@ class T_InputExprNode : public A_ExpressionNode
T_String const& id( ) const noexcept T_String const& id( ) const noexcept
{ return id_; } { return id_; }
T_SRDLocation const& idLocation( ) const noexcept ebcl::T_SRDLocation const& idLocation( ) const noexcept
{ return idLocation_; } { return idLocation_; }
}; };
@ -1335,33 +1333,33 @@ class T_BinaryOperatorNode : public A_ExpressionNode
}; };
} // namespace opast
/*= PARSER ===================================================================*/ /*= PARSER ===================================================================*/
// Parser output. Consists in a root node as well as other details (table of // Parser output. Consists in a root node as well as other details (table of
// constants, data types, etc...) // constants, data types, etc...)
struct T_ParserOutput struct T_OpsParserOutput
{ {
T_RootNode root; opast::T_RootNode root;
T_KeyValueTable< T_String , E_DataType > types; T_KeyValueTable< T_String , opast::E_DataType > types;
}; };
// The actual parser // The actual parser
class T_Parser : public A_PrivateImplementation class T_OpsParser : public ebcl::A_PrivateImplementation
{ {
private: private:
T_Array< T_SRDError > errors_; T_Array< ebcl::T_SRDError > errors_;
T_OwnPtr< T_ParserOutput > output_; T_OwnPtr< T_OpsParserOutput > output_;
public: public:
T_Parser( ) noexcept; T_OpsParser( ) noexcept;
bool parse( T_SRDList const& input ) noexcept; bool parse( ebcl::T_SRDList const& input ) noexcept;
T_Array< T_SRDError > const& errors( ) const noexcept T_Array< ebcl::T_SRDError > const& errors( ) const noexcept
{ return errors_; } { return errors_; }
T_OwnPtr< T_ParserOutput > result( ) noexcept T_OwnPtr< T_OpsParserOutput > result( ) noexcept
{ return std::move( output_ ); } { return std::move( output_ ); }
}; };
} // namespace opast

View file

@ -12,15 +12,14 @@ namespace {
struct T_CompilerImpl_ struct T_CompilerImpl_
{ {
P_OpProgram compile( P_OpProgram compile( T_OpsParserOutput const& input ) noexcept;
T_ParserOutput const& input ) noexcept;
private: private:
T_Visitor< A_Node > astVisitor{ ASTVisitorBrowser }; T_Visitor< A_Node > astVisitor{ ASTVisitorBrowser };
T_Set< uint32_t > constants{ UseTag< IndexBacked< > >( ) }; T_Set< uint32_t > constants{ UseTag< IndexBacked< > >( ) };
T_KeyValueTable< T_String , uint32_t > locations; T_KeyValueTable< T_String , uint32_t > locations;
T_ParserOutput* input; T_OpsParserOutput* input;
P_OpProgram output; P_OpProgram output;
uint32_t fiVariables , fiFramebuffers , uint32_t fiVariables , fiFramebuffers ,
@ -93,9 +92,9 @@ struct T_CompilerImpl_
P_OpProgram T_CompilerImpl_::compile( P_OpProgram T_CompilerImpl_::compile(
T_ParserOutput const& in ) noexcept T_OpsParserOutput const& in ) noexcept
{ {
input = const_cast< T_ParserOutput* >( &in ); input = const_cast< T_OpsParserOutput* >( &in );
output = NewOwned< T_OpProgram >( ); output = NewOwned< T_OpProgram >( );
// Gather all constants used in expressions, count resources // Gather all constants used in expressions, count resources
@ -886,14 +885,14 @@ void T_CompilerImpl_::applyStackEffects(
} }
/*= T_Compiler =================================================================*/ /*= T_OpsCompiler ==============================================================*/
T_Compiler::T_Compiler( ) noexcept T_OpsCompiler::T_OpsCompiler( ) noexcept
: A_PrivateImplementation( new T_CompilerImpl_( ) ) : A_PrivateImplementation( new T_CompilerImpl_( ) )
{ } { }
P_OpProgram T_Compiler::compile( P_OpProgram T_OpsCompiler::compile(
T_ParserOutput const& input ) noexcept T_OpsParserOutput const& input ) noexcept
{ {
return p< T_CompilerImpl_ >( ).compile( input ); return p< T_CompilerImpl_ >( ).compile( input );
} }

View file

@ -147,7 +147,7 @@ struct T_ParserImpl_
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
T_OwnPtr< T_ParserOutput >& output; T_OwnPtr< T_OpsParserOutput >& output;
T_Array< T_SRDError >& errors; T_Array< T_SRDError >& errors;
T_MultiArray< uint32_t > calls; T_MultiArray< uint32_t > calls;
T_Array< T_InstrRestriction > callInfo; T_Array< T_InstrRestriction > callInfo;
@ -163,7 +163,7 @@ struct T_ParserImpl_
} }; } };
T_ParserImpl_( T_Array< T_SRDError >* errors , T_ParserImpl_( T_Array< T_SRDError >* errors ,
T_OwnPtr< T_ParserOutput >* root ) noexcept; T_OwnPtr< T_OpsParserOutput >* root ) noexcept;
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
@ -292,7 +292,7 @@ struct T_ParserImpl_
inline T_ParserImpl_::T_ParserImpl_( inline T_ParserImpl_::T_ParserImpl_(
T_Array< T_SRDError >* const errors , T_Array< T_SRDError >* const errors ,
T_OwnPtr< T_ParserOutput >* const output ) noexcept T_OwnPtr< T_OpsParserOutput >* const output ) noexcept
: output( *output ) , errors( *errors ) : output( *output ) , errors( *errors )
{ } { }
@ -1924,16 +1924,16 @@ P_ExpressionNode T_ParserImpl_::parseUnaryOp(
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
T_Parser::T_Parser( ) noexcept T_OpsParser::T_OpsParser( ) noexcept
: A_PrivateImplementation( new T_ParserImpl_( &errors_ , &output_ ) ) , : A_PrivateImplementation( new T_ParserImpl_( &errors_ , &output_ ) ) ,
errors_( 64 ) , output_{} errors_( 64 ) , output_{}
{} {}
bool T_Parser::parse( bool T_OpsParser::parse(
T_SRDList const& input ) noexcept T_SRDList const& input ) noexcept
{ {
errors_.clear( ); errors_.clear( );
output_ = NewOwned< T_ParserOutput >( ); output_ = NewOwned< T_OpsParserOutput >( );
p< T_ParserImpl_ >( ).main( input ); p< T_ParserImpl_ >( ).main( input );
return errors_.empty( ); return errors_.empty( );
} }

View file

@ -73,10 +73,10 @@ int main( int argc , char** argv )
} }
// Parse the fuck // Parse the fuck
T_Parser parser; T_OpsParser parser;
if ( parser.parse( srdOut.list( ) ) ) { if ( parser.parse( srdOut.list( ) ) ) {
printf( "Parser successful. Compiling...\n" ); printf( "Parser successful. Compiling...\n" );
ops::T_Compiler compiler; T_OpsCompiler compiler;
compiler.compile( *parser.result( ) ); compiler.compile( *parser.result( ) );
return 0; return 0;
} else { } else {