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
] =
239 parse_file( const char **pcur
, uint
*file
)
243 for (i
= 0; i
< TGSI_FILE_COUNT
; i
++) {
244 const char *cur
= *pcur
;
246 if (str_match_no_case( &cur
, file_names
[i
] )) {
247 if (!is_digit_alpha_underscore( cur
)) {
259 struct translate_ctx
*ctx
,
265 eat_opt_white( &cur
);
268 *writemask
= TGSI_WRITEMASK_NONE
;
269 eat_opt_white( &cur
);
270 if (uprcase( *cur
) == 'X') {
272 *writemask
|= TGSI_WRITEMASK_X
;
274 if (uprcase( *cur
) == 'Y') {
276 *writemask
|= TGSI_WRITEMASK_Y
;
278 if (uprcase( *cur
) == 'Z') {
280 *writemask
|= TGSI_WRITEMASK_Z
;
282 if (uprcase( *cur
) == 'W') {
284 *writemask
|= TGSI_WRITEMASK_W
;
287 if (*writemask
== TGSI_WRITEMASK_NONE
) {
288 report_error( ctx
, "Writemask expected" );
295 *writemask
= TGSI_WRITEMASK_XYZW
;
300 /* <register_file_bracket> ::= <file> `['
303 parse_register_file_bracket(
304 struct translate_ctx
*ctx
,
307 if (!parse_file( &ctx
->cur
, file
)) {
308 report_error( ctx
, "Unknown register file" );
311 eat_opt_white( &ctx
->cur
);
312 if (*ctx
->cur
!= '[') {
313 report_error( ctx
, "Expected `['" );
320 /* <register_file_bracket_index> ::= <register_file_bracket> <uint>
323 parse_register_file_bracket_index(
324 struct translate_ctx
*ctx
,
330 if (!parse_register_file_bracket( ctx
, file
))
332 eat_opt_white( &ctx
->cur
);
333 if (!parse_uint( &ctx
->cur
, &uindex
)) {
334 report_error( ctx
, "Expected literal unsigned integer" );
337 *index
= (int) uindex
;
341 /* Parse destination register operand.
342 * <register_dst> ::= <register_file_bracket_index> `]'
346 struct translate_ctx
*ctx
,
350 if (!parse_register_file_bracket_index( ctx
, file
, index
))
352 eat_opt_white( &ctx
->cur
);
353 if (*ctx
->cur
!= ']') {
354 report_error( ctx
, "Expected `]'" );
361 /* Parse source register operand.
362 * <register_src> ::= <register_file_bracket_index> `]' |
363 * <register_file_bracket> <register_dst> [`.' (`x' | `y' | `z' | `w')] `]' |
364 * <register_file_bracket> <register_dst> [`.' (`x' | `y' | `z' | `w')] `+' <uint> `]' |
365 * <register_file_bracket> <register_dst> [`.' (`x' | `y' | `z' | `w')] `-' <uint> `]'
369 struct translate_ctx
*ctx
,
379 *ind_comp
= TGSI_SWIZZLE_X
;
380 if (!parse_register_file_bracket( ctx
, file
))
382 eat_opt_white( &ctx
->cur
);
384 if (parse_file( &cur
, ind_file
)) {
385 if (!parse_register_dst( ctx
, ind_file
, ind_index
))
387 eat_opt_white( &ctx
->cur
);
389 if (*ctx
->cur
== '.') {
391 eat_opt_white(&ctx
->cur
);
393 switch (uprcase(*ctx
->cur
)) {
395 *ind_comp
= TGSI_SWIZZLE_X
;
398 *ind_comp
= TGSI_SWIZZLE_Y
;
401 *ind_comp
= TGSI_SWIZZLE_Z
;
404 *ind_comp
= TGSI_SWIZZLE_W
;
407 report_error(ctx
, "Expected indirect register swizzle component `x', `y', `z' or `w'");
411 eat_opt_white(&ctx
->cur
);
414 if (*ctx
->cur
== '+' || *ctx
->cur
== '-') {
417 negate
= *ctx
->cur
== '-';
419 eat_opt_white( &ctx
->cur
);
420 if (!parse_uint( &ctx
->cur
, &uindex
)) {
421 report_error( ctx
, "Expected literal unsigned integer" );
425 *index
= -(int) uindex
;
427 *index
= (int) uindex
;
434 if (!parse_uint( &ctx
->cur
, &uindex
)) {
435 report_error( ctx
, "Expected literal unsigned integer" );
438 *index
= (int) uindex
;
439 *ind_file
= TGSI_FILE_NULL
;
442 eat_opt_white( &ctx
->cur
);
443 if (*ctx
->cur
!= ']') {
444 report_error( ctx
, "Expected `]'" );
451 /* Parse register declaration.
452 * <register_dcl> ::= <register_file_bracket_index> `]' |
453 * <register_file_bracket_index> `..' <index> `]'
457 struct translate_ctx
*ctx
,
462 if (!parse_register_file_bracket_index( ctx
, file
, first
))
464 eat_opt_white( &ctx
->cur
);
465 if (ctx
->cur
[0] == '.' && ctx
->cur
[1] == '.') {
469 eat_opt_white( &ctx
->cur
);
470 if (!parse_uint( &ctx
->cur
, &uindex
)) {
471 report_error( ctx
, "Expected literal integer" );
474 *last
= (int) uindex
;
475 eat_opt_white( &ctx
->cur
);
480 if (*ctx
->cur
!= ']') {
481 report_error( ctx
, "Expected `]' or `..'" );
488 static const char *modulate_names
[TGSI_MODULATE_COUNT
] =
501 struct translate_ctx
*ctx
,
502 struct tgsi_full_dst_register
*dst
)
509 if (!parse_register_dst( ctx
, &file
, &index
))
513 eat_opt_white( &cur
);
517 for (i
= 0; i
< TGSI_MODULATE_COUNT
; i
++) {
518 if (str_match_no_case( &cur
, modulate_names
[i
] )) {
519 if (!is_digit_alpha_underscore( cur
)) {
520 dst
->DstRegisterExtModulate
.Modulate
= i
;
528 if (!parse_opt_writemask( ctx
, &writemask
))
531 dst
->DstRegister
.File
= file
;
532 dst
->DstRegister
.Index
= index
;
533 dst
->DstRegister
.WriteMask
= writemask
;
538 parse_optional_swizzle(
539 struct translate_ctx
*ctx
,
541 boolean
*parsed_swizzle
,
542 boolean
*parsed_extswizzle
)
544 const char *cur
= ctx
->cur
;
546 *parsed_swizzle
= FALSE
;
547 *parsed_extswizzle
= FALSE
;
549 eat_opt_white( &cur
);
554 eat_opt_white( &cur
);
555 for (i
= 0; i
< 4; i
++) {
556 if (uprcase( *cur
) == 'X')
557 swizzle
[i
] = TGSI_SWIZZLE_X
;
558 else if (uprcase( *cur
) == 'Y')
559 swizzle
[i
] = TGSI_SWIZZLE_Y
;
560 else if (uprcase( *cur
) == 'Z')
561 swizzle
[i
] = TGSI_SWIZZLE_Z
;
562 else if (uprcase( *cur
) == 'W')
563 swizzle
[i
] = TGSI_SWIZZLE_W
;
566 swizzle
[i
] = TGSI_EXTSWIZZLE_ZERO
;
567 else if (*cur
== '1')
568 swizzle
[i
] = TGSI_EXTSWIZZLE_ONE
;
570 report_error( ctx
, "Expected register swizzle component `x', `y', `z', `w', `0' or `1'" );
573 *parsed_extswizzle
= TRUE
;
577 *parsed_swizzle
= TRUE
;
585 struct translate_ctx
*ctx
,
586 struct tgsi_full_src_register
*src
)
596 boolean parsed_ext_negate_paren
= FALSE
;
597 boolean parsed_swizzle
;
598 boolean parsed_extswizzle
;
600 if (*ctx
->cur
== '-') {
603 eat_opt_white( &cur
);
606 src
->SrcRegisterExtMod
.Negate
= 1;
607 eat_opt_white( &cur
);
609 parsed_ext_negate_paren
= TRUE
;
611 else if (*cur
== '|') {
613 src
->SrcRegisterExtMod
.Negate
= 1;
614 src
->SrcRegisterExtMod
.Absolute
= 1;
619 else if (*ctx
->cur
== '|') {
621 eat_opt_white( &ctx
->cur
);
622 src
->SrcRegisterExtMod
.Absolute
= 1;
625 if (*ctx
->cur
== '-') {
627 eat_opt_white( &ctx
->cur
);
628 src
->SrcRegister
.Negate
= 1;
632 if (parse_float( &cur
, &value
)) {
634 eat_opt_white( &cur
);
636 report_error( ctx
, "Expected `*'" );
641 report_error( ctx
, "Expected `('" );
645 src
->SrcRegisterExtMod
.Scale2X
= 1;
646 eat_opt_white( &cur
);
651 if (*ctx
->cur
== '(') {
653 eat_opt_white( &ctx
->cur
);
654 src
->SrcRegisterExtMod
.Bias
= 1;
658 if (parse_float( &cur
, &value
)) {
660 eat_opt_white( &cur
);
662 report_error( ctx
, "Expected `-'" );
667 report_error( ctx
, "Expected `('" );
671 src
->SrcRegisterExtMod
.Complement
= 1;
672 eat_opt_white( &cur
);
677 if (!parse_register_src(ctx
, &file
, &index
, &ind_file
, &ind_index
, &ind_comp
))
679 src
->SrcRegister
.File
= file
;
680 src
->SrcRegister
.Index
= index
;
681 if (ind_file
!= TGSI_FILE_NULL
) {
682 src
->SrcRegister
.Indirect
= 1;
683 src
->SrcRegisterInd
.File
= ind_file
;
684 src
->SrcRegisterInd
.Index
= ind_index
;
685 src
->SrcRegisterInd
.SwizzleX
= ind_comp
;
686 src
->SrcRegisterInd
.SwizzleY
= ind_comp
;
687 src
->SrcRegisterInd
.SwizzleZ
= ind_comp
;
688 src
->SrcRegisterInd
.SwizzleW
= ind_comp
;
691 /* Parse optional swizzle.
693 if (parse_optional_swizzle( ctx
, swizzle
, &parsed_swizzle
, &parsed_extswizzle
)) {
694 if (parsed_extswizzle
) {
695 assert( parsed_swizzle
);
697 src
->SrcRegisterExtSwz
.ExtSwizzleX
= swizzle
[0];
698 src
->SrcRegisterExtSwz
.ExtSwizzleY
= swizzle
[1];
699 src
->SrcRegisterExtSwz
.ExtSwizzleZ
= swizzle
[2];
700 src
->SrcRegisterExtSwz
.ExtSwizzleW
= swizzle
[3];
702 else if (parsed_swizzle
) {
703 src
->SrcRegister
.SwizzleX
= swizzle
[0];
704 src
->SrcRegister
.SwizzleY
= swizzle
[1];
705 src
->SrcRegister
.SwizzleZ
= swizzle
[2];
706 src
->SrcRegister
.SwizzleW
= swizzle
[3];
710 if (src
->SrcRegisterExtMod
.Complement
) {
711 eat_opt_white( &ctx
->cur
);
712 if (*ctx
->cur
!= ')') {
713 report_error( ctx
, "Expected `)'" );
719 if (src
->SrcRegisterExtMod
.Bias
) {
720 eat_opt_white( &ctx
->cur
);
721 if (*ctx
->cur
!= ')') {
722 report_error( ctx
, "Expected `)'" );
726 eat_opt_white( &ctx
->cur
);
727 if (*ctx
->cur
!= '-') {
728 report_error( ctx
, "Expected `-'" );
732 eat_opt_white( &ctx
->cur
);
733 if (!parse_float( &ctx
->cur
, &value
)) {
734 report_error( ctx
, "Expected literal floating point" );
738 report_error( ctx
, "Expected 0.5" );
743 if (src
->SrcRegisterExtMod
.Scale2X
) {
744 eat_opt_white( &ctx
->cur
);
745 if (*ctx
->cur
!= ')') {
746 report_error( ctx
, "Expected `)'" );
752 if (src
->SrcRegisterExtMod
.Absolute
) {
753 eat_opt_white( &ctx
->cur
);
754 if (*ctx
->cur
!= '|') {
755 report_error( ctx
, "Expected `|'" );
761 if (parsed_ext_negate_paren
) {
762 eat_opt_white( &ctx
->cur
);
763 if (*ctx
->cur
!= ')') {
764 report_error( ctx
, "Expected `)'" );
773 static const char *texture_names
[TGSI_TEXTURE_COUNT
] =
787 match_inst_mnemonic(const char **pcur
,
788 const struct tgsi_opcode_info
*info
)
790 if (str_match_no_case(pcur
, info
->mnemonic
)) {
798 struct translate_ctx
*ctx
,
802 uint saturate
= TGSI_SAT_NONE
;
803 const struct tgsi_opcode_info
*info
;
804 struct tgsi_full_instruction inst
;
807 /* Parse instruction name.
809 eat_opt_white( &ctx
->cur
);
810 for (i
= 0; i
< TGSI_OPCODE_LAST
; i
++) {
811 const char *cur
= ctx
->cur
;
813 info
= tgsi_get_opcode_info( i
);
814 if (match_inst_mnemonic(&cur
, info
)) {
815 if (str_match_no_case( &cur
, "_SATNV" ))
816 saturate
= TGSI_SAT_MINUS_PLUS_ONE
;
817 else if (str_match_no_case( &cur
, "_SAT" ))
818 saturate
= TGSI_SAT_ZERO_ONE
;
820 if (info
->num_dst
+ info
->num_src
+ info
->is_tex
== 0) {
821 if (!is_digit_alpha_underscore( cur
)) {
826 else if (*cur
== '\0' || eat_white( &cur
)) {
832 if (i
== TGSI_OPCODE_LAST
) {
834 report_error( ctx
, "Unknown opcode" );
836 report_error( ctx
, "Expected `DCL', `IMM' or a label" );
840 inst
= tgsi_default_full_instruction();
841 inst
.Instruction
.Opcode
= i
;
842 inst
.Instruction
.Saturate
= saturate
;
843 inst
.Instruction
.NumDstRegs
= info
->num_dst
;
844 inst
.Instruction
.NumSrcRegs
= info
->num_src
;
846 /* Parse instruction operands.
848 for (i
= 0; i
< info
->num_dst
+ info
->num_src
+ info
->is_tex
; i
++) {
850 eat_opt_white( &ctx
->cur
);
851 if (*ctx
->cur
!= ',') {
852 report_error( ctx
, "Expected `,'" );
856 eat_opt_white( &ctx
->cur
);
859 if (i
< info
->num_dst
) {
860 if (!parse_dst_operand( ctx
, &inst
.FullDstRegisters
[i
] ))
863 else if (i
< info
->num_dst
+ info
->num_src
) {
864 if (!parse_src_operand( ctx
, &inst
.FullSrcRegisters
[i
- info
->num_dst
] ))
870 for (j
= 0; j
< TGSI_TEXTURE_COUNT
; j
++) {
871 if (str_match_no_case( &ctx
->cur
, texture_names
[j
] )) {
872 if (!is_digit_alpha_underscore( ctx
->cur
)) {
873 inst
.InstructionExtTexture
.Texture
= j
;
878 if (j
== TGSI_TEXTURE_COUNT
) {
879 report_error( ctx
, "Expected texture target" );
885 if (info
->is_branch
) {
888 eat_opt_white( &ctx
->cur
);
889 if (*ctx
->cur
!= ':') {
890 report_error( ctx
, "Expected `:'" );
894 eat_opt_white( &ctx
->cur
);
895 if (!parse_uint( &ctx
->cur
, &target
)) {
896 report_error( ctx
, "Expected a label" );
899 inst
.InstructionExtLabel
.Label
= target
;
902 advance
= tgsi_build_full_instruction(
906 (uint
) (ctx
->tokens_end
- ctx
->tokens_cur
) );
909 ctx
->tokens_cur
+= advance
;
914 static const char *semantic_names
[TGSI_SEMANTIC_COUNT
] =
926 static const char *interpolate_names
[TGSI_INTERPOLATE_COUNT
] =
933 static boolean
parse_declaration( struct translate_ctx
*ctx
)
935 struct tgsi_full_declaration decl
;
943 assert(Elements(semantic_names
) == TGSI_SEMANTIC_COUNT
);
944 assert(Elements(interpolate_names
) == TGSI_INTERPOLATE_COUNT
);
946 if (!eat_white( &ctx
->cur
)) {
947 report_error( ctx
, "Syntax error" );
950 if (!parse_register_dcl( ctx
, &file
, &first
, &last
))
952 if (!parse_opt_writemask( ctx
, &writemask
))
955 decl
= tgsi_default_full_declaration();
956 decl
.Declaration
.File
= file
;
957 decl
.Declaration
.UsageMask
= writemask
;
958 decl
.DeclarationRange
.First
= first
;
959 decl
.DeclarationRange
.Last
= last
;
962 eat_opt_white( &cur
);
967 eat_opt_white( &cur
);
968 for (i
= 0; i
< TGSI_SEMANTIC_COUNT
; i
++) {
969 if (str_match_no_case( &cur
, semantic_names
[i
] )) {
970 const char *cur2
= cur
;
973 if (is_digit_alpha_underscore( cur
))
975 eat_opt_white( &cur2
);
978 eat_opt_white( &cur2
);
979 if (!parse_uint( &cur2
, &index
)) {
980 report_error( ctx
, "Expected literal integer" );
983 eat_opt_white( &cur2
);
985 report_error( ctx
, "Expected `]'" );
990 decl
.Semantic
.SemanticIndex
= index
;
995 decl
.Declaration
.Semantic
= 1;
996 decl
.Semantic
.SemanticName
= i
;
1005 eat_opt_white( &cur
);
1010 eat_opt_white( &cur
);
1011 for (i
= 0; i
< TGSI_INTERPOLATE_COUNT
; i
++) {
1012 if (str_match_no_case( &cur
, interpolate_names
[i
] )) {
1013 if (is_digit_alpha_underscore( cur
))
1015 decl
.Declaration
.Interpolate
= i
;
1021 if (i
== TGSI_INTERPOLATE_COUNT
) {
1022 report_error( ctx
, "Expected semantic or interpolate attribute" );
1027 advance
= tgsi_build_full_declaration(
1031 (uint
) (ctx
->tokens_end
- ctx
->tokens_cur
) );
1034 ctx
->tokens_cur
+= advance
;
1039 static boolean
parse_immediate( struct translate_ctx
*ctx
)
1041 struct tgsi_full_immediate imm
;
1046 if (!eat_white( &ctx
->cur
)) {
1047 report_error( ctx
, "Syntax error" );
1050 if (!str_match_no_case( &ctx
->cur
, "FLT32" ) || is_digit_alpha_underscore( ctx
->cur
)) {
1051 report_error( ctx
, "Expected `FLT32'" );
1054 eat_opt_white( &ctx
->cur
);
1055 if (*ctx
->cur
!= '{') {
1056 report_error( ctx
, "Expected `{'" );
1060 for (i
= 0; i
< 4; i
++) {
1061 eat_opt_white( &ctx
->cur
);
1063 if (*ctx
->cur
!= ',') {
1064 report_error( ctx
, "Expected `,'" );
1068 eat_opt_white( &ctx
->cur
);
1070 if (!parse_float( &ctx
->cur
, &values
[i
] )) {
1071 report_error( ctx
, "Expected literal floating point" );
1075 eat_opt_white( &ctx
->cur
);
1076 if (*ctx
->cur
!= '}') {
1077 report_error( ctx
, "Expected `}'" );
1082 imm
= tgsi_default_full_immediate();
1083 imm
.Immediate
.NrTokens
+= 4;
1084 imm
.Immediate
.DataType
= TGSI_IMM_FLOAT32
;
1085 imm
.u
[0].Float
= values
[0];
1086 imm
.u
[1].Float
= values
[1];
1087 imm
.u
[2].Float
= values
[2];
1088 imm
.u
[3].Float
= values
[3];
1090 advance
= tgsi_build_full_immediate(
1094 (uint
) (ctx
->tokens_end
- ctx
->tokens_cur
) );
1097 ctx
->tokens_cur
+= advance
;
1102 static boolean
translate( struct translate_ctx
*ctx
)
1104 eat_opt_white( &ctx
->cur
);
1105 if (!parse_header( ctx
))
1108 while (*ctx
->cur
!= '\0') {
1111 if (!eat_white( &ctx
->cur
)) {
1112 report_error( ctx
, "Syntax error" );
1116 if (*ctx
->cur
== '\0')
1119 if (parse_label( ctx
, &label_val
)) {
1120 if (!parse_instruction( ctx
, TRUE
))
1123 else if (str_match_no_case( &ctx
->cur
, "DCL" )) {
1124 if (!parse_declaration( ctx
))
1127 else if (str_match_no_case( &ctx
->cur
, "IMM" )) {
1128 if (!parse_immediate( ctx
))
1131 else if (!parse_instruction( ctx
, FALSE
)) {
1140 tgsi_text_translate(
1142 struct tgsi_token
*tokens
,
1145 struct translate_ctx ctx
;
1149 ctx
.tokens
= tokens
;
1150 ctx
.tokens_cur
= tokens
;
1151 ctx
.tokens_end
= tokens
+ num_tokens
;
1153 if (!translate( &ctx
))
1156 return tgsi_sanity_check( tokens
);