4 * Copyright 2008 Stefan Dösinger
5 * Copyright 2012 Matteo Bruni for CodeWeavers
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.
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.
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
23 #include "wine/debug.h"
25 #define YY_NO_UNISTD_H
26 #include "d3dcompiler_private.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(hlsl_parser);
31 #define YY_USER_ACTION \
33 hlsl_lloc.first_column = hlsl_ctx.column; \
34 hlsl_lloc.first_line = hlsl_ctx.line_no; \
35 hlsl_ctx.column += yyleng; \
40 %option noyywrap nounput noinput never-interactive
41 %option prefix="hlsl_"
43 %x pp pp_line pp_pragma pp_ignore
45 RESERVED1 auto|case|catch|char|class|const_cast|default|delete|dynamic_cast|enum
46 RESERVED2 explicit|friend|goto|long|mutable|new|operator|private|protected|public
47 RESERVED3 reinterpret_cast|short|signed|sizeof|static_cast|template|this|throw|try
48 RESERVED4 typename|union|unsigned|using|virtual
52 DOUBLESLASHCOMMENT "//"[^\n]*
54 IDENTIFIER [A-Za-z_][A-Za-z0-9_]*
60 hlsl_message("Line %u: Reserved keyword \"%s\" used.\n", hlsl_ctx.line_no, yytext);
61 set_parse_status(&hlsl_ctx.status, PARSE_ERR);
64 hlsl_message("Line %u: Reserved keyword \"%s\" used.\n", hlsl_ctx.line_no, yytext);
65 set_parse_status(&hlsl_ctx.status, PARSE_ERR);
68 hlsl_message("Line %u: Reserved keyword \"%s\" used.\n", hlsl_ctx.line_no, yytext);
69 set_parse_status(&hlsl_ctx.status, PARSE_ERR);
72 hlsl_message("Line %u: Reserved keyword \"%s\" used.\n", hlsl_ctx.line_no, yytext);
73 set_parse_status(&hlsl_ctx.status, PARSE_ERR);
76 BlendState {return KW_BLENDSTATE; }
77 break {return KW_BREAK; }
78 Buffer {return KW_BUFFER; }
79 cbuffer {return KW_CBUFFER; }
80 compile {return KW_COMPILE; }
81 const {return KW_CONST; }
82 continue {return KW_CONTINUE; }
83 DepthStencilState {return KW_DEPTHSTENCILSTATE; }
84 DepthStencilView {return KW_DEPTHSTENCILVIEW; }
85 discard {return KW_DISCARD; }
87 double {return KW_DOUBLE; }
88 else {return KW_ELSE; }
89 extern {return KW_EXTERN; }
90 false {return KW_FALSE; }
92 GeometryShader {return KW_GEOMETRYSHADER; }
93 groupshared {return KW_GROUPSHARED; }
96 inline {return KW_INLINE; }
97 inout {return KW_INOUT; }
98 matrix {return KW_MATRIX; }
99 namespace {return KW_NAMESPACE; }
100 nointerpolation {return KW_NOINTERPOLATION; }
101 out {return KW_OUT; }
102 pass {return KW_PASS; }
103 PixelShader {return KW_PIXELSHADER; }
104 precise {return KW_PRECISE; }
105 RasterizerState {return KW_RASTERIZERSTATE; }
106 RenderTargetView {return KW_RENDERTARGETVIEW; }
107 return {return KW_RETURN; }
108 register {return KW_REGISTER; }
109 sampler {return KW_SAMPLER; }
110 sampler1D {return KW_SAMPLER1D; }
111 sampler2D {return KW_SAMPLER2D; }
112 sampler3D {return KW_SAMPLER3D; }
113 samplerCUBE {return KW_SAMPLERCUBE; }
114 sampler_state {return KW_SAMPLER_STATE; }
115 SamplerComparisonState {return KW_SAMPLERCOMPARISONSTATE;}
116 shared {return KW_SHARED; }
117 stateblock {return KW_STATEBLOCK; }
118 stateblock_state {return KW_STATEBLOCK_STATE; }
119 static {return KW_STATIC; }
120 string {return KW_STRING; }
121 struct {return KW_STRUCT; }
122 switch {return KW_SWITCH; }
123 tbuffer {return KW_TBUFFER; }
124 technique {return KW_TECHNIQUE; }
125 technique10 {return KW_TECHNIQUE10; }
126 texture {return KW_TEXTURE; }
127 texture1D {return KW_TEXTURE1D; }
128 Texture1DArray {return KW_TEXTURE1DARRAY; }
129 texture2D {return KW_TEXTURE2D; }
130 Texture2DArray {return KW_TEXTURE2DARRAY; }
131 Texture2DMS {return KW_TEXTURE2DMS; }
132 Texture2DMSArray {return KW_TEXTURE2DMSARRAY; }
133 texture3D {return KW_TEXTURE3D; }
134 Texture3DArray {return KW_TEXTURE3DARRAY; }
135 textureCUBE {return KW_TEXTURECUBE; }
136 true {return KW_TRUE; }
137 typedef {return KW_TYPEDEF; }
138 uniform {return KW_UNIFORM; }
139 vector {return KW_VECTOR; }
140 VertexShader {return KW_VERTEXSHADER; }
141 void {return KW_VOID; }
142 volatile {return KW_VOLATILE; }
143 while {return KW_WHILE; }
145 \+\+ {return OP_INC; }
146 \-\- {return OP_DEC; }
148 \|\| {return OP_OR; }
150 \<\< {return OP_LEFTSHIFT; }
151 \<\<= {return OP_LEFTSHIFTASSIGN; }
152 \>\> {return OP_RIGHTSHIFT; }
153 \>\>= {return OP_RIGHTSHIFTASSIGN; }
154 \.\.\. {return OP_ELLIPSIS; }
158 \+= {return OP_ADDASSIGN; }
159 \-= {return OP_SUBASSIGN; }
160 \*= {return OP_MULASSIGN; }
161 \/= {return OP_DIVASSIGN; }
162 %= {return OP_MODASSIGN; }
163 &= {return OP_ANDASSIGN; }
164 \|= {return OP_ORASSIGN; }
165 ^= {return OP_XORASSIGN; }
166 ## {return OP_UNKNOWN1; }
167 #@ {return OP_UNKNOWN2; }
168 :: {return OP_UNKNOWN3; }
169 \-\> {return OP_UNKNOWN4; }
171 column_major {return KW_COLUMN_MAJOR; }
172 row_major {return KW_ROW_MAJOR; }
175 hlsl_lval.name = d3dcompiler_strdup(yytext);
176 if (get_variable(hlsl_ctx.cur_scope, yytext)
177 || find_function(yytext))
178 return VAR_IDENTIFIER;
179 else if (get_type(hlsl_ctx.cur_scope, yytext, TRUE))
180 return TYPE_IDENTIFIER;
182 return NEW_IDENTIFIER;
185 [0-9]*\.[0-9]+([eE][+-]?[0-9]+)?[h|H|f|F]? {
186 hlsl_lval.floatval = atof(yytext);
189 [0-9]+\.([eE][+-]?[0-9]+)?[h|H|f|F]? {
190 hlsl_lval.floatval = atof(yytext);
193 [0-9]+([eE][+-]?[0-9]+)?[h|H|f|F] {
194 hlsl_lval.floatval = atof(yytext);
198 sscanf(yytext, "0x%x", &hlsl_lval.intval);
202 sscanf(yytext, "0%o", &hlsl_lval.intval);
206 hlsl_lval.intval = (atoi(yytext));
210 {DOUBLESLASHCOMMENT} {}
223 TRACE("Got a #pragma.\n");
226 <pp_pragma>pack_matrix{WS}*\({WS}*row_major{WS}*\) {
227 TRACE("#pragma setting row_major mode.\n");
228 hlsl_ctx.matrix_majority = HLSL_ROW_MAJOR;
231 <pp_pragma>pack_matrix{WS}*\({WS}*column_major{WS}*\) {
232 TRACE("#pragma setting column_major mode.\n");
233 hlsl_ctx.matrix_majority = HLSL_COLUMN_MAJOR;
236 <pp_pragma>{NEWLINE} {
237 FIXME("Unsupported preprocessor #pragma directive at line %u.\n", hlsl_ctx.line_no);
242 TRACE("Preprocessor line info.\n");
244 hlsl_lval.intval = (atoi(yytext));
248 char *string = d3dcompiler_strdup(yytext + 1);
251 string[strlen(string) - 1] = 0;
252 hlsl_lval.name = string;
257 FIXME("Malformed preprocessor line directive?\n");
260 <pp_ignore>{NEWLINE} {
265 FIXME("Unexpected preprocessor directive.\n");
276 HRESULT parse_hlsl(enum shader_type type, DWORD major, DWORD minor,
277 const char *entrypoint, ID3D10Blob **shader, char **messages);
279 HRESULT parse_hlsl_shader(const char *text, enum shader_type type, DWORD major, DWORD minor,
280 const char *entrypoint, ID3D10Blob **shader, char **messages)
282 YY_BUFFER_STATE buffer;
285 buffer = hlsl__scan_string(text);
286 hlsl__switch_to_buffer(buffer);
288 hr = parse_hlsl(type, major, minor, entrypoint, shader, messages);
290 hlsl__delete_buffer(buffer);