xref: /aosp_15_r20/external/deqp/framework/randomshaders/rsgStatement.hpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1 #ifndef _RSGSTATEMENT_HPP
2 #define _RSGSTATEMENT_HPP
3 /*-------------------------------------------------------------------------
4  * drawElements Quality Program Random Shader Generator
5  * ----------------------------------------------------
6  *
7  * Copyright 2014 The Android Open Source Project
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  *//*!
22  * \file
23  * \brief Statements.
24  *//*--------------------------------------------------------------------*/
25 
26 #include "rsgDefs.hpp"
27 #include "rsgGeneratorState.hpp"
28 #include "rsgVariableManager.hpp"
29 #include "rsgExpression.hpp"
30 #include "rsgToken.hpp"
31 
32 #include <vector>
33 
34 namespace rsg
35 {
36 
37 class Statement
38 {
39 public:
40     Statement(void);
41     virtual ~Statement(void);
42 
43     virtual Statement *createNextChild(GeneratorState &state)            = DE_NULL;
44     virtual void tokenize(GeneratorState &state, TokenStream &str) const = DE_NULL;
45     virtual void execute(ExecutionContext &execCtx) const                = DE_NULL;
46 
47 protected:
48 };
49 
50 // IfStatement
51 // ForLoopStatement
52 // WhileStatement
53 // DoWhileStatement
54 
55 class ExpressionStatement : public Statement
56 {
57 public:
58     ExpressionStatement(GeneratorState &state);
59     virtual ~ExpressionStatement(void);
60 
createNextChild(GeneratorState & state)61     Statement *createNextChild(GeneratorState &state)
62     {
63         DE_UNREF(state);
64         return DE_NULL;
65     }
66     void tokenize(GeneratorState &state, TokenStream &str) const;
67     void execute(ExecutionContext &execCtx) const;
68 
69     static float getWeight(const GeneratorState &state);
70 
71 protected:
72     Expression *m_expression;
73 };
74 
75 class DeclarationStatement : public Statement
76 {
77 public:
78     DeclarationStatement(GeneratorState &state, Variable *variable = DE_NULL);
79     virtual ~DeclarationStatement(void);
80 
createNextChild(GeneratorState & state)81     Statement *createNextChild(GeneratorState &state)
82     {
83         DE_UNREF(state);
84         return DE_NULL;
85     }
86     void tokenize(GeneratorState &state, TokenStream &str) const;
87     void execute(ExecutionContext &execCtx) const;
88 
89     static float getWeight(const GeneratorState &state);
90 
91 protected:
92     const Variable *m_variable;
93     Expression *m_expression;
94 };
95 
96 class BlockStatement : public Statement
97 {
98 public:
99     BlockStatement(GeneratorState &state);
100     virtual ~BlockStatement(void);
101 
BlockStatement(void)102     BlockStatement(void) : m_numChildrenToCreate(0)
103     {
104     }
105     void init(GeneratorState &state);
106 
107     Statement *createNextChild(GeneratorState &state);
108     void tokenize(GeneratorState &state, TokenStream &str) const;
109     void execute(ExecutionContext &execCtx) const;
110 
111     static float getWeight(const GeneratorState &state);
112 
113     void addChild(Statement *statement);
114 
115 private:
116     VariableScope m_scope;
117 
118     int m_numChildrenToCreate;
119     std::vector<Statement *> m_children;
120 };
121 
122 class ConditionalStatement : public Statement
123 {
124 public:
125     ConditionalStatement(GeneratorState &state);
126     virtual ~ConditionalStatement(void);
127 
128     Statement *createNextChild(GeneratorState &state);
129     void tokenize(GeneratorState &state, TokenStream &str) const;
130     void execute(ExecutionContext &execCtx) const;
131 
132     static float getWeight(const GeneratorState &state);
133 
134 private:
135     bool isElseBlockRequired(const GeneratorState &state) const;
136 
137     Expression *m_condition;
138     Statement *m_trueStatement;
139     Statement *m_falseStatement;
140 
141     ValueScope m_conditionalScope;
142 };
143 
144 // \note Used for generating mandatory assignments (shader outputs, function outputs).
145 //       Normally assignment is handled inside ExpressionStatement where generator may
146 //       choose to generate AssignOp expression.
147 class AssignStatement : public Statement
148 {
149 public:
150     AssignStatement(const Variable *variable, Expression *value);
151     AssignStatement(GeneratorState &state, const Variable *variable, ConstValueRangeAccess valueRange);
152     virtual ~AssignStatement(void);
153 
createNextChild(GeneratorState & state)154     Statement *createNextChild(GeneratorState &state)
155     {
156         DE_UNREF(state);
157         return DE_NULL;
158     }
159     void tokenize(GeneratorState &state, TokenStream &str) const;
160     void execute(ExecutionContext &execCtx) const;
161 
162 private:
163     const Variable *m_variable;
164     Expression *m_valueExpr;
165 };
166 
167 } // namespace rsg
168 
169 #endif // _RSGSTATEMENT_HPP
170