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_SYNTAX_TREE_H
57 #define INCLUDED_CTL_SIMD_SYNTAX_TREE_H
58 
59 //-----------------------------------------------------------------------------
60 //
61 //	The syntax tree for the SIMD implementation of the
62 //	color transformation language.
63 //
64 //-----------------------------------------------------------------------------
65 
66 #include <CtlSyntaxTree.h>
67 
68 namespace Ctl {
69 
70 class SimdLContext;
71 
72 class DataType;
73 typedef RcPtr<DataType> DataTypePtr;
74 
75 class SimdArrayType;
76 typedef RcPtr<SimdArrayType> SimdArrayTypePtr;
77 
78 class SimdValueNode;
79 typedef RcPtr<SimdValueNode> SimdValueNodePtr;
80 
81 struct SimdModuleNode: public ModuleNode
82 {
83     SimdModuleNode (int lineNumber,
84 		    const StatementNodePtr &constants,
85 		    const FunctionNodePtr &functions);
86 
87     virtual void	generateCode (LContext &lcontext);
88 };
89 
90 
91 struct SimdFunctionNode: public FunctionNode
92 {
93     SimdFunctionNode (int lineNumber,
94 		      const std::string &name,
95 		      const SymbolInfoPtr &info,
96 		      const StatementNodePtr &body,
97 		      const std::vector<DataTypePtr> locals);
98 
99     virtual void        generateESizeCode(SimdLContext &slcontext,
100 					  SimdArrayTypePtr arrayType);
101 
102     virtual void	generateCode (LContext &lcontext);
103     std::vector<DataTypePtr> _locals;
104 };
105 
106 
107 struct SimdVariableNode: public VariableNode
108 {
109     SimdVariableNode (int lineNumber,
110 		      const std::string &name,
111 		      const SymbolInfoPtr &info,
112 		      const ExprNodePtr &initialValue,
113 		      bool assignInitialValue);
114 
115     virtual void	generateCode (LContext &lcontext);
116 };
117 
118 
119 struct SimdAssignmentNode: public AssignmentNode
120 {
121     SimdAssignmentNode (int lineNumber,
122 			const ExprNodePtr &lhs,
123 			const ExprNodePtr &rhs);
124 
125     virtual void	generateCode (LContext &lcontext);
126 };
127 
128 
129 struct SimdExprStatementNode: public ExprStatementNode
130 {
131     SimdExprStatementNode (int lineNumber, const ExprNodePtr &expr);
132 
133     virtual void	generateCode (LContext &lcontext);
134 };
135 
136 
137 struct SimdIfNode: public IfNode
138 {
139     SimdIfNode (int lineNumber,
140 		const ExprNodePtr &condition,
141 		const StatementNodePtr &truePath,
142 		const StatementNodePtr &falsePath);
143 
144     virtual void	generateCode (LContext &lcontext);
145 };
146 
147 
148 struct SimdReturnNode: public ReturnNode
149 {
150     SimdReturnNode (int lineNumber,
151 		    const SymbolInfoPtr &info,
152 		    const ExprNodePtr &returnedValue);
153 
154     virtual void	generateCode (LContext &lcontext);
155 };
156 
157 
158 struct SimdWhileNode: public WhileNode
159 {
160     SimdWhileNode (int lineNumber,
161 		   const ExprNodePtr &condition,
162 		   const StatementNodePtr &loopBody);
163 
164     virtual void	generateCode (LContext &lcontext);
165 };
166 
167 
168 struct SimdBinaryOpNode: public BinaryOpNode
169 {
170     SimdBinaryOpNode (int lineNumber,
171 		      Token op,
172 		      const ExprNodePtr &leftOperand,
173 		      const ExprNodePtr &rightOperand);
174 
175     virtual void	generateCode (LContext &lcontext);
176 };
177 
178 
179 struct SimdUnaryOpNode: public UnaryOpNode
180 {
181     SimdUnaryOpNode (int lineNumber,
182 		     Token op,
183 		     const ExprNodePtr &operand);
184 
185     virtual void	generateCode (LContext &lcontext);
186 };
187 
188 
189 struct SimdArrayIndexNode: public ArrayIndexNode
190 {
191     SimdArrayIndexNode (int lineNumber,
192 			const ExprNodePtr &array,
193 			const ExprNodePtr &index);
194 
195     virtual void	generateCode (LContext &lcontext);
196 };
197 
198 
199 struct SimdMemberNode: public MemberNode
200 {
201     SimdMemberNode (int lineNumber,
202 		const ExprNodePtr &obj,
203 		const std::string &member);
204 
205     virtual void	generateCode (LContext &lcontext);
206 };
207 
208 struct SimdSizeNode: public SizeNode
209 {
210     SimdSizeNode (int lineNumber,
211 		  const ExprNodePtr &obj);
212 
213     virtual void	generateCode (LContext &lcontext);
214 };
215 
216 struct SimdNameNode: public NameNode
217 {
218     SimdNameNode (int lineNumber,
219 		  const std::string &name,
220 		  const SymbolInfoPtr &info);
221 
222     virtual void	generateCode (LContext &lcontext);
223 };
224 
225 
226 struct SimdBoolLiteralNode: public BoolLiteralNode
227 {
228     SimdBoolLiteralNode (int lineNumber,
229 			 const LContext &lcontext,
230 			 bool value);
231 
232     virtual void	generateCode (LContext &lcontext);
233     virtual char*       valuePtr();
234 };
235 
236 
237 struct SimdIntLiteralNode: public IntLiteralNode
238 {
239     SimdIntLiteralNode (int lineNumber,
240 			const LContext &lcontext,
241 			int value);
242 
243     virtual void	generateCode (LContext &lcontext);
244     virtual char*       valuePtr();
245 };
246 
247 
248 struct SimdUIntLiteralNode: public UIntLiteralNode
249 {
250     SimdUIntLiteralNode (int lineNumber,
251 			 const LContext &lcontext,
252 			 unsigned int value);
253 
254     virtual void	generateCode (LContext &lcontext);
255     virtual char*       valuePtr();
256 };
257 
258 
259 struct SimdHalfLiteralNode: public HalfLiteralNode
260 {
261     SimdHalfLiteralNode (int lineNumber,
262 			 const LContext &lcontext,
263 			 half value);
264 
265     virtual void	generateCode (LContext &lcontext);
266     virtual char*       valuePtr();
267 };
268 
269 
270 struct SimdFloatLiteralNode: public FloatLiteralNode
271 {
272     SimdFloatLiteralNode (int lineNumber,
273 			  const LContext &lcontext,
274 			  float value);
275 
276     virtual void	generateCode (LContext &lcontext);
277     virtual char*       valuePtr();
278 };
279 
280 
281 struct SimdStringLiteralNode: public StringLiteralNode
282 {
283     SimdStringLiteralNode (int lineNumber,
284 			   const LContext &lcontext,
285 			   const std::string &value);
286 
287     virtual void	generateCode (LContext &lcontext);
288     virtual char*       valuePtr();
289 };
290 
291 
292 struct SimdCallNode: public CallNode
293 {
294     SimdCallNode (int lineNumber,
295 		  const NameNodePtr &function,
296 		  const ExprNodeVector &arguments);
297 
298     bool                returnsType(const TypePtr &t) const;
299     virtual void	generateCode (LContext &lcontext);
300 };
301 
302 
303 struct SimdValueNode: public ValueNode
304 {
305     SimdValueNode (int lineNumber, const ExprNodeVector &elements);
306 
307     virtual void	generateCodeRec (LContext &lcontext,
308 					 const DataTypePtr &,
309 					 int& eIndex);
310     virtual void	generateCode (LContext &lcontext);
311 
312     virtual void        castAndCopyRec(LContext &lcontext,
313 				       const DataTypePtr &dataType,
314 				       int &eIndex,
315 				       char *dest,
316 				       const SizeVector &sizes,
317 				       const SizeVector &offsets);
318 };
319 
320 
321 } // namespace Ctl
322 
323 #endif
324