1 /**************************************************************************
3 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
28 #include "util/u_debug.h"
29 #include "util/u_memory.h"
30 #include "tgsi_text.h"
31 #include "tgsi_build.h"
32 #include "tgsi_info.h"
33 #include "tgsi_parse.h"
34 #include "tgsi_sanity.h"
35 #include "tgsi_util.h"
37 static boolean
is_alpha_underscore( const char *cur
)
40 (*cur
>= 'a' && *cur
<= 'z') ||
41 (*cur
>= 'A' && *cur
<= 'Z') ||
45 static boolean
is_digit( const char *cur
)
47 return *cur
>= '0' && *cur
<= '9';
50 static boolean
is_digit_alpha_underscore( const char *cur
)
52 return is_digit( cur
) || is_alpha_underscore( cur
);
55 static boolean
uprcase( char c
)
57 if (c
>= 'a' && c
<= 'z')
58 return c
+= 'A' - 'a';
62 static boolean
str_match_no_case( const char **pcur
, const char *str
)
64 const char *cur
= *pcur
;
66 while (*str
!= '\0' && *str
== uprcase( *cur
)) {
77 /* Eat zero or more whitespaces.
79 static void eat_opt_white( const char **pcur
)
81 while (**pcur
== ' ' || **pcur
== '\t' || **pcur
== '\n')
85 /* Eat one or more whitespaces.
86 * Return TRUE if at least one whitespace eaten.
88 static boolean
eat_white( const char **pcur
)
90 const char *cur
= *pcur
;
92 eat_opt_white( pcur
);
96 /* Parse unsigned integer.
97 * No checks for overflow.
99 static boolean
parse_uint( const char **pcur
, uint
*val
)
101 const char *cur
= *pcur
;
103 if (is_digit( cur
)) {
105 while (is_digit( cur
))
106 *val
= *val
* 10 + *cur
++ - '0';
113 /* Parse floating point.
115 static boolean
parse_float( const char **pcur
, float *val
)
117 const char *cur
= *pcur
;
118 boolean integral_part
= FALSE
;
119 boolean fractional_part
= FALSE
;
121 *val
= (float) atof( cur
);
123 if (*cur
== '-' || *cur
== '+')
125 if (is_digit( cur
)) {
127 integral_part
= TRUE
;
128 while (is_digit( cur
))
133 if (is_digit( cur
)) {
135 fractional_part
= TRUE
;
136 while (is_digit( cur
))
140 if (!integral_part
&& !fractional_part
)
142 if (uprcase( *cur
) == 'E') {
144 if (*cur
== '-' || *cur
== '+')
146 if (is_digit( cur
)) {
148 while (is_digit( cur
))
162 struct tgsi_token
*tokens
;
163 struct tgsi_token
*tokens_cur
;
164 struct tgsi_token
*tokens_end
;
165 struct tgsi_header
*header
;
168 static void report_error( struct translate_ctx
*ctx
, const char *msg
)
170 debug_printf( "\nError: %s", msg
);
173 /* Parse shader header.
174 * Return TRUE for one of the following headers.
179 static boolean
parse_header( struct translate_ctx
*ctx
)
183 if (str_match_no_case( &ctx
->cur
, "FRAG1.1" ))
184 processor
= TGSI_PROCESSOR_FRAGMENT
;
185 else if (str_match_no_case( &ctx
->cur
, "VERT1.1" ))
186 processor
= TGSI_PROCESSOR_VERTEX
;
187 else if (str_match_no_case( &ctx
->cur
, "GEOM1.1" ))
188 processor
= TGSI_PROCESSOR_GEOMETRY
;
190 report_error( ctx
, "Unknown header" );
194 if (ctx
->tokens_cur
>= ctx
->tokens_end
)
196 *(struct tgsi_version
*) ctx
->tokens_cur
++ = tgsi_build_version();
198 if (ctx
->tokens_cur
>= ctx
->tokens_end
)
200 ctx
->header
= (struct tgsi_header
*) ctx
->tokens_cur
++;
201 *ctx
->header
= tgsi_build_header();
203 if (ctx
->tokens_cur
>= ctx
->tokens_end
)
205 *(struct tgsi_processor
*) ctx
->tokens_cur
++ = tgsi_build_processor( processor
, ctx
->header
);
210 static boolean
parse_label( struct translate_ctx
*ctx
, uint
*val
)
212 const char *cur
= ctx
->cur
;
214 if (parse_uint( &cur
, val
)) {
215 eat_opt_white( &cur
);
225 static const char *file_names
[TGSI_FILE_COUNT
] =
240 parse_file( const char **pcur
, uint
*file
)
244 for (i
= 0; i
< TGSI_FILE_COUNT
; i
++) {
245 const char *cur
= *pcur
;
247 if (str_match_no_case( &cur
, file_names
[i
] )) {
248 if (!is_digit_alpha_underscore( cur
)) {
260 struct translate_ctx
*ctx
,
266 eat_opt_white( &cur
);
269 *writemask
= TGSI_WRITEMASK_NONE
;
270 eat_opt_white( &cur
);
271 if (uprcase( *cur
) == 'X') {
273 *writemask
|= TGSI_WRITEMASK_X
;
275 if (uprcase( *cur
) == 'Y') {
277 *writemask
|= TGSI_WRITEMASK_Y
;
279 if (uprcase( *cur
) == 'Z') {
281 *writemask
|= TGSI_WRITEMASK_Z
;
283 if (uprcase( *cur
) == 'W') {
285 *writemask
|= TGSI_WRITEMASK_W
;
288 if (*writemask
== TGSI_WRITEMASK_NONE
) {
289 report_error( ctx
, "Writemask expected" );
296 *writemask
= TGSI_WRITEMASK_XYZW
;
301 /* <register_file_bracket> ::= <file> `['
304 parse_register_file_bracket(
305 struct translate_ctx
*ctx
,
308 if (!parse_file( &ctx
->cur
, file
)) {
309 report_error( ctx
, "Unknown register file" );
312 eat_opt_white( &ctx
->cur
);
313 if (*ctx
->cur
!= '[') {
314 report_error( ctx
, "Expected `['" );
321 /* <register_file_bracket_index> ::= <register_file_bracket> <uint>
324 parse_register_file_bracket_index(
325 struct translate_ctx
*ctx
,
331 if (!parse_register_file_bracket( ctx
, file
))
333 eat_opt_white( &ctx
->cur
);
334 if (!parse_uint( &ctx
->cur
, &uindex
)) {
335 report_error( ctx
, "Expected literal unsigned integer" );
338 *index
= (int) uindex
;
342 /* Parse destination register operand.
343 * <register_dst> ::= <register_file_bracket_index> `]'
347 struct translate_ctx
*ctx
,
351 if (!parse_register_file_bracket_index( ctx
, file
, index
))
353 eat_opt_white( &ctx
->cur
);
354 if (*ctx
->cur
!= ']') {
355 report_error( ctx
, "Expected `]'" );
362 /* Parse source register operand.
363 * <register_src> ::= <register_file_bracket_index> `]' |
364 * <register_file_bracket> <register_dst> [`.' (`x' | `y' | `z' | `w')] `]' |
365 * <register_file_bracket> <register_dst> [`.' (`x' | `y' | `z' | `w')] `+' <uint> `]' |
366 * <register_file_bracket> <register_dst> [`.' (`x' | `y' | `z' | `w')] `-' <uint> `]'
370 struct translate_ctx
*ctx
,
380 *ind_comp
= TGSI_SWIZZLE_X
;
381 if (!parse_register_file_bracket( ctx
, file
))
383 eat_opt_white( &ctx
->cur
);
385 if (parse_file( &cur
, ind_file
)) {
386 if (!parse_register_dst( ctx
, ind_file
, ind_index
))
388 eat_opt_white( &ctx
->cur
);
390 if (*ctx
->cur
== '.') {
392 eat_opt_white(&ctx
->cur
);
394 switch (uprcase(*ctx
->cur
)) {
396 *ind_comp
= TGSI_SWIZZLE_X
;
399 *ind_comp
= TGSI_SWIZZLE_Y
;
402 *ind_comp
= TGSI_SWIZZLE_Z
;
405 *ind_comp
= TGSI_SWIZZLE_W
;
408 report_error(ctx
, "Expected indirect register swizzle component `x', `y', `z' or `w'");
412 eat_opt_white(&ctx
->cur
);
415 if (*ctx
->cur
== '+' || *ctx
->cur
== '-') {
418 negate
= *ctx
->cur
== '-';
420 eat_opt_white( &ctx
->cur
);
421 if (!parse_uint( &ctx
->cur
, &uindex
)) {
422 report_error( ctx
, "Expected literal unsigned integer" );
426 *index
= -(int) uindex
;
428 *index
= (int) uindex
;
435 if (!parse_uint( &ctx
->cur
, &uindex
)) {
436 report_error( ctx
, "Expected literal unsigned integer" );
439 *index
= (int) uindex
;
440 *ind_file
= TGSI_FILE_NULL
;
443 eat_opt_white( &ctx
->cur
);
444 if (*ctx
->cur
!= ']') {
445 report_error( ctx
, "Expected `]'" );
452 /* Parse register declaration.
453 * <register_dcl> ::= <register_file_bracket_index> `]' |
454 * <register_file_bracket_index> `..' <index> `]'
458 struct translate_ctx
*ctx
,
463 if (!parse_register_file_bracket_index( ctx
, file
, first
))
465 eat_opt_white( &ctx
->cur
);
466 if (ctx
->cur
[0] == '.' && ctx
->cur
[1] == '.') {
470 eat_opt_white( &ctx
->cur
);
471 if (!parse_uint( &ctx
->cur
, &uindex
)) {
472 report_error( ctx
, "Expected literal integer" );
475 *last
= (int) uindex
;
476 eat_opt_white( &ctx
->cur
);
481 if (*ctx
->cur
!= ']') {
482 report_error( ctx
, "Expected `]' or `..'" );
489 static const char *modulate_names
[TGSI_MODULATE_COUNT
] =
502 struct translate_ctx
*ctx
,
503 struct tgsi_full_dst_register
*dst
)
510 if (!parse_register_dst( ctx
, &file
, &index
))
514 eat_opt_white( &cur
);
518 for (i
= 0; i
< TGSI_MODULATE_COUNT
; i
++) {
519 if (str_match_no_case( &cur
, modulate_names
[i
] )) {
520 if (!is_digit_alpha_underscore( cur
)) {
521 dst
->DstRegisterExtModulate
.Modulate
= i
;
529 if (!parse_opt_writemask( ctx
, &writemask
))
532 dst
->DstRegister
.File
= file
;
533 dst
->DstRegister
.Index
= index
;
534 dst
->DstRegister
.WriteMask
= writemask
;
539 parse_optional_swizzle(
540 struct translate_ctx
*ctx
,
542 boolean
*parsed_swizzle
)
544 const char *cur
= ctx
->cur
;
546 *parsed_swizzle
= FALSE
;
548 eat_opt_white( &cur
);
553 eat_opt_white( &cur
);
554 for (i
= 0; i
< 4; i
++) {
555 if (uprcase( *cur
) == 'X')
556 swizzle
[i
] = TGSI_SWIZZLE_X
;
557 else if (uprcase( *cur
) == 'Y')
558 swizzle
[i
] = TGSI_SWIZZLE_Y
;
559 else if (uprcase( *cur
) == 'Z')
560 swizzle
[i
] = TGSI_SWIZZLE_Z
;
561 else if (uprcase( *cur
) == 'W')
562 swizzle
[i
] = TGSI_SWIZZLE_W
;
564 report_error( ctx
, "Expected register swizzle component `x', `y', `z', `w', `0' or `1'" );
569 *parsed_swizzle
= TRUE
;
577 struct translate_ctx
*ctx
,
578 struct tgsi_full_src_register
*src
)
588 boolean parsed_ext_negate_paren
= FALSE
;
589 boolean parsed_swizzle
;
591 if (*ctx
->cur
== '-') {
594 eat_opt_white( &cur
);
597 src
->SrcRegisterExtMod
.Negate
= 1;
598 eat_opt_white( &cur
);
600 parsed_ext_negate_paren
= TRUE
;
602 else if (*cur
== '|') {
604 src
->SrcRegisterExtMod
.Negate
= 1;
605 src
->SrcRegisterExtMod
.Absolute
= 1;
610 else if (*ctx
->cur
== '|') {
612 eat_opt_white( &ctx
->cur
);
613 src
->SrcRegisterExtMod
.Absolute
= 1;
616 if (*ctx
->cur
== '-') {
618 eat_opt_white( &ctx
->cur
);
619 src
->SrcRegister
.Negate
= 1;
623 if (parse_float( &cur
, &value
)) {
625 eat_opt_white( &cur
);
627 report_error( ctx
, "Expected `*'" );
632 report_error( ctx
, "Expected `('" );
636 src
->SrcRegisterExtMod
.Scale2X
= 1;
637 eat_opt_white( &cur
);
642 if (*ctx
->cur
== '(') {
644 eat_opt_white( &ctx
->cur
);
645 src
->SrcRegisterExtMod
.Bias
= 1;
649 if (parse_float( &cur
, &value
)) {
651 eat_opt_white( &cur
);
653 report_error( ctx
, "Expected `-'" );
658 report_error( ctx
, "Expected `('" );
662 src
->SrcRegisterExtMod
.Complement
= 1;
663 eat_opt_white( &cur
);
668 if (!parse_register_src(ctx
, &file
, &index
, &ind_file
, &ind_index
, &ind_comp
))
670 src
->SrcRegister
.File
= file
;
671 src
->SrcRegister
.Index
= index
;
672 if (ind_file
!= TGSI_FILE_NULL
) {
673 src
->SrcRegister
.Indirect
= 1;
674 src
->SrcRegisterInd
.File
= ind_file
;
675 src
->SrcRegisterInd
.Index
= ind_index
;
676 src
->SrcRegisterInd
.SwizzleX
= ind_comp
;
677 src
->SrcRegisterInd
.SwizzleY
= ind_comp
;
678 src
->SrcRegisterInd
.SwizzleZ
= ind_comp
;
679 src
->SrcRegisterInd
.SwizzleW
= ind_comp
;
682 /* Parse optional swizzle.
684 if (parse_optional_swizzle( ctx
, swizzle
, &parsed_swizzle
)) {
685 if (parsed_swizzle
) {
686 src
->SrcRegister
.SwizzleX
= swizzle
[0];
687 src
->SrcRegister
.SwizzleY
= swizzle
[1];
688 src
->SrcRegister
.SwizzleZ
= swizzle
[2];
689 src
->SrcRegister
.SwizzleW
= swizzle
[3];
693 if (src
->SrcRegisterExtMod
.Complement
) {
694 eat_opt_white( &ctx
->cur
);
695 if (*ctx
->cur
!= ')') {
696 report_error( ctx
, "Expected `)'" );
702 if (src
->SrcRegisterExtMod
.Bias
) {
703 eat_opt_white( &ctx
->cur
);
704 if (*ctx
->cur
!= ')') {
705 report_error( ctx
, "Expected `)'" );
709 eat_opt_white( &ctx
->cur
);
710 if (*ctx
->cur
!= '-') {
711 report_error( ctx
, "Expected `-'" );
715 eat_opt_white( &ctx
->cur
);
716 if (!parse_float( &ctx
->cur
, &value
)) {
717 report_error( ctx
, "Expected literal floating point" );
721 report_error( ctx
, "Expected 0.5" );
726 if (src
->SrcRegisterExtMod
.Scale2X
) {
727 eat_opt_white( &ctx
->cur
);
728 if (*ctx
->cur
!= ')') {
729 report_error( ctx
, "Expected `)'" );
735 if (src
->SrcRegisterExtMod
.Absolute
) {
736 eat_opt_white( &ctx
->cur
);
737 if (*ctx
->cur
!= '|') {
738 report_error( ctx
, "Expected `|'" );
744 if (parsed_ext_negate_paren
) {
745 eat_opt_white( &ctx
->cur
);
746 if (*ctx
->cur
!= ')') {
747 report_error( ctx
, "Expected `)'" );
756 static const char *texture_names
[TGSI_TEXTURE_COUNT
] =
770 match_inst_mnemonic(const char **pcur
,
771 const struct tgsi_opcode_info
*info
)
773 if (str_match_no_case(pcur
, info
->mnemonic
)) {
781 struct translate_ctx
*ctx
,
785 uint saturate
= TGSI_SAT_NONE
;
786 const struct tgsi_opcode_info
*info
;
787 struct tgsi_full_instruction inst
;
790 /* Parse instruction name.
792 eat_opt_white( &ctx
->cur
);
793 for (i
= 0; i
< TGSI_OPCODE_LAST
; i
++) {
794 const char *cur
= ctx
->cur
;
796 info
= tgsi_get_opcode_info( i
);
797 if (match_inst_mnemonic(&cur
, info
)) {
798 if (str_match_no_case( &cur
, "_SATNV" ))
799 saturate
= TGSI_SAT_MINUS_PLUS_ONE
;
800 else if (str_match_no_case( &cur
, "_SAT" ))
801 saturate
= TGSI_SAT_ZERO_ONE
;
803 if (info
->num_dst
+ info
->num_src
+ info
->is_tex
== 0) {
804 if (!is_digit_alpha_underscore( cur
)) {
809 else if (*cur
== '\0' || eat_white( &cur
)) {
815 if (i
== TGSI_OPCODE_LAST
) {
817 report_error( ctx
, "Unknown opcode" );
819 report_error( ctx
, "Expected `DCL', `IMM' or a label" );
823 inst
= tgsi_default_full_instruction();
824 inst
.Instruction
.Opcode
= i
;
825 inst
.Instruction
.Saturate
= saturate
;
826 inst
.Instruction
.NumDstRegs
= info
->num_dst
;
827 inst
.Instruction
.NumSrcRegs
= info
->num_src
;
829 /* Parse instruction operands.
831 for (i
= 0; i
< info
->num_dst
+ info
->num_src
+ info
->is_tex
; i
++) {
833 eat_opt_white( &ctx
->cur
);
834 if (*ctx
->cur
!= ',') {
835 report_error( ctx
, "Expected `,'" );
839 eat_opt_white( &ctx
->cur
);
842 if (i
< info
->num_dst
) {
843 if (!parse_dst_operand( ctx
, &inst
.FullDstRegisters
[i
] ))
846 else if (i
< info
->num_dst
+ info
->num_src
) {
847 if (!parse_src_operand( ctx
, &inst
.FullSrcRegisters
[i
- info
->num_dst
] ))
853 for (j
= 0; j
< TGSI_TEXTURE_COUNT
; j
++) {
854 if (str_match_no_case( &ctx
->cur
, texture_names
[j
] )) {
855 if (!is_digit_alpha_underscore( ctx
->cur
)) {
856 inst
.InstructionExtTexture
.Texture
= j
;
861 if (j
== TGSI_TEXTURE_COUNT
) {
862 report_error( ctx
, "Expected texture target" );
868 if (info
->is_branch
) {
871 eat_opt_white( &ctx
->cur
);
872 if (*ctx
->cur
!= ':') {
873 report_error( ctx
, "Expected `:'" );
877 eat_opt_white( &ctx
->cur
);
878 if (!parse_uint( &ctx
->cur
, &target
)) {
879 report_error( ctx
, "Expected a label" );
882 inst
.InstructionExtLabel
.Label
= target
;
885 advance
= tgsi_build_full_instruction(
889 (uint
) (ctx
->tokens_end
- ctx
->tokens_cur
) );
892 ctx
->tokens_cur
+= advance
;
897 static const char *semantic_names
[TGSI_SEMANTIC_COUNT
] =
909 static const char *interpolate_names
[TGSI_INTERPOLATE_COUNT
] =
916 static boolean
parse_declaration( struct translate_ctx
*ctx
)
918 struct tgsi_full_declaration decl
;
926 assert(Elements(semantic_names
) == TGSI_SEMANTIC_COUNT
);
927 assert(Elements(interpolate_names
) == TGSI_INTERPOLATE_COUNT
);
929 if (!eat_white( &ctx
->cur
)) {
930 report_error( ctx
, "Syntax error" );
933 if (!parse_register_dcl( ctx
, &file
, &first
, &last
))
935 if (!parse_opt_writemask( ctx
, &writemask
))
938 decl
= tgsi_default_full_declaration();
939 decl
.Declaration
.File
= file
;
940 decl
.Declaration
.UsageMask
= writemask
;
941 decl
.DeclarationRange
.First
= first
;
942 decl
.DeclarationRange
.Last
= last
;
945 eat_opt_white( &cur
);
950 eat_opt_white( &cur
);
951 for (i
= 0; i
< TGSI_SEMANTIC_COUNT
; i
++) {
952 if (str_match_no_case( &cur
, semantic_names
[i
] )) {
953 const char *cur2
= cur
;
956 if (is_digit_alpha_underscore( cur
))
958 eat_opt_white( &cur2
);
961 eat_opt_white( &cur2
);
962 if (!parse_uint( &cur2
, &index
)) {
963 report_error( ctx
, "Expected literal integer" );
966 eat_opt_white( &cur2
);
968 report_error( ctx
, "Expected `]'" );
973 decl
.Semantic
.SemanticIndex
= index
;
978 decl
.Declaration
.Semantic
= 1;
979 decl
.Semantic
.SemanticName
= i
;
988 eat_opt_white( &cur
);
993 eat_opt_white( &cur
);
994 for (i
= 0; i
< TGSI_INTERPOLATE_COUNT
; i
++) {
995 if (str_match_no_case( &cur
, interpolate_names
[i
] )) {
996 if (is_digit_alpha_underscore( cur
))
998 decl
.Declaration
.Interpolate
= i
;
1004 if (i
== TGSI_INTERPOLATE_COUNT
) {
1005 report_error( ctx
, "Expected semantic or interpolate attribute" );
1010 advance
= tgsi_build_full_declaration(
1014 (uint
) (ctx
->tokens_end
- ctx
->tokens_cur
) );
1017 ctx
->tokens_cur
+= advance
;
1022 static boolean
parse_immediate( struct translate_ctx
*ctx
)
1024 struct tgsi_full_immediate imm
;
1029 if (!eat_white( &ctx
->cur
)) {
1030 report_error( ctx
, "Syntax error" );
1033 if (!str_match_no_case( &ctx
->cur
, "FLT32" ) || is_digit_alpha_underscore( ctx
->cur
)) {
1034 report_error( ctx
, "Expected `FLT32'" );
1037 eat_opt_white( &ctx
->cur
);
1038 if (*ctx
->cur
!= '{') {
1039 report_error( ctx
, "Expected `{'" );
1043 for (i
= 0; i
< 4; i
++) {
1044 eat_opt_white( &ctx
->cur
);
1046 if (*ctx
->cur
!= ',') {
1047 report_error( ctx
, "Expected `,'" );
1051 eat_opt_white( &ctx
->cur
);
1053 if (!parse_float( &ctx
->cur
, &values
[i
] )) {
1054 report_error( ctx
, "Expected literal floating point" );
1058 eat_opt_white( &ctx
->cur
);
1059 if (*ctx
->cur
!= '}') {
1060 report_error( ctx
, "Expected `}'" );
1065 imm
= tgsi_default_full_immediate();
1066 imm
.Immediate
.NrTokens
+= 4;
1067 imm
.Immediate
.DataType
= TGSI_IMM_FLOAT32
;
1068 imm
.u
[0].Float
= values
[0];
1069 imm
.u
[1].Float
= values
[1];
1070 imm
.u
[2].Float
= values
[2];
1071 imm
.u
[3].Float
= values
[3];
1073 advance
= tgsi_build_full_immediate(
1077 (uint
) (ctx
->tokens_end
- ctx
->tokens_cur
) );
1080 ctx
->tokens_cur
+= advance
;
1085 static boolean
translate( struct translate_ctx
*ctx
)
1087 eat_opt_white( &ctx
->cur
);
1088 if (!parse_header( ctx
))
1091 while (*ctx
->cur
!= '\0') {
1094 if (!eat_white( &ctx
->cur
)) {
1095 report_error( ctx
, "Syntax error" );
1099 if (*ctx
->cur
== '\0')
1102 if (parse_label( ctx
, &label_val
)) {
1103 if (!parse_instruction( ctx
, TRUE
))
1106 else if (str_match_no_case( &ctx
->cur
, "DCL" )) {
1107 if (!parse_declaration( ctx
))
1110 else if (str_match_no_case( &ctx
->cur
, "IMM" )) {
1111 if (!parse_immediate( ctx
))
1114 else if (!parse_instruction( ctx
, FALSE
)) {
1123 tgsi_text_translate(
1125 struct tgsi_token
*tokens
,
1128 struct translate_ctx ctx
;
1132 ctx
.tokens
= tokens
;
1133 ctx
.tokens_cur
= tokens
;
1134 ctx
.tokens_end
= tokens
+ num_tokens
;
1136 if (!translate( &ctx
))
1139 return tgsi_sanity_check( tokens
);