1*c2c66affSColin Finck /*
2*c2c66affSColin Finck  * Direct3D shader assembler
3*c2c66affSColin Finck  *
4*c2c66affSColin Finck  * Copyright 2008 Stefan Dösinger
5*c2c66affSColin Finck  * Copyright 2009 Matteo Bruni
6*c2c66affSColin Finck  *
7*c2c66affSColin Finck  * This library is free software; you can redistribute it and/or
8*c2c66affSColin Finck  * modify it under the terms of the GNU Lesser General Public
9*c2c66affSColin Finck  * License as published by the Free Software Foundation; either
10*c2c66affSColin Finck  * version 2.1 of the License, or (at your option) any later version.
11*c2c66affSColin Finck  *
12*c2c66affSColin Finck  * This library is distributed in the hope that it will be useful,
13*c2c66affSColin Finck  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14*c2c66affSColin Finck  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15*c2c66affSColin Finck  * Lesser General Public License for more details.
16*c2c66affSColin Finck  *
17*c2c66affSColin Finck  * You should have received a copy of the GNU Lesser General Public
18*c2c66affSColin Finck  * License along with this library; if not, write to the Free Software
19*c2c66affSColin Finck  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20*c2c66affSColin Finck  */
21*c2c66affSColin Finck 
22*c2c66affSColin Finck %{
23*c2c66affSColin Finck #include "wine/debug.h"
24*c2c66affSColin Finck 
25*c2c66affSColin Finck #include "d3dcompiler_private.h"
26*c2c66affSColin Finck #include "asmshader.tab.h"
27*c2c66affSColin Finck 
28*c2c66affSColin Finck WINE_DEFAULT_DEBUG_CHANNEL(asmshader);
29*c2c66affSColin Finck %}
30*c2c66affSColin Finck 
31*c2c66affSColin Finck %option noyywrap
32*c2c66affSColin Finck %option prefix="asmshader_"
33*c2c66affSColin Finck %option noinput nounput never-interactive
34*c2c66affSColin Finck 
35*c2c66affSColin Finck /* Swizzles and writemasks consist of a dot and up to 4 x, y, z or w characters,
36*c2c66affSColin Finck  * or up to 4 a, r, g, b characters. There are different rules for swizzles and
37*c2c66affSColin Finck  * writemasks wrt repetition, those are handled in the grammar.
38*c2c66affSColin Finck  */
39*c2c66affSColin Finck DOT                     \.
40*c2c66affSColin Finck COMPONENT               [xyzw]|[rgba]
41*c2c66affSColin Finck 
42*c2c66affSColin Finck /* Registers */
43*c2c66affSColin Finck REG_TEMP                r[0-9]+
44*c2c66affSColin Finck /* for relative addressing in the form o[x], v[x] and c[x] */
45*c2c66affSColin Finck REG_OUTPUT              o[0-9]*
46*c2c66affSColin Finck REG_INPUT               v[0-9]*
47*c2c66affSColin Finck REG_CONSTFLOAT          c[0-9]*
48*c2c66affSColin Finck REG_CONSTINT            i[0-9]+
49*c2c66affSColin Finck REG_CONSTBOOL           b[0-9]+
50*c2c66affSColin Finck REG_TEXTURE             t[0-9]+
51*c2c66affSColin Finck REG_TEXCRDOUT           oT[0-9]+
52*c2c66affSColin Finck REG_SAMPLER             s[0-9]+
53*c2c66affSColin Finck REG_OPOS                oPos
54*c2c66affSColin Finck REG_OFOG                oFog
55*c2c66affSColin Finck REG_OPTS                oPts
56*c2c66affSColin Finck REG_VERTEXCOLOR         oD[01]
57*c2c66affSColin Finck REG_FRAGCOLOR           oC[0-9]+
58*c2c66affSColin Finck REG_FRAGDEPTH           oDepth
59*c2c66affSColin Finck REG_VPOS                vPos
60*c2c66affSColin Finck REG_VFACE               vFace
61*c2c66affSColin Finck REG_ADDRESS             a0
62*c2c66affSColin Finck REG_LOOP                aL
63*c2c66affSColin Finck REG_PREDICATE           p0
64*c2c66affSColin Finck /* Not really a register, but it is considered as such */
65*c2c66affSColin Finck REG_LABEL               l[0-9]+
66*c2c66affSColin Finck 
67*c2c66affSColin Finck DCL_POSITION            _position[0-9]*
68*c2c66affSColin Finck DCL_BLENDWEIGHT         _blendweight[0-9]*
69*c2c66affSColin Finck DCL_BLENDINDICES        _blendindices[0-9]*
70*c2c66affSColin Finck DCL_NORMAL              _normal[0-9]*
71*c2c66affSColin Finck DCL_PSIZE               _psize[0-9]*
72*c2c66affSColin Finck DCL_TEXCOORD            _texcoord[0-9]*
73*c2c66affSColin Finck DCL_TANGENT             _tangent[0-9]*
74*c2c66affSColin Finck DCL_BINORMAL            _binormal[0-9]*
75*c2c66affSColin Finck DCL_TESSFACTOR          _tessfactor[0-9]*
76*c2c66affSColin Finck DCL_POSITIONT           _positiont[0-9]*
77*c2c66affSColin Finck DCL_COLOR               _color[0-9]*
78*c2c66affSColin Finck DCL_FOG                 _fog[0-9]*
79*c2c66affSColin Finck DCL_DEPTH               _depth[0-9]*
80*c2c66affSColin Finck DCL_SAMPLE              _sample[0-9]*
81*c2c66affSColin Finck 
82*c2c66affSColin Finck DCL_SAMPLER1D           _1d
83*c2c66affSColin Finck DCL_SAMPLER2D           _2d
84*c2c66affSColin Finck DCL_SAMPLERCUBE         _cube
85*c2c66affSColin Finck DCL_SAMPLERVOLUME       _volume
86*c2c66affSColin Finck 
87*c2c66affSColin Finck PREPROCESSORDIRECTIVE   #[^\n]*\n
88*c2c66affSColin Finck 
89*c2c66affSColin Finck /* Comments */
90*c2c66affSColin Finck DOUBLESLASHCOMMENT      "//"[^\n]*
91*c2c66affSColin Finck SEMICOLONCOMMENT        ";"[^\n]*
92*c2c66affSColin Finck 
93*c2c66affSColin Finck /* Whitespaces are spaces, tabs and newlines */
94*c2c66affSColin Finck WHITESPACE              [ \t]+
95*c2c66affSColin Finck NEWLINE                 (\n)|(\r\n)
96*c2c66affSColin Finck 
97*c2c66affSColin Finck COMMA                   ","
98*c2c66affSColin Finck 
99*c2c66affSColin Finck IMMVAL                  \-?(([0-9]+\.?)|([0-9]*\.[0-9]+))(f)?
100*c2c66affSColin Finck 
101*c2c66affSColin Finck ANY                     (.)
102*c2c66affSColin Finck 
103*c2c66affSColin Finck %%
104*c2c66affSColin Finck 
105*c2c66affSColin Finck     /* Common instructions(vertex and pixel shaders) */
106*c2c66affSColin Finck add                     {return INSTR_ADD;          }
107*c2c66affSColin Finck nop                     {return INSTR_NOP;          }
108*c2c66affSColin Finck mov                     {return INSTR_MOV;          }
109*c2c66affSColin Finck sub                     {return INSTR_SUB;          }
110*c2c66affSColin Finck mad                     {return INSTR_MAD;          }
111*c2c66affSColin Finck mul                     {return INSTR_MUL;          }
112*c2c66affSColin Finck rcp                     {return INSTR_RCP;          }
113*c2c66affSColin Finck rsq                     {return INSTR_RSQ;          }
114*c2c66affSColin Finck dp3                     {return INSTR_DP3;          }
115*c2c66affSColin Finck dp4                     {return INSTR_DP4;          }
116*c2c66affSColin Finck min                     {return INSTR_MIN;          }
117*c2c66affSColin Finck max                     {return INSTR_MAX;          }
118*c2c66affSColin Finck slt                     {return INSTR_SLT;          }
119*c2c66affSColin Finck sge                     {return INSTR_SGE;          }
120*c2c66affSColin Finck abs                     {return INSTR_ABS;          }
121*c2c66affSColin Finck exp                     {return INSTR_EXP;          }
122*c2c66affSColin Finck log                     {return INSTR_LOG;          }
123*c2c66affSColin Finck expp                    {return INSTR_EXPP;         }
124*c2c66affSColin Finck logp                    {return INSTR_LOGP;         }
125*c2c66affSColin Finck dst                     {return INSTR_DST;          }
126*c2c66affSColin Finck lrp                     {return INSTR_LRP;          }
127*c2c66affSColin Finck frc                     {return INSTR_FRC;          }
128*c2c66affSColin Finck pow                     {return INSTR_POW;          }
129*c2c66affSColin Finck crs                     {return INSTR_CRS;          }
130*c2c66affSColin Finck sgn                     {return INSTR_SGN;          }
131*c2c66affSColin Finck nrm                     {return INSTR_NRM;          }
132*c2c66affSColin Finck sincos                  {return INSTR_SINCOS;       }
133*c2c66affSColin Finck m4x4                    {return INSTR_M4x4;         }
134*c2c66affSColin Finck m4x3                    {return INSTR_M4x3;         }
135*c2c66affSColin Finck m3x4                    {return INSTR_M3x4;         }
136*c2c66affSColin Finck m3x3                    {return INSTR_M3x3;         }
137*c2c66affSColin Finck m3x2                    {return INSTR_M3x2;         }
138*c2c66affSColin Finck dcl                     {return INSTR_DCL;          }
139*c2c66affSColin Finck def                     {return INSTR_DEF;          }
140*c2c66affSColin Finck defb                    {return INSTR_DEFB;         }
141*c2c66affSColin Finck defi                    {return INSTR_DEFI;         }
142*c2c66affSColin Finck rep                     {return INSTR_REP;          }
143*c2c66affSColin Finck endrep                  {return INSTR_ENDREP;       }
144*c2c66affSColin Finck if                      {return INSTR_IF;           }
145*c2c66affSColin Finck else                    {return INSTR_ELSE;         }
146*c2c66affSColin Finck endif                   {return INSTR_ENDIF;        }
147*c2c66affSColin Finck break                   {return INSTR_BREAK;        }
148*c2c66affSColin Finck breakp                  {return INSTR_BREAKP;       }
149*c2c66affSColin Finck call                    {return INSTR_CALL;         }
150*c2c66affSColin Finck callnz                  {return INSTR_CALLNZ;       }
151*c2c66affSColin Finck loop                    {return INSTR_LOOP;         }
152*c2c66affSColin Finck ret                     {return INSTR_RET;          }
153*c2c66affSColin Finck endloop                 {return INSTR_ENDLOOP;      }
154*c2c66affSColin Finck label                   {return INSTR_LABEL;        }
155*c2c66affSColin Finck setp                    {return INSTR_SETP;         }
156*c2c66affSColin Finck texldl                  {return INSTR_TEXLDL;       }
157*c2c66affSColin Finck 
158*c2c66affSColin Finck     /* Vertex shader only instructions  */
159*c2c66affSColin Finck lit                     {return INSTR_LIT;          }
160*c2c66affSColin Finck mova                    {return INSTR_MOVA;         }
161*c2c66affSColin Finck 
162*c2c66affSColin Finck     /* Pixel shader only instructions   */
163*c2c66affSColin Finck cnd                     {return INSTR_CND;          }
164*c2c66affSColin Finck cmp                     {return INSTR_CMP;          }
165*c2c66affSColin Finck dp2add                  {return INSTR_DP2ADD;       }
166*c2c66affSColin Finck texcoord                {return INSTR_TEXCOORD;     }
167*c2c66affSColin Finck texcrd                  {return INSTR_TEXCRD;       }
168*c2c66affSColin Finck texkill                 {return INSTR_TEXKILL;      }
169*c2c66affSColin Finck tex                     {return INSTR_TEX;          }
170*c2c66affSColin Finck texld                   {return INSTR_TEXLD;        }
171*c2c66affSColin Finck texbem                  {return INSTR_TEXBEM;       }
172*c2c66affSColin Finck texbeml                 {return INSTR_TEXBEML;      }
173*c2c66affSColin Finck texreg2ar               {return INSTR_TEXREG2AR;    }
174*c2c66affSColin Finck texreg2gb               {return INSTR_TEXREG2GB;    }
175*c2c66affSColin Finck texreg2rgb              {return INSTR_TEXREG2RGB;   }
176*c2c66affSColin Finck texm3x2pad              {return INSTR_TEXM3x2PAD;   }
177*c2c66affSColin Finck texm3x2tex              {return INSTR_TEXM3x2TEX;   }
178*c2c66affSColin Finck texm3x3pad              {return INSTR_TEXM3x3PAD;   }
179*c2c66affSColin Finck texm3x3spec             {return INSTR_TEXM3x3SPEC;  }
180*c2c66affSColin Finck texm3x3vspec            {return INSTR_TEXM3x3VSPEC; }
181*c2c66affSColin Finck texm3x3tex              {return INSTR_TEXM3x3TEX;   }
182*c2c66affSColin Finck texdp3tex               {return INSTR_TEXDP3TEX;    }
183*c2c66affSColin Finck texm3x2depth            {return INSTR_TEXM3x2DEPTH; }
184*c2c66affSColin Finck texdp3                  {return INSTR_TEXDP3;       }
185*c2c66affSColin Finck texm3x3                 {return INSTR_TEXM3x3;      }
186*c2c66affSColin Finck texdepth                {return INSTR_TEXDEPTH;     }
187*c2c66affSColin Finck bem                     {return INSTR_BEM;          }
188*c2c66affSColin Finck dsx                     {return INSTR_DSX;          }
189*c2c66affSColin Finck dsy                     {return INSTR_DSY;          }
190*c2c66affSColin Finck texldp                  {return INSTR_TEXLDP;       }
191*c2c66affSColin Finck texldb                  {return INSTR_TEXLDB;       }
192*c2c66affSColin Finck texldd                  {return INSTR_TEXLDD;       }
193*c2c66affSColin Finck phase                   {return INSTR_PHASE;        }
194*c2c66affSColin Finck 
195*c2c66affSColin Finck {REG_TEMP}              {
196*c2c66affSColin Finck                             asmshader_lval.regnum = atoi(yytext + 1);
197*c2c66affSColin Finck                             return REG_TEMP;
198*c2c66affSColin Finck                         }
199*c2c66affSColin Finck {REG_OUTPUT}            {
200*c2c66affSColin Finck                             asmshader_lval.regnum = atoi(yytext + 1);
201*c2c66affSColin Finck                             return REG_OUTPUT;
202*c2c66affSColin Finck                         }
203*c2c66affSColin Finck {REG_INPUT}             {
204*c2c66affSColin Finck                             asmshader_lval.regnum = atoi(yytext + 1);
205*c2c66affSColin Finck                             return REG_INPUT;
206*c2c66affSColin Finck                         }
207*c2c66affSColin Finck {REG_CONSTFLOAT}        {
208*c2c66affSColin Finck                             asmshader_lval.regnum = atoi(yytext + 1);
209*c2c66affSColin Finck                             return REG_CONSTFLOAT;
210*c2c66affSColin Finck                         }
211*c2c66affSColin Finck {REG_CONSTINT}          {
212*c2c66affSColin Finck                             asmshader_lval.regnum = atoi(yytext + 1);
213*c2c66affSColin Finck                             return REG_CONSTINT;
214*c2c66affSColin Finck                         }
215*c2c66affSColin Finck {REG_CONSTBOOL}         {
216*c2c66affSColin Finck                             asmshader_lval.regnum = atoi(yytext + 1);
217*c2c66affSColin Finck                             return REG_CONSTBOOL;
218*c2c66affSColin Finck                         }
219*c2c66affSColin Finck {REG_TEXTURE}           {
220*c2c66affSColin Finck                             asmshader_lval.regnum = atoi(yytext + 1);
221*c2c66affSColin Finck                             return REG_TEXTURE;
222*c2c66affSColin Finck                         }
223*c2c66affSColin Finck {REG_TEXCRDOUT}         {
224*c2c66affSColin Finck                             asmshader_lval.regnum = atoi(yytext + 2);
225*c2c66affSColin Finck                             return REG_TEXCRDOUT;
226*c2c66affSColin Finck                         }
227*c2c66affSColin Finck {REG_SAMPLER}           {
228*c2c66affSColin Finck                             asmshader_lval.regnum = atoi(yytext + 1);
229*c2c66affSColin Finck                             return REG_SAMPLER;
230*c2c66affSColin Finck                         }
231*c2c66affSColin Finck {REG_OPOS}              {return REG_OPOS;           }
232*c2c66affSColin Finck {REG_OFOG}              {return REG_OFOG;           }
233*c2c66affSColin Finck {REG_OPTS}              {return REG_OPTS;           }
234*c2c66affSColin Finck {REG_VERTEXCOLOR}       {
235*c2c66affSColin Finck                             asmshader_lval.regnum = atoi(yytext + 2);
236*c2c66affSColin Finck                             return REG_VERTEXCOLOR;
237*c2c66affSColin Finck                         }
238*c2c66affSColin Finck {REG_FRAGCOLOR}         {
239*c2c66affSColin Finck                             asmshader_lval.regnum = atoi(yytext + 2);
240*c2c66affSColin Finck                             return REG_FRAGCOLOR;
241*c2c66affSColin Finck                         }
242*c2c66affSColin Finck {REG_FRAGDEPTH}         {return REG_FRAGDEPTH;      }
243*c2c66affSColin Finck {REG_VPOS}              {return REG_VPOS;           }
244*c2c66affSColin Finck {REG_VFACE}             {return REG_VFACE;          }
245*c2c66affSColin Finck {REG_ADDRESS}           {return REG_ADDRESS;        }
246*c2c66affSColin Finck {REG_LOOP}              {return REG_LOOP;           }
247*c2c66affSColin Finck {REG_PREDICATE}         {return REG_PREDICATE;      }
248*c2c66affSColin Finck 
249*c2c66affSColin Finck {REG_LABEL}             {
250*c2c66affSColin Finck                             asmshader_lval.regnum = atoi(yytext + 1);
251*c2c66affSColin Finck                             return REG_LABEL;
252*c2c66affSColin Finck                         }
253*c2c66affSColin Finck 
254*c2c66affSColin Finck     /* Shader versions. These are important to select the correct
255*c2c66affSColin Finck      * parser profile.
256*c2c66affSColin Finck      */
257*c2c66affSColin Finck vs\.1\.0|vs_1_0         {return VER_VS10;       }
258*c2c66affSColin Finck vs\.1\.1|vs_1_1         {return VER_VS11;       }
259*c2c66affSColin Finck 
260*c2c66affSColin Finck vs\.2\.0|vs_2_0         {return VER_VS20;       }
261*c2c66affSColin Finck vs\.2\.x|vs_2_x         {return VER_VS2X;       }
262*c2c66affSColin Finck vs\.3\.0|vs_3_0         {return VER_VS30;       }
263*c2c66affSColin Finck 
264*c2c66affSColin Finck ps\.1\.0|ps_1_0         {return VER_PS10;       }
265*c2c66affSColin Finck ps\.1\.1|ps_1_1         {return VER_PS11;       }
266*c2c66affSColin Finck ps\.1\.2|ps_1_2         {return VER_PS12;       }
267*c2c66affSColin Finck ps\.1\.3|ps_1_3         {return VER_PS13;       }
268*c2c66affSColin Finck ps\.1\.4|ps_1_4         {return VER_PS14;       }
269*c2c66affSColin Finck 
270*c2c66affSColin Finck ps\.2\.0|ps_2_0         {return VER_PS20;       }
271*c2c66affSColin Finck ps\.2\.x|ps_2_x         {return VER_PS2X;       }
272*c2c66affSColin Finck ps\.3\.0|ps_3_0         {return VER_PS30;       }
273*c2c66affSColin Finck 
274*c2c66affSColin Finck {DOT}                   {return yytext[0];      }
275*c2c66affSColin Finck {COMPONENT}             {
276*c2c66affSColin Finck                             switch(yytext[0]) {
277*c2c66affSColin Finck                                 case 'x':
278*c2c66affSColin Finck                                 case 'r':
279*c2c66affSColin Finck                                     asmshader_lval.component = 0;
280*c2c66affSColin Finck                                     break;
281*c2c66affSColin Finck                                 case 'y':
282*c2c66affSColin Finck                                 case 'g':
283*c2c66affSColin Finck                                     asmshader_lval.component = 1;
284*c2c66affSColin Finck                                     break;
285*c2c66affSColin Finck                                 case 'z':
286*c2c66affSColin Finck                                 case 'b':
287*c2c66affSColin Finck                                     asmshader_lval.component = 2;
288*c2c66affSColin Finck                                     break;
289*c2c66affSColin Finck                                 case 'w':
290*c2c66affSColin Finck                                 case 'a':
291*c2c66affSColin Finck                                     asmshader_lval.component = 3;
292*c2c66affSColin Finck                                     break;
293*c2c66affSColin Finck                             }
294*c2c66affSColin Finck                             return COMPONENT;
295*c2c66affSColin Finck                         }
296*c2c66affSColin Finck 
297*c2c66affSColin Finck     /* Output modifiers */
298*c2c66affSColin Finck \_x2                    {return SHIFT_X2;           }
299*c2c66affSColin Finck \_x4                    {return SHIFT_X4;           }
300*c2c66affSColin Finck \_x8                    {return SHIFT_X8;           }
301*c2c66affSColin Finck \_d2                    {return SHIFT_D2;           }
302*c2c66affSColin Finck \_d4                    {return SHIFT_D4;           }
303*c2c66affSColin Finck \_d8                    {return SHIFT_D8;           }
304*c2c66affSColin Finck \_sat                   {return MOD_SAT;            }
305*c2c66affSColin Finck \_pp                    {return MOD_PP;             }
306*c2c66affSColin Finck \_centroid              {return MOD_CENTROID;       }
307*c2c66affSColin Finck 
308*c2c66affSColin Finck     /* compare params */
309*c2c66affSColin Finck \_gt                    {return COMP_GT;            }
310*c2c66affSColin Finck \_lt                    {return COMP_LT;            }
311*c2c66affSColin Finck \_ge                    {return COMP_GE;            }
312*c2c66affSColin Finck \_le                    {return COMP_LE;            }
313*c2c66affSColin Finck \_eq                    {return COMP_EQ;            }
314*c2c66affSColin Finck \_ne                    {return COMP_NE;            }
315*c2c66affSColin Finck 
316*c2c66affSColin Finck {IMMVAL}                {
317*c2c66affSColin Finck                             asmshader_lval.immval.val = atof(yytext);
318*c2c66affSColin Finck                             asmshader_lval.immval.integer = ((strstr(yytext, ".") == NULL) && (strstr(yytext, "f") == NULL));
319*c2c66affSColin Finck                             return IMMVAL;
320*c2c66affSColin Finck                         }
321*c2c66affSColin Finck true                    {
322*c2c66affSColin Finck                             asmshader_lval.immbool = TRUE;
323*c2c66affSColin Finck                             return IMMBOOL;
324*c2c66affSColin Finck                         }
325*c2c66affSColin Finck false                   {
326*c2c66affSColin Finck                             asmshader_lval.immbool = FALSE;
327*c2c66affSColin Finck                             return IMMBOOL;
328*c2c66affSColin Finck                         }
329*c2c66affSColin Finck 
330*c2c66affSColin Finck {COMMA}                 {return yytext[0];          }
331*c2c66affSColin Finck -                       {return yytext[0];          }
332*c2c66affSColin Finck \(                      {return yytext[0];          }
333*c2c66affSColin Finck \)                      {return yytext[0];          }
334*c2c66affSColin Finck 
335*c2c66affSColin Finck     /* for relative addressing */
336*c2c66affSColin Finck \[|\]|\+                {return yytext[0];          }
337*c2c66affSColin Finck 
338*c2c66affSColin Finck \_bias                  {return SMOD_BIAS;          }
339*c2c66affSColin Finck     /* No _x2 here; it is identical to MOD_X2 */
340*c2c66affSColin Finck \_bx2                   {return SMOD_SCALEBIAS;     }
341*c2c66affSColin Finck \_dz                    {return SMOD_DZ;            }
342*c2c66affSColin Finck \_dw                    {return SMOD_DW;            }
343*c2c66affSColin Finck \_abs                   {return SMOD_ABS;           }
344*c2c66affSColin Finck 
345*c2c66affSColin Finck !                       {return SMOD_NOT;           }
346*c2c66affSColin Finck 
347*c2c66affSColin Finck {DCL_POSITION}          {
348*c2c66affSColin Finck                             if(yytext[strlen("_position")] == '\0') {
349*c2c66affSColin Finck                                 asmshader_lval.regnum = 0;
350*c2c66affSColin Finck                             } else {
351*c2c66affSColin Finck                                 asmshader_lval.regnum = atoi(yytext + strlen("_position"));
352*c2c66affSColin Finck                             }
353*c2c66affSColin Finck                             return USAGE_POSITION;
354*c2c66affSColin Finck                         }
355*c2c66affSColin Finck {DCL_BLENDWEIGHT}       {
356*c2c66affSColin Finck                             if(yytext[strlen("_blendweight")] == '\0') {
357*c2c66affSColin Finck                                 asmshader_lval.regnum = 0;
358*c2c66affSColin Finck                             } else {
359*c2c66affSColin Finck                                 asmshader_lval.regnum = atoi(yytext + strlen("_blendweight"));
360*c2c66affSColin Finck                             }
361*c2c66affSColin Finck                             return USAGE_BLENDWEIGHT;
362*c2c66affSColin Finck                         }
363*c2c66affSColin Finck {DCL_BLENDINDICES}      {
364*c2c66affSColin Finck                             if(yytext[strlen("_blendindices")] == '\0') {
365*c2c66affSColin Finck                                 asmshader_lval.regnum = 0;
366*c2c66affSColin Finck                             } else {
367*c2c66affSColin Finck                                 asmshader_lval.regnum = atoi(yytext + strlen("_blendindices"));
368*c2c66affSColin Finck                             }
369*c2c66affSColin Finck                             return USAGE_BLENDINDICES;
370*c2c66affSColin Finck                         }
371*c2c66affSColin Finck {DCL_NORMAL}            {
372*c2c66affSColin Finck                             if(yytext[strlen("_normal")] == '\0') {
373*c2c66affSColin Finck                                 asmshader_lval.regnum = 0;
374*c2c66affSColin Finck                             } else {
375*c2c66affSColin Finck                                 asmshader_lval.regnum = atoi(yytext + strlen("_normal"));
376*c2c66affSColin Finck                             }
377*c2c66affSColin Finck                             return USAGE_NORMAL;
378*c2c66affSColin Finck                         }
379*c2c66affSColin Finck {DCL_PSIZE}             {
380*c2c66affSColin Finck                             if(yytext[strlen("_psize")] == '\0') {
381*c2c66affSColin Finck                                 asmshader_lval.regnum = 0;
382*c2c66affSColin Finck                             } else {
383*c2c66affSColin Finck                                 asmshader_lval.regnum = atoi(yytext + strlen("_psize"));
384*c2c66affSColin Finck                             }
385*c2c66affSColin Finck                             return USAGE_PSIZE;
386*c2c66affSColin Finck                         }
387*c2c66affSColin Finck {DCL_TEXCOORD}          {
388*c2c66affSColin Finck                             if(yytext[strlen("_texcoord")] == '\0') {
389*c2c66affSColin Finck                                 asmshader_lval.regnum = 0;
390*c2c66affSColin Finck                             } else {
391*c2c66affSColin Finck                                 asmshader_lval.regnum = atoi(yytext + strlen("_texcoord"));
392*c2c66affSColin Finck                             }
393*c2c66affSColin Finck                             return USAGE_TEXCOORD;
394*c2c66affSColin Finck                         }
395*c2c66affSColin Finck {DCL_TANGENT}           {
396*c2c66affSColin Finck                             if(yytext[strlen("_tangent")] == '\0') {
397*c2c66affSColin Finck                                 asmshader_lval.regnum = 0;
398*c2c66affSColin Finck                             } else {
399*c2c66affSColin Finck                                 asmshader_lval.regnum = atoi(yytext + strlen("_tangent"));
400*c2c66affSColin Finck                             }
401*c2c66affSColin Finck                             return USAGE_TANGENT;
402*c2c66affSColin Finck                         }
403*c2c66affSColin Finck {DCL_BINORMAL}          {
404*c2c66affSColin Finck                             if(yytext[strlen("_binormal")] == '\0') {
405*c2c66affSColin Finck                                 asmshader_lval.regnum = 0;
406*c2c66affSColin Finck                             } else {
407*c2c66affSColin Finck                                 asmshader_lval.regnum = atoi(yytext + strlen("_binormal"));
408*c2c66affSColin Finck                             }
409*c2c66affSColin Finck                             return USAGE_BINORMAL;
410*c2c66affSColin Finck                         }
411*c2c66affSColin Finck {DCL_TESSFACTOR}        {
412*c2c66affSColin Finck                             if(yytext[strlen("_tessfactor")] == '\0') {
413*c2c66affSColin Finck                                 asmshader_lval.regnum = 0;
414*c2c66affSColin Finck                             } else {
415*c2c66affSColin Finck                                 asmshader_lval.regnum = atoi(yytext + strlen("_tessfactor"));
416*c2c66affSColin Finck                             }
417*c2c66affSColin Finck                             return USAGE_TESSFACTOR;
418*c2c66affSColin Finck                         }
419*c2c66affSColin Finck {DCL_POSITIONT}         {
420*c2c66affSColin Finck                             if(yytext[strlen("_positiont")] == '\0') {
421*c2c66affSColin Finck                                 asmshader_lval.regnum = 0;
422*c2c66affSColin Finck                             } else {
423*c2c66affSColin Finck                                 asmshader_lval.regnum = atoi(yytext + strlen("_positiont"));
424*c2c66affSColin Finck                             }
425*c2c66affSColin Finck                             return USAGE_POSITIONT;
426*c2c66affSColin Finck                         }
427*c2c66affSColin Finck {DCL_COLOR}             {
428*c2c66affSColin Finck                             if(yytext[strlen("_color")] == '\0') {
429*c2c66affSColin Finck                                 asmshader_lval.regnum = 0;
430*c2c66affSColin Finck                             } else {
431*c2c66affSColin Finck                                 asmshader_lval.regnum = atoi(yytext + strlen("_color"));
432*c2c66affSColin Finck                             }
433*c2c66affSColin Finck                             return USAGE_COLOR;
434*c2c66affSColin Finck                         }
435*c2c66affSColin Finck {DCL_FOG}               {
436*c2c66affSColin Finck                             if(yytext[strlen("_fog")] == '\0') {
437*c2c66affSColin Finck                                 asmshader_lval.regnum = 0;
438*c2c66affSColin Finck                             } else {
439*c2c66affSColin Finck                                 asmshader_lval.regnum = atoi(yytext + strlen("_fog"));
440*c2c66affSColin Finck                             }
441*c2c66affSColin Finck                             return USAGE_FOG;
442*c2c66affSColin Finck                         }
443*c2c66affSColin Finck {DCL_DEPTH}             {
444*c2c66affSColin Finck                             if(yytext[strlen("_depth")] == '\0') {
445*c2c66affSColin Finck                                 asmshader_lval.regnum = 0;
446*c2c66affSColin Finck                             } else {
447*c2c66affSColin Finck                                 asmshader_lval.regnum = atoi(yytext + strlen("_depth"));
448*c2c66affSColin Finck                             }
449*c2c66affSColin Finck                             return USAGE_DEPTH;
450*c2c66affSColin Finck                         }
451*c2c66affSColin Finck {DCL_SAMPLE}            {
452*c2c66affSColin Finck                             if(yytext[strlen("_sample")] == '\0') {
453*c2c66affSColin Finck                                 asmshader_lval.regnum = 0;
454*c2c66affSColin Finck                             } else {
455*c2c66affSColin Finck                                 asmshader_lval.regnum = atoi(yytext + strlen("_sample"));
456*c2c66affSColin Finck                             }
457*c2c66affSColin Finck                             return USAGE_SAMPLE;
458*c2c66affSColin Finck                         }
459*c2c66affSColin Finck 
460*c2c66affSColin Finck {DCL_SAMPLER1D}         { return SAMPTYPE_1D;       }
461*c2c66affSColin Finck {DCL_SAMPLER2D}         { return SAMPTYPE_2D;       }
462*c2c66affSColin Finck {DCL_SAMPLERCUBE}       { return SAMPTYPE_CUBE;     }
463*c2c66affSColin Finck {DCL_SAMPLERVOLUME}     { return SAMPTYPE_VOLUME;   }
464*c2c66affSColin Finck 
465*c2c66affSColin Finck {PREPROCESSORDIRECTIVE} {
466*c2c66affSColin Finck                             /* TODO: update current line information */
467*c2c66affSColin Finck                             TRACE("line info update: %s", yytext);
468*c2c66affSColin Finck                         }
469*c2c66affSColin Finck 
470*c2c66affSColin Finck     /* Skip comments */
471*c2c66affSColin Finck {DOUBLESLASHCOMMENT}    {                           }
472*c2c66affSColin Finck {SEMICOLONCOMMENT}      {                           }
473*c2c66affSColin Finck 
474*c2c66affSColin Finck {WHITESPACE}            { /* Do nothing */          }
475*c2c66affSColin Finck {NEWLINE}               {
476*c2c66affSColin Finck                             asm_ctx.line_no++;
477*c2c66affSColin Finck                         }
478*c2c66affSColin Finck 
479*c2c66affSColin Finck {ANY}                   {
480*c2c66affSColin Finck                             asmparser_message(&asm_ctx, "Line %u: Unexpected input %s\n", asm_ctx.line_no, yytext);
481*c2c66affSColin Finck                             set_parse_status(&asm_ctx.status, PARSE_ERR);
482*c2c66affSColin Finck                         }
483*c2c66affSColin Finck 
484*c2c66affSColin Finck %%
485*c2c66affSColin Finck 
486*c2c66affSColin Finck struct bwriter_shader *SlAssembleShader(const char *text, char **messages) {
487*c2c66affSColin Finck     struct bwriter_shader *ret = NULL;
488*c2c66affSColin Finck     YY_BUFFER_STATE buffer;
489*c2c66affSColin Finck     TRACE("%p, %p\n", text, messages);
490*c2c66affSColin Finck 
491*c2c66affSColin Finck     buffer = asmshader__scan_string(text);
492*c2c66affSColin Finck     asmshader__switch_to_buffer(buffer);
493*c2c66affSColin Finck 
494*c2c66affSColin Finck     ret = parse_asm_shader(messages);
495*c2c66affSColin Finck 
496*c2c66affSColin Finck     asmshader__delete_buffer(buffer);
497*c2c66affSColin Finck 
498*c2c66affSColin Finck     return ret;
499*c2c66affSColin Finck }
500