blob: 3fbdb271bf0415a0362f16c615e85f7ec852d480 [file] [log] [blame]
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001//
2// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
3// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7#include "OutputHLSL.h"
8
9#include "InfoSink.h"
10#include "debug.h"
11
12namespace sh
13{
14OutputHLSL::OutputHLSL(TParseContext &context) : TIntermTraverser(true, true, true), context(context)
15{
16}
17
18void OutputHLSL::header()
19{
20 EShLanguage language = context.language;
21 TInfoSinkBase &out = context.infoSink.obj;
22
23 if (language == EShLangFragment)
24 {
25 TString uniforms;
26 TString varyingInput;
27 TString varyingGlobals;
28
29 TSymbolTableLevel *symbols = context.symbolTable.getGlobalLevel();
30 int semanticIndex = 0;
31
32 for (TSymbolTableLevel::const_iterator namedSymbol = symbols->begin(); namedSymbol != symbols->end(); namedSymbol++)
33 {
34 const TSymbol *symbol = (*namedSymbol).second;
35 const TString &name = symbol->getName();
36
37 if (symbol->isVariable())
38 {
39 const TVariable *variable = static_cast<const TVariable*>(symbol);
40 const TType &type = variable->getType();
41 TQualifier qualifier = type.getQualifier();
42
43 if (qualifier == EvqUniform)
44 {
45 uniforms += "uniform " + typeString(type) + " " + name + arrayString(type) + ";\n";
46 }
47 else if (qualifier == EvqVaryingIn || qualifier == EvqInvariantVaryingIn)
48 {
49 char semantic[100];
50 sprintf(semantic, " : TEXCOORD%d", semanticIndex);
51 semanticIndex += type.isArray() ? type.getArraySize() : 1;
52
53 varyingInput += " " + typeString(type) + " " + name + arrayString(type) + semantic + ";\n";
54 varyingGlobals += "static " + typeString(type) + " " + name + arrayString(type) + " = " + initializer(type) + ";\n";
55 }
56 }
57 }
58
daniel@transgaming.com9b5f5442010-03-16 05:43:55 +000059 out << "uniform float4 gl_Window;\n"
60 "uniform float2 gl_Depth;\n"
daniel@transgaming.com79b820b2010-03-16 05:48:57 +000061 "uniform bool __frontCCW;\n"
daniel@transgaming.com9b5f5442010-03-16 05:43:55 +000062 "\n";
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000063 out << uniforms;
daniel@transgaming.com86487c22010-03-11 19:41:43 +000064 out << "\n"
65 "struct PS_INPUT\n" // FIXME: Prevent name clashes
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000066 "{\n";
daniel@transgaming.com9b5f5442010-03-16 05:43:55 +000067 out << varyingInput;
daniel@transgaming.com79b820b2010-03-16 05:48:57 +000068 out << " float4 gl_FragCoord : TEXCOORD" << HLSL_FRAG_COORD_SEMANTIC << ";\n";
69 out << " float __vFace : VFACE;\n"
daniel@transgaming.com9b5f5442010-03-16 05:43:55 +000070 "};\n"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000071 "\n";
72 out << varyingGlobals;
73 out << "\n"
74 "struct PS_OUTPUT\n" // FIXME: Prevent name clashes
75 "{\n"
76 " float4 gl_Color[1] : COLOR;\n"
77 "};\n"
78 "\n"
79 "static float4 gl_Color[1] = {float4(0, 0, 0, 0)};\n"
daniel@transgaming.com9b5f5442010-03-16 05:43:55 +000080 "static float4 gl_FragCoord = float4(0, 0, 0, 0);\n"
daniel@transgaming.com79b820b2010-03-16 05:48:57 +000081 "static bool gl_FrontFacing = false;\n"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000082 "\n"
83 "float4 gl_texture2D(sampler2D s, float2 t)\n"
84 "{\n"
85 " return tex2D(s, t);\n"
86 "}\n"
87 "\n"
88 "float4 gl_texture2DProj(sampler2D s, float3 t)\n"
89 "{\n"
90 " return tex2Dproj(s, float4(t.x, t.y, 0, t.z));\n"
91 "}\n"
92 "float4 gl_texture2DBias(sampler2D s, float2 t, float bias)\n"
93 "{\n"
94 " return tex2Dbias(s, float4(t.x, t.y, 0, bias));\n"
95 "}\n"
96 "\n"
97 "float4 gl_textureCube(samplerCUBE s, float3 t)\n"
98 "{\n"
99 " return texCUBE(s, t);\n"
100 "}\n"
101 "\n";
102 }
103 else
104 {
105 TString uniforms;
106 TString attributeInput;
107 TString attributeGlobals;
108 TString varyingOutput;
109 TString varyingGlobals;
110 TString globals;
111
112 TSymbolTableLevel *symbols = context.symbolTable.getGlobalLevel();
113 int semanticIndex = 0;
114
115 for (TSymbolTableLevel::const_iterator namedSymbol = symbols->begin(); namedSymbol != symbols->end(); namedSymbol++)
116 {
117 const TSymbol *symbol = (*namedSymbol).second;
118 const TString &name = symbol->getName();
119
120 if (symbol->isVariable())
121 {
122 const TVariable *variable = static_cast<const TVariable*>(symbol);
123 const TType &type = variable->getType();
124 TQualifier qualifier = type.getQualifier();
125
126 if (qualifier == EvqUniform)
127 {
128 uniforms += "uniform " + typeString(type) + " " + name + arrayString(type) + ";\n";
129 }
130 else if (qualifier == EvqAttribute)
131 {
132 char semantic[100];
133 sprintf(semantic, " : TEXCOORD%d", semanticIndex);
134 semanticIndex += type.isArray() ? type.getArraySize() : 1;
135
136 attributeInput += " " + typeString(type) + " " + name + arrayString(type) + semantic + ";\n";
137 attributeGlobals += "static " + typeString(type) + " " + name + arrayString(type) + " = " + initializer(type) + ";\n";
138 }
139 else if (qualifier == EvqVaryingOut || qualifier == EvqInvariantVaryingOut)
140 {
141 varyingOutput += " " + typeString(type) + " " + name + arrayString(type) + " : TEXCOORD0;\n"; // Actual semantic index assigned during link
142 varyingGlobals += "static " + typeString(type) + " " + name + arrayString(type) + " = " + initializer(type) + ";\n";
143 }
144 else if (qualifier == EvqGlobal)
145 {
146 globals += typeString(type) + " " + name + arrayString(type) + ";\n";
147 }
148 else UNREACHABLE();
149 }
150 }
151
daniel@transgaming.com9b5f5442010-03-16 05:43:55 +0000152 out << "uniform float2 gl_HalfPixelSize;\n"
153 "\n";
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000154 out << uniforms;
155 out << "\n";
156 out << globals;
daniel@transgaming.com9b5f5442010-03-16 05:43:55 +0000157 out << "\n"
158 "struct VS_INPUT\n" // FIXME: Prevent name clashes
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000159 "{\n";
160 out << attributeInput;
161 out << "};\n"
162 "\n";
163 out << attributeGlobals;
164 out << "\n"
165 "struct VS_OUTPUT\n" // FIXME: Prevent name clashes
166 "{\n"
167 " float4 gl_Position : POSITION;\n"
daniel@transgaming.com9b5f5442010-03-16 05:43:55 +0000168 " float gl_PointSize : PSIZE;\n"
169 " float4 gl_FragCoord : TEXCOORD" << HLSL_FRAG_COORD_SEMANTIC << ";\n";
170 out << varyingOutput;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000171 out << "};\n"
172 "\n"
173 "static float4 gl_Position = float4(0, 0, 0, 0);\n"
174 "static float gl_PointSize = float(0);\n";
175 out << varyingGlobals;
176 out << "\n";
177 }
178
daniel@transgaming.com86487c22010-03-11 19:41:43 +0000179 out << "struct gl_DepthRangeParameters\n"
180 "{\n"
181 " float near;\n"
182 " float far;\n"
183 " float diff;\n"
184 "};\n"
185 "\n"
186 "uniform gl_DepthRangeParameters gl_DepthRange;\n"
187 "\n"
188 "float vec1(float x)\n" // FIXME: Prevent name clashes
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000189 "{\n"
190 " return x;\n"
191 "}\n"
192 "\n"
193 "float vec1(float2 xy)\n" // FIXME: Prevent name clashes
194 "{\n"
195 " return xy[0];\n"
196 "}\n"
197 "\n"
198 "float vec1(float3 xyz)\n" // FIXME: Prevent name clashes
199 "{\n"
200 " return xyz[0];\n"
201 "}\n"
202 "\n"
203 "float vec1(float4 xyzw)\n" // FIXME: Prevent name clashes
204 "{\n"
205 " return xyzw[0];\n"
206 "}\n"
207 "\n"
208 "float2 vec2(float x)\n" // FIXME: Prevent name clashes
209 "{\n"
210 " return float2(x, x);\n"
211 "}\n"
212 "\n"
213 "float2 vec2(float x, float y)\n" // FIXME: Prevent name clashes
214 "{\n"
215 " return float2(x, y);\n"
216 "}\n"
217 "\n"
218 "float2 vec2(float2 xy)\n" // FIXME: Prevent name clashes
219 "{\n"
220 " return xy;\n"
221 "}\n"
222 "\n"
223 "float2 vec2(float3 xyz)\n" // FIXME: Prevent name clashes
224 "{\n"
225 " return float2(xyz[0], xyz[1]);\n"
226 "}\n"
227 "\n"
228 "float2 vec2(float4 xyzw)\n" // FIXME: Prevent name clashes
229 "{\n"
230 " return float2(xyzw[0], xyzw[1]);\n"
231 "}\n"
232 "\n"
233 "float3 vec3(float x)\n" // FIXME: Prevent name clashes
234 "{\n"
235 " return float3(x, x, x);\n"
236 "}\n"
237 "\n"
238 "float3 vec3(float x, float y, float z)\n" // FIXME: Prevent name clashes
239 "{\n"
240 " return float3(x, y, z);\n"
241 "}\n"
242 "\n"
243 "float3 vec3(float2 xy, float z)\n" // FIXME: Prevent name clashes
244 "{\n"
245 " return float3(xy[0], xy[1], z);\n"
246 "}\n"
247 "\n"
248 "float3 vec3(float x, float2 yz)\n" // FIXME: Prevent name clashes
249 "{\n"
250 " return float3(x, yz[0], yz[1]);\n"
251 "}\n"
252 "\n"
253 "float3 vec3(float3 xyz)\n" // FIXME: Prevent name clashes
254 "{\n"
255 " return xyz;\n"
256 "}\n"
257 "\n"
258 "float3 vec3(float4 xyzw)\n" // FIXME: Prevent name clashes
259 "{\n"
260 " return float3(xyzw[0], xyzw[1], xyzw[2]);\n"
261 "}\n"
262 "\n"
263 "float4 vec4(float x)\n" // FIXME: Prevent name clashes
264 "{\n"
265 " return float4(x, x, x, x);\n"
266 "}\n"
267 "\n"
268 "float4 vec4(float x, float y, float z, float w)\n" // FIXME: Prevent name clashes
269 "{\n"
270 " return float4(x, y, z, w);\n"
271 "}\n"
272 "\n"
273 "float4 vec4(float2 xy, float z, float w)\n" // FIXME: Prevent name clashes
274 "{\n"
275 " return float4(xy[0], xy[1], z, w);\n"
276 "}\n"
277 "\n"
278 "float4 vec4(float x, float2 yz, float w)\n" // FIXME: Prevent name clashes
279 "{\n"
280 " return float4(x, yz[0], yz[1], w);\n"
281 "}\n"
282 "\n"
283 "float4 vec4(float x, float y, float2 zw)\n" // FIXME: Prevent name clashes
284 "{\n"
285 " return float4(x, y, zw[0], zw[1]);\n"
286 "}\n"
287 "\n"
288 "float4 vec4(float2 xy, float2 zw)\n" // FIXME: Prevent name clashes
289 "{\n"
290 " return float4(xy[0], xy[1], zw[0], zw[1]);\n"
291 "}\n"
292 "\n"
293 "float4 vec4(float3 xyz, float w)\n" // FIXME: Prevent name clashes
294 "{\n"
295 " return float4(xyz[0], xyz[1], xyz[2], w);\n"
296 "}\n"
297 "\n"
298 "float4 vec4(float x, float3 yzw)\n" // FIXME: Prevent name clashes
299 "{\n"
300 " return float4(x, yzw[0], yzw[1], yzw[2]);\n"
301 "}\n"
302 "\n"
303 "float4 vec4(float4 xyzw)\n" // FIXME: Prevent name clashes
304 "{\n"
305 " return xyzw;\n"
306 "}\n"
307 "\n"
308 "bool xor(bool p, bool q)\n" // FIXME: Prevent name clashes
309 "{\n"
310 " return (p || q) && !(p && q);\n"
311 "}\n"
312 "\n"
313 "float mod(float x, float y)\n" // FIXME: Prevent name clashes
314 "{\n"
315 " return x - y * floor(x / y);\n"
316 "}\n"
daniel@transgaming.com680553b2010-03-08 21:30:52 +0000317 "\n"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000318 "float2 mod(float2 x, float y)\n" // FIXME: Prevent name clashes
319 "{\n"
320 " return x - y * floor(x / y);\n"
321 "}\n"
daniel@transgaming.com680553b2010-03-08 21:30:52 +0000322 "\n"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000323 "float3 mod(float3 x, float y)\n" // FIXME: Prevent name clashes
324 "{\n"
325 " return x - y * floor(x / y);\n"
326 "}\n"
daniel@transgaming.com680553b2010-03-08 21:30:52 +0000327 "\n"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000328 "float4 mod(float4 x, float y)\n" // FIXME: Prevent name clashes
329 "{\n"
330 " return x - y * floor(x / y);\n"
331 "}\n"
daniel@transgaming.com680553b2010-03-08 21:30:52 +0000332 "\n"
333 "float faceforward(float N, float I, float Nref)\n" // FIXME: Prevent name clashes
334 "{\n"
335 " if(dot(Nref, I) < 0)\n"
336 " {\n"
337 " return N;\n"
338 " }\n"
339 " else\n"
340 " {\n"
341 " return -N;\n"
342 " }\n"
343 "}\n"
344 "\n"
345 "float2 faceforward(float2 N, float2 I, float2 Nref)\n" // FIXME: Prevent name clashes
346 "{\n"
347 " if(dot(Nref, I) < 0)\n"
348 " {\n"
349 " return N;\n"
350 " }\n"
351 " else\n"
352 " {\n"
353 " return -N;\n"
354 " }\n"
355 "}\n"
356 "\n"
357 "float3 faceforward(float3 N, float3 I, float3 Nref)\n" // FIXME: Prevent name clashes
358 "{\n"
359 " if(dot(Nref, I) < 0)\n"
360 " {\n"
361 " return N;\n"
362 " }\n"
363 " else\n"
364 " {\n"
365 " return -N;\n"
366 " }\n"
367 "}\n"
368 "float4 faceforward(float4 N, float4 I, float4 Nref)\n" // FIXME: Prevent name clashes
369 "{\n"
370 " if(dot(Nref, I) < 0)\n"
371 " {\n"
372 " return N;\n"
373 " }\n"
374 " else\n"
375 " {\n"
376 " return -N;\n"
377 " }\n"
378 "}\n"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000379 "\n";
380}
381
382void OutputHLSL::visitSymbol(TIntermSymbol *node)
383{
384 TInfoSinkBase &out = context.infoSink.obj;
385
386 TString name = node->getSymbol();
387
388 if (name == "gl_FragColor")
389 {
390 out << "gl_Color[0]";
391 }
392 else if (name == "gl_FragData")
393 {
394 out << "gl_Color";
395 }
396 else
397 {
398 out << name;
399 }
400}
401
402bool OutputHLSL::visitBinary(Visit visit, TIntermBinary *node)
403{
404 TInfoSinkBase &out = context.infoSink.obj;
405
406 switch (node->getOp())
407 {
daniel@transgaming.com86487c22010-03-11 19:41:43 +0000408 case EOpAssign: outputTriplet(visit, "(", " = ", ")"); break;
409 case EOpInitialize: outputTriplet(visit, NULL, " = ", NULL); break;
410 case EOpAddAssign: outputTriplet(visit, NULL, " += ", NULL); break;
411 case EOpSubAssign: outputTriplet(visit, NULL, " -= ", NULL); break;
daniel@transgaming.com45d03582010-03-11 19:41:29 +0000412 case EOpMulAssign: outputTriplet(visit, NULL, " *= ", NULL); break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000413 case EOpVectorTimesMatrixAssign: UNIMPLEMENTED(); /* FIXME */ out << "matrix mult second child into first child"; break;
daniel@transgaming.com45d03582010-03-11 19:41:29 +0000414 case EOpVectorTimesScalarAssign: outputTriplet(visit, NULL, " *= ", NULL); break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000415 case EOpMatrixTimesScalarAssign: UNIMPLEMENTED(); /* FIXME */ out << "matrix scale second child into first child"; break;
416 case EOpMatrixTimesMatrixAssign: UNIMPLEMENTED(); /* FIXME */ out << "matrix mult second child into first child"; break;
daniel@transgaming.com45d03582010-03-11 19:41:29 +0000417 case EOpDivAssign: outputTriplet(visit, NULL, " /= ", NULL); break;
daniel@transgaming.com45d03582010-03-11 19:41:29 +0000418 case EOpIndexDirect: outputTriplet(visit, NULL, "[", "]"); break;
419 case EOpIndexIndirect: outputTriplet(visit, NULL, "[", "]"); break;
420 case EOpIndexDirectStruct: outputTriplet(visit, NULL, ".", NULL); break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000421 case EOpVectorSwizzle:
422 if (visit == InVisit)
423 {
424 out << ".";
425
426 TIntermAggregate *swizzle = node->getRight()->getAsAggregate();
427
428 if (swizzle)
429 {
430 TIntermSequence &sequence = swizzle->getSequence();
431
432 for (TIntermSequence::iterator sit = sequence.begin(); sit != sequence.end(); sit++)
433 {
434 TIntermConstantUnion *element = (*sit)->getAsConstantUnion();
435
436 if (element)
437 {
438 int i = element->getUnionArrayPointer()[0].getIConst();
439
440 switch (i)
441 {
442 case 0: out << "x"; break;
443 case 1: out << "y"; break;
444 case 2: out << "z"; break;
445 case 3: out << "w"; break;
446 default: UNREACHABLE();
447 }
448 }
449 else UNREACHABLE();
450 }
451 }
452 else UNREACHABLE();
453
454 return false; // Fully processed
455 }
456 break;
457 case EOpAdd: outputTriplet(visit, "(", " + ", ")"); break;
458 case EOpSub: outputTriplet(visit, "(", " - ", ")"); break;
459 case EOpMul: outputTriplet(visit, "(", " * ", ")"); break;
460 case EOpDiv: outputTriplet(visit, "(", " / ", ")"); break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000461 case EOpEqual: outputTriplet(visit, "(", " == ", ")"); break;
462 case EOpNotEqual: outputTriplet(visit, "(", " != ", ")"); break;
463 case EOpLessThan: outputTriplet(visit, "(", " < ", ")"); break;
464 case EOpGreaterThan: outputTriplet(visit, "(", " > ", ")"); break;
465 case EOpLessThanEqual: outputTriplet(visit, "(", " <= ", ")"); break;
466 case EOpGreaterThanEqual: outputTriplet(visit, "(", " >= ", ")"); break;
467 case EOpVectorTimesScalar: outputTriplet(visit, "(", " * ", ")"); break;
468 case EOpVectorTimesMatrix: UNIMPLEMENTED(); /* FIXME */ out << "vector-times-matrix"; break;
469 case EOpMatrixTimesVector: outputTriplet(visit, "mul(", ", ", ")"); break;
470 case EOpMatrixTimesScalar: UNIMPLEMENTED(); /* FIXME */ out << "matrix-scale"; break;
471 case EOpMatrixTimesMatrix: UNIMPLEMENTED(); /* FIXME */ out << "matrix-multiply"; break;
472 case EOpLogicalOr: outputTriplet(visit, "(", " || ", ")"); break;
473 case EOpLogicalXor: outputTriplet(visit, "xor(", ", ", ")"); break; // FIXME: Prevent name clashes
474 case EOpLogicalAnd: outputTriplet(visit, "(", " && ", ")"); break;
475 default: UNREACHABLE();
476 }
477
478 return true;
479}
480
481bool OutputHLSL::visitUnary(Visit visit, TIntermUnary *node)
482{
483 TInfoSinkBase &out = context.infoSink.obj;
484
485 switch (node->getOp())
486 {
487 case EOpNegative: outputTriplet(visit, "(-", NULL, ")"); break;
488 case EOpVectorLogicalNot: outputTriplet(visit, "(!", NULL, ")"); break;
489 case EOpLogicalNot: outputTriplet(visit, "(!", NULL, ")"); break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000490 case EOpPostIncrement: outputTriplet(visit, "(", NULL, "++)"); break;
491 case EOpPostDecrement: outputTriplet(visit, "(", NULL, "--)"); break;
492 case EOpPreIncrement: outputTriplet(visit, "(++", NULL, ")"); break;
493 case EOpPreDecrement: outputTriplet(visit, "(--", NULL, ")"); break;
494 case EOpConvIntToBool:
495 case EOpConvFloatToBool:
496 switch (node->getOperand()->getType().getNominalSize())
497 {
498 case 1: outputTriplet(visit, "bool(", NULL, ")"); break;
499 case 2: outputTriplet(visit, "bool2(", NULL, ")"); break;
500 case 3: outputTriplet(visit, "bool3(", NULL, ")"); break;
501 case 4: outputTriplet(visit, "bool4(", NULL, ")"); break;
502 default: UNREACHABLE();
503 }
504 break;
505 case EOpConvBoolToFloat:
506 case EOpConvIntToFloat:
507 switch (node->getOperand()->getType().getNominalSize())
508 {
509 case 1: outputTriplet(visit, "float(", NULL, ")"); break;
510 case 2: outputTriplet(visit, "float2(", NULL, ")"); break;
511 case 3: outputTriplet(visit, "float3(", NULL, ")"); break;
512 case 4: outputTriplet(visit, "float4(", NULL, ")"); break;
513 default: UNREACHABLE();
514 }
515 break;
516 case EOpConvFloatToInt:
517 case EOpConvBoolToInt:
518 switch (node->getOperand()->getType().getNominalSize())
519 {
520 case 1: outputTriplet(visit, "int(", NULL, ")"); break;
521 case 2: outputTriplet(visit, "int2(", NULL, ")"); break;
522 case 3: outputTriplet(visit, "int3(", NULL, ")"); break;
523 case 4: outputTriplet(visit, "int4(", NULL, ")"); break;
524 default: UNREACHABLE();
525 }
526 break;
527 case EOpRadians: outputTriplet(visit, "radians(", NULL, ")"); break;
528 case EOpDegrees: outputTriplet(visit, "degrees(", NULL, ")"); break;
529 case EOpSin: outputTriplet(visit, "sin(", NULL, ")"); break;
530 case EOpCos: outputTriplet(visit, "cos(", NULL, ")"); break;
531 case EOpTan: outputTriplet(visit, "tan(", NULL, ")"); break;
532 case EOpAsin: outputTriplet(visit, "asin(", NULL, ")"); break;
533 case EOpAcos: outputTriplet(visit, "acos(", NULL, ")"); break;
534 case EOpAtan: outputTriplet(visit, "atan(", NULL, ")"); break;
535 case EOpExp: outputTriplet(visit, "exp(", NULL, ")"); break;
536 case EOpLog: outputTriplet(visit, "log(", NULL, ")"); break;
537 case EOpExp2: outputTriplet(visit, "exp2(", NULL, ")"); break;
538 case EOpLog2: outputTriplet(visit, "log2(", NULL, ")"); break;
539 case EOpSqrt: outputTriplet(visit, "sqrt(", NULL, ")"); break;
540 case EOpInverseSqrt: outputTriplet(visit, "rsqrt(", NULL, ")"); break;
541 case EOpAbs: outputTriplet(visit, "abs(", NULL, ")"); break;
542 case EOpSign: outputTriplet(visit, "sign(", NULL, ")"); break;
543 case EOpFloor: outputTriplet(visit, "floor(", NULL, ")"); break;
544 case EOpCeil: outputTriplet(visit, "ceil(", NULL, ")"); break;
545 case EOpFract: outputTriplet(visit, "frac(", NULL, ")"); break;
546 case EOpLength: outputTriplet(visit, "length(", NULL, ")"); break;
547 case EOpNormalize: outputTriplet(visit, "normalize(", NULL, ")"); break;
daniel@transgaming.com45d03582010-03-11 19:41:29 +0000548// case EOpDPdx: outputTriplet(visit, "ddx(", NULL, ")"); break;
549// case EOpDPdy: outputTriplet(visit, "ddy(", NULL, ")"); break;
550// case EOpFwidth: outputTriplet(visit, "fwidth(", NULL, ")"); break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000551 case EOpAny: outputTriplet(visit, "any(", NULL, ")"); break;
552 case EOpAll: outputTriplet(visit, "all(", NULL, ")"); break;
553 default: UNREACHABLE();
554 }
555
556 return true;
557}
558
559bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
560{
561 EShLanguage language = context.language;
562 TInfoSinkBase &out = context.infoSink.obj;
563
564 if (node->getOp() == EOpNull)
565 {
566 out.message(EPrefixError, "node is still EOpNull!");
567 return true;
568 }
569
570 switch (node->getOp())
571 {
572 case EOpSequence: outputTriplet(visit, NULL, ";\n", ";\n"); break;
573 case EOpDeclaration:
574 if (visit == PreVisit)
575 {
576 TIntermSequence &sequence = node->getSequence();
577 TIntermTyped *variable = sequence[0]->getAsTyped();
578 bool visit = true;
579
580 if (variable && variable->getQualifier() == EvqTemporary)
581 {
582 out << typeString(variable->getType()) + " ";
583
584 for (TIntermSequence::iterator sit = sequence.begin(); sit != sequence.end(); sit++)
585 {
586 TIntermSymbol *symbol = (*sit)->getAsSymbolNode();
587
588 if (symbol)
589 {
590 symbol->traverse(this);
591
592 out << arrayString(symbol->getType());
593 }
594 else
595 {
596 (*sit)->traverse(this);
597 }
598
599 if (visit && this->inVisit)
600 {
601 if (*sit != sequence.back())
602 {
603 visit = this->visitAggregate(InVisit, node);
604 }
605 }
606 }
607
608 if (visit && this->postVisit)
609 {
610 this->visitAggregate(PostVisit, node);
611 }
612 }
613
614 return false;
615 }
616 else if (visit == InVisit)
617 {
618 out << ", ";
619 }
620 break;
621 case EOpComma: UNIMPLEMENTED(); /* FIXME */ out << "Comma\n"; return true;
622 case EOpFunction:
623 {
624 const TString &mangledName = node->getName();
625 TString name = TString(mangledName.c_str(), mangledName.find_first_of('('));
626
627 if (visit == PreVisit)
628 {
629 if (name == "main")
630 {
631 TSymbolTableLevel *symbols = context.symbolTable.getGlobalLevel();
632
633 if (language == EShLangFragment)
634 {
635 out << "PS_OUTPUT main(PS_INPUT input)\n" // FIXME: Prevent name clashes
daniel@transgaming.com9b5f5442010-03-16 05:43:55 +0000636 "{\n"
637 " float rhw = 1.0 / input.gl_FragCoord.w;\n"
638 " gl_FragCoord.x = (input.gl_FragCoord.x * rhw) * gl_Window.x + gl_Window.z;\n"
639 " gl_FragCoord.y = (input.gl_FragCoord.y * rhw) * gl_Window.y + gl_Window.w;\n"
640 " gl_FragCoord.z = (input.gl_FragCoord.z * rhw) * gl_Depth.x + gl_Depth.y;\n"
daniel@transgaming.com79b820b2010-03-16 05:48:57 +0000641 " gl_FragCoord.w = rhw;\n"
642 " gl_FrontFacing = __frontCCW ? (input.__vFace >= 0.0) : (input.__vFace <= 0.0);\n";
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000643
644 for (TSymbolTableLevel::const_iterator namedSymbol = symbols->begin(); namedSymbol != symbols->end(); namedSymbol++)
645 {
646 const TSymbol *symbol = (*namedSymbol).second;
647 const TString &name = symbol->getName();
648
649 if (symbol->isVariable())
650 {
651 const TVariable *variable = static_cast<const TVariable*>(symbol);
652 const TType &type = variable->getType();
653 TQualifier qualifier = type.getQualifier();
654
655 if(qualifier == EvqVaryingIn)
656 {
657 out << " " + name + " = input." + name + ";\n"; // FIXME: Prevent name clashes
658 }
659 }
660 }
661 }
662 else
663 {
664 out << "VS_OUTPUT main(VS_INPUT input)\n" // FIXME: Prevent name clashes
665 "{\n";
666
667 for (TSymbolTableLevel::const_iterator namedSymbol = symbols->begin(); namedSymbol != symbols->end(); namedSymbol++)
668 {
669 const TSymbol *symbol = (*namedSymbol).second;
670 const TString &name = symbol->getName();
671
672 if (symbol->isVariable())
673 {
674 const TVariable *variable = static_cast<const TVariable*>(symbol);
675 const TType &type = variable->getType();
676 TQualifier qualifier = type.getQualifier();
677
678 if (qualifier == EvqAttribute)
679 {
680 out << " " + name + " = input." + name + ";\n"; // FIXME: Prevent name clashes
681 }
682 }
683 }
684 }
685
686 // Erase the (empty) argument list
687 TIntermSequence &sequence = node->getSequence();
688 sequence.erase(sequence.begin());
689 }
690 else
691 {
692 out << typeString(node->getType()) << " " << name << "(";
693
694 TIntermSequence &sequence = node->getSequence();
695 TIntermSequence &arguments = sequence[0]->getAsAggregate()->getSequence();
696
697 for (unsigned int i = 0; i < arguments.size(); i++)
698 {
699 TIntermSymbol *symbol = arguments[i]->getAsSymbolNode();
700
701 if (symbol)
702 {
703 const TType &type = symbol->getType();
704 const TString &name = symbol->getSymbol();
705
706 out << typeString(type) + " " + name;
707
708 if(i < arguments.size() - 1)
709 {
710 out << ", ";
711 }
712 }
713 else UNREACHABLE();
714 }
715
716 sequence.erase(sequence.begin());
717
718 out << ")\n"
719 "{\n";
720 }
721 }
722 else if (visit == PostVisit)
723 {
724 if (name == "main")
725 {
726 if (language == EShLangFragment)
727 {
728 out << " PS_OUTPUT output;\n" // FIXME: Prevent name clashes
729 " output.gl_Color[0] = gl_Color[0];\n"; // FIXME: Prevent name clashes
730
731 TSymbolTableLevel *symbols = context.symbolTable.getGlobalLevel();
732
733 for (TSymbolTableLevel::const_iterator namedSymbol = symbols->begin(); namedSymbol != symbols->end(); namedSymbol++)
734 {
735 const TSymbol *symbol = (*namedSymbol).second;
736 const TString &name = symbol->getName();
737 }
738 }
739 else
740 {
741 out << " VS_OUTPUT output;\n" // FIXME: Prevent name clashes
742 " output.gl_Position.x = gl_Position.x - gl_HalfPixelSize.x * gl_Position.w;\n"
743 " output.gl_Position.y = -(gl_Position.y - gl_HalfPixelSize.y * gl_Position.w);\n"
744 " output.gl_Position.z = (gl_Position.z + gl_Position.w) * 0.5;\n"
745 " output.gl_Position.w = gl_Position.w;\n"
daniel@transgaming.com9b5f5442010-03-16 05:43:55 +0000746 " output.gl_PointSize = gl_PointSize;\n"
747 " output.gl_FragCoord = gl_Position;\n";
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000748
749 TSymbolTableLevel *symbols = context.symbolTable.getGlobalLevel();
750
751 for (TSymbolTableLevel::const_iterator namedSymbol = symbols->begin(); namedSymbol != symbols->end(); namedSymbol++)
752 {
753 const TSymbol *symbol = (*namedSymbol).second;
754 const TString &name = symbol->getName();
755
756 if (symbol->isVariable())
757 {
758 const TVariable *variable = static_cast<const TVariable*>(symbol);
759 TQualifier qualifier = variable->getType().getQualifier();
760
761 if(qualifier == EvqVaryingOut || qualifier == EvqInvariantVaryingOut)
762 {
763 out << " output." + name + " = " + name + ";\n"; // FIXME: Prevent name clashes
764 }
765 }
766 }
767 }
768
769 out << " return output;\n" // FIXME: Prevent name clashes
770 "}\n";
771 }
772 else
773 {
774 out << "}\n";
775 }
776 }
777 }
778 break;
779 case EOpFunctionCall:
780 {
781 if (visit == PreVisit)
782 {
783 const TString &mangledName = node->getName();
784 TString name = TString(mangledName.c_str(), mangledName.find_first_of('('));
785
786 if (node->isUserDefined())
787 {
788 out << name << "(";
789 }
790 else
791 {
792 if (name == "texture2D")
793 {
794 if (node->getSequence().size() == 2)
795 {
796 out << "gl_texture2D(";
797 }
798 else if (node->getSequence().size() == 3)
799 {
800 out << "gl_texture2DBias(";
801 }
802 else UNREACHABLE();
803 }
804 else if (name == "texture2DProj")
805 {
806 out << "gl_texture2DProj(";
807 }
808 else if (name == "texture2DLod")
809 {
810 out << "gl_texture2DLod(";
811 UNIMPLEMENTED(); // FIXME: Move lod to last texture coordinate component
812 }
813 else if (name == "texture2DProjLod")
814 {
815 out << "gl_texture2DProjLod(";
816 UNIMPLEMENTED(); // FIXME: Move lod to last texture coordinate component
817 }
818 else if (name == "textureCube")
819 {
820 out << "gl_textureCube("; // FIXME: Incorrect sampling location
821 }
822 else
823 {
824 UNIMPLEMENTED(); // FIXME
825 }
826 }
827 }
828 else if (visit == InVisit)
829 {
830 out << ", ";
831 }
832 else
833 {
834 out << ")";
835 }
836 }
837 break;
838 case EOpParameters: outputTriplet(visit, "(", ", ", ")\n{\n"); break;
839 case EOpConstructFloat: outputTriplet(visit, "vec1(", NULL, ")"); break;
840 case EOpConstructVec2: outputTriplet(visit, "vec2(", ", ", ")"); break;
841 case EOpConstructVec3: outputTriplet(visit, "vec3(", ", ", ")"); break;
842 case EOpConstructVec4: outputTriplet(visit, "vec4(", ", ", ")"); break;
843 case EOpConstructBool: UNIMPLEMENTED(); /* FIXME */ out << "Construct bool"; break;
844 case EOpConstructBVec2: UNIMPLEMENTED(); /* FIXME */ out << "Construct bvec2"; break;
845 case EOpConstructBVec3: UNIMPLEMENTED(); /* FIXME */ out << "Construct bvec3"; break;
846 case EOpConstructBVec4: UNIMPLEMENTED(); /* FIXME */ out << "Construct bvec4"; break;
847 case EOpConstructInt: UNIMPLEMENTED(); /* FIXME */ out << "Construct int"; break;
848 case EOpConstructIVec2: UNIMPLEMENTED(); /* FIXME */ out << "Construct ivec2"; break;
849 case EOpConstructIVec3: UNIMPLEMENTED(); /* FIXME */ out << "Construct ivec3"; break;
850 case EOpConstructIVec4: UNIMPLEMENTED(); /* FIXME */ out << "Construct ivec4"; break;
851 case EOpConstructMat2: outputTriplet(visit, "float2x2(", ", ", ")"); break;
852 case EOpConstructMat3: outputTriplet(visit, "float3x3(", ", ", ")"); break;
853 case EOpConstructMat4: UNIMPLEMENTED(); /* FIXME */ out << "Construct mat4"; break;
854 case EOpConstructStruct: UNIMPLEMENTED(); /* FIXME */ out << "Construct structure"; break;
855 case EOpLessThan: outputTriplet(visit, "(", " < ", ")"); break;
856 case EOpGreaterThan: outputTriplet(visit, "(", " > ", ")"); break;
857 case EOpLessThanEqual: outputTriplet(visit, "(", " <= ", ")"); break;
858 case EOpGreaterThanEqual: outputTriplet(visit, "(", " >= ", ")"); break;
859 case EOpVectorEqual: outputTriplet(visit, "(", " == ", ")"); break;
860 case EOpVectorNotEqual: outputTriplet(visit, "(", " != ", ")"); break;
861 case EOpMod: outputTriplet(visit, "mod(", ", ", ")"); break; // FIXME: Prevent name clashes
862 case EOpPow: outputTriplet(visit, "pow(", ", ", ")"); break;
863 case EOpAtan:
864 if (node->getSequence().size() == 1)
865 {
866 outputTriplet(visit, "atan(", ", ", ")");
867 }
868 else if (node->getSequence().size() == 2)
869 {
870 outputTriplet(visit, "atan2(", ", ", ")");
871 }
872 else UNREACHABLE();
873 break;
874 case EOpMin: outputTriplet(visit, "min(", ", ", ")"); break;
875 case EOpMax: outputTriplet(visit, "max(", ", ", ")"); break;
876 case EOpClamp: outputTriplet(visit, "clamp(", ", ", ")"); break;
877 case EOpMix: outputTriplet(visit, "lerp(", ", ", ")"); break;
878 case EOpStep: outputTriplet(visit, "step(", ", ", ")"); break;
879 case EOpSmoothStep: outputTriplet(visit, "smoothstep(", ", ", ")"); break;
880 case EOpDistance: outputTriplet(visit, "distance(", ", ", ")"); break;
881 case EOpDot: outputTriplet(visit, "dot(", ", ", ")"); break;
882 case EOpCross: outputTriplet(visit, "cross(", ", ", ")"); break;
daniel@transgaming.com680553b2010-03-08 21:30:52 +0000883 case EOpFaceForward: outputTriplet(visit, "faceforward(", ", ", ")"); break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000884 case EOpReflect: outputTriplet(visit, "reflect(", ", ", ")"); break;
885 case EOpRefract: outputTriplet(visit, "refract(", ", ", ")"); break;
886 case EOpMul: outputTriplet(visit, "(", " * ", ")"); break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000887 default: UNREACHABLE();
888 }
889
890 return true;
891}
892
893bool OutputHLSL::visitSelection(Visit visit, TIntermSelection *node)
894{
895 TInfoSinkBase &out = context.infoSink.obj;
896
897 out << "if(";
898
899 node->getCondition()->traverse(this);
900
901 out << ")\n"
902 "{\n";
903
904 node->getTrueBlock()->traverse(this);
905
906 out << ";}\n";
907
908 if (node->getFalseBlock())
909 {
910 out << "else\n"
911 "{\n";
912
913 node->getFalseBlock()->traverse(this);
914
915 out << ";}\n";
916 }
917
918 return false;
919}
920
921void OutputHLSL::visitConstantUnion(TIntermConstantUnion *node)
922{
923 TInfoSinkBase &out = context.infoSink.obj;
924
daniel@transgaming.com45d03582010-03-11 19:41:29 +0000925 TType &type = node->getType();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000926
daniel@transgaming.com86487c22010-03-11 19:41:43 +0000927 if (type.isField())
928 {
929 out << type.getFieldName();
930 }
931 else
932 {
933 int size = type.getObjectSize();
934 bool matrix = type.isMatrix();
935 TBasicType basicType = node->getUnionArrayPointer()[0].getType();
936
937 switch (basicType)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000938 {
939 case EbtBool:
daniel@transgaming.com45d03582010-03-11 19:41:29 +0000940 if (!matrix)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000941 {
daniel@transgaming.com45d03582010-03-11 19:41:29 +0000942 switch (size)
943 {
944 case 1: out << "bool("; break;
945 case 2: out << "bool2("; break;
946 case 3: out << "bool3("; break;
947 case 4: out << "bool4("; break;
948 default: UNREACHABLE();
949 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000950 }
951 else
952 {
daniel@transgaming.com45d03582010-03-11 19:41:29 +0000953 UNIMPLEMENTED();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000954 }
955 break;
956 case EbtFloat:
daniel@transgaming.com45d03582010-03-11 19:41:29 +0000957 if (!matrix)
958 {
959 switch (size)
960 {
961 case 1: out << "float("; break;
962 case 2: out << "float2("; break;
963 case 3: out << "float3("; break;
964 case 4: out << "float4("; break;
965 default: UNREACHABLE();
966 }
967 }
968 else
969 {
970 switch (size)
971 {
972 case 4: out << "float2x2("; break;
973 case 9: out << "float3x3("; break;
974 case 16: out << "float4x4("; break;
975 default: UNREACHABLE();
976 }
977 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000978 break;
979 case EbtInt:
daniel@transgaming.com45d03582010-03-11 19:41:29 +0000980 if (!matrix)
981 {
982 switch (size)
983 {
984 case 1: out << "int("; break;
985 case 2: out << "int2("; break;
986 case 3: out << "int3("; break;
987 case 4: out << "int4("; break;
988 default: UNREACHABLE();
989 }
990 }
991 else
992 {
993 UNIMPLEMENTED();
994 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000995 break;
daniel@transgaming.com45d03582010-03-11 19:41:29 +0000996 default:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000997 UNIMPLEMENTED(); // FIXME
998 }
999
daniel@transgaming.com45d03582010-03-11 19:41:29 +00001000 for (int i = 0; i < size; i++)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001001 {
daniel@transgaming.com45d03582010-03-11 19:41:29 +00001002 switch (basicType)
1003 {
1004 case EbtBool:
1005 if (node->getUnionArrayPointer()[i].getBConst())
1006 {
1007 out << "true";
1008 }
1009 else
1010 {
1011 out << "false";
1012 }
1013 break;
1014 case EbtFloat:
1015 out << node->getUnionArrayPointer()[i].getFConst();
1016 break;
1017 case EbtInt:
1018 out << node->getUnionArrayPointer()[i].getIConst();
1019 break;
1020 default:
1021 UNIMPLEMENTED(); // FIXME
1022 }
1023
1024 if (i != size - 1)
1025 {
1026 out << ", ";
1027 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001028 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001029
daniel@transgaming.com86487c22010-03-11 19:41:43 +00001030 out << ")";
1031 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001032}
1033
1034bool OutputHLSL::visitLoop(Visit visit, TIntermLoop *node)
1035{
1036 TInfoSinkBase &out = context.infoSink.obj;
1037
1038 if (!node->testFirst())
1039 {
1040 out << "do\n"
1041 "{\n";
1042 }
1043 else
1044 {
1045 out << "for(";
1046
1047 if (node->getInit())
1048 {
1049 node->getInit()->traverse(this);
1050 }
1051
1052 out << "; ";
1053
1054 if (node->getTest())
1055 {
1056 node->getTest()->traverse(this);
1057 }
1058
1059 out << "; ";
1060
1061 if (node->getTerminal())
1062 {
1063 node->getTerminal()->traverse(this);
1064 }
1065
1066 out << ")\n"
1067 "{\n";
1068 }
1069
1070 if (node->getBody())
1071 {
1072 node->getBody()->traverse(this);
1073 }
1074
1075 out << "}\n";
1076
1077 if (!node->testFirst())
1078 {
1079 out << "while(\n";
1080
1081 node->getTest()->traverse(this);
1082
1083 out << ")";
1084 }
1085
1086 out << ";\n";
1087
1088 return false;
1089}
1090
1091bool OutputHLSL::visitBranch(Visit visit, TIntermBranch *node)
1092{
1093 TInfoSinkBase &out = context.infoSink.obj;
1094
1095 switch (node->getFlowOp())
1096 {
1097 case EOpKill: outputTriplet(visit, "discard", NULL, NULL); break;
1098 case EOpBreak: UNIMPLEMENTED(); /* FIXME */ break;
1099 case EOpContinue: UNIMPLEMENTED(); /* FIXME */ break;
1100 case EOpReturn:
1101 if (visit == PreVisit)
1102 {
1103 if (node->getExpression())
1104 {
1105 out << "return ";
1106 }
1107 else
1108 {
1109 out << "return;\n";
1110 }
1111 }
1112 else if (visit == PostVisit)
1113 {
1114 out << ";\n";
1115 }
1116 break;
1117 default: UNREACHABLE();
1118 }
1119
1120 return true;
1121}
1122
1123void OutputHLSL::outputTriplet(Visit visit, const char *preString, const char *inString, const char *postString)
1124{
1125 TInfoSinkBase &out = context.infoSink.obj;
1126
1127 if (visit == PreVisit && preString)
1128 {
1129 out << preString;
1130 }
1131 else if (visit == InVisit && inString)
1132 {
1133 out << inString;
1134 }
1135 else if (visit == PostVisit && postString)
1136 {
1137 out << postString;
1138 }
1139}
1140
1141TString OutputHLSL::typeString(const TType &type)
1142{
1143 if (type.isMatrix())
1144 {
1145 switch (type.getNominalSize())
1146 {
1147 case 2: return "float2x2";
1148 case 3: return "float3x3";
1149 case 4: return "float4x4";
1150 }
1151 }
1152 else
1153 {
1154 switch (type.getBasicType())
1155 {
1156 case EbtFloat:
1157 switch (type.getNominalSize())
1158 {
1159 case 1: return "float";
1160 case 2: return "float2";
1161 case 3: return "float3";
1162 case 4: return "float4";
1163 }
1164 case EbtInt:
1165 switch (type.getNominalSize())
1166 {
1167 case 1: return "int";
1168 case 2: return "int2";
1169 case 3: return "int3";
1170 case 4: return "int4";
1171 }
1172 case EbtBool:
1173 switch (type.getNominalSize())
1174 {
1175 case 1: return "bool";
1176 case 2: return "bool2";
1177 case 3: return "bool3";
1178 case 4: return "bool4";
1179 }
1180 case EbtVoid:
1181 return "void";
1182 case EbtSampler2D:
1183 return "sampler2D";
1184 case EbtSamplerCube:
1185 return "samplerCUBE";
1186 }
1187 }
1188
1189 UNIMPLEMENTED(); // FIXME
1190 return "<unknown type>";
1191}
1192
1193TString OutputHLSL::arrayString(const TType &type)
1194{
1195 if (!type.isArray())
1196 {
1197 return "";
1198 }
1199
1200 char buffer[100];
1201 sprintf(buffer, "[%d]", type.getArraySize());
1202
1203 return buffer;
1204}
1205
1206TString OutputHLSL::initializer(const TType &type)
1207{
1208 TString string;
1209
1210 int arraySize = type.isArray() ? type.getArraySize() : 1;
1211
1212 if (type.isArray())
1213 {
1214 string += "{";
1215 }
1216
1217 for (int element = 0; element < arraySize; element++)
1218 {
1219 string += typeString(type) + "(";
1220
1221 for (int component = 0; component < type.getNominalSize(); component++)
1222 {
1223 string += "0";
1224
1225 if (component < type.getNominalSize() - 1)
1226 {
1227 string += ", ";
1228 }
1229 }
1230
1231 string += ")";
1232
1233 if (element < arraySize - 1)
1234 {
1235 string += ", ";
1236 }
1237 }
1238
1239 if (type.isArray())
1240 {
1241 string += "}";
1242 }
1243
1244 return string;
1245}
1246}