msvcrt: Added _sscanf_l implementation.
[wine] / dlls / d3dx9_36 / asmshader.l
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  */
21
22 %{
23 #include "config.h"
24 #include "wine/port.h"
25 #include "wine/debug.h"
26
27 #include "d3dx9_36_private.h"
28 #include "asmshader.tab.h"
29
30 WINE_DEFAULT_DEBUG_CHANNEL(asmshader);
31 %}
32
33 %option noyywrap
34 %option prefix="asmshader_"
35 %option noinput nounput
36
37 /* Registers */
38 REG_TEMP                r[0-9]+
39 /* for relative addressing in the form o[x], v[x] and c[x] */
40 REG_CONSTFLOAT          c[0-9]*
41
42 PREPROCESSORDIRECTIVE   #[^\n]*\n
43
44 /* Comments */
45 DOUBLESLASHCOMMENT      "//"[^\n]*
46 SEMICOLONCOMMENT        ";"[^\n]*
47
48 /* Whitespaces are spaces, tabs and newlines */
49 WHITESPACE              [ \t]+
50 NEWLINE                 (\n)|(\r\n)
51
52 COMMA                   ","
53
54 IMMVAL                  \-?(([0-9]+)|([0-9]*\.[0-9]+))(f)?
55
56 ANY                     (.)
57
58 %%
59
60     /* Common instructions(vertex and pixel shaders) */
61 mov                     {return INSTR_MOV;          }
62
63 {REG_TEMP}              {
64                             asmshader_lval.regnum = atoi(yytext + 1);
65                             return REG_TEMP;
66                         }
67 {REG_CONSTFLOAT}        {
68                             asmshader_lval.regnum = atoi(yytext + 1);
69                             return REG_CONSTFLOAT;
70                         }
71
72     /* Shader versions. These are important to select the correct
73      * parser profile.
74      */
75 vs\.1\.0|vs_1_0         {return VER_VS10;       }
76 vs\.1\.1|vs_1_1         {return VER_VS11;       }
77
78 vs_2_0                  {return VER_VS20;       }
79 vs_2_x                  {return VER_VS2X;       }
80 vs_3_0                  {return VER_VS30;       }
81
82 ps\.1\.0|ps_1_0         {return VER_PS10;       }
83 ps\.1\.1|ps_1_1         {return VER_PS11;       }
84 ps\.1\.2|ps_1_2         {return VER_PS12;       }
85 ps\.1\.3|ps_1_3         {return VER_PS13;       }
86 ps\.1\.4|ps_1_4         {return VER_PS14;       }
87
88 ps_2_0                  {return VER_PS20;       }
89 ps_2_x                  {return VER_PS2X;       }
90 ps_3_0                  {return VER_PS30;       }
91
92 {COMMA}                 {return yytext[0];          }
93 -                       {return yytext[0];          }
94 \(                      {return yytext[0];          }
95 \)                      {return yytext[0];          }
96
97 {PREPROCESSORDIRECTIVE} {
98                             /* TODO: update current line information */
99                             TRACE("line info update: %s", yytext);
100                         }
101
102     /* Skip comments */
103 {DOUBLESLASHCOMMENT}    {                           }
104 {SEMICOLONCOMMENT}      {                           }
105
106 {WHITESPACE}            { /* Do nothing */          }
107 {NEWLINE}               {
108                             asm_ctx.line_no++;
109                         }
110
111 {ANY}                   {
112                             asmparser_message(&asm_ctx, "Line %u: Unexpected input %s\n", asm_ctx.line_no, yytext);
113                             set_parse_status(&asm_ctx, PARSE_ERR);
114                         }
115
116 %%
117
118 struct bwriter_shader *SlAssembleShader(const char *text, char **messages) {
119     struct bwriter_shader *ret = NULL;
120     YY_BUFFER_STATE buffer;
121     TRACE("%p, %p\n", text, messages);
122
123     buffer = asmshader__scan_string(text);
124     asmshader__switch_to_buffer(buffer);
125
126     ret = parse_asm_shader(messages);
127
128     asmshader__delete_buffer(buffer);
129
130     return ret;
131 }