d3drm: Improve IDirect3DRMViewportX_Render stub.
[wine/multimedia.git] / dlls / d3dcompiler_43 / hlsl.l
blobef12ab967865732d057968ee3c8d6dfcb0a22f28
1 /*
2  * HLSL parser
3  *
4  * Copyright 2008 Stefan Dösinger
5  * Copyright 2012 Matteo Bruni for CodeWeavers
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 #define YY_NO_UNISTD_H
28 #include "d3dcompiler_private.h"
29 #include "hlsl.tab.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(hlsl_parser);
34 %option noyywrap nounput noinput
35 %option prefix="hlsl_"
37 %x pp pp_line pp_pragma pp_ignore
39 RESERVED1               auto|case|catch|char|class|const_cast|default|delete|dynamic_cast|enum
40 RESERVED2               explicit|friend|goto|long|mutable|new|operator|private|protected|public
41 RESERVED3               reinterpret_cast|short|signed|sizeof|static_cast|template|this|throw|try
42 RESERVED4               typename|union|unsigned|using|virtual
44 WS                      [ \t]
45 NEWLINE                 (\n)|(\r\n)
46 DOUBLESLASHCOMMENT      "//"[^\n]*
47 STRING                  \"[^\"]*\"
48 IDENTIFIER              [A-Za-z_][A-Za-z0-9_]*
50 ANY                     (.)
53 {RESERVED1}             {
54                             hlsl_message("Line %u: Reserved keyword \"%s\" used.\n", hlsl_ctx.line_no, yytext);
55                             set_parse_status(&hlsl_ctx.status, PARSE_ERR);
56                         }
57 {RESERVED2}             {
58                             hlsl_message("Line %u: Reserved keyword \"%s\" used.\n", hlsl_ctx.line_no, yytext);
59                             set_parse_status(&hlsl_ctx.status, PARSE_ERR);
60                         }
61 {RESERVED3}             {
62                             hlsl_message("Line %u: Reserved keyword \"%s\" used.\n", hlsl_ctx.line_no, yytext);
63                             set_parse_status(&hlsl_ctx.status, PARSE_ERR);
64                         }
65 {RESERVED4}             {
66                             hlsl_message("Line %u: Reserved keyword \"%s\" used.\n", hlsl_ctx.line_no, yytext);
67                             set_parse_status(&hlsl_ctx.status, PARSE_ERR);
68                         }
70 BlendState              {return KW_BLENDSTATE;          }
71 break                   {return KW_BREAK;               }
72 Buffer                  {return KW_BUFFER;              }
73 cbuffer                 {return KW_CBUFFER;             }
74 compile                 {return KW_COMPILE;             }
75 const                   {return KW_CONST;               }
76 continue                {return KW_CONTINUE;            }
77 DepthStencilState       {return KW_DEPTHSTENCILSTATE;   }
78 DepthStencilView        {return KW_DEPTHSTENCILVIEW;    }
79 discard                 {return KW_DISCARD;             }
80 do                      {return KW_DO;                  }
81 double                  {return KW_DOUBLE;              }
82 else                    {return KW_ELSE;                }
83 extern                  {return KW_EXTERN;              }
84 false                   {return KW_FALSE;               }
85 for                     {return KW_FOR;                 }
86 GeometryShader          {return KW_GEOMETRYSHADER;      }
87 groupshared             {return KW_GROUPSHARED;         }
88 if                      {return KW_IF;                  }
89 in                      {return KW_IN;                  }
90 inline                  {return KW_INLINE;              }
91 inout                   {return KW_INOUT;               }
92 matrix                  {return KW_MATRIX;              }
93 namespace               {return KW_NAMESPACE;           }
94 nointerpolation         {return KW_NOINTERPOLATION;     }
95 out                     {return KW_OUT;                 }
96 pass                    {return KW_PASS;                }
97 PixelShader             {return KW_PIXELSHADER;         }
98 precise                 {return KW_PRECISE;             }
99 RasterizerState         {return KW_RASTERIZERSTATE;     }
100 RenderTargetView        {return KW_RENDERTARGETVIEW;    }
101 return                  {return KW_RETURN;              }
102 register                {return KW_REGISTER;            }
103 sampler                 {return KW_SAMPLER;             }
104 sampler1D               {return KW_SAMPLER1D;           }
105 sampler2D               {return KW_SAMPLER2D;           }
106 sampler3D               {return KW_SAMPLER3D;           }
107 samplerCUBE             {return KW_SAMPLERCUBE;         }
108 sampler_state           {return KW_SAMPLER_STATE;       }
109 SamplerComparisonState  {return KW_SAMPLERCOMPARISONSTATE;}
110 shared                  {return KW_SHARED;              }
111 stateblock              {return KW_STATEBLOCK;          }
112 stateblock_state        {return KW_STATEBLOCK_STATE;    }
113 static                  {return KW_STATIC;              }
114 string                  {return KW_STRING;              }
115 struct                  {return KW_STRUCT;              }
116 switch                  {return KW_SWITCH;              }
117 tbuffer                 {return KW_TBUFFER;             }
118 technique               {return KW_TECHNIQUE;           }
119 technique10             {return KW_TECHNIQUE10;         }
120 texture                 {return KW_TEXTURE;             }
121 texture1D               {return KW_TEXTURE1D;           }
122 Texture1DArray          {return KW_TEXTURE1DARRAY;      }
123 texture2D               {return KW_TEXTURE2D;           }
124 Texture2DArray          {return KW_TEXTURE2DARRAY;      }
125 Texture2DMS             {return KW_TEXTURE2DMS;         }
126 Texture2DMSArray        {return KW_TEXTURE2DMSARRAY;    }
127 texture3D               {return KW_TEXTURE3D;           }
128 Texture3DArray          {return KW_TEXTURE3DARRAY;      }
129 textureCUBE             {return KW_TEXTURECUBE;         }
130 true                    {return KW_TRUE;                }
131 typedef                 {return KW_TYPEDEF;             }
132 uniform                 {return KW_UNIFORM;             }
133 vector                  {return KW_VECTOR;              }
134 VertexShader            {return KW_VERTEXSHADER;        }
135 void                    {return KW_VOID;                }
136 volatile                {return KW_VOLATILE;            }
137 while                   {return KW_WHILE;               }
139 \+\+                    {return OP_INC;                 }
140 \-\-                    {return OP_DEC;                 }
141 &&                      {return OP_AND;                 }
142 \|\|                    {return OP_OR;                  }
143 ==                      {return OP_EQ;                  }
144 \<\<                    {return OP_LEFTSHIFT;           }
145 \<\<=                   {return OP_LEFTSHIFTASSIGN;     }
146 \>\>                    {return OP_RIGHTSHIFT;          }
147 \>\>=                   {return OP_RIGHTSHIFTASSIGN;    }
148 \.\.\.                  {return OP_ELLIPSIS;            }
149 \<=                     {return OP_LE;                  }
150 \>=                     {return OP_GE;                  }
151 \<                      {return OP_LT;                  }
152 \>                      {return OP_GT;                  }
153 !=                      {return OP_NE;                  }
154 \+=                     {return OP_ADDASSIGN;           }
155 \-=                     {return OP_SUBASSIGN;           }
156 \*=                     {return OP_MULASSIGN;           }
157 \/=                     {return OP_DIVASSIGN;           }
158 %=                      {return OP_MODASSIGN;           }
159 &=                      {return OP_ANDASSIGN;           }
160 \|=                     {return OP_ORASSIGN;            }
161 ^=                      {return OP_XORASSIGN;           }
162 ##                      {return OP_UNKNOWN1;            }
163 #@                      {return OP_UNKNOWN2;            }
164 ::                      {return OP_UNKNOWN3;            }
165 \-\>                    {return OP_UNKNOWN4;            }
167 column_major            {return KW_COLUMN_MAJOR;        }
168 row_major               {return KW_ROW_MAJOR;           }
170 {IDENTIFIER}            {
171                             hlsl_lval.name = d3dcompiler_strdup(yytext);
172                             if (get_variable(hlsl_ctx.cur_scope, yytext)
173                                     || find_function(yytext))
174                                 return VAR_IDENTIFIER;
175                             else if (get_type(hlsl_ctx.cur_scope, yytext, TRUE))
176                                 return TYPE_IDENTIFIER;
177                             else
178                                 return NEW_IDENTIFIER;
179                         }
181 [+-]?[0-9]*\.[0-9]+([eE][+-]?[0-9]+)?[h|H|f|F]? {
182                             hlsl_lval.floatval = atof(yytext);
183                             return C_FLOAT;
184                         }
185 [+-]?[0-9]+\.([eE][+-]?[0-9]+)?[h|H|f|F]? {
186                             hlsl_lval.floatval = atof(yytext);
187                             return C_FLOAT;
188                         }
189 [+-]?[0-9]+([eE][+-]?[0-9]+)?[h|H|f|F] {
190                             hlsl_lval.floatval = atof(yytext);
191                             return C_FLOAT;
192                         }
193 0x[0-9a-fA-F]+          {
194                             sscanf(yytext, "0x%x", &hlsl_lval.intval);
195                             return C_INTEGER;
196                         }
197 0[0-7]+                 {
198                             sscanf(yytext, "0%o", &hlsl_lval.intval);
199                             return C_INTEGER;
200                         }
201 \-?[0-9]+               {
202                             hlsl_lval.intval = (atoi(yytext));
203                             return C_INTEGER;
204                         }
206 {DOUBLESLASHCOMMENT}    {}
208 {WS}+                   {}
209 {NEWLINE}               {
210                             hlsl_ctx.line_no++;
211                         }
213 ^#                      {
214                             BEGIN pp;
215                         }
217 <pp>pragma{WS}+         {
218                             TRACE("Got a #pragma.\n");
219                             BEGIN pp_pragma;
220                         }
221 <pp_pragma>pack_matrix{WS}*\({WS}*row_major{WS}*\) {
222                             TRACE("#pragma setting row_major mode.\n");
223                             hlsl_ctx.matrix_majority = HLSL_ROW_MAJOR;
224                             BEGIN pp_ignore;
225                         }
226 <pp_pragma>pack_matrix{WS}*\({WS}*column_major{WS}*\) {
227                             TRACE("#pragma setting column_major mode.\n");
228                             hlsl_ctx.matrix_majority = HLSL_COLUMN_MAJOR;
229                             BEGIN pp_ignore;
230                         }
231 <pp_pragma>{NEWLINE}    {
232                             FIXME("Unsupported preprocessor #pragma directive at line %u.\n", hlsl_ctx.line_no);
233                             BEGIN INITIAL;
234                         }
235 <pp_pragma>{ANY}        {}
236 <pp>[0-9]+              {
237                             TRACE("Preprocessor line info.\n");
238                             BEGIN pp_line;
239                             hlsl_lval.intval = (atoi(yytext));
240                             return PRE_LINE;
241                         }
242 <pp_line>{STRING}       {
243                             char *string = d3dcompiler_strdup(yytext + 1);
245                             BEGIN pp_ignore;
246                             string[strlen(string) - 1] = 0;
247                             hlsl_lval.name = string;
248                             return STRING;
249                         }
250 <pp_line>{WS}+          {}
251 <pp_line>{NEWLINE}      {
252                             FIXME("Malformed preprocessor line directive?\n");
253                             BEGIN INITIAL;
254                         }
255 <pp_ignore>{NEWLINE}    {
256                             BEGIN INITIAL;
257                         }
258 <pp_ignore>{ANY}        {}
259 <pp>{NEWLINE}           {
260                             FIXME("Unexpected preprocessor directive.\n");
261                             BEGIN INITIAL;
262                         }
263 <pp>{ANY}               {}
265 {ANY}                   {
266                             return yytext[0];
267                         }
271 struct bwriter_shader *parse_hlsl(enum shader_type type, DWORD version, const char *entrypoint, char **messages);
273 struct bwriter_shader *parse_hlsl_shader(const char *text, enum shader_type type, DWORD version,
274         const char *entrypoint, char **messages)
276     struct bwriter_shader *ret = NULL;
277     YY_BUFFER_STATE buffer;
279     buffer = hlsl__scan_string(text);
280     hlsl__switch_to_buffer(buffer);
282     ret = parse_hlsl(type, version, entrypoint, messages);
284     hlsl__delete_buffer(buffer);
285     return ret;