blob: 6d359da1e94f758b8b95ebc853ba793360263bc5 [file] [log] [blame]
Jarkko Poyry3c827362014-09-02 11:48:52 +03001/*-------------------------------------------------------------------------
2 * drawElements Quality Program Random Shader Generator
3 * ----------------------------------------------------
4 *
5 * Copyright 2014 The Android Open Source Project
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 *//*!
20 * \file
21 * \brief Expression generator.
22 *//*--------------------------------------------------------------------*/
23
24#include "rsgFunctionGenerator.hpp"
25#include "rsgUtils.hpp"
26
27using std::vector;
28
29namespace rsg
30{
31
32FunctionGenerator::FunctionGenerator (GeneratorState& state, Function& function)
33 : m_state (state)
34 , m_function (function)
35{
36}
37
38FunctionGenerator::~FunctionGenerator (void)
39{
40}
41
42void FunctionGenerator::generate (void)
43{
44 std::vector<Statement*> statementStack;
45
46 // Initialize
47 m_state.setStatementStack(statementStack);
48 statementStack.push_back(&m_function.getBody());
49 m_function.getBody().init(m_state);
50
51 // Process until statement stack is empty
52 while (!statementStack.empty())
53 {
54 DE_ASSERT((int)statementStack.size() <= m_state.getShaderParameters().maxStatementDepth);
55
56 Statement* curStatement = statementStack.back();
57 Statement* childStatement = curStatement->createNextChild(m_state);
58
59 if (childStatement)
60 statementStack.push_back(childStatement);
61 else
62 statementStack.pop_back();
63 }
64
65 // Create assignments if variables have bound value range
66 for (vector<Variable*>::iterator i = m_requiredAssignments.begin(); i != m_requiredAssignments.end(); i++)
67 {
68 Variable* variable = *i;
69 const ValueEntry* entry = m_state.getVariableManager().getValue(variable);
70 ValueRange valueRange(variable->getType());
71
72 valueRange.getMin() = entry->getValueRange().getMin().value();
73 valueRange.getMax() = entry->getValueRange().getMax().value();
74
75 // Remove value entry from this scope. After this entry ptr is invalid.
76 m_state.getVariableManager().removeValueFromCurrentScope(variable);
77
Jarkko Pöyryba84b6d2015-05-19 17:44:29 -070078 if (!isUndefinedValueRange(valueRange.asAccess()))
79 m_function.getBody().addChild(new AssignStatement(m_state, variable, valueRange.asAccess()));
Jarkko Poyry3c827362014-09-02 11:48:52 +030080 }
81}
82
83} // rsg