1bf215546Sopenharmony_ci%{
2bf215546Sopenharmony_ci/*
3bf215546Sopenharmony_ci * Copyright © 2009 Intel Corporation
4bf215546Sopenharmony_ci *
5bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
6bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
7bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation
8bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
10bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
11bf215546Sopenharmony_ci *
12bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next
13bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
14bf215546Sopenharmony_ci * Software.
15bf215546Sopenharmony_ci *
16bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21bf215546Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22bf215546Sopenharmony_ci * DEALINGS IN THE SOFTWARE.
23bf215546Sopenharmony_ci */
24bf215546Sopenharmony_ci
25bf215546Sopenharmony_ci#include <stdarg.h>
26bf215546Sopenharmony_ci#include <stdio.h>
27bf215546Sopenharmony_ci#include <stdlib.h>
28bf215546Sopenharmony_ci#include <string.h>
29bf215546Sopenharmony_ci
30bf215546Sopenharmony_ci#include "main/errors.h"
31bf215546Sopenharmony_ci#include "main/mtypes.h"
32bf215546Sopenharmony_ci
33bf215546Sopenharmony_ci#include "program/program.h"
34bf215546Sopenharmony_ci#include "program/prog_parameter.h"
35bf215546Sopenharmony_ci#include "program/prog_parameter_layout.h"
36bf215546Sopenharmony_ci#include "program/prog_statevars.h"
37bf215546Sopenharmony_ci#include "program/prog_instruction.h"
38bf215546Sopenharmony_ci
39bf215546Sopenharmony_ci#include "program/symbol_table.h"
40bf215546Sopenharmony_ci#include "program/program_parser.h"
41bf215546Sopenharmony_ci
42bf215546Sopenharmony_ci#include "util/u_math.h"
43bf215546Sopenharmony_ci#include "util/u_memory.h"
44bf215546Sopenharmony_ci
45bf215546Sopenharmony_cienum {
46bf215546Sopenharmony_ci   STATE_MATRIX_NO_MODIFIER,
47bf215546Sopenharmony_ci   STATE_MATRIX_INVERSE,
48bf215546Sopenharmony_ci   STATE_MATRIX_TRANSPOSE,
49bf215546Sopenharmony_ci   STATE_MATRIX_INVTRANS,
50bf215546Sopenharmony_ci};
51bf215546Sopenharmony_ci
52bf215546Sopenharmony_ciextern void *yy_scan_string(char *);
53bf215546Sopenharmony_ciextern void yy_delete_buffer(void *);
54bf215546Sopenharmony_ci
55bf215546Sopenharmony_cistatic struct asm_symbol *declare_variable(struct asm_parser_state *state,
56bf215546Sopenharmony_ci    char *name, enum asm_type t, struct YYLTYPE *locp);
57bf215546Sopenharmony_ci
58bf215546Sopenharmony_cistatic int add_state_reference(struct gl_program_parameter_list *param_list,
59bf215546Sopenharmony_ci    const gl_state_index16 tokens[STATE_LENGTH]);
60bf215546Sopenharmony_ci
61bf215546Sopenharmony_cistatic int initialize_symbol_from_state(struct gl_program *prog,
62bf215546Sopenharmony_ci    struct asm_symbol *param_var, const gl_state_index16 tokens[STATE_LENGTH]);
63bf215546Sopenharmony_ci
64bf215546Sopenharmony_cistatic int initialize_symbol_from_param(struct gl_program *prog,
65bf215546Sopenharmony_ci    struct asm_symbol *param_var, const gl_state_index16 tokens[STATE_LENGTH]);
66bf215546Sopenharmony_ci
67bf215546Sopenharmony_cistatic int initialize_symbol_from_const(struct gl_program *prog,
68bf215546Sopenharmony_ci    struct asm_symbol *param_var, const struct asm_vector *vec,
69bf215546Sopenharmony_ci    GLboolean allowSwizzle);
70bf215546Sopenharmony_ci
71bf215546Sopenharmony_cistatic int yyparse(struct asm_parser_state *state);
72bf215546Sopenharmony_ci
73bf215546Sopenharmony_cistatic char *make_error_string(const char *fmt, ...);
74bf215546Sopenharmony_ci
75bf215546Sopenharmony_cistatic void yyerror(struct YYLTYPE *locp, struct asm_parser_state *state,
76bf215546Sopenharmony_ci    const char *s);
77bf215546Sopenharmony_ci
78bf215546Sopenharmony_cistatic int validate_inputs(struct YYLTYPE *locp,
79bf215546Sopenharmony_ci    struct asm_parser_state *state);
80bf215546Sopenharmony_ci
81bf215546Sopenharmony_cistatic void init_dst_reg(struct prog_dst_register *r);
82bf215546Sopenharmony_ci
83bf215546Sopenharmony_cistatic void set_dst_reg(struct prog_dst_register *r,
84bf215546Sopenharmony_ci                        gl_register_file file, GLint index);
85bf215546Sopenharmony_ci
86bf215546Sopenharmony_cistatic void init_src_reg(struct asm_src_register *r);
87bf215546Sopenharmony_ci
88bf215546Sopenharmony_cistatic void set_src_reg(struct asm_src_register *r,
89bf215546Sopenharmony_ci                        gl_register_file file, GLint index);
90bf215546Sopenharmony_ci
91bf215546Sopenharmony_cistatic void set_src_reg_swz(struct asm_src_register *r,
92bf215546Sopenharmony_ci                            gl_register_file file, GLint index, GLuint swizzle);
93bf215546Sopenharmony_ci
94bf215546Sopenharmony_cistatic void asm_instruction_set_operands(struct asm_instruction *inst,
95bf215546Sopenharmony_ci    const struct prog_dst_register *dst, const struct asm_src_register *src0,
96bf215546Sopenharmony_ci    const struct asm_src_register *src1, const struct asm_src_register *src2);
97bf215546Sopenharmony_ci
98bf215546Sopenharmony_cistatic struct asm_instruction *asm_instruction_ctor(enum prog_opcode op,
99bf215546Sopenharmony_ci    const struct prog_dst_register *dst, const struct asm_src_register *src0,
100bf215546Sopenharmony_ci    const struct asm_src_register *src1, const struct asm_src_register *src2);
101bf215546Sopenharmony_ci
102bf215546Sopenharmony_cistatic struct asm_instruction *asm_instruction_copy_ctor(
103bf215546Sopenharmony_ci    const struct prog_instruction *base, const struct prog_dst_register *dst,
104bf215546Sopenharmony_ci    const struct asm_src_register *src0, const struct asm_src_register *src1,
105bf215546Sopenharmony_ci    const struct asm_src_register *src2);
106bf215546Sopenharmony_ci
107bf215546Sopenharmony_ci#ifndef FALSE
108bf215546Sopenharmony_ci#define FALSE 0
109bf215546Sopenharmony_ci#define TRUE (!FALSE)
110bf215546Sopenharmony_ci#endif
111bf215546Sopenharmony_ci
112bf215546Sopenharmony_ci#define YYLLOC_DEFAULT(Current, Rhs, N)					\
113bf215546Sopenharmony_ci   do {									\
114bf215546Sopenharmony_ci      if (N) {							\
115bf215546Sopenharmony_ci	 (Current).first_line = YYRHSLOC(Rhs, 1).first_line;		\
116bf215546Sopenharmony_ci	 (Current).first_column = YYRHSLOC(Rhs, 1).first_column;	\
117bf215546Sopenharmony_ci	 (Current).position = YYRHSLOC(Rhs, 1).position;		\
118bf215546Sopenharmony_ci	 (Current).last_line = YYRHSLOC(Rhs, N).last_line;		\
119bf215546Sopenharmony_ci	 (Current).last_column = YYRHSLOC(Rhs, N).last_column;		\
120bf215546Sopenharmony_ci      } else {								\
121bf215546Sopenharmony_ci	 (Current).first_line = YYRHSLOC(Rhs, 0).last_line;		\
122bf215546Sopenharmony_ci	 (Current).last_line = (Current).first_line;			\
123bf215546Sopenharmony_ci	 (Current).first_column = YYRHSLOC(Rhs, 0).last_column;		\
124bf215546Sopenharmony_ci	 (Current).last_column = (Current).first_column;		\
125bf215546Sopenharmony_ci	 (Current).position = YYRHSLOC(Rhs, 0).position			\
126bf215546Sopenharmony_ci	    + (Current).first_column;					\
127bf215546Sopenharmony_ci      }									\
128bf215546Sopenharmony_ci   } while(0)
129bf215546Sopenharmony_ci%}
130bf215546Sopenharmony_ci
131bf215546Sopenharmony_ci%pure-parser
132bf215546Sopenharmony_ci%locations
133bf215546Sopenharmony_ci%lex-param   { struct asm_parser_state *state }
134bf215546Sopenharmony_ci%parse-param { struct asm_parser_state *state }
135bf215546Sopenharmony_ci%error-verbose
136bf215546Sopenharmony_ci
137bf215546Sopenharmony_ci%union {
138bf215546Sopenharmony_ci   struct asm_instruction *inst;
139bf215546Sopenharmony_ci   struct asm_symbol *sym;
140bf215546Sopenharmony_ci   struct asm_symbol temp_sym;
141bf215546Sopenharmony_ci   struct asm_swizzle_mask swiz_mask;
142bf215546Sopenharmony_ci   struct asm_src_register src_reg;
143bf215546Sopenharmony_ci   struct prog_dst_register dst_reg;
144bf215546Sopenharmony_ci   struct prog_instruction temp_inst;
145bf215546Sopenharmony_ci   char *string;
146bf215546Sopenharmony_ci   unsigned result;
147bf215546Sopenharmony_ci   unsigned attrib;
148bf215546Sopenharmony_ci   int integer;
149bf215546Sopenharmony_ci   float real;
150bf215546Sopenharmony_ci   gl_state_index16 state[STATE_LENGTH];
151bf215546Sopenharmony_ci   int negate;
152bf215546Sopenharmony_ci   struct asm_vector vector;
153bf215546Sopenharmony_ci   enum prog_opcode opcode;
154bf215546Sopenharmony_ci
155bf215546Sopenharmony_ci   struct {
156bf215546Sopenharmony_ci      unsigned swz;
157bf215546Sopenharmony_ci      unsigned rgba_valid:1;
158bf215546Sopenharmony_ci      unsigned xyzw_valid:1;
159bf215546Sopenharmony_ci      unsigned negate:1;
160bf215546Sopenharmony_ci   } ext_swizzle;
161bf215546Sopenharmony_ci}
162bf215546Sopenharmony_ci
163bf215546Sopenharmony_ci%token ARBvp_10 ARBfp_10
164bf215546Sopenharmony_ci
165bf215546Sopenharmony_ci/* Tokens for assembler pseudo-ops */
166bf215546Sopenharmony_ci%token <integer> ADDRESS
167bf215546Sopenharmony_ci%token ALIAS ATTRIB
168bf215546Sopenharmony_ci%token OPTION OUTPUT
169bf215546Sopenharmony_ci%token PARAM
170bf215546Sopenharmony_ci%token <integer> TEMP
171bf215546Sopenharmony_ci%token END
172bf215546Sopenharmony_ci
173bf215546Sopenharmony_ci /* Tokens for instructions */
174bf215546Sopenharmony_ci%token <temp_inst> BIN_OP BINSC_OP SAMPLE_OP SCALAR_OP TRI_OP VECTOR_OP
175bf215546Sopenharmony_ci%token <temp_inst> ARL KIL SWZ TXD_OP
176bf215546Sopenharmony_ci
177bf215546Sopenharmony_ci%token <integer> INTEGER
178bf215546Sopenharmony_ci%token <real> REAL
179bf215546Sopenharmony_ci
180bf215546Sopenharmony_ci%token AMBIENT ATTENUATION
181bf215546Sopenharmony_ci%token BACK
182bf215546Sopenharmony_ci%token CLIP COLOR
183bf215546Sopenharmony_ci%token DEPTH DIFFUSE DIRECTION
184bf215546Sopenharmony_ci%token EMISSION ENV EYE
185bf215546Sopenharmony_ci%token FOG FOGCOORD FRAGMENT FRONT
186bf215546Sopenharmony_ci%token HALF
187bf215546Sopenharmony_ci%token INVERSE INVTRANS
188bf215546Sopenharmony_ci%token LIGHT LIGHTMODEL LIGHTPROD LOCAL
189bf215546Sopenharmony_ci%token MATERIAL MAT_PROGRAM MATRIX MATRIXINDEX MODELVIEW MVP
190bf215546Sopenharmony_ci%token NORMAL
191bf215546Sopenharmony_ci%token OBJECT
192bf215546Sopenharmony_ci%token PALETTE PARAMS PLANE POINT_TOK POINTSIZE POSITION PRIMARY PROGRAM PROJECTION
193bf215546Sopenharmony_ci%token RANGE RESULT ROW
194bf215546Sopenharmony_ci%token SCENECOLOR SECONDARY SHININESS SIZE_TOK SPECULAR SPOT STATE
195bf215546Sopenharmony_ci%token TEXCOORD TEXENV TEXGEN TEXGEN_Q TEXGEN_R TEXGEN_S TEXGEN_T TEXTURE TRANSPOSE
196bf215546Sopenharmony_ci%token TEXTURE_UNIT TEX_1D TEX_2D TEX_3D TEX_CUBE TEX_RECT
197bf215546Sopenharmony_ci%token TEX_SHADOW1D TEX_SHADOW2D TEX_SHADOWRECT
198bf215546Sopenharmony_ci%token TEX_ARRAY1D TEX_ARRAY2D TEX_ARRAYSHADOW1D TEX_ARRAYSHADOW2D
199bf215546Sopenharmony_ci%token VERTEX VTXATTRIB
200bf215546Sopenharmony_ci
201bf215546Sopenharmony_ci%token <string> IDENTIFIER USED_IDENTIFIER
202bf215546Sopenharmony_ci%type <string> string
203bf215546Sopenharmony_ci%token <swiz_mask> MASK4 MASK3 MASK2 MASK1 SWIZZLE
204bf215546Sopenharmony_ci%token DOT_DOT
205bf215546Sopenharmony_ci%token DOT
206bf215546Sopenharmony_ci
207bf215546Sopenharmony_ci%type <inst> instruction ALU_instruction TexInstruction
208bf215546Sopenharmony_ci%type <inst> ARL_instruction VECTORop_instruction
209bf215546Sopenharmony_ci%type <inst> SCALARop_instruction BINSCop_instruction BINop_instruction
210bf215546Sopenharmony_ci%type <inst> TRIop_instruction TXD_instruction SWZ_instruction SAMPLE_instruction
211bf215546Sopenharmony_ci%type <inst> KIL_instruction
212bf215546Sopenharmony_ci
213bf215546Sopenharmony_ci%type <dst_reg> dstReg maskedDstReg maskedAddrReg
214bf215546Sopenharmony_ci%type <src_reg> srcReg scalarUse scalarSrcReg swizzleSrcReg
215bf215546Sopenharmony_ci%type <swiz_mask> scalarSuffix swizzleSuffix extendedSwizzle
216bf215546Sopenharmony_ci%type <ext_swizzle> extSwizComp extSwizSel
217bf215546Sopenharmony_ci%type <swiz_mask> optionalMask
218bf215546Sopenharmony_ci
219bf215546Sopenharmony_ci%type <sym> progParamArray
220bf215546Sopenharmony_ci%type <integer> addrRegRelOffset addrRegPosOffset addrRegNegOffset
221bf215546Sopenharmony_ci%type <src_reg> progParamArrayMem progParamArrayAbs progParamArrayRel
222bf215546Sopenharmony_ci%type <sym> addrReg
223bf215546Sopenharmony_ci%type <swiz_mask> addrComponent addrWriteMask
224bf215546Sopenharmony_ci
225bf215546Sopenharmony_ci%type <result> resultBinding resultColBinding
226bf215546Sopenharmony_ci%type <integer> optFaceType optColorType
227bf215546Sopenharmony_ci%type <integer> optResultFaceType optResultColorType
228bf215546Sopenharmony_ci
229bf215546Sopenharmony_ci%type <integer> optTexImageUnitNum texImageUnitNum
230bf215546Sopenharmony_ci%type <integer> optTexCoordUnitNum texCoordUnitNum
231bf215546Sopenharmony_ci%type <integer> optLegacyTexUnitNum legacyTexUnitNum
232bf215546Sopenharmony_ci%type <integer> texImageUnit texTarget
233bf215546Sopenharmony_ci%type <integer> vtxAttribNum
234bf215546Sopenharmony_ci
235bf215546Sopenharmony_ci%type <attrib> attribBinding vtxAttribItem fragAttribItem
236bf215546Sopenharmony_ci
237bf215546Sopenharmony_ci%type <temp_sym> paramSingleInit paramSingleItemDecl
238bf215546Sopenharmony_ci%type <integer> optArraySize
239bf215546Sopenharmony_ci
240bf215546Sopenharmony_ci%type <state> stateSingleItem stateMultipleItem
241bf215546Sopenharmony_ci%type <state> stateMaterialItem
242bf215546Sopenharmony_ci%type <state> stateLightItem stateLightModelItem stateLightProdItem
243bf215546Sopenharmony_ci%type <state> stateTexGenItem stateFogItem stateClipPlaneItem statePointItem
244bf215546Sopenharmony_ci%type <state> stateMatrixItem stateMatrixRow stateMatrixRows
245bf215546Sopenharmony_ci%type <state> stateTexEnvItem stateDepthItem
246bf215546Sopenharmony_ci
247bf215546Sopenharmony_ci%type <state> stateLModProperty
248bf215546Sopenharmony_ci%type <state> stateMatrixName optMatrixRows
249bf215546Sopenharmony_ci
250bf215546Sopenharmony_ci%type <integer> stateMatProperty
251bf215546Sopenharmony_ci%type <integer> stateLightProperty stateSpotProperty
252bf215546Sopenharmony_ci%type <integer> stateLightNumber stateLProdProperty
253bf215546Sopenharmony_ci%type <integer> stateTexGenType stateTexGenCoord
254bf215546Sopenharmony_ci%type <integer> stateTexEnvProperty
255bf215546Sopenharmony_ci%type <integer> stateFogProperty
256bf215546Sopenharmony_ci%type <integer> stateClipPlaneNum
257bf215546Sopenharmony_ci%type <integer> statePointProperty
258bf215546Sopenharmony_ci
259bf215546Sopenharmony_ci%type <integer> stateOptMatModifier stateMatModifier stateMatrixRowNum
260bf215546Sopenharmony_ci%type <integer> stateOptModMatNum stateModMatNum statePaletteMatNum
261bf215546Sopenharmony_ci%type <integer> stateProgramMatNum
262bf215546Sopenharmony_ci
263bf215546Sopenharmony_ci%type <integer> ambDiffSpecPropertyMaterial
264bf215546Sopenharmony_ci%type <integer> ambDiffSpecPropertyLight
265bf215546Sopenharmony_ci
266bf215546Sopenharmony_ci%type <state> programSingleItem progEnvParam progLocalParam
267bf215546Sopenharmony_ci%type <state> programMultipleItem progEnvParams progLocalParams
268bf215546Sopenharmony_ci
269bf215546Sopenharmony_ci%type <temp_sym> paramMultipleInit paramMultInitList paramMultipleItem
270bf215546Sopenharmony_ci%type <temp_sym> paramSingleItemUse
271bf215546Sopenharmony_ci
272bf215546Sopenharmony_ci%type <integer> progEnvParamNum progLocalParamNum
273bf215546Sopenharmony_ci%type <state> progEnvParamNums progLocalParamNums
274bf215546Sopenharmony_ci
275bf215546Sopenharmony_ci%type <vector> paramConstDecl paramConstUse
276bf215546Sopenharmony_ci%type <vector> paramConstScalarDecl paramConstScalarUse paramConstVector
277bf215546Sopenharmony_ci%type <real> signedFloatConstant
278bf215546Sopenharmony_ci%type <negate> optionalSign
279bf215546Sopenharmony_ci
280bf215546Sopenharmony_ci%{
281bf215546Sopenharmony_ciextern int
282bf215546Sopenharmony_ci_mesa_program_lexer_lex(YYSTYPE *yylval_param, YYLTYPE *yylloc_param,
283bf215546Sopenharmony_ci                        void *yyscanner);
284bf215546Sopenharmony_ci
285bf215546Sopenharmony_cistatic int
286bf215546Sopenharmony_ciyylex(YYSTYPE *yylval_param, YYLTYPE *yylloc_param,
287bf215546Sopenharmony_ci      struct asm_parser_state *state)
288bf215546Sopenharmony_ci{
289bf215546Sopenharmony_ci   return _mesa_program_lexer_lex(yylval_param, yylloc_param, state->scanner);
290bf215546Sopenharmony_ci}
291bf215546Sopenharmony_ci%}
292bf215546Sopenharmony_ci
293bf215546Sopenharmony_ci%%
294bf215546Sopenharmony_ci
295bf215546Sopenharmony_ciprogram: language optionSequence statementSequence END
296bf215546Sopenharmony_ci	;
297bf215546Sopenharmony_ci
298bf215546Sopenharmony_cilanguage: ARBvp_10
299bf215546Sopenharmony_ci	{
300bf215546Sopenharmony_ci	   if (state->prog->Target != GL_VERTEX_PROGRAM_ARB) {
301bf215546Sopenharmony_ci	      yyerror(& @1, state, "invalid fragment program header");
302bf215546Sopenharmony_ci
303bf215546Sopenharmony_ci	   }
304bf215546Sopenharmony_ci	   state->mode = ARB_vertex;
305bf215546Sopenharmony_ci	}
306bf215546Sopenharmony_ci	| ARBfp_10
307bf215546Sopenharmony_ci	{
308bf215546Sopenharmony_ci	   if (state->prog->Target != GL_FRAGMENT_PROGRAM_ARB) {
309bf215546Sopenharmony_ci	      yyerror(& @1, state, "invalid vertex program header");
310bf215546Sopenharmony_ci	   }
311bf215546Sopenharmony_ci	   state->mode = ARB_fragment;
312bf215546Sopenharmony_ci
313bf215546Sopenharmony_ci	   state->option.TexRect =
314bf215546Sopenharmony_ci	      (state->ctx->Extensions.NV_texture_rectangle != GL_FALSE);
315bf215546Sopenharmony_ci	}
316bf215546Sopenharmony_ci	;
317bf215546Sopenharmony_ci
318bf215546Sopenharmony_cioptionSequence: optionSequence option
319bf215546Sopenharmony_ci	|
320bf215546Sopenharmony_ci	;
321bf215546Sopenharmony_ci
322bf215546Sopenharmony_cioption: OPTION string ';'
323bf215546Sopenharmony_ci	{
324bf215546Sopenharmony_ci	   int valid = 0;
325bf215546Sopenharmony_ci
326bf215546Sopenharmony_ci	   if (state->mode == ARB_vertex) {
327bf215546Sopenharmony_ci	      valid = _mesa_ARBvp_parse_option(state, $2);
328bf215546Sopenharmony_ci	   } else if (state->mode == ARB_fragment) {
329bf215546Sopenharmony_ci	      valid = _mesa_ARBfp_parse_option(state, $2);
330bf215546Sopenharmony_ci	   }
331bf215546Sopenharmony_ci
332bf215546Sopenharmony_ci
333bf215546Sopenharmony_ci	   free($2);
334bf215546Sopenharmony_ci
335bf215546Sopenharmony_ci	   if (!valid) {
336bf215546Sopenharmony_ci	      const char *const err_str = (state->mode == ARB_vertex)
337bf215546Sopenharmony_ci		 ? "invalid ARB vertex program option"
338bf215546Sopenharmony_ci		 : "invalid ARB fragment program option";
339bf215546Sopenharmony_ci
340bf215546Sopenharmony_ci	      yyerror(& @2, state, err_str);
341bf215546Sopenharmony_ci	      YYERROR;
342bf215546Sopenharmony_ci	   }
343bf215546Sopenharmony_ci	}
344bf215546Sopenharmony_ci	;
345bf215546Sopenharmony_ci
346bf215546Sopenharmony_cistatementSequence: statementSequence statement
347bf215546Sopenharmony_ci	|
348bf215546Sopenharmony_ci	;
349bf215546Sopenharmony_ci
350bf215546Sopenharmony_cistatement: instruction ';'
351bf215546Sopenharmony_ci	{
352bf215546Sopenharmony_ci	   if ($1 != NULL) {
353bf215546Sopenharmony_ci	      if (state->inst_tail == NULL) {
354bf215546Sopenharmony_ci		 state->inst_head = $1;
355bf215546Sopenharmony_ci	      } else {
356bf215546Sopenharmony_ci		 state->inst_tail->next = $1;
357bf215546Sopenharmony_ci	      }
358bf215546Sopenharmony_ci
359bf215546Sopenharmony_ci	      state->inst_tail = $1;
360bf215546Sopenharmony_ci	      $1->next = NULL;
361bf215546Sopenharmony_ci
362bf215546Sopenharmony_ci              state->prog->arb.NumInstructions++;
363bf215546Sopenharmony_ci	   }
364bf215546Sopenharmony_ci	}
365bf215546Sopenharmony_ci	| namingStatement ';'
366bf215546Sopenharmony_ci	;
367bf215546Sopenharmony_ci
368bf215546Sopenharmony_ciinstruction: ALU_instruction
369bf215546Sopenharmony_ci	{
370bf215546Sopenharmony_ci	   $$ = $1;
371bf215546Sopenharmony_ci           state->prog->arb.NumAluInstructions++;
372bf215546Sopenharmony_ci	}
373bf215546Sopenharmony_ci	| TexInstruction
374bf215546Sopenharmony_ci	{
375bf215546Sopenharmony_ci	   $$ = $1;
376bf215546Sopenharmony_ci           state->prog->arb.NumTexInstructions++;
377bf215546Sopenharmony_ci	}
378bf215546Sopenharmony_ci	;
379bf215546Sopenharmony_ci
380bf215546Sopenharmony_ciALU_instruction: ARL_instruction
381bf215546Sopenharmony_ci	| VECTORop_instruction
382bf215546Sopenharmony_ci	| SCALARop_instruction
383bf215546Sopenharmony_ci	| BINSCop_instruction
384bf215546Sopenharmony_ci	| BINop_instruction
385bf215546Sopenharmony_ci	| TRIop_instruction
386bf215546Sopenharmony_ci	| SWZ_instruction
387bf215546Sopenharmony_ci	;
388bf215546Sopenharmony_ci
389bf215546Sopenharmony_ciTexInstruction: SAMPLE_instruction
390bf215546Sopenharmony_ci	| KIL_instruction
391bf215546Sopenharmony_ci	| TXD_instruction
392bf215546Sopenharmony_ci	;
393bf215546Sopenharmony_ci
394bf215546Sopenharmony_ciARL_instruction: ARL maskedAddrReg ',' scalarSrcReg
395bf215546Sopenharmony_ci	{
396bf215546Sopenharmony_ci	   $$ = asm_instruction_ctor(OPCODE_ARL, & $2, & $4, NULL, NULL);
397bf215546Sopenharmony_ci	}
398bf215546Sopenharmony_ci	;
399bf215546Sopenharmony_ci
400bf215546Sopenharmony_ciVECTORop_instruction: VECTOR_OP maskedDstReg ',' swizzleSrcReg
401bf215546Sopenharmony_ci	{
402bf215546Sopenharmony_ci	   $$ = asm_instruction_copy_ctor(& $1, & $2, & $4, NULL, NULL);
403bf215546Sopenharmony_ci	}
404bf215546Sopenharmony_ci	;
405bf215546Sopenharmony_ci
406bf215546Sopenharmony_ciSCALARop_instruction: SCALAR_OP maskedDstReg ',' scalarSrcReg
407bf215546Sopenharmony_ci	{
408bf215546Sopenharmony_ci	   $$ = asm_instruction_copy_ctor(& $1, & $2, & $4, NULL, NULL);
409bf215546Sopenharmony_ci	}
410bf215546Sopenharmony_ci	;
411bf215546Sopenharmony_ci
412bf215546Sopenharmony_ciBINSCop_instruction: BINSC_OP maskedDstReg ',' scalarSrcReg ',' scalarSrcReg
413bf215546Sopenharmony_ci	{
414bf215546Sopenharmony_ci	   $$ = asm_instruction_copy_ctor(& $1, & $2, & $4, & $6, NULL);
415bf215546Sopenharmony_ci	}
416bf215546Sopenharmony_ci	;
417bf215546Sopenharmony_ci
418bf215546Sopenharmony_ci
419bf215546Sopenharmony_ciBINop_instruction: BIN_OP maskedDstReg ',' swizzleSrcReg ',' swizzleSrcReg
420bf215546Sopenharmony_ci	{
421bf215546Sopenharmony_ci	   $$ = asm_instruction_copy_ctor(& $1, & $2, & $4, & $6, NULL);
422bf215546Sopenharmony_ci	}
423bf215546Sopenharmony_ci	;
424bf215546Sopenharmony_ci
425bf215546Sopenharmony_ciTRIop_instruction: TRI_OP maskedDstReg ','
426bf215546Sopenharmony_ci                   swizzleSrcReg ',' swizzleSrcReg ',' swizzleSrcReg
427bf215546Sopenharmony_ci	{
428bf215546Sopenharmony_ci	   $$ = asm_instruction_copy_ctor(& $1, & $2, & $4, & $6, & $8);
429bf215546Sopenharmony_ci	}
430bf215546Sopenharmony_ci	;
431bf215546Sopenharmony_ci
432bf215546Sopenharmony_ciSAMPLE_instruction: SAMPLE_OP maskedDstReg ',' swizzleSrcReg ',' texImageUnit ',' texTarget
433bf215546Sopenharmony_ci	{
434bf215546Sopenharmony_ci	   $$ = asm_instruction_copy_ctor(& $1, & $2, & $4, NULL, NULL);
435bf215546Sopenharmony_ci	   if ($$ != NULL) {
436bf215546Sopenharmony_ci	      const GLbitfield tex_mask = (1U << $6);
437bf215546Sopenharmony_ci	      GLbitfield shadow_tex = 0;
438bf215546Sopenharmony_ci	      GLbitfield target_mask = 0;
439bf215546Sopenharmony_ci
440bf215546Sopenharmony_ci
441bf215546Sopenharmony_ci	      $$->Base.TexSrcUnit = $6;
442bf215546Sopenharmony_ci
443bf215546Sopenharmony_ci	      if ($8 < 0) {
444bf215546Sopenharmony_ci		 shadow_tex = tex_mask;
445bf215546Sopenharmony_ci
446bf215546Sopenharmony_ci		 $$->Base.TexSrcTarget = -$8;
447bf215546Sopenharmony_ci		 $$->Base.TexShadow = 1;
448bf215546Sopenharmony_ci	      } else {
449bf215546Sopenharmony_ci		 $$->Base.TexSrcTarget = $8;
450bf215546Sopenharmony_ci	      }
451bf215546Sopenharmony_ci
452bf215546Sopenharmony_ci	      target_mask = (1U << $$->Base.TexSrcTarget);
453bf215546Sopenharmony_ci
454bf215546Sopenharmony_ci	      /* If this texture unit was previously accessed and that access
455bf215546Sopenharmony_ci	       * had a different texture target, generate an error.
456bf215546Sopenharmony_ci	       *
457bf215546Sopenharmony_ci	       * If this texture unit was previously accessed and that access
458bf215546Sopenharmony_ci	       * had a different shadow mode, generate an error.
459bf215546Sopenharmony_ci	       */
460bf215546Sopenharmony_ci	      if ((state->prog->TexturesUsed[$6] != 0)
461bf215546Sopenharmony_ci		  && ((state->prog->TexturesUsed[$6] != target_mask)
462bf215546Sopenharmony_ci		      || ((state->prog->ShadowSamplers & tex_mask)
463bf215546Sopenharmony_ci			  != shadow_tex))) {
464bf215546Sopenharmony_ci		 yyerror(& @8, state,
465bf215546Sopenharmony_ci			 "multiple targets used on one texture image unit");
466bf215546Sopenharmony_ci		 YYERROR;
467bf215546Sopenharmony_ci	      }
468bf215546Sopenharmony_ci
469bf215546Sopenharmony_ci
470bf215546Sopenharmony_ci	      state->prog->TexturesUsed[$6] |= target_mask;
471bf215546Sopenharmony_ci	      state->prog->ShadowSamplers |= shadow_tex;
472bf215546Sopenharmony_ci	   }
473bf215546Sopenharmony_ci	}
474bf215546Sopenharmony_ci	;
475bf215546Sopenharmony_ci
476bf215546Sopenharmony_ciKIL_instruction: KIL swizzleSrcReg
477bf215546Sopenharmony_ci	{
478bf215546Sopenharmony_ci	   $$ = asm_instruction_ctor(OPCODE_KIL, NULL, & $2, NULL, NULL);
479bf215546Sopenharmony_ci	   state->fragment.UsesKill = 1;
480bf215546Sopenharmony_ci	}
481bf215546Sopenharmony_ci	;
482bf215546Sopenharmony_ci
483bf215546Sopenharmony_ciTXD_instruction: TXD_OP maskedDstReg ',' swizzleSrcReg ',' swizzleSrcReg ',' swizzleSrcReg ',' texImageUnit ',' texTarget
484bf215546Sopenharmony_ci	{
485bf215546Sopenharmony_ci	   $$ = asm_instruction_copy_ctor(& $1, & $2, & $4, & $6, & $8);
486bf215546Sopenharmony_ci	   if ($$ != NULL) {
487bf215546Sopenharmony_ci	      const GLbitfield tex_mask = (1U << $10);
488bf215546Sopenharmony_ci	      GLbitfield shadow_tex = 0;
489bf215546Sopenharmony_ci	      GLbitfield target_mask = 0;
490bf215546Sopenharmony_ci
491bf215546Sopenharmony_ci
492bf215546Sopenharmony_ci	      $$->Base.TexSrcUnit = $10;
493bf215546Sopenharmony_ci
494bf215546Sopenharmony_ci	      if ($12 < 0) {
495bf215546Sopenharmony_ci		 shadow_tex = tex_mask;
496bf215546Sopenharmony_ci
497bf215546Sopenharmony_ci		 $$->Base.TexSrcTarget = -$12;
498bf215546Sopenharmony_ci		 $$->Base.TexShadow = 1;
499bf215546Sopenharmony_ci	      } else {
500bf215546Sopenharmony_ci		 $$->Base.TexSrcTarget = $12;
501bf215546Sopenharmony_ci	      }
502bf215546Sopenharmony_ci
503bf215546Sopenharmony_ci	      target_mask = (1U << $$->Base.TexSrcTarget);
504bf215546Sopenharmony_ci
505bf215546Sopenharmony_ci	      /* If this texture unit was previously accessed and that access
506bf215546Sopenharmony_ci	       * had a different texture target, generate an error.
507bf215546Sopenharmony_ci	       *
508bf215546Sopenharmony_ci	       * If this texture unit was previously accessed and that access
509bf215546Sopenharmony_ci	       * had a different shadow mode, generate an error.
510bf215546Sopenharmony_ci	       */
511bf215546Sopenharmony_ci	      if ((state->prog->TexturesUsed[$10] != 0)
512bf215546Sopenharmony_ci		  && ((state->prog->TexturesUsed[$10] != target_mask)
513bf215546Sopenharmony_ci		      || ((state->prog->ShadowSamplers & tex_mask)
514bf215546Sopenharmony_ci			  != shadow_tex))) {
515bf215546Sopenharmony_ci		 yyerror(& @12, state,
516bf215546Sopenharmony_ci			 "multiple targets used on one texture image unit");
517bf215546Sopenharmony_ci		 YYERROR;
518bf215546Sopenharmony_ci	      }
519bf215546Sopenharmony_ci
520bf215546Sopenharmony_ci
521bf215546Sopenharmony_ci	      state->prog->TexturesUsed[$10] |= target_mask;
522bf215546Sopenharmony_ci	      state->prog->ShadowSamplers |= shadow_tex;
523bf215546Sopenharmony_ci	   }
524bf215546Sopenharmony_ci	}
525bf215546Sopenharmony_ci	;
526bf215546Sopenharmony_ci
527bf215546Sopenharmony_citexImageUnit: TEXTURE_UNIT optTexImageUnitNum
528bf215546Sopenharmony_ci	{
529bf215546Sopenharmony_ci	   $$ = $2;
530bf215546Sopenharmony_ci	}
531bf215546Sopenharmony_ci	;
532bf215546Sopenharmony_ci
533bf215546Sopenharmony_citexTarget: TEX_1D  { $$ = TEXTURE_1D_INDEX; }
534bf215546Sopenharmony_ci	| TEX_2D   { $$ = TEXTURE_2D_INDEX; }
535bf215546Sopenharmony_ci	| TEX_3D   { $$ = TEXTURE_3D_INDEX; }
536bf215546Sopenharmony_ci	| TEX_CUBE { $$ = TEXTURE_CUBE_INDEX; }
537bf215546Sopenharmony_ci	| TEX_RECT { $$ = TEXTURE_RECT_INDEX; }
538bf215546Sopenharmony_ci	| TEX_SHADOW1D   { $$ = -TEXTURE_1D_INDEX; }
539bf215546Sopenharmony_ci	| TEX_SHADOW2D   { $$ = -TEXTURE_2D_INDEX; }
540bf215546Sopenharmony_ci	| TEX_SHADOWRECT { $$ = -TEXTURE_RECT_INDEX; }
541bf215546Sopenharmony_ci	| TEX_ARRAY1D         { $$ = TEXTURE_1D_ARRAY_INDEX; }
542bf215546Sopenharmony_ci	| TEX_ARRAY2D         { $$ = TEXTURE_2D_ARRAY_INDEX; }
543bf215546Sopenharmony_ci	| TEX_ARRAYSHADOW1D   { $$ = -TEXTURE_1D_ARRAY_INDEX; }
544bf215546Sopenharmony_ci	| TEX_ARRAYSHADOW2D   { $$ = -TEXTURE_2D_ARRAY_INDEX; }
545bf215546Sopenharmony_ci	;
546bf215546Sopenharmony_ci
547bf215546Sopenharmony_ciSWZ_instruction: SWZ maskedDstReg ',' srcReg ',' extendedSwizzle
548bf215546Sopenharmony_ci	{
549bf215546Sopenharmony_ci	   /* FIXME: Is this correct?  Should the extenedSwizzle be applied
550bf215546Sopenharmony_ci	    * FIXME: to the existing swizzle?
551bf215546Sopenharmony_ci	    */
552bf215546Sopenharmony_ci	   $4.Base.Swizzle = $6.swizzle;
553bf215546Sopenharmony_ci	   $4.Base.Negate = $6.mask;
554bf215546Sopenharmony_ci
555bf215546Sopenharmony_ci	   $$ = asm_instruction_copy_ctor(& $1, & $2, & $4, NULL, NULL);
556bf215546Sopenharmony_ci	}
557bf215546Sopenharmony_ci	;
558bf215546Sopenharmony_ci
559bf215546Sopenharmony_ciscalarSrcReg: optionalSign scalarUse
560bf215546Sopenharmony_ci	{
561bf215546Sopenharmony_ci	   $$ = $2;
562bf215546Sopenharmony_ci
563bf215546Sopenharmony_ci	   if ($1) {
564bf215546Sopenharmony_ci	      $$.Base.Negate = ~$$.Base.Negate;
565bf215546Sopenharmony_ci	   }
566bf215546Sopenharmony_ci	}
567bf215546Sopenharmony_ci	;
568bf215546Sopenharmony_ci
569bf215546Sopenharmony_ciscalarUse:  srcReg scalarSuffix
570bf215546Sopenharmony_ci	{
571bf215546Sopenharmony_ci	   $$ = $1;
572bf215546Sopenharmony_ci
573bf215546Sopenharmony_ci	   $$.Base.Swizzle = _mesa_combine_swizzles($$.Base.Swizzle,
574bf215546Sopenharmony_ci						    $2.swizzle);
575bf215546Sopenharmony_ci	}
576bf215546Sopenharmony_ci	;
577bf215546Sopenharmony_ci
578bf215546Sopenharmony_ciswizzleSrcReg: optionalSign srcReg swizzleSuffix
579bf215546Sopenharmony_ci	{
580bf215546Sopenharmony_ci	   $$ = $2;
581bf215546Sopenharmony_ci
582bf215546Sopenharmony_ci	   if ($1) {
583bf215546Sopenharmony_ci	      $$.Base.Negate = ~$$.Base.Negate;
584bf215546Sopenharmony_ci	   }
585bf215546Sopenharmony_ci
586bf215546Sopenharmony_ci	   $$.Base.Swizzle = _mesa_combine_swizzles($$.Base.Swizzle,
587bf215546Sopenharmony_ci						    $3.swizzle);
588bf215546Sopenharmony_ci	}
589bf215546Sopenharmony_ci	;
590bf215546Sopenharmony_ci
591bf215546Sopenharmony_cimaskedDstReg: dstReg optionalMask
592bf215546Sopenharmony_ci	{
593bf215546Sopenharmony_ci	   $$ = $1;
594bf215546Sopenharmony_ci	   $$.WriteMask = $2.mask;
595bf215546Sopenharmony_ci
596bf215546Sopenharmony_ci	   if ($$.File == PROGRAM_OUTPUT) {
597bf215546Sopenharmony_ci	      /* Technically speaking, this should check that it is in
598bf215546Sopenharmony_ci	       * vertex program mode.  However, PositionInvariant can never be
599bf215546Sopenharmony_ci	       * set in fragment program mode, so it is somewhat irrelevant.
600bf215546Sopenharmony_ci	       */
601bf215546Sopenharmony_ci	      if (state->option.PositionInvariant
602bf215546Sopenharmony_ci	       && ($$.Index == VARYING_SLOT_POS)) {
603bf215546Sopenharmony_ci		 yyerror(& @1, state, "position-invariant programs cannot "
604bf215546Sopenharmony_ci			 "write position");
605bf215546Sopenharmony_ci		 YYERROR;
606bf215546Sopenharmony_ci	      }
607bf215546Sopenharmony_ci
608bf215546Sopenharmony_ci              state->prog->info.outputs_written |= BITFIELD64_BIT($$.Index);
609bf215546Sopenharmony_ci	   }
610bf215546Sopenharmony_ci	}
611bf215546Sopenharmony_ci	;
612bf215546Sopenharmony_ci
613bf215546Sopenharmony_cimaskedAddrReg: addrReg addrWriteMask
614bf215546Sopenharmony_ci	{
615bf215546Sopenharmony_ci	   set_dst_reg(& $$, PROGRAM_ADDRESS, 0);
616bf215546Sopenharmony_ci	   $$.WriteMask = $2.mask;
617bf215546Sopenharmony_ci	}
618bf215546Sopenharmony_ci	;
619bf215546Sopenharmony_ci
620bf215546Sopenharmony_ciextendedSwizzle: extSwizComp ',' extSwizComp ',' extSwizComp ',' extSwizComp
621bf215546Sopenharmony_ci	{
622bf215546Sopenharmony_ci	   const unsigned xyzw_valid =
623bf215546Sopenharmony_ci	      ($1.xyzw_valid << 0)
624bf215546Sopenharmony_ci	      | ($3.xyzw_valid << 1)
625bf215546Sopenharmony_ci	      | ($5.xyzw_valid << 2)
626bf215546Sopenharmony_ci	      | ($7.xyzw_valid << 3);
627bf215546Sopenharmony_ci	   const unsigned rgba_valid =
628bf215546Sopenharmony_ci	      ($1.rgba_valid << 0)
629bf215546Sopenharmony_ci	      | ($3.rgba_valid << 1)
630bf215546Sopenharmony_ci	      | ($5.rgba_valid << 2)
631bf215546Sopenharmony_ci	      | ($7.rgba_valid << 3);
632bf215546Sopenharmony_ci
633bf215546Sopenharmony_ci	   /* All of the swizzle components have to be valid in either RGBA
634bf215546Sopenharmony_ci	    * or XYZW.  Note that 0 and 1 are valid in both, so both masks
635bf215546Sopenharmony_ci	    * can have some bits set.
636bf215546Sopenharmony_ci	    *
637bf215546Sopenharmony_ci	    * We somewhat deviate from the spec here.  It would be really hard
638bf215546Sopenharmony_ci	    * to figure out which component is the error, and there probably
639bf215546Sopenharmony_ci	    * isn't a lot of benefit.
640bf215546Sopenharmony_ci	    */
641bf215546Sopenharmony_ci	   if ((rgba_valid != 0x0f) && (xyzw_valid != 0x0f)) {
642bf215546Sopenharmony_ci	      yyerror(& @1, state, "cannot combine RGBA and XYZW swizzle "
643bf215546Sopenharmony_ci		      "components");
644bf215546Sopenharmony_ci	      YYERROR;
645bf215546Sopenharmony_ci	   }
646bf215546Sopenharmony_ci
647bf215546Sopenharmony_ci	   $$.swizzle = MAKE_SWIZZLE4($1.swz, $3.swz, $5.swz, $7.swz);
648bf215546Sopenharmony_ci	   $$.mask = ($1.negate) | ($3.negate << 1) | ($5.negate << 2)
649bf215546Sopenharmony_ci	      | ($7.negate << 3);
650bf215546Sopenharmony_ci	}
651bf215546Sopenharmony_ci	;
652bf215546Sopenharmony_ci
653bf215546Sopenharmony_ciextSwizComp: optionalSign extSwizSel
654bf215546Sopenharmony_ci	{
655bf215546Sopenharmony_ci	   $$ = $2;
656bf215546Sopenharmony_ci	   $$.negate = ($1) ? 1 : 0;
657bf215546Sopenharmony_ci	}
658bf215546Sopenharmony_ci	;
659bf215546Sopenharmony_ci
660bf215546Sopenharmony_ciextSwizSel: INTEGER
661bf215546Sopenharmony_ci	{
662bf215546Sopenharmony_ci	   if (($1 != 0) && ($1 != 1)) {
663bf215546Sopenharmony_ci	      yyerror(& @1, state, "invalid extended swizzle selector");
664bf215546Sopenharmony_ci	      YYERROR;
665bf215546Sopenharmony_ci	   }
666bf215546Sopenharmony_ci
667bf215546Sopenharmony_ci	   $$.swz = ($1 == 0) ? SWIZZLE_ZERO : SWIZZLE_ONE;
668bf215546Sopenharmony_ci           $$.negate = 0;
669bf215546Sopenharmony_ci
670bf215546Sopenharmony_ci	   /* 0 and 1 are valid for both RGBA swizzle names and XYZW
671bf215546Sopenharmony_ci	    * swizzle names.
672bf215546Sopenharmony_ci	    */
673bf215546Sopenharmony_ci	   $$.xyzw_valid = 1;
674bf215546Sopenharmony_ci	   $$.rgba_valid = 1;
675bf215546Sopenharmony_ci	}
676bf215546Sopenharmony_ci	| string
677bf215546Sopenharmony_ci	{
678bf215546Sopenharmony_ci	   char s;
679bf215546Sopenharmony_ci
680bf215546Sopenharmony_ci	   if (strlen($1) > 1) {
681bf215546Sopenharmony_ci	      yyerror(& @1, state, "invalid extended swizzle selector");
682bf215546Sopenharmony_ci	      YYERROR;
683bf215546Sopenharmony_ci	   }
684bf215546Sopenharmony_ci
685bf215546Sopenharmony_ci	   s = $1[0];
686bf215546Sopenharmony_ci	   free($1);
687bf215546Sopenharmony_ci
688bf215546Sopenharmony_ci           $$.rgba_valid = 0;
689bf215546Sopenharmony_ci           $$.xyzw_valid = 0;
690bf215546Sopenharmony_ci           $$.negate = 0;
691bf215546Sopenharmony_ci
692bf215546Sopenharmony_ci	   switch (s) {
693bf215546Sopenharmony_ci	   case 'x':
694bf215546Sopenharmony_ci	      $$.swz = SWIZZLE_X;
695bf215546Sopenharmony_ci	      $$.xyzw_valid = 1;
696bf215546Sopenharmony_ci	      break;
697bf215546Sopenharmony_ci	   case 'y':
698bf215546Sopenharmony_ci	      $$.swz = SWIZZLE_Y;
699bf215546Sopenharmony_ci	      $$.xyzw_valid = 1;
700bf215546Sopenharmony_ci	      break;
701bf215546Sopenharmony_ci	   case 'z':
702bf215546Sopenharmony_ci	      $$.swz = SWIZZLE_Z;
703bf215546Sopenharmony_ci	      $$.xyzw_valid = 1;
704bf215546Sopenharmony_ci	      break;
705bf215546Sopenharmony_ci	   case 'w':
706bf215546Sopenharmony_ci	      $$.swz = SWIZZLE_W;
707bf215546Sopenharmony_ci	      $$.xyzw_valid = 1;
708bf215546Sopenharmony_ci	      break;
709bf215546Sopenharmony_ci
710bf215546Sopenharmony_ci	   case 'r':
711bf215546Sopenharmony_ci	      $$.swz = SWIZZLE_X;
712bf215546Sopenharmony_ci	      $$.rgba_valid = 1;
713bf215546Sopenharmony_ci	      break;
714bf215546Sopenharmony_ci	   case 'g':
715bf215546Sopenharmony_ci	      $$.swz = SWIZZLE_Y;
716bf215546Sopenharmony_ci	      $$.rgba_valid = 1;
717bf215546Sopenharmony_ci	      break;
718bf215546Sopenharmony_ci	   case 'b':
719bf215546Sopenharmony_ci	      $$.swz = SWIZZLE_Z;
720bf215546Sopenharmony_ci	      $$.rgba_valid = 1;
721bf215546Sopenharmony_ci	      break;
722bf215546Sopenharmony_ci	   case 'a':
723bf215546Sopenharmony_ci	      $$.swz = SWIZZLE_W;
724bf215546Sopenharmony_ci	      $$.rgba_valid = 1;
725bf215546Sopenharmony_ci	      break;
726bf215546Sopenharmony_ci
727bf215546Sopenharmony_ci	   default:
728bf215546Sopenharmony_ci	      yyerror(& @1, state, "invalid extended swizzle selector");
729bf215546Sopenharmony_ci	      YYERROR;
730bf215546Sopenharmony_ci	      break;
731bf215546Sopenharmony_ci	   }
732bf215546Sopenharmony_ci	}
733bf215546Sopenharmony_ci	;
734bf215546Sopenharmony_ci
735bf215546Sopenharmony_cisrcReg: USED_IDENTIFIER /* temporaryReg | progParamSingle */
736bf215546Sopenharmony_ci	{
737bf215546Sopenharmony_ci	   struct asm_symbol *const s = (struct asm_symbol *)
738bf215546Sopenharmony_ci              _mesa_symbol_table_find_symbol(state->st, $1);
739bf215546Sopenharmony_ci
740bf215546Sopenharmony_ci	   free($1);
741bf215546Sopenharmony_ci
742bf215546Sopenharmony_ci	   if (s == NULL) {
743bf215546Sopenharmony_ci	      yyerror(& @1, state, "invalid operand variable");
744bf215546Sopenharmony_ci	      YYERROR;
745bf215546Sopenharmony_ci	   } else if ((s->type != at_param) && (s->type != at_temp)
746bf215546Sopenharmony_ci		      && (s->type != at_attrib)) {
747bf215546Sopenharmony_ci	      yyerror(& @1, state, "invalid operand variable");
748bf215546Sopenharmony_ci	      YYERROR;
749bf215546Sopenharmony_ci	   } else if ((s->type == at_param) && s->param_is_array) {
750bf215546Sopenharmony_ci	      yyerror(& @1, state, "non-array access to array PARAM");
751bf215546Sopenharmony_ci	      YYERROR;
752bf215546Sopenharmony_ci	   }
753bf215546Sopenharmony_ci
754bf215546Sopenharmony_ci	   init_src_reg(& $$);
755bf215546Sopenharmony_ci	   switch (s->type) {
756bf215546Sopenharmony_ci	   case at_temp:
757bf215546Sopenharmony_ci	      set_src_reg(& $$, PROGRAM_TEMPORARY, s->temp_binding);
758bf215546Sopenharmony_ci	      break;
759bf215546Sopenharmony_ci	   case at_param:
760bf215546Sopenharmony_ci              set_src_reg_swz(& $$, s->param_binding_type,
761bf215546Sopenharmony_ci                              s->param_binding_begin,
762bf215546Sopenharmony_ci                              s->param_binding_swizzle);
763bf215546Sopenharmony_ci	      break;
764bf215546Sopenharmony_ci	   case at_attrib:
765bf215546Sopenharmony_ci	      set_src_reg(& $$, PROGRAM_INPUT, s->attrib_binding);
766bf215546Sopenharmony_ci              state->prog->info.inputs_read |= BITFIELD64_BIT($$.Base.Index);
767bf215546Sopenharmony_ci
768bf215546Sopenharmony_ci	      if (!validate_inputs(& @1, state)) {
769bf215546Sopenharmony_ci		 YYERROR;
770bf215546Sopenharmony_ci	      }
771bf215546Sopenharmony_ci	      break;
772bf215546Sopenharmony_ci
773bf215546Sopenharmony_ci	   default:
774bf215546Sopenharmony_ci	      YYERROR;
775bf215546Sopenharmony_ci	      break;
776bf215546Sopenharmony_ci	   }
777bf215546Sopenharmony_ci	}
778bf215546Sopenharmony_ci	| attribBinding
779bf215546Sopenharmony_ci	{
780bf215546Sopenharmony_ci	   set_src_reg(& $$, PROGRAM_INPUT, $1);
781bf215546Sopenharmony_ci           state->prog->info.inputs_read |= BITFIELD64_BIT($$.Base.Index);
782bf215546Sopenharmony_ci
783bf215546Sopenharmony_ci	   if (!validate_inputs(& @1, state)) {
784bf215546Sopenharmony_ci	      YYERROR;
785bf215546Sopenharmony_ci	   }
786bf215546Sopenharmony_ci	}
787bf215546Sopenharmony_ci	| progParamArray '[' progParamArrayMem ']'
788bf215546Sopenharmony_ci	{
789bf215546Sopenharmony_ci	   if (! $3.Base.RelAddr
790bf215546Sopenharmony_ci	       && ((unsigned) $3.Base.Index >= $1->param_binding_length)) {
791bf215546Sopenharmony_ci	      yyerror(& @3, state, "out of bounds array access");
792bf215546Sopenharmony_ci	      YYERROR;
793bf215546Sopenharmony_ci	   }
794bf215546Sopenharmony_ci
795bf215546Sopenharmony_ci	   init_src_reg(& $$);
796bf215546Sopenharmony_ci	   $$.Base.File = $1->param_binding_type;
797bf215546Sopenharmony_ci
798bf215546Sopenharmony_ci	   if ($3.Base.RelAddr) {
799bf215546Sopenharmony_ci              state->prog->arb.IndirectRegisterFiles |= (1 << $$.Base.File);
800bf215546Sopenharmony_ci	      $1->param_accessed_indirectly = 1;
801bf215546Sopenharmony_ci
802bf215546Sopenharmony_ci	      $$.Base.RelAddr = 1;
803bf215546Sopenharmony_ci	      $$.Base.Index = $3.Base.Index;
804bf215546Sopenharmony_ci	      $$.Symbol = $1;
805bf215546Sopenharmony_ci	   } else {
806bf215546Sopenharmony_ci	      $$.Base.Index = $1->param_binding_begin + $3.Base.Index;
807bf215546Sopenharmony_ci	   }
808bf215546Sopenharmony_ci	}
809bf215546Sopenharmony_ci	| paramSingleItemUse
810bf215546Sopenharmony_ci	{
811bf215546Sopenharmony_ci           gl_register_file file = ($1.name != NULL)
812bf215546Sopenharmony_ci	      ? $1.param_binding_type
813bf215546Sopenharmony_ci	      : PROGRAM_CONSTANT;
814bf215546Sopenharmony_ci           set_src_reg_swz(& $$, file, $1.param_binding_begin,
815bf215546Sopenharmony_ci                           $1.param_binding_swizzle);
816bf215546Sopenharmony_ci	}
817bf215546Sopenharmony_ci	;
818bf215546Sopenharmony_ci
819bf215546Sopenharmony_cidstReg: resultBinding
820bf215546Sopenharmony_ci	{
821bf215546Sopenharmony_ci	   set_dst_reg(& $$, PROGRAM_OUTPUT, $1);
822bf215546Sopenharmony_ci	}
823bf215546Sopenharmony_ci	| USED_IDENTIFIER /* temporaryReg | vertexResultReg */
824bf215546Sopenharmony_ci	{
825bf215546Sopenharmony_ci	   struct asm_symbol *const s = (struct asm_symbol *)
826bf215546Sopenharmony_ci              _mesa_symbol_table_find_symbol(state->st, $1);
827bf215546Sopenharmony_ci
828bf215546Sopenharmony_ci	   free($1);
829bf215546Sopenharmony_ci
830bf215546Sopenharmony_ci	   if (s == NULL) {
831bf215546Sopenharmony_ci	      yyerror(& @1, state, "invalid operand variable");
832bf215546Sopenharmony_ci	      YYERROR;
833bf215546Sopenharmony_ci	   } else if ((s->type != at_output) && (s->type != at_temp)) {
834bf215546Sopenharmony_ci	      yyerror(& @1, state, "invalid operand variable");
835bf215546Sopenharmony_ci	      YYERROR;
836bf215546Sopenharmony_ci	   }
837bf215546Sopenharmony_ci
838bf215546Sopenharmony_ci	   switch (s->type) {
839bf215546Sopenharmony_ci	   case at_temp:
840bf215546Sopenharmony_ci	      set_dst_reg(& $$, PROGRAM_TEMPORARY, s->temp_binding);
841bf215546Sopenharmony_ci	      break;
842bf215546Sopenharmony_ci	   case at_output:
843bf215546Sopenharmony_ci	      set_dst_reg(& $$, PROGRAM_OUTPUT, s->output_binding);
844bf215546Sopenharmony_ci	      break;
845bf215546Sopenharmony_ci	   default:
846bf215546Sopenharmony_ci	      set_dst_reg(& $$, s->param_binding_type, s->param_binding_begin);
847bf215546Sopenharmony_ci	      break;
848bf215546Sopenharmony_ci	   }
849bf215546Sopenharmony_ci	}
850bf215546Sopenharmony_ci	;
851bf215546Sopenharmony_ci
852bf215546Sopenharmony_ciprogParamArray: USED_IDENTIFIER
853bf215546Sopenharmony_ci	{
854bf215546Sopenharmony_ci	   struct asm_symbol *const s = (struct asm_symbol *)
855bf215546Sopenharmony_ci              _mesa_symbol_table_find_symbol(state->st, $1);
856bf215546Sopenharmony_ci
857bf215546Sopenharmony_ci	   free($1);
858bf215546Sopenharmony_ci
859bf215546Sopenharmony_ci	   if (s == NULL) {
860bf215546Sopenharmony_ci	      yyerror(& @1, state, "invalid operand variable");
861bf215546Sopenharmony_ci	      YYERROR;
862bf215546Sopenharmony_ci	   } else if ((s->type != at_param) || !s->param_is_array) {
863bf215546Sopenharmony_ci	      yyerror(& @1, state, "array access to non-PARAM variable");
864bf215546Sopenharmony_ci	      YYERROR;
865bf215546Sopenharmony_ci	   } else {
866bf215546Sopenharmony_ci	      $$ = s;
867bf215546Sopenharmony_ci	   }
868bf215546Sopenharmony_ci	}
869bf215546Sopenharmony_ci	;
870bf215546Sopenharmony_ci
871bf215546Sopenharmony_ciprogParamArrayMem: progParamArrayAbs | progParamArrayRel;
872bf215546Sopenharmony_ci
873bf215546Sopenharmony_ciprogParamArrayAbs: INTEGER
874bf215546Sopenharmony_ci	{
875bf215546Sopenharmony_ci	   init_src_reg(& $$);
876bf215546Sopenharmony_ci	   $$.Base.Index = $1;
877bf215546Sopenharmony_ci	}
878bf215546Sopenharmony_ci	;
879bf215546Sopenharmony_ci
880bf215546Sopenharmony_ciprogParamArrayRel: addrReg addrComponent addrRegRelOffset
881bf215546Sopenharmony_ci	{
882bf215546Sopenharmony_ci	   /* FINISHME: Add support for multiple address registers.
883bf215546Sopenharmony_ci	    */
884bf215546Sopenharmony_ci	   /* FINISHME: Add support for 4-component address registers.
885bf215546Sopenharmony_ci	    */
886bf215546Sopenharmony_ci	   init_src_reg(& $$);
887bf215546Sopenharmony_ci	   $$.Base.RelAddr = 1;
888bf215546Sopenharmony_ci	   $$.Base.Index = $3;
889bf215546Sopenharmony_ci	}
890bf215546Sopenharmony_ci	;
891bf215546Sopenharmony_ci
892bf215546Sopenharmony_ciaddrRegRelOffset:              { $$ = 0; }
893bf215546Sopenharmony_ci	| '+' addrRegPosOffset { $$ = $2; }
894bf215546Sopenharmony_ci	| '-' addrRegNegOffset { $$ = -$2; }
895bf215546Sopenharmony_ci	;
896bf215546Sopenharmony_ci
897bf215546Sopenharmony_ciaddrRegPosOffset: INTEGER
898bf215546Sopenharmony_ci	{
899bf215546Sopenharmony_ci	   if (($1 < 0) || ($1 > (state->limits->MaxAddressOffset - 1))) {
900bf215546Sopenharmony_ci              char s[100];
901bf215546Sopenharmony_ci              snprintf(s, sizeof(s),
902bf215546Sopenharmony_ci                             "relative address offset too large (%d)", $1);
903bf215546Sopenharmony_ci	      yyerror(& @1, state, s);
904bf215546Sopenharmony_ci	      YYERROR;
905bf215546Sopenharmony_ci	   } else {
906bf215546Sopenharmony_ci	      $$ = $1;
907bf215546Sopenharmony_ci	   }
908bf215546Sopenharmony_ci	}
909bf215546Sopenharmony_ci	;
910bf215546Sopenharmony_ci
911bf215546Sopenharmony_ciaddrRegNegOffset: INTEGER
912bf215546Sopenharmony_ci	{
913bf215546Sopenharmony_ci	   if (($1 < 0) || ($1 > state->limits->MaxAddressOffset)) {
914bf215546Sopenharmony_ci              char s[100];
915bf215546Sopenharmony_ci              snprintf(s, sizeof(s),
916bf215546Sopenharmony_ci                             "relative address offset too large (%d)", $1);
917bf215546Sopenharmony_ci	      yyerror(& @1, state, s);
918bf215546Sopenharmony_ci	      YYERROR;
919bf215546Sopenharmony_ci	   } else {
920bf215546Sopenharmony_ci	      $$ = $1;
921bf215546Sopenharmony_ci	   }
922bf215546Sopenharmony_ci	}
923bf215546Sopenharmony_ci	;
924bf215546Sopenharmony_ci
925bf215546Sopenharmony_ciaddrReg: USED_IDENTIFIER
926bf215546Sopenharmony_ci	{
927bf215546Sopenharmony_ci	   struct asm_symbol *const s = (struct asm_symbol *)
928bf215546Sopenharmony_ci              _mesa_symbol_table_find_symbol(state->st, $1);
929bf215546Sopenharmony_ci
930bf215546Sopenharmony_ci	   free($1);
931bf215546Sopenharmony_ci
932bf215546Sopenharmony_ci	   if (s == NULL) {
933bf215546Sopenharmony_ci	      yyerror(& @1, state, "invalid array member");
934bf215546Sopenharmony_ci	      YYERROR;
935bf215546Sopenharmony_ci	   } else if (s->type != at_address) {
936bf215546Sopenharmony_ci	      yyerror(& @1, state,
937bf215546Sopenharmony_ci		      "invalid variable for indexed array access");
938bf215546Sopenharmony_ci	      YYERROR;
939bf215546Sopenharmony_ci	   } else {
940bf215546Sopenharmony_ci	      $$ = s;
941bf215546Sopenharmony_ci	   }
942bf215546Sopenharmony_ci	}
943bf215546Sopenharmony_ci	;
944bf215546Sopenharmony_ci
945bf215546Sopenharmony_ciaddrComponent: MASK1
946bf215546Sopenharmony_ci	{
947bf215546Sopenharmony_ci	   if ($1.mask != WRITEMASK_X) {
948bf215546Sopenharmony_ci	      yyerror(& @1, state, "invalid address component selector");
949bf215546Sopenharmony_ci	      YYERROR;
950bf215546Sopenharmony_ci	   } else {
951bf215546Sopenharmony_ci	      $$ = $1;
952bf215546Sopenharmony_ci	   }
953bf215546Sopenharmony_ci	}
954bf215546Sopenharmony_ci	;
955bf215546Sopenharmony_ci
956bf215546Sopenharmony_ciaddrWriteMask: MASK1
957bf215546Sopenharmony_ci	{
958bf215546Sopenharmony_ci	   if ($1.mask != WRITEMASK_X) {
959bf215546Sopenharmony_ci	      yyerror(& @1, state,
960bf215546Sopenharmony_ci		      "address register write mask must be \".x\"");
961bf215546Sopenharmony_ci	      YYERROR;
962bf215546Sopenharmony_ci	   } else {
963bf215546Sopenharmony_ci	      $$ = $1;
964bf215546Sopenharmony_ci	   }
965bf215546Sopenharmony_ci	}
966bf215546Sopenharmony_ci	;
967bf215546Sopenharmony_ci
968bf215546Sopenharmony_ciscalarSuffix: MASK1;
969bf215546Sopenharmony_ci
970bf215546Sopenharmony_ciswizzleSuffix: MASK1
971bf215546Sopenharmony_ci	| MASK4
972bf215546Sopenharmony_ci	| SWIZZLE
973bf215546Sopenharmony_ci	|              { $$.swizzle = SWIZZLE_NOOP; $$.mask = WRITEMASK_XYZW; }
974bf215546Sopenharmony_ci	;
975bf215546Sopenharmony_ci
976bf215546Sopenharmony_cioptionalMask: MASK4 | MASK3 | MASK2 | MASK1
977bf215546Sopenharmony_ci	|              { $$.swizzle = SWIZZLE_NOOP; $$.mask = WRITEMASK_XYZW; }
978bf215546Sopenharmony_ci	;
979bf215546Sopenharmony_ci
980bf215546Sopenharmony_cinamingStatement: ATTRIB_statement
981bf215546Sopenharmony_ci	| PARAM_statement
982bf215546Sopenharmony_ci	| TEMP_statement
983bf215546Sopenharmony_ci	| ADDRESS_statement
984bf215546Sopenharmony_ci	| OUTPUT_statement
985bf215546Sopenharmony_ci	| ALIAS_statement
986bf215546Sopenharmony_ci	;
987bf215546Sopenharmony_ci
988bf215546Sopenharmony_ciATTRIB_statement: ATTRIB IDENTIFIER '=' attribBinding
989bf215546Sopenharmony_ci	{
990bf215546Sopenharmony_ci	   struct asm_symbol *const s =
991bf215546Sopenharmony_ci	      declare_variable(state, $2, at_attrib, & @2);
992bf215546Sopenharmony_ci
993bf215546Sopenharmony_ci	   if (s == NULL) {
994bf215546Sopenharmony_ci	      free($2);
995bf215546Sopenharmony_ci	      YYERROR;
996bf215546Sopenharmony_ci	   } else {
997bf215546Sopenharmony_ci	      s->attrib_binding = $4;
998bf215546Sopenharmony_ci	      state->InputsBound |= BITFIELD64_BIT(s->attrib_binding);
999bf215546Sopenharmony_ci
1000bf215546Sopenharmony_ci	      if (!validate_inputs(& @4, state)) {
1001bf215546Sopenharmony_ci		 YYERROR;
1002bf215546Sopenharmony_ci	      }
1003bf215546Sopenharmony_ci	   }
1004bf215546Sopenharmony_ci	}
1005bf215546Sopenharmony_ci	;
1006bf215546Sopenharmony_ci
1007bf215546Sopenharmony_ciattribBinding: VERTEX vtxAttribItem
1008bf215546Sopenharmony_ci	{
1009bf215546Sopenharmony_ci	   $$ = $2;
1010bf215546Sopenharmony_ci	}
1011bf215546Sopenharmony_ci	| FRAGMENT fragAttribItem
1012bf215546Sopenharmony_ci	{
1013bf215546Sopenharmony_ci	   $$ = $2;
1014bf215546Sopenharmony_ci	}
1015bf215546Sopenharmony_ci	;
1016bf215546Sopenharmony_ci
1017bf215546Sopenharmony_civtxAttribItem: POSITION
1018bf215546Sopenharmony_ci	{
1019bf215546Sopenharmony_ci	   $$ = VERT_ATTRIB_POS;
1020bf215546Sopenharmony_ci	}
1021bf215546Sopenharmony_ci	| NORMAL
1022bf215546Sopenharmony_ci	{
1023bf215546Sopenharmony_ci	   $$ = VERT_ATTRIB_NORMAL;
1024bf215546Sopenharmony_ci	}
1025bf215546Sopenharmony_ci	| COLOR optColorType
1026bf215546Sopenharmony_ci	{
1027bf215546Sopenharmony_ci	   $$ = VERT_ATTRIB_COLOR0 + $2;
1028bf215546Sopenharmony_ci	}
1029bf215546Sopenharmony_ci	| FOGCOORD
1030bf215546Sopenharmony_ci	{
1031bf215546Sopenharmony_ci	   $$ = VERT_ATTRIB_FOG;
1032bf215546Sopenharmony_ci	}
1033bf215546Sopenharmony_ci	| TEXCOORD optTexCoordUnitNum
1034bf215546Sopenharmony_ci	{
1035bf215546Sopenharmony_ci	   $$ = VERT_ATTRIB_TEX0 + $2;
1036bf215546Sopenharmony_ci	}
1037bf215546Sopenharmony_ci	| MATRIXINDEX '[' vtxWeightNum ']'
1038bf215546Sopenharmony_ci	{
1039bf215546Sopenharmony_ci	   yyerror(& @1, state, "GL_ARB_matrix_palette not supported");
1040bf215546Sopenharmony_ci	   YYERROR;
1041bf215546Sopenharmony_ci	}
1042bf215546Sopenharmony_ci	| VTXATTRIB '[' vtxAttribNum ']'
1043bf215546Sopenharmony_ci	{
1044bf215546Sopenharmony_ci	   $$ = VERT_ATTRIB_GENERIC0 + $3;
1045bf215546Sopenharmony_ci	}
1046bf215546Sopenharmony_ci	;
1047bf215546Sopenharmony_ci
1048bf215546Sopenharmony_civtxAttribNum: INTEGER
1049bf215546Sopenharmony_ci	{
1050bf215546Sopenharmony_ci	   if ((unsigned) $1 >= state->limits->MaxAttribs) {
1051bf215546Sopenharmony_ci	      yyerror(& @1, state, "invalid vertex attribute reference");
1052bf215546Sopenharmony_ci	      YYERROR;
1053bf215546Sopenharmony_ci	   }
1054bf215546Sopenharmony_ci
1055bf215546Sopenharmony_ci	   $$ = $1;
1056bf215546Sopenharmony_ci	}
1057bf215546Sopenharmony_ci	;
1058bf215546Sopenharmony_ci
1059bf215546Sopenharmony_civtxWeightNum: INTEGER;
1060bf215546Sopenharmony_ci
1061bf215546Sopenharmony_cifragAttribItem: POSITION
1062bf215546Sopenharmony_ci	{
1063bf215546Sopenharmony_ci	   $$ = VARYING_SLOT_POS;
1064bf215546Sopenharmony_ci	}
1065bf215546Sopenharmony_ci	| COLOR optColorType
1066bf215546Sopenharmony_ci	{
1067bf215546Sopenharmony_ci	   $$ = VARYING_SLOT_COL0 + $2;
1068bf215546Sopenharmony_ci	}
1069bf215546Sopenharmony_ci	| FOGCOORD
1070bf215546Sopenharmony_ci	{
1071bf215546Sopenharmony_ci	   $$ = VARYING_SLOT_FOGC;
1072bf215546Sopenharmony_ci	}
1073bf215546Sopenharmony_ci	| TEXCOORD optTexCoordUnitNum
1074bf215546Sopenharmony_ci	{
1075bf215546Sopenharmony_ci	   $$ = VARYING_SLOT_TEX0 + $2;
1076bf215546Sopenharmony_ci	}
1077bf215546Sopenharmony_ci	;
1078bf215546Sopenharmony_ci
1079bf215546Sopenharmony_ciPARAM_statement: PARAM_singleStmt | PARAM_multipleStmt;
1080bf215546Sopenharmony_ci
1081bf215546Sopenharmony_ciPARAM_singleStmt: PARAM IDENTIFIER paramSingleInit
1082bf215546Sopenharmony_ci	{
1083bf215546Sopenharmony_ci	   struct asm_symbol *const s =
1084bf215546Sopenharmony_ci	      declare_variable(state, $2, at_param, & @2);
1085bf215546Sopenharmony_ci
1086bf215546Sopenharmony_ci	   if (s == NULL) {
1087bf215546Sopenharmony_ci	      free($2);
1088bf215546Sopenharmony_ci	      YYERROR;
1089bf215546Sopenharmony_ci	   } else {
1090bf215546Sopenharmony_ci	      s->param_binding_type = $3.param_binding_type;
1091bf215546Sopenharmony_ci	      s->param_binding_begin = $3.param_binding_begin;
1092bf215546Sopenharmony_ci	      s->param_binding_length = $3.param_binding_length;
1093bf215546Sopenharmony_ci              s->param_binding_swizzle = $3.param_binding_swizzle;
1094bf215546Sopenharmony_ci	      s->param_is_array = 0;
1095bf215546Sopenharmony_ci	   }
1096bf215546Sopenharmony_ci	}
1097bf215546Sopenharmony_ci	;
1098bf215546Sopenharmony_ci
1099bf215546Sopenharmony_ciPARAM_multipleStmt: PARAM IDENTIFIER '[' optArraySize ']' paramMultipleInit
1100bf215546Sopenharmony_ci	{
1101bf215546Sopenharmony_ci	   if (($4 != 0) && ((unsigned) $4 != $6.param_binding_length)) {
1102bf215546Sopenharmony_ci	      free($2);
1103bf215546Sopenharmony_ci	      yyerror(& @4, state,
1104bf215546Sopenharmony_ci		      "parameter array size and number of bindings must match");
1105bf215546Sopenharmony_ci	      YYERROR;
1106bf215546Sopenharmony_ci	   } else {
1107bf215546Sopenharmony_ci	      struct asm_symbol *const s =
1108bf215546Sopenharmony_ci		 declare_variable(state, $2, $6.type, & @2);
1109bf215546Sopenharmony_ci
1110bf215546Sopenharmony_ci	      if (s == NULL) {
1111bf215546Sopenharmony_ci		 free($2);
1112bf215546Sopenharmony_ci		 YYERROR;
1113bf215546Sopenharmony_ci	      } else {
1114bf215546Sopenharmony_ci		 s->param_binding_type = $6.param_binding_type;
1115bf215546Sopenharmony_ci		 s->param_binding_begin = $6.param_binding_begin;
1116bf215546Sopenharmony_ci		 s->param_binding_length = $6.param_binding_length;
1117bf215546Sopenharmony_ci                 s->param_binding_swizzle = SWIZZLE_XYZW;
1118bf215546Sopenharmony_ci		 s->param_is_array = 1;
1119bf215546Sopenharmony_ci	      }
1120bf215546Sopenharmony_ci	   }
1121bf215546Sopenharmony_ci	}
1122bf215546Sopenharmony_ci	;
1123bf215546Sopenharmony_ci
1124bf215546Sopenharmony_cioptArraySize:
1125bf215546Sopenharmony_ci	{
1126bf215546Sopenharmony_ci	   $$ = 0;
1127bf215546Sopenharmony_ci	}
1128bf215546Sopenharmony_ci	| INTEGER
1129bf215546Sopenharmony_ci        {
1130bf215546Sopenharmony_ci	   if (($1 < 1) || ((unsigned) $1 > state->limits->MaxParameters)) {
1131bf215546Sopenharmony_ci              char msg[100];
1132bf215546Sopenharmony_ci              snprintf(msg, sizeof(msg),
1133bf215546Sopenharmony_ci                             "invalid parameter array size (size=%d max=%u)",
1134bf215546Sopenharmony_ci                             $1, state->limits->MaxParameters);
1135bf215546Sopenharmony_ci	      yyerror(& @1, state, msg);
1136bf215546Sopenharmony_ci	      YYERROR;
1137bf215546Sopenharmony_ci	   } else {
1138bf215546Sopenharmony_ci	      $$ = $1;
1139bf215546Sopenharmony_ci	   }
1140bf215546Sopenharmony_ci	}
1141bf215546Sopenharmony_ci	;
1142bf215546Sopenharmony_ci
1143bf215546Sopenharmony_ciparamSingleInit: '=' paramSingleItemDecl
1144bf215546Sopenharmony_ci	{
1145bf215546Sopenharmony_ci	   $$ = $2;
1146bf215546Sopenharmony_ci	}
1147bf215546Sopenharmony_ci	;
1148bf215546Sopenharmony_ci
1149bf215546Sopenharmony_ciparamMultipleInit: '=' '{' paramMultInitList '}'
1150bf215546Sopenharmony_ci	{
1151bf215546Sopenharmony_ci	   $$ = $3;
1152bf215546Sopenharmony_ci	}
1153bf215546Sopenharmony_ci	;
1154bf215546Sopenharmony_ci
1155bf215546Sopenharmony_ciparamMultInitList: paramMultipleItem
1156bf215546Sopenharmony_ci	| paramMultInitList ',' paramMultipleItem
1157bf215546Sopenharmony_ci	{
1158bf215546Sopenharmony_ci	   $1.param_binding_length += $3.param_binding_length;
1159bf215546Sopenharmony_ci	   $$ = $1;
1160bf215546Sopenharmony_ci	}
1161bf215546Sopenharmony_ci	;
1162bf215546Sopenharmony_ci
1163bf215546Sopenharmony_ciparamSingleItemDecl: stateSingleItem
1164bf215546Sopenharmony_ci	{
1165bf215546Sopenharmony_ci	   memset(& $$, 0, sizeof($$));
1166bf215546Sopenharmony_ci	   $$.param_binding_begin = ~0;
1167bf215546Sopenharmony_ci	   initialize_symbol_from_state(state->prog, & $$, $1);
1168bf215546Sopenharmony_ci	}
1169bf215546Sopenharmony_ci	| programSingleItem
1170bf215546Sopenharmony_ci	{
1171bf215546Sopenharmony_ci	   memset(& $$, 0, sizeof($$));
1172bf215546Sopenharmony_ci	   $$.param_binding_begin = ~0;
1173bf215546Sopenharmony_ci	   initialize_symbol_from_param(state->prog, & $$, $1);
1174bf215546Sopenharmony_ci	}
1175bf215546Sopenharmony_ci	| paramConstDecl
1176bf215546Sopenharmony_ci	{
1177bf215546Sopenharmony_ci	   memset(& $$, 0, sizeof($$));
1178bf215546Sopenharmony_ci	   $$.param_binding_begin = ~0;
1179bf215546Sopenharmony_ci	   initialize_symbol_from_const(state->prog, & $$, & $1, GL_TRUE);
1180bf215546Sopenharmony_ci	}
1181bf215546Sopenharmony_ci	;
1182bf215546Sopenharmony_ci
1183bf215546Sopenharmony_ciparamSingleItemUse: stateSingleItem
1184bf215546Sopenharmony_ci	{
1185bf215546Sopenharmony_ci	   memset(& $$, 0, sizeof($$));
1186bf215546Sopenharmony_ci	   $$.param_binding_begin = ~0;
1187bf215546Sopenharmony_ci	   initialize_symbol_from_state(state->prog, & $$, $1);
1188bf215546Sopenharmony_ci	}
1189bf215546Sopenharmony_ci	| programSingleItem
1190bf215546Sopenharmony_ci	{
1191bf215546Sopenharmony_ci	   memset(& $$, 0, sizeof($$));
1192bf215546Sopenharmony_ci	   $$.param_binding_begin = ~0;
1193bf215546Sopenharmony_ci	   initialize_symbol_from_param(state->prog, & $$, $1);
1194bf215546Sopenharmony_ci	}
1195bf215546Sopenharmony_ci	| paramConstUse
1196bf215546Sopenharmony_ci	{
1197bf215546Sopenharmony_ci	   memset(& $$, 0, sizeof($$));
1198bf215546Sopenharmony_ci	   $$.param_binding_begin = ~0;
1199bf215546Sopenharmony_ci	   initialize_symbol_from_const(state->prog, & $$, & $1, GL_TRUE);
1200bf215546Sopenharmony_ci	}
1201bf215546Sopenharmony_ci	;
1202bf215546Sopenharmony_ci
1203bf215546Sopenharmony_ciparamMultipleItem: stateMultipleItem
1204bf215546Sopenharmony_ci	{
1205bf215546Sopenharmony_ci	   memset(& $$, 0, sizeof($$));
1206bf215546Sopenharmony_ci	   $$.param_binding_begin = ~0;
1207bf215546Sopenharmony_ci	   initialize_symbol_from_state(state->prog, & $$, $1);
1208bf215546Sopenharmony_ci	}
1209bf215546Sopenharmony_ci	| programMultipleItem
1210bf215546Sopenharmony_ci	{
1211bf215546Sopenharmony_ci	   memset(& $$, 0, sizeof($$));
1212bf215546Sopenharmony_ci	   $$.param_binding_begin = ~0;
1213bf215546Sopenharmony_ci	   initialize_symbol_from_param(state->prog, & $$, $1);
1214bf215546Sopenharmony_ci	}
1215bf215546Sopenharmony_ci	| paramConstDecl
1216bf215546Sopenharmony_ci	{
1217bf215546Sopenharmony_ci	   memset(& $$, 0, sizeof($$));
1218bf215546Sopenharmony_ci	   $$.param_binding_begin = ~0;
1219bf215546Sopenharmony_ci	   initialize_symbol_from_const(state->prog, & $$, & $1, GL_FALSE);
1220bf215546Sopenharmony_ci	}
1221bf215546Sopenharmony_ci	;
1222bf215546Sopenharmony_ci
1223bf215546Sopenharmony_cistateMultipleItem: stateSingleItem        { memcpy($$, $1, sizeof($$)); }
1224bf215546Sopenharmony_ci	| STATE stateMatrixRows           { memcpy($$, $2, sizeof($$)); }
1225bf215546Sopenharmony_ci	;
1226bf215546Sopenharmony_ci
1227bf215546Sopenharmony_cistateSingleItem: STATE stateMaterialItem  { memcpy($$, $2, sizeof($$)); }
1228bf215546Sopenharmony_ci	| STATE stateLightItem            { memcpy($$, $2, sizeof($$)); }
1229bf215546Sopenharmony_ci	| STATE stateLightModelItem       { memcpy($$, $2, sizeof($$)); }
1230bf215546Sopenharmony_ci	| STATE stateLightProdItem        { memcpy($$, $2, sizeof($$)); }
1231bf215546Sopenharmony_ci	| STATE stateTexGenItem           { memcpy($$, $2, sizeof($$)); }
1232bf215546Sopenharmony_ci	| STATE stateTexEnvItem           { memcpy($$, $2, sizeof($$)); }
1233bf215546Sopenharmony_ci	| STATE stateFogItem              { memcpy($$, $2, sizeof($$)); }
1234bf215546Sopenharmony_ci	| STATE stateClipPlaneItem        { memcpy($$, $2, sizeof($$)); }
1235bf215546Sopenharmony_ci	| STATE statePointItem            { memcpy($$, $2, sizeof($$)); }
1236bf215546Sopenharmony_ci	| STATE stateMatrixRow            { memcpy($$, $2, sizeof($$)); }
1237bf215546Sopenharmony_ci	| STATE stateDepthItem            { memcpy($$, $2, sizeof($$)); }
1238bf215546Sopenharmony_ci	;
1239bf215546Sopenharmony_ci
1240bf215546Sopenharmony_cistateMaterialItem: MATERIAL optFaceType stateMatProperty
1241bf215546Sopenharmony_ci	{
1242bf215546Sopenharmony_ci	   memset($$, 0, sizeof($$));
1243bf215546Sopenharmony_ci	   $$[0] = STATE_MATERIAL;
1244bf215546Sopenharmony_ci	   $$[1] = $3 + $2;
1245bf215546Sopenharmony_ci	   $$[2] = 0;
1246bf215546Sopenharmony_ci	}
1247bf215546Sopenharmony_ci	;
1248bf215546Sopenharmony_ci
1249bf215546Sopenharmony_cistateMatProperty: ambDiffSpecPropertyMaterial
1250bf215546Sopenharmony_ci	{
1251bf215546Sopenharmony_ci	   $$ = $1;
1252bf215546Sopenharmony_ci	}
1253bf215546Sopenharmony_ci	| EMISSION
1254bf215546Sopenharmony_ci	{
1255bf215546Sopenharmony_ci	   $$ = MAT_ATTRIB_FRONT_EMISSION;
1256bf215546Sopenharmony_ci	}
1257bf215546Sopenharmony_ci	| SHININESS
1258bf215546Sopenharmony_ci	{
1259bf215546Sopenharmony_ci	   $$ = MAT_ATTRIB_FRONT_SHININESS;
1260bf215546Sopenharmony_ci	}
1261bf215546Sopenharmony_ci	;
1262bf215546Sopenharmony_ci
1263bf215546Sopenharmony_cistateLightItem: LIGHT '[' stateLightNumber ']' stateLightProperty
1264bf215546Sopenharmony_ci	{
1265bf215546Sopenharmony_ci	   memset($$, 0, sizeof($$));
1266bf215546Sopenharmony_ci	   $$[0] = STATE_LIGHT;
1267bf215546Sopenharmony_ci	   $$[1] = $3;
1268bf215546Sopenharmony_ci	   $$[2] = $5;
1269bf215546Sopenharmony_ci	}
1270bf215546Sopenharmony_ci	;
1271bf215546Sopenharmony_ci
1272bf215546Sopenharmony_cistateLightProperty: ambDiffSpecPropertyLight
1273bf215546Sopenharmony_ci	{
1274bf215546Sopenharmony_ci	   $$ = $1;
1275bf215546Sopenharmony_ci	}
1276bf215546Sopenharmony_ci	| POSITION
1277bf215546Sopenharmony_ci	{
1278bf215546Sopenharmony_ci	   $$ = STATE_POSITION;
1279bf215546Sopenharmony_ci	}
1280bf215546Sopenharmony_ci	| ATTENUATION
1281bf215546Sopenharmony_ci	{
1282bf215546Sopenharmony_ci	   $$ = STATE_ATTENUATION;
1283bf215546Sopenharmony_ci	}
1284bf215546Sopenharmony_ci	| SPOT stateSpotProperty
1285bf215546Sopenharmony_ci	{
1286bf215546Sopenharmony_ci	   $$ = $2;
1287bf215546Sopenharmony_ci	}
1288bf215546Sopenharmony_ci	| HALF
1289bf215546Sopenharmony_ci	{
1290bf215546Sopenharmony_ci	   $$ = STATE_HALF_VECTOR;
1291bf215546Sopenharmony_ci	}
1292bf215546Sopenharmony_ci	;
1293bf215546Sopenharmony_ci
1294bf215546Sopenharmony_cistateSpotProperty: DIRECTION
1295bf215546Sopenharmony_ci	{
1296bf215546Sopenharmony_ci	   $$ = STATE_SPOT_DIRECTION;
1297bf215546Sopenharmony_ci	}
1298bf215546Sopenharmony_ci	;
1299bf215546Sopenharmony_ci
1300bf215546Sopenharmony_cistateLightModelItem: LIGHTMODEL stateLModProperty
1301bf215546Sopenharmony_ci	{
1302bf215546Sopenharmony_ci	   $$[0] = $2[0];
1303bf215546Sopenharmony_ci	   $$[1] = $2[1];
1304bf215546Sopenharmony_ci	}
1305bf215546Sopenharmony_ci	;
1306bf215546Sopenharmony_ci
1307bf215546Sopenharmony_cistateLModProperty: AMBIENT
1308bf215546Sopenharmony_ci	{
1309bf215546Sopenharmony_ci	   memset($$, 0, sizeof($$));
1310bf215546Sopenharmony_ci	   $$[0] = STATE_LIGHTMODEL_AMBIENT;
1311bf215546Sopenharmony_ci	}
1312bf215546Sopenharmony_ci	| optFaceType SCENECOLOR
1313bf215546Sopenharmony_ci	{
1314bf215546Sopenharmony_ci	   memset($$, 0, sizeof($$));
1315bf215546Sopenharmony_ci	   $$[0] = STATE_LIGHTMODEL_SCENECOLOR;
1316bf215546Sopenharmony_ci	   $$[1] = $1;
1317bf215546Sopenharmony_ci	}
1318bf215546Sopenharmony_ci	;
1319bf215546Sopenharmony_ci
1320bf215546Sopenharmony_cistateLightProdItem: LIGHTPROD '[' stateLightNumber ']' optFaceType stateLProdProperty
1321bf215546Sopenharmony_ci	{
1322bf215546Sopenharmony_ci	   memset($$, 0, sizeof($$));
1323bf215546Sopenharmony_ci	   $$[0] = STATE_LIGHTPROD;
1324bf215546Sopenharmony_ci	   $$[1] = $3;
1325bf215546Sopenharmony_ci	   $$[2] = $6 + $5;
1326bf215546Sopenharmony_ci	   $$[3] = 0;
1327bf215546Sopenharmony_ci	}
1328bf215546Sopenharmony_ci	;
1329bf215546Sopenharmony_ci
1330bf215546Sopenharmony_cistateLProdProperty: ambDiffSpecPropertyMaterial;
1331bf215546Sopenharmony_ci
1332bf215546Sopenharmony_cistateTexEnvItem: TEXENV optLegacyTexUnitNum stateTexEnvProperty
1333bf215546Sopenharmony_ci	{
1334bf215546Sopenharmony_ci	   memset($$, 0, sizeof($$));
1335bf215546Sopenharmony_ci	   $$[0] = $3;
1336bf215546Sopenharmony_ci	   $$[1] = $2;
1337bf215546Sopenharmony_ci	}
1338bf215546Sopenharmony_ci	;
1339bf215546Sopenharmony_ci
1340bf215546Sopenharmony_cistateTexEnvProperty: COLOR
1341bf215546Sopenharmony_ci	{
1342bf215546Sopenharmony_ci	   $$ = STATE_TEXENV_COLOR;
1343bf215546Sopenharmony_ci	}
1344bf215546Sopenharmony_ci	;
1345bf215546Sopenharmony_ci
1346bf215546Sopenharmony_ciambDiffSpecPropertyMaterial: AMBIENT
1347bf215546Sopenharmony_ci	{
1348bf215546Sopenharmony_ci	   $$ = MAT_ATTRIB_FRONT_AMBIENT;
1349bf215546Sopenharmony_ci	}
1350bf215546Sopenharmony_ci	| DIFFUSE
1351bf215546Sopenharmony_ci	{
1352bf215546Sopenharmony_ci	   $$ = MAT_ATTRIB_FRONT_DIFFUSE;
1353bf215546Sopenharmony_ci	}
1354bf215546Sopenharmony_ci	| SPECULAR
1355bf215546Sopenharmony_ci	{
1356bf215546Sopenharmony_ci	   $$ = MAT_ATTRIB_FRONT_SPECULAR;
1357bf215546Sopenharmony_ci	}
1358bf215546Sopenharmony_ci	;
1359bf215546Sopenharmony_ci
1360bf215546Sopenharmony_ciambDiffSpecPropertyLight: AMBIENT
1361bf215546Sopenharmony_ci        {
1362bf215546Sopenharmony_ci           $$ = STATE_AMBIENT;
1363bf215546Sopenharmony_ci        }
1364bf215546Sopenharmony_ci        | DIFFUSE
1365bf215546Sopenharmony_ci        {
1366bf215546Sopenharmony_ci           $$ = STATE_DIFFUSE;
1367bf215546Sopenharmony_ci        }
1368bf215546Sopenharmony_ci        | SPECULAR
1369bf215546Sopenharmony_ci        {
1370bf215546Sopenharmony_ci           $$ = STATE_SPECULAR;
1371bf215546Sopenharmony_ci        }
1372bf215546Sopenharmony_ci        ;
1373bf215546Sopenharmony_ci
1374bf215546Sopenharmony_cistateLightNumber: INTEGER
1375bf215546Sopenharmony_ci	{
1376bf215546Sopenharmony_ci	   if ((unsigned) $1 >= state->MaxLights) {
1377bf215546Sopenharmony_ci	      yyerror(& @1, state, "invalid light selector");
1378bf215546Sopenharmony_ci	      YYERROR;
1379bf215546Sopenharmony_ci	   }
1380bf215546Sopenharmony_ci
1381bf215546Sopenharmony_ci	   $$ = $1;
1382bf215546Sopenharmony_ci	}
1383bf215546Sopenharmony_ci	;
1384bf215546Sopenharmony_ci
1385bf215546Sopenharmony_cistateTexGenItem: TEXGEN optTexCoordUnitNum stateTexGenType stateTexGenCoord
1386bf215546Sopenharmony_ci	{
1387bf215546Sopenharmony_ci	   memset($$, 0, sizeof($$));
1388bf215546Sopenharmony_ci	   $$[0] = STATE_TEXGEN;
1389bf215546Sopenharmony_ci	   $$[1] = $2;
1390bf215546Sopenharmony_ci	   $$[2] = $3 + $4;
1391bf215546Sopenharmony_ci	}
1392bf215546Sopenharmony_ci	;
1393bf215546Sopenharmony_ci
1394bf215546Sopenharmony_cistateTexGenType: EYE
1395bf215546Sopenharmony_ci	{
1396bf215546Sopenharmony_ci	   $$ = STATE_TEXGEN_EYE_S;
1397bf215546Sopenharmony_ci	}
1398bf215546Sopenharmony_ci	| OBJECT
1399bf215546Sopenharmony_ci	{
1400bf215546Sopenharmony_ci	   $$ = STATE_TEXGEN_OBJECT_S;
1401bf215546Sopenharmony_ci	}
1402bf215546Sopenharmony_ci	;
1403bf215546Sopenharmony_cistateTexGenCoord: TEXGEN_S
1404bf215546Sopenharmony_ci	{
1405bf215546Sopenharmony_ci	   $$ = STATE_TEXGEN_EYE_S - STATE_TEXGEN_EYE_S;
1406bf215546Sopenharmony_ci	}
1407bf215546Sopenharmony_ci	| TEXGEN_T
1408bf215546Sopenharmony_ci	{
1409bf215546Sopenharmony_ci	   $$ = STATE_TEXGEN_EYE_T - STATE_TEXGEN_EYE_S;
1410bf215546Sopenharmony_ci	}
1411bf215546Sopenharmony_ci	| TEXGEN_R
1412bf215546Sopenharmony_ci	{
1413bf215546Sopenharmony_ci	   $$ = STATE_TEXGEN_EYE_R - STATE_TEXGEN_EYE_S;
1414bf215546Sopenharmony_ci	}
1415bf215546Sopenharmony_ci	| TEXGEN_Q
1416bf215546Sopenharmony_ci	{
1417bf215546Sopenharmony_ci	   $$ = STATE_TEXGEN_EYE_Q - STATE_TEXGEN_EYE_S;
1418bf215546Sopenharmony_ci	}
1419bf215546Sopenharmony_ci	;
1420bf215546Sopenharmony_ci
1421bf215546Sopenharmony_cistateFogItem: FOG stateFogProperty
1422bf215546Sopenharmony_ci	{
1423bf215546Sopenharmony_ci	   memset($$, 0, sizeof($$));
1424bf215546Sopenharmony_ci	   $$[0] = $2;
1425bf215546Sopenharmony_ci	}
1426bf215546Sopenharmony_ci	;
1427bf215546Sopenharmony_ci
1428bf215546Sopenharmony_cistateFogProperty: COLOR
1429bf215546Sopenharmony_ci	{
1430bf215546Sopenharmony_ci	   $$ = STATE_FOG_COLOR;
1431bf215546Sopenharmony_ci	}
1432bf215546Sopenharmony_ci	| PARAMS
1433bf215546Sopenharmony_ci	{
1434bf215546Sopenharmony_ci	   $$ = STATE_FOG_PARAMS;
1435bf215546Sopenharmony_ci	}
1436bf215546Sopenharmony_ci	;
1437bf215546Sopenharmony_ci
1438bf215546Sopenharmony_cistateClipPlaneItem: CLIP '[' stateClipPlaneNum ']' PLANE
1439bf215546Sopenharmony_ci	{
1440bf215546Sopenharmony_ci	   memset($$, 0, sizeof($$));
1441bf215546Sopenharmony_ci	   $$[0] = STATE_CLIPPLANE;
1442bf215546Sopenharmony_ci	   $$[1] = $3;
1443bf215546Sopenharmony_ci	}
1444bf215546Sopenharmony_ci	;
1445bf215546Sopenharmony_ci
1446bf215546Sopenharmony_cistateClipPlaneNum: INTEGER
1447bf215546Sopenharmony_ci	{
1448bf215546Sopenharmony_ci	   if ((unsigned) $1 >= state->MaxClipPlanes) {
1449bf215546Sopenharmony_ci	      yyerror(& @1, state, "invalid clip plane selector");
1450bf215546Sopenharmony_ci	      YYERROR;
1451bf215546Sopenharmony_ci	   }
1452bf215546Sopenharmony_ci
1453bf215546Sopenharmony_ci	   $$ = $1;
1454bf215546Sopenharmony_ci	}
1455bf215546Sopenharmony_ci	;
1456bf215546Sopenharmony_ci
1457bf215546Sopenharmony_cistatePointItem: POINT_TOK statePointProperty
1458bf215546Sopenharmony_ci	{
1459bf215546Sopenharmony_ci	   memset($$, 0, sizeof($$));
1460bf215546Sopenharmony_ci	   $$[0] = $2;
1461bf215546Sopenharmony_ci	}
1462bf215546Sopenharmony_ci	;
1463bf215546Sopenharmony_ci
1464bf215546Sopenharmony_cistatePointProperty: SIZE_TOK
1465bf215546Sopenharmony_ci	{
1466bf215546Sopenharmony_ci	   $$ = STATE_POINT_SIZE;
1467bf215546Sopenharmony_ci	}
1468bf215546Sopenharmony_ci	| ATTENUATION
1469bf215546Sopenharmony_ci	{
1470bf215546Sopenharmony_ci	   $$ = STATE_POINT_ATTENUATION;
1471bf215546Sopenharmony_ci	}
1472bf215546Sopenharmony_ci	;
1473bf215546Sopenharmony_ci
1474bf215546Sopenharmony_cistateMatrixRow: stateMatrixItem ROW '[' stateMatrixRowNum ']'
1475bf215546Sopenharmony_ci	{
1476bf215546Sopenharmony_ci	   $$[0] = $1[0] + $1[2];
1477bf215546Sopenharmony_ci	   $$[1] = $1[1];
1478bf215546Sopenharmony_ci	   $$[2] = $4;
1479bf215546Sopenharmony_ci	   $$[3] = $4;
1480bf215546Sopenharmony_ci	}
1481bf215546Sopenharmony_ci	;
1482bf215546Sopenharmony_ci
1483bf215546Sopenharmony_cistateMatrixRows: stateMatrixItem optMatrixRows
1484bf215546Sopenharmony_ci	{
1485bf215546Sopenharmony_ci	   $$[0] = $1[0] + $1[2];
1486bf215546Sopenharmony_ci	   $$[1] = $1[1];
1487bf215546Sopenharmony_ci	   $$[2] = $2[2];
1488bf215546Sopenharmony_ci	   $$[3] = $2[3];
1489bf215546Sopenharmony_ci	}
1490bf215546Sopenharmony_ci	;
1491bf215546Sopenharmony_ci
1492bf215546Sopenharmony_cioptMatrixRows:
1493bf215546Sopenharmony_ci	{
1494bf215546Sopenharmony_ci	   $$[2] = 0;
1495bf215546Sopenharmony_ci	   $$[3] = 3;
1496bf215546Sopenharmony_ci	}
1497bf215546Sopenharmony_ci	| ROW '[' stateMatrixRowNum DOT_DOT stateMatrixRowNum ']'
1498bf215546Sopenharmony_ci	{
1499bf215546Sopenharmony_ci	   /* It seems logical that the matrix row range specifier would have
1500bf215546Sopenharmony_ci	    * to specify a range or more than one row (i.e., $5 > $3).
1501bf215546Sopenharmony_ci	    * However, the ARB_vertex_program spec says "a program will fail
1502bf215546Sopenharmony_ci	    * to load if <a> is greater than <b>."  This means that $3 == $5
1503bf215546Sopenharmony_ci	    * is valid.
1504bf215546Sopenharmony_ci	    */
1505bf215546Sopenharmony_ci	   if ($3 > $5) {
1506bf215546Sopenharmony_ci	      yyerror(& @3, state, "invalid matrix row range");
1507bf215546Sopenharmony_ci	      YYERROR;
1508bf215546Sopenharmony_ci	   }
1509bf215546Sopenharmony_ci
1510bf215546Sopenharmony_ci	   $$[2] = $3;
1511bf215546Sopenharmony_ci	   $$[3] = $5;
1512bf215546Sopenharmony_ci	}
1513bf215546Sopenharmony_ci	;
1514bf215546Sopenharmony_ci
1515bf215546Sopenharmony_cistateMatrixItem: MATRIX stateMatrixName stateOptMatModifier
1516bf215546Sopenharmony_ci	{
1517bf215546Sopenharmony_ci	   $$[0] = $2[0];
1518bf215546Sopenharmony_ci	   $$[1] = $2[1];
1519bf215546Sopenharmony_ci	   $$[2] = $3;
1520bf215546Sopenharmony_ci	}
1521bf215546Sopenharmony_ci	;
1522bf215546Sopenharmony_ci
1523bf215546Sopenharmony_cistateOptMatModifier:
1524bf215546Sopenharmony_ci	{
1525bf215546Sopenharmony_ci	   $$ = STATE_MATRIX_NO_MODIFIER;
1526bf215546Sopenharmony_ci	}
1527bf215546Sopenharmony_ci	| stateMatModifier
1528bf215546Sopenharmony_ci	{
1529bf215546Sopenharmony_ci	   $$ = $1;
1530bf215546Sopenharmony_ci	}
1531bf215546Sopenharmony_ci	;
1532bf215546Sopenharmony_ci
1533bf215546Sopenharmony_cistateMatModifier: INVERSE
1534bf215546Sopenharmony_ci	{
1535bf215546Sopenharmony_ci	   $$ = STATE_MATRIX_INVERSE;
1536bf215546Sopenharmony_ci	}
1537bf215546Sopenharmony_ci	| TRANSPOSE
1538bf215546Sopenharmony_ci	{
1539bf215546Sopenharmony_ci	   $$ = STATE_MATRIX_TRANSPOSE;
1540bf215546Sopenharmony_ci	}
1541bf215546Sopenharmony_ci	| INVTRANS
1542bf215546Sopenharmony_ci	{
1543bf215546Sopenharmony_ci	   $$ = STATE_MATRIX_INVTRANS;
1544bf215546Sopenharmony_ci	}
1545bf215546Sopenharmony_ci	;
1546bf215546Sopenharmony_ci
1547bf215546Sopenharmony_cistateMatrixRowNum: INTEGER
1548bf215546Sopenharmony_ci	{
1549bf215546Sopenharmony_ci	   if ($1 > 3) {
1550bf215546Sopenharmony_ci	      yyerror(& @1, state, "invalid matrix row reference");
1551bf215546Sopenharmony_ci	      YYERROR;
1552bf215546Sopenharmony_ci	   }
1553bf215546Sopenharmony_ci
1554bf215546Sopenharmony_ci	   $$ = $1;
1555bf215546Sopenharmony_ci	}
1556bf215546Sopenharmony_ci	;
1557bf215546Sopenharmony_ci
1558bf215546Sopenharmony_cistateMatrixName: MODELVIEW stateOptModMatNum
1559bf215546Sopenharmony_ci	{
1560bf215546Sopenharmony_ci	   $$[0] = STATE_MODELVIEW_MATRIX;
1561bf215546Sopenharmony_ci	   $$[1] = $2;
1562bf215546Sopenharmony_ci	}
1563bf215546Sopenharmony_ci	| PROJECTION
1564bf215546Sopenharmony_ci	{
1565bf215546Sopenharmony_ci	   $$[0] = STATE_PROJECTION_MATRIX;
1566bf215546Sopenharmony_ci	   $$[1] = 0;
1567bf215546Sopenharmony_ci	}
1568bf215546Sopenharmony_ci	| MVP
1569bf215546Sopenharmony_ci	{
1570bf215546Sopenharmony_ci	   $$[0] = STATE_MVP_MATRIX;
1571bf215546Sopenharmony_ci	   $$[1] = 0;
1572bf215546Sopenharmony_ci	}
1573bf215546Sopenharmony_ci	| TEXTURE optTexCoordUnitNum
1574bf215546Sopenharmony_ci	{
1575bf215546Sopenharmony_ci	   $$[0] = STATE_TEXTURE_MATRIX;
1576bf215546Sopenharmony_ci	   $$[1] = $2;
1577bf215546Sopenharmony_ci	}
1578bf215546Sopenharmony_ci	| PALETTE '[' statePaletteMatNum ']'
1579bf215546Sopenharmony_ci	{
1580bf215546Sopenharmony_ci	   yyerror(& @1, state, "GL_ARB_matrix_palette not supported");
1581bf215546Sopenharmony_ci	   YYERROR;
1582bf215546Sopenharmony_ci	}
1583bf215546Sopenharmony_ci	| MAT_PROGRAM '[' stateProgramMatNum ']'
1584bf215546Sopenharmony_ci	{
1585bf215546Sopenharmony_ci	   $$[0] = STATE_PROGRAM_MATRIX;
1586bf215546Sopenharmony_ci	   $$[1] = $3;
1587bf215546Sopenharmony_ci	}
1588bf215546Sopenharmony_ci	;
1589bf215546Sopenharmony_ci
1590bf215546Sopenharmony_cistateOptModMatNum:
1591bf215546Sopenharmony_ci	{
1592bf215546Sopenharmony_ci	   $$ = 0;
1593bf215546Sopenharmony_ci	}
1594bf215546Sopenharmony_ci	| '[' stateModMatNum ']'
1595bf215546Sopenharmony_ci	{
1596bf215546Sopenharmony_ci	   $$ = $2;
1597bf215546Sopenharmony_ci	}
1598bf215546Sopenharmony_ci	;
1599bf215546Sopenharmony_cistateModMatNum: INTEGER
1600bf215546Sopenharmony_ci	{
1601bf215546Sopenharmony_ci	   /* Since GL_ARB_vertex_blend isn't supported, only modelview matrix
1602bf215546Sopenharmony_ci	    * zero is valid.
1603bf215546Sopenharmony_ci	    */
1604bf215546Sopenharmony_ci	   if ($1 != 0) {
1605bf215546Sopenharmony_ci	      yyerror(& @1, state, "invalid modelview matrix index");
1606bf215546Sopenharmony_ci	      YYERROR;
1607bf215546Sopenharmony_ci	   }
1608bf215546Sopenharmony_ci
1609bf215546Sopenharmony_ci	   $$ = $1;
1610bf215546Sopenharmony_ci	}
1611bf215546Sopenharmony_ci	;
1612bf215546Sopenharmony_cistatePaletteMatNum: INTEGER
1613bf215546Sopenharmony_ci	{
1614bf215546Sopenharmony_ci	   /* Since GL_ARB_matrix_palette isn't supported, just let any value
1615bf215546Sopenharmony_ci	    * through here.  The error will be generated later.
1616bf215546Sopenharmony_ci	    */
1617bf215546Sopenharmony_ci	   $$ = $1;
1618bf215546Sopenharmony_ci	}
1619bf215546Sopenharmony_ci	;
1620bf215546Sopenharmony_cistateProgramMatNum: INTEGER
1621bf215546Sopenharmony_ci	{
1622bf215546Sopenharmony_ci	   if ((unsigned) $1 >= state->MaxProgramMatrices) {
1623bf215546Sopenharmony_ci	      yyerror(& @1, state, "invalid program matrix selector");
1624bf215546Sopenharmony_ci	      YYERROR;
1625bf215546Sopenharmony_ci	   }
1626bf215546Sopenharmony_ci
1627bf215546Sopenharmony_ci	   $$ = $1;
1628bf215546Sopenharmony_ci	}
1629bf215546Sopenharmony_ci	;
1630bf215546Sopenharmony_ci
1631bf215546Sopenharmony_cistateDepthItem: DEPTH RANGE
1632bf215546Sopenharmony_ci	{
1633bf215546Sopenharmony_ci	   memset($$, 0, sizeof($$));
1634bf215546Sopenharmony_ci	   $$[0] = STATE_DEPTH_RANGE;
1635bf215546Sopenharmony_ci	}
1636bf215546Sopenharmony_ci	;
1637bf215546Sopenharmony_ci
1638bf215546Sopenharmony_ci
1639bf215546Sopenharmony_ciprogramSingleItem: progEnvParam | progLocalParam;
1640bf215546Sopenharmony_ci
1641bf215546Sopenharmony_ciprogramMultipleItem: progEnvParams | progLocalParams;
1642bf215546Sopenharmony_ci
1643bf215546Sopenharmony_ciprogEnvParams: PROGRAM ENV '[' progEnvParamNums ']'
1644bf215546Sopenharmony_ci	{
1645bf215546Sopenharmony_ci	   memset($$, 0, sizeof($$));
1646bf215546Sopenharmony_ci	   $$[0] = state->state_param_enum_env;
1647bf215546Sopenharmony_ci	   $$[1] = $4[0];
1648bf215546Sopenharmony_ci	   $$[2] = $4[1];
1649bf215546Sopenharmony_ci           $$[3] = 0;
1650bf215546Sopenharmony_ci	}
1651bf215546Sopenharmony_ci	;
1652bf215546Sopenharmony_ci
1653bf215546Sopenharmony_ciprogEnvParamNums: progEnvParamNum
1654bf215546Sopenharmony_ci	{
1655bf215546Sopenharmony_ci	   $$[0] = $1;
1656bf215546Sopenharmony_ci	   $$[1] = $1;
1657bf215546Sopenharmony_ci	}
1658bf215546Sopenharmony_ci	| progEnvParamNum DOT_DOT progEnvParamNum
1659bf215546Sopenharmony_ci	{
1660bf215546Sopenharmony_ci	   $$[0] = $1;
1661bf215546Sopenharmony_ci	   $$[1] = $3;
1662bf215546Sopenharmony_ci	}
1663bf215546Sopenharmony_ci	;
1664bf215546Sopenharmony_ci
1665bf215546Sopenharmony_ciprogEnvParam: PROGRAM ENV '[' progEnvParamNum ']'
1666bf215546Sopenharmony_ci	{
1667bf215546Sopenharmony_ci	   memset($$, 0, sizeof($$));
1668bf215546Sopenharmony_ci	   $$[0] = state->state_param_enum_env;
1669bf215546Sopenharmony_ci	   $$[1] = $4;
1670bf215546Sopenharmony_ci	   $$[2] = $4;
1671bf215546Sopenharmony_ci           $$[3] = 0;
1672bf215546Sopenharmony_ci	}
1673bf215546Sopenharmony_ci	;
1674bf215546Sopenharmony_ci
1675bf215546Sopenharmony_ciprogLocalParams: PROGRAM LOCAL '[' progLocalParamNums ']'
1676bf215546Sopenharmony_ci	{
1677bf215546Sopenharmony_ci	   memset($$, 0, sizeof($$));
1678bf215546Sopenharmony_ci	   $$[0] = state->state_param_enum_local;
1679bf215546Sopenharmony_ci	   $$[1] = $4[0];
1680bf215546Sopenharmony_ci	   $$[2] = $4[1];
1681bf215546Sopenharmony_ci           $$[3] = 0;
1682bf215546Sopenharmony_ci	}
1683bf215546Sopenharmony_ci
1684bf215546Sopenharmony_ciprogLocalParamNums: progLocalParamNum
1685bf215546Sopenharmony_ci	{
1686bf215546Sopenharmony_ci	   $$[0] = $1;
1687bf215546Sopenharmony_ci	   $$[1] = $1;
1688bf215546Sopenharmony_ci	}
1689bf215546Sopenharmony_ci	| progLocalParamNum DOT_DOT progLocalParamNum
1690bf215546Sopenharmony_ci	{
1691bf215546Sopenharmony_ci	   $$[0] = $1;
1692bf215546Sopenharmony_ci	   $$[1] = $3;
1693bf215546Sopenharmony_ci	}
1694bf215546Sopenharmony_ci	;
1695bf215546Sopenharmony_ci
1696bf215546Sopenharmony_ciprogLocalParam: PROGRAM LOCAL '[' progLocalParamNum ']'
1697bf215546Sopenharmony_ci	{
1698bf215546Sopenharmony_ci	   memset($$, 0, sizeof($$));
1699bf215546Sopenharmony_ci	   $$[0] = state->state_param_enum_local;
1700bf215546Sopenharmony_ci	   $$[1] = $4;
1701bf215546Sopenharmony_ci	   $$[2] = $4;
1702bf215546Sopenharmony_ci           $$[3] = 0;
1703bf215546Sopenharmony_ci	}
1704bf215546Sopenharmony_ci	;
1705bf215546Sopenharmony_ci
1706bf215546Sopenharmony_ciprogEnvParamNum: INTEGER
1707bf215546Sopenharmony_ci	{
1708bf215546Sopenharmony_ci	   if ((unsigned) $1 >= state->limits->MaxEnvParams) {
1709bf215546Sopenharmony_ci	      yyerror(& @1, state, "invalid environment parameter reference");
1710bf215546Sopenharmony_ci	      YYERROR;
1711bf215546Sopenharmony_ci	   }
1712bf215546Sopenharmony_ci	   $$ = $1;
1713bf215546Sopenharmony_ci	}
1714bf215546Sopenharmony_ci	;
1715bf215546Sopenharmony_ci
1716bf215546Sopenharmony_ciprogLocalParamNum: INTEGER
1717bf215546Sopenharmony_ci	{
1718bf215546Sopenharmony_ci	   if ((unsigned) $1 >= state->limits->MaxLocalParams) {
1719bf215546Sopenharmony_ci	      yyerror(& @1, state, "invalid local parameter reference");
1720bf215546Sopenharmony_ci	      YYERROR;
1721bf215546Sopenharmony_ci	   }
1722bf215546Sopenharmony_ci	   $$ = $1;
1723bf215546Sopenharmony_ci	}
1724bf215546Sopenharmony_ci	;
1725bf215546Sopenharmony_ci
1726bf215546Sopenharmony_ci
1727bf215546Sopenharmony_ci
1728bf215546Sopenharmony_ciparamConstDecl: paramConstScalarDecl | paramConstVector;
1729bf215546Sopenharmony_ciparamConstUse: paramConstScalarUse | paramConstVector;
1730bf215546Sopenharmony_ci
1731bf215546Sopenharmony_ciparamConstScalarDecl: signedFloatConstant
1732bf215546Sopenharmony_ci	{
1733bf215546Sopenharmony_ci	   $$.count = 4;
1734bf215546Sopenharmony_ci	   $$.data[0].f = $1;
1735bf215546Sopenharmony_ci	   $$.data[1].f = $1;
1736bf215546Sopenharmony_ci	   $$.data[2].f = $1;
1737bf215546Sopenharmony_ci	   $$.data[3].f = $1;
1738bf215546Sopenharmony_ci	}
1739bf215546Sopenharmony_ci	;
1740bf215546Sopenharmony_ci
1741bf215546Sopenharmony_ciparamConstScalarUse: REAL
1742bf215546Sopenharmony_ci	{
1743bf215546Sopenharmony_ci	   $$.count = 1;
1744bf215546Sopenharmony_ci	   $$.data[0].f = $1;
1745bf215546Sopenharmony_ci	   $$.data[1].f = $1;
1746bf215546Sopenharmony_ci	   $$.data[2].f = $1;
1747bf215546Sopenharmony_ci	   $$.data[3].f = $1;
1748bf215546Sopenharmony_ci	}
1749bf215546Sopenharmony_ci	| INTEGER
1750bf215546Sopenharmony_ci	{
1751bf215546Sopenharmony_ci	   $$.count = 1;
1752bf215546Sopenharmony_ci	   $$.data[0].f = (float) $1;
1753bf215546Sopenharmony_ci	   $$.data[1].f = (float) $1;
1754bf215546Sopenharmony_ci	   $$.data[2].f = (float) $1;
1755bf215546Sopenharmony_ci	   $$.data[3].f = (float) $1;
1756bf215546Sopenharmony_ci	}
1757bf215546Sopenharmony_ci	;
1758bf215546Sopenharmony_ci
1759bf215546Sopenharmony_ciparamConstVector: '{' signedFloatConstant '}'
1760bf215546Sopenharmony_ci	{
1761bf215546Sopenharmony_ci	   $$.count = 4;
1762bf215546Sopenharmony_ci	   $$.data[0].f = $2;
1763bf215546Sopenharmony_ci	   $$.data[1].f = 0.0f;
1764bf215546Sopenharmony_ci	   $$.data[2].f = 0.0f;
1765bf215546Sopenharmony_ci	   $$.data[3].f = 1.0f;
1766bf215546Sopenharmony_ci	}
1767bf215546Sopenharmony_ci	| '{' signedFloatConstant ',' signedFloatConstant '}'
1768bf215546Sopenharmony_ci	{
1769bf215546Sopenharmony_ci	   $$.count = 4;
1770bf215546Sopenharmony_ci	   $$.data[0].f = $2;
1771bf215546Sopenharmony_ci	   $$.data[1].f = $4;
1772bf215546Sopenharmony_ci	   $$.data[2].f = 0.0f;
1773bf215546Sopenharmony_ci	   $$.data[3].f = 1.0f;
1774bf215546Sopenharmony_ci	}
1775bf215546Sopenharmony_ci	| '{' signedFloatConstant ',' signedFloatConstant ','
1776bf215546Sopenharmony_ci              signedFloatConstant '}'
1777bf215546Sopenharmony_ci	{
1778bf215546Sopenharmony_ci	   $$.count = 4;
1779bf215546Sopenharmony_ci	   $$.data[0].f = $2;
1780bf215546Sopenharmony_ci	   $$.data[1].f = $4;
1781bf215546Sopenharmony_ci	   $$.data[2].f = $6;
1782bf215546Sopenharmony_ci	   $$.data[3].f = 1.0f;
1783bf215546Sopenharmony_ci	}
1784bf215546Sopenharmony_ci	| '{' signedFloatConstant ',' signedFloatConstant ','
1785bf215546Sopenharmony_ci              signedFloatConstant ',' signedFloatConstant '}'
1786bf215546Sopenharmony_ci	{
1787bf215546Sopenharmony_ci	   $$.count = 4;
1788bf215546Sopenharmony_ci	   $$.data[0].f = $2;
1789bf215546Sopenharmony_ci	   $$.data[1].f = $4;
1790bf215546Sopenharmony_ci	   $$.data[2].f = $6;
1791bf215546Sopenharmony_ci	   $$.data[3].f = $8;
1792bf215546Sopenharmony_ci	}
1793bf215546Sopenharmony_ci	;
1794bf215546Sopenharmony_ci
1795bf215546Sopenharmony_cisignedFloatConstant: optionalSign REAL
1796bf215546Sopenharmony_ci	{
1797bf215546Sopenharmony_ci	   $$ = ($1) ? -$2 : $2;
1798bf215546Sopenharmony_ci	}
1799bf215546Sopenharmony_ci	| optionalSign INTEGER
1800bf215546Sopenharmony_ci	{
1801bf215546Sopenharmony_ci	   $$ = (float)(($1) ? -$2 : $2);
1802bf215546Sopenharmony_ci	}
1803bf215546Sopenharmony_ci	;
1804bf215546Sopenharmony_ci
1805bf215546Sopenharmony_cioptionalSign: '+'        { $$ = FALSE; }
1806bf215546Sopenharmony_ci	| '-'            { $$ = TRUE;  }
1807bf215546Sopenharmony_ci	|                { $$ = FALSE; }
1808bf215546Sopenharmony_ci	;
1809bf215546Sopenharmony_ci
1810bf215546Sopenharmony_ciTEMP_statement: TEMP { $<integer>$ = $1; } varNameList
1811bf215546Sopenharmony_ci	;
1812bf215546Sopenharmony_ci
1813bf215546Sopenharmony_ciADDRESS_statement: ADDRESS { $<integer>$ = $1; } varNameList
1814bf215546Sopenharmony_ci	;
1815bf215546Sopenharmony_ci
1816bf215546Sopenharmony_civarNameList: varNameList ',' IDENTIFIER
1817bf215546Sopenharmony_ci	{
1818bf215546Sopenharmony_ci	   if (!declare_variable(state, $3, $<integer>0, & @3)) {
1819bf215546Sopenharmony_ci	      free($3);
1820bf215546Sopenharmony_ci	      YYERROR;
1821bf215546Sopenharmony_ci	   }
1822bf215546Sopenharmony_ci	}
1823bf215546Sopenharmony_ci	| IDENTIFIER
1824bf215546Sopenharmony_ci	{
1825bf215546Sopenharmony_ci	   if (!declare_variable(state, $1, $<integer>0, & @1)) {
1826bf215546Sopenharmony_ci	      free($1);
1827bf215546Sopenharmony_ci	      YYERROR;
1828bf215546Sopenharmony_ci	   }
1829bf215546Sopenharmony_ci	}
1830bf215546Sopenharmony_ci	;
1831bf215546Sopenharmony_ci
1832bf215546Sopenharmony_ciOUTPUT_statement: OUTPUT IDENTIFIER '=' resultBinding
1833bf215546Sopenharmony_ci	{
1834bf215546Sopenharmony_ci	   struct asm_symbol *const s =
1835bf215546Sopenharmony_ci	      declare_variable(state, $2, at_output, & @2);
1836bf215546Sopenharmony_ci
1837bf215546Sopenharmony_ci	   if (s == NULL) {
1838bf215546Sopenharmony_ci	      free($2);
1839bf215546Sopenharmony_ci	      YYERROR;
1840bf215546Sopenharmony_ci	   } else {
1841bf215546Sopenharmony_ci	      s->output_binding = $4;
1842bf215546Sopenharmony_ci	   }
1843bf215546Sopenharmony_ci	}
1844bf215546Sopenharmony_ci	;
1845bf215546Sopenharmony_ci
1846bf215546Sopenharmony_ciresultBinding: RESULT POSITION
1847bf215546Sopenharmony_ci	{
1848bf215546Sopenharmony_ci	   if (state->mode == ARB_vertex) {
1849bf215546Sopenharmony_ci	      $$ = VARYING_SLOT_POS;
1850bf215546Sopenharmony_ci	   } else {
1851bf215546Sopenharmony_ci	      yyerror(& @2, state, "invalid program result name");
1852bf215546Sopenharmony_ci	      YYERROR;
1853bf215546Sopenharmony_ci	   }
1854bf215546Sopenharmony_ci	}
1855bf215546Sopenharmony_ci	| RESULT FOGCOORD
1856bf215546Sopenharmony_ci	{
1857bf215546Sopenharmony_ci	   if (state->mode == ARB_vertex) {
1858bf215546Sopenharmony_ci	      $$ = VARYING_SLOT_FOGC;
1859bf215546Sopenharmony_ci	   } else {
1860bf215546Sopenharmony_ci	      yyerror(& @2, state, "invalid program result name");
1861bf215546Sopenharmony_ci	      YYERROR;
1862bf215546Sopenharmony_ci	   }
1863bf215546Sopenharmony_ci	}
1864bf215546Sopenharmony_ci	| RESULT resultColBinding
1865bf215546Sopenharmony_ci	{
1866bf215546Sopenharmony_ci	   $$ = $2;
1867bf215546Sopenharmony_ci	}
1868bf215546Sopenharmony_ci	| RESULT POINTSIZE
1869bf215546Sopenharmony_ci	{
1870bf215546Sopenharmony_ci	   if (state->mode == ARB_vertex) {
1871bf215546Sopenharmony_ci	      $$ = VARYING_SLOT_PSIZ;
1872bf215546Sopenharmony_ci	   } else {
1873bf215546Sopenharmony_ci	      yyerror(& @2, state, "invalid program result name");
1874bf215546Sopenharmony_ci	      YYERROR;
1875bf215546Sopenharmony_ci	   }
1876bf215546Sopenharmony_ci	}
1877bf215546Sopenharmony_ci	| RESULT TEXCOORD optTexCoordUnitNum
1878bf215546Sopenharmony_ci	{
1879bf215546Sopenharmony_ci	   if (state->mode == ARB_vertex) {
1880bf215546Sopenharmony_ci	      $$ = VARYING_SLOT_TEX0 + $3;
1881bf215546Sopenharmony_ci	   } else {
1882bf215546Sopenharmony_ci	      yyerror(& @2, state, "invalid program result name");
1883bf215546Sopenharmony_ci	      YYERROR;
1884bf215546Sopenharmony_ci	   }
1885bf215546Sopenharmony_ci	}
1886bf215546Sopenharmony_ci	| RESULT DEPTH
1887bf215546Sopenharmony_ci	{
1888bf215546Sopenharmony_ci	   if (state->mode == ARB_fragment) {
1889bf215546Sopenharmony_ci	      $$ = FRAG_RESULT_DEPTH;
1890bf215546Sopenharmony_ci	   } else {
1891bf215546Sopenharmony_ci	      yyerror(& @2, state, "invalid program result name");
1892bf215546Sopenharmony_ci	      YYERROR;
1893bf215546Sopenharmony_ci	   }
1894bf215546Sopenharmony_ci	}
1895bf215546Sopenharmony_ci	;
1896bf215546Sopenharmony_ci
1897bf215546Sopenharmony_ciresultColBinding: COLOR optResultFaceType optResultColorType
1898bf215546Sopenharmony_ci	{
1899bf215546Sopenharmony_ci	   $$ = $2 + $3;
1900bf215546Sopenharmony_ci	}
1901bf215546Sopenharmony_ci	;
1902bf215546Sopenharmony_ci
1903bf215546Sopenharmony_cioptResultFaceType:
1904bf215546Sopenharmony_ci	{
1905bf215546Sopenharmony_ci	   if (state->mode == ARB_vertex) {
1906bf215546Sopenharmony_ci	      $$ = VARYING_SLOT_COL0;
1907bf215546Sopenharmony_ci	   } else {
1908bf215546Sopenharmony_ci	      if (state->option.DrawBuffers)
1909bf215546Sopenharmony_ci		 $$ = FRAG_RESULT_DATA0;
1910bf215546Sopenharmony_ci	      else
1911bf215546Sopenharmony_ci		 $$ = FRAG_RESULT_COLOR;
1912bf215546Sopenharmony_ci	   }
1913bf215546Sopenharmony_ci	}
1914bf215546Sopenharmony_ci	| '[' INTEGER ']'
1915bf215546Sopenharmony_ci	{
1916bf215546Sopenharmony_ci	   if (state->mode == ARB_vertex) {
1917bf215546Sopenharmony_ci	      yyerror(& @1, state, "invalid program result name");
1918bf215546Sopenharmony_ci	      YYERROR;
1919bf215546Sopenharmony_ci	   } else {
1920bf215546Sopenharmony_ci	      if (!state->option.DrawBuffers) {
1921bf215546Sopenharmony_ci		 /* From the ARB_draw_buffers spec (same text exists
1922bf215546Sopenharmony_ci		  * for ATI_draw_buffers):
1923bf215546Sopenharmony_ci		  *
1924bf215546Sopenharmony_ci		  *     If this option is not specified, a fragment
1925bf215546Sopenharmony_ci		  *     program that attempts to bind
1926bf215546Sopenharmony_ci		  *     "result.color[n]" will fail to load, and only
1927bf215546Sopenharmony_ci		  *     "result.color" will be allowed.
1928bf215546Sopenharmony_ci		  */
1929bf215546Sopenharmony_ci		 yyerror(& @1, state,
1930bf215546Sopenharmony_ci			 "result.color[] used without "
1931bf215546Sopenharmony_ci			 "`OPTION ARB_draw_buffers' or "
1932bf215546Sopenharmony_ci			 "`OPTION ATI_draw_buffers'");
1933bf215546Sopenharmony_ci		 YYERROR;
1934bf215546Sopenharmony_ci	      } else if ($2 >= state->MaxDrawBuffers) {
1935bf215546Sopenharmony_ci		 yyerror(& @1, state,
1936bf215546Sopenharmony_ci			 "result.color[] exceeds MAX_DRAW_BUFFERS_ARB");
1937bf215546Sopenharmony_ci		 YYERROR;
1938bf215546Sopenharmony_ci	      }
1939bf215546Sopenharmony_ci	      $$ = FRAG_RESULT_DATA0 + $2;
1940bf215546Sopenharmony_ci	   }
1941bf215546Sopenharmony_ci	}
1942bf215546Sopenharmony_ci	| FRONT
1943bf215546Sopenharmony_ci	{
1944bf215546Sopenharmony_ci	   if (state->mode == ARB_vertex) {
1945bf215546Sopenharmony_ci	      $$ = VARYING_SLOT_COL0;
1946bf215546Sopenharmony_ci	   } else {
1947bf215546Sopenharmony_ci	      yyerror(& @1, state, "invalid program result name");
1948bf215546Sopenharmony_ci	      YYERROR;
1949bf215546Sopenharmony_ci	   }
1950bf215546Sopenharmony_ci	}
1951bf215546Sopenharmony_ci	| BACK
1952bf215546Sopenharmony_ci	{
1953bf215546Sopenharmony_ci	   if (state->mode == ARB_vertex) {
1954bf215546Sopenharmony_ci	      $$ = VARYING_SLOT_BFC0;
1955bf215546Sopenharmony_ci	   } else {
1956bf215546Sopenharmony_ci	      yyerror(& @1, state, "invalid program result name");
1957bf215546Sopenharmony_ci	      YYERROR;
1958bf215546Sopenharmony_ci	   }
1959bf215546Sopenharmony_ci	}
1960bf215546Sopenharmony_ci	;
1961bf215546Sopenharmony_ci
1962bf215546Sopenharmony_cioptResultColorType:
1963bf215546Sopenharmony_ci	{
1964bf215546Sopenharmony_ci	   $$ = 0;
1965bf215546Sopenharmony_ci	}
1966bf215546Sopenharmony_ci	| PRIMARY
1967bf215546Sopenharmony_ci	{
1968bf215546Sopenharmony_ci	   if (state->mode == ARB_vertex) {
1969bf215546Sopenharmony_ci	      $$ = 0;
1970bf215546Sopenharmony_ci	   } else {
1971bf215546Sopenharmony_ci	      yyerror(& @1, state, "invalid program result name");
1972bf215546Sopenharmony_ci	      YYERROR;
1973bf215546Sopenharmony_ci	   }
1974bf215546Sopenharmony_ci	}
1975bf215546Sopenharmony_ci	| SECONDARY
1976bf215546Sopenharmony_ci	{
1977bf215546Sopenharmony_ci	   if (state->mode == ARB_vertex) {
1978bf215546Sopenharmony_ci	      $$ = 1;
1979bf215546Sopenharmony_ci	   } else {
1980bf215546Sopenharmony_ci	      yyerror(& @1, state, "invalid program result name");
1981bf215546Sopenharmony_ci	      YYERROR;
1982bf215546Sopenharmony_ci	   }
1983bf215546Sopenharmony_ci	}
1984bf215546Sopenharmony_ci	;
1985bf215546Sopenharmony_ci
1986bf215546Sopenharmony_cioptFaceType:    { $$ = 0; }
1987bf215546Sopenharmony_ci	| FRONT	{ $$ = 0; }
1988bf215546Sopenharmony_ci	| BACK  { $$ = 1; }
1989bf215546Sopenharmony_ci	;
1990bf215546Sopenharmony_ci
1991bf215546Sopenharmony_cioptColorType:       { $$ = 0; }
1992bf215546Sopenharmony_ci	| PRIMARY   { $$ = 0; }
1993bf215546Sopenharmony_ci	| SECONDARY { $$ = 1; }
1994bf215546Sopenharmony_ci	;
1995bf215546Sopenharmony_ci
1996bf215546Sopenharmony_cioptTexCoordUnitNum:                { $$ = 0; }
1997bf215546Sopenharmony_ci	| '[' texCoordUnitNum ']'  { $$ = $2; }
1998bf215546Sopenharmony_ci	;
1999bf215546Sopenharmony_ci
2000bf215546Sopenharmony_cioptTexImageUnitNum:                { $$ = 0; }
2001bf215546Sopenharmony_ci	| '[' texImageUnitNum ']'  { $$ = $2; }
2002bf215546Sopenharmony_ci	;
2003bf215546Sopenharmony_ci
2004bf215546Sopenharmony_cioptLegacyTexUnitNum:               { $$ = 0; }
2005bf215546Sopenharmony_ci	| '[' legacyTexUnitNum ']' { $$ = $2; }
2006bf215546Sopenharmony_ci	;
2007bf215546Sopenharmony_ci
2008bf215546Sopenharmony_citexCoordUnitNum: INTEGER
2009bf215546Sopenharmony_ci	{
2010bf215546Sopenharmony_ci	   if ((unsigned) $1 >= state->MaxTextureCoordUnits) {
2011bf215546Sopenharmony_ci	      yyerror(& @1, state, "invalid texture coordinate unit selector");
2012bf215546Sopenharmony_ci	      YYERROR;
2013bf215546Sopenharmony_ci	   }
2014bf215546Sopenharmony_ci
2015bf215546Sopenharmony_ci	   $$ = $1;
2016bf215546Sopenharmony_ci	}
2017bf215546Sopenharmony_ci	;
2018bf215546Sopenharmony_ci
2019bf215546Sopenharmony_citexImageUnitNum: INTEGER
2020bf215546Sopenharmony_ci	{
2021bf215546Sopenharmony_ci	   if ((unsigned) $1 >= state->MaxTextureImageUnits) {
2022bf215546Sopenharmony_ci	      yyerror(& @1, state, "invalid texture image unit selector");
2023bf215546Sopenharmony_ci	      YYERROR;
2024bf215546Sopenharmony_ci	   }
2025bf215546Sopenharmony_ci
2026bf215546Sopenharmony_ci	   $$ = $1;
2027bf215546Sopenharmony_ci	}
2028bf215546Sopenharmony_ci	;
2029bf215546Sopenharmony_ci
2030bf215546Sopenharmony_cilegacyTexUnitNum: INTEGER
2031bf215546Sopenharmony_ci	{
2032bf215546Sopenharmony_ci	   if ((unsigned) $1 >= state->MaxTextureUnits) {
2033bf215546Sopenharmony_ci	      yyerror(& @1, state, "invalid texture unit selector");
2034bf215546Sopenharmony_ci	      YYERROR;
2035bf215546Sopenharmony_ci	   }
2036bf215546Sopenharmony_ci
2037bf215546Sopenharmony_ci	   $$ = $1;
2038bf215546Sopenharmony_ci	}
2039bf215546Sopenharmony_ci	;
2040bf215546Sopenharmony_ci
2041bf215546Sopenharmony_ciALIAS_statement: ALIAS IDENTIFIER '=' USED_IDENTIFIER
2042bf215546Sopenharmony_ci	{
2043bf215546Sopenharmony_ci	   struct asm_symbol *exist = (struct asm_symbol *)
2044bf215546Sopenharmony_ci              _mesa_symbol_table_find_symbol(state->st, $2);
2045bf215546Sopenharmony_ci	   struct asm_symbol *target = (struct asm_symbol *)
2046bf215546Sopenharmony_ci              _mesa_symbol_table_find_symbol(state->st, $4);
2047bf215546Sopenharmony_ci
2048bf215546Sopenharmony_ci	   free($4);
2049bf215546Sopenharmony_ci
2050bf215546Sopenharmony_ci	   if (exist != NULL) {
2051bf215546Sopenharmony_ci	      char m[1000];
2052bf215546Sopenharmony_ci	      snprintf(m, sizeof(m), "redeclared identifier: %s", $2);
2053bf215546Sopenharmony_ci	      free($2);
2054bf215546Sopenharmony_ci	      yyerror(& @2, state, m);
2055bf215546Sopenharmony_ci	      YYERROR;
2056bf215546Sopenharmony_ci	   } else if (target == NULL) {
2057bf215546Sopenharmony_ci	      free($2);
2058bf215546Sopenharmony_ci	      yyerror(& @4, state,
2059bf215546Sopenharmony_ci		      "undefined variable binding in ALIAS statement");
2060bf215546Sopenharmony_ci	      YYERROR;
2061bf215546Sopenharmony_ci	   } else {
2062bf215546Sopenharmony_ci              _mesa_symbol_table_add_symbol(state->st, $2, target);
2063bf215546Sopenharmony_ci	   }
2064bf215546Sopenharmony_ci	}
2065bf215546Sopenharmony_ci	;
2066bf215546Sopenharmony_ci
2067bf215546Sopenharmony_cistring: IDENTIFIER
2068bf215546Sopenharmony_ci	| USED_IDENTIFIER
2069bf215546Sopenharmony_ci	;
2070bf215546Sopenharmony_ci
2071bf215546Sopenharmony_ci%%
2072bf215546Sopenharmony_ci
2073bf215546Sopenharmony_civoid
2074bf215546Sopenharmony_ciasm_instruction_set_operands(struct asm_instruction *inst,
2075bf215546Sopenharmony_ci			     const struct prog_dst_register *dst,
2076bf215546Sopenharmony_ci			     const struct asm_src_register *src0,
2077bf215546Sopenharmony_ci			     const struct asm_src_register *src1,
2078bf215546Sopenharmony_ci			     const struct asm_src_register *src2)
2079bf215546Sopenharmony_ci{
2080bf215546Sopenharmony_ci   /* In the core ARB extensions only the KIL instruction doesn't have a
2081bf215546Sopenharmony_ci    * destination register.
2082bf215546Sopenharmony_ci    */
2083bf215546Sopenharmony_ci   if (dst == NULL) {
2084bf215546Sopenharmony_ci      init_dst_reg(& inst->Base.DstReg);
2085bf215546Sopenharmony_ci   } else {
2086bf215546Sopenharmony_ci      inst->Base.DstReg = *dst;
2087bf215546Sopenharmony_ci   }
2088bf215546Sopenharmony_ci
2089bf215546Sopenharmony_ci   if (src0 != NULL) {
2090bf215546Sopenharmony_ci      inst->Base.SrcReg[0] = src0->Base;
2091bf215546Sopenharmony_ci      inst->SrcReg[0] = *src0;
2092bf215546Sopenharmony_ci   } else {
2093bf215546Sopenharmony_ci      init_src_reg(& inst->SrcReg[0]);
2094bf215546Sopenharmony_ci   }
2095bf215546Sopenharmony_ci
2096bf215546Sopenharmony_ci   if (src1 != NULL) {
2097bf215546Sopenharmony_ci      inst->Base.SrcReg[1] = src1->Base;
2098bf215546Sopenharmony_ci      inst->SrcReg[1] = *src1;
2099bf215546Sopenharmony_ci   } else {
2100bf215546Sopenharmony_ci      init_src_reg(& inst->SrcReg[1]);
2101bf215546Sopenharmony_ci   }
2102bf215546Sopenharmony_ci
2103bf215546Sopenharmony_ci   if (src2 != NULL) {
2104bf215546Sopenharmony_ci      inst->Base.SrcReg[2] = src2->Base;
2105bf215546Sopenharmony_ci      inst->SrcReg[2] = *src2;
2106bf215546Sopenharmony_ci   } else {
2107bf215546Sopenharmony_ci      init_src_reg(& inst->SrcReg[2]);
2108bf215546Sopenharmony_ci   }
2109bf215546Sopenharmony_ci}
2110bf215546Sopenharmony_ci
2111bf215546Sopenharmony_ci
2112bf215546Sopenharmony_cistruct asm_instruction *
2113bf215546Sopenharmony_ciasm_instruction_ctor(enum prog_opcode op,
2114bf215546Sopenharmony_ci		     const struct prog_dst_register *dst,
2115bf215546Sopenharmony_ci		     const struct asm_src_register *src0,
2116bf215546Sopenharmony_ci		     const struct asm_src_register *src1,
2117bf215546Sopenharmony_ci		     const struct asm_src_register *src2)
2118bf215546Sopenharmony_ci{
2119bf215546Sopenharmony_ci   struct asm_instruction *inst = calloc(1, sizeof(struct asm_instruction));
2120bf215546Sopenharmony_ci
2121bf215546Sopenharmony_ci   if (inst) {
2122bf215546Sopenharmony_ci      _mesa_init_instructions(& inst->Base, 1);
2123bf215546Sopenharmony_ci      inst->Base.Opcode = op;
2124bf215546Sopenharmony_ci
2125bf215546Sopenharmony_ci      asm_instruction_set_operands(inst, dst, src0, src1, src2);
2126bf215546Sopenharmony_ci   }
2127bf215546Sopenharmony_ci
2128bf215546Sopenharmony_ci   return inst;
2129bf215546Sopenharmony_ci}
2130bf215546Sopenharmony_ci
2131bf215546Sopenharmony_ci
2132bf215546Sopenharmony_cistruct asm_instruction *
2133bf215546Sopenharmony_ciasm_instruction_copy_ctor(const struct prog_instruction *base,
2134bf215546Sopenharmony_ci			  const struct prog_dst_register *dst,
2135bf215546Sopenharmony_ci			  const struct asm_src_register *src0,
2136bf215546Sopenharmony_ci			  const struct asm_src_register *src1,
2137bf215546Sopenharmony_ci			  const struct asm_src_register *src2)
2138bf215546Sopenharmony_ci{
2139bf215546Sopenharmony_ci   struct asm_instruction *inst = CALLOC_STRUCT(asm_instruction);
2140bf215546Sopenharmony_ci
2141bf215546Sopenharmony_ci   if (inst) {
2142bf215546Sopenharmony_ci      _mesa_init_instructions(& inst->Base, 1);
2143bf215546Sopenharmony_ci      inst->Base.Opcode = base->Opcode;
2144bf215546Sopenharmony_ci      inst->Base.Saturate = base->Saturate;
2145bf215546Sopenharmony_ci
2146bf215546Sopenharmony_ci      asm_instruction_set_operands(inst, dst, src0, src1, src2);
2147bf215546Sopenharmony_ci   }
2148bf215546Sopenharmony_ci
2149bf215546Sopenharmony_ci   return inst;
2150bf215546Sopenharmony_ci}
2151bf215546Sopenharmony_ci
2152bf215546Sopenharmony_ci
2153bf215546Sopenharmony_civoid
2154bf215546Sopenharmony_ciinit_dst_reg(struct prog_dst_register *r)
2155bf215546Sopenharmony_ci{
2156bf215546Sopenharmony_ci   memset(r, 0, sizeof(*r));
2157bf215546Sopenharmony_ci   r->File = PROGRAM_UNDEFINED;
2158bf215546Sopenharmony_ci   r->WriteMask = WRITEMASK_XYZW;
2159bf215546Sopenharmony_ci}
2160bf215546Sopenharmony_ci
2161bf215546Sopenharmony_ci
2162bf215546Sopenharmony_ci/** Like init_dst_reg() but set the File and Index fields. */
2163bf215546Sopenharmony_civoid
2164bf215546Sopenharmony_ciset_dst_reg(struct prog_dst_register *r, gl_register_file file, GLint index)
2165bf215546Sopenharmony_ci{
2166bf215546Sopenharmony_ci   const GLint maxIndex = 1 << INST_INDEX_BITS;
2167bf215546Sopenharmony_ci   const GLint minIndex = 0;
2168bf215546Sopenharmony_ci   assert(index >= minIndex);
2169bf215546Sopenharmony_ci   (void) minIndex;
2170bf215546Sopenharmony_ci   assert(index <= maxIndex);
2171bf215546Sopenharmony_ci   (void) maxIndex;
2172bf215546Sopenharmony_ci   assert(file == PROGRAM_TEMPORARY ||
2173bf215546Sopenharmony_ci	  file == PROGRAM_ADDRESS ||
2174bf215546Sopenharmony_ci	  file == PROGRAM_OUTPUT);
2175bf215546Sopenharmony_ci   memset(r, 0, sizeof(*r));
2176bf215546Sopenharmony_ci   r->File = file;
2177bf215546Sopenharmony_ci   r->Index = index;
2178bf215546Sopenharmony_ci   r->WriteMask = WRITEMASK_XYZW;
2179bf215546Sopenharmony_ci}
2180bf215546Sopenharmony_ci
2181bf215546Sopenharmony_ci
2182bf215546Sopenharmony_civoid
2183bf215546Sopenharmony_ciinit_src_reg(struct asm_src_register *r)
2184bf215546Sopenharmony_ci{
2185bf215546Sopenharmony_ci   memset(r, 0, sizeof(*r));
2186bf215546Sopenharmony_ci   r->Base.File = PROGRAM_UNDEFINED;
2187bf215546Sopenharmony_ci   r->Base.Swizzle = SWIZZLE_NOOP;
2188bf215546Sopenharmony_ci   r->Symbol = NULL;
2189bf215546Sopenharmony_ci}
2190bf215546Sopenharmony_ci
2191bf215546Sopenharmony_ci
2192bf215546Sopenharmony_ci/** Like init_src_reg() but set the File and Index fields.
2193bf215546Sopenharmony_ci * \return GL_TRUE if a valid src register, GL_FALSE otherwise
2194bf215546Sopenharmony_ci */
2195bf215546Sopenharmony_civoid
2196bf215546Sopenharmony_ciset_src_reg(struct asm_src_register *r, gl_register_file file, GLint index)
2197bf215546Sopenharmony_ci{
2198bf215546Sopenharmony_ci   set_src_reg_swz(r, file, index, SWIZZLE_XYZW);
2199bf215546Sopenharmony_ci}
2200bf215546Sopenharmony_ci
2201bf215546Sopenharmony_ci
2202bf215546Sopenharmony_civoid
2203bf215546Sopenharmony_ciset_src_reg_swz(struct asm_src_register *r, gl_register_file file, GLint index,
2204bf215546Sopenharmony_ci                GLuint swizzle)
2205bf215546Sopenharmony_ci{
2206bf215546Sopenharmony_ci   const GLint maxIndex = (1 << INST_INDEX_BITS) - 1;
2207bf215546Sopenharmony_ci   const GLint minIndex = -(1 << INST_INDEX_BITS);
2208bf215546Sopenharmony_ci   assert(file < PROGRAM_FILE_MAX);
2209bf215546Sopenharmony_ci   assert(index >= minIndex);
2210bf215546Sopenharmony_ci   (void) minIndex;
2211bf215546Sopenharmony_ci   assert(index <= maxIndex);
2212bf215546Sopenharmony_ci   (void) maxIndex;
2213bf215546Sopenharmony_ci   memset(r, 0, sizeof(*r));
2214bf215546Sopenharmony_ci   r->Base.File = file;
2215bf215546Sopenharmony_ci   r->Base.Index = index;
2216bf215546Sopenharmony_ci   r->Base.Swizzle = swizzle;
2217bf215546Sopenharmony_ci   r->Symbol = NULL;
2218bf215546Sopenharmony_ci}
2219bf215546Sopenharmony_ci
2220bf215546Sopenharmony_ci
2221bf215546Sopenharmony_ci/**
2222bf215546Sopenharmony_ci * Validate the set of inputs used by a program
2223bf215546Sopenharmony_ci *
2224bf215546Sopenharmony_ci * Validates that legal sets of inputs are used by the program.  In this case
2225bf215546Sopenharmony_ci * "used" included both reading the input or binding the input to a name using
2226bf215546Sopenharmony_ci * the \c ATTRIB command.
2227bf215546Sopenharmony_ci *
2228bf215546Sopenharmony_ci * \return
2229bf215546Sopenharmony_ci * \c TRUE if the combination of inputs used is valid, \c FALSE otherwise.
2230bf215546Sopenharmony_ci */
2231bf215546Sopenharmony_ciint
2232bf215546Sopenharmony_civalidate_inputs(struct YYLTYPE *locp, struct asm_parser_state *state)
2233bf215546Sopenharmony_ci{
2234bf215546Sopenharmony_ci   const GLbitfield64 inputs = state->prog->info.inputs_read | state->InputsBound;
2235bf215546Sopenharmony_ci   GLbitfield ff_inputs = 0;
2236bf215546Sopenharmony_ci
2237bf215546Sopenharmony_ci   /* Since Mesa internal attribute indices are different from
2238bf215546Sopenharmony_ci    * how NV_vertex_program defines attribute aliasing, we have to construct
2239bf215546Sopenharmony_ci    * a separate usage mask based on how the aliasing is defined.
2240bf215546Sopenharmony_ci    *
2241bf215546Sopenharmony_ci    * Note that attribute aliasing is optional if NV_vertex_program is
2242bf215546Sopenharmony_ci    * unsupported.
2243bf215546Sopenharmony_ci    */
2244bf215546Sopenharmony_ci   if (inputs & VERT_BIT_POS)
2245bf215546Sopenharmony_ci      ff_inputs |= 1 << 0;
2246bf215546Sopenharmony_ci   if (inputs & VERT_BIT_NORMAL)
2247bf215546Sopenharmony_ci      ff_inputs |= 1 << 2;
2248bf215546Sopenharmony_ci   if (inputs & VERT_BIT_COLOR0)
2249bf215546Sopenharmony_ci      ff_inputs |= 1 << 3;
2250bf215546Sopenharmony_ci   if (inputs & VERT_BIT_COLOR1)
2251bf215546Sopenharmony_ci      ff_inputs |= 1 << 4;
2252bf215546Sopenharmony_ci   if (inputs & VERT_BIT_FOG)
2253bf215546Sopenharmony_ci      ff_inputs |= 1 << 5;
2254bf215546Sopenharmony_ci
2255bf215546Sopenharmony_ci   ff_inputs |= ((inputs & VERT_BIT_TEX_ALL) >> VERT_ATTRIB_TEX0) << 8;
2256bf215546Sopenharmony_ci
2257bf215546Sopenharmony_ci   if ((ff_inputs & (inputs >> VERT_ATTRIB_GENERIC0)) != 0) {
2258bf215546Sopenharmony_ci      yyerror(locp, state, "illegal use of generic attribute and name attribute");
2259bf215546Sopenharmony_ci      return 0;
2260bf215546Sopenharmony_ci   }
2261bf215546Sopenharmony_ci
2262bf215546Sopenharmony_ci   return 1;
2263bf215546Sopenharmony_ci}
2264bf215546Sopenharmony_ci
2265bf215546Sopenharmony_ci
2266bf215546Sopenharmony_cistruct asm_symbol *
2267bf215546Sopenharmony_cideclare_variable(struct asm_parser_state *state, char *name, enum asm_type t,
2268bf215546Sopenharmony_ci		 struct YYLTYPE *locp)
2269bf215546Sopenharmony_ci{
2270bf215546Sopenharmony_ci   struct asm_symbol *s = NULL;
2271bf215546Sopenharmony_ci   struct asm_symbol *exist = (struct asm_symbol *)
2272bf215546Sopenharmony_ci      _mesa_symbol_table_find_symbol(state->st, name);
2273bf215546Sopenharmony_ci
2274bf215546Sopenharmony_ci
2275bf215546Sopenharmony_ci   if (exist != NULL) {
2276bf215546Sopenharmony_ci      yyerror(locp, state, "redeclared identifier");
2277bf215546Sopenharmony_ci   } else {
2278bf215546Sopenharmony_ci      s = calloc(1, sizeof(struct asm_symbol));
2279bf215546Sopenharmony_ci      s->name = name;
2280bf215546Sopenharmony_ci      s->type = t;
2281bf215546Sopenharmony_ci
2282bf215546Sopenharmony_ci      switch (t) {
2283bf215546Sopenharmony_ci      case at_temp:
2284bf215546Sopenharmony_ci         if (state->prog->arb.NumTemporaries >= state->limits->MaxTemps) {
2285bf215546Sopenharmony_ci	    yyerror(locp, state, "too many temporaries declared");
2286bf215546Sopenharmony_ci	    free(s);
2287bf215546Sopenharmony_ci	    return NULL;
2288bf215546Sopenharmony_ci	 }
2289bf215546Sopenharmony_ci
2290bf215546Sopenharmony_ci         s->temp_binding = state->prog->arb.NumTemporaries;
2291bf215546Sopenharmony_ci         state->prog->arb.NumTemporaries++;
2292bf215546Sopenharmony_ci	 break;
2293bf215546Sopenharmony_ci
2294bf215546Sopenharmony_ci      case at_address:
2295bf215546Sopenharmony_ci         if (state->prog->arb.NumAddressRegs >=
2296bf215546Sopenharmony_ci             state->limits->MaxAddressRegs) {
2297bf215546Sopenharmony_ci	    yyerror(locp, state, "too many address registers declared");
2298bf215546Sopenharmony_ci	    free(s);
2299bf215546Sopenharmony_ci	    return NULL;
2300bf215546Sopenharmony_ci	 }
2301bf215546Sopenharmony_ci
2302bf215546Sopenharmony_ci	 /* FINISHME: Add support for multiple address registers.
2303bf215546Sopenharmony_ci	  */
2304bf215546Sopenharmony_ci         state->prog->arb.NumAddressRegs++;
2305bf215546Sopenharmony_ci	 break;
2306bf215546Sopenharmony_ci
2307bf215546Sopenharmony_ci      default:
2308bf215546Sopenharmony_ci	 break;
2309bf215546Sopenharmony_ci      }
2310bf215546Sopenharmony_ci
2311bf215546Sopenharmony_ci      _mesa_symbol_table_add_symbol(state->st, s->name, s);
2312bf215546Sopenharmony_ci      s->next = state->sym;
2313bf215546Sopenharmony_ci      state->sym = s;
2314bf215546Sopenharmony_ci   }
2315bf215546Sopenharmony_ci
2316bf215546Sopenharmony_ci   return s;
2317bf215546Sopenharmony_ci}
2318bf215546Sopenharmony_ci
2319bf215546Sopenharmony_ci
2320bf215546Sopenharmony_ciint add_state_reference(struct gl_program_parameter_list *param_list,
2321bf215546Sopenharmony_ci			const gl_state_index16 tokens[STATE_LENGTH])
2322bf215546Sopenharmony_ci{
2323bf215546Sopenharmony_ci   const GLuint size = 4; /* XXX fix */
2324bf215546Sopenharmony_ci   char *name;
2325bf215546Sopenharmony_ci   GLint index;
2326bf215546Sopenharmony_ci
2327bf215546Sopenharmony_ci   name = _mesa_program_state_string(tokens);
2328bf215546Sopenharmony_ci   index = _mesa_add_parameter(param_list, PROGRAM_STATE_VAR, name,
2329bf215546Sopenharmony_ci                               size, GL_NONE, NULL, tokens, true);
2330bf215546Sopenharmony_ci   param_list->StateFlags |= _mesa_program_state_flags(tokens);
2331bf215546Sopenharmony_ci
2332bf215546Sopenharmony_ci   /* free name string here since we duplicated it in add_parameter() */
2333bf215546Sopenharmony_ci   free(name);
2334bf215546Sopenharmony_ci
2335bf215546Sopenharmony_ci   return index;
2336bf215546Sopenharmony_ci}
2337bf215546Sopenharmony_ci
2338bf215546Sopenharmony_ci
2339bf215546Sopenharmony_ciint
2340bf215546Sopenharmony_ciinitialize_symbol_from_state(struct gl_program *prog,
2341bf215546Sopenharmony_ci			     struct asm_symbol *param_var,
2342bf215546Sopenharmony_ci			     const gl_state_index16 tokens[STATE_LENGTH])
2343bf215546Sopenharmony_ci{
2344bf215546Sopenharmony_ci   int idx = -1;
2345bf215546Sopenharmony_ci   gl_state_index16 state_tokens[STATE_LENGTH];
2346bf215546Sopenharmony_ci
2347bf215546Sopenharmony_ci
2348bf215546Sopenharmony_ci   memcpy(state_tokens, tokens, sizeof(state_tokens));
2349bf215546Sopenharmony_ci
2350bf215546Sopenharmony_ci   param_var->type = at_param;
2351bf215546Sopenharmony_ci   param_var->param_binding_type = PROGRAM_STATE_VAR;
2352bf215546Sopenharmony_ci
2353bf215546Sopenharmony_ci   /* If we are adding a STATE_MATRIX that has multiple rows, we need to
2354bf215546Sopenharmony_ci    * unroll it and call add_state_reference() for each row
2355bf215546Sopenharmony_ci    */
2356bf215546Sopenharmony_ci   if (state_tokens[0] >= STATE_MODELVIEW_MATRIX &&
2357bf215546Sopenharmony_ci       state_tokens[0] <= STATE_PROGRAM_MATRIX_INVTRANS
2358bf215546Sopenharmony_ci       && (state_tokens[2] != state_tokens[3])) {
2359bf215546Sopenharmony_ci      int row;
2360bf215546Sopenharmony_ci      const int first_row = state_tokens[2];
2361bf215546Sopenharmony_ci      const int last_row = state_tokens[3];
2362bf215546Sopenharmony_ci
2363bf215546Sopenharmony_ci      for (row = first_row; row <= last_row; row++) {
2364bf215546Sopenharmony_ci	 state_tokens[2] = state_tokens[3] = row;
2365bf215546Sopenharmony_ci
2366bf215546Sopenharmony_ci	 idx = add_state_reference(prog->Parameters, state_tokens);
2367bf215546Sopenharmony_ci	 if (param_var->param_binding_begin == ~0U) {
2368bf215546Sopenharmony_ci	    param_var->param_binding_begin = idx;
2369bf215546Sopenharmony_ci            param_var->param_binding_swizzle = SWIZZLE_XYZW;
2370bf215546Sopenharmony_ci         }
2371bf215546Sopenharmony_ci
2372bf215546Sopenharmony_ci	 param_var->param_binding_length++;
2373bf215546Sopenharmony_ci      }
2374bf215546Sopenharmony_ci   }
2375bf215546Sopenharmony_ci   else {
2376bf215546Sopenharmony_ci      idx = add_state_reference(prog->Parameters, state_tokens);
2377bf215546Sopenharmony_ci      if (param_var->param_binding_begin == ~0U) {
2378bf215546Sopenharmony_ci	 param_var->param_binding_begin = idx;
2379bf215546Sopenharmony_ci         param_var->param_binding_swizzle = SWIZZLE_XYZW;
2380bf215546Sopenharmony_ci      }
2381bf215546Sopenharmony_ci      param_var->param_binding_length++;
2382bf215546Sopenharmony_ci   }
2383bf215546Sopenharmony_ci
2384bf215546Sopenharmony_ci   return idx;
2385bf215546Sopenharmony_ci}
2386bf215546Sopenharmony_ci
2387bf215546Sopenharmony_ci
2388bf215546Sopenharmony_ciint
2389bf215546Sopenharmony_ciinitialize_symbol_from_param(struct gl_program *prog,
2390bf215546Sopenharmony_ci			     struct asm_symbol *param_var,
2391bf215546Sopenharmony_ci			     const gl_state_index16 tokens[STATE_LENGTH])
2392bf215546Sopenharmony_ci{
2393bf215546Sopenharmony_ci   int idx = -1;
2394bf215546Sopenharmony_ci   gl_state_index16 state_tokens[STATE_LENGTH];
2395bf215546Sopenharmony_ci
2396bf215546Sopenharmony_ci
2397bf215546Sopenharmony_ci   memcpy(state_tokens, tokens, sizeof(state_tokens));
2398bf215546Sopenharmony_ci
2399bf215546Sopenharmony_ci   assert(state_tokens[0] == STATE_VERTEX_PROGRAM_ENV ||
2400bf215546Sopenharmony_ci          state_tokens[0] == STATE_VERTEX_PROGRAM_LOCAL ||
2401bf215546Sopenharmony_ci          state_tokens[0] == STATE_FRAGMENT_PROGRAM_ENV ||
2402bf215546Sopenharmony_ci          state_tokens[0] == STATE_FRAGMENT_PROGRAM_LOCAL);
2403bf215546Sopenharmony_ci
2404bf215546Sopenharmony_ci   /*
2405bf215546Sopenharmony_ci    * The param type is STATE_VAR.  The program parameter entry will
2406bf215546Sopenharmony_ci    * effectively be a pointer into the LOCAL or ENV parameter array.
2407bf215546Sopenharmony_ci    */
2408bf215546Sopenharmony_ci   param_var->type = at_param;
2409bf215546Sopenharmony_ci   param_var->param_binding_type = PROGRAM_STATE_VAR;
2410bf215546Sopenharmony_ci
2411bf215546Sopenharmony_ci   /* If we are adding a STATE_ENV or STATE_LOCAL that has multiple elements,
2412bf215546Sopenharmony_ci    * we need to unroll it and call add_state_reference() for each row
2413bf215546Sopenharmony_ci    */
2414bf215546Sopenharmony_ci   if (state_tokens[1] != state_tokens[2]) {
2415bf215546Sopenharmony_ci      int row;
2416bf215546Sopenharmony_ci      const int first_row = state_tokens[1];
2417bf215546Sopenharmony_ci      const int last_row = state_tokens[2];
2418bf215546Sopenharmony_ci
2419bf215546Sopenharmony_ci      for (row = first_row; row <= last_row; row++) {
2420bf215546Sopenharmony_ci	 state_tokens[1] = state_tokens[2] = row;
2421bf215546Sopenharmony_ci
2422bf215546Sopenharmony_ci	 idx = add_state_reference(prog->Parameters, state_tokens);
2423bf215546Sopenharmony_ci	 if (param_var->param_binding_begin == ~0U) {
2424bf215546Sopenharmony_ci	    param_var->param_binding_begin = idx;
2425bf215546Sopenharmony_ci            param_var->param_binding_swizzle = SWIZZLE_XYZW;
2426bf215546Sopenharmony_ci         }
2427bf215546Sopenharmony_ci	 param_var->param_binding_length++;
2428bf215546Sopenharmony_ci      }
2429bf215546Sopenharmony_ci   }
2430bf215546Sopenharmony_ci   else {
2431bf215546Sopenharmony_ci      idx = add_state_reference(prog->Parameters, state_tokens);
2432bf215546Sopenharmony_ci      if (param_var->param_binding_begin == ~0U) {
2433bf215546Sopenharmony_ci	 param_var->param_binding_begin = idx;
2434bf215546Sopenharmony_ci         param_var->param_binding_swizzle = SWIZZLE_XYZW;
2435bf215546Sopenharmony_ci      }
2436bf215546Sopenharmony_ci      param_var->param_binding_length++;
2437bf215546Sopenharmony_ci   }
2438bf215546Sopenharmony_ci
2439bf215546Sopenharmony_ci   return idx;
2440bf215546Sopenharmony_ci}
2441bf215546Sopenharmony_ci
2442bf215546Sopenharmony_ci
2443bf215546Sopenharmony_ci/**
2444bf215546Sopenharmony_ci * Put a float/vector constant/literal into the parameter list.
2445bf215546Sopenharmony_ci * \param param_var  returns info about the parameter/constant's location,
2446bf215546Sopenharmony_ci *                   binding, type, etc.
2447bf215546Sopenharmony_ci * \param vec  the vector/constant to add
2448bf215546Sopenharmony_ci * \param allowSwizzle  if true, try to consolidate constants which only differ
2449bf215546Sopenharmony_ci *                      by a swizzle.  We don't want to do this when building
2450bf215546Sopenharmony_ci *                      arrays of constants that may be indexed indirectly.
2451bf215546Sopenharmony_ci * \return index of the constant in the parameter list.
2452bf215546Sopenharmony_ci */
2453bf215546Sopenharmony_ciint
2454bf215546Sopenharmony_ciinitialize_symbol_from_const(struct gl_program *prog,
2455bf215546Sopenharmony_ci			     struct asm_symbol *param_var,
2456bf215546Sopenharmony_ci			     const struct asm_vector *vec,
2457bf215546Sopenharmony_ci                             GLboolean allowSwizzle)
2458bf215546Sopenharmony_ci{
2459bf215546Sopenharmony_ci   unsigned swizzle;
2460bf215546Sopenharmony_ci   const int idx = _mesa_add_unnamed_constant(prog->Parameters,
2461bf215546Sopenharmony_ci                                              vec->data, vec->count,
2462bf215546Sopenharmony_ci                                              allowSwizzle ? &swizzle : NULL);
2463bf215546Sopenharmony_ci
2464bf215546Sopenharmony_ci   param_var->type = at_param;
2465bf215546Sopenharmony_ci   param_var->param_binding_type = PROGRAM_CONSTANT;
2466bf215546Sopenharmony_ci
2467bf215546Sopenharmony_ci   if (param_var->param_binding_begin == ~0U) {
2468bf215546Sopenharmony_ci      param_var->param_binding_begin = idx;
2469bf215546Sopenharmony_ci      param_var->param_binding_swizzle = allowSwizzle ? swizzle : SWIZZLE_XYZW;
2470bf215546Sopenharmony_ci   }
2471bf215546Sopenharmony_ci   param_var->param_binding_length++;
2472bf215546Sopenharmony_ci
2473bf215546Sopenharmony_ci   return idx;
2474bf215546Sopenharmony_ci}
2475bf215546Sopenharmony_ci
2476bf215546Sopenharmony_ci
2477bf215546Sopenharmony_cichar *
2478bf215546Sopenharmony_cimake_error_string(const char *fmt, ...)
2479bf215546Sopenharmony_ci{
2480bf215546Sopenharmony_ci   int length;
2481bf215546Sopenharmony_ci   char *str;
2482bf215546Sopenharmony_ci   va_list args;
2483bf215546Sopenharmony_ci
2484bf215546Sopenharmony_ci
2485bf215546Sopenharmony_ci   /* Call vsnprintf once to determine how large the final string is.  Call it
2486bf215546Sopenharmony_ci    * again to do the actual formatting.  from the vsnprintf manual page:
2487bf215546Sopenharmony_ci    *
2488bf215546Sopenharmony_ci    *    Upon successful return, these functions return the number of
2489bf215546Sopenharmony_ci    *    characters printed  (not including the trailing '\0' used to end
2490bf215546Sopenharmony_ci    *    output to strings).
2491bf215546Sopenharmony_ci    */
2492bf215546Sopenharmony_ci   va_start(args, fmt);
2493bf215546Sopenharmony_ci   length = 1 + vsnprintf(NULL, 0, fmt, args);
2494bf215546Sopenharmony_ci   va_end(args);
2495bf215546Sopenharmony_ci
2496bf215546Sopenharmony_ci   str = malloc(length);
2497bf215546Sopenharmony_ci   if (str) {
2498bf215546Sopenharmony_ci      va_start(args, fmt);
2499bf215546Sopenharmony_ci      vsnprintf(str, length, fmt, args);
2500bf215546Sopenharmony_ci      va_end(args);
2501bf215546Sopenharmony_ci   }
2502bf215546Sopenharmony_ci
2503bf215546Sopenharmony_ci   return str;
2504bf215546Sopenharmony_ci}
2505bf215546Sopenharmony_ci
2506bf215546Sopenharmony_ci
2507bf215546Sopenharmony_civoid
2508bf215546Sopenharmony_ciyyerror(YYLTYPE *locp, struct asm_parser_state *state, const char *s)
2509bf215546Sopenharmony_ci{
2510bf215546Sopenharmony_ci   char *err_str;
2511bf215546Sopenharmony_ci
2512bf215546Sopenharmony_ci
2513bf215546Sopenharmony_ci   err_str = make_error_string("glProgramStringARB(%s)\n", s);
2514bf215546Sopenharmony_ci   if (err_str) {
2515bf215546Sopenharmony_ci      _mesa_error(state->ctx, GL_INVALID_OPERATION, "%s", err_str);
2516bf215546Sopenharmony_ci      free(err_str);
2517bf215546Sopenharmony_ci   }
2518bf215546Sopenharmony_ci
2519bf215546Sopenharmony_ci   err_str = make_error_string("line %u, char %u: error: %s\n",
2520bf215546Sopenharmony_ci			       locp->first_line, locp->first_column, s);
2521bf215546Sopenharmony_ci   _mesa_set_program_error(state->ctx, locp->position, err_str);
2522bf215546Sopenharmony_ci
2523bf215546Sopenharmony_ci   if (err_str) {
2524bf215546Sopenharmony_ci      free(err_str);
2525bf215546Sopenharmony_ci   }
2526bf215546Sopenharmony_ci}
2527bf215546Sopenharmony_ci
2528bf215546Sopenharmony_ci
2529bf215546Sopenharmony_ciGLboolean
2530bf215546Sopenharmony_ci_mesa_parse_arb_program(struct gl_context *ctx, GLenum target, const GLubyte *str,
2531bf215546Sopenharmony_ci			GLsizei len, struct asm_parser_state *state)
2532bf215546Sopenharmony_ci{
2533bf215546Sopenharmony_ci   struct asm_instruction *inst;
2534bf215546Sopenharmony_ci   unsigned i;
2535bf215546Sopenharmony_ci   GLubyte *strz;
2536bf215546Sopenharmony_ci   GLboolean result = GL_FALSE;
2537bf215546Sopenharmony_ci   void *temp;
2538bf215546Sopenharmony_ci   struct asm_symbol *sym;
2539bf215546Sopenharmony_ci
2540bf215546Sopenharmony_ci   state->ctx = ctx;
2541bf215546Sopenharmony_ci   state->prog->Target = target;
2542bf215546Sopenharmony_ci   state->prog->Parameters = _mesa_new_parameter_list();
2543bf215546Sopenharmony_ci
2544bf215546Sopenharmony_ci   /* Make a copy of the program string and force it to be newline and NUL-terminated.
2545bf215546Sopenharmony_ci    */
2546bf215546Sopenharmony_ci   strz = (GLubyte *) ralloc_size(state->mem_ctx, len + 2);
2547bf215546Sopenharmony_ci   if (strz == NULL) {
2548bf215546Sopenharmony_ci      if (state->prog->Parameters) {
2549bf215546Sopenharmony_ci         _mesa_free_parameter_list(state->prog->Parameters);
2550bf215546Sopenharmony_ci         state->prog->Parameters = NULL;
2551bf215546Sopenharmony_ci      }
2552bf215546Sopenharmony_ci      _mesa_error(ctx, GL_OUT_OF_MEMORY, "glProgramStringARB");
2553bf215546Sopenharmony_ci      return GL_FALSE;
2554bf215546Sopenharmony_ci   }
2555bf215546Sopenharmony_ci   memcpy (strz, str, len);
2556bf215546Sopenharmony_ci   strz[len]     = '\n';
2557bf215546Sopenharmony_ci   strz[len + 1] = '\0';
2558bf215546Sopenharmony_ci
2559bf215546Sopenharmony_ci   state->prog->String = strz;
2560bf215546Sopenharmony_ci
2561bf215546Sopenharmony_ci   state->st = _mesa_symbol_table_ctor();
2562bf215546Sopenharmony_ci
2563bf215546Sopenharmony_ci   state->limits = (target == GL_VERTEX_PROGRAM_ARB)
2564bf215546Sopenharmony_ci      ? & ctx->Const.Program[MESA_SHADER_VERTEX]
2565bf215546Sopenharmony_ci      : & ctx->Const.Program[MESA_SHADER_FRAGMENT];
2566bf215546Sopenharmony_ci
2567bf215546Sopenharmony_ci   state->MaxTextureImageUnits = ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxTextureImageUnits;
2568bf215546Sopenharmony_ci   state->MaxTextureCoordUnits = ctx->Const.MaxTextureCoordUnits;
2569bf215546Sopenharmony_ci   state->MaxTextureUnits = ctx->Const.MaxTextureUnits;
2570bf215546Sopenharmony_ci   state->MaxClipPlanes = ctx->Const.MaxClipPlanes;
2571bf215546Sopenharmony_ci   state->MaxLights = ctx->Const.MaxLights;
2572bf215546Sopenharmony_ci   state->MaxProgramMatrices = ctx->Const.MaxProgramMatrices;
2573bf215546Sopenharmony_ci   state->MaxDrawBuffers = ctx->Const.MaxDrawBuffers;
2574bf215546Sopenharmony_ci
2575bf215546Sopenharmony_ci   state->state_param_enum_env = (target == GL_VERTEX_PROGRAM_ARB)
2576bf215546Sopenharmony_ci      ? STATE_VERTEX_PROGRAM_ENV : STATE_FRAGMENT_PROGRAM_ENV;
2577bf215546Sopenharmony_ci   state->state_param_enum_local = (target == GL_VERTEX_PROGRAM_ARB)
2578bf215546Sopenharmony_ci      ? STATE_VERTEX_PROGRAM_LOCAL : STATE_FRAGMENT_PROGRAM_LOCAL;
2579bf215546Sopenharmony_ci
2580bf215546Sopenharmony_ci   _mesa_set_program_error(ctx, -1, NULL);
2581bf215546Sopenharmony_ci
2582bf215546Sopenharmony_ci   _mesa_program_lexer_ctor(& state->scanner, state, (const char *) strz, len + 1);
2583bf215546Sopenharmony_ci   yyparse(state);
2584bf215546Sopenharmony_ci   _mesa_program_lexer_dtor(state->scanner);
2585bf215546Sopenharmony_ci
2586bf215546Sopenharmony_ci   /* Remove the newline we added so reflection returns the original string */
2587bf215546Sopenharmony_ci   strz[len] = '\0';
2588bf215546Sopenharmony_ci
2589bf215546Sopenharmony_ci   if (ctx->Program.ErrorPos != -1) {
2590bf215546Sopenharmony_ci      goto error;
2591bf215546Sopenharmony_ci   }
2592bf215546Sopenharmony_ci
2593bf215546Sopenharmony_ci   if (! _mesa_layout_parameters(state)) {
2594bf215546Sopenharmony_ci      struct YYLTYPE loc;
2595bf215546Sopenharmony_ci
2596bf215546Sopenharmony_ci      loc.first_line = 0;
2597bf215546Sopenharmony_ci      loc.first_column = 0;
2598bf215546Sopenharmony_ci      loc.position = len;
2599bf215546Sopenharmony_ci
2600bf215546Sopenharmony_ci      yyerror(& loc, state, "invalid PARAM usage");
2601bf215546Sopenharmony_ci      goto error;
2602bf215546Sopenharmony_ci   }
2603bf215546Sopenharmony_ci
2604bf215546Sopenharmony_ci
2605bf215546Sopenharmony_ci
2606bf215546Sopenharmony_ci   /* Add one instruction to store the "END" instruction.
2607bf215546Sopenharmony_ci    */
2608bf215546Sopenharmony_ci   state->prog->arb.Instructions =
2609bf215546Sopenharmony_ci      rzalloc_array(state->mem_ctx, struct prog_instruction,
2610bf215546Sopenharmony_ci                    state->prog->arb.NumInstructions + 1);
2611bf215546Sopenharmony_ci
2612bf215546Sopenharmony_ci   if (state->prog->arb.Instructions == NULL) {
2613bf215546Sopenharmony_ci      goto error;
2614bf215546Sopenharmony_ci   }
2615bf215546Sopenharmony_ci
2616bf215546Sopenharmony_ci   inst = state->inst_head;
2617bf215546Sopenharmony_ci   for (i = 0; i < state->prog->arb.NumInstructions; i++) {
2618bf215546Sopenharmony_ci      struct asm_instruction *const temp = inst->next;
2619bf215546Sopenharmony_ci
2620bf215546Sopenharmony_ci      state->prog->arb.Instructions[i] = inst->Base;
2621bf215546Sopenharmony_ci      inst = temp;
2622bf215546Sopenharmony_ci   }
2623bf215546Sopenharmony_ci
2624bf215546Sopenharmony_ci   /* Finally, tag on an OPCODE_END instruction */
2625bf215546Sopenharmony_ci   {
2626bf215546Sopenharmony_ci      const GLuint numInst = state->prog->arb.NumInstructions;
2627bf215546Sopenharmony_ci      _mesa_init_instructions(state->prog->arb.Instructions + numInst, 1);
2628bf215546Sopenharmony_ci      state->prog->arb.Instructions[numInst].Opcode = OPCODE_END;
2629bf215546Sopenharmony_ci   }
2630bf215546Sopenharmony_ci   state->prog->arb.NumInstructions++;
2631bf215546Sopenharmony_ci
2632bf215546Sopenharmony_ci   state->prog->arb.NumParameters = state->prog->Parameters->NumParameters;
2633bf215546Sopenharmony_ci   state->prog->arb.NumAttributes =
2634bf215546Sopenharmony_ci      util_bitcount64(state->prog->info.inputs_read);
2635bf215546Sopenharmony_ci
2636bf215546Sopenharmony_ci   /*
2637bf215546Sopenharmony_ci    * Initialize native counts to logical counts.  The device driver may
2638bf215546Sopenharmony_ci    * change them if program is translated into a hardware program.
2639bf215546Sopenharmony_ci    */
2640bf215546Sopenharmony_ci   state->prog->arb.NumNativeInstructions = state->prog->arb.NumInstructions;
2641bf215546Sopenharmony_ci   state->prog->arb.NumNativeTemporaries = state->prog->arb.NumTemporaries;
2642bf215546Sopenharmony_ci   state->prog->arb.NumNativeParameters = state->prog->arb.NumParameters;
2643bf215546Sopenharmony_ci   state->prog->arb.NumNativeAttributes = state->prog->arb.NumAttributes;
2644bf215546Sopenharmony_ci   state->prog->arb.NumNativeAddressRegs = state->prog->arb.NumAddressRegs;
2645bf215546Sopenharmony_ci
2646bf215546Sopenharmony_ci   result = GL_TRUE;
2647bf215546Sopenharmony_ci
2648bf215546Sopenharmony_cierror:
2649bf215546Sopenharmony_ci   for (inst = state->inst_head; inst != NULL; inst = temp) {
2650bf215546Sopenharmony_ci      temp = inst->next;
2651bf215546Sopenharmony_ci      free(inst);
2652bf215546Sopenharmony_ci   }
2653bf215546Sopenharmony_ci
2654bf215546Sopenharmony_ci   state->inst_head = NULL;
2655bf215546Sopenharmony_ci   state->inst_tail = NULL;
2656bf215546Sopenharmony_ci
2657bf215546Sopenharmony_ci   for (sym = state->sym; sym != NULL; sym = temp) {
2658bf215546Sopenharmony_ci      temp = sym->next;
2659bf215546Sopenharmony_ci
2660bf215546Sopenharmony_ci      free((void *) sym->name);
2661bf215546Sopenharmony_ci      free(sym);
2662bf215546Sopenharmony_ci   }
2663bf215546Sopenharmony_ci   state->sym = NULL;
2664bf215546Sopenharmony_ci
2665bf215546Sopenharmony_ci   _mesa_symbol_table_dtor(state->st);
2666bf215546Sopenharmony_ci   state->st = NULL;
2667bf215546Sopenharmony_ci
2668bf215546Sopenharmony_ci   if (result != GL_TRUE) {
2669bf215546Sopenharmony_ci      if (state->prog->Parameters) {
2670bf215546Sopenharmony_ci         _mesa_free_parameter_list(state->prog->Parameters);
2671bf215546Sopenharmony_ci         state->prog->Parameters = NULL;
2672bf215546Sopenharmony_ci      }
2673bf215546Sopenharmony_ci      ralloc_free(state->prog->String);
2674bf215546Sopenharmony_ci      state->prog->String = NULL;
2675bf215546Sopenharmony_ci   }
2676bf215546Sopenharmony_ci
2677bf215546Sopenharmony_ci   return result;
2678bf215546Sopenharmony_ci}
2679