Matteo Bruni : d3dcompiler: Add a stub lexer.
Alexandre Julliard
julliard at winehq.org
Wed May 16 14:22:38 CDT 2012
Module: wine
Branch: master
Commit: d2ddd20054fed95439770121fc872fd80e61da42
URL: http://source.winehq.org/git/wine.git/?a=commit;h=d2ddd20054fed95439770121fc872fd80e61da42
Author: Matteo Bruni <mbruni at codeweavers.com>
Date: Tue May 15 16:12:57 2012 +0200
d3dcompiler: Add a stub lexer.
---
.gitignore | 1 +
dlls/d3dcompiler_43/Makefile.in | 5 +-
dlls/d3dcompiler_43/d3dcompiler_private.h | 15 +++
dlls/d3dcompiler_43/hlsl.l | 146 +++++++++++++++++++++++++++++
dlls/d3dcompiler_43/hlsl.y | 11 +-
5 files changed, 171 insertions(+), 7 deletions(-)
diff --git a/.gitignore b/.gitignore
index 7f4bb73..defdcdf 100644
--- a/.gitignore
+++ b/.gitignore
@@ -54,6 +54,7 @@ dlls/d3dcompiler_43/asmshader.tab.h
dlls/d3dcompiler_43/asmshader.yy.c
dlls/d3dcompiler_43/hlsl.tab.c
dlls/d3dcompiler_43/hlsl.tab.h
+dlls/d3dcompiler_43/hlsl.yy.c
dlls/dispex/disp_ex.h
dlls/dispex/disp_ex_p.c
dlls/dxdiagn/fil_data.h
diff --git a/dlls/d3dcompiler_43/Makefile.in b/dlls/d3dcompiler_43/Makefile.in
index 15a9dc4..a13fb74 100644
--- a/dlls/d3dcompiler_43/Makefile.in
+++ b/dlls/d3dcompiler_43/Makefile.in
@@ -12,7 +12,10 @@ C_SRCS = \
reflection.c \
utils.c
-LEX_SRCS = asmshader.l
+LEX_SRCS = \
+ asmshader.l \
+ hlsl.l
+
BISON_SRCS = \
asmshader.y \
hlsl.y
diff --git a/dlls/d3dcompiler_43/d3dcompiler_private.h b/dlls/d3dcompiler_43/d3dcompiler_private.h
index 2936077..72c2511 100644
--- a/dlls/d3dcompiler_43/d3dcompiler_private.h
+++ b/dlls/d3dcompiler_43/d3dcompiler_private.h
@@ -154,6 +154,21 @@ static inline BOOL d3dcompiler_free(void *ptr)
return HeapFree(GetProcessHeap(), 0, ptr);
}
+static inline char *d3dcompiler_strdup(const char *string)
+{
+ char *copy;
+ SIZE_T len;
+
+ if (!string)
+ return NULL;
+
+ len = strlen(string);
+ copy = d3dcompiler_alloc(len + 1);
+ if (copy)
+ memcpy(copy, string, len + 1);
+ return copy;
+}
+
struct asm_parser;
/* This structure is only used in asmshader.y, but since the .l file accesses the semantic types
diff --git a/dlls/d3dcompiler_43/hlsl.l b/dlls/d3dcompiler_43/hlsl.l
new file mode 100644
index 0000000..439f384
--- /dev/null
+++ b/dlls/d3dcompiler_43/hlsl.l
@@ -0,0 +1,146 @@
+/*
+ * HLSL parser
+ *
+ * Copyright 2008 Stefan Dösinger
+ * Copyright 2012 Matteo Bruni for CodeWeavers
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+%{
+#include "config.h"
+#include "wine/port.h"
+#include "wine/debug.h"
+
+#define YY_NO_UNISTD_H
+#include "d3dcompiler_private.h"
+#include "hlsl.tab.h"
+
+WINE_DEFAULT_DEBUG_CHANNEL(hlsl_parser);
+%}
+
+%option noyywrap nounput noinput
+%option prefix="hlsl_"
+
+%x pp pp_line pp_pragma pp_ignore
+
+RESERVED1 auto|case|catch|char|class|const_cast|default|delete|dynamic_cast|enum
+RESERVED2 explicit|friend|goto|long|mutable|new|operator|private|protected|public
+RESERVED3 reinterpret_cast|short|signed|sizeof|static_cast|template|this|throw|try
+RESERVED4 typename|union|unsigned|using|virtual
+
+WS [ \t]
+NEWLINE (\n)|(\r\n)
+STRING \"[^\"]*\"
+
+ANY (.)
+
+%%
+{RESERVED1} {
+ hlsl_message("Line %u: Reserved keyword \"%s\" used.\n", hlsl_ctx.line_no, yytext);
+ set_parse_status(&hlsl_ctx.status, PARSE_ERR);
+ }
+{RESERVED2} {
+ hlsl_message("Line %u: Reserved keyword \"%s\" used.\n", hlsl_ctx.line_no, yytext);
+ set_parse_status(&hlsl_ctx.status, PARSE_ERR);
+ }
+{RESERVED3} {
+ hlsl_message("Line %u: Reserved keyword \"%s\" used.\n", hlsl_ctx.line_no, yytext);
+ set_parse_status(&hlsl_ctx.status, PARSE_ERR);
+ }
+{RESERVED4} {
+ hlsl_message("Line %u: Reserved keyword \"%s\" used.\n", hlsl_ctx.line_no, yytext);
+ set_parse_status(&hlsl_ctx.status, PARSE_ERR);
+ }
+
+{WS}+ {}
+{NEWLINE} {
+ hlsl_ctx.line_no++;
+ }
+
+^# {
+ BEGIN pp;
+ }
+
+<pp>pragma{WS}+ {
+ TRACE("Got a #pragma.\n");
+ BEGIN pp_pragma;
+ }
+<pp_pragma>pack_matrix{WS}*\({WS}*row_major{WS}*\) {
+ TRACE("#pragma setting row_major mode.\n");
+ hlsl_ctx.matrix_majority = HLSL_ROW_MAJOR;
+ BEGIN pp_ignore;
+ }
+<pp_pragma>pack_matrix{WS}*\({WS}*column_major{WS}*\) {
+ TRACE("#pragma setting column_major mode.\n");
+ hlsl_ctx.matrix_majority = HLSL_COLUMN_MAJOR;
+ BEGIN pp_ignore;
+ }
+<pp_pragma>{NEWLINE} {
+ FIXME("Unsupported preprocessor #pragma directive at line %u.\n", hlsl_ctx.line_no);
+ BEGIN INITIAL;
+ }
+<pp_pragma>{ANY} {}
+<pp>[0-9]+ {
+ TRACE("Preprocessor line info.\n");
+ BEGIN pp_line;
+ hlsl_lval.intval = (atoi(yytext));
+ return PRE_LINE;
+ }
+<pp_line>{STRING} {
+ char *string = d3dcompiler_strdup(yytext + 1);
+
+ BEGIN pp_ignore;
+ string[strlen(string) - 1] = 0;
+ hlsl_lval.name = string;
+ return STRING;
+ }
+<pp_line>{WS}+ {}
+<pp_line>{NEWLINE} {
+ FIXME("Malformed preprocessor line directive?\n");
+ BEGIN INITIAL;
+ }
+<pp_ignore>{NEWLINE} {
+ BEGIN INITIAL;
+ }
+<pp_ignore>{ANY} {}
+<pp>{NEWLINE} {
+ FIXME("Unexpected preprocessor directive.\n");
+ BEGIN INITIAL;
+ }
+<pp>{ANY} {}
+
+{ANY} {
+ return yytext[0];
+ }
+
+%%
+
+struct bwriter_shader *parse_hlsl(enum shader_type type, DWORD version, const char *entrypoint, char **messages);
+
+struct bwriter_shader *parse_hlsl_shader(const char *text, enum shader_type type, DWORD version,
+ const char *entrypoint, char **messages)
+{
+ struct bwriter_shader *ret = NULL;
+ YY_BUFFER_STATE buffer;
+
+ buffer = hlsl__scan_string(text);
+ hlsl__switch_to_buffer(buffer);
+
+ ret = parse_hlsl(type, version, entrypoint, messages);
+
+ hlsl__delete_buffer(buffer);
+ return ret;
+}
diff --git a/dlls/d3dcompiler_43/hlsl.y b/dlls/d3dcompiler_43/hlsl.y
index 2010f5f..5691848 100644
--- a/dlls/d3dcompiler_43/hlsl.y
+++ b/dlls/d3dcompiler_43/hlsl.y
@@ -28,11 +28,7 @@
WINE_DEFAULT_DEBUG_CHANNEL(hlsl_parser);
-int hlsl_lex(void)
-{
- FIXME("Lexer.\n");
- return 0;
-}
+int hlsl_lex(void);
struct hlsl_parse_ctx hlsl_ctx;
@@ -83,12 +79,15 @@ preproc_directive: PRE_LINE STRING
%%
-struct bwriter_shader *parse_hlsl_shader(const char *text, enum shader_type type, DWORD version, const char *entrypoint, char **messages)
+struct bwriter_shader *parse_hlsl(enum shader_type type, DWORD version, const char *entrypoint, char **messages)
{
hlsl_ctx.line_no = 1;
+ hlsl_ctx.source_file = d3dcompiler_strdup("");
hlsl_ctx.matrix_majority = HLSL_COLUMN_MAJOR;
hlsl_parse();
+ d3dcompiler_free(hlsl_ctx.source_file);
+
return NULL;
}
More information about the wine-cvs
mailing list