1 /**************************************************************************
3 * Copyright 2009 VMware, Inc.
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 **************************************************************************/
31 #include "../pp/sl_pp_public.h"
32 #include "sl_cl_parse.h"
35 /* revision number - increment after each change affecting emitted output */
38 /* external declaration (or precision or invariant stmt) */
39 #define EXTERNAL_NULL 0
40 #define EXTERNAL_FUNCTION_DEFINITION 1
41 #define EXTERNAL_DECLARATION 2
42 #define DEFAULT_PRECISION 3
43 #define INVARIANT_STMT 4
46 #define PRECISION_DEFAULT 0
47 #define PRECISION_LOW 1
48 #define PRECISION_MEDIUM 2
49 #define PRECISION_HIGH 3
52 #define DECLARATION_FUNCTION_PROTOTYPE 1
53 #define DECLARATION_INIT_DECLARATOR_LIST 2
56 #define FUNCTION_ORDINARY 0
57 #define FUNCTION_CONSTRUCTOR 1
58 #define FUNCTION_OPERATOR 2
60 /* function call type */
61 #define FUNCTION_CALL_NONARRAY 0
62 #define FUNCTION_CALL_ARRAY 1
65 #define OPERATOR_ADDASSIGN 1
66 #define OPERATOR_SUBASSIGN 2
67 #define OPERATOR_MULASSIGN 3
68 #define OPERATOR_DIVASSIGN 4
69 /*#define OPERATOR_MODASSIGN 5*/
70 /*#define OPERATOR_LSHASSIGN 6*/
71 /*#define OPERATOR_RSHASSIGN 7*/
72 /*#define OPERATOR_ORASSIGN 8*/
73 /*#define OPERATOR_XORASSIGN 9*/
74 /*#define OPERATOR_ANDASSIGN 10*/
75 #define OPERATOR_LOGICALXOR 11
76 /*#define OPERATOR_BITOR 12*/
77 /*#define OPERATOR_BITXOR 13*/
78 /*#define OPERATOR_BITAND 14*/
79 #define OPERATOR_LESS 15
80 #define OPERATOR_GREATER 16
81 #define OPERATOR_LESSEQUAL 17
82 #define OPERATOR_GREATEREQUAL 18
83 /*#define OPERATOR_LSHIFT 19*/
84 /*#define OPERATOR_RSHIFT 20*/
85 #define OPERATOR_MULTIPLY 21
86 #define OPERATOR_DIVIDE 22
87 /*#define OPERATOR_MODULUS 23*/
88 #define OPERATOR_INCREMENT 24
89 #define OPERATOR_DECREMENT 25
90 #define OPERATOR_PLUS 26
91 #define OPERATOR_MINUS 27
92 /*#define OPERATOR_COMPLEMENT 28*/
93 #define OPERATOR_NOT 29
95 /* init declarator list */
96 #define DECLARATOR_NONE 0
97 #define DECLARATOR_NEXT 1
99 /* variable declaration */
100 #define VARIABLE_NONE 0
101 #define VARIABLE_IDENTIFIER 1
102 #define VARIABLE_INITIALIZER 2
103 #define VARIABLE_ARRAY_EXPLICIT 3
104 #define VARIABLE_ARRAY_UNKNOWN 4
107 #define TYPE_QUALIFIER_NONE 0
108 #define TYPE_QUALIFIER_CONST 1
109 #define TYPE_QUALIFIER_ATTRIBUTE 2
110 #define TYPE_QUALIFIER_VARYING 3
111 #define TYPE_QUALIFIER_UNIFORM 4
112 #define TYPE_QUALIFIER_FIXEDOUTPUT 5
113 #define TYPE_QUALIFIER_FIXEDINPUT 6
115 /* invariant qualifier */
116 #define TYPE_VARIANT 90
117 #define TYPE_INVARIANT 91
119 /* centroid qualifier */
120 #define TYPE_CENTER 95
121 #define TYPE_CENTROID 96
124 #define TYPE_SPECIFIER_VOID 0
125 #define TYPE_SPECIFIER_BOOL 1
126 #define TYPE_SPECIFIER_BVEC2 2
127 #define TYPE_SPECIFIER_BVEC3 3
128 #define TYPE_SPECIFIER_BVEC4 4
129 #define TYPE_SPECIFIER_INT 5
130 #define TYPE_SPECIFIER_IVEC2 6
131 #define TYPE_SPECIFIER_IVEC3 7
132 #define TYPE_SPECIFIER_IVEC4 8
133 #define TYPE_SPECIFIER_FLOAT 9
134 #define TYPE_SPECIFIER_VEC2 10
135 #define TYPE_SPECIFIER_VEC3 11
136 #define TYPE_SPECIFIER_VEC4 12
137 #define TYPE_SPECIFIER_MAT2 13
138 #define TYPE_SPECIFIER_MAT3 14
139 #define TYPE_SPECIFIER_MAT4 15
140 #define TYPE_SPECIFIER_SAMPLER1D 16
141 #define TYPE_SPECIFIER_SAMPLER2D 17
142 #define TYPE_SPECIFIER_SAMPLER3D 18
143 #define TYPE_SPECIFIER_SAMPLERCUBE 19
144 #define TYPE_SPECIFIER_SAMPLER1DSHADOW 20
145 #define TYPE_SPECIFIER_SAMPLER2DSHADOW 21
146 #define TYPE_SPECIFIER_SAMPLER2DRECT 22
147 #define TYPE_SPECIFIER_SAMPLER2DRECTSHADOW 23
148 #define TYPE_SPECIFIER_STRUCT 24
149 #define TYPE_SPECIFIER_TYPENAME 25
152 #define TYPE_SPECIFIER_MAT23 26
153 #define TYPE_SPECIFIER_MAT32 27
154 #define TYPE_SPECIFIER_MAT24 28
155 #define TYPE_SPECIFIER_MAT42 29
156 #define TYPE_SPECIFIER_MAT34 30
157 #define TYPE_SPECIFIER_MAT43 31
159 /* type specifier array */
160 #define TYPE_SPECIFIER_NONARRAY 0
161 #define TYPE_SPECIFIER_ARRAY 1
163 /* structure field */
166 #define FIELD_ARRAY 2
170 #define OP_BLOCK_BEGIN_NO_NEW_SCOPE 1
171 #define OP_BLOCK_BEGIN_NEW_SCOPE 2
175 #define OP_CONTINUE 6
178 #define OP_EXPRESSION 9
183 #define OP_PUSH_VOID 14
184 #define OP_PUSH_BOOL 15
185 #define OP_PUSH_INT 16
186 #define OP_PUSH_FLOAT 17
187 #define OP_PUSH_IDENTIFIER 18
188 #define OP_SEQUENCE 19
190 #define OP_ADDASSIGN 21
191 #define OP_SUBASSIGN 22
192 #define OP_MULASSIGN 23
193 #define OP_DIVASSIGN 24
194 /*#define OP_MODASSIGN 25*/
195 /*#define OP_LSHASSIGN 26*/
196 /*#define OP_RSHASSIGN 27*/
197 /*#define OP_ORASSIGN 28*/
198 /*#define OP_XORASSIGN 29*/
199 /*#define OP_ANDASSIGN 30*/
201 #define OP_LOGICALOR 32
202 #define OP_LOGICALXOR 33
203 #define OP_LOGICALAND 34
204 /*#define OP_BITOR 35*/
205 /*#define OP_BITXOR 36*/
206 /*#define OP_BITAND 37*/
208 #define OP_NOTEQUAL 39
210 #define OP_GREATER 41
211 #define OP_LESSEQUAL 42
212 #define OP_GREATEREQUAL 43
213 /*#define OP_LSHIFT 44*/
214 /*#define OP_RSHIFT 45*/
216 #define OP_SUBTRACT 47
217 #define OP_MULTIPLY 48
219 /*#define OP_MODULUS 50*/
220 #define OP_PREINCREMENT 51
221 #define OP_PREDECREMENT 52
224 /*#define OP_COMPLEMENT 55*/
226 #define OP_SUBSCRIPT 57
229 #define OP_POSTINCREMENT 60
230 #define OP_POSTDECREMENT 61
231 #define OP_PRECISION 62
234 /* parameter qualifier */
235 #define PARAM_QUALIFIER_IN 0
236 #define PARAM_QUALIFIER_OUT 1
237 #define PARAM_QUALIFIER_INOUT 2
239 /* function parameter */
240 #define PARAMETER_NONE 0
241 #define PARAMETER_NEXT 1
243 /* function parameter array presence */
244 #define PARAMETER_ARRAY_NOT_PRESENT 0
245 #define PARAMETER_ARRAY_PRESENT 1
278 int sampler2DRectShadow
;
322 struct parse_context
{
323 struct sl_pp_context
*context
;
325 struct parse_dict dict
;
327 struct sl_pp_token_info
*tokens
;
328 unsigned int tokens_read
;
329 unsigned int tokens_cap
;
331 unsigned char *out_buf
;
332 unsigned int out_cap
;
334 unsigned int shader_type
;
335 unsigned int parsing_builtin
;
349 _emit(struct parse_context
*ctx
,
353 if (*out
== ctx
->out_cap
) {
354 ctx
->out_cap
+= 4096;
355 ctx
->out_buf
= (unsigned char *)realloc(ctx
->out_buf
, ctx
->out_cap
* sizeof(unsigned char));
357 ctx
->out_buf
[*out
] = b
;
363 _update(struct parse_context
*ctx
,
367 ctx
->out_buf
[out
] = b
;
372 _error(struct parse_context
*ctx
,
375 if (ctx
->error
[0] == '\0') {
376 strcpy(ctx
->error
, msg
);
381 static const struct sl_pp_token_info
*
382 _fetch_token(struct parse_context
*ctx
,
385 if (ctx
->process_error
) {
389 while (pos
>= ctx
->tokens_read
) {
390 if (ctx
->tokens_read
== ctx
->tokens_cap
) {
391 ctx
->tokens_cap
+= 1024;
392 ctx
->tokens
= realloc(ctx
->tokens
,
393 ctx
->tokens_cap
* sizeof(struct sl_pp_token_info
));
395 _error(ctx
, "out of memory");
396 ctx
->process_error
= 1;
400 if (sl_pp_process_get(ctx
->context
, &ctx
->tokens
[ctx
->tokens_read
])) {
401 _error(ctx
, sl_pp_context_error_message(ctx
->context
));
402 ctx
->process_error
= 1;
405 switch (ctx
->tokens
[ctx
->tokens_read
].token
) {
407 case SL_PP_SEMICOLON
:
415 case SL_PP_INCREMENT
:
416 case SL_PP_ADDASSIGN
:
418 case SL_PP_DECREMENT
:
419 case SL_PP_SUBASSIGN
:
424 case SL_PP_MULASSIGN
:
426 case SL_PP_DIVASSIGN
:
428 case SL_PP_MODASSIGN
:
430 case SL_PP_LSHIFTASSIGN
:
432 case SL_PP_LESSEQUAL
:
434 case SL_PP_RSHIFTASSIGN
:
436 case SL_PP_GREATEREQUAL
:
441 case SL_PP_BITANDASSIGN
:
444 case SL_PP_BITXORASSIGN
:
447 case SL_PP_BITORASSIGN
:
451 case SL_PP_IDENTIFIER
:
461 return &ctx
->tokens
[pos
];
466 _parse_token(struct parse_context
*ctx
,
467 enum sl_pp_token token
,
468 struct parse_state
*ps
)
470 const struct sl_pp_token_info
*input
= _fetch_token(ctx
, ps
->in
);
472 if (input
&& input
->token
== token
) {
481 _parse_id(struct parse_context
*ctx
,
483 struct parse_state
*ps
)
485 const struct sl_pp_token_info
*input
= _fetch_token(ctx
, ps
->in
);
487 if (input
&& input
->token
== SL_PP_IDENTIFIER
&& input
->data
.identifier
== id
) {
496 _parse_identifier(struct parse_context
*ctx
,
497 struct parse_state
*ps
)
499 const struct sl_pp_token_info
*input
= _fetch_token(ctx
, ps
->in
);
501 if (input
&& input
->token
== SL_PP_IDENTIFIER
) {
502 const char *cstr
= sl_pp_context_cstr(ctx
->context
, input
->data
.identifier
);
505 _emit(ctx
, &ps
->out
, *cstr
);
515 _parse_float(struct parse_context
*ctx
,
516 struct parse_state
*ps
)
518 const struct sl_pp_token_info
*input
= _fetch_token(ctx
, ps
->in
);
520 if (input
&& input
->token
== SL_PP_FLOAT
) {
521 const char *cstr
= sl_pp_context_cstr(ctx
->context
, input
->data
._float
);
523 _emit(ctx
, &ps
->out
, 1);
525 _emit(ctx
, &ps
->out
, *cstr
);
535 _parse_uint(struct parse_context
*ctx
,
536 struct parse_state
*ps
)
538 const struct sl_pp_token_info
*input
= _fetch_token(ctx
, ps
->in
);
540 if (input
&& input
->token
== SL_PP_UINT
) {
541 const char *cstr
= sl_pp_context_cstr(ctx
->context
, input
->data
._uint
);
543 _emit(ctx
, &ps
->out
, 1);
545 _emit(ctx
, &ps
->out
, *cstr
);
554 /**************************************/
558 _parse_unary_expression(struct parse_context
*ctx
,
559 struct parse_state
*ps
);
562 _parse_conditional_expression(struct parse_context
*ctx
,
563 struct parse_state
*ps
);
567 _parse_constant_expression(struct parse_context
*ctx
,
568 struct parse_state
*ps
);
572 _parse_primary_expression(struct parse_context
*ctx
,
573 struct parse_state
*ps
);
577 _parse_statement(struct parse_context
*ctx
,
578 struct parse_state
*ps
);
582 _parse_type_specifier(struct parse_context
*ctx
,
583 struct parse_state
*ps
);
587 _parse_declaration(struct parse_context
*ctx
,
588 struct parse_state
*ps
);
592 _parse_statement_list(struct parse_context
*ctx
,
593 struct parse_state
*ps
);
597 _parse_assignment_expression(struct parse_context
*ctx
,
598 struct parse_state
*ps
);
602 _parse_precision(struct parse_context
*ctx
,
603 struct parse_state
*ps
);
607 _parse_overriden_operator(struct parse_context
*ctx
,
608 struct parse_state
*ps
)
612 if (_parse_token(ctx
, SL_PP_INCREMENT
, ps
) == 0) {
613 op
= OPERATOR_INCREMENT
;
614 } else if (_parse_token(ctx
, SL_PP_ADDASSIGN
, ps
) == 0) {
615 op
= OPERATOR_ADDASSIGN
;
616 } else if (_parse_token(ctx
, SL_PP_PLUS
, ps
) == 0) {
618 } else if (_parse_token(ctx
, SL_PP_DECREMENT
, ps
) == 0) {
619 op
= OPERATOR_DECREMENT
;
620 } else if (_parse_token(ctx
, SL_PP_SUBASSIGN
, ps
) == 0) {
621 op
= OPERATOR_SUBASSIGN
;
622 } else if (_parse_token(ctx
, SL_PP_MINUS
, ps
) == 0) {
624 } else if (_parse_token(ctx
, SL_PP_NOT
, ps
) == 0) {
626 } else if (_parse_token(ctx
, SL_PP_MULASSIGN
, ps
) == 0) {
627 op
= OPERATOR_MULASSIGN
;
628 } else if (_parse_token(ctx
, SL_PP_STAR
, ps
) == 0) {
629 op
= OPERATOR_MULTIPLY
;
630 } else if (_parse_token(ctx
, SL_PP_DIVASSIGN
, ps
) == 0) {
631 op
= OPERATOR_DIVASSIGN
;
632 } else if (_parse_token(ctx
, SL_PP_SLASH
, ps
) == 0) {
633 op
= OPERATOR_DIVIDE
;
634 } else if (_parse_token(ctx
, SL_PP_LESSEQUAL
, ps
) == 0) {
635 op
= OPERATOR_LESSEQUAL
;
636 } else if (_parse_token(ctx
, SL_PP_LESS
, ps
) == 0) {
638 } else if (_parse_token(ctx
, SL_PP_GREATEREQUAL
, ps
) == 0) {
639 op
= OPERATOR_GREATEREQUAL
;
640 } else if (_parse_token(ctx
, SL_PP_GREATER
, ps
) == 0) {
641 op
= OPERATOR_GREATER
;
642 } else if (_parse_token(ctx
, SL_PP_XOR
, ps
) == 0) {
643 op
= OPERATOR_LOGICALXOR
;
648 _emit(ctx
, &ps
->out
, op
);
654 _parse_function_decl_identifier(struct parse_context
*ctx
,
655 struct parse_state
*ps
)
657 struct parse_state p
= *ps
;
658 unsigned int e
= _emit(ctx
, &p
.out
, 0);
660 if (ctx
->parsing_builtin
&& _parse_id(ctx
, ctx
->dict
.__constructor
, &p
) == 0) {
661 _update(ctx
, e
, FUNCTION_CONSTRUCTOR
);
666 if (ctx
->parsing_builtin
&& _parse_id(ctx
, ctx
->dict
.__operator
, &p
) == 0) {
667 _update(ctx
, e
, FUNCTION_OPERATOR
);
668 if (_parse_overriden_operator(ctx
, &p
) == 0) {
675 if (_parse_identifier(ctx
, &p
) == 0) {
676 _update(ctx
, e
, FUNCTION_ORDINARY
);
686 _parse_invariant_qualifier(struct parse_context
*ctx
,
687 struct parse_state
*ps
)
689 if (_parse_id(ctx
, ctx
->dict
.invariant
, ps
)) {
692 _emit(ctx
, &ps
->out
, TYPE_INVARIANT
);
698 _parse_centroid_qualifier(struct parse_context
*ctx
,
699 struct parse_state
*ps
)
701 if (_parse_id(ctx
, ctx
->dict
.centroid
, ps
)) {
704 _emit(ctx
, &ps
->out
, TYPE_CENTROID
);
710 _parse_type_qualifier(struct parse_context
*ctx
,
711 struct parse_state
*ps
)
713 struct parse_state p
= *ps
;
714 const struct sl_pp_token_info
*input
= _fetch_token(ctx
, p
.in
);
715 unsigned int e
= _emit(ctx
, &p
.out
, 0);
718 if (!input
|| input
->token
!= SL_PP_IDENTIFIER
) {
721 id
= input
->data
.identifier
;
723 if (id
== ctx
->dict
._const
) {
724 _update(ctx
, e
, TYPE_QUALIFIER_CONST
);
725 } else if (ctx
->shader_type
== 2 && id
== ctx
->dict
.attribute
) {
726 _update(ctx
, e
, TYPE_QUALIFIER_ATTRIBUTE
);
727 } else if (id
== ctx
->dict
.varying
) {
728 _update(ctx
, e
, TYPE_QUALIFIER_VARYING
);
729 } else if (id
== ctx
->dict
.uniform
) {
730 _update(ctx
, e
, TYPE_QUALIFIER_UNIFORM
);
731 } else if (ctx
->parsing_builtin
&& id
== ctx
->dict
.__fixed_output
) {
732 _update(ctx
, e
, TYPE_QUALIFIER_FIXEDOUTPUT
);
733 } else if (ctx
->parsing_builtin
&& id
== ctx
->dict
.__fixed_input
) {
734 _update(ctx
, e
, TYPE_QUALIFIER_FIXEDINPUT
);
738 _parse_token(ctx
, SL_PP_IDENTIFIER
, &p
);
745 _parse_struct_declarator(struct parse_context
*ctx
,
746 struct parse_state
*ps
)
748 struct parse_state p
= *ps
;
751 if (_parse_identifier(ctx
, &p
)) {
754 e
= _emit(ctx
, &p
.out
, FIELD_NONE
);
757 if (_parse_token(ctx
, SL_PP_LBRACKET
, &p
)) {
760 if (_parse_constant_expression(ctx
, &p
)) {
761 _error(ctx
, "expected constant integral expression");
764 if (_parse_token(ctx
, SL_PP_RBRACKET
, &p
)) {
765 _error(ctx
, "expected `]'");
768 _update(ctx
, e
, FIELD_ARRAY
);
775 _parse_struct_declarator_list(struct parse_context
*ctx
,
776 struct parse_state
*ps
)
778 struct parse_state p
= *ps
;
780 if (_parse_struct_declarator(ctx
, &p
)) {
786 _emit(ctx
, &p
.out
, FIELD_NEXT
);
787 if (_parse_token(ctx
, SL_PP_COMMA
, &p
)) {
790 if (_parse_struct_declarator(ctx
, &p
)) {
798 _parse_struct_declaration(struct parse_context
*ctx
,
799 struct parse_state
*ps
)
801 struct parse_state p
= *ps
;
803 if (_parse_type_specifier(ctx
, &p
)) {
806 if (_parse_struct_declarator_list(ctx
, &p
)) {
809 if (_parse_token(ctx
, SL_PP_SEMICOLON
, &p
)) {
812 _emit(ctx
, &p
.out
, FIELD_NONE
);
819 _parse_struct_declaration_list(struct parse_context
*ctx
,
820 struct parse_state
*ps
)
822 struct parse_state p
= *ps
;
824 if (_parse_struct_declaration(ctx
, &p
)) {
830 _emit(ctx
, &p
.out
, FIELD_NEXT
);
831 if (_parse_struct_declaration(ctx
, &p
)) {
839 _parse_struct_specifier(struct parse_context
*ctx
,
840 struct parse_state
*ps
)
842 struct parse_state p
= *ps
;
844 if (_parse_id(ctx
, ctx
->dict
._struct
, &p
)) {
847 if (_parse_identifier(ctx
, &p
)) {
848 _emit(ctx
, &p
.out
, '\0');
850 if (_parse_token(ctx
, SL_PP_LBRACE
, &p
)) {
851 _error(ctx
, "expected `{'");
854 if (_parse_struct_declaration_list(ctx
, &p
)) {
857 if (_parse_token(ctx
, SL_PP_RBRACE
, &p
)) {
860 _emit(ctx
, &p
.out
, FIELD_NONE
);
867 _parse_type_specifier_nonarray(struct parse_context
*ctx
,
868 struct parse_state
*ps
)
870 struct parse_state p
= *ps
;
871 unsigned int e
= _emit(ctx
, &p
.out
, 0);
872 const struct sl_pp_token_info
*input
;
875 if (_parse_struct_specifier(ctx
, &p
) == 0) {
876 _update(ctx
, e
, TYPE_SPECIFIER_STRUCT
);
881 input
= _fetch_token(ctx
, p
.in
);
882 if (!input
|| input
->token
!= SL_PP_IDENTIFIER
) {
885 id
= input
->data
.identifier
;
887 if (id
== ctx
->dict
._void
) {
888 _update(ctx
, e
, TYPE_SPECIFIER_VOID
);
889 } else if (id
== ctx
->dict
._float
) {
890 _update(ctx
, e
, TYPE_SPECIFIER_FLOAT
);
891 } else if (id
== ctx
->dict
._int
) {
892 _update(ctx
, e
, TYPE_SPECIFIER_INT
);
893 } else if (id
== ctx
->dict
._bool
) {
894 _update(ctx
, e
, TYPE_SPECIFIER_BOOL
);
895 } else if (id
== ctx
->dict
.vec2
) {
896 _update(ctx
, e
, TYPE_SPECIFIER_VEC2
);
897 } else if (id
== ctx
->dict
.vec3
) {
898 _update(ctx
, e
, TYPE_SPECIFIER_VEC3
);
899 } else if (id
== ctx
->dict
.vec4
) {
900 _update(ctx
, e
, TYPE_SPECIFIER_VEC4
);
901 } else if (id
== ctx
->dict
.bvec2
) {
902 _update(ctx
, e
, TYPE_SPECIFIER_BVEC2
);
903 } else if (id
== ctx
->dict
.bvec3
) {
904 _update(ctx
, e
, TYPE_SPECIFIER_BVEC3
);
905 } else if (id
== ctx
->dict
.bvec4
) {
906 _update(ctx
, e
, TYPE_SPECIFIER_BVEC4
);
907 } else if (id
== ctx
->dict
.ivec2
) {
908 _update(ctx
, e
, TYPE_SPECIFIER_IVEC2
);
909 } else if (id
== ctx
->dict
.ivec3
) {
910 _update(ctx
, e
, TYPE_SPECIFIER_IVEC3
);
911 } else if (id
== ctx
->dict
.ivec4
) {
912 _update(ctx
, e
, TYPE_SPECIFIER_IVEC4
);
913 } else if (id
== ctx
->dict
.mat2
) {
914 _update(ctx
, e
, TYPE_SPECIFIER_MAT2
);
915 } else if (id
== ctx
->dict
.mat3
) {
916 _update(ctx
, e
, TYPE_SPECIFIER_MAT3
);
917 } else if (id
== ctx
->dict
.mat4
) {
918 _update(ctx
, e
, TYPE_SPECIFIER_MAT4
);
919 } else if (id
== ctx
->dict
.mat2x3
) {
920 _update(ctx
, e
, TYPE_SPECIFIER_MAT23
);
921 } else if (id
== ctx
->dict
.mat3x2
) {
922 _update(ctx
, e
, TYPE_SPECIFIER_MAT32
);
923 } else if (id
== ctx
->dict
.mat2x4
) {
924 _update(ctx
, e
, TYPE_SPECIFIER_MAT24
);
925 } else if (id
== ctx
->dict
.mat4x2
) {
926 _update(ctx
, e
, TYPE_SPECIFIER_MAT42
);
927 } else if (id
== ctx
->dict
.mat3x4
) {
928 _update(ctx
, e
, TYPE_SPECIFIER_MAT34
);
929 } else if (id
== ctx
->dict
.mat4x3
) {
930 _update(ctx
, e
, TYPE_SPECIFIER_MAT43
);
931 } else if (id
== ctx
->dict
.sampler1D
) {
932 _update(ctx
, e
, TYPE_SPECIFIER_SAMPLER1D
);
933 } else if (id
== ctx
->dict
.sampler2D
) {
934 _update(ctx
, e
, TYPE_SPECIFIER_SAMPLER2D
);
935 } else if (id
== ctx
->dict
.sampler3D
) {
936 _update(ctx
, e
, TYPE_SPECIFIER_SAMPLER3D
);
937 } else if (id
== ctx
->dict
.samplerCube
) {
938 _update(ctx
, e
, TYPE_SPECIFIER_SAMPLERCUBE
);
939 } else if (id
== ctx
->dict
.sampler1DShadow
) {
940 _update(ctx
, e
, TYPE_SPECIFIER_SAMPLER1DSHADOW
);
941 } else if (id
== ctx
->dict
.sampler2DShadow
) {
942 _update(ctx
, e
, TYPE_SPECIFIER_SAMPLER2DSHADOW
);
943 } else if (id
== ctx
->dict
.sampler2DRect
) {
944 _update(ctx
, e
, TYPE_SPECIFIER_SAMPLER2DRECT
);
945 } else if (id
== ctx
->dict
.sampler2DRectShadow
) {
946 _update(ctx
, e
, TYPE_SPECIFIER_SAMPLER2DRECTSHADOW
);
947 } else if (_parse_identifier(ctx
, &p
) == 0) {
948 _update(ctx
, e
, TYPE_SPECIFIER_TYPENAME
);
955 _parse_token(ctx
, SL_PP_IDENTIFIER
, &p
);
962 _parse_type_specifier_array(struct parse_context
*ctx
,
963 struct parse_state
*ps
)
965 struct parse_state p
= *ps
;
967 if (_parse_token(ctx
, SL_PP_LBRACKET
, &p
)) {
970 if (_parse_constant_expression(ctx
, &p
)) {
971 _error(ctx
, "expected constant integral expression");
974 if (_parse_token(ctx
, SL_PP_RBRACKET
, &p
)) {
975 _error(ctx
, "expected `]'");
984 _parse_type_specifier(struct parse_context
*ctx
,
985 struct parse_state
*ps
)
987 struct parse_state p
= *ps
;
990 if (_parse_type_specifier_nonarray(ctx
, &p
)) {
994 e
= _emit(ctx
, &p
.out
, TYPE_SPECIFIER_ARRAY
);
995 if (_parse_type_specifier_array(ctx
, &p
)) {
996 _update(ctx
, e
, TYPE_SPECIFIER_NONARRAY
);
1004 _parse_fully_specified_type(struct parse_context
*ctx
,
1005 struct parse_state
*ps
)
1007 struct parse_state p
= *ps
;
1009 if (_parse_invariant_qualifier(ctx
, &p
)) {
1010 _emit(ctx
, &p
.out
, TYPE_VARIANT
);
1012 if (_parse_centroid_qualifier(ctx
, &p
)) {
1013 _emit(ctx
, &p
.out
, TYPE_CENTER
);
1015 if (_parse_type_qualifier(ctx
, &p
)) {
1016 _emit(ctx
, &p
.out
, TYPE_QUALIFIER_NONE
);
1018 if (_parse_precision(ctx
, &p
)) {
1019 _emit(ctx
, &p
.out
, PRECISION_DEFAULT
);
1021 if (_parse_type_specifier(ctx
, &p
)) {
1030 _parse_function_header(struct parse_context
*ctx
,
1031 struct parse_state
*ps
)
1033 struct parse_state p
= *ps
;
1035 if (_parse_fully_specified_type(ctx
, &p
)) {
1038 if (_parse_function_decl_identifier(ctx
, &p
)) {
1041 if (_parse_token(ctx
, SL_PP_LPAREN
, &p
)) {
1050 _parse_parameter_qualifier(struct parse_context
*ctx
,
1051 struct parse_state
*ps
)
1053 unsigned int e
= _emit(ctx
, &ps
->out
, PARAM_QUALIFIER_IN
);
1055 if (_parse_id(ctx
, ctx
->dict
.out
, ps
) == 0) {
1056 _update(ctx
, e
, PARAM_QUALIFIER_OUT
);
1057 } else if (_parse_id(ctx
, ctx
->dict
.inout
, ps
) == 0) {
1058 _update(ctx
, e
, PARAM_QUALIFIER_INOUT
);
1060 _parse_id(ctx
, ctx
->dict
.in
, ps
);
1067 _parse_function_identifier(struct parse_context
*ctx
,
1068 struct parse_state
*ps
)
1070 struct parse_state p
;
1073 if (_parse_identifier(ctx
, ps
)) {
1076 e
= _emit(ctx
, &ps
->out
, FUNCTION_CALL_NONARRAY
);
1079 if (_parse_token(ctx
, SL_PP_LBRACKET
, &p
)) {
1082 if (_parse_constant_expression(ctx
, &p
)) {
1083 _error(ctx
, "expected constant integral expression");
1086 if (_parse_token(ctx
, SL_PP_RBRACKET
, &p
)) {
1087 _error(ctx
, "expected `]'");
1090 _update(ctx
, e
, FUNCTION_CALL_ARRAY
);
1097 _parse_function_call_header(struct parse_context
*ctx
,
1098 struct parse_state
*ps
)
1100 struct parse_state p
= *ps
;
1102 if (_parse_function_identifier(ctx
, &p
)) {
1105 if (_parse_token(ctx
, SL_PP_LPAREN
, &p
)) {
1114 _parse_assign_expression(struct parse_context
*ctx
,
1115 struct parse_state
*ps
)
1117 struct parse_state p
= *ps
;
1120 if (_parse_unary_expression(ctx
, &p
)) {
1124 if (_parse_token(ctx
, SL_PP_ASSIGN
, &p
) == 0) {
1126 } else if (_parse_token(ctx
, SL_PP_MULASSIGN
, &p
) == 0) {
1128 } else if (_parse_token(ctx
, SL_PP_DIVASSIGN
, &p
) == 0) {
1130 } else if (_parse_token(ctx
, SL_PP_ADDASSIGN
, &p
) == 0) {
1132 } else if (_parse_token(ctx
, SL_PP_SUBASSIGN
, &p
) == 0) {
1138 if (_parse_assignment_expression(ctx
, &p
)) {
1141 _emit(ctx
, &p
.out
, op
);
1149 _parse_assignment_expression(struct parse_context
*ctx
,
1150 struct parse_state
*ps
)
1152 if (_parse_assign_expression(ctx
, ps
) == 0) {
1156 if (_parse_conditional_expression(ctx
, ps
) == 0) {
1165 _parse_function_call_header_with_parameters(struct parse_context
*ctx
,
1166 struct parse_state
*ps
)
1168 struct parse_state p
= *ps
;
1170 if (_parse_function_call_header(ctx
, &p
)) {
1173 if (_parse_assignment_expression(ctx
, &p
)) {
1176 _emit(ctx
, &p
.out
, OP_END
);
1179 if (_parse_token(ctx
, SL_PP_COMMA
, &p
)) {
1182 if (_parse_assignment_expression(ctx
, &p
)) {
1185 _emit(ctx
, &p
.out
, OP_END
);
1191 _parse_function_call_header_no_parameters(struct parse_context
*ctx
,
1192 struct parse_state
*ps
)
1194 if (_parse_function_call_header(ctx
, ps
)) {
1197 _parse_id(ctx
, ctx
->dict
._void
, ps
);
1203 _parse_function_call_generic(struct parse_context
*ctx
,
1204 struct parse_state
*ps
)
1206 struct parse_state p
= *ps
;
1208 if (_parse_function_call_header_with_parameters(ctx
, &p
) == 0) {
1209 if (_parse_token(ctx
, SL_PP_RPAREN
, &p
) == 0) {
1213 _error(ctx
, "expected `)'");
1218 if (_parse_function_call_header_no_parameters(ctx
, &p
) == 0) {
1219 if (_parse_token(ctx
, SL_PP_RPAREN
, &p
) == 0) {
1223 _error(ctx
, "expected `)'");
1232 _parse_method_call(struct parse_context
*ctx
,
1233 struct parse_state
*ps
)
1235 struct parse_state p
= *ps
;
1237 _emit(ctx
, &p
.out
, OP_METHOD
);
1238 if (_parse_identifier(ctx
, &p
)) {
1241 if (_parse_token(ctx
, SL_PP_DOT
, &p
)) {
1244 if (_parse_function_call_generic(ctx
, &p
)) {
1247 _emit(ctx
, &p
.out
, OP_END
);
1254 _parse_regular_function_call(struct parse_context
*ctx
,
1255 struct parse_state
*ps
)
1257 struct parse_state p
= *ps
;
1259 _emit(ctx
, &p
.out
, OP_CALL
);
1260 if (_parse_function_call_generic(ctx
, &p
)) {
1263 _emit(ctx
, &p
.out
, OP_END
);
1270 _parse_function_call(struct parse_context
*ctx
,
1271 struct parse_state
*ps
)
1273 if (_parse_regular_function_call(ctx
, ps
) == 0) {
1277 if (_parse_method_call(ctx
, ps
) == 0) {
1286 _parse_expression(struct parse_context
*ctx
,
1287 struct parse_state
*ps
)
1289 struct parse_state p
= *ps
;
1291 if (_parse_assignment_expression(ctx
, &p
)) {
1297 if (_parse_token(ctx
, SL_PP_COMMA
, &p
)) {
1300 if (_parse_assignment_expression(ctx
, &p
)) {
1303 _emit(ctx
, &p
.out
, OP_SEQUENCE
);
1309 _parse_postfix_expression(struct parse_context
*ctx
,
1310 struct parse_state
*ps
)
1312 struct parse_state p
;
1314 if (_parse_function_call(ctx
, ps
)) {
1315 if (_parse_primary_expression(ctx
, ps
)) {
1322 if (_parse_token(ctx
, SL_PP_INCREMENT
, &p
) == 0) {
1323 _emit(ctx
, &p
.out
, OP_POSTINCREMENT
);
1324 } else if (_parse_token(ctx
, SL_PP_DECREMENT
, &p
) == 0) {
1325 _emit(ctx
, &p
.out
, OP_POSTDECREMENT
);
1326 } else if (_parse_token(ctx
, SL_PP_LBRACKET
, &p
) == 0) {
1327 if (_parse_expression(ctx
, &p
)) {
1328 _error(ctx
, "expected an integral expression");
1331 if (_parse_token(ctx
, SL_PP_RBRACKET
, &p
)) {
1332 _error(ctx
, "expected `]'");
1335 _emit(ctx
, &p
.out
, OP_SUBSCRIPT
);
1336 } else if (_parse_token(ctx
, SL_PP_DOT
, &p
) == 0) {
1337 _emit(ctx
, &p
.out
, OP_FIELD
);
1338 if (_parse_identifier(ctx
, &p
)) {
1349 _parse_unary_expression(struct parse_context
*ctx
,
1350 struct parse_state
*ps
)
1352 struct parse_state p
;
1355 if (_parse_postfix_expression(ctx
, ps
) == 0) {
1360 if (_parse_token(ctx
, SL_PP_INCREMENT
, &p
) == 0) {
1361 op
= OP_PREINCREMENT
;
1362 } else if (_parse_token(ctx
, SL_PP_DECREMENT
, &p
) == 0) {
1363 op
= OP_PREDECREMENT
;
1364 } else if (_parse_token(ctx
, SL_PP_PLUS
, &p
) == 0) {
1366 } else if (_parse_token(ctx
, SL_PP_MINUS
, &p
) == 0) {
1368 } else if (_parse_token(ctx
, SL_PP_NOT
, &p
) == 0) {
1374 if (_parse_unary_expression(ctx
, &p
)) {
1377 _emit(ctx
, &p
.out
, op
);
1384 _parse_multiplicative_expression(struct parse_context
*ctx
,
1385 struct parse_state
*ps
)
1387 struct parse_state p
= *ps
;
1389 if (_parse_unary_expression(ctx
, &p
)) {
1396 if (_parse_token(ctx
, SL_PP_STAR
, &p
) == 0) {
1398 } else if (_parse_token(ctx
, SL_PP_SLASH
, &p
) == 0) {
1403 if (_parse_unary_expression(ctx
, &p
)) {
1406 _emit(ctx
, &p
.out
, op
);
1412 _parse_additive_expression(struct parse_context
*ctx
,
1413 struct parse_state
*ps
)
1415 struct parse_state p
= *ps
;
1417 if (_parse_multiplicative_expression(ctx
, &p
)) {
1424 if (_parse_token(ctx
, SL_PP_PLUS
, &p
) == 0) {
1426 } else if (_parse_token(ctx
, SL_PP_MINUS
, &p
) == 0) {
1431 if (_parse_multiplicative_expression(ctx
, &p
)) {
1434 _emit(ctx
, &p
.out
, op
);
1440 _parse_relational_expression(struct parse_context
*ctx
,
1441 struct parse_state
*ps
)
1443 struct parse_state p
= *ps
;
1445 if (_parse_additive_expression(ctx
, &p
)) {
1452 if (_parse_token(ctx
, SL_PP_LESS
, &p
) == 0) {
1454 } else if (_parse_token(ctx
, SL_PP_GREATER
, &p
) == 0) {
1456 } else if (_parse_token(ctx
, SL_PP_LESSEQUAL
, &p
) == 0) {
1458 } else if (_parse_token(ctx
, SL_PP_GREATEREQUAL
, &p
) == 0) {
1459 op
= OP_GREATEREQUAL
;
1463 if (_parse_additive_expression(ctx
, &p
)) {
1466 _emit(ctx
, &p
.out
, op
);
1472 _parse_equality_expression(struct parse_context
*ctx
,
1473 struct parse_state
*ps
)
1475 struct parse_state p
= *ps
;
1477 if (_parse_relational_expression(ctx
, &p
)) {
1484 if (_parse_token(ctx
, SL_PP_EQUAL
, &p
) == 0) {
1486 } else if (_parse_token(ctx
, SL_PP_NOTEQUAL
, &p
) == 0) {
1491 if (_parse_relational_expression(ctx
, &p
)) {
1494 _emit(ctx
, &p
.out
, op
);
1500 _parse_logical_and_expression(struct parse_context
*ctx
,
1501 struct parse_state
*ps
)
1503 struct parse_state p
= *ps
;
1505 if (_parse_equality_expression(ctx
, &p
)) {
1510 if (_parse_token(ctx
, SL_PP_AND
, &p
)) {
1513 if (_parse_equality_expression(ctx
, &p
)) {
1516 _emit(ctx
, &p
.out
, OP_LOGICALAND
);
1522 _parse_logical_xor_expression(struct parse_context
*ctx
,
1523 struct parse_state
*ps
)
1525 struct parse_state p
= *ps
;
1527 if (_parse_logical_and_expression(ctx
, &p
)) {
1532 if (_parse_token(ctx
, SL_PP_XOR
, &p
)) {
1535 if (_parse_logical_and_expression(ctx
, &p
)) {
1538 _emit(ctx
, &p
.out
, OP_LOGICALXOR
);
1544 _parse_logical_or_expression(struct parse_context
*ctx
,
1545 struct parse_state
*ps
)
1547 struct parse_state p
= *ps
;
1549 if (_parse_logical_xor_expression(ctx
, &p
)) {
1554 if (_parse_token(ctx
, SL_PP_OR
, &p
)) {
1557 if (_parse_logical_xor_expression(ctx
, &p
)) {
1560 _emit(ctx
, &p
.out
, OP_LOGICALOR
);
1566 _parse_conditional_expression(struct parse_context
*ctx
,
1567 struct parse_state
*ps
)
1569 struct parse_state p
= *ps
;
1571 if (_parse_logical_or_expression(ctx
, &p
)) {
1576 if (_parse_token(ctx
, SL_PP_QUESTION
, &p
)) {
1579 if (_parse_expression(ctx
, &p
)) {
1582 if (_parse_token(ctx
, SL_PP_COLON
, &p
)) {
1585 if (_parse_conditional_expression(ctx
, &p
)) {
1588 _emit(ctx
, &p
.out
, OP_SELECT
);
1594 _parse_constant_expression(struct parse_context
*ctx
,
1595 struct parse_state
*ps
)
1597 if (_parse_conditional_expression(ctx
, ps
)) {
1600 _emit(ctx
, &ps
->out
, OP_END
);
1606 _parse_parameter_declarator_array(struct parse_context
*ctx
,
1607 struct parse_state
*ps
)
1609 struct parse_state p
= *ps
;
1611 if (_parse_token(ctx
, SL_PP_LBRACKET
, &p
)) {
1614 if (_parse_constant_expression(ctx
, &p
)) {
1615 _error(ctx
, "expected constant integral expression");
1618 if (_parse_token(ctx
, SL_PP_RBRACKET
, &p
)) {
1619 _error(ctx
, "expected `]'");
1628 _parse_parameter_declarator(struct parse_context
*ctx
,
1629 struct parse_state
*ps
)
1631 struct parse_state p
= *ps
;
1634 if (_parse_type_specifier(ctx
, &p
)) {
1637 if (_parse_identifier(ctx
, &p
)) {
1640 e
= _emit(ctx
, &p
.out
, PARAMETER_ARRAY_PRESENT
);
1641 if (_parse_parameter_declarator_array(ctx
, &p
)) {
1642 _update(ctx
, e
, PARAMETER_ARRAY_NOT_PRESENT
);
1650 _parse_parameter_type_specifier_array(struct parse_context
*ctx
,
1651 struct parse_state
*ps
)
1653 struct parse_state p
= *ps
;
1655 if (_parse_token(ctx
, SL_PP_LBRACKET
, &p
)) {
1658 if (_parse_constant_expression(ctx
, &p
)) {
1659 _error(ctx
, "expected constant integral expression");
1662 if (_parse_token(ctx
, SL_PP_RBRACKET
, &p
)) {
1663 _error(ctx
, "expected `]'");
1672 _parse_parameter_type_specifier(struct parse_context
*ctx
,
1673 struct parse_state
*ps
)
1675 struct parse_state p
= *ps
;
1678 if (_parse_type_specifier(ctx
, &p
)) {
1681 _emit(ctx
, &p
.out
, '\0');
1683 e
= _emit(ctx
, &p
.out
, PARAMETER_ARRAY_PRESENT
);
1684 if (_parse_parameter_type_specifier_array(ctx
, &p
)) {
1685 _update(ctx
, e
, PARAMETER_ARRAY_NOT_PRESENT
);
1693 _parse_parameter_declaration(struct parse_context
*ctx
,
1694 struct parse_state
*ps
)
1696 struct parse_state p
= *ps
;
1697 unsigned int e
= _emit(ctx
, &p
.out
, PARAMETER_NEXT
);
1701 if (_parse_type_qualifier(ctx
, &p
)) {
1702 _emit(ctx
, &p
.out
, TYPE_QUALIFIER_NONE
);
1704 _parse_parameter_qualifier(ctx
, &p
);
1705 if (_parse_precision(ctx
, &p
)) {
1706 _emit(ctx
, &p
.out
, PRECISION_DEFAULT
);
1708 if (_parse_parameter_declarator(ctx
, &p
) == 0) {
1712 if (_parse_parameter_type_specifier(ctx
, &p
) == 0) {
1722 _parse_function_header_with_parameters(struct parse_context
*ctx
,
1723 struct parse_state
*ps
)
1725 struct parse_state p
= *ps
;
1727 if (_parse_function_header(ctx
, &p
)) {
1730 if (_parse_parameter_declaration(ctx
, &p
)) {
1736 if (_parse_token(ctx
, SL_PP_COMMA
, &p
)) {
1739 if (_parse_parameter_declaration(ctx
, &p
)) {
1747 _parse_function_declarator(struct parse_context
*ctx
,
1748 struct parse_state
*ps
)
1750 if (_parse_function_header_with_parameters(ctx
, ps
) == 0) {
1754 if (_parse_function_header(ctx
, ps
) == 0) {
1763 _parse_function_prototype(struct parse_context
*ctx
,
1764 struct parse_state
*ps
)
1766 struct parse_state p
= *ps
;
1768 if (_parse_function_header(ctx
, &p
) == 0) {
1769 if (_parse_id(ctx
, ctx
->dict
._void
, &p
) == 0) {
1770 if (_parse_token(ctx
, SL_PP_RPAREN
, &p
) == 0) {
1771 _emit(ctx
, &p
.out
, PARAMETER_NONE
);
1775 _error(ctx
, "expected `)'");
1781 if (_parse_function_declarator(ctx
, &p
) == 0) {
1782 if (_parse_token(ctx
, SL_PP_RPAREN
, &p
) == 0) {
1783 _emit(ctx
, &p
.out
, PARAMETER_NONE
);
1787 _error(ctx
, "expected `)'");
1796 _parse_precision(struct parse_context
*ctx
,
1797 struct parse_state
*ps
)
1799 const struct sl_pp_token_info
*input
= _fetch_token(ctx
, ps
->in
);
1801 unsigned int precision
;
1803 if (!input
|| input
->token
!= SL_PP_IDENTIFIER
) {
1806 id
= input
->data
.identifier
;
1808 if (id
== ctx
->dict
.lowp
) {
1809 precision
= PRECISION_LOW
;
1810 } else if (id
== ctx
->dict
.mediump
) {
1811 precision
= PRECISION_MEDIUM
;
1812 } else if (id
== ctx
->dict
.highp
) {
1813 precision
= PRECISION_HIGH
;
1818 _parse_token(ctx
, SL_PP_IDENTIFIER
, ps
);
1819 _emit(ctx
, &ps
->out
, precision
);
1825 _parse_prectype(struct parse_context
*ctx
,
1826 struct parse_state
*ps
)
1828 const struct sl_pp_token_info
*input
= _fetch_token(ctx
, ps
->in
);
1832 if (!input
|| input
->token
!= SL_PP_IDENTIFIER
) {
1835 id
= input
->data
.identifier
;
1837 if (id
== ctx
->dict
._int
) {
1838 type
= TYPE_SPECIFIER_INT
;
1839 } else if (id
== ctx
->dict
._float
) {
1840 type
= TYPE_SPECIFIER_FLOAT
;
1841 } else if (id
== ctx
->dict
.sampler1D
) {
1842 type
= TYPE_SPECIFIER_SAMPLER1D
;
1843 } else if (id
== ctx
->dict
.sampler2D
) {
1844 type
= TYPE_SPECIFIER_SAMPLER2D
;
1845 } else if (id
== ctx
->dict
.sampler3D
) {
1846 type
= TYPE_SPECIFIER_SAMPLER3D
;
1847 } else if (id
== ctx
->dict
.samplerCube
) {
1848 type
= TYPE_SPECIFIER_SAMPLERCUBE
;
1849 } else if (id
== ctx
->dict
.sampler1DShadow
) {
1850 type
= TYPE_SPECIFIER_SAMPLER1DSHADOW
;
1851 } else if (id
== ctx
->dict
.sampler2DShadow
) {
1852 type
= TYPE_SPECIFIER_SAMPLER2DSHADOW
;
1853 } else if (id
== ctx
->dict
.sampler2DRect
) {
1854 type
= TYPE_SPECIFIER_SAMPLER2DRECT
;
1855 } else if (id
== ctx
->dict
.sampler2DRectShadow
) {
1856 type
= TYPE_SPECIFIER_SAMPLER2DRECTSHADOW
;
1861 _parse_token(ctx
, SL_PP_IDENTIFIER
, ps
);
1862 _emit(ctx
, &ps
->out
, type
);
1868 _parse_precision_stmt(struct parse_context
*ctx
,
1869 struct parse_state
*ps
)
1871 struct parse_state p
= *ps
;
1873 if (_parse_id(ctx
, ctx
->dict
.precision
, &p
)) {
1876 if (_parse_precision(ctx
, &p
)) {
1879 if (_parse_prectype(ctx
, &p
)) {
1882 if (_parse_token(ctx
, SL_PP_SEMICOLON
, &p
)) {
1891 _parse_floatconstant(struct parse_context
*ctx
,
1892 struct parse_state
*ps
)
1894 struct parse_state p
= *ps
;
1896 _emit(ctx
, &p
.out
, OP_PUSH_FLOAT
);
1897 if (_parse_float(ctx
, &p
)) {
1906 _parse_intconstant(struct parse_context
*ctx
,
1907 struct parse_state
*ps
)
1909 struct parse_state p
= *ps
;
1911 _emit(ctx
, &p
.out
, OP_PUSH_INT
);
1912 if (_parse_uint(ctx
, &p
)) {
1921 _parse_boolconstant(struct parse_context
*ctx
,
1922 struct parse_state
*ps
)
1924 if (_parse_id(ctx
, ctx
->dict
._false
, ps
) == 0) {
1925 _emit(ctx
, &ps
->out
, OP_PUSH_BOOL
);
1926 _emit(ctx
, &ps
->out
, 2); /* radix */
1927 _emit(ctx
, &ps
->out
, '0');
1928 _emit(ctx
, &ps
->out
, '\0');
1932 if (_parse_id(ctx
, ctx
->dict
._true
, ps
) == 0) {
1933 _emit(ctx
, &ps
->out
, OP_PUSH_BOOL
);
1934 _emit(ctx
, &ps
->out
, 2); /* radix */
1935 _emit(ctx
, &ps
->out
, '1');
1936 _emit(ctx
, &ps
->out
, '\0');
1945 _parse_variable_identifier(struct parse_context
*ctx
,
1946 struct parse_state
*ps
)
1948 struct parse_state p
= *ps
;
1950 _emit(ctx
, &p
.out
, OP_PUSH_IDENTIFIER
);
1951 if (_parse_identifier(ctx
, &p
)) {
1960 _parse_primary_expression(struct parse_context
*ctx
,
1961 struct parse_state
*ps
)
1963 struct parse_state p
;
1965 if (_parse_floatconstant(ctx
, ps
) == 0) {
1968 if (_parse_boolconstant(ctx
, ps
) == 0) {
1971 if (_parse_intconstant(ctx
, ps
) == 0) {
1974 if (_parse_variable_identifier(ctx
, ps
) == 0) {
1979 if (_parse_token(ctx
, SL_PP_LPAREN
, &p
)) {
1982 if (_parse_expression(ctx
, &p
)) {
1985 if (_parse_token(ctx
, SL_PP_RPAREN
, &p
)) {
1995 _parse_asm_argument(struct parse_context
*ctx
,
1996 struct parse_state
*ps
)
1998 if (_parse_variable_identifier(ctx
, ps
) == 0) {
1999 struct parse_state p
= *ps
;
2001 if (_parse_token(ctx
, SL_PP_DOT
, &p
)) {
2004 _emit(ctx
, &p
.out
, OP_FIELD
);
2005 if (_parse_identifier(ctx
, &p
)) {
2012 if (_parse_floatconstant(ctx
, ps
) == 0) {
2021 _parse_asm_arguments(struct parse_context
*ctx
,
2022 struct parse_state
*ps
)
2024 struct parse_state p
= *ps
;
2026 if (_parse_asm_argument(ctx
, &p
)) {
2029 _emit(ctx
, &p
.out
, OP_END
);
2033 if (_parse_token(ctx
, SL_PP_COMMA
, &p
)) {
2036 if (_parse_asm_argument(ctx
, &p
)) {
2039 _emit(ctx
, &p
.out
, OP_END
);
2045 _parse_asm_statement(struct parse_context
*ctx
,
2046 struct parse_state
*ps
)
2048 struct parse_state p
= *ps
;
2050 if (_parse_id(ctx
, ctx
->dict
.___asm
, &p
)) {
2053 if (_parse_identifier(ctx
, &p
)) {
2056 if (_parse_asm_arguments(ctx
, &p
)) {
2059 if (_parse_token(ctx
, SL_PP_SEMICOLON
, &p
)) {
2062 _emit(ctx
, &p
.out
, OP_END
);
2069 _parse_selection_statement(struct parse_context
*ctx
,
2070 struct parse_state
*ps
)
2072 struct parse_state p
= *ps
;
2074 _emit(ctx
, &p
.out
, OP_IF
);
2075 if (_parse_id(ctx
, ctx
->dict
._if
, &p
)) {
2078 if (_parse_token(ctx
, SL_PP_LPAREN
, &p
)) {
2079 _error(ctx
, "expected `('");
2082 if (_parse_expression(ctx
, &p
)) {
2083 _error(ctx
, "expected an expression");
2086 if (_parse_token(ctx
, SL_PP_RPAREN
, &p
)) {
2087 _error(ctx
, "expected `)'");
2090 _emit(ctx
, &p
.out
, OP_END
);
2091 if (_parse_statement(ctx
, &p
)) {
2096 if (_parse_id(ctx
, ctx
->dict
._else
, &p
) == 0) {
2097 if (_parse_statement(ctx
, &p
) == 0) {
2103 _emit(ctx
, &ps
->out
, OP_EXPRESSION
);
2104 _emit(ctx
, &ps
->out
, OP_PUSH_VOID
);
2105 _emit(ctx
, &ps
->out
, OP_END
);
2111 _parse_expression_statement(struct parse_context
*ctx
,
2112 struct parse_state
*ps
)
2114 struct parse_state p
= *ps
;
2116 if (_parse_expression(ctx
, &p
)) {
2117 _emit(ctx
, &p
.out
, OP_PUSH_VOID
);
2119 if (_parse_token(ctx
, SL_PP_SEMICOLON
, &p
)) {
2122 _emit(ctx
, &p
.out
, OP_END
);
2129 _parse_for_init_statement(struct parse_context
*ctx
,
2130 struct parse_state
*ps
)
2132 struct parse_state p
= *ps
;
2133 unsigned int e
= _emit(ctx
, &p
.out
, OP_EXPRESSION
);
2135 if (_parse_expression_statement(ctx
, &p
) == 0) {
2140 if (_parse_declaration(ctx
, &p
) == 0) {
2141 _update(ctx
, e
, OP_DECLARE
);
2151 _parse_initializer(struct parse_context
*ctx
,
2152 struct parse_state
*ps
)
2154 if (_parse_assignment_expression(ctx
, ps
) == 0) {
2155 _emit(ctx
, &ps
->out
, OP_END
);
2163 _parse_condition_initializer(struct parse_context
*ctx
,
2164 struct parse_state
*ps
)
2166 struct parse_state p
= *ps
;
2168 _emit(ctx
, &p
.out
, OP_DECLARE
);
2169 _emit(ctx
, &p
.out
, DECLARATION_INIT_DECLARATOR_LIST
);
2170 if (_parse_fully_specified_type(ctx
, &p
)) {
2173 _emit(ctx
, &p
.out
, VARIABLE_IDENTIFIER
);
2174 if (_parse_identifier(ctx
, &p
)) {
2177 if (_parse_token(ctx
, SL_PP_ASSIGN
, &p
)) {
2178 _error(ctx
, "expected `='");
2181 _emit(ctx
, &p
.out
, VARIABLE_INITIALIZER
);
2182 if (_parse_initializer(ctx
, &p
)) {
2183 _error(ctx
, "expected an initialiser");
2186 _emit(ctx
, &p
.out
, DECLARATOR_NONE
);
2193 _parse_condition(struct parse_context
*ctx
,
2194 struct parse_state
*ps
)
2196 struct parse_state p
;
2198 if (_parse_condition_initializer(ctx
, ps
) == 0) {
2203 _emit(ctx
, &p
.out
, OP_EXPRESSION
);
2204 if (_parse_expression(ctx
, &p
) == 0) {
2205 _emit(ctx
, &p
.out
, OP_END
);
2215 _parse_for_rest_statement(struct parse_context
*ctx
,
2216 struct parse_state
*ps
)
2218 struct parse_state p
= *ps
;
2220 if (_parse_condition(ctx
, &p
)) {
2221 _emit(ctx
, &p
.out
, OP_EXPRESSION
);
2222 _emit(ctx
, &p
.out
, OP_PUSH_BOOL
);
2223 _emit(ctx
, &p
.out
, 2);
2224 _emit(ctx
, &p
.out
, '1');
2225 _emit(ctx
, &p
.out
, '\0');
2226 _emit(ctx
, &p
.out
, OP_END
);
2228 if (_parse_token(ctx
, SL_PP_SEMICOLON
, &p
)) {
2231 if (_parse_expression(ctx
, &p
)) {
2232 _emit(ctx
, &p
.out
, OP_PUSH_VOID
);
2234 _emit(ctx
, &p
.out
, OP_END
);
2241 _parse_iteration_statement(struct parse_context
*ctx
,
2242 struct parse_state
*ps
)
2244 struct parse_state p
= *ps
;
2246 if (_parse_id(ctx
, ctx
->dict
._while
, &p
) == 0) {
2247 _emit(ctx
, &p
.out
, OP_WHILE
);
2248 if (_parse_token(ctx
, SL_PP_LPAREN
, &p
)) {
2249 _error(ctx
, "expected `('");
2252 if (_parse_condition(ctx
, &p
)) {
2253 _error(ctx
, "expected an expression");
2256 if (_parse_token(ctx
, SL_PP_RPAREN
, &p
)) {
2257 _error(ctx
, "expected `)'");
2260 if (_parse_statement(ctx
, &p
)) {
2267 if (_parse_id(ctx
, ctx
->dict
._do
, &p
) == 0) {
2268 _emit(ctx
, &p
.out
, OP_DO
);
2269 if (_parse_statement(ctx
, &p
)) {
2272 if (_parse_id(ctx
, ctx
->dict
._while
, &p
)) {
2275 if (_parse_token(ctx
, SL_PP_LPAREN
, &p
)) {
2276 _error(ctx
, "expected `('");
2279 if (_parse_expression(ctx
, &p
)) {
2280 _error(ctx
, "expected an expression");
2283 if (_parse_token(ctx
, SL_PP_RPAREN
, &p
)) {
2284 _error(ctx
, "expected `)'");
2287 _emit(ctx
, &p
.out
, OP_END
);
2288 if (_parse_token(ctx
, SL_PP_SEMICOLON
, &p
)) {
2289 _error(ctx
, "expected `;'");
2296 if (_parse_id(ctx
, ctx
->dict
._for
, &p
) == 0) {
2297 _emit(ctx
, &p
.out
, OP_FOR
);
2298 if (_parse_token(ctx
, SL_PP_LPAREN
, &p
)) {
2299 _error(ctx
, "expected `('");
2302 if (_parse_for_init_statement(ctx
, &p
)) {
2305 if (_parse_for_rest_statement(ctx
, &p
)) {
2308 if (_parse_token(ctx
, SL_PP_RPAREN
, &p
)) {
2309 _error(ctx
, "expected `)'");
2312 if (_parse_statement(ctx
, &p
)) {
2324 _parse_jump_statement(struct parse_context
*ctx
,
2325 struct parse_state
*ps
)
2327 struct parse_state p
= *ps
;
2328 unsigned int e
= _emit(ctx
, &p
.out
, 0);
2330 if (_parse_id(ctx
, ctx
->dict
._continue
, &p
) == 0) {
2331 _update(ctx
, e
, OP_CONTINUE
);
2332 } else if (_parse_id(ctx
, ctx
->dict
._break
, &p
) == 0) {
2333 _update(ctx
, e
, OP_BREAK
);
2334 } else if (_parse_id(ctx
, ctx
->dict
._return
, &p
) == 0) {
2335 _update(ctx
, e
, OP_RETURN
);
2336 if (_parse_expression(ctx
, &p
)) {
2337 _emit(ctx
, &p
.out
, OP_PUSH_VOID
);
2339 _emit(ctx
, &p
.out
, OP_END
);
2340 } else if (ctx
->shader_type
== 1 && _parse_id(ctx
, ctx
->dict
.discard
, &p
) == 0) {
2341 _update(ctx
, e
, OP_DISCARD
);
2345 if (_parse_token(ctx
, SL_PP_SEMICOLON
, &p
)) {
2354 _parse_simple_statement(struct parse_context
*ctx
,
2355 struct parse_state
*ps
)
2357 struct parse_state p
;
2360 if (_parse_selection_statement(ctx
, ps
) == 0) {
2364 if (_parse_iteration_statement(ctx
, ps
) == 0) {
2368 if (_parse_jump_statement(ctx
, ps
) == 0) {
2373 e
= _emit(ctx
, &p
.out
, OP_EXPRESSION
);
2374 if (_parse_expression_statement(ctx
, &p
) == 0) {
2379 if (_parse_precision_stmt(ctx
, &p
) == 0) {
2380 _update(ctx
, e
, OP_PRECISION
);
2385 if (ctx
->parsing_builtin
&& _parse_asm_statement(ctx
, &p
) == 0) {
2386 _update(ctx
, e
, OP_ASM
);
2391 if (_parse_declaration(ctx
, &p
) == 0) {
2392 _update(ctx
, e
, OP_DECLARE
);
2402 _parse_compound_statement(struct parse_context
*ctx
,
2403 struct parse_state
*ps
)
2405 struct parse_state p
= *ps
;
2407 if (_parse_token(ctx
, SL_PP_LBRACE
, &p
)) {
2410 _emit(ctx
, &p
.out
, OP_BLOCK_BEGIN_NEW_SCOPE
);
2411 _parse_statement_list(ctx
, &p
);
2412 if (_parse_token(ctx
, SL_PP_RBRACE
, &p
)) {
2415 _emit(ctx
, &p
.out
, OP_END
);
2422 _parse_statement(struct parse_context
*ctx
,
2423 struct parse_state
*ps
)
2425 if (_parse_compound_statement(ctx
, ps
) == 0) {
2429 if (_parse_simple_statement(ctx
, ps
) == 0) {
2438 _parse_statement_list(struct parse_context
*ctx
,
2439 struct parse_state
*ps
)
2441 struct parse_state p
= *ps
;
2443 if (_parse_statement(ctx
, &p
)) {
2449 if (_parse_statement(ctx
, &p
)) {
2457 _parse_compound_statement_no_new_scope(struct parse_context
*ctx
,
2458 struct parse_state
*ps
)
2460 struct parse_state p
= *ps
;
2462 if (_parse_token(ctx
, SL_PP_LBRACE
, &p
)) {
2465 _emit(ctx
, &p
.out
, OP_BLOCK_BEGIN_NO_NEW_SCOPE
);
2466 _parse_statement_list(ctx
, &p
);
2467 if (_parse_token(ctx
, SL_PP_RBRACE
, &p
)) {
2470 _emit(ctx
, &p
.out
, OP_END
);
2477 _parse_function_definition(struct parse_context
*ctx
,
2478 struct parse_state
*ps
)
2480 struct parse_state p
= *ps
;
2482 if (_parse_function_prototype(ctx
, &p
)) {
2485 if (_parse_compound_statement_no_new_scope(ctx
, &p
)) {
2494 _parse_invariant_stmt(struct parse_context
*ctx
,
2495 struct parse_state
*ps
)
2497 struct parse_state p
= *ps
;
2499 if (_parse_id(ctx
, ctx
->dict
.invariant
, &p
)) {
2502 if (_parse_identifier(ctx
, &p
)) {
2505 if (_parse_token(ctx
, SL_PP_SEMICOLON
, &p
)) {
2514 _parse_single_declaration(struct parse_context
*ctx
,
2515 struct parse_state
*ps
)
2517 struct parse_state p
= *ps
;
2520 if (_parse_fully_specified_type(ctx
, &p
)) {
2524 e
= _emit(ctx
, &p
.out
, VARIABLE_IDENTIFIER
);
2525 if (_parse_identifier(ctx
, &p
)) {
2526 _update(ctx
, e
, VARIABLE_NONE
);
2531 e
= _emit(ctx
, &p
.out
, VARIABLE_NONE
);
2534 if (_parse_token(ctx
, SL_PP_ASSIGN
, &p
) == 0) {
2535 _update(ctx
, e
, VARIABLE_INITIALIZER
);
2536 if (_parse_initializer(ctx
, &p
) == 0) {
2540 _error(ctx
, "expected an initialiser");
2545 if (_parse_token(ctx
, SL_PP_LBRACKET
, &p
) == 0) {
2546 if (_parse_constant_expression(ctx
, &p
)) {
2547 _update(ctx
, e
, VARIABLE_ARRAY_UNKNOWN
);
2549 _update(ctx
, e
, VARIABLE_ARRAY_EXPLICIT
);
2551 if (_parse_token(ctx
, SL_PP_RBRACKET
, &p
) == 0) {
2555 _error(ctx
, "expected `]'");
2563 _parse_init_declarator_list(struct parse_context
*ctx
,
2564 struct parse_state
*ps
)
2566 struct parse_state p
= *ps
;
2568 if (_parse_single_declaration(ctx
, &p
)) {
2576 if (_parse_token(ctx
, SL_PP_COMMA
, &p
)) {
2579 _emit(ctx
, &p
.out
, DECLARATOR_NEXT
);
2580 _emit(ctx
, &p
.out
, VARIABLE_IDENTIFIER
);
2581 if (_parse_identifier(ctx
, &p
)) {
2585 e
= _emit(ctx
, &p
.out
, VARIABLE_NONE
);
2588 if (_parse_token(ctx
, SL_PP_ASSIGN
, &p
) == 0) {
2589 if (_parse_initializer(ctx
, &p
) == 0) {
2590 _update(ctx
, e
, VARIABLE_INITIALIZER
);
2594 _error(ctx
, "expected an initialiser");
2599 if (_parse_token(ctx
, SL_PP_LBRACKET
, &p
) == 0) {
2602 if (_parse_constant_expression(ctx
, &p
)) {
2603 arr
= VARIABLE_ARRAY_UNKNOWN
;
2605 arr
= VARIABLE_ARRAY_EXPLICIT
;
2607 if (_parse_token(ctx
, SL_PP_RBRACKET
, &p
) == 0) {
2608 _update(ctx
, e
, arr
);
2612 _error(ctx
, "expected `]'");
2618 _emit(ctx
, &ps
->out
, DECLARATOR_NONE
);
2624 _parse_declaration(struct parse_context
*ctx
,
2625 struct parse_state
*ps
)
2627 struct parse_state p
= *ps
;
2628 unsigned int e
= _emit(ctx
, &p
.out
, DECLARATION_FUNCTION_PROTOTYPE
);
2630 if (_parse_function_prototype(ctx
, &p
)) {
2631 if (_parse_init_declarator_list(ctx
, &p
)) {
2634 _update(ctx
, e
, DECLARATION_INIT_DECLARATOR_LIST
);
2636 if (_parse_token(ctx
, SL_PP_SEMICOLON
, &p
)) {
2637 _error(ctx
, "expected `;'");
2646 _parse_external_declaration(struct parse_context
*ctx
,
2647 struct parse_state
*ps
)
2649 struct parse_state p
= *ps
;
2650 unsigned int e
= _emit(ctx
, &p
.out
, 0);
2652 if (_parse_precision_stmt(ctx
, &p
) == 0) {
2653 _update(ctx
, e
, DEFAULT_PRECISION
);
2658 if (_parse_function_definition(ctx
, &p
) == 0) {
2659 _update(ctx
, e
, EXTERNAL_FUNCTION_DEFINITION
);
2664 if (_parse_invariant_stmt(ctx
, &p
) == 0) {
2665 _update(ctx
, e
, INVARIANT_STMT
);
2670 if (_parse_declaration(ctx
, &p
) == 0) {
2671 _update(ctx
, e
, EXTERNAL_DECLARATION
);
2676 _error(ctx
, "expected an identifier");
2682 _parse_translation_unit(struct parse_context
*ctx
,
2683 struct parse_state
*ps
)
2685 _emit(ctx
, &ps
->out
, REVISION
);
2686 if (_parse_external_declaration(ctx
, ps
)) {
2689 while (_parse_external_declaration(ctx
, ps
) == 0) {
2691 _emit(ctx
, &ps
->out
, EXTERNAL_NULL
);
2692 if (_parse_token(ctx
, SL_PP_EOF
, ps
)) {
2699 #define ADD_NAME_STR(CTX, NAME, STR)\
2701 (CTX).dict.NAME = sl_pp_context_add_unique_str((CTX).context, (STR));\
2702 if ((CTX).dict.NAME == -1) {\
2707 #define ADD_NAME(CTX, NAME) ADD_NAME_STR(CTX, NAME, #NAME)
2711 sl_cl_compile(struct sl_pp_context
*context
,
2712 unsigned int shader_type
,
2713 unsigned int parsing_builtin
,
2714 unsigned char **output
,
2715 unsigned int *cboutput
,
2717 unsigned int cberror
)
2719 struct parse_context ctx
;
2720 struct parse_state ps
;
2722 ctx
.context
= context
;
2724 ADD_NAME_STR(ctx
, _void
, "void");
2725 ADD_NAME_STR(ctx
, _float
, "float");
2726 ADD_NAME_STR(ctx
, _int
, "int");
2727 ADD_NAME_STR(ctx
, _bool
, "bool");
2728 ADD_NAME(ctx
, vec2
);
2729 ADD_NAME(ctx
, vec3
);
2730 ADD_NAME(ctx
, vec4
);
2731 ADD_NAME(ctx
, bvec2
);
2732 ADD_NAME(ctx
, bvec3
);
2733 ADD_NAME(ctx
, bvec4
);
2734 ADD_NAME(ctx
, ivec2
);
2735 ADD_NAME(ctx
, ivec3
);
2736 ADD_NAME(ctx
, ivec4
);
2737 ADD_NAME(ctx
, mat2
);
2738 ADD_NAME(ctx
, mat3
);
2739 ADD_NAME(ctx
, mat4
);
2740 ADD_NAME(ctx
, mat2x3
);
2741 ADD_NAME(ctx
, mat3x2
);
2742 ADD_NAME(ctx
, mat2x4
);
2743 ADD_NAME(ctx
, mat4x2
);
2744 ADD_NAME(ctx
, mat3x4
);
2745 ADD_NAME(ctx
, mat4x3
);
2746 ADD_NAME(ctx
, sampler1D
);
2747 ADD_NAME(ctx
, sampler2D
);
2748 ADD_NAME(ctx
, sampler3D
);
2749 ADD_NAME(ctx
, samplerCube
);
2750 ADD_NAME(ctx
, sampler1DShadow
);
2751 ADD_NAME(ctx
, sampler2DShadow
);
2752 ADD_NAME(ctx
, sampler2DRect
);
2753 ADD_NAME(ctx
, sampler2DRectShadow
);
2755 ADD_NAME(ctx
, invariant
);
2757 ADD_NAME(ctx
, centroid
);
2759 ADD_NAME(ctx
, precision
);
2760 ADD_NAME(ctx
, lowp
);
2761 ADD_NAME(ctx
, mediump
);
2762 ADD_NAME(ctx
, highp
);
2764 ADD_NAME_STR(ctx
, _const
, "const");
2765 ADD_NAME(ctx
, attribute
);
2766 ADD_NAME(ctx
, varying
);
2767 ADD_NAME(ctx
, uniform
);
2768 ADD_NAME(ctx
, __fixed_output
);
2769 ADD_NAME(ctx
, __fixed_input
);
2773 ADD_NAME(ctx
, inout
);
2775 ADD_NAME_STR(ctx
, _struct
, "struct");
2777 ADD_NAME(ctx
, __constructor
);
2778 ADD_NAME(ctx
, __operator
);
2779 ADD_NAME_STR(ctx
, ___asm
, "__asm");
2781 ADD_NAME_STR(ctx
, _if
, "if");
2782 ADD_NAME_STR(ctx
, _else
, "else");
2783 ADD_NAME_STR(ctx
, _for
, "for");
2784 ADD_NAME_STR(ctx
, _while
, "while");
2785 ADD_NAME_STR(ctx
, _do
, "do");
2787 ADD_NAME_STR(ctx
, _continue
, "continue");
2788 ADD_NAME_STR(ctx
, _break
, "break");
2789 ADD_NAME_STR(ctx
, _return
, "return");
2790 ADD_NAME(ctx
, discard
);
2792 ADD_NAME_STR(ctx
, _false
, "false");
2793 ADD_NAME_STR(ctx
, _true
, "true");
2798 ctx
.shader_type
= shader_type
;
2799 ctx
.parsing_builtin
= 1;
2801 ctx
.error
[0] = '\0';
2802 ctx
.process_error
= 0;
2804 ctx
.tokens_cap
= 1024;
2805 ctx
.tokens_read
= 0;
2806 ctx
.tokens
= malloc(ctx
.tokens_cap
* sizeof(struct sl_pp_token_info
));
2808 strncpy(error
, "out of memory", cberror
);
2815 if (_parse_translation_unit(&ctx
, &ps
)) {
2816 strncpy(error
, ctx
.error
, cberror
);
2821 *output
= ctx
.out_buf
;