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
24 #include "wine/port.h"
25 #include "wine/debug.h"
27 #define YY_NO_UNISTD_H
28 #include "d3dcompiler_private.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
52 hlsl_message("Line %u: Reserved keyword \"%s\" used.\n", hlsl_ctx.line_no, yytext);
53 set_parse_status(&hlsl_ctx.status, PARSE_ERR);
56 hlsl_message("Line %u: Reserved keyword \"%s\" used.\n", hlsl_ctx.line_no, yytext);
57 set_parse_status(&hlsl_ctx.status, PARSE_ERR);
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);
78 TRACE("Got a #pragma.\n");
81 <pp_pragma>pack_matrix{WS}*\({WS}*row_major{WS}*\) {
82 TRACE("#pragma setting row_major mode.\n");
83 hlsl_ctx.matrix_majority = HLSL_ROW_MAJOR;
86 <pp_pragma>pack_matrix{WS}*\({WS}*column_major{WS}*\) {
87 TRACE("#pragma setting column_major mode.\n");
88 hlsl_ctx.matrix_majority = HLSL_COLUMN_MAJOR;
91 <pp_pragma>{NEWLINE} {
92 FIXME("Unsupported preprocessor #pragma directive at line %u.\n", hlsl_ctx.line_no);
97 TRACE("Preprocessor line info.\n");
99 hlsl_lval.intval = (atoi(yytext));
103 char *string = d3dcompiler_strdup(yytext + 1);
106 string[strlen(string) - 1] = 0;
107 hlsl_lval.name = string;
112 FIXME("Malformed preprocessor line directive?\n");
115 <pp_ignore>{NEWLINE} {
120 FIXME("Unexpected preprocessor directive.\n");
131 struct bwriter_shader *parse_hlsl(enum shader_type type, DWORD version, const char *entrypoint, char **messages);
133 struct bwriter_shader *parse_hlsl_shader(const char *text, enum shader_type type, DWORD version,
134 const char *entrypoint, char **messages)
136 struct bwriter_shader *ret = NULL;
137 YY_BUFFER_STATE buffer;
139 buffer = hlsl__scan_string(text);
140 hlsl__switch_to_buffer(buffer);
142 ret = parse_hlsl(type, version, entrypoint, messages);
144 hlsl__delete_buffer(buffer);