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#ifndef _MSC_VER
26bf215546Sopenharmony_ci#include <unistd.h>
27bf215546Sopenharmony_ci#endif
28bf215546Sopenharmony_ci
29bf215546Sopenharmony_ci#include "main/glheader.h"
30bf215546Sopenharmony_ci
31bf215546Sopenharmony_ci#include "program/prog_instruction.h"
32bf215546Sopenharmony_ci#include "program/prog_statevars.h"
33bf215546Sopenharmony_ci#include "program/symbol_table.h"
34bf215546Sopenharmony_ci#include "program/program_parser.h"
35bf215546Sopenharmony_ci#include "program/program_parse.tab.h"
36bf215546Sopenharmony_ci#include "util/strtod.h"
37bf215546Sopenharmony_ci
38bf215546Sopenharmony_ci#define require_ARB_vp (yyextra->mode == ARB_vertex)
39bf215546Sopenharmony_ci#define require_ARB_fp (yyextra->mode == ARB_fragment)
40bf215546Sopenharmony_ci#define require_shadow (yyextra->option.Shadow)
41bf215546Sopenharmony_ci#define require_rect   (yyextra->option.TexRect)
42bf215546Sopenharmony_ci#define require_texarray        (yyextra->option.TexArray)
43bf215546Sopenharmony_ci
44bf215546Sopenharmony_ci#ifndef HAVE_UNISTD_H
45bf215546Sopenharmony_ci#define YY_NO_UNISTD_H
46bf215546Sopenharmony_ci#endif
47bf215546Sopenharmony_ci
48bf215546Sopenharmony_ci#define return_token_or_IDENTIFIER(condition, token)	\
49bf215546Sopenharmony_ci   do {							\
50bf215546Sopenharmony_ci      if (condition) {					\
51bf215546Sopenharmony_ci	 return token;					\
52bf215546Sopenharmony_ci      } else {						\
53bf215546Sopenharmony_ci	 return handle_ident(yyextra, yytext, yylval);	\
54bf215546Sopenharmony_ci      }							\
55bf215546Sopenharmony_ci   } while (0)
56bf215546Sopenharmony_ci
57bf215546Sopenharmony_ci#define return_token_or_DOT(condition, token)		\
58bf215546Sopenharmony_ci   do {							\
59bf215546Sopenharmony_ci      if (condition) {					\
60bf215546Sopenharmony_ci	 return token;					\
61bf215546Sopenharmony_ci      } else {						\
62bf215546Sopenharmony_ci	 yyless(1);					\
63bf215546Sopenharmony_ci	 return DOT;					\
64bf215546Sopenharmony_ci      }							\
65bf215546Sopenharmony_ci   } while (0)
66bf215546Sopenharmony_ci
67bf215546Sopenharmony_ci
68bf215546Sopenharmony_ci#define return_opcode(condition, token, opcode, len)	\
69bf215546Sopenharmony_ci   do {							\
70bf215546Sopenharmony_ci      if (condition &&					\
71bf215546Sopenharmony_ci	  _mesa_parse_instruction_suffix(yyextra,	\
72bf215546Sopenharmony_ci					 yytext + len,	\
73bf215546Sopenharmony_ci					 & yylval->temp_inst)) {	\
74bf215546Sopenharmony_ci	 yylval->temp_inst.Opcode = OPCODE_ ## opcode;	\
75bf215546Sopenharmony_ci	 return token;					\
76bf215546Sopenharmony_ci      } else {						\
77bf215546Sopenharmony_ci	 return handle_ident(yyextra, yytext, yylval);	\
78bf215546Sopenharmony_ci      }							\
79bf215546Sopenharmony_ci   } while (0)
80bf215546Sopenharmony_ci
81bf215546Sopenharmony_ci#define SWIZZLE_INVAL  MAKE_SWIZZLE4(SWIZZLE_NIL, SWIZZLE_NIL, \
82bf215546Sopenharmony_ci				     SWIZZLE_NIL, SWIZZLE_NIL)
83bf215546Sopenharmony_ci
84bf215546Sopenharmony_cistatic unsigned
85bf215546Sopenharmony_cimask_from_char(char c)
86bf215546Sopenharmony_ci{
87bf215546Sopenharmony_ci   switch (c) {
88bf215546Sopenharmony_ci   case 'x':
89bf215546Sopenharmony_ci   case 'r':
90bf215546Sopenharmony_ci      return WRITEMASK_X;
91bf215546Sopenharmony_ci   case 'y':
92bf215546Sopenharmony_ci   case 'g':
93bf215546Sopenharmony_ci      return WRITEMASK_Y;
94bf215546Sopenharmony_ci   case 'z':
95bf215546Sopenharmony_ci   case 'b':
96bf215546Sopenharmony_ci      return WRITEMASK_Z;
97bf215546Sopenharmony_ci   case 'w':
98bf215546Sopenharmony_ci   case 'a':
99bf215546Sopenharmony_ci      return WRITEMASK_W;
100bf215546Sopenharmony_ci   }
101bf215546Sopenharmony_ci
102bf215546Sopenharmony_ci   return 0;
103bf215546Sopenharmony_ci}
104bf215546Sopenharmony_ci
105bf215546Sopenharmony_cistatic unsigned
106bf215546Sopenharmony_ciswiz_from_char(char c)
107bf215546Sopenharmony_ci{
108bf215546Sopenharmony_ci   switch (c) {
109bf215546Sopenharmony_ci   case 'x':
110bf215546Sopenharmony_ci   case 'r':
111bf215546Sopenharmony_ci      return SWIZZLE_X;
112bf215546Sopenharmony_ci   case 'y':
113bf215546Sopenharmony_ci   case 'g':
114bf215546Sopenharmony_ci      return SWIZZLE_Y;
115bf215546Sopenharmony_ci   case 'z':
116bf215546Sopenharmony_ci   case 'b':
117bf215546Sopenharmony_ci      return SWIZZLE_Z;
118bf215546Sopenharmony_ci   case 'w':
119bf215546Sopenharmony_ci   case 'a':
120bf215546Sopenharmony_ci      return SWIZZLE_W;
121bf215546Sopenharmony_ci   }
122bf215546Sopenharmony_ci
123bf215546Sopenharmony_ci   return 0;
124bf215546Sopenharmony_ci}
125bf215546Sopenharmony_ci
126bf215546Sopenharmony_cistatic int
127bf215546Sopenharmony_cihandle_ident(struct asm_parser_state *state, const char *text, YYSTYPE *lval)
128bf215546Sopenharmony_ci{
129bf215546Sopenharmony_ci   lval->string = strdup(text);
130bf215546Sopenharmony_ci
131bf215546Sopenharmony_ci   return (_mesa_symbol_table_find_symbol(state->st, text) == NULL)
132bf215546Sopenharmony_ci      ? IDENTIFIER : USED_IDENTIFIER;
133bf215546Sopenharmony_ci}
134bf215546Sopenharmony_ci
135bf215546Sopenharmony_ci#define YY_USER_ACTION							\
136bf215546Sopenharmony_ci   do {									\
137bf215546Sopenharmony_ci      yylloc->first_column = yylloc->last_column;			\
138bf215546Sopenharmony_ci      yylloc->last_column += yyleng;					\
139bf215546Sopenharmony_ci      if ((yylloc->first_line == 1)					\
140bf215546Sopenharmony_ci	  && (yylloc->first_column == 1)) {				\
141bf215546Sopenharmony_ci	 yylloc->position = 1;						\
142bf215546Sopenharmony_ci      } else {								\
143bf215546Sopenharmony_ci	 yylloc->position += yylloc->last_column - yylloc->first_column; \
144bf215546Sopenharmony_ci      }									\
145bf215546Sopenharmony_ci   } while(0);
146bf215546Sopenharmony_ci
147bf215546Sopenharmony_ci#define YY_NO_INPUT
148bf215546Sopenharmony_ci
149bf215546Sopenharmony_ci/* Yes, this is intentionally doing nothing. We have this line of code
150bf215546Sopenharmony_cihere only to avoid the compiler complaining about an unput function
151bf215546Sopenharmony_cithat is defined, but never called. */
152bf215546Sopenharmony_ci#define YY_USER_INIT while (0) { unput(0); }
153bf215546Sopenharmony_ci
154bf215546Sopenharmony_ci#define YY_EXTRA_TYPE struct asm_parser_state *
155bf215546Sopenharmony_ci
156bf215546Sopenharmony_ci/* Flex defines a couple of functions with no declarations nor the
157bf215546Sopenharmony_cistatic keyword. Declare them here to avoid a compiler warning. */
158bf215546Sopenharmony_ciint yyget_column  (yyscan_t yyscanner);
159bf215546Sopenharmony_civoid yyset_column (int  column_no , yyscan_t yyscanner);
160bf215546Sopenharmony_ci
161bf215546Sopenharmony_ci%}
162bf215546Sopenharmony_ci
163bf215546Sopenharmony_cinum    [0-9]+
164bf215546Sopenharmony_ciexp    [Ee][-+]?[0-9]+
165bf215546Sopenharmony_cifrac   "."[0-9]+
166bf215546Sopenharmony_cidot    "."[ \t]*
167bf215546Sopenharmony_ci
168bf215546Sopenharmony_cisat    (_SAT)?
169bf215546Sopenharmony_ci
170bf215546Sopenharmony_ci%option prefix="_mesa_program_lexer_"
171bf215546Sopenharmony_ci%option bison-bridge bison-locations reentrant noyywrap
172bf215546Sopenharmony_ci%%
173bf215546Sopenharmony_ci
174bf215546Sopenharmony_ci"!!ARBvp1.0"              { return ARBvp_10; }
175bf215546Sopenharmony_ci"!!ARBfp1.0"              { return ARBfp_10; }
176bf215546Sopenharmony_ciADDRESS                   {
177bf215546Sopenharmony_ci   yylval->integer = at_address;
178bf215546Sopenharmony_ci   return_token_or_IDENTIFIER(require_ARB_vp, ADDRESS);
179bf215546Sopenharmony_ci}
180bf215546Sopenharmony_ciALIAS                     { return ALIAS; }
181bf215546Sopenharmony_ciATTRIB                    { return ATTRIB; }
182bf215546Sopenharmony_ciEND                       { return END; }
183bf215546Sopenharmony_ciOPTION                    { return OPTION; }
184bf215546Sopenharmony_ciOUTPUT                    { return OUTPUT; }
185bf215546Sopenharmony_ciPARAM                     { return PARAM; }
186bf215546Sopenharmony_ciTEMP                      { yylval->integer = at_temp; return TEMP; }
187bf215546Sopenharmony_ci
188bf215546Sopenharmony_ciABS{sat}           { return_opcode(             1, VECTOR_OP, ABS, 3); }
189bf215546Sopenharmony_ciADD{sat}           { return_opcode(             1, BIN_OP, ADD, 3); }
190bf215546Sopenharmony_ciARL                { return_opcode(require_ARB_vp, ARL, ARL, 3); }
191bf215546Sopenharmony_ci
192bf215546Sopenharmony_ciCMP{sat}           { return_opcode(require_ARB_fp, TRI_OP, CMP, 3); }
193bf215546Sopenharmony_ciCOS{sat}           { return_opcode(require_ARB_fp, SCALAR_OP, COS, 3); }
194bf215546Sopenharmony_ci
195bf215546Sopenharmony_ciDP3{sat}           { return_opcode(             1, BIN_OP, DP3, 3); }
196bf215546Sopenharmony_ciDP4{sat}           { return_opcode(             1, BIN_OP, DP4, 3); }
197bf215546Sopenharmony_ciDPH{sat}           { return_opcode(             1, BIN_OP, DPH, 3); }
198bf215546Sopenharmony_ciDST{sat}           { return_opcode(             1, BIN_OP, DST, 3); }
199bf215546Sopenharmony_ci
200bf215546Sopenharmony_ciEX2{sat}           { return_opcode(             1, SCALAR_OP, EX2, 3); }
201bf215546Sopenharmony_ciEXP                { return_opcode(require_ARB_vp, SCALAR_OP, EXP, 3); }
202bf215546Sopenharmony_ci
203bf215546Sopenharmony_ciFLR{sat}           { return_opcode(             1, VECTOR_OP, FLR, 3); }
204bf215546Sopenharmony_ciFRC{sat}           { return_opcode(             1, VECTOR_OP, FRC, 3); }
205bf215546Sopenharmony_ci
206bf215546Sopenharmony_ciKIL                { return_opcode(require_ARB_fp, KIL, KIL, 3); }
207bf215546Sopenharmony_ci
208bf215546Sopenharmony_ciLIT{sat}           { return_opcode(             1, VECTOR_OP, LIT, 3); }
209bf215546Sopenharmony_ciLG2{sat}           { return_opcode(             1, SCALAR_OP, LG2, 3); }
210bf215546Sopenharmony_ciLOG                { return_opcode(require_ARB_vp, SCALAR_OP, LOG, 3); }
211bf215546Sopenharmony_ciLRP{sat}           { return_opcode(require_ARB_fp, TRI_OP, LRP, 3); }
212bf215546Sopenharmony_ci
213bf215546Sopenharmony_ciMAD{sat}           { return_opcode(             1, TRI_OP, MAD, 3); }
214bf215546Sopenharmony_ciMAX{sat}           { return_opcode(             1, BIN_OP, MAX, 3); }
215bf215546Sopenharmony_ciMIN{sat}           { return_opcode(             1, BIN_OP, MIN, 3); }
216bf215546Sopenharmony_ciMOV{sat}           { return_opcode(             1, VECTOR_OP, MOV, 3); }
217bf215546Sopenharmony_ciMUL{sat}           { return_opcode(             1, BIN_OP, MUL, 3); }
218bf215546Sopenharmony_ci
219bf215546Sopenharmony_ciPOW{sat}           { return_opcode(             1, BINSC_OP, POW, 3); }
220bf215546Sopenharmony_ci
221bf215546Sopenharmony_ciRCP{sat}           { return_opcode(             1, SCALAR_OP, RCP, 3); }
222bf215546Sopenharmony_ciRSQ{sat}           { return_opcode(             1, SCALAR_OP, RSQ, 3); }
223bf215546Sopenharmony_ci
224bf215546Sopenharmony_ciSCS{sat}           { return_opcode(require_ARB_fp, SCALAR_OP, SCS, 3); }
225bf215546Sopenharmony_ciSGE{sat}           { return_opcode(             1, BIN_OP, SGE, 3); }
226bf215546Sopenharmony_ciSIN{sat}           { return_opcode(require_ARB_fp, SCALAR_OP, SIN, 3); }
227bf215546Sopenharmony_ciSLT{sat}           { return_opcode(             1, BIN_OP, SLT, 3); }
228bf215546Sopenharmony_ciSUB{sat}           { return_opcode(             1, BIN_OP, SUB, 3); }
229bf215546Sopenharmony_ciSWZ{sat}           { return_opcode(             1, SWZ, SWZ, 3); }
230bf215546Sopenharmony_ci
231bf215546Sopenharmony_ciTEX{sat}           { return_opcode(require_ARB_fp, SAMPLE_OP, TEX, 3); }
232bf215546Sopenharmony_ciTXB{sat}           { return_opcode(require_ARB_fp, SAMPLE_OP, TXB, 3); }
233bf215546Sopenharmony_ciTXP{sat}           { return_opcode(require_ARB_fp, SAMPLE_OP, TXP, 3); }
234bf215546Sopenharmony_ci
235bf215546Sopenharmony_ciXPD{sat}           { return_opcode(             1, BIN_OP, XPD, 3); }
236bf215546Sopenharmony_ci
237bf215546Sopenharmony_civertex                    { return_token_or_IDENTIFIER(require_ARB_vp, VERTEX); }
238bf215546Sopenharmony_cifragment                  { return_token_or_IDENTIFIER(require_ARB_fp, FRAGMENT); }
239bf215546Sopenharmony_ciprogram                   { return PROGRAM; }
240bf215546Sopenharmony_cistate                     { return STATE; }
241bf215546Sopenharmony_ciresult                    { return RESULT; }
242bf215546Sopenharmony_ci
243bf215546Sopenharmony_ci{dot}ambient              { return AMBIENT; }
244bf215546Sopenharmony_ci{dot}attenuation          { return ATTENUATION; }
245bf215546Sopenharmony_ci{dot}back                 { return BACK; }
246bf215546Sopenharmony_ci{dot}clip                 { return_token_or_DOT(require_ARB_vp, CLIP); }
247bf215546Sopenharmony_ci{dot}color                { return COLOR; }
248bf215546Sopenharmony_ci{dot}depth                { return_token_or_DOT(require_ARB_fp, DEPTH); }
249bf215546Sopenharmony_ci{dot}diffuse              { return DIFFUSE; }
250bf215546Sopenharmony_ci{dot}direction            { return DIRECTION; }
251bf215546Sopenharmony_ci{dot}emission             { return EMISSION; }
252bf215546Sopenharmony_ci{dot}env                  { return ENV; }
253bf215546Sopenharmony_ci{dot}eye                  { return EYE; }
254bf215546Sopenharmony_ci{dot}fogcoord             { return FOGCOORD; }
255bf215546Sopenharmony_ci{dot}fog                  { return FOG; }
256bf215546Sopenharmony_ci{dot}front                { return FRONT; }
257bf215546Sopenharmony_ci{dot}half                 { return HALF; }
258bf215546Sopenharmony_ci{dot}inverse              { return INVERSE; }
259bf215546Sopenharmony_ci{dot}invtrans             { return INVTRANS; }
260bf215546Sopenharmony_ci{dot}light                { return LIGHT; }
261bf215546Sopenharmony_ci{dot}lightmodel           { return LIGHTMODEL; }
262bf215546Sopenharmony_ci{dot}lightprod            { return LIGHTPROD; }
263bf215546Sopenharmony_ci{dot}local                { return LOCAL; }
264bf215546Sopenharmony_ci{dot}material             { return MATERIAL; }
265bf215546Sopenharmony_ci{dot}program              { return MAT_PROGRAM; }
266bf215546Sopenharmony_ci{dot}matrix               { return MATRIX; }
267bf215546Sopenharmony_ci{dot}matrixindex          { return_token_or_DOT(require_ARB_vp, MATRIXINDEX); }
268bf215546Sopenharmony_ci{dot}modelview            { return MODELVIEW; }
269bf215546Sopenharmony_ci{dot}mvp                  { return MVP; }
270bf215546Sopenharmony_ci{dot}normal               { return_token_or_DOT(require_ARB_vp, NORMAL); }
271bf215546Sopenharmony_ci{dot}object               { return OBJECT; }
272bf215546Sopenharmony_ci{dot}palette              { return PALETTE; }
273bf215546Sopenharmony_ci{dot}params               { return PARAMS; }
274bf215546Sopenharmony_ci{dot}plane                { return PLANE; }
275bf215546Sopenharmony_ci{dot}point                { return_token_or_DOT(require_ARB_vp, POINT_TOK); }
276bf215546Sopenharmony_ci{dot}pointsize            { return_token_or_DOT(require_ARB_vp, POINTSIZE); }
277bf215546Sopenharmony_ci{dot}position             { return POSITION; }
278bf215546Sopenharmony_ci{dot}primary              { return PRIMARY; }
279bf215546Sopenharmony_ci{dot}projection           { return PROJECTION; }
280bf215546Sopenharmony_ci{dot}range                { return_token_or_DOT(require_ARB_fp, RANGE); }
281bf215546Sopenharmony_ci{dot}row                  { return ROW; }
282bf215546Sopenharmony_ci{dot}scenecolor           { return SCENECOLOR; }
283bf215546Sopenharmony_ci{dot}secondary            { return SECONDARY; }
284bf215546Sopenharmony_ci{dot}shininess            { return SHININESS; }
285bf215546Sopenharmony_ci{dot}size                 { return_token_or_DOT(require_ARB_vp, SIZE_TOK); }
286bf215546Sopenharmony_ci{dot}specular             { return SPECULAR; }
287bf215546Sopenharmony_ci{dot}spot                 { return SPOT; }
288bf215546Sopenharmony_ci{dot}texcoord             { return TEXCOORD; }
289bf215546Sopenharmony_ci{dot}texenv               { return_token_or_DOT(require_ARB_fp, TEXENV); }
290bf215546Sopenharmony_ci{dot}texgen               { return_token_or_DOT(require_ARB_vp, TEXGEN); }
291bf215546Sopenharmony_ci{dot}q                    { return_token_or_DOT(require_ARB_vp, TEXGEN_Q); }
292bf215546Sopenharmony_ci{dot}s                    { return_token_or_DOT(require_ARB_vp, TEXGEN_S); }
293bf215546Sopenharmony_ci{dot}t                    { return_token_or_DOT(require_ARB_vp, TEXGEN_T); }
294bf215546Sopenharmony_ci{dot}texture              { return TEXTURE; }
295bf215546Sopenharmony_ci{dot}transpose            { return TRANSPOSE; }
296bf215546Sopenharmony_ci{dot}attrib               { return_token_or_DOT(require_ARB_vp, VTXATTRIB); }
297bf215546Sopenharmony_ci
298bf215546Sopenharmony_citexture                   { return_token_or_IDENTIFIER(require_ARB_fp, TEXTURE_UNIT); }
299bf215546Sopenharmony_ci1D                        { return_token_or_IDENTIFIER(require_ARB_fp, TEX_1D); }
300bf215546Sopenharmony_ci2D                        { return_token_or_IDENTIFIER(require_ARB_fp, TEX_2D); }
301bf215546Sopenharmony_ci3D                        { return_token_or_IDENTIFIER(require_ARB_fp, TEX_3D); }
302bf215546Sopenharmony_ciCUBE                      { return_token_or_IDENTIFIER(require_ARB_fp, TEX_CUBE); }
303bf215546Sopenharmony_ciRECT                      { return_token_or_IDENTIFIER(require_ARB_fp && require_rect, TEX_RECT); }
304bf215546Sopenharmony_ciSHADOW1D                  { return_token_or_IDENTIFIER(require_ARB_fp && require_shadow, TEX_SHADOW1D); }
305bf215546Sopenharmony_ciSHADOW2D                  { return_token_or_IDENTIFIER(require_ARB_fp && require_shadow, TEX_SHADOW2D); }
306bf215546Sopenharmony_ciSHADOWRECT                { return_token_or_IDENTIFIER(require_ARB_fp && require_shadow && require_rect, TEX_SHADOWRECT); }
307bf215546Sopenharmony_ciARRAY1D                   { return_token_or_IDENTIFIER(require_ARB_fp && require_texarray, TEX_ARRAY1D); }
308bf215546Sopenharmony_ciARRAY2D                   { return_token_or_IDENTIFIER(require_ARB_fp && require_texarray, TEX_ARRAY2D); }
309bf215546Sopenharmony_ciARRAYSHADOW1D             { return_token_or_IDENTIFIER(require_ARB_fp && require_shadow && require_texarray, TEX_ARRAYSHADOW1D); }
310bf215546Sopenharmony_ciARRAYSHADOW2D             { return_token_or_IDENTIFIER(require_ARB_fp && require_shadow && require_texarray, TEX_ARRAYSHADOW2D); }
311bf215546Sopenharmony_ci
312bf215546Sopenharmony_ci[_a-zA-Z$][_a-zA-Z0-9$]*  { return handle_ident(yyextra, yytext, yylval); }
313bf215546Sopenharmony_ci
314bf215546Sopenharmony_ci".."                      { return DOT_DOT; }
315bf215546Sopenharmony_ci
316bf215546Sopenharmony_ci{num}                     {
317bf215546Sopenharmony_ci   yylval->integer = strtol(yytext, NULL, 10);
318bf215546Sopenharmony_ci   return INTEGER;
319bf215546Sopenharmony_ci}
320bf215546Sopenharmony_ci{num}?{frac}{exp}?        {
321bf215546Sopenharmony_ci   yylval->real = _mesa_strtof(yytext, NULL);
322bf215546Sopenharmony_ci   return REAL;
323bf215546Sopenharmony_ci}
324bf215546Sopenharmony_ci{num}"."/[^.]             {
325bf215546Sopenharmony_ci   yylval->real = _mesa_strtof(yytext, NULL);
326bf215546Sopenharmony_ci   return REAL;
327bf215546Sopenharmony_ci}
328bf215546Sopenharmony_ci{num}{exp}                {
329bf215546Sopenharmony_ci   yylval->real = _mesa_strtof(yytext, NULL);
330bf215546Sopenharmony_ci   return REAL;
331bf215546Sopenharmony_ci}
332bf215546Sopenharmony_ci{num}"."{exp}             {
333bf215546Sopenharmony_ci   yylval->real = _mesa_strtof(yytext, NULL);
334bf215546Sopenharmony_ci   return REAL;
335bf215546Sopenharmony_ci}
336bf215546Sopenharmony_ci
337bf215546Sopenharmony_ci".xyzw"                   {
338bf215546Sopenharmony_ci   yylval->swiz_mask.swizzle = SWIZZLE_NOOP;
339bf215546Sopenharmony_ci   yylval->swiz_mask.mask = WRITEMASK_XYZW;
340bf215546Sopenharmony_ci   return MASK4;
341bf215546Sopenharmony_ci}
342bf215546Sopenharmony_ci
343bf215546Sopenharmony_ci".xy"[zw]                 {
344bf215546Sopenharmony_ci   yylval->swiz_mask.swizzle = SWIZZLE_INVAL;
345bf215546Sopenharmony_ci   yylval->swiz_mask.mask = WRITEMASK_XY
346bf215546Sopenharmony_ci      | mask_from_char(yytext[3]);
347bf215546Sopenharmony_ci   return MASK3;
348bf215546Sopenharmony_ci}
349bf215546Sopenharmony_ci".xzw"                    {
350bf215546Sopenharmony_ci   yylval->swiz_mask.swizzle = SWIZZLE_INVAL;
351bf215546Sopenharmony_ci   yylval->swiz_mask.mask = WRITEMASK_XZW;
352bf215546Sopenharmony_ci   return MASK3;
353bf215546Sopenharmony_ci}
354bf215546Sopenharmony_ci".yzw"                    {
355bf215546Sopenharmony_ci   yylval->swiz_mask.swizzle = SWIZZLE_INVAL;
356bf215546Sopenharmony_ci   yylval->swiz_mask.mask = WRITEMASK_YZW;
357bf215546Sopenharmony_ci   return MASK3;
358bf215546Sopenharmony_ci}
359bf215546Sopenharmony_ci
360bf215546Sopenharmony_ci".x"[yzw]                 {
361bf215546Sopenharmony_ci   yylval->swiz_mask.swizzle = SWIZZLE_INVAL;
362bf215546Sopenharmony_ci   yylval->swiz_mask.mask = WRITEMASK_X
363bf215546Sopenharmony_ci      | mask_from_char(yytext[2]);
364bf215546Sopenharmony_ci   return MASK2;
365bf215546Sopenharmony_ci}
366bf215546Sopenharmony_ci".y"[zw]                  {
367bf215546Sopenharmony_ci   yylval->swiz_mask.swizzle = SWIZZLE_INVAL;
368bf215546Sopenharmony_ci   yylval->swiz_mask.mask = WRITEMASK_Y
369bf215546Sopenharmony_ci      | mask_from_char(yytext[2]);
370bf215546Sopenharmony_ci   return MASK2;
371bf215546Sopenharmony_ci}
372bf215546Sopenharmony_ci".zw"                     {
373bf215546Sopenharmony_ci   yylval->swiz_mask.swizzle = SWIZZLE_INVAL;
374bf215546Sopenharmony_ci   yylval->swiz_mask.mask = WRITEMASK_ZW;
375bf215546Sopenharmony_ci   return MASK2;
376bf215546Sopenharmony_ci}
377bf215546Sopenharmony_ci
378bf215546Sopenharmony_ci"."[xyzw]                 {
379bf215546Sopenharmony_ci   const unsigned s = swiz_from_char(yytext[1]);
380bf215546Sopenharmony_ci   yylval->swiz_mask.swizzle = MAKE_SWIZZLE4(s, s, s, s);
381bf215546Sopenharmony_ci   yylval->swiz_mask.mask = mask_from_char(yytext[1]);
382bf215546Sopenharmony_ci   return MASK1;
383bf215546Sopenharmony_ci}
384bf215546Sopenharmony_ci
385bf215546Sopenharmony_ci"."[xyzw]{4}              {
386bf215546Sopenharmony_ci   yylval->swiz_mask.swizzle = MAKE_SWIZZLE4(swiz_from_char(yytext[1]),
387bf215546Sopenharmony_ci					    swiz_from_char(yytext[2]),
388bf215546Sopenharmony_ci					    swiz_from_char(yytext[3]),
389bf215546Sopenharmony_ci					    swiz_from_char(yytext[4]));
390bf215546Sopenharmony_ci   yylval->swiz_mask.mask = 0;
391bf215546Sopenharmony_ci   return SWIZZLE;
392bf215546Sopenharmony_ci}
393bf215546Sopenharmony_ci
394bf215546Sopenharmony_ci".rgba"                   {
395bf215546Sopenharmony_ci   yylval->swiz_mask.swizzle = SWIZZLE_NOOP;
396bf215546Sopenharmony_ci   yylval->swiz_mask.mask = WRITEMASK_XYZW;
397bf215546Sopenharmony_ci   return_token_or_DOT(require_ARB_fp, MASK4);
398bf215546Sopenharmony_ci}
399bf215546Sopenharmony_ci
400bf215546Sopenharmony_ci".rg"[ba]                 {
401bf215546Sopenharmony_ci   yylval->swiz_mask.swizzle = SWIZZLE_INVAL;
402bf215546Sopenharmony_ci   yylval->swiz_mask.mask = WRITEMASK_XY
403bf215546Sopenharmony_ci      | mask_from_char(yytext[3]);
404bf215546Sopenharmony_ci   return_token_or_DOT(require_ARB_fp, MASK3);
405bf215546Sopenharmony_ci}
406bf215546Sopenharmony_ci".rba"                    {
407bf215546Sopenharmony_ci   yylval->swiz_mask.swizzle = SWIZZLE_INVAL;
408bf215546Sopenharmony_ci   yylval->swiz_mask.mask = WRITEMASK_XZW;
409bf215546Sopenharmony_ci   return_token_or_DOT(require_ARB_fp, MASK3);
410bf215546Sopenharmony_ci}
411bf215546Sopenharmony_ci".gba"                    {
412bf215546Sopenharmony_ci   yylval->swiz_mask.swizzle = SWIZZLE_INVAL;
413bf215546Sopenharmony_ci   yylval->swiz_mask.mask = WRITEMASK_YZW;
414bf215546Sopenharmony_ci   return_token_or_DOT(require_ARB_fp, MASK3);
415bf215546Sopenharmony_ci}
416bf215546Sopenharmony_ci
417bf215546Sopenharmony_ci".r"[gba]                 {
418bf215546Sopenharmony_ci   yylval->swiz_mask.swizzle = SWIZZLE_INVAL;
419bf215546Sopenharmony_ci   yylval->swiz_mask.mask = WRITEMASK_X
420bf215546Sopenharmony_ci      | mask_from_char(yytext[2]);
421bf215546Sopenharmony_ci   return_token_or_DOT(require_ARB_fp, MASK2);
422bf215546Sopenharmony_ci}
423bf215546Sopenharmony_ci".g"[ba]                  {
424bf215546Sopenharmony_ci   yylval->swiz_mask.swizzle = SWIZZLE_INVAL;
425bf215546Sopenharmony_ci   yylval->swiz_mask.mask = WRITEMASK_Y
426bf215546Sopenharmony_ci      | mask_from_char(yytext[2]);
427bf215546Sopenharmony_ci   return_token_or_DOT(require_ARB_fp, MASK2);
428bf215546Sopenharmony_ci}
429bf215546Sopenharmony_ci".ba"                     {
430bf215546Sopenharmony_ci   yylval->swiz_mask.swizzle = SWIZZLE_INVAL;
431bf215546Sopenharmony_ci   yylval->swiz_mask.mask = WRITEMASK_ZW;
432bf215546Sopenharmony_ci   return_token_or_DOT(require_ARB_fp, MASK2);
433bf215546Sopenharmony_ci}
434bf215546Sopenharmony_ci
435bf215546Sopenharmony_ci"."[gba]                  {
436bf215546Sopenharmony_ci   const unsigned s = swiz_from_char(yytext[1]);
437bf215546Sopenharmony_ci   yylval->swiz_mask.swizzle = MAKE_SWIZZLE4(s, s, s, s);
438bf215546Sopenharmony_ci   yylval->swiz_mask.mask = mask_from_char(yytext[1]);
439bf215546Sopenharmony_ci   return_token_or_DOT(require_ARB_fp, MASK1);
440bf215546Sopenharmony_ci}
441bf215546Sopenharmony_ci
442bf215546Sopenharmony_ci
443bf215546Sopenharmony_ci".r"                      {
444bf215546Sopenharmony_ci   if (require_ARB_vp) {
445bf215546Sopenharmony_ci      return TEXGEN_R;
446bf215546Sopenharmony_ci   } else {
447bf215546Sopenharmony_ci      yylval->swiz_mask.swizzle = MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_X,
448bf215546Sopenharmony_ci						SWIZZLE_X, SWIZZLE_X);
449bf215546Sopenharmony_ci      yylval->swiz_mask.mask = WRITEMASK_X;
450bf215546Sopenharmony_ci      return MASK1;
451bf215546Sopenharmony_ci   }
452bf215546Sopenharmony_ci}
453bf215546Sopenharmony_ci
454bf215546Sopenharmony_ci"."[rgba]{4}              {
455bf215546Sopenharmony_ci   yylval->swiz_mask.swizzle = MAKE_SWIZZLE4(swiz_from_char(yytext[1]),
456bf215546Sopenharmony_ci					    swiz_from_char(yytext[2]),
457bf215546Sopenharmony_ci					    swiz_from_char(yytext[3]),
458bf215546Sopenharmony_ci					    swiz_from_char(yytext[4]));
459bf215546Sopenharmony_ci   yylval->swiz_mask.mask = 0;
460bf215546Sopenharmony_ci   return_token_or_DOT(require_ARB_fp, SWIZZLE);
461bf215546Sopenharmony_ci}
462bf215546Sopenharmony_ci
463bf215546Sopenharmony_ci"."                       { return DOT; }
464bf215546Sopenharmony_ci
465bf215546Sopenharmony_ci\n                        {
466bf215546Sopenharmony_ci   yylloc->first_line++;
467bf215546Sopenharmony_ci   yylloc->first_column = 1;
468bf215546Sopenharmony_ci   yylloc->last_line++;
469bf215546Sopenharmony_ci   yylloc->last_column = 1;
470bf215546Sopenharmony_ci   yylloc->position++;
471bf215546Sopenharmony_ci}
472bf215546Sopenharmony_ci[ \t\r]+                  /* eat whitespace */ ;
473bf215546Sopenharmony_ci#.*$                      /* eat comments */ ;
474bf215546Sopenharmony_ci.                         { return yytext[0]; }
475bf215546Sopenharmony_ci%%
476bf215546Sopenharmony_ci
477bf215546Sopenharmony_civoid
478bf215546Sopenharmony_ci_mesa_program_lexer_ctor(void **scanner, struct asm_parser_state *state,
479bf215546Sopenharmony_ci			 const char *string, size_t len)
480bf215546Sopenharmony_ci{
481bf215546Sopenharmony_ci   yylex_init_extra(state, scanner);
482bf215546Sopenharmony_ci   yy_scan_bytes(string, len, *scanner);
483bf215546Sopenharmony_ci}
484bf215546Sopenharmony_ci
485bf215546Sopenharmony_civoid
486bf215546Sopenharmony_ci_mesa_program_lexer_dtor(void *scanner)
487bf215546Sopenharmony_ci{
488bf215546Sopenharmony_ci   yylex_destroy(scanner);
489bf215546Sopenharmony_ci}
490