comctl32/tests: Remove variables cx and cy which are not really used from test_approx...
[wine.git] / dlls / d3dx9_36 / asmshader.l
blob65ecfa50afd04f2005a473274b1084fbb3c6a88e
1 /*
2  * Direct3D shader assembler
3  *
4  * Copyright 2008 Stefan Dösinger
5  * Copyright 2009 Matteo Bruni
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  */
23 #include "config.h"
24 #include "wine/port.h"
25 #include "wine/debug.h"
27 #include "d3dx9_36_private.h"
28 #include "asmshader.tab.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(asmshader);
33 %option noyywrap
34 %option prefix="asmshader_"
35 %option noinput nounput
37 /* Swizzles and writemasks consist of a dot and up to 4 x, y, z or w characters,
38  * or up to 4 a, r, g, b characters. There are different rules for swizzles and
39  * writemasks wrt repetition, those are handled in the grammar.
40  */
41 DOT                     \.
42 COMPONENT               [xyzw]|[rgba]
44 /* Registers */
45 REG_TEMP                r[0-9]+
46 /* for relative addressing in the form o[x], v[x] and c[x] */
47 REG_CONSTFLOAT          c[0-9]*
49 PREPROCESSORDIRECTIVE   #[^\n]*\n
51 /* Comments */
52 DOUBLESLASHCOMMENT      "//"[^\n]*
53 SEMICOLONCOMMENT        ";"[^\n]*
55 /* Whitespaces are spaces, tabs and newlines */
56 WHITESPACE              [ \t]+
57 NEWLINE                 (\n)|(\r\n)
59 COMMA                   ","
61 IMMVAL                  \-?(([0-9]+)|([0-9]*\.[0-9]+))(f)?
63 ANY                     (.)
67     /* Common instructions(vertex and pixel shaders) */
68 mov                     {return INSTR_MOV;          }
70 {REG_TEMP}              {
71                             asmshader_lval.regnum = atoi(yytext + 1);
72                             return REG_TEMP;
73                         }
74 {REG_CONSTFLOAT}        {
75                             asmshader_lval.regnum = atoi(yytext + 1);
76                             return REG_CONSTFLOAT;
77                         }
79     /* Shader versions. These are important to select the correct
80      * parser profile.
81      */
82 vs\.1\.0|vs_1_0         {return VER_VS10;       }
83 vs\.1\.1|vs_1_1         {return VER_VS11;       }
85 vs_2_0                  {return VER_VS20;       }
86 vs_2_x                  {return VER_VS2X;       }
87 vs_3_0                  {return VER_VS30;       }
89 ps\.1\.0|ps_1_0         {return VER_PS10;       }
90 ps\.1\.1|ps_1_1         {return VER_PS11;       }
91 ps\.1\.2|ps_1_2         {return VER_PS12;       }
92 ps\.1\.3|ps_1_3         {return VER_PS13;       }
93 ps\.1\.4|ps_1_4         {return VER_PS14;       }
95 ps_2_0                  {return VER_PS20;       }
96 ps_2_x                  {return VER_PS2X;       }
97 ps_3_0                  {return VER_PS30;       }
99 {DOT}                   {return yytext[0];      }
100 {COMPONENT}             {
101                             switch(yytext[0]) {
102                                 case 'x':
103                                 case 'r':
104                                     asmshader_lval.component = 0;
105                                     break;
106                                 case 'y':
107                                 case 'g':
108                                     asmshader_lval.component = 1;
109                                     break;
110                                 case 'z':
111                                 case 'b':
112                                     asmshader_lval.component = 2;
113                                     break;
114                                 case 'w':
115                                 case 'a':
116                                     asmshader_lval.component = 3;
117                                     break;
118                             }
119                             return COMPONENT;
120                         }
122     /* Output modifiers */
123 \_sat                   {return MOD_SAT;            }
124 \_pp                    {return MOD_PP;             }
125 \_centroid              {return MOD_CENTROID;       }
127 {COMMA}                 {return yytext[0];          }
128 -                       {return yytext[0];          }
129 \(                      {return yytext[0];          }
130 \)                      {return yytext[0];          }
132 \_abs                   {return SMOD_ABS;           }
134 {PREPROCESSORDIRECTIVE} {
135                             /* TODO: update current line information */
136                             TRACE("line info update: %s", yytext);
137                         }
139     /* Skip comments */
140 {DOUBLESLASHCOMMENT}    {                           }
141 {SEMICOLONCOMMENT}      {                           }
143 {WHITESPACE}            { /* Do nothing */          }
144 {NEWLINE}               {
145                             asm_ctx.line_no++;
146                         }
148 {ANY}                   {
149                             asmparser_message(&asm_ctx, "Line %u: Unexpected input %s\n", asm_ctx.line_no, yytext);
150                             set_parse_status(&asm_ctx, PARSE_ERR);
151                         }
155 struct bwriter_shader *SlAssembleShader(const char *text, char **messages) {
156     struct bwriter_shader *ret = NULL;
157     YY_BUFFER_STATE buffer;
158     TRACE("%p, %p\n", text, messages);
160     buffer = asmshader__scan_string(text);
161     asmshader__switch_to_buffer(buffer);
163     ret = parse_asm_shader(messages);
165     asmshader__delete_buffer(buffer);
167     return ret;