tgsi_dump.c revision 92209314df4f12e8b47336a25ba14cb6b9a23df2
1/**************************************************************************
2 *
3 * Copyright 2007-2008 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28#include "util/u_debug.h"
29#include "util/u_string.h"
30#include "util/u_math.h"
31#include "util/u_memory.h"
32#include "tgsi_dump.h"
33#include "tgsi_info.h"
34#include "tgsi_iterate.h"
35
36
37/** Number of spaces to indent for IF/LOOP/etc */
38static const int indent_spaces = 3;
39
40
41struct dump_ctx
42{
43   struct tgsi_iterate_context iter;
44
45   uint instno;
46   int indent;
47
48   uint indentation;
49
50   void (*printf)(struct dump_ctx *ctx, const char *format, ...);
51};
52
53static void
54dump_ctx_printf(struct dump_ctx *ctx, const char *format, ...)
55{
56   va_list ap;
57   (void)ctx;
58   va_start(ap, format);
59   _debug_vprintf(format, ap);
60   va_end(ap);
61}
62
63static void
64dump_enum(
65   struct dump_ctx *ctx,
66   uint e,
67   const char **enums,
68   uint enum_count )
69{
70   if (e >= enum_count)
71      ctx->printf( ctx, "%u", e );
72   else
73      ctx->printf( ctx, "%s", enums[e] );
74}
75
76#define EOL()           ctx->printf( ctx, "\n" )
77#define TXT(S)          ctx->printf( ctx, "%s", S )
78#define CHR(C)          ctx->printf( ctx, "%c", C )
79#define UIX(I)          ctx->printf( ctx, "0x%x", I )
80#define UID(I)          ctx->printf( ctx, "%u", I )
81#define INSTID(I)          ctx->printf( ctx, "% 3u", I )
82#define SID(I)          ctx->printf( ctx, "%d", I )
83#define FLT(F)          ctx->printf( ctx, "%10.4f", F )
84#define ENM(E,ENUMS)    dump_enum( ctx, E, ENUMS, sizeof( ENUMS ) / sizeof( *ENUMS ) )
85
86static const char *processor_type_names[] =
87{
88   "FRAG",
89   "VERT",
90   "GEOM"
91};
92
93const char *
94tgsi_file_names[TGSI_FILE_COUNT] =
95{
96   "NULL",
97   "CONST",
98   "IN",
99   "OUT",
100   "TEMP",
101   "SAMP",
102   "ADDR",
103   "IMM",
104   "PRED",
105   "SV",
106   "IMMX",
107   "TEMPX"
108};
109
110static const char *interpolate_names[] =
111{
112   "CONSTANT",
113   "LINEAR",
114   "PERSPECTIVE"
115};
116
117static const char *semantic_names[] =
118{
119   "POSITION",
120   "COLOR",
121   "BCOLOR",
122   "FOG",
123   "PSIZE",
124   "GENERIC",
125   "NORMAL",
126   "FACE",
127   "EDGEFLAG",
128   "PRIM_ID",
129   "INSTANCEID",
130   "STENCIL"
131};
132
133static const char *immediate_type_names[] =
134{
135   "FLT32",
136   "UINT32",
137   "INT32"
138};
139
140const char *
141tgsi_swizzle_names[4] =
142{
143   "x",
144   "y",
145   "z",
146   "w"
147};
148
149const char *
150tgsi_texture_names[TGSI_TEXTURE_COUNT] =
151{
152   "UNKNOWN",
153   "1D",
154   "2D",
155   "3D",
156   "CUBE",
157   "RECT",
158   "SHADOW1D",
159   "SHADOW2D",
160   "SHADOWRECT"
161};
162
163const char *tgsi_property_names[TGSI_PROPERTY_COUNT] =
164{
165   "GS_INPUT_PRIMITIVE",
166   "GS_OUTPUT_PRIMITIVE",
167   "GS_MAX_OUTPUT_VERTICES",
168   "FS_COORD_ORIGIN",
169   "FS_COORD_PIXEL_CENTER",
170   "FS_COLOR0_WRITES_ALL_CBUFS",
171};
172
173const char *tgsi_primitive_names[PIPE_PRIM_MAX] =
174{
175   "POINTS",
176   "LINES",
177   "LINE_LOOP",
178   "LINE_STRIP",
179   "TRIANGLES",
180   "TRIANGLE_STRIP",
181   "TRIANGLE_FAN",
182   "QUADS",
183   "QUAD_STRIP",
184   "POLYGON",
185   "LINES_ADJACENCY",
186   "LINE_STRIP_ADJACENCY",
187   "TRIANGLES_ADJACENCY",
188   "TRIANGLE_STRIP_ADJACENCY"
189};
190
191const char *tgsi_fs_coord_origin_names[2] =
192{
193   "UPPER_LEFT",
194   "LOWER_LEFT"
195};
196
197const char *tgsi_fs_coord_pixel_center_names[2] =
198{
199   "HALF_INTEGER",
200   "INTEGER"
201};
202
203
204static void
205_dump_register_src(
206   struct dump_ctx *ctx,
207   const struct tgsi_full_src_register *src )
208{
209   ENM(src->Register.File, tgsi_file_names);
210   if (src->Register.Dimension) {
211      if (src->Dimension.Indirect) {
212         CHR( '[' );
213         ENM( src->DimIndirect.File, tgsi_file_names );
214         CHR( '[' );
215         SID( src->DimIndirect.Index );
216         TXT( "]." );
217         ENM( src->DimIndirect.SwizzleX, tgsi_swizzle_names );
218         if (src->Dimension.Index != 0) {
219            if (src->Dimension.Index > 0)
220               CHR( '+' );
221            SID( src->Dimension.Index );
222         }
223         CHR( ']' );
224      } else {
225         CHR('[');
226         SID(src->Dimension.Index);
227         CHR(']');
228      }
229   }
230   if (src->Register.Indirect) {
231      CHR( '[' );
232      ENM( src->Indirect.File, tgsi_file_names );
233      CHR( '[' );
234      SID( src->Indirect.Index );
235      TXT( "]." );
236      ENM( src->Indirect.SwizzleX, tgsi_swizzle_names );
237      if (src->Register.Index != 0) {
238         if (src->Register.Index > 0)
239            CHR( '+' );
240         SID( src->Register.Index );
241      }
242      CHR( ']' );
243   } else {
244      CHR( '[' );
245      SID( src->Register.Index );
246      CHR( ']' );
247   }
248}
249
250
251static void
252_dump_register_dst(
253   struct dump_ctx *ctx,
254   const struct tgsi_full_dst_register *dst )
255{
256   ENM(dst->Register.File, tgsi_file_names);
257   if (dst->Register.Dimension) {
258      if (dst->Dimension.Indirect) {
259         CHR( '[' );
260         ENM( dst->DimIndirect.File, tgsi_file_names );
261         CHR( '[' );
262         SID( dst->DimIndirect.Index );
263         TXT( "]." );
264         ENM( dst->DimIndirect.SwizzleX, tgsi_swizzle_names );
265         if (dst->Dimension.Index != 0) {
266            if (dst->Dimension.Index > 0)
267               CHR( '+' );
268            SID( dst->Dimension.Index );
269         }
270         CHR( ']' );
271      } else {
272         CHR('[');
273         SID(dst->Dimension.Index);
274         CHR(']');
275      }
276   }
277   if (dst->Register.Indirect) {
278      CHR( '[' );
279      ENM( dst->Indirect.File, tgsi_file_names );
280      CHR( '[' );
281      SID( dst->Indirect.Index );
282      TXT( "]." );
283      ENM( dst->Indirect.SwizzleX, tgsi_swizzle_names );
284      if (dst->Register.Index != 0) {
285         if (dst->Register.Index > 0)
286            CHR( '+' );
287         SID( dst->Register.Index );
288      }
289      CHR( ']' );
290   } else {
291      CHR( '[' );
292      SID( dst->Register.Index );
293      CHR( ']' );
294   }
295}
296static void
297_dump_writemask(
298   struct dump_ctx *ctx,
299   uint writemask )
300{
301   if (writemask != TGSI_WRITEMASK_XYZW) {
302      CHR( '.' );
303      if (writemask & TGSI_WRITEMASK_X)
304         CHR( 'x' );
305      if (writemask & TGSI_WRITEMASK_Y)
306         CHR( 'y' );
307      if (writemask & TGSI_WRITEMASK_Z)
308         CHR( 'z' );
309      if (writemask & TGSI_WRITEMASK_W)
310         CHR( 'w' );
311   }
312}
313
314static void
315dump_imm_data(struct tgsi_iterate_context *iter,
316              union tgsi_immediate_data *data,
317              unsigned num_tokens,
318              unsigned data_type)
319{
320   struct dump_ctx *ctx = (struct dump_ctx *)iter;
321   unsigned i ;
322
323   TXT( " {" );
324
325   assert( num_tokens <= 4 );
326   for (i = 0; i < num_tokens; i++) {
327      switch (data_type) {
328      case TGSI_IMM_FLOAT32:
329         FLT( data[i].Float );
330         break;
331      case TGSI_IMM_UINT32:
332         UID(data[i].Uint);
333         break;
334      case TGSI_IMM_INT32:
335         SID(data[i].Int);
336         break;
337      default:
338         assert( 0 );
339      }
340
341      if (i < num_tokens - 1)
342         TXT( ", " );
343   }
344   TXT( "}" );
345}
346
347static boolean
348iter_declaration(
349   struct tgsi_iterate_context *iter,
350   struct tgsi_full_declaration *decl )
351{
352   struct dump_ctx *ctx = (struct dump_ctx *)iter;
353
354   assert(Elements(semantic_names) == TGSI_SEMANTIC_COUNT);
355   assert(Elements(interpolate_names) == TGSI_INTERPOLATE_COUNT);
356
357   TXT( "DCL " );
358
359   ENM(decl->Declaration.File, tgsi_file_names);
360
361   /* all geometry shader inputs are two dimensional */
362   if (decl->Declaration.File == TGSI_FILE_INPUT &&
363       iter->processor.Processor == TGSI_PROCESSOR_GEOMETRY) {
364      TXT("[]");
365   }
366
367   if (decl->Declaration.Dimension) {
368      CHR('[');
369      SID(decl->Dim.Index2D);
370      CHR(']');
371   }
372
373   CHR('[');
374   SID(decl->Range.First);
375   if (decl->Range.First != decl->Range.Last) {
376      TXT("..");
377      SID(decl->Range.Last);
378   }
379   CHR(']');
380
381   _dump_writemask(
382      ctx,
383      decl->Declaration.UsageMask );
384
385   if (decl->Declaration.Semantic) {
386      TXT( ", " );
387      ENM( decl->Semantic.Name, semantic_names );
388      if (decl->Semantic.Index != 0 ||
389          decl->Semantic.Name == TGSI_SEMANTIC_GENERIC) {
390         CHR( '[' );
391         UID( decl->Semantic.Index );
392         CHR( ']' );
393      }
394   }
395
396   if (iter->processor.Processor == TGSI_PROCESSOR_FRAGMENT &&
397       decl->Declaration.File == TGSI_FILE_INPUT)
398   {
399      TXT( ", " );
400      ENM( decl->Declaration.Interpolate, interpolate_names );
401   }
402
403   if (decl->Declaration.Centroid) {
404      TXT( ", CENTROID" );
405   }
406
407   if (decl->Declaration.Invariant) {
408      TXT( ", INVARIANT" );
409   }
410
411   if (decl->Declaration.CylindricalWrap) {
412      TXT(", CYLWRAP_");
413      if (decl->Declaration.CylindricalWrap & TGSI_CYLINDRICAL_WRAP_X) {
414         CHR('X');
415      }
416      if (decl->Declaration.CylindricalWrap & TGSI_CYLINDRICAL_WRAP_Y) {
417         CHR('Y');
418      }
419      if (decl->Declaration.CylindricalWrap & TGSI_CYLINDRICAL_WRAP_Z) {
420         CHR('Z');
421      }
422      if (decl->Declaration.CylindricalWrap & TGSI_CYLINDRICAL_WRAP_W) {
423         CHR('W');
424      }
425   }
426
427   if (decl->Declaration.File == TGSI_FILE_IMMEDIATE_ARRAY) {
428      unsigned i;
429      char range_indent[4];
430
431      TXT(" {");
432
433      if (decl->Range.Last < 10)
434         range_indent[0] = '\0';
435      else if (decl->Range.Last < 100) {
436         range_indent[0] = ' ';
437         range_indent[1] = '\0';
438      } else if (decl->Range.Last < 1000) {
439         range_indent[0] = ' ';
440         range_indent[1] = ' ';
441         range_indent[2] = '\0';
442      } else {
443         range_indent[0] = ' ';
444         range_indent[1] = ' ';
445         range_indent[2] = ' ';
446         range_indent[3] = '\0';
447      }
448
449      dump_imm_data(iter, decl->ImmediateData.u,
450                    4, TGSI_IMM_FLOAT32);
451      for(i = 1; i <= decl->Range.Last; ++i) {
452         /* indent by strlen of:
453          *   "DCL IMMX[0..1] {" */
454         CHR('\n');
455         TXT( "                " );
456         TXT( range_indent );
457         dump_imm_data(iter, decl->ImmediateData.u + i,
458                       4, TGSI_IMM_FLOAT32);
459      }
460
461      TXT(" }");
462   }
463
464   EOL();
465
466   return TRUE;
467}
468
469void
470tgsi_dump_declaration(
471   const struct tgsi_full_declaration *decl )
472{
473   struct dump_ctx ctx;
474
475   ctx.printf = dump_ctx_printf;
476
477   iter_declaration( &ctx.iter, (struct tgsi_full_declaration *)decl );
478}
479
480static boolean
481iter_property(
482   struct tgsi_iterate_context *iter,
483   struct tgsi_full_property *prop )
484{
485   int i;
486   struct dump_ctx *ctx = (struct dump_ctx *)iter;
487
488   assert(Elements(tgsi_property_names) == TGSI_PROPERTY_COUNT);
489
490   TXT( "PROPERTY " );
491   ENM(prop->Property.PropertyName, tgsi_property_names);
492
493   if (prop->Property.NrTokens > 1)
494      TXT(" ");
495
496   for (i = 0; i < prop->Property.NrTokens - 1; ++i) {
497      switch (prop->Property.PropertyName) {
498      case TGSI_PROPERTY_GS_INPUT_PRIM:
499      case TGSI_PROPERTY_GS_OUTPUT_PRIM:
500         ENM(prop->u[i].Data, tgsi_primitive_names);
501         break;
502      case TGSI_PROPERTY_FS_COORD_ORIGIN:
503         ENM(prop->u[i].Data, tgsi_fs_coord_origin_names);
504         break;
505      case TGSI_PROPERTY_FS_COORD_PIXEL_CENTER:
506         ENM(prop->u[i].Data, tgsi_fs_coord_pixel_center_names);
507         break;
508      default:
509         SID( prop->u[i].Data );
510         break;
511      }
512      if (i < prop->Property.NrTokens - 2)
513         TXT( ", " );
514   }
515   EOL();
516
517   return TRUE;
518}
519
520void tgsi_dump_property(
521   const struct tgsi_full_property *prop )
522{
523   struct dump_ctx ctx;
524
525   ctx.printf = dump_ctx_printf;
526
527   iter_property( &ctx.iter, (struct tgsi_full_property *)prop );
528}
529
530static boolean
531iter_immediate(
532   struct tgsi_iterate_context *iter,
533   struct tgsi_full_immediate *imm )
534{
535   struct dump_ctx *ctx = (struct dump_ctx *) iter;
536
537   TXT( "IMM " );
538   ENM( imm->Immediate.DataType, immediate_type_names );
539
540   dump_imm_data(iter, imm->u, imm->Immediate.NrTokens - 1,
541                 imm->Immediate.DataType);
542
543   EOL();
544
545   return TRUE;
546}
547
548void
549tgsi_dump_immediate(
550   const struct tgsi_full_immediate *imm )
551{
552   struct dump_ctx ctx;
553
554   ctx.printf = dump_ctx_printf;
555
556   iter_immediate( &ctx.iter, (struct tgsi_full_immediate *)imm );
557}
558
559static boolean
560iter_instruction(
561   struct tgsi_iterate_context *iter,
562   struct tgsi_full_instruction *inst )
563{
564   struct dump_ctx *ctx = (struct dump_ctx *) iter;
565   uint instno = ctx->instno++;
566   const struct tgsi_opcode_info *info = tgsi_get_opcode_info( inst->Instruction.Opcode );
567   uint i;
568   boolean first_reg = TRUE;
569
570   INSTID( instno );
571   TXT( ": " );
572
573   ctx->indent -= info->pre_dedent;
574   for(i = 0; (int)i < ctx->indent; ++i)
575      TXT( "  " );
576   ctx->indent += info->post_indent;
577
578   if (inst->Instruction.Predicate) {
579      CHR( '(' );
580
581      if (inst->Predicate.Negate)
582         CHR( '!' );
583
584      TXT( "PRED[" );
585      SID( inst->Predicate.Index );
586      CHR( ']' );
587
588      if (inst->Predicate.SwizzleX != TGSI_SWIZZLE_X ||
589          inst->Predicate.SwizzleY != TGSI_SWIZZLE_Y ||
590          inst->Predicate.SwizzleZ != TGSI_SWIZZLE_Z ||
591          inst->Predicate.SwizzleW != TGSI_SWIZZLE_W) {
592         CHR( '.' );
593         ENM( inst->Predicate.SwizzleX, tgsi_swizzle_names );
594         ENM( inst->Predicate.SwizzleY, tgsi_swizzle_names );
595         ENM( inst->Predicate.SwizzleZ, tgsi_swizzle_names );
596         ENM( inst->Predicate.SwizzleW, tgsi_swizzle_names );
597      }
598
599      TXT( ") " );
600   }
601
602   TXT( info->mnemonic );
603
604   switch (inst->Instruction.Saturate) {
605   case TGSI_SAT_NONE:
606      break;
607   case TGSI_SAT_ZERO_ONE:
608      TXT( "_SAT" );
609      break;
610   case TGSI_SAT_MINUS_PLUS_ONE:
611      TXT( "_SATNV" );
612      break;
613   default:
614      assert( 0 );
615   }
616
617   for (i = 0; i < inst->Instruction.NumDstRegs; i++) {
618      const struct tgsi_full_dst_register *dst = &inst->Dst[i];
619
620      if (!first_reg)
621         CHR( ',' );
622      CHR( ' ' );
623
624      _dump_register_dst( ctx, dst );
625      _dump_writemask( ctx, dst->Register.WriteMask );
626
627      first_reg = FALSE;
628   }
629
630   for (i = 0; i < inst->Instruction.NumSrcRegs; i++) {
631      const struct tgsi_full_src_register *src = &inst->Src[i];
632
633      if (!first_reg)
634         CHR( ',' );
635      CHR( ' ' );
636
637      if (src->Register.Negate)
638         CHR( '-' );
639      if (src->Register.Absolute)
640         CHR( '|' );
641
642      _dump_register_src(ctx, src);
643
644      if (src->Register.SwizzleX != TGSI_SWIZZLE_X ||
645          src->Register.SwizzleY != TGSI_SWIZZLE_Y ||
646          src->Register.SwizzleZ != TGSI_SWIZZLE_Z ||
647          src->Register.SwizzleW != TGSI_SWIZZLE_W) {
648         CHR( '.' );
649         ENM( src->Register.SwizzleX, tgsi_swizzle_names );
650         ENM( src->Register.SwizzleY, tgsi_swizzle_names );
651         ENM( src->Register.SwizzleZ, tgsi_swizzle_names );
652         ENM( src->Register.SwizzleW, tgsi_swizzle_names );
653      }
654
655      if (src->Register.Absolute)
656         CHR( '|' );
657
658      first_reg = FALSE;
659   }
660
661   if (inst->Instruction.Texture) {
662      TXT( ", " );
663      ENM( inst->Texture.Texture, tgsi_texture_names );
664   }
665
666   switch (inst->Instruction.Opcode) {
667   case TGSI_OPCODE_IF:
668   case TGSI_OPCODE_ELSE:
669   case TGSI_OPCODE_BGNLOOP:
670   case TGSI_OPCODE_ENDLOOP:
671   case TGSI_OPCODE_CAL:
672      TXT( " :" );
673      UID( inst->Label.Label );
674      break;
675   }
676
677   /* update indentation */
678   if (inst->Instruction.Opcode == TGSI_OPCODE_IF ||
679       inst->Instruction.Opcode == TGSI_OPCODE_ELSE ||
680       inst->Instruction.Opcode == TGSI_OPCODE_BGNLOOP) {
681      ctx->indentation += indent_spaces;
682   }
683
684   EOL();
685
686   return TRUE;
687}
688
689void
690tgsi_dump_instruction(
691   const struct tgsi_full_instruction *inst,
692   uint instno )
693{
694   struct dump_ctx ctx;
695
696   ctx.instno = instno;
697   ctx.indent = 0;
698   ctx.printf = dump_ctx_printf;
699   ctx.indentation = 0;
700
701   iter_instruction( &ctx.iter, (struct tgsi_full_instruction *)inst );
702}
703
704static boolean
705prolog(
706   struct tgsi_iterate_context *iter )
707{
708   struct dump_ctx *ctx = (struct dump_ctx *) iter;
709   ENM( iter->processor.Processor, processor_type_names );
710   EOL();
711   return TRUE;
712}
713
714void
715tgsi_dump(
716   const struct tgsi_token *tokens,
717   uint flags )
718{
719   struct dump_ctx ctx;
720
721   ctx.iter.prolog = prolog;
722   ctx.iter.iterate_instruction = iter_instruction;
723   ctx.iter.iterate_declaration = iter_declaration;
724   ctx.iter.iterate_immediate = iter_immediate;
725   ctx.iter.iterate_property = iter_property;
726   ctx.iter.epilog = NULL;
727
728   ctx.instno = 0;
729   ctx.indent = 0;
730   ctx.printf = dump_ctx_printf;
731   ctx.indentation = 0;
732
733   tgsi_iterate_shader( tokens, &ctx.iter );
734}
735
736struct str_dump_ctx
737{
738   struct dump_ctx base;
739   char *str;
740   char *ptr;
741   int left;
742};
743
744static void
745str_dump_ctx_printf(struct dump_ctx *ctx, const char *format, ...)
746{
747   struct str_dump_ctx *sctx = (struct str_dump_ctx *)ctx;
748
749   if(sctx->left > 1) {
750      int written;
751      va_list ap;
752      va_start(ap, format);
753      written = util_vsnprintf(sctx->ptr, sctx->left, format, ap);
754      va_end(ap);
755
756      /* Some complicated logic needed to handle the return value of
757       * vsnprintf:
758       */
759      if (written > 0) {
760         written = MIN2(sctx->left, written);
761         sctx->ptr += written;
762         sctx->left -= written;
763      }
764   }
765}
766
767void
768tgsi_dump_str(
769   const struct tgsi_token *tokens,
770   uint flags,
771   char *str,
772   size_t size)
773{
774   struct str_dump_ctx ctx;
775
776   ctx.base.iter.prolog = prolog;
777   ctx.base.iter.iterate_instruction = iter_instruction;
778   ctx.base.iter.iterate_declaration = iter_declaration;
779   ctx.base.iter.iterate_immediate = iter_immediate;
780   ctx.base.iter.iterate_property = iter_property;
781   ctx.base.iter.epilog = NULL;
782
783   ctx.base.instno = 0;
784   ctx.base.indent = 0;
785   ctx.base.printf = &str_dump_ctx_printf;
786   ctx.base.indentation = 0;
787
788   ctx.str = str;
789   ctx.str[0] = 0;
790   ctx.ptr = str;
791   ctx.left = (int)size;
792
793   tgsi_iterate_shader( tokens, &ctx.base.iter );
794}
795