From 0c9ca6c04e60ef9d93dcf79d517ef8d279fd2917 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Wed, 15 Nov 2017 18:44:34 +0100 Subject: [PATCH] Parser/compiler - Some refactoring --- control.hh | 26 +++---- demo.cc | 4 +- externals.hh | 3 + opast.hh | 206 ++++++++++++++++++++++++------------------------- opcomp.cc | 17 ++-- opparser.cc | 12 +-- parsercheck.cc | 4 +- 7 files changed, 135 insertions(+), 137 deletions(-) diff --git a/control.hh b/control.hh index 6698fa4..9e7149d 100644 --- a/control.hh +++ b/control.hh @@ -6,8 +6,6 @@ struct T_Rendertarget; namespace ops { -using namespace ebcl; - enum E_OpType { OP_END , @@ -89,18 +87,18 @@ struct T_Op static constexpr int MAX_ARGS = 2; E_OpType op; - T_SRDLocation location; + ebcl::T_SRDLocation location; uint32_t args[ MAX_ARGS ]; T_Op( const E_OpType op , - T_SRDLocation const& location , + ebcl::T_SRDLocation const& location , const uint32_t arg0 = 0 ) noexcept : op( op ) , location( location ) , args{ arg0 } { } T_Op( const E_OpType op , - T_SRDLocation const& location , + ebcl::T_SRDLocation const& location , std::initializer_list< uint32_t > a ) noexcept : op( op ) , location( location ) { @@ -147,15 +145,6 @@ struct 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 { @@ -228,3 +217,12 @@ class X_OpFailure : public std::exception }; } // namespace ops + + +class T_OpsCompiler : public ebcl::A_PrivateImplementation +{ + public: + T_OpsCompiler( ) noexcept; + + ops::P_OpProgram compile( T_OpsParserOutput const& input ) noexcept; +}; diff --git a/demo.cc b/demo.cc index 8921c93..983eabd 100644 --- a/demo.cc +++ b/demo.cc @@ -133,10 +133,10 @@ bool T_Demo::loadProgram( ) } // Parse the fuck - opast::T_Parser parser; + T_OpsParser parser; if ( parser.parse( srdOut.list( ) ) ) { printf( "Parser successful. Compiling...\n" ); - ops::T_Compiler compiler; + T_OpsCompiler compiler; program = compiler.compile( *parser.result( ) ); return true; } diff --git a/externals.hh b/externals.hh index ec70fdd..3381f3f 100644 --- a/externals.hh +++ b/externals.hh @@ -42,12 +42,15 @@ using ebcl::NewOwned; using ebcl::T_SharedPtr; using ebcl::NewShared; +using ebcl::T_Flags; using ebcl::T_Optional; using ebcl::T_Union; using ebcl::T_Variant; using ebcl::T_Array; using ebcl::T_AutoArray; +using ebcl::T_StaticArray; +using ebcl::T_MultiArray; using ebcl::T_String; using ebcl::T_StringBuilder; diff --git a/opast.hh b/opast.hh index 27547f9..c84778a 100644 --- a/opast.hh +++ b/opast.hh @@ -6,8 +6,6 @@ namespace opast { -using namespace ebcl; - /*= BASE CLASS FOR AST NODES ===================================================*/ @@ -73,7 +71,7 @@ class A_Node private: const E_Type type_; A_Node* const parent_; - T_SRDLocation location_; + ebcl::T_SRDLocation location_; protected: explicit A_Node( const E_Type type , @@ -85,9 +83,9 @@ class A_Node E_Type type( ) const noexcept { return type_; } - T_SRDLocation& location( ) noexcept + ebcl::T_SRDLocation& location( ) noexcept { return location_; } - T_SRDLocation const& location( ) const noexcept + ebcl::T_SRDLocation const& location( ) const noexcept { return location_; } A_Node& parent( ) const noexcept @@ -232,12 +230,12 @@ class A_FuncNode : public A_Node struct T_Local_ { T_String name; - T_SRDLocation location; + ebcl::T_SRDLocation location; bool argument; E_DataType type{ E_DataType::UNKNOWN }; T_Local_( T_String const& name , - T_SRDLocation const& location , + ebcl::T_SRDLocation const& location , const bool argument ) noexcept : name{ name } , location{ location } , 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_SRDLocation const& location ) noexcept; + ebcl::T_SRDLocation const& location ) noexcept; uint32_t locals( ) const noexcept { return locals_.size( ); } @@ -329,14 +327,14 @@ class T_RootNode : public A_Node struct T_AddFunctionResult { A_FuncNode& function; - T_Optional< T_SRDLocation > dupLocation; + T_Optional< ebcl::T_SRDLocation > dupLocation; T_AddFunctionResult( A_FuncNode& function ) noexcept : function{ function } , dupLocation{} {} T_AddFunctionResult( A_FuncNode& function , - T_SRDLocation const& dupLocation ) noexcept + ebcl::T_SRDLocation const& dupLocation ) noexcept : 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 // of the initial argument. - T_Optional< T_SRDLocation > addArgument( - T_SRDToken const& token ) noexcept; + T_Optional< ebcl::T_SRDLocation > addArgument( + ebcl::T_SRDToken const& token ) noexcept; uint32_t arguments( ) const noexcept; }; @@ -403,12 +401,12 @@ class T_CallInstrNode : public A_InstructionNode { private: T_String id_; - T_SRDLocation idLocation_; + ebcl::T_SRDLocation idLocation_; T_AutoArray< P_ArgumentNode , 8 > arguments_; public: T_CallInstrNode( T_InstrListNode& parent , - T_SRDToken const& idToken ) noexcept + ebcl::T_SRDToken const& idToken ) noexcept : A_InstructionNode( OP_CALL , parent ) , id_( idToken.stringValue( ) ) , idLocation_( idToken.location( ) ) @@ -424,7 +422,7 @@ class T_CallInstrNode : public A_InstructionNode T_String const& id( ) const noexcept { return id_; } - T_SRDLocation const& idLocation( ) const noexcept + ebcl::T_SRDLocation const& idLocation( ) const noexcept { return idLocation_; } uint32_t arguments( ) const noexcept @@ -539,15 +537,15 @@ class T_LocalsInstrNode : public A_InstructionNode { private: T_AutoArray< T_String , 8 > vars_; - T_AutoArray< T_SRDLocation , 8 > varLocs_; + T_AutoArray< ebcl::T_SRDLocation , 8 > varLocs_; public: T_LocalsInstrNode( T_InstrListNode& parent ) noexcept : A_InstructionNode( OP_LOCALS , parent ) { } - T_Optional< T_SRDLocation > addVariable( - T_SRDToken const& token ) noexcept; + T_Optional< ebcl::T_SRDLocation > addVariable( + ebcl::T_SRDToken const& token ) noexcept; uint32_t variables( ) const noexcept { return vars_.size( ); } @@ -556,7 +554,7 @@ class T_LocalsInstrNode : public A_InstructionNode const uint32_t index ) const noexcept { return vars_[ index ]; } - T_SRDLocation const& varLocation( + ebcl::T_SRDLocation const& varLocation( const uint32_t index ) const noexcept { return varLocs_[ index ]; } }; @@ -566,12 +564,12 @@ class T_SetInstrNode : public A_InstructionNode { private: T_String id_; - T_SRDLocation idLocation_; + ebcl::T_SRDLocation idLocation_; P_ExpressionNode expression_; public: T_SetInstrNode( T_InstrListNode& parent , - T_SRDToken const& idToken ) noexcept + ebcl::T_SRDToken const& idToken ) noexcept : A_InstructionNode( OP_SET , parent ) , id_( idToken.stringValue( ) ) , idLocation_( idToken.location( ) ) @@ -579,7 +577,7 @@ class T_SetInstrNode : public A_InstructionNode T_String const& id( ) const noexcept { return id_; } - T_SRDLocation const& idLocation( ) const noexcept + ebcl::T_SRDLocation const& idLocation( ) const noexcept { return idLocation_; } void setExpression( P_ExpressionNode expression ) noexcept @@ -598,14 +596,14 @@ class A_ResourceDefInstrNode : public A_InstructionNode { private: T_String id_; - T_SRDLocation idLocation_; + ebcl::T_SRDLocation idLocation_; E_DataType dataType_; protected: A_ResourceDefInstrNode( const E_Type type , T_InstrListNode& parent , - T_SRDToken const& identifier , + ebcl::T_SRDToken const& identifier , const E_DataType dataType ) noexcept : A_InstructionNode( type , parent , E_InstrRestriction::FRAME ) , id_( identifier.stringValue( ) ) , @@ -616,7 +614,7 @@ class A_ResourceDefInstrNode : public A_InstructionNode public: T_String const& id( ) const noexcept { return id_; } - T_SRDLocation const& idLocation( ) const noexcept + ebcl::T_SRDLocation const& idLocation( ) const noexcept { return idLocation_; } E_DataType dataType( ) const noexcept @@ -639,7 +637,7 @@ class T_FramebufferInstrNode : public A_ResourceDefInstrNode public: T_Attachment( T_FramebufferInstrNode& parent , const bool depth , - T_SRDToken const& texId , + ebcl::T_SRDToken const& texId , P_ExpressionNode lod = { } ) noexcept : A_Node( TN_FBATT , &parent ) , depth_( depth ) , @@ -670,14 +668,14 @@ class T_FramebufferInstrNode : public A_ResourceDefInstrNode public: T_FramebufferInstrNode( T_InstrListNode& parent , - T_SRDToken const& identifier ) noexcept + ebcl::T_SRDToken const& identifier ) noexcept : A_ResourceDefInstrNode( OP_FRAMEBUFFER , parent , identifier , E_DataType::FRAMEBUFFER ) { } // --------------------------------------------------------------------- - bool addColorAttachment( T_SRDToken const& id , + bool addColorAttachment( ebcl::T_SRDToken const& id , P_ExpressionNode lod = {} ) 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; T_Attachment* depthAttachment( ) const noexcept @@ -701,18 +699,18 @@ class T_InputInstrNode : public A_ResourceDefInstrNode { private: float defValue_; - T_SRDLocation dvLocation_; + ebcl::T_SRDLocation dvLocation_; public: T_InputInstrNode( T_InstrListNode& parent , - T_SRDToken const& tName ) noexcept + ebcl::T_SRDToken const& tName ) noexcept : A_ResourceDefInstrNode( OP_INPUT , parent , tName , E_DataType::INPUT ) {} T_InputInstrNode( T_InstrListNode& parent , - T_SRDToken const& tName , - T_SRDToken const& tDefault ) noexcept + ebcl::T_SRDToken const& tName , + ebcl::T_SRDToken const& tDefault ) noexcept : A_ResourceDefInstrNode( OP_INPUT , parent , tName , E_DataType::INPUT ) , defValue_( tDefault.floatValue( ) ) , dvLocation_( tDefault.location( ) ) @@ -720,7 +718,7 @@ class T_InputInstrNode : public A_ResourceDefInstrNode float defValue( ) const noexcept { return defValue_; } - T_SRDLocation const& defValueLocation( ) const noexcept + ebcl::T_SRDLocation const& defValueLocation( ) const noexcept { return dvLocation_; } }; @@ -729,12 +727,12 @@ class T_PipelineInstrNode : public A_ResourceDefInstrNode { private: T_StaticArray< T_String , 6 > pids_; - T_StaticArray< T_SRDLocation , 6 > pidLocations_; + T_StaticArray< ebcl::T_SRDLocation , 6 > pidLocations_; public: T_PipelineInstrNode( T_InstrListNode& parent , - T_SRDToken const& idToken ) noexcept + ebcl::T_SRDToken const& idToken ) noexcept : A_ResourceDefInstrNode( OP_PIPELINE , parent , 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 // is already in the pipeline's list, the location of the first // occurrence will be returned. - T_Optional< T_SRDLocation > addProgram( - T_SRDToken const& pidToken ) noexcept; + T_Optional< ebcl::T_SRDLocation > addProgram( + ebcl::T_SRDToken const& pidToken ) noexcept; uint32_t size( ) const noexcept { return pids_.size( ); } T_String const& program( const uint32_t index ) const noexcept { 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 ]; } }; @@ -760,13 +758,13 @@ class T_ProgramInstrNode : public A_ResourceDefInstrNode { private: T_String path_; - T_SRDLocation pathLocation_; + ebcl::T_SRDLocation pathLocation_; public: T_ProgramInstrNode( T_InstrListNode& parent , - T_SRDToken const& idToken , - T_SRDToken const& pathToken ) noexcept + ebcl::T_SRDToken const& idToken , + ebcl::T_SRDToken const& pathToken ) noexcept : A_ResourceDefInstrNode( OP_PROGRAM , parent , idToken , E_DataType::PROGRAM ) , path_( pathToken.stringValue( ) ) , @@ -775,7 +773,7 @@ class T_ProgramInstrNode : public A_ResourceDefInstrNode T_String const& path( ) const noexcept { return path_; } - T_SRDLocation const& pathLocation( ) const noexcept + ebcl::T_SRDLocation const& pathLocation( ) const noexcept { return pathLocation_; } }; @@ -785,25 +783,25 @@ class T_SamplerInstrNode : public A_ResourceDefInstrNode private: struct T_Sampling_ { - T_SRDLocation location; + ebcl::T_SRDLocation location; E_TexSampling mode; }; struct T_Mipmaps_ { - T_SRDLocation location; + ebcl::T_SRDLocation location; T_Optional< E_TexSampling > mode; }; struct T_Wrapping_ { - T_SRDLocation location; + ebcl::T_SRDLocation location; E_TexWrap mode; }; struct T_LOD_ { - T_SRDLocation location; + ebcl::T_SRDLocation location; P_ArgumentNode min; P_ArgumentNode max; }; @@ -816,7 +814,7 @@ class T_SamplerInstrNode : public A_ResourceDefInstrNode public: T_SamplerInstrNode( T_InstrListNode& parent , - T_SRDToken const& id ) noexcept + ebcl::T_SRDToken const& id ) noexcept : A_ResourceDefInstrNode( OP_SAMPLER , parent , id , E_DataType::SAMPLER ) { } @@ -824,19 +822,19 @@ class T_SamplerInstrNode : public A_ResourceDefInstrNode // Attempt to set sampling mode, mipmap mode, wrapping mode or // LOD minimal/maximal, returning the location of the previous // definition if there was one. - T_Optional< T_SRDLocation > setSampling( + T_Optional< ebcl::T_SRDLocation > setSampling( E_TexSampling mode , - T_SRDLocation const& location ) noexcept; - T_Optional< T_SRDLocation > setMipmapSampling( + ebcl::T_SRDLocation const& location ) noexcept; + T_Optional< ebcl::T_SRDLocation > setMipmapSampling( E_TexSampling mode , - T_SRDLocation const& location ) noexcept; - T_Optional< T_SRDLocation > setNoMipmap( - T_SRDLocation const& location ) noexcept; - T_Optional< T_SRDLocation > setWrapping( + ebcl::T_SRDLocation const& location ) noexcept; + T_Optional< ebcl::T_SRDLocation > setNoMipmap( + ebcl::T_SRDLocation const& location ) noexcept; + T_Optional< ebcl::T_SRDLocation > setWrapping( E_TexWrap mode , - T_SRDLocation const& location ) noexcept; - T_Optional< T_SRDLocation > setLOD( - T_SRDLocation const& location , + ebcl::T_SRDLocation const& location ) noexcept; + T_Optional< ebcl::T_SRDLocation > setLOD( + ebcl::T_SRDLocation const& location , P_ExpressionNode min , P_ExpressionNode max ) noexcept; @@ -865,7 +863,7 @@ class T_TextureInstrNode : public A_ResourceDefInstrNode public: T_TextureInstrNode( T_InstrListNode& parent , - T_SRDToken const& id , + ebcl::T_SRDToken const& id , E_TexType type ) noexcept : A_ResourceDefInstrNode( OP_TEXTURE , parent , id , E_DataType::TEXTURE ) , @@ -921,33 +919,33 @@ class T_OutputDebugInstrNode : public A_InstructionNode { private: T_String idTexture_; - T_SRDLocation locTexture_; + ebcl::T_SRDLocation locTexture_; E_ODbgMode mode_; - T_SRDLocation locMode_; + ebcl::T_SRDLocation locMode_; T_String description_; - T_SRDLocation locDescription_; + ebcl::T_SRDLocation locDescription_; public: T_OutputDebugInstrNode( T_InstrListNode& parent , - T_SRDToken const& texture , + ebcl::T_SRDToken const& texture , const E_ODbgMode mode , - T_SRDLocation const& modeLocation , - T_SRDToken const& description ) noexcept; + ebcl::T_SRDLocation const& modeLocation , + ebcl::T_SRDToken const& description ) noexcept; T_String const& texture( ) const noexcept { return idTexture_; } - T_SRDLocation const& textureLocation( ) const noexcept + ebcl::T_SRDLocation const& textureLocation( ) const noexcept { return locTexture_; } E_ODbgMode mode( ) const noexcept { return mode_; } - T_SRDLocation const& modeLocation( ) const noexcept + ebcl::T_SRDLocation const& modeLocation( ) const noexcept { return locMode_; } T_String const& description( ) const noexcept { return description_; } - T_SRDLocation const& descriptionLocation( ) const noexcept + ebcl::T_SRDLocation const& descriptionLocation( ) const noexcept { return locDescription_; } }; @@ -1029,16 +1027,16 @@ class T_UniformsInstrNode : public A_InstructionNode private: bool integers_; T_String progId_; - T_SRDLocation progIdLocation_; + ebcl::T_SRDLocation progIdLocation_; uint32_t uloc_; - T_SRDLocation ulocLocation_; + ebcl::T_SRDLocation ulocLocation_; T_StaticArray< P_ArgumentNode , 4 > values_; public: T_UniformsInstrNode( T_InstrListNode& parent , const bool integers , - T_SRDToken const& prog , - T_SRDToken const& loc ) noexcept + ebcl::T_SRDToken const& prog , + ebcl::T_SRDToken const& loc ) noexcept : A_InstructionNode( OP_UNIFORMS , parent ) , integers_( integers ) , progId_( prog.stringValue( ) ) , progIdLocation_( prog.location( ) ) , uloc_( loc.longValue( ) ) , ulocLocation_( loc.location( ) ) @@ -1049,12 +1047,12 @@ class T_UniformsInstrNode : public A_InstructionNode T_String const& progId( ) const noexcept { return progId_; } - T_SRDLocation const& progIdLocation( ) const noexcept + ebcl::T_SRDLocation const& progIdLocation( ) const noexcept { return progIdLocation_; } uint32_t uloc( ) const noexcept { return uloc_; } - T_SRDLocation const& ulocLocation( ) const noexcept + ebcl::T_SRDLocation const& ulocLocation( ) const noexcept { return ulocLocation_; } void addValue( P_ExpressionNode value ) noexcept @@ -1082,12 +1080,12 @@ class T_UseInstrNode : public A_InstructionNode private: T_String id_; - T_SRDLocation idLocation_; + ebcl::T_SRDLocation idLocation_; public: T_UseInstrNode( T_InstrListNode& parent , const E_Type type , - T_SRDToken const& identifier ) noexcept + ebcl::T_SRDToken const& identifier ) noexcept : A_InstructionNode( ([type]() { switch ( type ) { case FRAMEBUFFER: return OP_USE_FRAMEBUFFER; @@ -1103,7 +1101,7 @@ class T_UseInstrNode : public A_InstructionNode T_String const& id( ) const noexcept { return id_; } - T_SRDLocation const& idLocation( ) const noexcept + ebcl::T_SRDLocation const& idLocation( ) const noexcept { return idLocation_; } }; @@ -1112,15 +1110,15 @@ class T_UseTextureInstrNode : public T_UseInstrNode { private: uint32_t bank_; - T_SRDLocation bankLocation_; + ebcl::T_SRDLocation bankLocation_; T_String samplerId_; - T_SRDLocation samplerIdLocation_; + ebcl::T_SRDLocation samplerIdLocation_; public: T_UseTextureInstrNode( T_InstrListNode& parent , - T_SRDToken const& bank , - T_SRDToken const& identifier , - T_SRDToken const& sampler ) noexcept + ebcl::T_SRDToken const& bank , + ebcl::T_SRDToken const& identifier , + ebcl::T_SRDToken const& sampler ) noexcept : T_UseInstrNode( parent , TEXTURE , identifier ) , bank_( bank.longValue( ) ) , bankLocation_( bank.location( ) ) , @@ -1130,12 +1128,12 @@ class T_UseTextureInstrNode : public T_UseInstrNode uint32_t bank( ) const noexcept { return bank_; } - T_SRDLocation const& bankLocation( ) const noexcept + ebcl::T_SRDLocation const& bankLocation( ) const noexcept { return bankLocation_; } T_String const& samplerId( ) const noexcept { return samplerId_; } - T_SRDLocation const& samplerIdLocation( ) const noexcept + ebcl::T_SRDLocation const& samplerIdLocation( ) const noexcept { return samplerIdLocation_; } }; @@ -1183,9 +1181,9 @@ class T_ConstantExprNode : public A_ExpressionNode public: T_ConstantExprNode( A_Node& parent , - T_SRDToken const& token ) noexcept + ebcl::T_SRDToken const& token ) noexcept : A_ExpressionNode( EXPR_CONST , parent ) , - wasFloat_( token.type( ) == E_SRDTokenType::FLOAT ) , + wasFloat_( token.type( ) == ebcl::E_SRDTokenType::FLOAT ) , vFloat_( token.floatValue( ) ) , vInt_( token.longValue( ) ) { location( ) = token.location( ); } @@ -1218,7 +1216,7 @@ class T_IdentifierExprNode : public A_ExpressionNode public: T_IdentifierExprNode( A_Node& parent , - T_SRDToken const& token ) noexcept + ebcl::T_SRDToken const& token ) noexcept : T_IdentifierExprNode( parent , token.stringValue( ) ) { location( ) = token.location( ); } @@ -1236,11 +1234,11 @@ class T_InputExprNode : public A_ExpressionNode { private: T_String id_; - T_SRDLocation idLocation_; + ebcl::T_SRDLocation idLocation_; public: T_InputExprNode( A_Node& parent , - T_SRDToken const& token ) noexcept + ebcl::T_SRDToken const& token ) noexcept : A_ExpressionNode( EXPR_INPUT , parent ) , id_( token.stringValue( ) ) , idLocation_( token.location( ) ) @@ -1248,7 +1246,7 @@ class T_InputExprNode : public A_ExpressionNode T_String const& id( ) const noexcept { return id_; } - T_SRDLocation const& idLocation( ) const noexcept + ebcl::T_SRDLocation const& idLocation( ) const noexcept { return idLocation_; } }; @@ -1335,33 +1333,33 @@ class T_BinaryOperatorNode : public A_ExpressionNode }; +} // namespace opast + + /*= PARSER ===================================================================*/ // Parser output. Consists in a root node as well as other details (table of // constants, data types, etc...) -struct T_ParserOutput +struct T_OpsParserOutput { - T_RootNode root; - T_KeyValueTable< T_String , E_DataType > types; + opast::T_RootNode root; + T_KeyValueTable< T_String , opast::E_DataType > types; }; // The actual parser -class T_Parser : public A_PrivateImplementation +class T_OpsParser : public ebcl::A_PrivateImplementation { private: - T_Array< T_SRDError > errors_; - T_OwnPtr< T_ParserOutput > output_; + T_Array< ebcl::T_SRDError > errors_; + T_OwnPtr< T_OpsParserOutput > output_; 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_; } - T_OwnPtr< T_ParserOutput > result( ) noexcept + T_OwnPtr< T_OpsParserOutput > result( ) noexcept { return std::move( output_ ); } }; - - -} // namespace opast diff --git a/opcomp.cc b/opcomp.cc index 13c0b8f..448ef3c 100644 --- a/opcomp.cc +++ b/opcomp.cc @@ -12,15 +12,14 @@ namespace { struct T_CompilerImpl_ { - P_OpProgram compile( - T_ParserOutput const& input ) noexcept; + P_OpProgram compile( T_OpsParserOutput const& input ) noexcept; private: T_Visitor< A_Node > astVisitor{ ASTVisitorBrowser }; T_Set< uint32_t > constants{ UseTag< IndexBacked< > >( ) }; T_KeyValueTable< T_String , uint32_t > locations; - T_ParserOutput* input; + T_OpsParserOutput* input; P_OpProgram output; uint32_t fiVariables , fiFramebuffers , @@ -93,9 +92,9 @@ struct T_CompilerImpl_ 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 >( ); // 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_( ) ) { } -P_OpProgram T_Compiler::compile( - T_ParserOutput const& input ) noexcept +P_OpProgram T_OpsCompiler::compile( + T_OpsParserOutput const& input ) noexcept { return p< T_CompilerImpl_ >( ).compile( input ); } diff --git a/opparser.cc b/opparser.cc index 2b72f34..d9aece6 100644 --- a/opparser.cc +++ b/opparser.cc @@ -147,7 +147,7 @@ struct T_ParserImpl_ // --------------------------------------------------------------------- - T_OwnPtr< T_ParserOutput >& output; + T_OwnPtr< T_OpsParserOutput >& output; T_Array< T_SRDError >& errors; T_MultiArray< uint32_t > calls; T_Array< T_InstrRestriction > callInfo; @@ -163,7 +163,7 @@ struct T_ParserImpl_ } }; 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_( T_Array< T_SRDError >* const errors , - T_OwnPtr< T_ParserOutput >* const output ) noexcept + T_OwnPtr< T_OpsParserOutput >* const output ) noexcept : 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_ ) ) , errors_( 64 ) , output_{} {} -bool T_Parser::parse( +bool T_OpsParser::parse( T_SRDList const& input ) noexcept { errors_.clear( ); - output_ = NewOwned< T_ParserOutput >( ); + output_ = NewOwned< T_OpsParserOutput >( ); p< T_ParserImpl_ >( ).main( input ); return errors_.empty( ); } diff --git a/parsercheck.cc b/parsercheck.cc index 6dffb9d..4935c7f 100644 --- a/parsercheck.cc +++ b/parsercheck.cc @@ -73,10 +73,10 @@ int main( int argc , char** argv ) } // Parse the fuck - T_Parser parser; + T_OpsParser parser; if ( parser.parse( srdOut.list( ) ) ) { printf( "Parser successful. Compiling...\n" ); - ops::T_Compiler compiler; + T_OpsCompiler compiler; compiler.compile( *parser.result( ) ); return 0; } else {