13c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#ifndef _RSGSTATEMENT_HPP 23c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define _RSGSTATEMENT_HPP 33c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*------------------------------------------------------------------------- 43c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * drawElements Quality Program Random Shader Generator 53c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * ---------------------------------------------------- 63c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 73c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Copyright 2014 The Android Open Source Project 83c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 93c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Licensed under the Apache License, Version 2.0 (the "License"); 103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * you may not use this file except in compliance with the License. 113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * You may obtain a copy of the License at 123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * http://www.apache.org/licenses/LICENSE-2.0 143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Unless required by applicable law or agreed to in writing, software 163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * distributed under the License is distributed on an "AS IS" BASIS, 173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * See the License for the specific language governing permissions and 193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * limitations under the License. 203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*! 223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \file 233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Statements. 243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "rsgDefs.hpp" 273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "rsgGeneratorState.hpp" 283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "rsgVariableManager.hpp" 293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "rsgExpression.hpp" 303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "rsgToken.hpp" 313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <vector> 333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 343c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace rsg 353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 373c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass Statement 383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 393c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Statement (void); 413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry virtual ~Statement (void); 423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry virtual Statement* createNextChild (GeneratorState& state) = DE_NULL; 443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry virtual void tokenize (GeneratorState& state, TokenStream& str) const = DE_NULL; 453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry virtual void execute (ExecutionContext& execCtx) const = DE_NULL; 463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 473c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprotected: 483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// IfStatement 513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// ForLoopStatement 523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// WhileStatement 533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// DoWhileStatement 543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 553c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass ExpressionStatement : public Statement 563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 573c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ExpressionStatement (GeneratorState& state); 593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry virtual ~ExpressionStatement (void); 603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Statement* createNextChild (GeneratorState& state) { DE_UNREF(state); return DE_NULL; } 623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void tokenize (GeneratorState& state, TokenStream& str) const; 633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void execute (ExecutionContext& execCtx) const; 643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry static float getWeight (const GeneratorState& state); 663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 673c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprotected: 683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Expression* m_expression; 693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 713c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass DeclarationStatement : public Statement 723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 733c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DeclarationStatement (GeneratorState& state, Variable* variable = DE_NULL); 753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry virtual ~DeclarationStatement (void); 763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Statement* createNextChild (GeneratorState& state) { DE_UNREF(state); return DE_NULL; } 783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void tokenize (GeneratorState& state, TokenStream& str) const; 793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void execute (ExecutionContext& execCtx) const; 803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry static float getWeight (const GeneratorState& state); 823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 833c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprotected: 843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const Variable* m_variable; 853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Expression* m_expression; 863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 883c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass BlockStatement : public Statement 893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 903c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry BlockStatement (GeneratorState& state); 923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry virtual ~BlockStatement (void); 933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry BlockStatement (void) : m_numChildrenToCreate(0) {} 953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void init (GeneratorState& state); 963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Statement* createNextChild (GeneratorState& state); 983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void tokenize (GeneratorState& state, TokenStream& str) const; 993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void execute (ExecutionContext& execCtx) const; 1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry static float getWeight (const GeneratorState& state); 1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void addChild (Statement* statement); 1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry VariableScope m_scope; 1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int m_numChildrenToCreate; 1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::vector<Statement*> m_children; 1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass ConditionalStatement : public Statement 1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ConditionalStatement (GeneratorState& state); 1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry virtual ~ConditionalStatement (void); 1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Statement* createNextChild (GeneratorState& state); 1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void tokenize (GeneratorState& state, TokenStream& str) const; 1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void execute (ExecutionContext& execCtx) const; 1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry static float getWeight (const GeneratorState& state); 1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool isElseBlockRequired (const GeneratorState& state) const; 1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Expression* m_condition; 1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Statement* m_trueStatement; 1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Statement* m_falseStatement; 1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ValueScope m_conditionalScope; 1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// \note Used for generating mandatory assignments (shader outputs, function outputs). 1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Normally assignment is handled inside ExpressionStatement where generator may 1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// choose to generate AssignOp expression. 1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass AssignStatement : public Statement 1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry AssignStatement (const Variable* variable, Expression* value); 1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry AssignStatement (GeneratorState& state, const Variable* variable, ConstValueRangeAccess valueRange); 1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry virtual ~AssignStatement (void); 1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Statement* createNextChild (GeneratorState& state) { DE_UNREF(state); return DE_NULL; } 1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void tokenize (GeneratorState& state, TokenStream& str) const; 1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void execute (ExecutionContext& execCtx) const; 1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const Variable* m_variable; 1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Expression* m_valueExpr; 1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // rsg 1543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#endif // _RSGSTATEMENT_HPP 156