2 * Direct3D shader assembler
4 * Copyright 2008 Stefan Dösinger
5 * Copyright 2009 Matteo Bruni
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 #include "d3dx9_36_private.h"
28 #include "asmshader.tab.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(asmshader);
34 %option prefix="asmshader_"
35 %option noinput nounput
37 /* Swizzles and writemasks consist of a dot and up to 4 x, y, z or w characters,
38 * or up to 4 a, r, g, b characters. There are different rules for swizzles and
39 * writemasks wrt repetition, those are handled in the grammar.
42 COMPONENT [xyzw]|[rgba]
46 /* for relative addressing in the form o[x], v[x] and c[x] */
47 REG_CONSTFLOAT c[0-9]*
49 PREPROCESSORDIRECTIVE #[^\n]*\n
52 DOUBLESLASHCOMMENT "//"[^\n]*
53 SEMICOLONCOMMENT ";"[^\n]*
55 /* Whitespaces are spaces, tabs and newlines */
61 IMMVAL \-?(([0-9]+)|([0-9]*\.[0-9]+))(f)?
67 /* Common instructions(vertex and pixel shaders) */
68 mov {return INSTR_MOV; }
71 asmshader_lval.regnum = atoi(yytext + 1);
75 asmshader_lval.regnum = atoi(yytext + 1);
76 return REG_CONSTFLOAT;
79 /* Shader versions. These are important to select the correct
82 vs\.1\.0|vs_1_0 {return VER_VS10; }
83 vs\.1\.1|vs_1_1 {return VER_VS11; }
85 vs_2_0 {return VER_VS20; }
86 vs_2_x {return VER_VS2X; }
87 vs_3_0 {return VER_VS30; }
89 ps\.1\.0|ps_1_0 {return VER_PS10; }
90 ps\.1\.1|ps_1_1 {return VER_PS11; }
91 ps\.1\.2|ps_1_2 {return VER_PS12; }
92 ps\.1\.3|ps_1_3 {return VER_PS13; }
93 ps\.1\.4|ps_1_4 {return VER_PS14; }
95 ps_2_0 {return VER_PS20; }
96 ps_2_x {return VER_PS2X; }
97 ps_3_0 {return VER_PS30; }
99 {DOT} {return yytext[0]; }
104 asmshader_lval.component = 0;
108 asmshader_lval.component = 1;
112 asmshader_lval.component = 2;
116 asmshader_lval.component = 3;
122 /* Output modifiers */
123 \_sat {return MOD_SAT; }
124 \_pp {return MOD_PP; }
125 \_centroid {return MOD_CENTROID; }
127 {COMMA} {return yytext[0]; }
128 - {return yytext[0]; }
129 \( {return yytext[0]; }
130 \) {return yytext[0]; }
132 \_abs {return SMOD_ABS; }
134 {PREPROCESSORDIRECTIVE} {
135 /* TODO: update current line information */
136 TRACE("line info update: %s", yytext);
140 {DOUBLESLASHCOMMENT} { }
141 {SEMICOLONCOMMENT} { }
143 {WHITESPACE} { /* Do nothing */ }
149 asmparser_message(&asm_ctx, "Line %u: Unexpected input %s\n", asm_ctx.line_no, yytext);
150 set_parse_status(&asm_ctx, PARSE_ERR);
155 struct bwriter_shader *SlAssembleShader(const char *text, char **messages) {
156 struct bwriter_shader *ret = NULL;
157 YY_BUFFER_STATE buffer;
158 TRACE("%p, %p\n", text, messages);
160 buffer = asmshader__scan_string(text);
161 asmshader__switch_to_buffer(buffer);
163 ret = parse_asm_shader(messages);
165 asmshader__delete_buffer(buffer);