• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*-------------------------------------------------------------------------
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 
27 using std::vector;
28 
29 namespace rsg
30 {
31 
FunctionGenerator(GeneratorState & state,Function & function)32 FunctionGenerator::FunctionGenerator (GeneratorState& state, Function& function)
33 	: m_state		(state)
34 	, m_function	(function)
35 {
36 }
37 
~FunctionGenerator(void)38 FunctionGenerator::~FunctionGenerator (void)
39 {
40 }
41 
generate(void)42 void 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 
78 		if (!isUndefinedValueRange(valueRange.asAccess()))
79 			m_function.getBody().addChild(new AssignStatement(m_state, variable, valueRange.asAccess()));
80 	}
81 }
82 
83 } // rsg
84