1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program Random Shader Generator
3 * ----------------------------------------------------
5 * Copyright 2014 The Android Open Source Project
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * \brief Expression generator.
22 *//*--------------------------------------------------------------------*/
24 #include "rsgFunctionGenerator.hpp"
25 #include "rsgUtils.hpp"
32 FunctionGenerator::FunctionGenerator (GeneratorState& state, Function& function)
34 , m_function (function)
38 FunctionGenerator::~FunctionGenerator (void)
42 void FunctionGenerator::generate (void)
44 std::vector<Statement*> statementStack;
47 m_state.setStatementStack(statementStack);
48 statementStack.push_back(&m_function.getBody());
49 m_function.getBody().init(m_state);
51 // Process until statement stack is empty
52 while (!statementStack.empty())
54 DE_ASSERT((int)statementStack.size() <= m_state.getShaderParameters().maxStatementDepth);
56 Statement* curStatement = statementStack.back();
57 Statement* childStatement = curStatement->createNextChild(m_state);
60 statementStack.push_back(childStatement);
62 statementStack.pop_back();
65 // Create assignments if variables have bound value range
66 for (vector<Variable*>::iterator i = m_requiredAssignments.begin(); i != m_requiredAssignments.end(); i++)
68 Variable* variable = *i;
69 const ValueEntry* entry = m_state.getVariableManager().getValue(variable);
70 ValueRange valueRange(variable->getType());
72 valueRange.getMin() = entry->getValueRange().getMin().value();
73 valueRange.getMax() = entry->getValueRange().getMax().value();
75 // Remove value entry from this scope. After this entry ptr is invalid.
76 m_state.getVariableManager().removeValueFromCurrentScope(variable);
78 if (!isUndefinedValueRange(valueRange.asAccess()))
79 m_function.getBody().addChild(new AssignStatement(m_state, variable, valueRange.asAccess()));