Add CTS_ARB_gl_spirv test implementation
[platform/upstream/VK-GL-CTS.git] / framework / randomshaders / rsgStatement.hpp
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
61         Statement*                              createNextChild                 (GeneratorState& state) { DE_UNREF(state); return DE_NULL; }
62         void                                    tokenize                                (GeneratorState& state, TokenStream& str) const;
63         void                                    execute                                 (ExecutionContext& execCtx) const;
64
65         static float                    getWeight                               (const GeneratorState& state);
66
67 protected:
68         Expression*                             m_expression;
69 };
70
71 class DeclarationStatement : public Statement
72 {
73 public:
74                                                         DeclarationStatement    (GeneratorState& state, Variable* variable = DE_NULL);
75         virtual                                 ~DeclarationStatement   (void);
76
77         Statement*                              createNextChild                 (GeneratorState& state) { DE_UNREF(state); return DE_NULL; }
78         void                                    tokenize                                (GeneratorState& state, TokenStream& str) const;
79         void                                    execute                                 (ExecutionContext& execCtx) const;
80
81         static float                    getWeight                               (const GeneratorState& state);
82
83 protected:
84         const Variable*                 m_variable;
85         Expression*                             m_expression;
86 };
87
88 class BlockStatement : public Statement
89 {
90 public:
91                                                         BlockStatement                  (GeneratorState& state);
92         virtual                                 ~BlockStatement                 (void);
93
94                                                         BlockStatement                  (void) : m_numChildrenToCreate(0) {}
95         void                                    init                                    (GeneratorState& state);
96
97         Statement*                              createNextChild                 (GeneratorState& state);
98         void                                    tokenize                                (GeneratorState& state, TokenStream& str) const;
99         void                                    execute                                 (ExecutionContext& execCtx) const;
100
101         static float                    getWeight                               (const GeneratorState& state);
102
103         void                                    addChild                                (Statement* statement);
104
105 private:
106         VariableScope                   m_scope;
107
108         int                                             m_numChildrenToCreate;
109         std::vector<Statement*> m_children;
110 };
111
112 class ConditionalStatement : public Statement
113 {
114 public:
115                                                         ConditionalStatement    (GeneratorState& state);
116         virtual                                 ~ConditionalStatement   (void);
117
118         Statement*                              createNextChild                 (GeneratorState& state);
119         void                                    tokenize                                (GeneratorState& state, TokenStream& str) const;
120         void                                    execute                                 (ExecutionContext& execCtx) const;
121
122         static float                    getWeight                               (const GeneratorState& state);
123
124 private:
125         bool                                    isElseBlockRequired             (const GeneratorState& state) const;
126
127         Expression*                             m_condition;
128         Statement*                              m_trueStatement;
129         Statement*                              m_falseStatement;
130
131         ValueScope                              m_conditionalScope;
132 };
133
134 // \note Used for generating mandatory assignments (shader outputs, function outputs).
135 //       Normally assignment is handled inside ExpressionStatement where generator may
136 //       choose to generate AssignOp expression.
137 class AssignStatement : public Statement
138 {
139 public:
140                                                         AssignStatement                 (const Variable* variable, Expression* value);
141                                                         AssignStatement                 (GeneratorState& state, const Variable* variable, ConstValueRangeAccess valueRange);
142         virtual                                 ~AssignStatement                (void);
143
144         Statement*                              createNextChild                 (GeneratorState& state) { DE_UNREF(state); return DE_NULL; }
145         void                                    tokenize                                (GeneratorState& state, TokenStream& str) const;
146         void                                    execute                                 (ExecutionContext& execCtx) const;
147
148 private:
149         const Variable*                 m_variable;
150         Expression*                             m_valueExpr;
151 };
152
153 } // rsg
154
155 #endif // _RSGSTATEMENT_HPP