1 ///////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2013 Academy of Motion Picture Arts and Sciences
3 // ("A.M.P.A.S."). Portions contributed by others as indicated.
4 // All rights reserved.
5 //
6 // A worldwide, royalty-free, non-exclusive right to copy, modify, create
7 // derivatives, and use, in source and binary forms, is hereby granted,
8 // subject to acceptance of this license. Performance of any of the
9 // aforementioned acts indicates acceptance to be bound by the following
10 // terms and conditions:
11 //
12 //  * Copies of source code, in whole or in part, must retain the
13 //    above copyright notice, this list of conditions and the
14 //    Disclaimer of Warranty.
15 //
16 //  * Use in binary form must retain the above copyright notice,
17 //    this list of conditions and the Disclaimer of Warranty in the
18 //    documentation and/or other materials provided with the distribution.
19 //
20 //  * Nothing in this license shall be deemed to grant any rights to
21 //    trademarks, copyrights, patents, trade secrets or any other
22 //    intellectual property of A.M.P.A.S. or any contributors, except
23 //    as expressly stated herein.
24 //
25 //  * Neither the name "A.M.P.A.S." nor the name of any other
26 //    contributors to this software may be used to endorse or promote
27 //    products derivative of or based on this software without express
28 //    prior written permission of A.M.P.A.S. or the contributors, as
29 //    appropriate.
30 //
31 // This license shall be construed pursuant to the laws of the State of
32 // California, and any disputes related thereto shall be subject to the
33 // jurisdiction of the courts therein.
34 //
35 // Disclaimer of Warranty: THIS SOFTWARE IS PROVIDED BY A.M.P.A.S. AND
36 // CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
37 // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
38 // FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT ARE DISCLAIMED. IN NO
39 // EVENT SHALL A.M.P.A.S., OR ANY CONTRIBUTORS OR DISTRIBUTORS, BE LIABLE
40 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, RESITUTIONARY,
41 // OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
42 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
43 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
44 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
46 // THE POSSIBILITY OF SUCH DAMAGE.
47 //
48 // WITHOUT LIMITING THE GENERALITY OF THE FOREGOING, THE ACADEMY
49 // SPECIFICALLY DISCLAIMS ANY REPRESENTATIONS OR WARRANTIES WHATSOEVER
50 // RELATED TO PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS IN THE ACADEMY
51 // COLOR ENCODING SYSTEM, OR APPLICATIONS THEREOF, HELD BY PARTIES OTHER
52 // THAN A.M.P.A.S., WHETHER DISCLOSED OR UNDISCLOSED.
53 ///////////////////////////////////////////////////////////////////////////
54 
55 
56 #ifndef INCLUDED_CTL_SIMD_L_CONTEXT_H
57 #define INCLUDED_CTL_SIMD_L_CONTEXT_H
58 
59 //-----------------------------------------------------------------------------
60 //
61 //	class SimdLContext
62 //
63 //-----------------------------------------------------------------------------
64 
65 #include <CtlLContext.h>
66 #include <CtlSymbolTable.h>
67 #include <list>
68 #include <vector>
69 
70 namespace Ctl {
71 
72 class SimdReg;
73 class SimdInst;
74 class SimdCallInst;
75 class SimdModule;
76 
77 class Type;
78 typedef RcPtr <Type> TypePtr;
79 
80 class SimdLContext: public LContext
81 {
82   public:
83 
84     SimdLContext (std::istream &file,
85 		  Module *module,
86 		  SymbolTable &symtab);
87 
88     void		addInst (SimdInst *inst);
89     void		addStaticData (SimdReg *reg);
90 
91     struct Path
92     {
93 	SimdInst *	firstInst;
94 	SimdInst *	lastInst;
95     };
96 
currentPath()97     Path	currentPath () const			{return _currentPath;}
setCurrentPath(const Path & path)98     void	setCurrentPath (const Path &path)	{_currentPath = path;}
99     void        appendPath(const Path &path);
100     void	newPath ();
101 
102     virtual void	newStackFrame ();
103     virtual AddrPtr	parameterAddr (const DataTypePtr &parameterType);
104     virtual AddrPtr	returnValueAddr (const DataTypePtr &returnType);
105     virtual AddrPtr	autoVariableAddr (const DataTypePtr &variableType);
locals()106     virtual std::vector<DataTypePtr>& locals() { return _locals;}
107 
108     SimdModule *	simdModule ();
109 
110     void		mustFixCall (SimdCallInst *inst,
111 				     const SymbolInfoPtr &info);
112 
113     void		fixCalls ();
114 
115     //-----------------------------------------------
116     // Factory for syntax tree nodes and type objects
117     //-----------------------------------------------
118 
119     virtual ModuleNodePtr	newModuleNode
120 				    (int lineNumber,
121 				     const StatementNodePtr &constants,
122 				     const FunctionNodePtr &functions) const;
123 
124     virtual FunctionNodePtr	newFunctionNode
125 				    (int lineNumber,
126 				     const std::string &name,
127 				     const SymbolInfoPtr &info,
128 				     const StatementNodePtr &body) const;
129 
130     virtual VariableNodePtr	newVariableNode
131 				    (int lineNumber,
132 				     const std::string &name,
133 				     const SymbolInfoPtr &info,
134 				     const ExprNodePtr &initialValue,
135 				     bool assignInitialValue) const;
136 
137     virtual AssignmentNodePtr	newAssignmentNode
138 				    (int lineNumber,
139 				     const ExprNodePtr &lhs,
140 				     const ExprNodePtr &rhs) const;
141 
142     virtual ExprStatementNodePtr newExprStatementNode
143 				    (int lineNumber,
144 				     const ExprNodePtr &expr) const;
145 
146     virtual IfNodePtr		newIfNode
147 				    (int lineNumber,
148 				     const ExprNodePtr &condition,
149 				     const StatementNodePtr &truePath,
150 				     const StatementNodePtr &falsePath) const;
151 
152     virtual ReturnNodePtr	newReturnNode
153 				    (int lineNumber,
154 				     const SymbolInfoPtr &info,
155 				     const ExprNodePtr &returnedValue) const;
156 
157     virtual WhileNodePtr	newWhileNode
158 				    (int lineNumber,
159 				     const ExprNodePtr &condition,
160 				     const StatementNodePtr &loopBody) const;
161 
162     virtual BinaryOpNodePtr	newBinaryOpNode
163 				    (int lineNumber,
164 				     Token op,
165 				     const ExprNodePtr &leftOperand,
166 				     const ExprNodePtr &rightOperand) const;
167 
168     virtual UnaryOpNodePtr	newUnaryOpNode
169 				    (int lineNumber,
170 				     Token op,
171 				     const ExprNodePtr &operand) const;
172 
173     virtual ArrayIndexNodePtr	newArrayIndexNode
174 				    (int lineNumber,
175 				     const ExprNodePtr &array,
176 				     const ExprNodePtr &index) const;
177 
178     virtual MemberNodePtr	newMemberNode
179 				    (int lineNumber,
180 				     const ExprNodePtr &obj,
181 				     const std::string &member) const;
182 
183     virtual SizeNodePtr	        newSizeNode
184 				    (int lineNumber,
185 				     const ExprNodePtr &obj) const;
186 
187     virtual NameNodePtr		newNameNode
188 				    (int lineNumber,
189 				     const std::string &name,
190 				     const SymbolInfoPtr &info) const;
191 
192     virtual BoolLiteralNodePtr	newBoolLiteralNode
193 				    (int lineNumber, bool value) const;
194 
195     virtual IntLiteralNodePtr	newIntLiteralNode
196 				    (int lineNumber, int value) const;
197 
198     virtual UIntLiteralNodePtr	newUIntLiteralNode
199 				    (int lineNumber, unsigned value) const;
200 
201     virtual HalfLiteralNodePtr	newHalfLiteralNode
202 				    (int lineNumber, half value) const;
203 
204     virtual FloatLiteralNodePtr	newFloatLiteralNode
205 				    (int lineNumber, float value) const;
206 
207     virtual StringLiteralNodePtr newStringLiteralNode
208 				    (int lineNumber,
209 				     const std::string &value) const;
210 
211     virtual CallNodePtr		newCallNode
212 				    (int lineNumber,
213 				     const NameNodePtr &function,
214 				     const ExprNodeVector &arguments) const;
215 
216     virtual ValueNodePtr	newValueNode
217 				    (int lineNumber,
218 				     const ExprNodeVector &elements) const;
219 
220     virtual VoidTypePtr		newVoidType () const;
221 
222     virtual BoolTypePtr		newBoolType () const;
223 
224     virtual IntTypePtr		newIntType () const;
225 
226     virtual UIntTypePtr		newUIntType () const;
227 
228     virtual HalfTypePtr		newHalfType () const;
229 
230     virtual FloatTypePtr	newFloatType () const;
231 
232     virtual StringTypePtr	newStringType () const;
233 
234 
235     virtual ArrayTypePtr	newArrayType
236 				    (const DataTypePtr &baseType,
237 				     int size,
238 				     ArrayTypeUsage usage = NON_PARAMETER);
239 
240     virtual StructTypePtr	newStructType
241 				    (const std::string &name,
242 				     const MemberVector &members) const;
243 
244     virtual FunctionTypePtr	newFunctionType
245 				    (const DataTypePtr &returnType,
246 				     bool returnVarying,
247 				     const ParamVector &parameters) const;
248   private:
249 
250     struct FixCall
251     {
FixCallFixCall252 	FixCall (SimdCallInst * inst, const SymbolInfoPtr &info):
253 	    inst (inst), info (info) {}
254 
255 	SimdCallInst *	inst;
256 	SymbolInfoPtr	info;
257     };
258 
259     typedef std::list <FixCall> FixCallsList;
260 
261     Path		_currentPath;
262     int			_nextParameterAddr;
263     FixCallsList	_fixCallsList;
264 
265     std::vector<DataTypePtr> _locals;
266 };
267 
268 
269 } // namespace Ctl
270 
271 #endif
272