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
123 /* layout qualifiers */
124 #define LAYOUT_QUALIFIER_NONE 0
125 #define LAYOUT_QUALIFIER_UPPER_LEFT 1
126 #define LAYOUT_QUALIFIER_PIXEL_CENTER_INTEGER 2
129 #define TYPE_SPECIFIER_VOID 0
130 #define TYPE_SPECIFIER_BOOL 1
131 #define TYPE_SPECIFIER_BVEC2 2
132 #define TYPE_SPECIFIER_BVEC3 3
133 #define TYPE_SPECIFIER_BVEC4 4
134 #define TYPE_SPECIFIER_INT 5
135 #define TYPE_SPECIFIER_IVEC2 6
136 #define TYPE_SPECIFIER_IVEC3 7
137 #define TYPE_SPECIFIER_IVEC4 8
138 #define TYPE_SPECIFIER_FLOAT 9
139 #define TYPE_SPECIFIER_VEC2 10
140 #define TYPE_SPECIFIER_VEC3 11
141 #define TYPE_SPECIFIER_VEC4 12
142 #define TYPE_SPECIFIER_MAT2 13
143 #define TYPE_SPECIFIER_MAT3 14
144 #define TYPE_SPECIFIER_MAT4 15
145 #define TYPE_SPECIFIER_SAMPLER1D 16
146 #define TYPE_SPECIFIER_SAMPLER2D 17
147 #define TYPE_SPECIFIER_SAMPLER3D 18
148 #define TYPE_SPECIFIER_SAMPLERCUBE 19
149 #define TYPE_SPECIFIER_SAMPLER1DSHADOW 20
150 #define TYPE_SPECIFIER_SAMPLER2DSHADOW 21
151 #define TYPE_SPECIFIER_SAMPLER2DRECT 22
152 #define TYPE_SPECIFIER_SAMPLER2DRECTSHADOW 23
153 #define TYPE_SPECIFIER_STRUCT 24
154 #define TYPE_SPECIFIER_TYPENAME 25
157 #define TYPE_SPECIFIER_MAT23 26
158 #define TYPE_SPECIFIER_MAT32 27
159 #define TYPE_SPECIFIER_MAT24 28
160 #define TYPE_SPECIFIER_MAT42 29
161 #define TYPE_SPECIFIER_MAT34 30
162 #define TYPE_SPECIFIER_MAT43 31
164 /* type specifier array */
165 #define TYPE_SPECIFIER_NONARRAY 0
166 #define TYPE_SPECIFIER_ARRAY 1
168 /* structure field */
171 #define FIELD_ARRAY 2
175 #define OP_BLOCK_BEGIN_NO_NEW_SCOPE 1
176 #define OP_BLOCK_BEGIN_NEW_SCOPE 2
180 #define OP_CONTINUE 6
183 #define OP_EXPRESSION 9
188 #define OP_PUSH_VOID 14
189 #define OP_PUSH_BOOL 15
190 #define OP_PUSH_INT 16
191 #define OP_PUSH_FLOAT 17
192 #define OP_PUSH_IDENTIFIER 18
193 #define OP_SEQUENCE 19
195 #define OP_ADDASSIGN 21
196 #define OP_SUBASSIGN 22
197 #define OP_MULASSIGN 23
198 #define OP_DIVASSIGN 24
199 /*#define OP_MODASSIGN 25*/
200 /*#define OP_LSHASSIGN 26*/
201 /*#define OP_RSHASSIGN 27*/
202 /*#define OP_ORASSIGN 28*/
203 /*#define OP_XORASSIGN 29*/
204 /*#define OP_ANDASSIGN 30*/
206 #define OP_LOGICALOR 32
207 #define OP_LOGICALXOR 33
208 #define OP_LOGICALAND 34
209 /*#define OP_BITOR 35*/
210 /*#define OP_BITXOR 36*/
211 /*#define OP_BITAND 37*/
213 #define OP_NOTEQUAL 39
215 #define OP_GREATER 41
216 #define OP_LESSEQUAL 42
217 #define OP_GREATEREQUAL 43
218 /*#define OP_LSHIFT 44*/
219 /*#define OP_RSHIFT 45*/
221 #define OP_SUBTRACT 47
222 #define OP_MULTIPLY 48
224 /*#define OP_MODULUS 50*/
225 #define OP_PREINCREMENT 51
226 #define OP_PREDECREMENT 52
229 /*#define OP_COMPLEMENT 55*/
231 #define OP_SUBSCRIPT 57
234 #define OP_POSTINCREMENT 60
235 #define OP_POSTDECREMENT 61
236 #define OP_PRECISION 62
239 /* parameter qualifier */
240 #define PARAM_QUALIFIER_IN 0
241 #define PARAM_QUALIFIER_OUT 1
242 #define PARAM_QUALIFIER_INOUT 2
244 /* function parameter */
245 #define PARAMETER_NONE 0
246 #define PARAMETER_NEXT 1
248 /* function parameter array presence */
249 #define PARAMETER_ARRAY_NOT_PRESENT 0
250 #define PARAMETER_ARRAY_PRESENT 1
283 int sampler2DRectShadow
;
306 int origin_upper_left
;
307 int pixel_center_integer
;
331 struct parse_context
{
332 struct sl_pp_context
*context
;
334 struct parse_dict dict
;
336 struct sl_pp_token_info
*tokens
;
337 unsigned int tokens_read
;
338 unsigned int tokens_cap
;
340 unsigned char *out_buf
;
341 unsigned int out_cap
;
343 unsigned int shader_type
;
344 unsigned int parsing_builtin
;
358 _emit(struct parse_context
*ctx
,
362 if (*out
== ctx
->out_cap
) {
363 ctx
->out_cap
+= 4096;
364 ctx
->out_buf
= (unsigned char *)realloc(ctx
->out_buf
, ctx
->out_cap
* sizeof(unsigned char));
366 ctx
->out_buf
[*out
] = b
;
372 _update(struct parse_context
*ctx
,
376 ctx
->out_buf
[out
] = b
;
381 _error(struct parse_context
*ctx
,
384 if (ctx
->error
[0] == '\0') {
385 strcpy(ctx
->error
, msg
);
390 static const struct sl_pp_token_info
*
391 _fetch_token(struct parse_context
*ctx
,
394 if (ctx
->process_error
) {
398 while (pos
>= ctx
->tokens_read
) {
399 if (ctx
->tokens_read
== ctx
->tokens_cap
) {
400 ctx
->tokens_cap
+= 1024;
401 ctx
->tokens
= realloc(ctx
->tokens
,
402 ctx
->tokens_cap
* sizeof(struct sl_pp_token_info
));
404 _error(ctx
, "out of memory");
405 ctx
->process_error
= 1;
409 if (sl_pp_process_get(ctx
->context
, &ctx
->tokens
[ctx
->tokens_read
])) {
410 _error(ctx
, sl_pp_context_error_message(ctx
->context
));
411 ctx
->process_error
= 1;
414 switch (ctx
->tokens
[ctx
->tokens_read
].token
) {
416 case SL_PP_SEMICOLON
:
424 case SL_PP_INCREMENT
:
425 case SL_PP_ADDASSIGN
:
427 case SL_PP_DECREMENT
:
428 case SL_PP_SUBASSIGN
:
433 case SL_PP_MULASSIGN
:
435 case SL_PP_DIVASSIGN
:
437 case SL_PP_MODASSIGN
:
439 case SL_PP_LSHIFTASSIGN
:
441 case SL_PP_LESSEQUAL
:
443 case SL_PP_RSHIFTASSIGN
:
445 case SL_PP_GREATEREQUAL
:
450 case SL_PP_BITANDASSIGN
:
453 case SL_PP_BITXORASSIGN
:
456 case SL_PP_BITORASSIGN
:
460 case SL_PP_IDENTIFIER
:
470 return &ctx
->tokens
[pos
];
475 * Try to parse/match a particular token.
476 * \return 0 for success, -1 for error.
479 _parse_token(struct parse_context
*ctx
,
480 enum sl_pp_token token
,
481 struct parse_state
*ps
)
483 const struct sl_pp_token_info
*input
= _fetch_token(ctx
, ps
->in
);
485 if (input
&& input
->token
== token
) {
494 * Try to parse an identifer.
495 * \return 0 for success, -1 for error
498 _parse_id(struct parse_context
*ctx
,
500 struct parse_state
*ps
)
502 const struct sl_pp_token_info
*input
= _fetch_token(ctx
, ps
->in
);
504 if (input
&& input
->token
== SL_PP_IDENTIFIER
&& input
->data
.identifier
== id
) {
513 _parse_identifier(struct parse_context
*ctx
,
514 struct parse_state
*ps
)
516 const struct sl_pp_token_info
*input
= _fetch_token(ctx
, ps
->in
);
518 if (input
&& input
->token
== SL_PP_IDENTIFIER
) {
519 const char *cstr
= sl_pp_context_cstr(ctx
->context
, input
->data
.identifier
);
522 _emit(ctx
, &ps
->out
, *cstr
);
532 _parse_float(struct parse_context
*ctx
,
533 struct parse_state
*ps
)
535 const struct sl_pp_token_info
*input
= _fetch_token(ctx
, ps
->in
);
537 if (input
&& input
->token
== SL_PP_FLOAT
) {
538 const char *cstr
= sl_pp_context_cstr(ctx
->context
, input
->data
._float
);
540 _emit(ctx
, &ps
->out
, 1);
542 _emit(ctx
, &ps
->out
, *cstr
);
552 _parse_uint(struct parse_context
*ctx
,
553 struct parse_state
*ps
)
555 const struct sl_pp_token_info
*input
= _fetch_token(ctx
, ps
->in
);
557 if (input
&& input
->token
== SL_PP_UINT
) {
558 const char *cstr
= sl_pp_context_cstr(ctx
->context
, input
->data
._uint
);
560 _emit(ctx
, &ps
->out
, 1);
562 _emit(ctx
, &ps
->out
, *cstr
);
571 /**************************************/
575 _parse_unary_expression(struct parse_context
*ctx
,
576 struct parse_state
*ps
);
579 _parse_conditional_expression(struct parse_context
*ctx
,
580 struct parse_state
*ps
);
584 _parse_constant_expression(struct parse_context
*ctx
,
585 struct parse_state
*ps
);
589 _parse_primary_expression(struct parse_context
*ctx
,
590 struct parse_state
*ps
);
594 _parse_statement(struct parse_context
*ctx
,
595 struct parse_state
*ps
);
599 _parse_type_specifier(struct parse_context
*ctx
,
600 struct parse_state
*ps
);
604 _parse_declaration(struct parse_context
*ctx
,
605 struct parse_state
*ps
);
609 _parse_statement_list(struct parse_context
*ctx
,
610 struct parse_state
*ps
);
614 _parse_assignment_expression(struct parse_context
*ctx
,
615 struct parse_state
*ps
);
619 _parse_precision(struct parse_context
*ctx
,
620 struct parse_state
*ps
);
624 _parse_overriden_operator(struct parse_context
*ctx
,
625 struct parse_state
*ps
)
629 if (_parse_token(ctx
, SL_PP_INCREMENT
, ps
) == 0) {
630 op
= OPERATOR_INCREMENT
;
631 } else if (_parse_token(ctx
, SL_PP_ADDASSIGN
, ps
) == 0) {
632 op
= OPERATOR_ADDASSIGN
;
633 } else if (_parse_token(ctx
, SL_PP_PLUS
, ps
) == 0) {
635 } else if (_parse_token(ctx
, SL_PP_DECREMENT
, ps
) == 0) {
636 op
= OPERATOR_DECREMENT
;
637 } else if (_parse_token(ctx
, SL_PP_SUBASSIGN
, ps
) == 0) {
638 op
= OPERATOR_SUBASSIGN
;
639 } else if (_parse_token(ctx
, SL_PP_MINUS
, ps
) == 0) {
641 } else if (_parse_token(ctx
, SL_PP_NOT
, ps
) == 0) {
643 } else if (_parse_token(ctx
, SL_PP_MULASSIGN
, ps
) == 0) {
644 op
= OPERATOR_MULASSIGN
;
645 } else if (_parse_token(ctx
, SL_PP_STAR
, ps
) == 0) {
646 op
= OPERATOR_MULTIPLY
;
647 } else if (_parse_token(ctx
, SL_PP_DIVASSIGN
, ps
) == 0) {
648 op
= OPERATOR_DIVASSIGN
;
649 } else if (_parse_token(ctx
, SL_PP_SLASH
, ps
) == 0) {
650 op
= OPERATOR_DIVIDE
;
651 } else if (_parse_token(ctx
, SL_PP_LESSEQUAL
, ps
) == 0) {
652 op
= OPERATOR_LESSEQUAL
;
653 } else if (_parse_token(ctx
, SL_PP_LESS
, ps
) == 0) {
655 } else if (_parse_token(ctx
, SL_PP_GREATEREQUAL
, ps
) == 0) {
656 op
= OPERATOR_GREATEREQUAL
;
657 } else if (_parse_token(ctx
, SL_PP_GREATER
, ps
) == 0) {
658 op
= OPERATOR_GREATER
;
659 } else if (_parse_token(ctx
, SL_PP_XOR
, ps
) == 0) {
660 op
= OPERATOR_LOGICALXOR
;
665 _emit(ctx
, &ps
->out
, op
);
671 _parse_function_decl_identifier(struct parse_context
*ctx
,
672 struct parse_state
*ps
)
674 struct parse_state p
= *ps
;
675 unsigned int e
= _emit(ctx
, &p
.out
, 0);
677 if (ctx
->parsing_builtin
&& _parse_id(ctx
, ctx
->dict
.__constructor
, &p
) == 0) {
678 _update(ctx
, e
, FUNCTION_CONSTRUCTOR
);
683 if (ctx
->parsing_builtin
&& _parse_id(ctx
, ctx
->dict
.__operator
, &p
) == 0) {
684 _update(ctx
, e
, FUNCTION_OPERATOR
);
685 if (_parse_overriden_operator(ctx
, &p
) == 0) {
692 if (_parse_identifier(ctx
, &p
) == 0) {
693 _update(ctx
, e
, FUNCTION_ORDINARY
);
703 _parse_invariant_qualifier(struct parse_context
*ctx
,
704 struct parse_state
*ps
)
706 if (_parse_id(ctx
, ctx
->dict
.invariant
, ps
)) {
709 _emit(ctx
, &ps
->out
, TYPE_INVARIANT
);
715 _parse_centroid_qualifier(struct parse_context
*ctx
,
716 struct parse_state
*ps
)
718 if (_parse_id(ctx
, ctx
->dict
.centroid
, ps
)) {
721 _emit(ctx
, &ps
->out
, TYPE_CENTROID
);
727 _parse_layout_qualifier(struct parse_context
*ctx
,
728 struct parse_state
*ps
)
730 if (_parse_id(ctx
, ctx
->dict
.layout
, ps
) == 0) {
731 /* start of a parenthesised list of layout qualifiers */
733 if (_parse_token(ctx
, SL_PP_LPAREN
, ps
)) {
734 _error(ctx
, "expected `('");
738 /* parse comma-separated ID list */
740 if (_parse_id(ctx
, ctx
->dict
.origin_upper_left
, ps
) == 0) {
741 _emit(ctx
, &ps
->out
, LAYOUT_QUALIFIER_UPPER_LEFT
);
743 else if (_parse_id(ctx
, ctx
->dict
.pixel_center_integer
, ps
) == 0) {
744 _emit(ctx
, &ps
->out
, LAYOUT_QUALIFIER_PIXEL_CENTER_INTEGER
);
747 _error(ctx
, "expected a layout qualifier");
751 if (_parse_token(ctx
, SL_PP_RPAREN
, ps
) == 0) {
755 else if (_parse_token(ctx
, SL_PP_COMMA
, ps
) == 0) {
756 /* another layout qualifier is coming */
759 _error(ctx
, "expected `,' or `)'");
770 _parse_storage_qualifier(struct parse_context
*ctx
,
771 struct parse_state
*ps
)
773 struct parse_state p
= *ps
;
774 const struct sl_pp_token_info
*input
= _fetch_token(ctx
, p
.in
);
775 unsigned int e
= _emit(ctx
, &p
.out
, 0);
778 if (!input
|| input
->token
!= SL_PP_IDENTIFIER
) {
781 id
= input
->data
.identifier
;
783 if (id
== ctx
->dict
._const
) {
784 _update(ctx
, e
, TYPE_QUALIFIER_CONST
);
785 } else if (ctx
->shader_type
== 2 && id
== ctx
->dict
.attribute
) {
786 _update(ctx
, e
, TYPE_QUALIFIER_ATTRIBUTE
);
787 } else if (id
== ctx
->dict
.varying
) {
788 _update(ctx
, e
, TYPE_QUALIFIER_VARYING
);
789 } else if (id
== ctx
->dict
.uniform
) {
790 _update(ctx
, e
, TYPE_QUALIFIER_UNIFORM
);
791 } else if (ctx
->parsing_builtin
&& id
== ctx
->dict
.__fixed_output
) {
792 _update(ctx
, e
, TYPE_QUALIFIER_FIXEDOUTPUT
);
793 } else if (ctx
->parsing_builtin
&& id
== ctx
->dict
.__fixed_input
) {
794 _update(ctx
, e
, TYPE_QUALIFIER_FIXEDINPUT
);
798 _parse_token(ctx
, SL_PP_IDENTIFIER
, &p
);
805 _parse_struct_declarator(struct parse_context
*ctx
,
806 struct parse_state
*ps
)
808 struct parse_state p
= *ps
;
811 if (_parse_identifier(ctx
, &p
)) {
814 e
= _emit(ctx
, &p
.out
, FIELD_NONE
);
817 if (_parse_token(ctx
, SL_PP_LBRACKET
, &p
)) {
820 if (_parse_constant_expression(ctx
, &p
)) {
821 _error(ctx
, "expected constant integral expression");
824 if (_parse_token(ctx
, SL_PP_RBRACKET
, &p
)) {
825 _error(ctx
, "expected `]'");
828 _update(ctx
, e
, FIELD_ARRAY
);
835 _parse_struct_declarator_list(struct parse_context
*ctx
,
836 struct parse_state
*ps
)
838 struct parse_state p
= *ps
;
840 if (_parse_struct_declarator(ctx
, &p
)) {
846 _emit(ctx
, &p
.out
, FIELD_NEXT
);
847 if (_parse_token(ctx
, SL_PP_COMMA
, &p
)) {
850 if (_parse_struct_declarator(ctx
, &p
)) {
858 _parse_struct_declaration(struct parse_context
*ctx
,
859 struct parse_state
*ps
)
861 struct parse_state p
= *ps
;
863 if (_parse_type_specifier(ctx
, &p
)) {
866 if (_parse_struct_declarator_list(ctx
, &p
)) {
869 if (_parse_token(ctx
, SL_PP_SEMICOLON
, &p
)) {
872 _emit(ctx
, &p
.out
, FIELD_NONE
);
879 _parse_struct_declaration_list(struct parse_context
*ctx
,
880 struct parse_state
*ps
)
882 struct parse_state p
= *ps
;
884 if (_parse_struct_declaration(ctx
, &p
)) {
890 _emit(ctx
, &p
.out
, FIELD_NEXT
);
891 if (_parse_struct_declaration(ctx
, &p
)) {
899 _parse_struct_specifier(struct parse_context
*ctx
,
900 struct parse_state
*ps
)
902 struct parse_state p
= *ps
;
904 if (_parse_id(ctx
, ctx
->dict
._struct
, &p
)) {
907 if (_parse_identifier(ctx
, &p
)) {
908 _emit(ctx
, &p
.out
, '\0');
910 if (_parse_token(ctx
, SL_PP_LBRACE
, &p
)) {
911 _error(ctx
, "expected `{'");
914 if (_parse_struct_declaration_list(ctx
, &p
)) {
917 if (_parse_token(ctx
, SL_PP_RBRACE
, &p
)) {
920 _emit(ctx
, &p
.out
, FIELD_NONE
);
927 _parse_type_specifier_nonarray(struct parse_context
*ctx
,
928 struct parse_state
*ps
)
930 struct parse_state p
= *ps
;
931 unsigned int e
= _emit(ctx
, &p
.out
, 0);
932 const struct sl_pp_token_info
*input
;
935 if (_parse_struct_specifier(ctx
, &p
) == 0) {
936 _update(ctx
, e
, TYPE_SPECIFIER_STRUCT
);
941 input
= _fetch_token(ctx
, p
.in
);
942 if (!input
|| input
->token
!= SL_PP_IDENTIFIER
) {
945 id
= input
->data
.identifier
;
947 if (id
== ctx
->dict
._void
) {
948 _update(ctx
, e
, TYPE_SPECIFIER_VOID
);
949 } else if (id
== ctx
->dict
._float
) {
950 _update(ctx
, e
, TYPE_SPECIFIER_FLOAT
);
951 } else if (id
== ctx
->dict
._int
) {
952 _update(ctx
, e
, TYPE_SPECIFIER_INT
);
953 } else if (id
== ctx
->dict
._bool
) {
954 _update(ctx
, e
, TYPE_SPECIFIER_BOOL
);
955 } else if (id
== ctx
->dict
.vec2
) {
956 _update(ctx
, e
, TYPE_SPECIFIER_VEC2
);
957 } else if (id
== ctx
->dict
.vec3
) {
958 _update(ctx
, e
, TYPE_SPECIFIER_VEC3
);
959 } else if (id
== ctx
->dict
.vec4
) {
960 _update(ctx
, e
, TYPE_SPECIFIER_VEC4
);
961 } else if (id
== ctx
->dict
.bvec2
) {
962 _update(ctx
, e
, TYPE_SPECIFIER_BVEC2
);
963 } else if (id
== ctx
->dict
.bvec3
) {
964 _update(ctx
, e
, TYPE_SPECIFIER_BVEC3
);
965 } else if (id
== ctx
->dict
.bvec4
) {
966 _update(ctx
, e
, TYPE_SPECIFIER_BVEC4
);
967 } else if (id
== ctx
->dict
.ivec2
) {
968 _update(ctx
, e
, TYPE_SPECIFIER_IVEC2
);
969 } else if (id
== ctx
->dict
.ivec3
) {
970 _update(ctx
, e
, TYPE_SPECIFIER_IVEC3
);
971 } else if (id
== ctx
->dict
.ivec4
) {
972 _update(ctx
, e
, TYPE_SPECIFIER_IVEC4
);
973 } else if (id
== ctx
->dict
.mat2
) {
974 _update(ctx
, e
, TYPE_SPECIFIER_MAT2
);
975 } else if (id
== ctx
->dict
.mat3
) {
976 _update(ctx
, e
, TYPE_SPECIFIER_MAT3
);
977 } else if (id
== ctx
->dict
.mat4
) {
978 _update(ctx
, e
, TYPE_SPECIFIER_MAT4
);
979 } else if (id
== ctx
->dict
.mat2x3
) {
980 _update(ctx
, e
, TYPE_SPECIFIER_MAT23
);
981 } else if (id
== ctx
->dict
.mat3x2
) {
982 _update(ctx
, e
, TYPE_SPECIFIER_MAT32
);
983 } else if (id
== ctx
->dict
.mat2x4
) {
984 _update(ctx
, e
, TYPE_SPECIFIER_MAT24
);
985 } else if (id
== ctx
->dict
.mat4x2
) {
986 _update(ctx
, e
, TYPE_SPECIFIER_MAT42
);
987 } else if (id
== ctx
->dict
.mat3x4
) {
988 _update(ctx
, e
, TYPE_SPECIFIER_MAT34
);
989 } else if (id
== ctx
->dict
.mat4x3
) {
990 _update(ctx
, e
, TYPE_SPECIFIER_MAT43
);
991 } else if (id
== ctx
->dict
.sampler1D
) {
992 _update(ctx
, e
, TYPE_SPECIFIER_SAMPLER1D
);
993 } else if (id
== ctx
->dict
.sampler2D
) {
994 _update(ctx
, e
, TYPE_SPECIFIER_SAMPLER2D
);
995 } else if (id
== ctx
->dict
.sampler3D
) {
996 _update(ctx
, e
, TYPE_SPECIFIER_SAMPLER3D
);
997 } else if (id
== ctx
->dict
.samplerCube
) {
998 _update(ctx
, e
, TYPE_SPECIFIER_SAMPLERCUBE
);
999 } else if (id
== ctx
->dict
.sampler1DShadow
) {
1000 _update(ctx
, e
, TYPE_SPECIFIER_SAMPLER1DSHADOW
);
1001 } else if (id
== ctx
->dict
.sampler2DShadow
) {
1002 _update(ctx
, e
, TYPE_SPECIFIER_SAMPLER2DSHADOW
);
1003 } else if (id
== ctx
->dict
.sampler2DRect
) {
1004 _update(ctx
, e
, TYPE_SPECIFIER_SAMPLER2DRECT
);
1005 } else if (id
== ctx
->dict
.sampler2DRectShadow
) {
1006 _update(ctx
, e
, TYPE_SPECIFIER_SAMPLER2DRECTSHADOW
);
1007 } else if (_parse_identifier(ctx
, &p
) == 0) {
1008 _update(ctx
, e
, TYPE_SPECIFIER_TYPENAME
);
1015 _parse_token(ctx
, SL_PP_IDENTIFIER
, &p
);
1022 _parse_type_specifier_array(struct parse_context
*ctx
,
1023 struct parse_state
*ps
)
1025 struct parse_state p
= *ps
;
1027 if (_parse_token(ctx
, SL_PP_LBRACKET
, &p
)) {
1030 if (_parse_constant_expression(ctx
, &p
)) {
1031 _error(ctx
, "expected constant integral expression");
1034 if (_parse_token(ctx
, SL_PP_RBRACKET
, &p
)) {
1035 _error(ctx
, "expected `]'");
1044 _parse_type_specifier(struct parse_context
*ctx
,
1045 struct parse_state
*ps
)
1047 struct parse_state p
= *ps
;
1050 if (_parse_type_specifier_nonarray(ctx
, &p
)) {
1054 e
= _emit(ctx
, &p
.out
, TYPE_SPECIFIER_ARRAY
);
1055 if (_parse_type_specifier_array(ctx
, &p
)) {
1056 _update(ctx
, e
, TYPE_SPECIFIER_NONARRAY
);
1064 _parse_fully_specified_type(struct parse_context
*ctx
,
1065 struct parse_state
*ps
)
1067 struct parse_state p
= *ps
;
1069 if (_parse_layout_qualifier(ctx
, &p
)) {
1072 _emit(ctx
, &p
.out
, LAYOUT_QUALIFIER_NONE
);
1074 if (_parse_invariant_qualifier(ctx
, &p
)) {
1075 _emit(ctx
, &p
.out
, TYPE_VARIANT
);
1078 if (_parse_centroid_qualifier(ctx
, &p
)) {
1079 _emit(ctx
, &p
.out
, TYPE_CENTER
);
1081 if (_parse_storage_qualifier(ctx
, &p
)) {
1082 _emit(ctx
, &p
.out
, TYPE_QUALIFIER_NONE
);
1084 if (_parse_precision(ctx
, &p
)) {
1085 _emit(ctx
, &p
.out
, PRECISION_DEFAULT
);
1087 if (_parse_type_specifier(ctx
, &p
)) {
1096 _parse_function_header(struct parse_context
*ctx
,
1097 struct parse_state
*ps
)
1099 struct parse_state p
= *ps
;
1101 if (_parse_fully_specified_type(ctx
, &p
)) {
1104 if (_parse_function_decl_identifier(ctx
, &p
)) {
1107 if (_parse_token(ctx
, SL_PP_LPAREN
, &p
)) {
1116 _parse_parameter_qualifier(struct parse_context
*ctx
,
1117 struct parse_state
*ps
)
1119 unsigned int e
= _emit(ctx
, &ps
->out
, PARAM_QUALIFIER_IN
);
1121 if (_parse_id(ctx
, ctx
->dict
.out
, ps
) == 0) {
1122 _update(ctx
, e
, PARAM_QUALIFIER_OUT
);
1123 } else if (_parse_id(ctx
, ctx
->dict
.inout
, ps
) == 0) {
1124 _update(ctx
, e
, PARAM_QUALIFIER_INOUT
);
1126 _parse_id(ctx
, ctx
->dict
.in
, ps
);
1133 _parse_function_identifier(struct parse_context
*ctx
,
1134 struct parse_state
*ps
)
1136 struct parse_state p
;
1139 if (_parse_identifier(ctx
, ps
)) {
1142 e
= _emit(ctx
, &ps
->out
, FUNCTION_CALL_NONARRAY
);
1145 if (_parse_token(ctx
, SL_PP_LBRACKET
, &p
)) {
1148 if (_parse_constant_expression(ctx
, &p
)) {
1149 _error(ctx
, "expected constant integral expression");
1152 if (_parse_token(ctx
, SL_PP_RBRACKET
, &p
)) {
1153 _error(ctx
, "expected `]'");
1156 _update(ctx
, e
, FUNCTION_CALL_ARRAY
);
1163 _parse_function_call_header(struct parse_context
*ctx
,
1164 struct parse_state
*ps
)
1166 struct parse_state p
= *ps
;
1168 if (_parse_function_identifier(ctx
, &p
)) {
1171 if (_parse_token(ctx
, SL_PP_LPAREN
, &p
)) {
1180 _parse_assign_expression(struct parse_context
*ctx
,
1181 struct parse_state
*ps
)
1183 struct parse_state p
= *ps
;
1186 if (_parse_unary_expression(ctx
, &p
)) {
1190 if (_parse_token(ctx
, SL_PP_ASSIGN
, &p
) == 0) {
1192 } else if (_parse_token(ctx
, SL_PP_MULASSIGN
, &p
) == 0) {
1194 } else if (_parse_token(ctx
, SL_PP_DIVASSIGN
, &p
) == 0) {
1196 } else if (_parse_token(ctx
, SL_PP_ADDASSIGN
, &p
) == 0) {
1198 } else if (_parse_token(ctx
, SL_PP_SUBASSIGN
, &p
) == 0) {
1204 if (_parse_assignment_expression(ctx
, &p
)) {
1207 _emit(ctx
, &p
.out
, op
);
1215 _parse_assignment_expression(struct parse_context
*ctx
,
1216 struct parse_state
*ps
)
1218 if (_parse_assign_expression(ctx
, ps
) == 0) {
1222 if (_parse_conditional_expression(ctx
, ps
) == 0) {
1231 _parse_function_call_header_with_parameters(struct parse_context
*ctx
,
1232 struct parse_state
*ps
)
1234 struct parse_state p
= *ps
;
1236 if (_parse_function_call_header(ctx
, &p
)) {
1239 if (_parse_assignment_expression(ctx
, &p
)) {
1242 _emit(ctx
, &p
.out
, OP_END
);
1245 if (_parse_token(ctx
, SL_PP_COMMA
, &p
)) {
1248 if (_parse_assignment_expression(ctx
, &p
)) {
1251 _emit(ctx
, &p
.out
, OP_END
);
1257 _parse_function_call_header_no_parameters(struct parse_context
*ctx
,
1258 struct parse_state
*ps
)
1260 if (_parse_function_call_header(ctx
, ps
)) {
1263 _parse_id(ctx
, ctx
->dict
._void
, ps
);
1269 _parse_function_call_generic(struct parse_context
*ctx
,
1270 struct parse_state
*ps
)
1272 struct parse_state p
= *ps
;
1274 if (_parse_function_call_header_with_parameters(ctx
, &p
) == 0) {
1275 if (_parse_token(ctx
, SL_PP_RPAREN
, &p
) == 0) {
1279 _error(ctx
, "expected `)'");
1284 if (_parse_function_call_header_no_parameters(ctx
, &p
) == 0) {
1285 if (_parse_token(ctx
, SL_PP_RPAREN
, &p
) == 0) {
1289 _error(ctx
, "expected `)'");
1298 _parse_method_call(struct parse_context
*ctx
,
1299 struct parse_state
*ps
)
1301 struct parse_state p
= *ps
;
1303 _emit(ctx
, &p
.out
, OP_METHOD
);
1304 if (_parse_identifier(ctx
, &p
)) {
1307 if (_parse_token(ctx
, SL_PP_DOT
, &p
)) {
1310 if (_parse_function_call_generic(ctx
, &p
)) {
1313 _emit(ctx
, &p
.out
, OP_END
);
1320 _parse_regular_function_call(struct parse_context
*ctx
,
1321 struct parse_state
*ps
)
1323 struct parse_state p
= *ps
;
1325 _emit(ctx
, &p
.out
, OP_CALL
);
1326 if (_parse_function_call_generic(ctx
, &p
)) {
1329 _emit(ctx
, &p
.out
, OP_END
);
1336 _parse_function_call(struct parse_context
*ctx
,
1337 struct parse_state
*ps
)
1339 if (_parse_regular_function_call(ctx
, ps
) == 0) {
1343 if (_parse_method_call(ctx
, ps
) == 0) {
1352 _parse_expression(struct parse_context
*ctx
,
1353 struct parse_state
*ps
)
1355 struct parse_state p
= *ps
;
1357 if (_parse_assignment_expression(ctx
, &p
)) {
1363 if (_parse_token(ctx
, SL_PP_COMMA
, &p
)) {
1366 if (_parse_assignment_expression(ctx
, &p
)) {
1369 _emit(ctx
, &p
.out
, OP_SEQUENCE
);
1375 _parse_postfix_expression(struct parse_context
*ctx
,
1376 struct parse_state
*ps
)
1378 struct parse_state p
;
1380 if (_parse_function_call(ctx
, ps
)) {
1381 if (_parse_primary_expression(ctx
, ps
)) {
1388 if (_parse_token(ctx
, SL_PP_INCREMENT
, &p
) == 0) {
1389 _emit(ctx
, &p
.out
, OP_POSTINCREMENT
);
1390 } else if (_parse_token(ctx
, SL_PP_DECREMENT
, &p
) == 0) {
1391 _emit(ctx
, &p
.out
, OP_POSTDECREMENT
);
1392 } else if (_parse_token(ctx
, SL_PP_LBRACKET
, &p
) == 0) {
1393 if (_parse_expression(ctx
, &p
)) {
1394 _error(ctx
, "expected an integral expression");
1397 if (_parse_token(ctx
, SL_PP_RBRACKET
, &p
)) {
1398 _error(ctx
, "expected `]'");
1401 _emit(ctx
, &p
.out
, OP_SUBSCRIPT
);
1402 } else if (_parse_token(ctx
, SL_PP_DOT
, &p
) == 0) {
1403 _emit(ctx
, &p
.out
, OP_FIELD
);
1404 if (_parse_identifier(ctx
, &p
)) {
1415 _parse_unary_expression(struct parse_context
*ctx
,
1416 struct parse_state
*ps
)
1418 struct parse_state p
;
1421 if (_parse_postfix_expression(ctx
, ps
) == 0) {
1426 if (_parse_token(ctx
, SL_PP_INCREMENT
, &p
) == 0) {
1427 op
= OP_PREINCREMENT
;
1428 } else if (_parse_token(ctx
, SL_PP_DECREMENT
, &p
) == 0) {
1429 op
= OP_PREDECREMENT
;
1430 } else if (_parse_token(ctx
, SL_PP_PLUS
, &p
) == 0) {
1432 } else if (_parse_token(ctx
, SL_PP_MINUS
, &p
) == 0) {
1434 } else if (_parse_token(ctx
, SL_PP_NOT
, &p
) == 0) {
1440 if (_parse_unary_expression(ctx
, &p
)) {
1443 _emit(ctx
, &p
.out
, op
);
1450 _parse_multiplicative_expression(struct parse_context
*ctx
,
1451 struct parse_state
*ps
)
1453 struct parse_state p
= *ps
;
1455 if (_parse_unary_expression(ctx
, &p
)) {
1462 if (_parse_token(ctx
, SL_PP_STAR
, &p
) == 0) {
1464 } else if (_parse_token(ctx
, SL_PP_SLASH
, &p
) == 0) {
1469 if (_parse_unary_expression(ctx
, &p
)) {
1472 _emit(ctx
, &p
.out
, op
);
1478 _parse_additive_expression(struct parse_context
*ctx
,
1479 struct parse_state
*ps
)
1481 struct parse_state p
= *ps
;
1483 if (_parse_multiplicative_expression(ctx
, &p
)) {
1490 if (_parse_token(ctx
, SL_PP_PLUS
, &p
) == 0) {
1492 } else if (_parse_token(ctx
, SL_PP_MINUS
, &p
) == 0) {
1497 if (_parse_multiplicative_expression(ctx
, &p
)) {
1500 _emit(ctx
, &p
.out
, op
);
1506 _parse_relational_expression(struct parse_context
*ctx
,
1507 struct parse_state
*ps
)
1509 struct parse_state p
= *ps
;
1511 if (_parse_additive_expression(ctx
, &p
)) {
1518 if (_parse_token(ctx
, SL_PP_LESS
, &p
) == 0) {
1520 } else if (_parse_token(ctx
, SL_PP_GREATER
, &p
) == 0) {
1522 } else if (_parse_token(ctx
, SL_PP_LESSEQUAL
, &p
) == 0) {
1524 } else if (_parse_token(ctx
, SL_PP_GREATEREQUAL
, &p
) == 0) {
1525 op
= OP_GREATEREQUAL
;
1529 if (_parse_additive_expression(ctx
, &p
)) {
1532 _emit(ctx
, &p
.out
, op
);
1538 _parse_equality_expression(struct parse_context
*ctx
,
1539 struct parse_state
*ps
)
1541 struct parse_state p
= *ps
;
1543 if (_parse_relational_expression(ctx
, &p
)) {
1550 if (_parse_token(ctx
, SL_PP_EQUAL
, &p
) == 0) {
1552 } else if (_parse_token(ctx
, SL_PP_NOTEQUAL
, &p
) == 0) {
1557 if (_parse_relational_expression(ctx
, &p
)) {
1560 _emit(ctx
, &p
.out
, op
);
1566 _parse_logical_and_expression(struct parse_context
*ctx
,
1567 struct parse_state
*ps
)
1569 struct parse_state p
= *ps
;
1571 if (_parse_equality_expression(ctx
, &p
)) {
1576 if (_parse_token(ctx
, SL_PP_AND
, &p
)) {
1579 if (_parse_equality_expression(ctx
, &p
)) {
1582 _emit(ctx
, &p
.out
, OP_LOGICALAND
);
1588 _parse_logical_xor_expression(struct parse_context
*ctx
,
1589 struct parse_state
*ps
)
1591 struct parse_state p
= *ps
;
1593 if (_parse_logical_and_expression(ctx
, &p
)) {
1598 if (_parse_token(ctx
, SL_PP_XOR
, &p
)) {
1601 if (_parse_logical_and_expression(ctx
, &p
)) {
1604 _emit(ctx
, &p
.out
, OP_LOGICALXOR
);
1610 _parse_logical_or_expression(struct parse_context
*ctx
,
1611 struct parse_state
*ps
)
1613 struct parse_state p
= *ps
;
1615 if (_parse_logical_xor_expression(ctx
, &p
)) {
1620 if (_parse_token(ctx
, SL_PP_OR
, &p
)) {
1623 if (_parse_logical_xor_expression(ctx
, &p
)) {
1626 _emit(ctx
, &p
.out
, OP_LOGICALOR
);
1632 _parse_conditional_expression(struct parse_context
*ctx
,
1633 struct parse_state
*ps
)
1635 struct parse_state p
= *ps
;
1637 if (_parse_logical_or_expression(ctx
, &p
)) {
1642 if (_parse_token(ctx
, SL_PP_QUESTION
, &p
)) {
1645 if (_parse_expression(ctx
, &p
)) {
1648 if (_parse_token(ctx
, SL_PP_COLON
, &p
)) {
1651 if (_parse_conditional_expression(ctx
, &p
)) {
1654 _emit(ctx
, &p
.out
, OP_SELECT
);
1660 _parse_constant_expression(struct parse_context
*ctx
,
1661 struct parse_state
*ps
)
1663 if (_parse_conditional_expression(ctx
, ps
)) {
1666 _emit(ctx
, &ps
->out
, OP_END
);
1672 _parse_parameter_declarator_array(struct parse_context
*ctx
,
1673 struct parse_state
*ps
)
1675 struct parse_state p
= *ps
;
1677 if (_parse_token(ctx
, SL_PP_LBRACKET
, &p
)) {
1680 if (_parse_constant_expression(ctx
, &p
)) {
1681 _error(ctx
, "expected constant integral expression");
1684 if (_parse_token(ctx
, SL_PP_RBRACKET
, &p
)) {
1685 _error(ctx
, "expected `]'");
1694 _parse_parameter_declarator(struct parse_context
*ctx
,
1695 struct parse_state
*ps
)
1697 struct parse_state p
= *ps
;
1700 if (_parse_type_specifier(ctx
, &p
)) {
1703 if (_parse_identifier(ctx
, &p
)) {
1706 e
= _emit(ctx
, &p
.out
, PARAMETER_ARRAY_PRESENT
);
1707 if (_parse_parameter_declarator_array(ctx
, &p
)) {
1708 _update(ctx
, e
, PARAMETER_ARRAY_NOT_PRESENT
);
1716 _parse_parameter_type_specifier_array(struct parse_context
*ctx
,
1717 struct parse_state
*ps
)
1719 struct parse_state p
= *ps
;
1721 if (_parse_token(ctx
, SL_PP_LBRACKET
, &p
)) {
1724 if (_parse_constant_expression(ctx
, &p
)) {
1725 _error(ctx
, "expected constant integral expression");
1728 if (_parse_token(ctx
, SL_PP_RBRACKET
, &p
)) {
1729 _error(ctx
, "expected `]'");
1738 _parse_parameter_type_specifier(struct parse_context
*ctx
,
1739 struct parse_state
*ps
)
1741 struct parse_state p
= *ps
;
1744 if (_parse_type_specifier(ctx
, &p
)) {
1747 _emit(ctx
, &p
.out
, '\0');
1749 e
= _emit(ctx
, &p
.out
, PARAMETER_ARRAY_PRESENT
);
1750 if (_parse_parameter_type_specifier_array(ctx
, &p
)) {
1751 _update(ctx
, e
, PARAMETER_ARRAY_NOT_PRESENT
);
1759 _parse_parameter_declaration(struct parse_context
*ctx
,
1760 struct parse_state
*ps
)
1762 struct parse_state p
= *ps
;
1763 unsigned int e
= _emit(ctx
, &p
.out
, PARAMETER_NEXT
);
1767 if (_parse_storage_qualifier(ctx
, &p
)) {
1768 _emit(ctx
, &p
.out
, TYPE_QUALIFIER_NONE
);
1770 _parse_parameter_qualifier(ctx
, &p
);
1771 if (_parse_precision(ctx
, &p
)) {
1772 _emit(ctx
, &p
.out
, PRECISION_DEFAULT
);
1774 if (_parse_parameter_declarator(ctx
, &p
) == 0) {
1778 if (_parse_parameter_type_specifier(ctx
, &p
) == 0) {
1788 _parse_function_header_with_parameters(struct parse_context
*ctx
,
1789 struct parse_state
*ps
)
1791 struct parse_state p
= *ps
;
1793 if (_parse_function_header(ctx
, &p
)) {
1796 if (_parse_parameter_declaration(ctx
, &p
)) {
1802 if (_parse_token(ctx
, SL_PP_COMMA
, &p
)) {
1805 if (_parse_parameter_declaration(ctx
, &p
)) {
1813 _parse_function_declarator(struct parse_context
*ctx
,
1814 struct parse_state
*ps
)
1816 if (_parse_function_header_with_parameters(ctx
, ps
) == 0) {
1820 if (_parse_function_header(ctx
, ps
) == 0) {
1829 _parse_function_prototype(struct parse_context
*ctx
,
1830 struct parse_state
*ps
)
1832 struct parse_state p
= *ps
;
1834 if (_parse_function_header(ctx
, &p
) == 0) {
1835 if (_parse_id(ctx
, ctx
->dict
._void
, &p
) == 0) {
1836 if (_parse_token(ctx
, SL_PP_RPAREN
, &p
) == 0) {
1837 _emit(ctx
, &p
.out
, PARAMETER_NONE
);
1841 _error(ctx
, "expected `)'");
1847 if (_parse_function_declarator(ctx
, &p
) == 0) {
1848 if (_parse_token(ctx
, SL_PP_RPAREN
, &p
) == 0) {
1849 _emit(ctx
, &p
.out
, PARAMETER_NONE
);
1853 _error(ctx
, "expected `)'");
1862 _parse_precision(struct parse_context
*ctx
,
1863 struct parse_state
*ps
)
1865 const struct sl_pp_token_info
*input
= _fetch_token(ctx
, ps
->in
);
1867 unsigned int precision
;
1869 if (!input
|| input
->token
!= SL_PP_IDENTIFIER
) {
1872 id
= input
->data
.identifier
;
1874 if (id
== ctx
->dict
.lowp
) {
1875 precision
= PRECISION_LOW
;
1876 } else if (id
== ctx
->dict
.mediump
) {
1877 precision
= PRECISION_MEDIUM
;
1878 } else if (id
== ctx
->dict
.highp
) {
1879 precision
= PRECISION_HIGH
;
1884 _parse_token(ctx
, SL_PP_IDENTIFIER
, ps
);
1885 _emit(ctx
, &ps
->out
, precision
);
1891 _parse_prectype(struct parse_context
*ctx
,
1892 struct parse_state
*ps
)
1894 const struct sl_pp_token_info
*input
= _fetch_token(ctx
, ps
->in
);
1898 if (!input
|| input
->token
!= SL_PP_IDENTIFIER
) {
1901 id
= input
->data
.identifier
;
1903 if (id
== ctx
->dict
._int
) {
1904 type
= TYPE_SPECIFIER_INT
;
1905 } else if (id
== ctx
->dict
._float
) {
1906 type
= TYPE_SPECIFIER_FLOAT
;
1907 } else if (id
== ctx
->dict
.sampler1D
) {
1908 type
= TYPE_SPECIFIER_SAMPLER1D
;
1909 } else if (id
== ctx
->dict
.sampler2D
) {
1910 type
= TYPE_SPECIFIER_SAMPLER2D
;
1911 } else if (id
== ctx
->dict
.sampler3D
) {
1912 type
= TYPE_SPECIFIER_SAMPLER3D
;
1913 } else if (id
== ctx
->dict
.samplerCube
) {
1914 type
= TYPE_SPECIFIER_SAMPLERCUBE
;
1915 } else if (id
== ctx
->dict
.sampler1DShadow
) {
1916 type
= TYPE_SPECIFIER_SAMPLER1DSHADOW
;
1917 } else if (id
== ctx
->dict
.sampler2DShadow
) {
1918 type
= TYPE_SPECIFIER_SAMPLER2DSHADOW
;
1919 } else if (id
== ctx
->dict
.sampler2DRect
) {
1920 type
= TYPE_SPECIFIER_SAMPLER2DRECT
;
1921 } else if (id
== ctx
->dict
.sampler2DRectShadow
) {
1922 type
= TYPE_SPECIFIER_SAMPLER2DRECTSHADOW
;
1927 _parse_token(ctx
, SL_PP_IDENTIFIER
, ps
);
1928 _emit(ctx
, &ps
->out
, type
);
1934 _parse_precision_stmt(struct parse_context
*ctx
,
1935 struct parse_state
*ps
)
1937 struct parse_state p
= *ps
;
1939 if (_parse_id(ctx
, ctx
->dict
.precision
, &p
)) {
1942 if (_parse_precision(ctx
, &p
)) {
1945 if (_parse_prectype(ctx
, &p
)) {
1948 if (_parse_token(ctx
, SL_PP_SEMICOLON
, &p
)) {
1957 _parse_floatconstant(struct parse_context
*ctx
,
1958 struct parse_state
*ps
)
1960 struct parse_state p
= *ps
;
1962 _emit(ctx
, &p
.out
, OP_PUSH_FLOAT
);
1963 if (_parse_float(ctx
, &p
)) {
1972 _parse_intconstant(struct parse_context
*ctx
,
1973 struct parse_state
*ps
)
1975 struct parse_state p
= *ps
;
1977 _emit(ctx
, &p
.out
, OP_PUSH_INT
);
1978 if (_parse_uint(ctx
, &p
)) {
1987 _parse_boolconstant(struct parse_context
*ctx
,
1988 struct parse_state
*ps
)
1990 if (_parse_id(ctx
, ctx
->dict
._false
, ps
) == 0) {
1991 _emit(ctx
, &ps
->out
, OP_PUSH_BOOL
);
1992 _emit(ctx
, &ps
->out
, 2); /* radix */
1993 _emit(ctx
, &ps
->out
, '0');
1994 _emit(ctx
, &ps
->out
, '\0');
1998 if (_parse_id(ctx
, ctx
->dict
._true
, ps
) == 0) {
1999 _emit(ctx
, &ps
->out
, OP_PUSH_BOOL
);
2000 _emit(ctx
, &ps
->out
, 2); /* radix */
2001 _emit(ctx
, &ps
->out
, '1');
2002 _emit(ctx
, &ps
->out
, '\0');
2011 _parse_variable_identifier(struct parse_context
*ctx
,
2012 struct parse_state
*ps
)
2014 struct parse_state p
= *ps
;
2016 _emit(ctx
, &p
.out
, OP_PUSH_IDENTIFIER
);
2017 if (_parse_identifier(ctx
, &p
)) {
2026 _parse_primary_expression(struct parse_context
*ctx
,
2027 struct parse_state
*ps
)
2029 struct parse_state p
;
2031 if (_parse_floatconstant(ctx
, ps
) == 0) {
2034 if (_parse_boolconstant(ctx
, ps
) == 0) {
2037 if (_parse_intconstant(ctx
, ps
) == 0) {
2040 if (_parse_variable_identifier(ctx
, ps
) == 0) {
2045 if (_parse_token(ctx
, SL_PP_LPAREN
, &p
)) {
2048 if (_parse_expression(ctx
, &p
)) {
2051 if (_parse_token(ctx
, SL_PP_RPAREN
, &p
)) {
2061 _parse_asm_argument(struct parse_context
*ctx
,
2062 struct parse_state
*ps
)
2064 if (_parse_variable_identifier(ctx
, ps
) == 0) {
2065 struct parse_state p
= *ps
;
2067 if (_parse_token(ctx
, SL_PP_DOT
, &p
)) {
2070 _emit(ctx
, &p
.out
, OP_FIELD
);
2071 if (_parse_identifier(ctx
, &p
)) {
2078 if (_parse_floatconstant(ctx
, ps
) == 0) {
2087 _parse_asm_arguments(struct parse_context
*ctx
,
2088 struct parse_state
*ps
)
2090 struct parse_state p
= *ps
;
2092 if (_parse_asm_argument(ctx
, &p
)) {
2095 _emit(ctx
, &p
.out
, OP_END
);
2099 if (_parse_token(ctx
, SL_PP_COMMA
, &p
)) {
2102 if (_parse_asm_argument(ctx
, &p
)) {
2105 _emit(ctx
, &p
.out
, OP_END
);
2111 _parse_asm_statement(struct parse_context
*ctx
,
2112 struct parse_state
*ps
)
2114 struct parse_state p
= *ps
;
2116 if (_parse_id(ctx
, ctx
->dict
.___asm
, &p
)) {
2119 if (_parse_identifier(ctx
, &p
)) {
2122 if (_parse_asm_arguments(ctx
, &p
)) {
2125 if (_parse_token(ctx
, SL_PP_SEMICOLON
, &p
)) {
2128 _emit(ctx
, &p
.out
, OP_END
);
2135 _parse_selection_statement(struct parse_context
*ctx
,
2136 struct parse_state
*ps
)
2138 struct parse_state p
= *ps
;
2140 _emit(ctx
, &p
.out
, OP_IF
);
2141 if (_parse_id(ctx
, ctx
->dict
._if
, &p
)) {
2144 if (_parse_token(ctx
, SL_PP_LPAREN
, &p
)) {
2145 _error(ctx
, "expected `('");
2148 if (_parse_expression(ctx
, &p
)) {
2149 _error(ctx
, "expected an expression");
2152 if (_parse_token(ctx
, SL_PP_RPAREN
, &p
)) {
2153 _error(ctx
, "expected `)'");
2156 _emit(ctx
, &p
.out
, OP_END
);
2157 if (_parse_statement(ctx
, &p
)) {
2162 if (_parse_id(ctx
, ctx
->dict
._else
, &p
) == 0) {
2163 if (_parse_statement(ctx
, &p
) == 0) {
2169 _emit(ctx
, &ps
->out
, OP_EXPRESSION
);
2170 _emit(ctx
, &ps
->out
, OP_PUSH_VOID
);
2171 _emit(ctx
, &ps
->out
, OP_END
);
2177 _parse_expression_statement(struct parse_context
*ctx
,
2178 struct parse_state
*ps
)
2180 struct parse_state p
= *ps
;
2182 if (_parse_expression(ctx
, &p
)) {
2183 _emit(ctx
, &p
.out
, OP_PUSH_VOID
);
2185 if (_parse_token(ctx
, SL_PP_SEMICOLON
, &p
)) {
2188 _emit(ctx
, &p
.out
, OP_END
);
2195 _parse_for_init_statement(struct parse_context
*ctx
,
2196 struct parse_state
*ps
)
2198 struct parse_state p
= *ps
;
2199 unsigned int e
= _emit(ctx
, &p
.out
, OP_EXPRESSION
);
2201 if (_parse_expression_statement(ctx
, &p
) == 0) {
2206 if (_parse_declaration(ctx
, &p
) == 0) {
2207 _update(ctx
, e
, OP_DECLARE
);
2217 _parse_initializer(struct parse_context
*ctx
,
2218 struct parse_state
*ps
)
2220 if (_parse_assignment_expression(ctx
, ps
) == 0) {
2221 _emit(ctx
, &ps
->out
, OP_END
);
2229 _parse_condition_initializer(struct parse_context
*ctx
,
2230 struct parse_state
*ps
)
2232 struct parse_state p
= *ps
;
2234 _emit(ctx
, &p
.out
, OP_DECLARE
);
2235 _emit(ctx
, &p
.out
, DECLARATION_INIT_DECLARATOR_LIST
);
2236 if (_parse_fully_specified_type(ctx
, &p
)) {
2239 _emit(ctx
, &p
.out
, VARIABLE_IDENTIFIER
);
2240 if (_parse_identifier(ctx
, &p
)) {
2243 if (_parse_token(ctx
, SL_PP_ASSIGN
, &p
)) {
2244 _error(ctx
, "expected `='");
2247 _emit(ctx
, &p
.out
, VARIABLE_INITIALIZER
);
2248 if (_parse_initializer(ctx
, &p
)) {
2249 _error(ctx
, "expected an initialiser");
2252 _emit(ctx
, &p
.out
, DECLARATOR_NONE
);
2259 _parse_condition(struct parse_context
*ctx
,
2260 struct parse_state
*ps
)
2262 struct parse_state p
;
2264 if (_parse_condition_initializer(ctx
, ps
) == 0) {
2269 _emit(ctx
, &p
.out
, OP_EXPRESSION
);
2270 if (_parse_expression(ctx
, &p
) == 0) {
2271 _emit(ctx
, &p
.out
, OP_END
);
2281 _parse_for_rest_statement(struct parse_context
*ctx
,
2282 struct parse_state
*ps
)
2284 struct parse_state p
= *ps
;
2286 if (_parse_condition(ctx
, &p
)) {
2287 _emit(ctx
, &p
.out
, OP_EXPRESSION
);
2288 _emit(ctx
, &p
.out
, OP_PUSH_BOOL
);
2289 _emit(ctx
, &p
.out
, 2);
2290 _emit(ctx
, &p
.out
, '1');
2291 _emit(ctx
, &p
.out
, '\0');
2292 _emit(ctx
, &p
.out
, OP_END
);
2294 if (_parse_token(ctx
, SL_PP_SEMICOLON
, &p
)) {
2297 if (_parse_expression(ctx
, &p
)) {
2298 _emit(ctx
, &p
.out
, OP_PUSH_VOID
);
2300 _emit(ctx
, &p
.out
, OP_END
);
2307 _parse_iteration_statement(struct parse_context
*ctx
,
2308 struct parse_state
*ps
)
2310 struct parse_state p
= *ps
;
2312 if (_parse_id(ctx
, ctx
->dict
._while
, &p
) == 0) {
2313 _emit(ctx
, &p
.out
, OP_WHILE
);
2314 if (_parse_token(ctx
, SL_PP_LPAREN
, &p
)) {
2315 _error(ctx
, "expected `('");
2318 if (_parse_condition(ctx
, &p
)) {
2319 _error(ctx
, "expected an expression");
2322 if (_parse_token(ctx
, SL_PP_RPAREN
, &p
)) {
2323 _error(ctx
, "expected `)'");
2326 if (_parse_statement(ctx
, &p
)) {
2333 if (_parse_id(ctx
, ctx
->dict
._do
, &p
) == 0) {
2334 _emit(ctx
, &p
.out
, OP_DO
);
2335 if (_parse_statement(ctx
, &p
)) {
2338 if (_parse_id(ctx
, ctx
->dict
._while
, &p
)) {
2341 if (_parse_token(ctx
, SL_PP_LPAREN
, &p
)) {
2342 _error(ctx
, "expected `('");
2345 if (_parse_expression(ctx
, &p
)) {
2346 _error(ctx
, "expected an expression");
2349 if (_parse_token(ctx
, SL_PP_RPAREN
, &p
)) {
2350 _error(ctx
, "expected `)'");
2353 _emit(ctx
, &p
.out
, OP_END
);
2354 if (_parse_token(ctx
, SL_PP_SEMICOLON
, &p
)) {
2355 _error(ctx
, "expected `;'");
2362 if (_parse_id(ctx
, ctx
->dict
._for
, &p
) == 0) {
2363 _emit(ctx
, &p
.out
, OP_FOR
);
2364 if (_parse_token(ctx
, SL_PP_LPAREN
, &p
)) {
2365 _error(ctx
, "expected `('");
2368 if (_parse_for_init_statement(ctx
, &p
)) {
2371 if (_parse_for_rest_statement(ctx
, &p
)) {
2374 if (_parse_token(ctx
, SL_PP_RPAREN
, &p
)) {
2375 _error(ctx
, "expected `)'");
2378 if (_parse_statement(ctx
, &p
)) {
2390 _parse_jump_statement(struct parse_context
*ctx
,
2391 struct parse_state
*ps
)
2393 struct parse_state p
= *ps
;
2394 unsigned int e
= _emit(ctx
, &p
.out
, 0);
2396 if (_parse_id(ctx
, ctx
->dict
._continue
, &p
) == 0) {
2397 _update(ctx
, e
, OP_CONTINUE
);
2398 } else if (_parse_id(ctx
, ctx
->dict
._break
, &p
) == 0) {
2399 _update(ctx
, e
, OP_BREAK
);
2400 } else if (_parse_id(ctx
, ctx
->dict
._return
, &p
) == 0) {
2401 _update(ctx
, e
, OP_RETURN
);
2402 if (_parse_expression(ctx
, &p
)) {
2403 _emit(ctx
, &p
.out
, OP_PUSH_VOID
);
2405 _emit(ctx
, &p
.out
, OP_END
);
2406 } else if (ctx
->shader_type
== 1 && _parse_id(ctx
, ctx
->dict
.discard
, &p
) == 0) {
2407 _update(ctx
, e
, OP_DISCARD
);
2411 if (_parse_token(ctx
, SL_PP_SEMICOLON
, &p
)) {
2420 _parse_simple_statement(struct parse_context
*ctx
,
2421 struct parse_state
*ps
)
2423 struct parse_state p
;
2426 if (_parse_selection_statement(ctx
, ps
) == 0) {
2430 if (_parse_iteration_statement(ctx
, ps
) == 0) {
2434 if (_parse_jump_statement(ctx
, ps
) == 0) {
2439 e
= _emit(ctx
, &p
.out
, OP_EXPRESSION
);
2440 if (_parse_expression_statement(ctx
, &p
) == 0) {
2445 if (_parse_precision_stmt(ctx
, &p
) == 0) {
2446 _update(ctx
, e
, OP_PRECISION
);
2451 if (ctx
->parsing_builtin
&& _parse_asm_statement(ctx
, &p
) == 0) {
2452 _update(ctx
, e
, OP_ASM
);
2457 if (_parse_declaration(ctx
, &p
) == 0) {
2458 _update(ctx
, e
, OP_DECLARE
);
2468 _parse_compound_statement(struct parse_context
*ctx
,
2469 struct parse_state
*ps
)
2471 struct parse_state p
= *ps
;
2473 if (_parse_token(ctx
, SL_PP_LBRACE
, &p
)) {
2476 _emit(ctx
, &p
.out
, OP_BLOCK_BEGIN_NEW_SCOPE
);
2477 _parse_statement_list(ctx
, &p
);
2478 if (_parse_token(ctx
, SL_PP_RBRACE
, &p
)) {
2481 _emit(ctx
, &p
.out
, OP_END
);
2488 _parse_statement(struct parse_context
*ctx
,
2489 struct parse_state
*ps
)
2491 if (_parse_compound_statement(ctx
, ps
) == 0) {
2495 if (_parse_simple_statement(ctx
, ps
) == 0) {
2504 _parse_statement_list(struct parse_context
*ctx
,
2505 struct parse_state
*ps
)
2507 struct parse_state p
= *ps
;
2509 if (_parse_statement(ctx
, &p
)) {
2515 if (_parse_statement(ctx
, &p
)) {
2523 _parse_compound_statement_no_new_scope(struct parse_context
*ctx
,
2524 struct parse_state
*ps
)
2526 struct parse_state p
= *ps
;
2528 if (_parse_token(ctx
, SL_PP_LBRACE
, &p
)) {
2531 _emit(ctx
, &p
.out
, OP_BLOCK_BEGIN_NO_NEW_SCOPE
);
2532 _parse_statement_list(ctx
, &p
);
2533 if (_parse_token(ctx
, SL_PP_RBRACE
, &p
)) {
2536 _emit(ctx
, &p
.out
, OP_END
);
2543 _parse_function_definition(struct parse_context
*ctx
,
2544 struct parse_state
*ps
)
2546 struct parse_state p
= *ps
;
2548 if (_parse_function_prototype(ctx
, &p
)) {
2551 if (_parse_compound_statement_no_new_scope(ctx
, &p
)) {
2560 _parse_invariant_stmt(struct parse_context
*ctx
,
2561 struct parse_state
*ps
)
2563 struct parse_state p
= *ps
;
2565 if (_parse_id(ctx
, ctx
->dict
.invariant
, &p
)) {
2568 if (_parse_identifier(ctx
, &p
)) {
2571 if (_parse_token(ctx
, SL_PP_SEMICOLON
, &p
)) {
2580 _parse_single_declaration(struct parse_context
*ctx
,
2581 struct parse_state
*ps
)
2583 struct parse_state p
= *ps
;
2586 if (_parse_fully_specified_type(ctx
, &p
)) {
2590 e
= _emit(ctx
, &p
.out
, VARIABLE_IDENTIFIER
);
2591 if (_parse_identifier(ctx
, &p
)) {
2592 _update(ctx
, e
, VARIABLE_NONE
);
2597 e
= _emit(ctx
, &p
.out
, VARIABLE_NONE
);
2600 if (_parse_token(ctx
, SL_PP_ASSIGN
, &p
) == 0) {
2601 _update(ctx
, e
, VARIABLE_INITIALIZER
);
2602 if (_parse_initializer(ctx
, &p
) == 0) {
2606 _error(ctx
, "expected an initialiser");
2611 if (_parse_token(ctx
, SL_PP_LBRACKET
, &p
) == 0) {
2612 if (_parse_constant_expression(ctx
, &p
)) {
2613 _update(ctx
, e
, VARIABLE_ARRAY_UNKNOWN
);
2615 _update(ctx
, e
, VARIABLE_ARRAY_EXPLICIT
);
2617 if (_parse_token(ctx
, SL_PP_RBRACKET
, &p
) == 0) {
2621 _error(ctx
, "expected `]'");
2629 _parse_init_declarator_list(struct parse_context
*ctx
,
2630 struct parse_state
*ps
)
2632 struct parse_state p
= *ps
;
2634 if (_parse_single_declaration(ctx
, &p
)) {
2642 if (_parse_token(ctx
, SL_PP_COMMA
, &p
)) {
2645 _emit(ctx
, &p
.out
, DECLARATOR_NEXT
);
2646 _emit(ctx
, &p
.out
, VARIABLE_IDENTIFIER
);
2647 if (_parse_identifier(ctx
, &p
)) {
2651 e
= _emit(ctx
, &p
.out
, VARIABLE_NONE
);
2654 if (_parse_token(ctx
, SL_PP_ASSIGN
, &p
) == 0) {
2655 if (_parse_initializer(ctx
, &p
) == 0) {
2656 _update(ctx
, e
, VARIABLE_INITIALIZER
);
2660 _error(ctx
, "expected an initialiser");
2665 if (_parse_token(ctx
, SL_PP_LBRACKET
, &p
) == 0) {
2668 if (_parse_constant_expression(ctx
, &p
)) {
2669 arr
= VARIABLE_ARRAY_UNKNOWN
;
2671 arr
= VARIABLE_ARRAY_EXPLICIT
;
2673 if (_parse_token(ctx
, SL_PP_RBRACKET
, &p
) == 0) {
2674 _update(ctx
, e
, arr
);
2678 _error(ctx
, "expected `]'");
2684 _emit(ctx
, &ps
->out
, DECLARATOR_NONE
);
2690 _parse_declaration(struct parse_context
*ctx
,
2691 struct parse_state
*ps
)
2693 struct parse_state p
= *ps
;
2694 unsigned int e
= _emit(ctx
, &p
.out
, DECLARATION_FUNCTION_PROTOTYPE
);
2696 if (_parse_function_prototype(ctx
, &p
)) {
2697 if (_parse_init_declarator_list(ctx
, &p
)) {
2700 _update(ctx
, e
, DECLARATION_INIT_DECLARATOR_LIST
);
2702 if (_parse_token(ctx
, SL_PP_SEMICOLON
, &p
)) {
2703 _error(ctx
, "expected `;'");
2712 _parse_external_declaration(struct parse_context
*ctx
,
2713 struct parse_state
*ps
)
2715 struct parse_state p
= *ps
;
2716 unsigned int e
= _emit(ctx
, &p
.out
, 0);
2718 if (_parse_precision_stmt(ctx
, &p
) == 0) {
2719 _update(ctx
, e
, DEFAULT_PRECISION
);
2724 if (_parse_function_definition(ctx
, &p
) == 0) {
2725 _update(ctx
, e
, EXTERNAL_FUNCTION_DEFINITION
);
2730 if (_parse_invariant_stmt(ctx
, &p
) == 0) {
2731 _update(ctx
, e
, INVARIANT_STMT
);
2736 if (_parse_declaration(ctx
, &p
) == 0) {
2737 _update(ctx
, e
, EXTERNAL_DECLARATION
);
2742 _error(ctx
, "expected an identifier");
2748 _parse_translation_unit(struct parse_context
*ctx
,
2749 struct parse_state
*ps
)
2751 _emit(ctx
, &ps
->out
, REVISION
);
2752 if (_parse_external_declaration(ctx
, ps
)) {
2755 while (_parse_external_declaration(ctx
, ps
) == 0) {
2757 _emit(ctx
, &ps
->out
, EXTERNAL_NULL
);
2758 if (_parse_token(ctx
, SL_PP_EOF
, ps
)) {
2765 #define ADD_NAME_STR(CTX, NAME, STR)\
2767 (CTX).dict.NAME = sl_pp_context_add_unique_str((CTX).context, (STR));\
2768 if ((CTX).dict.NAME == -1) {\
2773 #define ADD_NAME(CTX, NAME) ADD_NAME_STR(CTX, NAME, #NAME)
2777 sl_cl_compile(struct sl_pp_context
*context
,
2778 unsigned int shader_type
,
2779 unsigned int parsing_builtin
,
2780 unsigned char **output
,
2781 unsigned int *cboutput
,
2783 unsigned int cberror
)
2785 struct parse_context ctx
;
2786 struct parse_state ps
;
2788 ctx
.context
= context
;
2790 ADD_NAME_STR(ctx
, _void
, "void");
2791 ADD_NAME_STR(ctx
, _float
, "float");
2792 ADD_NAME_STR(ctx
, _int
, "int");
2793 ADD_NAME_STR(ctx
, _bool
, "bool");
2794 ADD_NAME(ctx
, vec2
);
2795 ADD_NAME(ctx
, vec3
);
2796 ADD_NAME(ctx
, vec4
);
2797 ADD_NAME(ctx
, bvec2
);
2798 ADD_NAME(ctx
, bvec3
);
2799 ADD_NAME(ctx
, bvec4
);
2800 ADD_NAME(ctx
, ivec2
);
2801 ADD_NAME(ctx
, ivec3
);
2802 ADD_NAME(ctx
, ivec4
);
2803 ADD_NAME(ctx
, mat2
);
2804 ADD_NAME(ctx
, mat3
);
2805 ADD_NAME(ctx
, mat4
);
2806 ADD_NAME(ctx
, mat2x3
);
2807 ADD_NAME(ctx
, mat3x2
);
2808 ADD_NAME(ctx
, mat2x4
);
2809 ADD_NAME(ctx
, mat4x2
);
2810 ADD_NAME(ctx
, mat3x4
);
2811 ADD_NAME(ctx
, mat4x3
);
2812 ADD_NAME(ctx
, sampler1D
);
2813 ADD_NAME(ctx
, sampler2D
);
2814 ADD_NAME(ctx
, sampler3D
);
2815 ADD_NAME(ctx
, samplerCube
);
2816 ADD_NAME(ctx
, sampler1DShadow
);
2817 ADD_NAME(ctx
, sampler2DShadow
);
2818 ADD_NAME(ctx
, sampler2DRect
);
2819 ADD_NAME(ctx
, sampler2DRectShadow
);
2821 ADD_NAME(ctx
, invariant
);
2823 ADD_NAME(ctx
, centroid
);
2825 ADD_NAME(ctx
, precision
);
2826 ADD_NAME(ctx
, lowp
);
2827 ADD_NAME(ctx
, mediump
);
2828 ADD_NAME(ctx
, highp
);
2830 ADD_NAME_STR(ctx
, _const
, "const");
2831 ADD_NAME(ctx
, attribute
);
2832 ADD_NAME(ctx
, varying
);
2833 ADD_NAME(ctx
, uniform
);
2834 ADD_NAME(ctx
, __fixed_output
);
2835 ADD_NAME(ctx
, __fixed_input
);
2839 ADD_NAME(ctx
, inout
);
2841 ADD_NAME(ctx
, layout
);
2842 ADD_NAME(ctx
, origin_upper_left
);
2843 ADD_NAME(ctx
, pixel_center_integer
);
2845 ADD_NAME_STR(ctx
, _struct
, "struct");
2847 ADD_NAME(ctx
, __constructor
);
2848 ADD_NAME(ctx
, __operator
);
2849 ADD_NAME_STR(ctx
, ___asm
, "__asm");
2851 ADD_NAME_STR(ctx
, _if
, "if");
2852 ADD_NAME_STR(ctx
, _else
, "else");
2853 ADD_NAME_STR(ctx
, _for
, "for");
2854 ADD_NAME_STR(ctx
, _while
, "while");
2855 ADD_NAME_STR(ctx
, _do
, "do");
2857 ADD_NAME_STR(ctx
, _continue
, "continue");
2858 ADD_NAME_STR(ctx
, _break
, "break");
2859 ADD_NAME_STR(ctx
, _return
, "return");
2860 ADD_NAME(ctx
, discard
);
2862 ADD_NAME_STR(ctx
, _false
, "false");
2863 ADD_NAME_STR(ctx
, _true
, "true");
2868 ctx
.shader_type
= shader_type
;
2869 ctx
.parsing_builtin
= 1;
2871 ctx
.error
[0] = '\0';
2872 ctx
.process_error
= 0;
2874 ctx
.tokens_cap
= 1024;
2875 ctx
.tokens_read
= 0;
2876 ctx
.tokens
= malloc(ctx
.tokens_cap
* sizeof(struct sl_pp_token_info
));
2878 strncpy(error
, "out of memory", cberror
);
2885 if (_parse_translation_unit(&ctx
, &ps
)) {
2886 strncpy(error
, ctx
.error
, cberror
);
2891 *output
= ctx
.out_buf
;