diff --git a/reactos/CMakeLists.txt b/reactos/CMakeLists.txt index 861e5959b1c..df6bd7bed5d 100644 --- a/reactos/CMakeLists.txt +++ b/reactos/CMakeLists.txt @@ -233,6 +233,7 @@ else() add_subdirectory(modules) add_subdirectory(ntoskrnl) add_subdirectory(subsystems) + add_subdirectory(tools/wpp) add_subdirectory(win32ss) # Create {bootcd, livecd, bootcdregtest}.lst diff --git a/reactos/dll/directx/wine/CMakeLists.txt b/reactos/dll/directx/wine/CMakeLists.txt index 64a2befba77..2df9deb0bfa 100644 --- a/reactos/dll/directx/wine/CMakeLists.txt +++ b/reactos/dll/directx/wine/CMakeLists.txt @@ -1,6 +1,7 @@ add_subdirectory(d3d8) add_subdirectory(d3d9) +add_subdirectory(d3dcompiler_43) add_subdirectory(d3dx9_24) if(NOT MSVC) add_subdirectory(d3dx9_25) diff --git a/reactos/dll/directx/wine/d3dcompiler_43/CMakeLists.txt b/reactos/dll/directx/wine/d3dcompiler_43/CMakeLists.txt new file mode 100644 index 00000000000..e99f39621c5 --- /dev/null +++ b/reactos/dll/directx/wine/d3dcompiler_43/CMakeLists.txt @@ -0,0 +1,30 @@ + +add_definitions( + -D__WINESRC__ + -DDIRECT3D_VERSION=0x0900) + +include_directories(${REACTOS_SOURCE_DIR}/include/reactos/wine) + +spec2def(d3dcompiler_43.dll d3dcompiler_43.spec ADD_IMPORTLIB) + +list(APPEND SOURCE + asmparser.c + asmshader.tab.c + asmshader.yy.c + blob.c + bytecodewriter.c + compiler.c + d3dcompiler_43_main.c + hlsl.tab.c + hlsl.yy.c + reflection.c + utils.c + ${CMAKE_CURRENT_BINARY_DIR}/d3dcompiler_43_stubs.c + ${CMAKE_CURRENT_BINARY_DIR}/d3dcompiler_43.def) + +add_library(d3dcompiler_43 SHARED ${SOURCE} version.rc) +set_module_type(d3dcompiler_43 win32dll) +target_link_libraries(d3dcompiler_43 dx10guid uuid wine wpp) +add_importlibs(d3dcompiler_43 msvcrt kernel32 ntdll) +add_dependencies(d3dcompiler_43 d3d_idl_headers) +add_cd_file(TARGET d3dcompiler_43 DESTINATION reactos/system32 FOR all) diff --git a/reactos/dll/directx/wine/d3dcompiler_43/asmparser.c b/reactos/dll/directx/wine/d3dcompiler_43/asmparser.c new file mode 100644 index 00000000000..c57343f9fce --- /dev/null +++ b/reactos/dll/directx/wine/d3dcompiler_43/asmparser.c @@ -0,0 +1,1554 @@ +/* + * Direct3D asm shader parser + * + * Copyright 2008 Stefan Dösinger + * Copyright 2009 Matteo Bruni + * + * 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" + +#include "d3dcompiler_private.h" + +WINE_DEFAULT_DEBUG_CHANNEL(asmshader); +WINE_DECLARE_DEBUG_CHANNEL(parsed_shader); + + +/* How to map vs 1.0 and 2.0 varyings to 3.0 ones + * oTx is mapped to ox, which happens to be an + * identical mapping since BWRITERSPR_TEXCRDOUT == BWRITERSPR_OUTPUT + * oPos, oFog and point size are mapped to general output regs as well. + * the vs 1.x and 2.x parser functions add varying declarations + * to the shader, and the 1.x and 2.x output functions check those varyings + */ +#define OT0_REG 0 +#define OT1_REG 1 +#define OT2_REG 2 +#define OT3_REG 3 +#define OT4_REG 4 +#define OT5_REG 5 +#define OT6_REG 6 +#define OT7_REG 7 +#define OPOS_REG 8 +#define OFOG_REG 9 +#define OFOG_WRITEMASK BWRITERSP_WRITEMASK_0 +#define OPTS_REG 9 +#define OPTS_WRITEMASK BWRITERSP_WRITEMASK_1 +#define OD0_REG 10 +#define OD1_REG 11 + +/* Input color registers 0-1 are identically mapped */ +#define C0_VARYING 0 +#define C1_VARYING 1 +#define T0_VARYING 2 +#define T1_VARYING 3 +#define T2_VARYING 4 +#define T3_VARYING 5 +#define T4_VARYING 6 +#define T5_VARYING 7 +#define T6_VARYING 8 +#define T7_VARYING 9 + +/**************************************************************** + * Common(non-version specific) shader parser control code * + ****************************************************************/ + +static void asmparser_end(struct asm_parser *This) { + TRACE("Finalizing shader\n"); +} + +static void asmparser_constF(struct asm_parser *This, DWORD reg, float x, float y, float z, float w) { + if(!This->shader) return; + TRACE("Adding float constant %u at pos %u\n", reg, This->shader->num_cf); + TRACE_(parsed_shader)("def c%u, %f, %f, %f, %f\n", reg, x, y, z, w); + if(!add_constF(This->shader, reg, x, y, z, w)) { + ERR("Out of memory\n"); + set_parse_status(&This->status, PARSE_ERR); + } +} + +static void asmparser_constB(struct asm_parser *This, DWORD reg, BOOL x) { + if(!This->shader) return; + TRACE("Adding boolean constant %u at pos %u\n", reg, This->shader->num_cb); + TRACE_(parsed_shader)("def b%u, %s\n", reg, x ? "true" : "false"); + if(!add_constB(This->shader, reg, x)) { + ERR("Out of memory\n"); + set_parse_status(&This->status, PARSE_ERR); + } +} + +static void asmparser_constI(struct asm_parser *This, DWORD reg, INT x, INT y, INT z, INT w) { + if(!This->shader) return; + TRACE("Adding integer constant %u at pos %u\n", reg, This->shader->num_ci); + TRACE_(parsed_shader)("def i%u, %d, %d, %d, %d\n", reg, x, y, z, w); + if(!add_constI(This->shader, reg, x, y, z, w)) { + ERR("Out of memory\n"); + set_parse_status(&This->status, PARSE_ERR); + } +} + +static void asmparser_dcl_output(struct asm_parser *This, DWORD usage, DWORD num, + const struct shader_reg *reg) { + if(!This->shader) return; + if(This->shader->type == ST_PIXEL) { + asmparser_message(This, "Line %u: Output register declared in a pixel shader\n", This->line_no); + set_parse_status(&This->status, PARSE_ERR); + } + if(!record_declaration(This->shader, usage, num, 0, TRUE, reg->regnum, reg->u.writemask, FALSE)) { + ERR("Out of memory\n"); + set_parse_status(&This->status, PARSE_ERR); + } +} + +static void asmparser_dcl_output_unsupported(struct asm_parser *This, DWORD usage, DWORD num, + const struct shader_reg *reg) { + asmparser_message(This, "Line %u: Output declaration unsupported in this shader version\n", This->line_no); + set_parse_status(&This->status, PARSE_ERR); +} + +static void asmparser_dcl_input(struct asm_parser *This, DWORD usage, DWORD num, + DWORD mod, const struct shader_reg *reg) { + struct instruction instr; + + if(!This->shader) return; + if(mod != 0 && + (This->shader->version != BWRITERPS_VERSION(3, 0) || + (mod != BWRITERSPDM_MSAMPCENTROID && + mod != BWRITERSPDM_PARTIALPRECISION))) { + asmparser_message(This, "Line %u: Unsupported modifier in dcl instruction\n", This->line_no); + set_parse_status(&This->status, PARSE_ERR); + return; + } + + /* Check register type and modifiers */ + instr.dstmod = mod; + instr.shift = 0; + This->funcs->dstreg(This, &instr, reg); + + if(!record_declaration(This->shader, usage, num, mod, FALSE, reg->regnum, reg->u.writemask, FALSE)) { + ERR("Out of memory\n"); + set_parse_status(&This->status, PARSE_ERR); + } +} + +static void asmparser_dcl_input_ps_2(struct asm_parser *This, DWORD usage, DWORD num, + DWORD mod, const struct shader_reg *reg) { + struct instruction instr; + + if(!This->shader) return; + instr.dstmod = mod; + instr.shift = 0; + This->funcs->dstreg(This, &instr, reg); + if(!record_declaration(This->shader, usage, num, mod, FALSE, instr.dst.regnum, instr.dst.u.writemask, FALSE)) { + ERR("Out of memory\n"); + set_parse_status(&This->status, PARSE_ERR); + } +} + +static void asmparser_dcl_input_unsupported(struct asm_parser *This, + DWORD usage, DWORD num, DWORD mod, const struct shader_reg *reg) +{ + asmparser_message(This, "Line %u: Input declaration unsupported in this shader version\n", This->line_no); + set_parse_status(&This->status, PARSE_ERR); +} + +static void asmparser_dcl_sampler(struct asm_parser *This, DWORD samptype, + DWORD mod, DWORD regnum, + unsigned int line_no) { + if(!This->shader) return; + if(mod != 0 && + (This->shader->version != BWRITERPS_VERSION(3, 0) || + (mod != BWRITERSPDM_MSAMPCENTROID && + mod != BWRITERSPDM_PARTIALPRECISION))) { + asmparser_message(This, "Line %u: Unsupported modifier in dcl instruction\n", This->line_no); + set_parse_status(&This->status, PARSE_ERR); + return; + } + if(!record_sampler(This->shader, samptype, mod, regnum)) { + ERR("Out of memory\n"); + set_parse_status(&This->status, PARSE_ERR); + } +} + +static void asmparser_dcl_sampler_unsupported(struct asm_parser *This, + DWORD samptype, DWORD mod, DWORD regnum, unsigned int line_no) +{ + asmparser_message(This, "Line %u: Sampler declaration unsupported in this shader version\n", This->line_no); + set_parse_status(&This->status, PARSE_ERR); +} + +static void asmparser_sincos(struct asm_parser *This, DWORD mod, DWORD shift, + const struct shader_reg *dst, + const struct src_regs *srcs) { + struct instruction *instr; + + if(!srcs || srcs->count != 3) { + asmparser_message(This, "Line %u: sincos (vs 2) has an incorrect number of source registers\n", This->line_no); + set_parse_status(&This->status, PARSE_ERR); + return; + } + + instr = alloc_instr(3); + if(!instr) { + ERR("Error allocating memory for the instruction\n"); + set_parse_status(&This->status, PARSE_ERR); + return; + } + + instr->opcode = BWRITERSIO_SINCOS; + instr->dstmod = mod; + instr->shift = shift; + instr->comptype = 0; + + This->funcs->dstreg(This, instr, dst); + This->funcs->srcreg(This, instr, 0, &srcs->reg[0]); + This->funcs->srcreg(This, instr, 1, &srcs->reg[1]); + This->funcs->srcreg(This, instr, 2, &srcs->reg[2]); + + if(!add_instruction(This->shader, instr)) { + ERR("Out of memory\n"); + set_parse_status(&This->status, PARSE_ERR); + } +} + +static struct shader_reg map_oldps_register(const struct shader_reg *reg, BOOL tex_varying) { + struct shader_reg ret; + switch(reg->type) { + case BWRITERSPR_TEXTURE: + if(tex_varying) { + ret = *reg; + ret.type = BWRITERSPR_INPUT; + switch(reg->regnum) { + case 0: ret.regnum = T0_VARYING; break; + case 1: ret.regnum = T1_VARYING; break; + case 2: ret.regnum = T2_VARYING; break; + case 3: ret.regnum = T3_VARYING; break; + case 4: ret.regnum = T4_VARYING; break; + case 5: ret.regnum = T5_VARYING; break; + case 6: ret.regnum = T6_VARYING; break; + case 7: ret.regnum = T7_VARYING; break; + default: + FIXME("Unexpected TEXTURE register t%u\n", reg->regnum); + return *reg; + } + return ret; + } else { + ret = *reg; + ret.type = BWRITERSPR_TEMP; + switch(reg->regnum) { + case 0: ret.regnum = T0_REG; break; + case 1: ret.regnum = T1_REG; break; + case 2: ret.regnum = T2_REG; break; + case 3: ret.regnum = T3_REG; break; + default: + FIXME("Unexpected TEXTURE register t%u\n", reg->regnum); + return *reg; + } + return ret; + } + + /* case BWRITERSPR_INPUT - Identical mapping of 1.x/2.0 color varyings + to 3.0 ones */ + + default: return *reg; + } +} + +static void asmparser_texcoord(struct asm_parser *This, DWORD mod, DWORD shift, + const struct shader_reg *dst, + const struct src_regs *srcs) { + struct instruction *instr; + + if(srcs) { + asmparser_message(This, "Line %u: Source registers in texcoord instruction\n", This->line_no); + set_parse_status(&This->status, PARSE_ERR); + return; + } + + instr = alloc_instr(1); + if(!instr) { + ERR("Error allocating memory for the instruction\n"); + set_parse_status(&This->status, PARSE_ERR); + return; + } + + /* texcoord copies the texture coord data into a temporary register-like + * readable form. In newer shader models this equals a MOV from v0 to r0, + * record it as this. + */ + instr->opcode = BWRITERSIO_MOV; + instr->dstmod = mod | BWRITERSPDM_SATURATE; /* texcoord clamps to [0;1] */ + instr->shift = shift; + instr->comptype = 0; + + This->funcs->dstreg(This, instr, dst); + /* The src reg needs special care */ + instr->src[0] = map_oldps_register(dst, TRUE); + + if(!add_instruction(This->shader, instr)) { + ERR("Out of memory\n"); + set_parse_status(&This->status, PARSE_ERR); + } +} + +static void asmparser_texcrd(struct asm_parser *This, DWORD mod, DWORD shift, + const struct shader_reg *dst, + const struct src_regs *srcs) { + struct instruction *instr; + + if(!srcs || srcs->count != 1) { + asmparser_message(This, "Line %u: Wrong number of source registers in texcrd instruction\n", This->line_no); + set_parse_status(&This->status, PARSE_ERR); + return; + } + + instr = alloc_instr(1); + if(!instr) { + ERR("Error allocating memory for the instruction\n"); + set_parse_status(&This->status, PARSE_ERR); + return; + } + + /* The job of texcrd is done by mov in later shader versions */ + instr->opcode = BWRITERSIO_MOV; + instr->dstmod = mod; + instr->shift = shift; + instr->comptype = 0; + + This->funcs->dstreg(This, instr, dst); + This->funcs->srcreg(This, instr, 0, &srcs->reg[0]); + + if(!add_instruction(This->shader, instr)) { + ERR("Out of memory\n"); + set_parse_status(&This->status, PARSE_ERR); + } +} + +static void asmparser_texkill(struct asm_parser *This, + const struct shader_reg *dst) { + struct instruction *instr = alloc_instr(0); + + if(!instr) { + ERR("Error allocating memory for the instruction\n"); + set_parse_status(&This->status, PARSE_ERR); + return; + } + + instr->opcode = BWRITERSIO_TEXKILL; + instr->dstmod = 0; + instr->shift = 0; + instr->comptype = 0; + + /* Do not run the dst register through the normal + * register conversion. If used with ps_1_0 to ps_1_3 + * the texture coordinate from that register is used, + * not the temporary register value. In ps_1_4 and + * ps_2_0 t0 is always a varying and temporaries can + * be used with texkill. + */ + instr->dst = map_oldps_register(dst, TRUE); + instr->has_dst = TRUE; + + if(!add_instruction(This->shader, instr)) { + ERR("Out of memory\n"); + set_parse_status(&This->status, PARSE_ERR); + } +} + +static void asmparser_texhelper(struct asm_parser *This, DWORD mod, DWORD shift, + const struct shader_reg *dst, + const struct shader_reg *src0) { + struct instruction *instr = alloc_instr(2); + + if(!instr) { + ERR("Error allocating memory for the instruction\n"); + set_parse_status(&This->status, PARSE_ERR); + return; + } + + instr->opcode = BWRITERSIO_TEX; + instr->dstmod = mod; + instr->shift = shift; + instr->comptype = 0; + /* The dest register can be mapped normally to a temporary register */ + This->funcs->dstreg(This, instr, dst); + /* Use the src passed as parameter by the specific instruction handler */ + instr->src[0] = *src0; + + /* The 2nd source register is the sampler register with the + * destination's regnum + */ + ZeroMemory(&instr->src[1], sizeof(instr->src[1])); + instr->src[1].type = BWRITERSPR_SAMPLER; + instr->src[1].regnum = dst->regnum; + instr->src[1].u.swizzle = BWRITERVS_NOSWIZZLE; + instr->src[1].srcmod = BWRITERSPSM_NONE; + instr->src[1].rel_reg = NULL; + + if(!add_instruction(This->shader, instr)) { + ERR("Out of memory\n"); + set_parse_status(&This->status, PARSE_ERR); + } +} + +static void asmparser_tex(struct asm_parser *This, DWORD mod, DWORD shift, + const struct shader_reg *dst) { + struct shader_reg src; + + /* The first source register is the varying containing the coordinate */ + src = map_oldps_register(dst, TRUE); + asmparser_texhelper(This, mod, shift, dst, &src); +} + +static void asmparser_texld14(struct asm_parser *This, DWORD mod, DWORD shift, + const struct shader_reg *dst, + const struct src_regs *srcs) { + struct instruction *instr; + + if(!srcs || srcs->count != 1) { + asmparser_message(This, "Line %u: texld (PS 1.4) has a wrong number of source registers\n", This->line_no); + set_parse_status(&This->status, PARSE_ERR); + return; + } + + instr = alloc_instr(2); + if(!instr) { + ERR("Error allocating memory for the instruction\n"); + set_parse_status(&This->status, PARSE_ERR); + return; + } + + /* This code is recording a texld instruction, not tex. However, + * texld borrows the opcode of tex + */ + instr->opcode = BWRITERSIO_TEX; + instr->dstmod = mod; + instr->shift = shift; + instr->comptype = 0; + + This->funcs->dstreg(This, instr, dst); + This->funcs->srcreg(This, instr, 0, &srcs->reg[0]); + + /* The 2nd source register is the sampler register with the + * destination's regnum + */ + ZeroMemory(&instr->src[1], sizeof(instr->src[1])); + instr->src[1].type = BWRITERSPR_SAMPLER; + instr->src[1].regnum = dst->regnum; + instr->src[1].u.swizzle = BWRITERVS_NOSWIZZLE; + instr->src[1].srcmod = BWRITERSPSM_NONE; + instr->src[1].rel_reg = NULL; + + if(!add_instruction(This->shader, instr)) { + ERR("Out of memory\n"); + set_parse_status(&This->status, PARSE_ERR); + } +} + +static void asmparser_texreg2ar(struct asm_parser *This, DWORD mod, DWORD shift, + const struct shader_reg *dst, + const struct shader_reg *src0) { + struct shader_reg src; + + src = map_oldps_register(src0, FALSE); + /* Supply the correct swizzle */ + src.u.swizzle = BWRITERVS_X_W | BWRITERVS_Y_X | BWRITERVS_Z_X | BWRITERVS_W_X; + asmparser_texhelper(This, mod, shift, dst, &src); +} + +static void asmparser_texreg2gb(struct asm_parser *This, DWORD mod, DWORD shift, + const struct shader_reg *dst, + const struct shader_reg *src0) { + struct shader_reg src; + + src = map_oldps_register(src0, FALSE); + /* Supply the correct swizzle */ + src.u.swizzle = BWRITERVS_X_Y | BWRITERVS_Y_Z | BWRITERVS_Z_Z | BWRITERVS_W_Z; + asmparser_texhelper(This, mod, shift, dst, &src); +} + +static void asmparser_texreg2rgb(struct asm_parser *This, DWORD mod, DWORD shift, + const struct shader_reg *dst, + const struct shader_reg *src0) { + struct shader_reg src; + + src = map_oldps_register(src0, FALSE); + /* Supply the correct swizzle */ + src.u.swizzle = BWRITERVS_X_X | BWRITERVS_Y_Y | BWRITERVS_Z_Z | BWRITERVS_W_Z; + asmparser_texhelper(This, mod, shift, dst, &src); +} + +/* Complex pixel shader 1.3 instructions like texm3x3tex are tricky - the + * bytecode writer works instruction by instruction, so we can't properly + * convert these from/to equivalent ps_3_0 instructions. Then simply keep using + * the ps_1_3 opcodes and just adapt the registers in the common fashion (i.e. + * go through asmparser_instr). + */ + +static void asmparser_instr(struct asm_parser *This, DWORD opcode, + DWORD mod, DWORD shift, + BWRITER_COMPARISON_TYPE comp, + const struct shader_reg *dst, + const struct src_regs *srcs, int expectednsrcs) { + struct instruction *instr; + unsigned int i; + BOOL firstreg = TRUE; + unsigned int src_count = srcs ? srcs->count : 0; + + if(!This->shader) return; + + TRACE_(parsed_shader)("%s%s%s%s ", debug_print_opcode(opcode), + debug_print_dstmod(mod), + debug_print_shift(shift), + debug_print_comp(comp)); + if(dst) { + TRACE_(parsed_shader)("%s", debug_print_dstreg(dst)); + firstreg = FALSE; + } + for(i = 0; i < src_count; i++) { + if(!firstreg) TRACE_(parsed_shader)(", "); + else firstreg = FALSE; + TRACE_(parsed_shader)("%s", debug_print_srcreg(&srcs->reg[i])); + } + TRACE_(parsed_shader)("\n"); + + /* Check for instructions with different syntaxes in different shader versions */ + switch(opcode) { + case BWRITERSIO_SINCOS: + /* The syntax changes between vs 2 and the other shader versions */ + if(This->shader->version == BWRITERVS_VERSION(2, 0) || + This->shader->version == BWRITERVS_VERSION(2, 1)) { + asmparser_sincos(This, mod, shift, dst, srcs); + return; + } + /* Use the default handling */ + break; + case BWRITERSIO_TEXCOORD: + /* texcoord/texcrd are two instructions present only in PS <= 1.3 and PS 1.4 respectively */ + if(This->shader->version == BWRITERPS_VERSION(1, 4)) + asmparser_texcrd(This, mod, shift, dst, srcs); + else asmparser_texcoord(This, mod, shift, dst, srcs); + return; + case BWRITERSIO_TEX: + /* this encodes both the tex PS 1.x instruction and the + texld 1.4/2.0+ instruction */ + if(This->shader->version == BWRITERPS_VERSION(1, 0) || + This->shader->version == BWRITERPS_VERSION(1, 1) || + This->shader->version == BWRITERPS_VERSION(1, 2) || + This->shader->version == BWRITERPS_VERSION(1, 3)) { + asmparser_tex(This, mod, shift, dst); + return; + } + else if(This->shader->version == BWRITERPS_VERSION(1, 4)) { + asmparser_texld14(This, mod, shift, dst, srcs); + return; + } + /* else fallback to the standard behavior */ + break; + } + + if(src_count != expectednsrcs) { + asmparser_message(This, "Line %u: Wrong number of source registers\n", This->line_no); + set_parse_status(&This->status, PARSE_ERR); + return; + } + + /* Handle PS 1.x instructions, "regularizing" them */ + switch(opcode) { + case BWRITERSIO_TEXKILL: + asmparser_texkill(This, dst); + return; + case BWRITERSIO_TEXREG2AR: + asmparser_texreg2ar(This, mod, shift, dst, &srcs->reg[0]); + return; + case BWRITERSIO_TEXREG2GB: + asmparser_texreg2gb(This, mod, shift, dst, &srcs->reg[0]); + return; + case BWRITERSIO_TEXREG2RGB: + asmparser_texreg2rgb(This, mod, shift, dst, &srcs->reg[0]); + return; + } + + instr = alloc_instr(src_count); + if(!instr) { + ERR("Error allocating memory for the instruction\n"); + set_parse_status(&This->status, PARSE_ERR); + return; + } + + instr->opcode = opcode; + instr->dstmod = mod; + instr->shift = shift; + instr->comptype = comp; + if(dst) This->funcs->dstreg(This, instr, dst); + for(i = 0; i < src_count; i++) { + This->funcs->srcreg(This, instr, i, &srcs->reg[i]); + } + + if(!add_instruction(This->shader, instr)) { + ERR("Out of memory\n"); + set_parse_status(&This->status, PARSE_ERR); + } +} + +static struct shader_reg map_oldvs_register(const struct shader_reg *reg) { + struct shader_reg ret; + switch(reg->type) { + case BWRITERSPR_RASTOUT: + ret = *reg; + ret.type = BWRITERSPR_OUTPUT; + switch(reg->regnum) { + case BWRITERSRO_POSITION: + ret.regnum = OPOS_REG; + break; + case BWRITERSRO_FOG: + ret.regnum = OFOG_REG; + ret.u.writemask = OFOG_WRITEMASK; + break; + case BWRITERSRO_POINT_SIZE: + ret.regnum = OPTS_REG; + ret.u.writemask = OPTS_WRITEMASK; + break; + default: + FIXME("Unhandled RASTOUT register %u\n", reg->regnum); + return *reg; + } + return ret; + + case BWRITERSPR_TEXCRDOUT: + ret = *reg; + ret.type = BWRITERSPR_OUTPUT; + switch(reg->regnum) { + case 0: ret.regnum = OT0_REG; break; + case 1: ret.regnum = OT1_REG; break; + case 2: ret.regnum = OT2_REG; break; + case 3: ret.regnum = OT3_REG; break; + case 4: ret.regnum = OT4_REG; break; + case 5: ret.regnum = OT5_REG; break; + case 6: ret.regnum = OT6_REG; break; + case 7: ret.regnum = OT7_REG; break; + default: + FIXME("Unhandled TEXCRDOUT regnum %u\n", reg->regnum); + return *reg; + } + return ret; + + case BWRITERSPR_ATTROUT: + ret = *reg; + ret.type = BWRITERSPR_OUTPUT; + switch(reg->regnum) { + case 0: ret.regnum = OD0_REG; break; + case 1: ret.regnum = OD1_REG; break; + default: + FIXME("Unhandled ATTROUT regnum %u\n", reg->regnum); + return *reg; + } + return ret; + + default: return *reg; + } +} + +/* Checks for unsupported source modifiers in VS (all versions) or + PS 2.0 and newer */ +static void check_legacy_srcmod(struct asm_parser *This, DWORD srcmod) { + if(srcmod == BWRITERSPSM_BIAS || srcmod == BWRITERSPSM_BIASNEG || + srcmod == BWRITERSPSM_SIGN || srcmod == BWRITERSPSM_SIGNNEG || + srcmod == BWRITERSPSM_COMP || srcmod == BWRITERSPSM_X2 || + srcmod == BWRITERSPSM_X2NEG || srcmod == BWRITERSPSM_DZ || + srcmod == BWRITERSPSM_DW) { + asmparser_message(This, "Line %u: Source modifier %s not supported in this shader version\n", + This->line_no, + debug_print_srcmod(srcmod)); + set_parse_status(&This->status, PARSE_ERR); + } +} + +static void check_abs_srcmod(struct asm_parser *This, DWORD srcmod) { + if(srcmod == BWRITERSPSM_ABS || srcmod == BWRITERSPSM_ABSNEG) { + asmparser_message(This, "Line %u: Source modifier %s not supported in this shader version\n", + This->line_no, + debug_print_srcmod(srcmod)); + set_parse_status(&This->status, PARSE_ERR); + } +} + +static void check_loop_swizzle(struct asm_parser *This, + const struct shader_reg *src) { + if((src->type == BWRITERSPR_LOOP && src->u.swizzle != BWRITERVS_NOSWIZZLE) || + (src->rel_reg && src->rel_reg->type == BWRITERSPR_LOOP && + src->rel_reg->u.swizzle != BWRITERVS_NOSWIZZLE)) { + asmparser_message(This, "Line %u: Swizzle not allowed on aL register\n", This->line_no); + set_parse_status(&This->status, PARSE_ERR); + } +} + +static void check_shift_dstmod(struct asm_parser *This, DWORD shift) { + if(shift != 0) { + asmparser_message(This, "Line %u: Shift modifiers not supported in this shader version\n", + This->line_no); + set_parse_status(&This->status, PARSE_ERR); + } +} + +static void check_ps_dstmod(struct asm_parser *This, DWORD dstmod) { + if(dstmod == BWRITERSPDM_PARTIALPRECISION || + dstmod == BWRITERSPDM_MSAMPCENTROID) { + asmparser_message(This, "Line %u: Instruction modifier %s not supported in this shader version\n", + This->line_no, + debug_print_dstmod(dstmod)); + set_parse_status(&This->status, PARSE_ERR); + } +} + +struct allowed_reg_type { + DWORD type; + DWORD count; + BOOL reladdr; +}; + +static BOOL check_reg_type(const struct shader_reg *reg, + const struct allowed_reg_type *allowed) { + unsigned int i = 0; + + while(allowed[i].type != ~0U) { + if(reg->type == allowed[i].type) { + if(reg->rel_reg) { + if(allowed[i].reladdr) + return TRUE; /* The relative addressing register + can have a negative value, we + can't check the register index */ + return FALSE; + } + if(reg->regnum < allowed[i].count) return TRUE; + return FALSE; + } + i++; + } + return FALSE; +} + +/* Native assembler doesn't do separate checks for src and dst registers */ +static const struct allowed_reg_type vs_1_reg_allowed[] = { + { BWRITERSPR_TEMP, 12, FALSE }, + { BWRITERSPR_INPUT, 16, FALSE }, + { BWRITERSPR_CONST, ~0U, TRUE }, + { BWRITERSPR_ADDR, 1, FALSE }, + { BWRITERSPR_RASTOUT, 3, FALSE }, /* oPos, oFog and oPts */ + { BWRITERSPR_ATTROUT, 2, FALSE }, + { BWRITERSPR_TEXCRDOUT, 8, FALSE }, + { ~0U, 0 } /* End tag */ +}; + +/* struct instruction *asmparser_srcreg + * + * Records a source register in the instruction and does shader version + * specific checks and modifications on it + * + * Parameters: + * This: Shader parser instance + * instr: instruction to store the register in + * num: Number of source register + * src: Pointer to source the register structure. The caller can free + * it afterwards + */ +static void asmparser_srcreg_vs_1(struct asm_parser *This, + struct instruction *instr, int num, + const struct shader_reg *src) { + struct shader_reg reg; + + if(!check_reg_type(src, vs_1_reg_allowed)) { + asmparser_message(This, "Line %u: Source register %s not supported in VS 1\n", + This->line_no, + debug_print_srcreg(src)); + set_parse_status(&This->status, PARSE_ERR); + } + check_legacy_srcmod(This, src->srcmod); + check_abs_srcmod(This, src->srcmod); + reg = map_oldvs_register(src); + instr->src[num] = reg; +} + +static const struct allowed_reg_type vs_2_reg_allowed[] = { + { BWRITERSPR_TEMP, 12, FALSE }, + { BWRITERSPR_INPUT, 16, FALSE }, + { BWRITERSPR_CONST, ~0U, TRUE }, + { BWRITERSPR_ADDR, 1, FALSE }, + { BWRITERSPR_CONSTBOOL, 16, FALSE }, + { BWRITERSPR_CONSTINT, 16, FALSE }, + { BWRITERSPR_LOOP, 1, FALSE }, + { BWRITERSPR_LABEL, 2048, FALSE }, + { BWRITERSPR_PREDICATE, 1, FALSE }, + { BWRITERSPR_RASTOUT, 3, FALSE }, /* oPos, oFog and oPts */ + { BWRITERSPR_ATTROUT, 2, FALSE }, + { BWRITERSPR_TEXCRDOUT, 8, FALSE }, + { ~0U, 0 } /* End tag */ +}; + +static void asmparser_srcreg_vs_2(struct asm_parser *This, + struct instruction *instr, int num, + const struct shader_reg *src) { + struct shader_reg reg; + + if(!check_reg_type(src, vs_2_reg_allowed)) { + asmparser_message(This, "Line %u: Source register %s not supported in VS 2\n", + This->line_no, + debug_print_srcreg(src)); + set_parse_status(&This->status, PARSE_ERR); + } + check_loop_swizzle(This, src); + check_legacy_srcmod(This, src->srcmod); + check_abs_srcmod(This, src->srcmod); + reg = map_oldvs_register(src); + instr->src[num] = reg; +} + +static const struct allowed_reg_type vs_3_reg_allowed[] = { + { BWRITERSPR_TEMP, 32, FALSE }, + { BWRITERSPR_INPUT, 16, TRUE }, + { BWRITERSPR_CONST, ~0U, TRUE }, + { BWRITERSPR_ADDR, 1, FALSE }, + { BWRITERSPR_CONSTBOOL, 16, FALSE }, + { BWRITERSPR_CONSTINT, 16, FALSE }, + { BWRITERSPR_LOOP, 1, FALSE }, + { BWRITERSPR_LABEL, 2048, FALSE }, + { BWRITERSPR_PREDICATE, 1, FALSE }, + { BWRITERSPR_SAMPLER, 4, FALSE }, + { BWRITERSPR_OUTPUT, 12, TRUE }, + { ~0U, 0 } /* End tag */ +}; + +static void asmparser_srcreg_vs_3(struct asm_parser *This, + struct instruction *instr, int num, + const struct shader_reg *src) { + if(!check_reg_type(src, vs_3_reg_allowed)) { + asmparser_message(This, "Line %u: Source register %s not supported in VS 3.0\n", + This->line_no, + debug_print_srcreg(src)); + set_parse_status(&This->status, PARSE_ERR); + } + check_loop_swizzle(This, src); + check_legacy_srcmod(This, src->srcmod); + instr->src[num] = *src; +} + +static const struct allowed_reg_type ps_1_0123_reg_allowed[] = { + { BWRITERSPR_CONST, 8, FALSE }, + { BWRITERSPR_TEMP, 2, FALSE }, + { BWRITERSPR_TEXTURE, 4, FALSE }, + { BWRITERSPR_INPUT, 2, FALSE }, + { ~0U, 0 } /* End tag */ +}; + +static void asmparser_srcreg_ps_1_0123(struct asm_parser *This, + struct instruction *instr, int num, + const struct shader_reg *src) { + struct shader_reg reg; + + if(!check_reg_type(src, ps_1_0123_reg_allowed)) { + asmparser_message(This, "Line %u: Source register %s not supported in <== PS 1.3\n", + This->line_no, + debug_print_srcreg(src)); + set_parse_status(&This->status, PARSE_ERR); + } + check_abs_srcmod(This, src->srcmod); + reg = map_oldps_register(src, FALSE); + instr->src[num] = reg; +} + +static const struct allowed_reg_type ps_1_4_reg_allowed[] = { + { BWRITERSPR_CONST, 8, FALSE }, + { BWRITERSPR_TEMP, 6, FALSE }, + { BWRITERSPR_TEXTURE, 6, FALSE }, + { BWRITERSPR_INPUT, 2, FALSE }, + { ~0U, 0 } /* End tag */ +}; + +static void asmparser_srcreg_ps_1_4(struct asm_parser *This, + struct instruction *instr, int num, + const struct shader_reg *src) { + struct shader_reg reg; + + if(!check_reg_type(src, ps_1_4_reg_allowed)) { + asmparser_message(This, "Line %u: Source register %s not supported in PS 1.4\n", + This->line_no, + debug_print_srcreg(src)); + set_parse_status(&This->status, PARSE_ERR); + } + check_abs_srcmod(This, src->srcmod); + reg = map_oldps_register(src, TRUE); + instr->src[num] = reg; +} + +static const struct allowed_reg_type ps_2_0_reg_allowed[] = { + { BWRITERSPR_INPUT, 2, FALSE }, + { BWRITERSPR_TEMP, 32, FALSE }, + { BWRITERSPR_CONST, 32, FALSE }, + { BWRITERSPR_CONSTINT, 16, FALSE }, + { BWRITERSPR_CONSTBOOL, 16, FALSE }, + { BWRITERSPR_SAMPLER, 16, FALSE }, + { BWRITERSPR_TEXTURE, 8, FALSE }, + { BWRITERSPR_COLOROUT, 4, FALSE }, + { BWRITERSPR_DEPTHOUT, 1, FALSE }, + { ~0U, 0 } /* End tag */ +}; + +static void asmparser_srcreg_ps_2(struct asm_parser *This, + struct instruction *instr, int num, + const struct shader_reg *src) { + struct shader_reg reg; + + if(!check_reg_type(src, ps_2_0_reg_allowed)) { + asmparser_message(This, "Line %u: Source register %s not supported in PS 2.0\n", + This->line_no, + debug_print_srcreg(src)); + set_parse_status(&This->status, PARSE_ERR); + } + check_legacy_srcmod(This, src->srcmod); + check_abs_srcmod(This, src->srcmod); + reg = map_oldps_register(src, TRUE); + instr->src[num] = reg; +} + +static const struct allowed_reg_type ps_2_x_reg_allowed[] = { + { BWRITERSPR_INPUT, 2, FALSE }, + { BWRITERSPR_TEMP, 32, FALSE }, + { BWRITERSPR_CONST, 32, FALSE }, + { BWRITERSPR_CONSTINT, 16, FALSE }, + { BWRITERSPR_CONSTBOOL, 16, FALSE }, + { BWRITERSPR_PREDICATE, 1, FALSE }, + { BWRITERSPR_SAMPLER, 16, FALSE }, + { BWRITERSPR_TEXTURE, 8, FALSE }, + { BWRITERSPR_LABEL, 2048, FALSE }, + { BWRITERSPR_COLOROUT, 4, FALSE }, + { BWRITERSPR_DEPTHOUT, 1, FALSE }, + { ~0U, 0 } /* End tag */ +}; + +static void asmparser_srcreg_ps_2_x(struct asm_parser *This, + struct instruction *instr, int num, + const struct shader_reg *src) { + struct shader_reg reg; + + if(!check_reg_type(src, ps_2_x_reg_allowed)) { + asmparser_message(This, "Line %u: Source register %s not supported in PS 2.x\n", + This->line_no, + debug_print_srcreg(src)); + set_parse_status(&This->status, PARSE_ERR); + } + check_legacy_srcmod(This, src->srcmod); + check_abs_srcmod(This, src->srcmod); + reg = map_oldps_register(src, TRUE); + instr->src[num] = reg; +} + +static const struct allowed_reg_type ps_3_reg_allowed[] = { + { BWRITERSPR_INPUT, 10, TRUE }, + { BWRITERSPR_TEMP, 32, FALSE }, + { BWRITERSPR_CONST, 224, FALSE }, + { BWRITERSPR_CONSTINT, 16, FALSE }, + { BWRITERSPR_CONSTBOOL, 16, FALSE }, + { BWRITERSPR_PREDICATE, 1, FALSE }, + { BWRITERSPR_SAMPLER, 16, FALSE }, + { BWRITERSPR_MISCTYPE, 2, FALSE }, /* vPos and vFace */ + { BWRITERSPR_LOOP, 1, FALSE }, + { BWRITERSPR_LABEL, 2048, FALSE }, + { BWRITERSPR_COLOROUT, 4, FALSE }, + { BWRITERSPR_DEPTHOUT, 1, FALSE }, + { ~0U, 0 } /* End tag */ +}; + +static void asmparser_srcreg_ps_3(struct asm_parser *This, + struct instruction *instr, int num, + const struct shader_reg *src) { + if(!check_reg_type(src, ps_3_reg_allowed)) { + asmparser_message(This, "Line %u: Source register %s not supported in PS 3.0\n", + This->line_no, + debug_print_srcreg(src)); + set_parse_status(&This->status, PARSE_ERR); + } + check_loop_swizzle(This, src); + check_legacy_srcmod(This, src->srcmod); + instr->src[num] = *src; +} + +static void asmparser_dstreg_vs_1(struct asm_parser *This, + struct instruction *instr, + const struct shader_reg *dst) { + struct shader_reg reg; + + if(!check_reg_type(dst, vs_1_reg_allowed)) { + asmparser_message(This, "Line %u: Destination register %s not supported in VS 1\n", + This->line_no, + debug_print_dstreg(dst)); + set_parse_status(&This->status, PARSE_ERR); + } + check_ps_dstmod(This, instr->dstmod); + check_shift_dstmod(This, instr->shift); + reg = map_oldvs_register(dst); + instr->dst = reg; + instr->has_dst = TRUE; +} + +static void asmparser_dstreg_vs_2(struct asm_parser *This, + struct instruction *instr, + const struct shader_reg *dst) { + struct shader_reg reg; + + if(!check_reg_type(dst, vs_2_reg_allowed)) { + asmparser_message(This, "Line %u: Destination register %s not supported in VS 2.0\n", + This->line_no, + debug_print_dstreg(dst)); + set_parse_status(&This->status, PARSE_ERR); + } + check_ps_dstmod(This, instr->dstmod); + check_shift_dstmod(This, instr->shift); + reg = map_oldvs_register(dst); + instr->dst = reg; + instr->has_dst = TRUE; +} + +static void asmparser_dstreg_vs_3(struct asm_parser *This, + struct instruction *instr, + const struct shader_reg *dst) { + if(!check_reg_type(dst, vs_3_reg_allowed)) { + asmparser_message(This, "Line %u: Destination register %s not supported in VS 3.0\n", + This->line_no, + debug_print_dstreg(dst)); + set_parse_status(&This->status, PARSE_ERR); + } + check_ps_dstmod(This, instr->dstmod); + check_shift_dstmod(This, instr->shift); + instr->dst = *dst; + instr->has_dst = TRUE; +} + +static void asmparser_dstreg_ps_1_0123(struct asm_parser *This, + struct instruction *instr, + const struct shader_reg *dst) { + struct shader_reg reg; + + if(!check_reg_type(dst, ps_1_0123_reg_allowed)) { + asmparser_message(This, "Line %u: Destination register %s not supported in PS 1\n", + This->line_no, + debug_print_dstreg(dst)); + set_parse_status(&This->status, PARSE_ERR); + } + reg = map_oldps_register(dst, FALSE); + instr->dst = reg; + instr->has_dst = TRUE; +} + +static void asmparser_dstreg_ps_1_4(struct asm_parser *This, + struct instruction *instr, + const struct shader_reg *dst) { + struct shader_reg reg; + + if(!check_reg_type(dst, ps_1_4_reg_allowed)) { + asmparser_message(This, "Line %u: Destination register %s not supported in PS 1\n", + This->line_no, + debug_print_dstreg(dst)); + set_parse_status(&This->status, PARSE_ERR); + } + reg = map_oldps_register(dst, TRUE); + instr->dst = reg; + instr->has_dst = TRUE; +} + +static void asmparser_dstreg_ps_2(struct asm_parser *This, + struct instruction *instr, + const struct shader_reg *dst) { + struct shader_reg reg; + + if(!check_reg_type(dst, ps_2_0_reg_allowed)) { + asmparser_message(This, "Line %u: Destination register %s not supported in PS 2.0\n", + This->line_no, + debug_print_dstreg(dst)); + set_parse_status(&This->status, PARSE_ERR); + } + check_shift_dstmod(This, instr->shift); + reg = map_oldps_register(dst, TRUE); + instr->dst = reg; + instr->has_dst = TRUE; +} + +static void asmparser_dstreg_ps_2_x(struct asm_parser *This, + struct instruction *instr, + const struct shader_reg *dst) { + struct shader_reg reg; + + if(!check_reg_type(dst, ps_2_x_reg_allowed)) { + asmparser_message(This, "Line %u: Destination register %s not supported in PS 2.x\n", + This->line_no, + debug_print_dstreg(dst)); + set_parse_status(&This->status, PARSE_ERR); + } + check_shift_dstmod(This, instr->shift); + reg = map_oldps_register(dst, TRUE); + instr->dst = reg; + instr->has_dst = TRUE; +} + +static void asmparser_dstreg_ps_3(struct asm_parser *This, + struct instruction *instr, + const struct shader_reg *dst) { + if(!check_reg_type(dst, ps_3_reg_allowed)) { + asmparser_message(This, "Line %u: Destination register %s not supported in PS 3.0\n", + This->line_no, + debug_print_dstreg(dst)); + set_parse_status(&This->status, PARSE_ERR); + } + check_shift_dstmod(This, instr->shift); + instr->dst = *dst; + instr->has_dst = TRUE; +} + +static void asmparser_predicate_supported(struct asm_parser *This, + const struct shader_reg *predicate) { + /* this sets the predicate of the last instruction added to the shader */ + if(!This->shader) return; + if(This->shader->num_instrs == 0) ERR("Predicate without an instruction\n"); + This->shader->instr[This->shader->num_instrs - 1]->has_predicate = TRUE; + This->shader->instr[This->shader->num_instrs - 1]->predicate = *predicate; +} + +static void asmparser_predicate_unsupported(struct asm_parser *This, + const struct shader_reg *predicate) { + asmparser_message(This, "Line %u: Predicate not supported in < VS 2.0 or PS 2.x\n", This->line_no); + set_parse_status(&This->status, PARSE_ERR); +} + +static void asmparser_coissue_supported(struct asm_parser *This) { + /* this sets the coissue flag of the last instruction added to the shader */ + if(!This->shader) return; + if(This->shader->num_instrs == 0){ + asmparser_message(This, "Line %u: Coissue flag on the first shader instruction\n", This->line_no); + set_parse_status(&This->status, PARSE_ERR); + } + This->shader->instr[This->shader->num_instrs-1]->coissue = TRUE; +} + +static void asmparser_coissue_unsupported(struct asm_parser *This) { + asmparser_message(This, "Line %u: Coissue is only supported in pixel shaders versions <= 1.4\n", This->line_no); + set_parse_status(&This->status, PARSE_ERR); +} + +static const struct asmparser_backend parser_vs_1 = { + asmparser_constF, + asmparser_constI, + asmparser_constB, + + asmparser_dstreg_vs_1, + asmparser_srcreg_vs_1, + + asmparser_predicate_unsupported, + asmparser_coissue_unsupported, + + asmparser_dcl_output_unsupported, + asmparser_dcl_input, + asmparser_dcl_sampler_unsupported, + + asmparser_end, + + asmparser_instr, +}; + +static const struct asmparser_backend parser_vs_2 = { + asmparser_constF, + asmparser_constI, + asmparser_constB, + + asmparser_dstreg_vs_2, + asmparser_srcreg_vs_2, + + asmparser_predicate_supported, + asmparser_coissue_unsupported, + + asmparser_dcl_output_unsupported, + asmparser_dcl_input, + asmparser_dcl_sampler_unsupported, + + asmparser_end, + + asmparser_instr, +}; + +static const struct asmparser_backend parser_vs_3 = { + asmparser_constF, + asmparser_constI, + asmparser_constB, + + asmparser_dstreg_vs_3, + asmparser_srcreg_vs_3, + + asmparser_predicate_supported, + asmparser_coissue_unsupported, + + asmparser_dcl_output, + asmparser_dcl_input, + asmparser_dcl_sampler, + + asmparser_end, + + asmparser_instr, +}; + +static const struct asmparser_backend parser_ps_1_0123 = { + asmparser_constF, + asmparser_constI, + asmparser_constB, + + asmparser_dstreg_ps_1_0123, + asmparser_srcreg_ps_1_0123, + + asmparser_predicate_unsupported, + asmparser_coissue_supported, + + asmparser_dcl_output_unsupported, + asmparser_dcl_input_unsupported, + asmparser_dcl_sampler_unsupported, + + asmparser_end, + + asmparser_instr, +}; + +static const struct asmparser_backend parser_ps_1_4 = { + asmparser_constF, + asmparser_constI, + asmparser_constB, + + asmparser_dstreg_ps_1_4, + asmparser_srcreg_ps_1_4, + + asmparser_predicate_unsupported, + asmparser_coissue_supported, + + asmparser_dcl_output_unsupported, + asmparser_dcl_input_unsupported, + asmparser_dcl_sampler_unsupported, + + asmparser_end, + + asmparser_instr, +}; + +static const struct asmparser_backend parser_ps_2 = { + asmparser_constF, + asmparser_constI, + asmparser_constB, + + asmparser_dstreg_ps_2, + asmparser_srcreg_ps_2, + + asmparser_predicate_unsupported, + asmparser_coissue_unsupported, + + asmparser_dcl_output_unsupported, + asmparser_dcl_input_ps_2, + asmparser_dcl_sampler, + + asmparser_end, + + asmparser_instr, +}; + +static const struct asmparser_backend parser_ps_2_x = { + asmparser_constF, + asmparser_constI, + asmparser_constB, + + asmparser_dstreg_ps_2_x, + asmparser_srcreg_ps_2_x, + + asmparser_predicate_supported, + asmparser_coissue_unsupported, + + asmparser_dcl_output_unsupported, + asmparser_dcl_input_ps_2, + asmparser_dcl_sampler, + + asmparser_end, + + asmparser_instr, +}; + +static const struct asmparser_backend parser_ps_3 = { + asmparser_constF, + asmparser_constI, + asmparser_constB, + + asmparser_dstreg_ps_3, + asmparser_srcreg_ps_3, + + asmparser_predicate_supported, + asmparser_coissue_unsupported, + + asmparser_dcl_output_unsupported, + asmparser_dcl_input, + asmparser_dcl_sampler, + + asmparser_end, + + asmparser_instr, +}; + +static void gen_oldvs_output(struct bwriter_shader *shader) { + record_declaration(shader, BWRITERDECLUSAGE_POSITION, 0, 0, TRUE, OPOS_REG, BWRITERSP_WRITEMASK_ALL, TRUE); + record_declaration(shader, BWRITERDECLUSAGE_TEXCOORD, 0, 0, TRUE, OT0_REG, BWRITERSP_WRITEMASK_ALL, TRUE); + record_declaration(shader, BWRITERDECLUSAGE_TEXCOORD, 1, 0, TRUE, OT1_REG, BWRITERSP_WRITEMASK_ALL, TRUE); + record_declaration(shader, BWRITERDECLUSAGE_TEXCOORD, 2, 0, TRUE, OT2_REG, BWRITERSP_WRITEMASK_ALL, TRUE); + record_declaration(shader, BWRITERDECLUSAGE_TEXCOORD, 3, 0, TRUE, OT3_REG, BWRITERSP_WRITEMASK_ALL, TRUE); + record_declaration(shader, BWRITERDECLUSAGE_TEXCOORD, 4, 0, TRUE, OT4_REG, BWRITERSP_WRITEMASK_ALL, TRUE); + record_declaration(shader, BWRITERDECLUSAGE_TEXCOORD, 5, 0, TRUE, OT5_REG, BWRITERSP_WRITEMASK_ALL, TRUE); + record_declaration(shader, BWRITERDECLUSAGE_TEXCOORD, 6, 0, TRUE, OT6_REG, BWRITERSP_WRITEMASK_ALL, TRUE); + record_declaration(shader, BWRITERDECLUSAGE_TEXCOORD, 7, 0, TRUE, OT7_REG, BWRITERSP_WRITEMASK_ALL, TRUE); + record_declaration(shader, BWRITERDECLUSAGE_FOG, 0, 0, TRUE, OFOG_REG, OFOG_WRITEMASK, TRUE); + record_declaration(shader, BWRITERDECLUSAGE_PSIZE, 0, 0, TRUE, OPTS_REG, OPTS_WRITEMASK, TRUE); + record_declaration(shader, BWRITERDECLUSAGE_COLOR, 0, 0, TRUE, OD0_REG, BWRITERSP_WRITEMASK_ALL, TRUE); + record_declaration(shader, BWRITERDECLUSAGE_COLOR, 1, 0, TRUE, OD1_REG, BWRITERSP_WRITEMASK_ALL, TRUE); +} + +static void gen_oldps_input(struct bwriter_shader *shader, DWORD texcoords) { + switch(texcoords) { + case 8: record_declaration(shader, BWRITERDECLUSAGE_TEXCOORD, 7, 0, FALSE, T7_VARYING, BWRITERSP_WRITEMASK_ALL, TRUE); + /* fall through */ + case 7: record_declaration(shader, BWRITERDECLUSAGE_TEXCOORD, 6, 0, FALSE, T6_VARYING, BWRITERSP_WRITEMASK_ALL, TRUE); + /* fall through */ + case 6: record_declaration(shader, BWRITERDECLUSAGE_TEXCOORD, 5, 0, FALSE, T5_VARYING, BWRITERSP_WRITEMASK_ALL, TRUE); + /* fall through */ + case 5: record_declaration(shader, BWRITERDECLUSAGE_TEXCOORD, 4, 0, FALSE, T4_VARYING, BWRITERSP_WRITEMASK_ALL, TRUE); + /* fall through */ + case 4: record_declaration(shader, BWRITERDECLUSAGE_TEXCOORD, 3, 0, FALSE, T3_VARYING, BWRITERSP_WRITEMASK_ALL, TRUE); + /* fall through */ + case 3: record_declaration(shader, BWRITERDECLUSAGE_TEXCOORD, 2, 0, FALSE, T2_VARYING, BWRITERSP_WRITEMASK_ALL, TRUE); + /* fall through */ + case 2: record_declaration(shader, BWRITERDECLUSAGE_TEXCOORD, 1, 0, FALSE, T1_VARYING, BWRITERSP_WRITEMASK_ALL, TRUE); + /* fall through */ + case 1: record_declaration(shader, BWRITERDECLUSAGE_TEXCOORD, 0, 0, FALSE, T0_VARYING, BWRITERSP_WRITEMASK_ALL, TRUE); + }; + record_declaration(shader, BWRITERDECLUSAGE_COLOR, 0, 0, FALSE, C0_VARYING, BWRITERSP_WRITEMASK_ALL, TRUE); + record_declaration(shader, BWRITERDECLUSAGE_COLOR, 1, 0, FALSE, C1_VARYING, BWRITERSP_WRITEMASK_ALL, TRUE); +} + +void create_vs10_parser(struct asm_parser *ret) { + TRACE_(parsed_shader)("vs_1_0\n"); + + ret->shader = d3dcompiler_alloc(sizeof(*ret->shader)); + if(!ret->shader) { + ERR("Failed to allocate memory for the shader\n"); + set_parse_status(&ret->status, PARSE_ERR); + return; + } + + ret->shader->type = ST_VERTEX; + ret->shader->version = BWRITERVS_VERSION(1, 0); + ret->funcs = &parser_vs_1; + gen_oldvs_output(ret->shader); +} + +void create_vs11_parser(struct asm_parser *ret) { + TRACE_(parsed_shader)("vs_1_1\n"); + + ret->shader = d3dcompiler_alloc(sizeof(*ret->shader)); + if(!ret->shader) { + ERR("Failed to allocate memory for the shader\n"); + set_parse_status(&ret->status, PARSE_ERR); + return; + } + + ret->shader->type = ST_VERTEX; + ret->shader->version = BWRITERVS_VERSION(1, 1); + ret->funcs = &parser_vs_1; + gen_oldvs_output(ret->shader); +} + +void create_vs20_parser(struct asm_parser *ret) { + TRACE_(parsed_shader)("vs_2_0\n"); + + ret->shader = d3dcompiler_alloc(sizeof(*ret->shader)); + if(!ret->shader) { + ERR("Failed to allocate memory for the shader\n"); + set_parse_status(&ret->status, PARSE_ERR); + return; + } + + ret->shader->type = ST_VERTEX; + ret->shader->version = BWRITERVS_VERSION(2, 0); + ret->funcs = &parser_vs_2; + gen_oldvs_output(ret->shader); +} + +void create_vs2x_parser(struct asm_parser *ret) { + TRACE_(parsed_shader)("vs_2_x\n"); + + ret->shader = d3dcompiler_alloc(sizeof(*ret->shader)); + if(!ret->shader) { + ERR("Failed to allocate memory for the shader\n"); + set_parse_status(&ret->status, PARSE_ERR); + return; + } + + ret->shader->type = ST_VERTEX; + ret->shader->version = BWRITERVS_VERSION(2, 1); + ret->funcs = &parser_vs_2; + gen_oldvs_output(ret->shader); +} + +void create_vs30_parser(struct asm_parser *ret) { + TRACE_(parsed_shader)("vs_3_0\n"); + + ret->shader = d3dcompiler_alloc(sizeof(*ret->shader)); + if(!ret->shader) { + ERR("Failed to allocate memory for the shader\n"); + set_parse_status(&ret->status, PARSE_ERR); + return; + } + + ret->shader->type = ST_VERTEX; + ret->shader->version = BWRITERVS_VERSION(3, 0); + ret->funcs = &parser_vs_3; +} + +void create_ps10_parser(struct asm_parser *ret) { + TRACE_(parsed_shader)("ps_1_0\n"); + + ret->shader = d3dcompiler_alloc(sizeof(*ret->shader)); + if(!ret->shader) { + ERR("Failed to allocate memory for the shader\n"); + set_parse_status(&ret->status, PARSE_ERR); + return; + } + + ret->shader->type = ST_PIXEL; + ret->shader->version = BWRITERPS_VERSION(1, 0); + ret->funcs = &parser_ps_1_0123; + gen_oldps_input(ret->shader, 4); +} + +void create_ps11_parser(struct asm_parser *ret) { + TRACE_(parsed_shader)("ps_1_1\n"); + + ret->shader = d3dcompiler_alloc(sizeof(*ret->shader)); + if(!ret->shader) { + ERR("Failed to allocate memory for the shader\n"); + set_parse_status(&ret->status, PARSE_ERR); + return; + } + + ret->shader->type = ST_PIXEL; + ret->shader->version = BWRITERPS_VERSION(1, 1); + ret->funcs = &parser_ps_1_0123; + gen_oldps_input(ret->shader, 4); +} + +void create_ps12_parser(struct asm_parser *ret) { + TRACE_(parsed_shader)("ps_1_2\n"); + + ret->shader = d3dcompiler_alloc(sizeof(*ret->shader)); + if(!ret->shader) { + ERR("Failed to allocate memory for the shader\n"); + set_parse_status(&ret->status, PARSE_ERR); + return; + } + + ret->shader->type = ST_PIXEL; + ret->shader->version = BWRITERPS_VERSION(1, 2); + ret->funcs = &parser_ps_1_0123; + gen_oldps_input(ret->shader, 4); +} + +void create_ps13_parser(struct asm_parser *ret) { + TRACE_(parsed_shader)("ps_1_3\n"); + + ret->shader = d3dcompiler_alloc(sizeof(*ret->shader)); + if(!ret->shader) { + ERR("Failed to allocate memory for the shader\n"); + set_parse_status(&ret->status, PARSE_ERR); + return; + } + + ret->shader->type = ST_PIXEL; + ret->shader->version = BWRITERPS_VERSION(1, 3); + ret->funcs = &parser_ps_1_0123; + gen_oldps_input(ret->shader, 4); +} + +void create_ps14_parser(struct asm_parser *ret) { + TRACE_(parsed_shader)("ps_1_4\n"); + + ret->shader = d3dcompiler_alloc(sizeof(*ret->shader)); + if(!ret->shader) { + ERR("Failed to allocate memory for the shader\n"); + set_parse_status(&ret->status, PARSE_ERR); + return; + } + + ret->shader->type = ST_PIXEL; + ret->shader->version = BWRITERPS_VERSION(1, 4); + ret->funcs = &parser_ps_1_4; + gen_oldps_input(ret->shader, 6); +} + +void create_ps20_parser(struct asm_parser *ret) { + TRACE_(parsed_shader)("ps_2_0\n"); + + ret->shader = d3dcompiler_alloc(sizeof(*ret->shader)); + if(!ret->shader) { + ERR("Failed to allocate memory for the shader\n"); + set_parse_status(&ret->status, PARSE_ERR); + return; + } + + ret->shader->type = ST_PIXEL; + ret->shader->version = BWRITERPS_VERSION(2, 0); + ret->funcs = &parser_ps_2; + gen_oldps_input(ret->shader, 8); +} + +void create_ps2x_parser(struct asm_parser *ret) { + TRACE_(parsed_shader)("ps_2_x\n"); + + ret->shader = d3dcompiler_alloc(sizeof(*ret->shader)); + if(!ret->shader) { + ERR("Failed to allocate memory for the shader\n"); + set_parse_status(&ret->status, PARSE_ERR); + return; + } + + ret->shader->type = ST_PIXEL; + ret->shader->version = BWRITERPS_VERSION(2, 1); + ret->funcs = &parser_ps_2_x; + gen_oldps_input(ret->shader, 8); +} + +void create_ps30_parser(struct asm_parser *ret) { + TRACE_(parsed_shader)("ps_3_0\n"); + + ret->shader = d3dcompiler_alloc(sizeof(*ret->shader)); + if(!ret->shader) { + ERR("Failed to allocate memory for the shader\n"); + set_parse_status(&ret->status, PARSE_ERR); + return; + } + + ret->shader->type = ST_PIXEL; + ret->shader->version = BWRITERPS_VERSION(3, 0); + ret->funcs = &parser_ps_3; +} diff --git a/reactos/dll/directx/wine/d3dcompiler_43/asmshader.l b/reactos/dll/directx/wine/d3dcompiler_43/asmshader.l new file mode 100644 index 00000000000..35a404817f5 --- /dev/null +++ b/reactos/dll/directx/wine/d3dcompiler_43/asmshader.l @@ -0,0 +1,501 @@ +/* + * Direct3D shader assembler + * + * Copyright 2008 Stefan Dösinger + * Copyright 2009 Matteo Bruni + * + * 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" + +#include "d3dcompiler_private.h" +#include "asmshader.tab.h" + +WINE_DEFAULT_DEBUG_CHANNEL(asmshader); +%} + +%option noyywrap +%option prefix="asmshader_" +%option noinput nounput never-interactive + +/* Swizzles and writemasks consist of a dot and up to 4 x, y, z or w characters, + * or up to 4 a, r, g, b characters. There are different rules for swizzles and + * writemasks wrt repetition, those are handled in the grammar. + */ +DOT \. +COMPONENT [xyzw]|[rgba] + +/* Registers */ +REG_TEMP r[0-9]+ +/* for relative addressing in the form o[x], v[x] and c[x] */ +REG_OUTPUT o[0-9]* +REG_INPUT v[0-9]* +REG_CONSTFLOAT c[0-9]* +REG_CONSTINT i[0-9]+ +REG_CONSTBOOL b[0-9]+ +REG_TEXTURE t[0-9]+ +REG_TEXCRDOUT oT[0-9]+ +REG_SAMPLER s[0-9]+ +REG_OPOS oPos +REG_OFOG oFog +REG_OPTS oPts +REG_VERTEXCOLOR oD[01] +REG_FRAGCOLOR oC[0-9]+ +REG_FRAGDEPTH oDepth +REG_VPOS vPos +REG_VFACE vFace +REG_ADDRESS a0 +REG_LOOP aL +REG_PREDICATE p0 +/* Not really a register, but it is considered as such */ +REG_LABEL l[0-9]+ + +DCL_POSITION _position[0-9]* +DCL_BLENDWEIGHT _blendweight[0-9]* +DCL_BLENDINDICES _blendindices[0-9]* +DCL_NORMAL _normal[0-9]* +DCL_PSIZE _psize[0-9]* +DCL_TEXCOORD _texcoord[0-9]* +DCL_TANGENT _tangent[0-9]* +DCL_BINORMAL _binormal[0-9]* +DCL_TESSFACTOR _tessfactor[0-9]* +DCL_POSITIONT _positiont[0-9]* +DCL_COLOR _color[0-9]* +DCL_FOG _fog[0-9]* +DCL_DEPTH _depth[0-9]* +DCL_SAMPLE _sample[0-9]* + +DCL_SAMPLER1D _1d +DCL_SAMPLER2D _2d +DCL_SAMPLERCUBE _cube +DCL_SAMPLERVOLUME _volume + +PREPROCESSORDIRECTIVE #[^\n]*\n + +/* Comments */ +DOUBLESLASHCOMMENT "//"[^\n]* +SEMICOLONCOMMENT ";"[^\n]* + +/* Whitespaces are spaces, tabs and newlines */ +WHITESPACE [ \t]+ +NEWLINE (\n)|(\r\n) + +COMMA "," + +IMMVAL \-?(([0-9]+\.?)|([0-9]*\.[0-9]+))(f)? + +ANY (.) + +%% + + /* Common instructions(vertex and pixel shaders) */ +add {return INSTR_ADD; } +nop {return INSTR_NOP; } +mov {return INSTR_MOV; } +sub {return INSTR_SUB; } +mad {return INSTR_MAD; } +mul {return INSTR_MUL; } +rcp {return INSTR_RCP; } +rsq {return INSTR_RSQ; } +dp3 {return INSTR_DP3; } +dp4 {return INSTR_DP4; } +min {return INSTR_MIN; } +max {return INSTR_MAX; } +slt {return INSTR_SLT; } +sge {return INSTR_SGE; } +abs {return INSTR_ABS; } +exp {return INSTR_EXP; } +log {return INSTR_LOG; } +expp {return INSTR_EXPP; } +logp {return INSTR_LOGP; } +dst {return INSTR_DST; } +lrp {return INSTR_LRP; } +frc {return INSTR_FRC; } +pow {return INSTR_POW; } +crs {return INSTR_CRS; } +sgn {return INSTR_SGN; } +nrm {return INSTR_NRM; } +sincos {return INSTR_SINCOS; } +m4x4 {return INSTR_M4x4; } +m4x3 {return INSTR_M4x3; } +m3x4 {return INSTR_M3x4; } +m3x3 {return INSTR_M3x3; } +m3x2 {return INSTR_M3x2; } +dcl {return INSTR_DCL; } +def {return INSTR_DEF; } +defb {return INSTR_DEFB; } +defi {return INSTR_DEFI; } +rep {return INSTR_REP; } +endrep {return INSTR_ENDREP; } +if {return INSTR_IF; } +else {return INSTR_ELSE; } +endif {return INSTR_ENDIF; } +break {return INSTR_BREAK; } +breakp {return INSTR_BREAKP; } +call {return INSTR_CALL; } +callnz {return INSTR_CALLNZ; } +loop {return INSTR_LOOP; } +ret {return INSTR_RET; } +endloop {return INSTR_ENDLOOP; } +label {return INSTR_LABEL; } +setp {return INSTR_SETP; } +texldl {return INSTR_TEXLDL; } + + /* Vertex shader only instructions */ +lit {return INSTR_LIT; } +mova {return INSTR_MOVA; } + + /* Pixel shader only instructions */ +cnd {return INSTR_CND; } +cmp {return INSTR_CMP; } +dp2add {return INSTR_DP2ADD; } +texcoord {return INSTR_TEXCOORD; } +texcrd {return INSTR_TEXCRD; } +texkill {return INSTR_TEXKILL; } +tex {return INSTR_TEX; } +texld {return INSTR_TEXLD; } +texbem {return INSTR_TEXBEM; } +texbeml {return INSTR_TEXBEML; } +texreg2ar {return INSTR_TEXREG2AR; } +texreg2gb {return INSTR_TEXREG2GB; } +texreg2rgb {return INSTR_TEXREG2RGB; } +texm3x2pad {return INSTR_TEXM3x2PAD; } +texm3x2tex {return INSTR_TEXM3x2TEX; } +texm3x3pad {return INSTR_TEXM3x3PAD; } +texm3x3spec {return INSTR_TEXM3x3SPEC; } +texm3x3vspec {return INSTR_TEXM3x3VSPEC; } +texm3x3tex {return INSTR_TEXM3x3TEX; } +texdp3tex {return INSTR_TEXDP3TEX; } +texm3x2depth {return INSTR_TEXM3x2DEPTH; } +texdp3 {return INSTR_TEXDP3; } +texm3x3 {return INSTR_TEXM3x3; } +texdepth {return INSTR_TEXDEPTH; } +bem {return INSTR_BEM; } +dsx {return INSTR_DSX; } +dsy {return INSTR_DSY; } +texldp {return INSTR_TEXLDP; } +texldb {return INSTR_TEXLDB; } +texldd {return INSTR_TEXLDD; } +phase {return INSTR_PHASE; } + +{REG_TEMP} { + asmshader_lval.regnum = atoi(yytext + 1); + return REG_TEMP; + } +{REG_OUTPUT} { + asmshader_lval.regnum = atoi(yytext + 1); + return REG_OUTPUT; + } +{REG_INPUT} { + asmshader_lval.regnum = atoi(yytext + 1); + return REG_INPUT; + } +{REG_CONSTFLOAT} { + asmshader_lval.regnum = atoi(yytext + 1); + return REG_CONSTFLOAT; + } +{REG_CONSTINT} { + asmshader_lval.regnum = atoi(yytext + 1); + return REG_CONSTINT; + } +{REG_CONSTBOOL} { + asmshader_lval.regnum = atoi(yytext + 1); + return REG_CONSTBOOL; + } +{REG_TEXTURE} { + asmshader_lval.regnum = atoi(yytext + 1); + return REG_TEXTURE; + } +{REG_TEXCRDOUT} { + asmshader_lval.regnum = atoi(yytext + 2); + return REG_TEXCRDOUT; + } +{REG_SAMPLER} { + asmshader_lval.regnum = atoi(yytext + 1); + return REG_SAMPLER; + } +{REG_OPOS} {return REG_OPOS; } +{REG_OFOG} {return REG_OFOG; } +{REG_OPTS} {return REG_OPTS; } +{REG_VERTEXCOLOR} { + asmshader_lval.regnum = atoi(yytext + 2); + return REG_VERTEXCOLOR; + } +{REG_FRAGCOLOR} { + asmshader_lval.regnum = atoi(yytext + 2); + return REG_FRAGCOLOR; + } +{REG_FRAGDEPTH} {return REG_FRAGDEPTH; } +{REG_VPOS} {return REG_VPOS; } +{REG_VFACE} {return REG_VFACE; } +{REG_ADDRESS} {return REG_ADDRESS; } +{REG_LOOP} {return REG_LOOP; } +{REG_PREDICATE} {return REG_PREDICATE; } + +{REG_LABEL} { + asmshader_lval.regnum = atoi(yytext + 1); + return REG_LABEL; + } + + /* Shader versions. These are important to select the correct + * parser profile. + */ +vs\.1\.0|vs_1_0 {return VER_VS10; } +vs\.1\.1|vs_1_1 {return VER_VS11; } + +vs\.2\.0|vs_2_0 {return VER_VS20; } +vs\.2\.x|vs_2_x {return VER_VS2X; } +vs\.3\.0|vs_3_0 {return VER_VS30; } + +ps\.1\.0|ps_1_0 {return VER_PS10; } +ps\.1\.1|ps_1_1 {return VER_PS11; } +ps\.1\.2|ps_1_2 {return VER_PS12; } +ps\.1\.3|ps_1_3 {return VER_PS13; } +ps\.1\.4|ps_1_4 {return VER_PS14; } + +ps\.2\.0|ps_2_0 {return VER_PS20; } +ps\.2\.x|ps_2_x {return VER_PS2X; } +ps\.3\.0|ps_3_0 {return VER_PS30; } + +{DOT} {return yytext[0]; } +{COMPONENT} { + switch(yytext[0]) { + case 'x': + case 'r': + asmshader_lval.component = 0; + break; + case 'y': + case 'g': + asmshader_lval.component = 1; + break; + case 'z': + case 'b': + asmshader_lval.component = 2; + break; + case 'w': + case 'a': + asmshader_lval.component = 3; + break; + } + return COMPONENT; + } + + /* Output modifiers */ +\_x2 {return SHIFT_X2; } +\_x4 {return SHIFT_X4; } +\_x8 {return SHIFT_X8; } +\_d2 {return SHIFT_D2; } +\_d4 {return SHIFT_D4; } +\_d8 {return SHIFT_D8; } +\_sat {return MOD_SAT; } +\_pp {return MOD_PP; } +\_centroid {return MOD_CENTROID; } + + /* compare params */ +\_gt {return COMP_GT; } +\_lt {return COMP_LT; } +\_ge {return COMP_GE; } +\_le {return COMP_LE; } +\_eq {return COMP_EQ; } +\_ne {return COMP_NE; } + +{IMMVAL} { + asmshader_lval.immval.val = atof(yytext); + asmshader_lval.immval.integer = ((strstr(yytext, ".") == NULL) && (strstr(yytext, "f") == NULL)); + return IMMVAL; + } +true { + asmshader_lval.immbool = TRUE; + return IMMBOOL; + } +false { + asmshader_lval.immbool = FALSE; + return IMMBOOL; + } + +{COMMA} {return yytext[0]; } +- {return yytext[0]; } +\( {return yytext[0]; } +\) {return yytext[0]; } + + /* for relative addressing */ +\[|\]|\+ {return yytext[0]; } + +\_bias {return SMOD_BIAS; } + /* No _x2 here; it is identical to MOD_X2 */ +\_bx2 {return SMOD_SCALEBIAS; } +\_dz {return SMOD_DZ; } +\_dw {return SMOD_DW; } +\_abs {return SMOD_ABS; } + +! {return SMOD_NOT; } + +{DCL_POSITION} { + if(yytext[strlen("_position")] == '\0') { + asmshader_lval.regnum = 0; + } else { + asmshader_lval.regnum = atoi(yytext + strlen("_position")); + } + return USAGE_POSITION; + } +{DCL_BLENDWEIGHT} { + if(yytext[strlen("_blendweight")] == '\0') { + asmshader_lval.regnum = 0; + } else { + asmshader_lval.regnum = atoi(yytext + strlen("_blendweight")); + } + return USAGE_BLENDWEIGHT; + } +{DCL_BLENDINDICES} { + if(yytext[strlen("_blendindices")] == '\0') { + asmshader_lval.regnum = 0; + } else { + asmshader_lval.regnum = atoi(yytext + strlen("_blendindices")); + } + return USAGE_BLENDINDICES; + } +{DCL_NORMAL} { + if(yytext[strlen("_normal")] == '\0') { + asmshader_lval.regnum = 0; + } else { + asmshader_lval.regnum = atoi(yytext + strlen("_normal")); + } + return USAGE_NORMAL; + } +{DCL_PSIZE} { + if(yytext[strlen("_psize")] == '\0') { + asmshader_lval.regnum = 0; + } else { + asmshader_lval.regnum = atoi(yytext + strlen("_psize")); + } + return USAGE_PSIZE; + } +{DCL_TEXCOORD} { + if(yytext[strlen("_texcoord")] == '\0') { + asmshader_lval.regnum = 0; + } else { + asmshader_lval.regnum = atoi(yytext + strlen("_texcoord")); + } + return USAGE_TEXCOORD; + } +{DCL_TANGENT} { + if(yytext[strlen("_tangent")] == '\0') { + asmshader_lval.regnum = 0; + } else { + asmshader_lval.regnum = atoi(yytext + strlen("_tangent")); + } + return USAGE_TANGENT; + } +{DCL_BINORMAL} { + if(yytext[strlen("_binormal")] == '\0') { + asmshader_lval.regnum = 0; + } else { + asmshader_lval.regnum = atoi(yytext + strlen("_binormal")); + } + return USAGE_BINORMAL; + } +{DCL_TESSFACTOR} { + if(yytext[strlen("_tessfactor")] == '\0') { + asmshader_lval.regnum = 0; + } else { + asmshader_lval.regnum = atoi(yytext + strlen("_tessfactor")); + } + return USAGE_TESSFACTOR; + } +{DCL_POSITIONT} { + if(yytext[strlen("_positiont")] == '\0') { + asmshader_lval.regnum = 0; + } else { + asmshader_lval.regnum = atoi(yytext + strlen("_positiont")); + } + return USAGE_POSITIONT; + } +{DCL_COLOR} { + if(yytext[strlen("_color")] == '\0') { + asmshader_lval.regnum = 0; + } else { + asmshader_lval.regnum = atoi(yytext + strlen("_color")); + } + return USAGE_COLOR; + } +{DCL_FOG} { + if(yytext[strlen("_fog")] == '\0') { + asmshader_lval.regnum = 0; + } else { + asmshader_lval.regnum = atoi(yytext + strlen("_fog")); + } + return USAGE_FOG; + } +{DCL_DEPTH} { + if(yytext[strlen("_depth")] == '\0') { + asmshader_lval.regnum = 0; + } else { + asmshader_lval.regnum = atoi(yytext + strlen("_depth")); + } + return USAGE_DEPTH; + } +{DCL_SAMPLE} { + if(yytext[strlen("_sample")] == '\0') { + asmshader_lval.regnum = 0; + } else { + asmshader_lval.regnum = atoi(yytext + strlen("_sample")); + } + return USAGE_SAMPLE; + } + +{DCL_SAMPLER1D} { return SAMPTYPE_1D; } +{DCL_SAMPLER2D} { return SAMPTYPE_2D; } +{DCL_SAMPLERCUBE} { return SAMPTYPE_CUBE; } +{DCL_SAMPLERVOLUME} { return SAMPTYPE_VOLUME; } + +{PREPROCESSORDIRECTIVE} { + /* TODO: update current line information */ + TRACE("line info update: %s", yytext); + } + + /* Skip comments */ +{DOUBLESLASHCOMMENT} { } +{SEMICOLONCOMMENT} { } + +{WHITESPACE} { /* Do nothing */ } +{NEWLINE} { + asm_ctx.line_no++; + } + +{ANY} { + asmparser_message(&asm_ctx, "Line %u: Unexpected input %s\n", asm_ctx.line_no, yytext); + set_parse_status(&asm_ctx.status, PARSE_ERR); + } + +%% + +struct bwriter_shader *SlAssembleShader(const char *text, char **messages) { + struct bwriter_shader *ret = NULL; + YY_BUFFER_STATE buffer; + TRACE("%p, %p\n", text, messages); + + buffer = asmshader__scan_string(text); + asmshader__switch_to_buffer(buffer); + + ret = parse_asm_shader(messages); + + asmshader__delete_buffer(buffer); + + return ret; +} diff --git a/reactos/dll/directx/wine/d3dcompiler_43/asmshader.tab.c b/reactos/dll/directx/wine/d3dcompiler_43/asmshader.tab.c new file mode 100644 index 00000000000..e5e0d3e577c --- /dev/null +++ b/reactos/dll/directx/wine/d3dcompiler_43/asmshader.tab.c @@ -0,0 +1,4886 @@ +/* A Bison parser, made by GNU Bison 2.5. */ + +/* Bison implementation for Yacc-like parsers in C + + Copyright (C) 1984, 1989-1990, 2000-2011 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* As a special exception, you may create a larger work that contains + part or all of the Bison parser skeleton and distribute that work + under terms of your choice, so long as that work isn't itself a + parser generator using the skeleton or a modified version thereof + as a parser skeleton. Alternatively, if you modify or redistribute + the parser skeleton itself, you may (at your option) remove this + special exception, which will cause the skeleton and the resulting + Bison output files to be licensed under the GNU General Public + License without this special exception. + + This special exception was added by the Free Software Foundation in + version 2.2 of Bison. */ + +/* C LALR(1) parser skeleton written by Richard Stallman, by + simplifying the original so-called "semantic" parser. */ + +/* All symbols defined below should begin with yy or YY, to avoid + infringing on user name space. This should be done even for local + variables, as they might otherwise be expanded by user macros. + There are some unavoidable exceptions within include files to + define necessary library symbols; they are noted "INFRINGES ON + USER NAME SPACE" below. */ + +/* Identify Bison output. */ +#define YYBISON 1 + +/* Bison version. */ +#define YYBISON_VERSION "2.5" + +/* Skeleton name. */ +#define YYSKELETON_NAME "yacc.c" + +/* Pure parsers. */ +#define YYPURE 0 + +/* Push parsers. */ +#define YYPUSH 0 + +/* Pull parsers. */ +#define YYPULL 1 + +/* Using locations. */ +#define YYLSP_NEEDED 0 + +/* Substitute the variable and function names. */ +#define yyparse asmshader_parse +#define yylex asmshader_lex +#define yyerror asmshader_error +#define yylval asmshader_lval +#define yychar asmshader_char +#define yydebug asmshader_debug +#define yynerrs asmshader_nerrs + + +/* Copy the first part of user declarations. */ + +/* Line 268 of yacc.c */ +#line 22 "asmshader.y" + +#include "config.h" +#include "wine/port.h" +#include "wine/debug.h" + +#include "d3dcompiler_private.h" + +WINE_DEFAULT_DEBUG_CHANNEL(asmshader); + +struct asm_parser asm_ctx; + +void asmparser_message(struct asm_parser *ctx, const char *fmt, ...) +{ + va_list args; + + va_start(args, fmt); + compilation_message(&ctx->messages, fmt, args); + va_end(args); +} + +static void asmshader_error(char const *s) { + asmparser_message(&asm_ctx, "Line %u: Error \"%s\" from bison\n", asm_ctx.line_no, s); + set_parse_status(&asm_ctx.status, PARSE_ERR); +} + +static void set_rel_reg(struct shader_reg *reg, struct rel_reg *rel) { + /* We can have an additional offset without true relative addressing + * ex. c2[ 4 ] */ + reg->regnum += rel->additional_offset; + if(!rel->has_rel_reg) { + reg->rel_reg = NULL; + } else { + reg->rel_reg = d3dcompiler_alloc(sizeof(*reg->rel_reg)); + if(!reg->rel_reg) { + return; + } + reg->rel_reg->type = rel->type; + reg->rel_reg->u.swizzle = rel->swizzle; + reg->rel_reg->regnum = rel->rel_regnum; + } +} + +/* Needed lexer functions declarations */ +int asmshader_lex(void); + + + + +/* Line 268 of yacc.c */ +#line 128 "asmshader.tab.c" + +/* Enabling traces. */ +#ifndef YYDEBUG +# define YYDEBUG 0 +#endif + +/* Enabling verbose error messages. */ +#ifdef YYERROR_VERBOSE +# undef YYERROR_VERBOSE +# define YYERROR_VERBOSE 1 +#else +# define YYERROR_VERBOSE 0 +#endif + +/* Enabling the token table. */ +#ifndef YYTOKEN_TABLE +# define YYTOKEN_TABLE 0 +#endif + + +/* Tokens. */ +#ifndef YYTOKENTYPE +# define YYTOKENTYPE + /* Put the tokens into the symbol table, so that GDB and other debuggers + know about them. */ + enum yytokentype { + INSTR_ADD = 258, + INSTR_NOP = 259, + INSTR_MOV = 260, + INSTR_SUB = 261, + INSTR_MAD = 262, + INSTR_MUL = 263, + INSTR_RCP = 264, + INSTR_RSQ = 265, + INSTR_DP3 = 266, + INSTR_DP4 = 267, + INSTR_MIN = 268, + INSTR_MAX = 269, + INSTR_SLT = 270, + INSTR_SGE = 271, + INSTR_ABS = 272, + INSTR_EXP = 273, + INSTR_LOG = 274, + INSTR_EXPP = 275, + INSTR_LOGP = 276, + INSTR_DST = 277, + INSTR_LRP = 278, + INSTR_FRC = 279, + INSTR_POW = 280, + INSTR_CRS = 281, + INSTR_SGN = 282, + INSTR_NRM = 283, + INSTR_SINCOS = 284, + INSTR_M4x4 = 285, + INSTR_M4x3 = 286, + INSTR_M3x4 = 287, + INSTR_M3x3 = 288, + INSTR_M3x2 = 289, + INSTR_DCL = 290, + INSTR_DEF = 291, + INSTR_DEFB = 292, + INSTR_DEFI = 293, + INSTR_REP = 294, + INSTR_ENDREP = 295, + INSTR_IF = 296, + INSTR_ELSE = 297, + INSTR_ENDIF = 298, + INSTR_BREAK = 299, + INSTR_BREAKP = 300, + INSTR_CALL = 301, + INSTR_CALLNZ = 302, + INSTR_LOOP = 303, + INSTR_RET = 304, + INSTR_ENDLOOP = 305, + INSTR_LABEL = 306, + INSTR_SETP = 307, + INSTR_TEXLDL = 308, + INSTR_LIT = 309, + INSTR_MOVA = 310, + INSTR_CND = 311, + INSTR_CMP = 312, + INSTR_DP2ADD = 313, + INSTR_TEXCOORD = 314, + INSTR_TEXCRD = 315, + INSTR_TEXKILL = 316, + INSTR_TEX = 317, + INSTR_TEXLD = 318, + INSTR_TEXBEM = 319, + INSTR_TEXBEML = 320, + INSTR_TEXREG2AR = 321, + INSTR_TEXREG2GB = 322, + INSTR_TEXREG2RGB = 323, + INSTR_TEXM3x2PAD = 324, + INSTR_TEXM3x2TEX = 325, + INSTR_TEXM3x3PAD = 326, + INSTR_TEXM3x3SPEC = 327, + INSTR_TEXM3x3VSPEC = 328, + INSTR_TEXM3x3TEX = 329, + INSTR_TEXDP3TEX = 330, + INSTR_TEXM3x2DEPTH = 331, + INSTR_TEXDP3 = 332, + INSTR_TEXM3x3 = 333, + INSTR_TEXDEPTH = 334, + INSTR_BEM = 335, + INSTR_DSX = 336, + INSTR_DSY = 337, + INSTR_TEXLDP = 338, + INSTR_TEXLDB = 339, + INSTR_TEXLDD = 340, + INSTR_PHASE = 341, + REG_TEMP = 342, + REG_OUTPUT = 343, + REG_INPUT = 344, + REG_CONSTFLOAT = 345, + REG_CONSTINT = 346, + REG_CONSTBOOL = 347, + REG_TEXTURE = 348, + REG_SAMPLER = 349, + REG_TEXCRDOUT = 350, + REG_OPOS = 351, + REG_OFOG = 352, + REG_OPTS = 353, + REG_VERTEXCOLOR = 354, + REG_FRAGCOLOR = 355, + REG_FRAGDEPTH = 356, + REG_VPOS = 357, + REG_VFACE = 358, + REG_ADDRESS = 359, + REG_LOOP = 360, + REG_PREDICATE = 361, + REG_LABEL = 362, + VER_VS10 = 363, + VER_VS11 = 364, + VER_VS20 = 365, + VER_VS2X = 366, + VER_VS30 = 367, + VER_PS10 = 368, + VER_PS11 = 369, + VER_PS12 = 370, + VER_PS13 = 371, + VER_PS14 = 372, + VER_PS20 = 373, + VER_PS2X = 374, + VER_PS30 = 375, + SHIFT_X2 = 376, + SHIFT_X4 = 377, + SHIFT_X8 = 378, + SHIFT_D2 = 379, + SHIFT_D4 = 380, + SHIFT_D8 = 381, + MOD_SAT = 382, + MOD_PP = 383, + MOD_CENTROID = 384, + COMP_GT = 385, + COMP_LT = 386, + COMP_GE = 387, + COMP_LE = 388, + COMP_EQ = 389, + COMP_NE = 390, + SMOD_BIAS = 391, + SMOD_SCALEBIAS = 392, + SMOD_DZ = 393, + SMOD_DW = 394, + SMOD_ABS = 395, + SMOD_NOT = 396, + SAMPTYPE_1D = 397, + SAMPTYPE_2D = 398, + SAMPTYPE_CUBE = 399, + SAMPTYPE_VOLUME = 400, + USAGE_POSITION = 401, + USAGE_BLENDWEIGHT = 402, + USAGE_BLENDINDICES = 403, + USAGE_NORMAL = 404, + USAGE_PSIZE = 405, + USAGE_TEXCOORD = 406, + USAGE_TANGENT = 407, + USAGE_BINORMAL = 408, + USAGE_TESSFACTOR = 409, + USAGE_POSITIONT = 410, + USAGE_COLOR = 411, + USAGE_FOG = 412, + USAGE_DEPTH = 413, + USAGE_SAMPLE = 414, + COMPONENT = 415, + IMMVAL = 416, + IMMBOOL = 417 + }; +#endif + + + +#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED +typedef union YYSTYPE +{ + +/* Line 293 of yacc.c */ +#line 70 "asmshader.y" + + struct { + float val; + BOOL integer; + } immval; + BOOL immbool; + unsigned int regnum; + struct shader_reg reg; + DWORD srcmod; + DWORD writemask; + struct { + DWORD writemask; + DWORD idx; + DWORD last; + } wm_components; + DWORD swizzle; + struct { + DWORD swizzle; + DWORD idx; + } sw_components; + DWORD component; + struct { + DWORD mod; + DWORD shift; + } modshift; + BWRITER_COMPARISON_TYPE comptype; + struct { + DWORD dclusage; + unsigned int regnum; + } declaration; + BWRITERSAMPLER_TEXTURE_TYPE samplertype; + struct rel_reg rel_reg; + struct src_regs sregs; + + + +/* Line 293 of yacc.c */ +#line 363 "asmshader.tab.c" +} YYSTYPE; +# define YYSTYPE_IS_TRIVIAL 1 +# define yystype YYSTYPE /* obsolescent; will be withdrawn */ +# define YYSTYPE_IS_DECLARED 1 +#endif + + +/* Copy the second part of user declarations. */ + + +/* Line 343 of yacc.c */ +#line 375 "asmshader.tab.c" + +#ifdef short +# undef short +#endif + +#ifdef YYTYPE_UINT8 +typedef YYTYPE_UINT8 yytype_uint8; +#else +typedef unsigned char yytype_uint8; +#endif + +#ifdef YYTYPE_INT8 +typedef YYTYPE_INT8 yytype_int8; +#elif (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +typedef signed char yytype_int8; +#else +typedef short int yytype_int8; +#endif + +#ifdef YYTYPE_UINT16 +typedef YYTYPE_UINT16 yytype_uint16; +#else +typedef unsigned short int yytype_uint16; +#endif + +#ifdef YYTYPE_INT16 +typedef YYTYPE_INT16 yytype_int16; +#else +typedef short int yytype_int16; +#endif + +#ifndef YYSIZE_T +# ifdef __SIZE_TYPE__ +# define YYSIZE_T __SIZE_TYPE__ +# elif defined size_t +# define YYSIZE_T size_t +# elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +# include /* INFRINGES ON USER NAME SPACE */ +# define YYSIZE_T size_t +# else +# define YYSIZE_T unsigned int +# endif +#endif + +#define YYSIZE_MAXIMUM ((YYSIZE_T) -1) + +#ifndef YY_ +# if defined YYENABLE_NLS && YYENABLE_NLS +# if ENABLE_NLS +# include /* INFRINGES ON USER NAME SPACE */ +# define YY_(msgid) dgettext ("bison-runtime", msgid) +# endif +# endif +# ifndef YY_ +# define YY_(msgid) msgid +# endif +#endif + +/* Suppress unused-variable warnings by "using" E. */ +#if ! defined lint || defined __GNUC__ +# define YYUSE(e) ((void) (e)) +#else +# define YYUSE(e) /* empty */ +#endif + +/* Identity function, used to suppress warnings about constant conditions. */ +#ifndef lint +# define YYID(n) (n) +#else +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static int +YYID (int yyi) +#else +static int +YYID (yyi) + int yyi; +#endif +{ + return yyi; +} +#endif + +#if ! defined yyoverflow || YYERROR_VERBOSE + +/* The parser invokes alloca or malloc; define the necessary symbols. */ + +# ifdef YYSTACK_USE_ALLOCA +# if YYSTACK_USE_ALLOCA +# ifdef __GNUC__ +# define YYSTACK_ALLOC __builtin_alloca +# elif defined __BUILTIN_VA_ARG_INCR +# include /* INFRINGES ON USER NAME SPACE */ +# elif defined _AIX +# define YYSTACK_ALLOC __alloca +# elif defined _MSC_VER +# include /* INFRINGES ON USER NAME SPACE */ +# define alloca _alloca +# else +# define YYSTACK_ALLOC alloca +# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +# include /* INFRINGES ON USER NAME SPACE */ +# ifndef EXIT_SUCCESS +# define EXIT_SUCCESS 0 +# endif +# endif +# endif +# endif +# endif + +# ifdef YYSTACK_ALLOC + /* Pacify GCC's `empty if-body' warning. */ +# define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0)) +# ifndef YYSTACK_ALLOC_MAXIMUM + /* The OS might guarantee only one guard page at the bottom of the stack, + and a page size can be as small as 4096 bytes. So we cannot safely + invoke alloca (N) if N exceeds 4096. Use a slightly smaller number + to allow for a few compiler-allocated temporary stack slots. */ +# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */ +# endif +# else +# define YYSTACK_ALLOC YYMALLOC +# define YYSTACK_FREE YYFREE +# ifndef YYSTACK_ALLOC_MAXIMUM +# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM +# endif +# if (defined __cplusplus && ! defined EXIT_SUCCESS \ + && ! ((defined YYMALLOC || defined malloc) \ + && (defined YYFREE || defined free))) +# include /* INFRINGES ON USER NAME SPACE */ +# ifndef EXIT_SUCCESS +# define EXIT_SUCCESS 0 +# endif +# endif +# ifndef YYMALLOC +# define YYMALLOC malloc +# if ! defined malloc && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ +# endif +# endif +# ifndef YYFREE +# define YYFREE free +# if ! defined free && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +void free (void *); /* INFRINGES ON USER NAME SPACE */ +# endif +# endif +# endif +#endif /* ! defined yyoverflow || YYERROR_VERBOSE */ + + +#if (! defined yyoverflow \ + && (! defined __cplusplus \ + || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) + +/* A type that is properly aligned for any stack member. */ +union yyalloc +{ + yytype_int16 yyss_alloc; + YYSTYPE yyvs_alloc; +}; + +/* The size of the maximum gap between one aligned stack and the next. */ +# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1) + +/* The size of an array large to enough to hold all stacks, each with + N elements. */ +# define YYSTACK_BYTES(N) \ + ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \ + + YYSTACK_GAP_MAXIMUM) + +# define YYCOPY_NEEDED 1 + +/* Relocate STACK from its old location to the new one. The + local variables YYSIZE and YYSTACKSIZE give the old and new number of + elements in the stack, and YYPTR gives the new location of the + stack. Advance YYPTR to a properly aligned location for the next + stack. */ +# define YYSTACK_RELOCATE(Stack_alloc, Stack) \ + do \ + { \ + YYSIZE_T yynewbytes; \ + YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \ + Stack = &yyptr->Stack_alloc; \ + yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \ + yyptr += yynewbytes / sizeof (*yyptr); \ + } \ + while (YYID (0)) + +#endif + +#if defined YYCOPY_NEEDED && YYCOPY_NEEDED +/* Copy COUNT objects from FROM to TO. The source and destination do + not overlap. */ +# ifndef YYCOPY +# if defined __GNUC__ && 1 < __GNUC__ +# define YYCOPY(To, From, Count) \ + __builtin_memcpy (To, From, (Count) * sizeof (*(From))) +# else +# define YYCOPY(To, From, Count) \ + do \ + { \ + YYSIZE_T yyi; \ + for (yyi = 0; yyi < (Count); yyi++) \ + (To)[yyi] = (From)[yyi]; \ + } \ + while (YYID (0)) +# endif +# endif +#endif /* !YYCOPY_NEEDED */ + +/* YYFINAL -- State number of the termination state. */ +#define YYFINAL 16 +/* YYLAST -- Last index in YYTABLE. */ +#define YYLAST 733 + +/* YYNTOKENS -- Number of terminals. */ +#define YYNTOKENS 171 +/* YYNNTS -- Number of nonterminals. */ +#define YYNNTS 26 +/* YYNRULES -- Number of rules. */ +#define YYNRULES 228 +/* YYNRULES -- Number of states. */ +#define YYNSTATES 552 + +/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ +#define YYUNDEFTOK 2 +#define YYMAXUTOK 417 + +#define YYTRANSLATE(YYX) \ + ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) + +/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */ +static const yytype_uint8 yytranslate[] = +{ + 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 169, 170, 2, 163, 164, 166, 165, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 167, 2, 168, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, + 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, + 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, + 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, + 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, + 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, + 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, + 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, + 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, + 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, + 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, + 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, + 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, + 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, + 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, + 155, 156, 157, 158, 159, 160, 161, 162 +}; + +#if YYDEBUG +/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in + YYRHS. */ +static const yytype_uint16 yyprhs[] = +{ + 0, 0, 3, 6, 8, 10, 12, 14, 16, 18, + 20, 22, 24, 26, 28, 30, 32, 33, 36, 38, + 41, 44, 50, 52, 58, 64, 70, 76, 82, 88, + 94, 100, 106, 112, 118, 124, 130, 136, 142, 148, + 154, 160, 166, 172, 178, 184, 190, 196, 202, 208, + 214, 220, 226, 232, 236, 241, 246, 252, 256, 261, + 266, 270, 275, 280, 291, 302, 307, 310, 312, 315, + 319, 321, 323, 325, 329, 332, 335, 338, 341, 343, + 345, 348, 354, 360, 366, 372, 378, 384, 390, 394, + 400, 403, 407, 411, 417, 423, 429, 435, 441, 447, + 453, 459, 465, 471, 477, 483, 489, 495, 501, 507, + 513, 519, 525, 531, 537, 543, 545, 548, 551, 553, + 555, 557, 559, 561, 563, 565, 567, 569, 571, 573, + 575, 577, 579, 581, 583, 585, 587, 589, 591, 594, + 596, 599, 600, 603, 605, 608, 609, 612, 614, 616, + 618, 620, 622, 624, 626, 628, 630, 632, 636, 640, + 645, 650, 656, 662, 669, 673, 674, 678, 683, 690, + 697, 706, 708, 712, 714, 716, 718, 720, 722, 724, + 726, 728, 730, 732, 734, 736, 738, 740, 742, 744, + 746, 748, 750, 752, 754, 756, 758, 760, 762, 764, + 766, 768, 770, 772, 774, 776, 778, 780, 782, 784, + 786, 788, 790, 792, 794, 796, 798, 800, 802, 804, + 806, 808, 810, 812, 814, 816, 818, 820, 825 +}; + +/* YYRHS -- A `-1'-separated list of the rules' RHS. */ +static const yytype_int16 yyrhs[] = +{ + 172, 0, -1, 173, 174, -1, 108, -1, 109, -1, + 110, -1, 111, -1, 112, -1, 113, -1, 114, -1, + 115, -1, 116, -1, 117, -1, 118, -1, 119, -1, + 120, -1, -1, 174, 175, -1, 176, -1, 196, 176, + -1, 163, 176, -1, 3, 183, 177, 164, 185, -1, + 4, -1, 5, 183, 177, 164, 185, -1, 6, 183, + 177, 164, 185, -1, 7, 183, 177, 164, 185, -1, + 8, 183, 177, 164, 185, -1, 9, 183, 177, 164, + 185, -1, 10, 183, 177, 164, 185, -1, 11, 183, + 177, 164, 185, -1, 12, 183, 177, 164, 185, -1, + 13, 183, 177, 164, 185, -1, 14, 183, 177, 164, + 185, -1, 15, 183, 177, 164, 185, -1, 16, 183, + 177, 164, 185, -1, 17, 183, 177, 164, 185, -1, + 18, 183, 177, 164, 185, -1, 19, 183, 177, 164, + 185, -1, 21, 183, 177, 164, 185, -1, 20, 183, + 177, 164, 185, -1, 22, 183, 177, 164, 185, -1, + 23, 183, 177, 164, 185, -1, 24, 183, 177, 164, + 185, -1, 25, 183, 177, 164, 185, -1, 26, 183, + 177, 164, 185, -1, 27, 183, 177, 164, 185, -1, + 28, 183, 177, 164, 185, -1, 29, 183, 177, 164, + 185, -1, 30, 183, 177, 164, 185, -1, 31, 183, + 177, 164, 185, -1, 32, 183, 177, 164, 185, -1, + 33, 183, 177, 164, 185, -1, 34, 183, 177, 164, + 185, -1, 35, 193, 88, -1, 35, 193, 88, 179, + -1, 35, 193, 183, 194, -1, 35, 193, 183, 194, + 179, -1, 35, 183, 194, -1, 35, 183, 194, 179, + -1, 35, 195, 183, 94, -1, 35, 183, 94, -1, + 35, 195, 183, 194, -1, 35, 195, 183, 88, -1, + 36, 90, 164, 161, 164, 161, 164, 161, 164, 161, + -1, 38, 91, 164, 161, 164, 161, 164, 161, 164, + 161, -1, 37, 92, 164, 162, -1, 39, 185, -1, + 40, -1, 41, 185, -1, 41, 192, 185, -1, 42, + -1, 43, -1, 44, -1, 44, 192, 185, -1, 45, + 185, -1, 46, 185, -1, 47, 185, -1, 48, 185, + -1, 49, -1, 50, -1, 51, 185, -1, 52, 192, + 177, 164, 185, -1, 53, 183, 177, 164, 185, -1, + 54, 183, 177, 164, 185, -1, 55, 183, 177, 164, + 185, -1, 56, 183, 177, 164, 185, -1, 57, 183, + 177, 164, 185, -1, 58, 183, 177, 164, 185, -1, + 59, 183, 177, -1, 60, 183, 177, 164, 185, -1, + 61, 177, -1, 62, 183, 177, -1, 79, 183, 177, + -1, 63, 183, 177, 164, 185, -1, 83, 183, 177, + 164, 185, -1, 84, 183, 177, 164, 185, -1, 64, + 183, 177, 164, 185, -1, 65, 183, 177, 164, 185, + -1, 66, 183, 177, 164, 185, -1, 67, 183, 177, + 164, 185, -1, 68, 183, 177, 164, 185, -1, 69, + 183, 177, 164, 185, -1, 71, 183, 177, 164, 185, + -1, 72, 183, 177, 164, 185, -1, 73, 183, 177, + 164, 185, -1, 74, 183, 177, 164, 185, -1, 75, + 183, 177, 164, 185, -1, 76, 183, 177, 164, 185, + -1, 70, 183, 177, 164, 185, -1, 77, 183, 177, + 164, 185, -1, 78, 183, 177, 164, 185, -1, 80, + 183, 177, 164, 185, -1, 81, 183, 177, 164, 185, + -1, 82, 183, 177, 164, 185, -1, 85, 183, 177, + 164, 185, -1, 86, -1, 178, 187, -1, 178, 179, + -1, 87, -1, 88, -1, 89, -1, 90, -1, 91, + -1, 92, -1, 93, -1, 95, -1, 94, -1, 96, + -1, 98, -1, 97, -1, 99, -1, 100, -1, 101, + -1, 106, -1, 102, -1, 103, -1, 104, -1, 105, + -1, 165, 180, -1, 160, -1, 180, 160, -1, -1, + 165, 182, -1, 160, -1, 182, 160, -1, -1, 183, + 184, -1, 121, -1, 122, -1, 123, -1, 124, -1, + 125, -1, 126, -1, 127, -1, 128, -1, 129, -1, + 186, -1, 185, 164, 186, -1, 191, 187, 181, -1, + 191, 187, 189, 181, -1, 166, 191, 187, 181, -1, + 166, 191, 187, 189, 181, -1, 161, 166, 191, 187, + 181, -1, 161, 166, 191, 187, 189, 181, -1, 141, + 191, 181, -1, -1, 167, 188, 168, -1, 167, 190, + 181, 168, -1, 167, 188, 163, 190, 181, 168, -1, + 167, 190, 181, 163, 188, 168, -1, 167, 188, 163, + 190, 181, 163, 188, 168, -1, 161, -1, 188, 163, + 161, -1, 136, -1, 121, -1, 137, -1, 138, -1, + 139, -1, 140, -1, 104, -1, 105, -1, 87, -1, + 88, -1, 89, -1, 90, -1, 91, -1, 92, -1, + 93, -1, 95, -1, 94, -1, 96, -1, 97, -1, + 99, -1, 100, -1, 101, -1, 106, -1, 102, -1, + 103, -1, 104, -1, 105, -1, 107, -1, 130, -1, + 131, -1, 132, -1, 133, -1, 134, -1, 135, -1, + 146, -1, 147, -1, 148, -1, 149, -1, 150, -1, + 151, -1, 152, -1, 153, -1, 154, -1, 155, -1, + 156, -1, 157, -1, 158, -1, 159, -1, 89, -1, + 93, -1, 142, -1, 143, -1, 144, -1, 145, -1, + 169, 106, 181, 170, -1, 169, 141, 106, 181, 170, + -1 +}; + +/* YYRLINE[YYN] -- source line where rule number YYN was defined. */ +static const yytype_uint16 yyrline[] = +{ + 0, 311, 311, 316, 321, 326, 331, 336, 341, 346, + 351, 356, 361, 366, 371, 376, 382, 383, 388, 392, + 397, 403, 408, 413, 418, 423, 428, 433, 438, 443, + 448, 453, 458, 463, 468, 473, 478, 483, 488, 493, + 498, 503, 508, 513, 518, 523, 528, 533, 538, 543, + 548, 553, 558, 563, 575, 587, 610, 633, 655, 677, + 687, 702, 709, 716, 720, 724, 728, 733, 738, 743, + 748, 753, 758, 763, 768, 773, 778, 783, 788, 793, + 798, 803, 808, 813, 818, 823, 828, 833, 838, 843, + 849, 854, 859, 864, 875, 880, 885, 890, 895, 900, + 905, 910, 915, 920, 925, 930, 935, 940, 945, 950, + 955, 960, 965, 970, 975, 980, 987, 995, 1004, 1008, + 1012, 1016, 1022, 1028, 1034, 1038, 1042, 1048, 1052, 1056, + 1060, 1064, 1068, 1072, 1076, 1082, 1088, 1093, 1100, 1115, + 1121, 1137, 1141, 1163, 1168, 1182, 1186, 1199, 1204, 1209, + 1214, 1219, 1224, 1229, 1234, 1239, 1245, 1250, 1261, 1269, + 1277, 1285, 1310, 1324, 1338, 1348, 1352, 1357, 1365, 1373, + 1381, 1390, 1399, 1409, 1413, 1417, 1421, 1425, 1429, 1434, + 1438, 1443, 1447, 1453, 1457, 1461, 1465, 1469, 1473, 1479, + 1483, 1489, 1495, 1501, 1507, 1513, 1517, 1521, 1525, 1529, + 1533, 1538, 1539, 1540, 1541, 1542, 1543, 1545, 1551, 1557, + 1563, 1569, 1575, 1581, 1587, 1593, 1599, 1605, 1611, 1617, + 1623, 1630, 1634, 1639, 1643, 1647, 1651, 1656, 1664 +}; +#endif + +#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE +/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. + First, the terminals, then, starting at YYNTOKENS, nonterminals. */ +static const char *const yytname[] = +{ + "$end", "error", "$undefined", "INSTR_ADD", "INSTR_NOP", "INSTR_MOV", + "INSTR_SUB", "INSTR_MAD", "INSTR_MUL", "INSTR_RCP", "INSTR_RSQ", + "INSTR_DP3", "INSTR_DP4", "INSTR_MIN", "INSTR_MAX", "INSTR_SLT", + "INSTR_SGE", "INSTR_ABS", "INSTR_EXP", "INSTR_LOG", "INSTR_EXPP", + "INSTR_LOGP", "INSTR_DST", "INSTR_LRP", "INSTR_FRC", "INSTR_POW", + "INSTR_CRS", "INSTR_SGN", "INSTR_NRM", "INSTR_SINCOS", "INSTR_M4x4", + "INSTR_M4x3", "INSTR_M3x4", "INSTR_M3x3", "INSTR_M3x2", "INSTR_DCL", + "INSTR_DEF", "INSTR_DEFB", "INSTR_DEFI", "INSTR_REP", "INSTR_ENDREP", + "INSTR_IF", "INSTR_ELSE", "INSTR_ENDIF", "INSTR_BREAK", "INSTR_BREAKP", + "INSTR_CALL", "INSTR_CALLNZ", "INSTR_LOOP", "INSTR_RET", "INSTR_ENDLOOP", + "INSTR_LABEL", "INSTR_SETP", "INSTR_TEXLDL", "INSTR_LIT", "INSTR_MOVA", + "INSTR_CND", "INSTR_CMP", "INSTR_DP2ADD", "INSTR_TEXCOORD", + "INSTR_TEXCRD", "INSTR_TEXKILL", "INSTR_TEX", "INSTR_TEXLD", + "INSTR_TEXBEM", "INSTR_TEXBEML", "INSTR_TEXREG2AR", "INSTR_TEXREG2GB", + "INSTR_TEXREG2RGB", "INSTR_TEXM3x2PAD", "INSTR_TEXM3x2TEX", + "INSTR_TEXM3x3PAD", "INSTR_TEXM3x3SPEC", "INSTR_TEXM3x3VSPEC", + "INSTR_TEXM3x3TEX", "INSTR_TEXDP3TEX", "INSTR_TEXM3x2DEPTH", + "INSTR_TEXDP3", "INSTR_TEXM3x3", "INSTR_TEXDEPTH", "INSTR_BEM", + "INSTR_DSX", "INSTR_DSY", "INSTR_TEXLDP", "INSTR_TEXLDB", "INSTR_TEXLDD", + "INSTR_PHASE", "REG_TEMP", "REG_OUTPUT", "REG_INPUT", "REG_CONSTFLOAT", + "REG_CONSTINT", "REG_CONSTBOOL", "REG_TEXTURE", "REG_SAMPLER", + "REG_TEXCRDOUT", "REG_OPOS", "REG_OFOG", "REG_OPTS", "REG_VERTEXCOLOR", + "REG_FRAGCOLOR", "REG_FRAGDEPTH", "REG_VPOS", "REG_VFACE", "REG_ADDRESS", + "REG_LOOP", "REG_PREDICATE", "REG_LABEL", "VER_VS10", "VER_VS11", + "VER_VS20", "VER_VS2X", "VER_VS30", "VER_PS10", "VER_PS11", "VER_PS12", + "VER_PS13", "VER_PS14", "VER_PS20", "VER_PS2X", "VER_PS30", "SHIFT_X2", + "SHIFT_X4", "SHIFT_X8", "SHIFT_D2", "SHIFT_D4", "SHIFT_D8", "MOD_SAT", + "MOD_PP", "MOD_CENTROID", "COMP_GT", "COMP_LT", "COMP_GE", "COMP_LE", + "COMP_EQ", "COMP_NE", "SMOD_BIAS", "SMOD_SCALEBIAS", "SMOD_DZ", + "SMOD_DW", "SMOD_ABS", "SMOD_NOT", "SAMPTYPE_1D", "SAMPTYPE_2D", + "SAMPTYPE_CUBE", "SAMPTYPE_VOLUME", "USAGE_POSITION", + "USAGE_BLENDWEIGHT", "USAGE_BLENDINDICES", "USAGE_NORMAL", "USAGE_PSIZE", + "USAGE_TEXCOORD", "USAGE_TANGENT", "USAGE_BINORMAL", "USAGE_TESSFACTOR", + "USAGE_POSITIONT", "USAGE_COLOR", "USAGE_FOG", "USAGE_DEPTH", + "USAGE_SAMPLE", "COMPONENT", "IMMVAL", "IMMBOOL", "'+'", "','", "'.'", + "'-'", "'['", "']'", "'('", "')'", "$accept", "shader", "version_marker", + "instructions", "complexinstr", "instruction", "dreg", "dreg_name", + "writemask", "wm_components", "swizzle", "sw_components", "omods", + "omodifier", "sregs", "sreg", "rel_reg", "immsum", "smod", "relreg_name", + "sreg_name", "comp", "dclusage", "dcl_inputreg", "sampdcl", "predicate", 0 +}; +#endif + +# ifdef YYPRINT +/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to + token YYLEX-NUM. */ +static const yytype_uint16 yytoknum[] = +{ + 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, + 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, + 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, + 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, + 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, + 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, + 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, + 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, + 335, 336, 337, 338, 339, 340, 341, 342, 343, 344, + 345, 346, 347, 348, 349, 350, 351, 352, 353, 354, + 355, 356, 357, 358, 359, 360, 361, 362, 363, 364, + 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, + 375, 376, 377, 378, 379, 380, 381, 382, 383, 384, + 385, 386, 387, 388, 389, 390, 391, 392, 393, 394, + 395, 396, 397, 398, 399, 400, 401, 402, 403, 404, + 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, + 415, 416, 417, 43, 44, 46, 45, 91, 93, 40, + 41 +}; +# endif + +/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ +static const yytype_uint8 yyr1[] = +{ + 0, 171, 172, 173, 173, 173, 173, 173, 173, 173, + 173, 173, 173, 173, 173, 173, 174, 174, 175, 175, + 175, 176, 176, 176, 176, 176, 176, 176, 176, 176, + 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, + 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, + 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, + 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, + 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, + 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, + 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, + 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, + 176, 176, 176, 176, 176, 176, 177, 177, 178, 178, + 178, 178, 178, 178, 178, 178, 178, 178, 178, 178, + 178, 178, 178, 178, 178, 178, 178, 178, 179, 180, + 180, 181, 181, 182, 182, 183, 183, 184, 184, 184, + 184, 184, 184, 184, 184, 184, 185, 185, 186, 186, + 186, 186, 186, 186, 186, 187, 187, 187, 187, 187, + 187, 188, 188, 189, 189, 189, 189, 189, 189, 190, + 190, 191, 191, 191, 191, 191, 191, 191, 191, 191, + 191, 191, 191, 191, 191, 191, 191, 191, 191, 191, + 191, 192, 192, 192, 192, 192, 192, 193, 193, 193, + 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, + 193, 194, 194, 195, 195, 195, 195, 196, 196 +}; + +/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ +static const yytype_uint8 yyr2[] = +{ + 0, 2, 2, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 0, 2, 1, 2, + 2, 5, 1, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 3, 4, 4, 5, 3, 4, 4, + 3, 4, 4, 10, 10, 4, 2, 1, 2, 3, + 1, 1, 1, 3, 2, 2, 2, 2, 1, 1, + 2, 5, 5, 5, 5, 5, 5, 5, 3, 5, + 2, 3, 3, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 1, 2, 2, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, + 2, 0, 2, 1, 2, 0, 2, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 3, 3, 4, + 4, 5, 5, 6, 3, 0, 3, 4, 6, 6, + 8, 1, 3, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 4, 5 +}; + +/* YYDEFACT[STATE-NAME] -- Default reduction number in state STATE-NUM. + Performed when YYTABLE doesn't specify something else to do. Zero + means the default is an error. */ +static const yytype_uint8 yydefact[] = +{ + 0, 3, 4, 5, 6, 7, 8, 9, 10, 11, + 12, 13, 14, 15, 0, 16, 1, 2, 145, 22, + 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, + 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, + 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, + 145, 0, 0, 0, 0, 67, 0, 70, 71, 72, + 0, 0, 0, 0, 78, 79, 0, 0, 145, 145, + 145, 145, 145, 145, 145, 145, 0, 145, 145, 145, + 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, + 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, + 145, 115, 0, 0, 17, 18, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 223, 224, + 225, 226, 207, 208, 209, 210, 211, 212, 213, 214, + 215, 216, 217, 218, 219, 220, 0, 145, 145, 0, + 0, 0, 181, 182, 183, 184, 185, 186, 187, 189, + 188, 190, 191, 192, 193, 194, 196, 197, 198, 199, + 195, 200, 0, 0, 0, 66, 156, 165, 201, 202, + 203, 204, 205, 206, 68, 0, 0, 74, 75, 76, + 77, 80, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 118, 119, 120, 121, 122, 123, 124, 126, 125, + 127, 129, 128, 130, 131, 132, 134, 135, 136, 137, + 133, 90, 165, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 20, 141, 0, + 19, 147, 148, 149, 150, 151, 152, 153, 154, 155, + 0, 146, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 221, 222, 60, 57, 53, 0, 0, 0, + 0, 0, 141, 0, 165, 0, 0, 141, 69, 73, + 0, 0, 0, 0, 0, 0, 0, 88, 0, 0, + 117, 116, 91, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 92, + 0, 0, 0, 0, 0, 0, 0, 0, 141, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 58, 54, 55, 62, 59, 61, 0, 65, 0, 164, + 165, 141, 157, 179, 180, 171, 0, 141, 174, 173, + 175, 176, 177, 178, 158, 141, 0, 0, 0, 0, + 0, 0, 0, 0, 139, 138, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 143, 142, + 227, 0, 21, 23, 24, 25, 26, 27, 28, 29, + 30, 31, 32, 33, 34, 35, 36, 37, 39, 38, + 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, + 50, 51, 52, 56, 0, 0, 141, 160, 141, 0, + 166, 0, 159, 81, 82, 83, 84, 85, 86, 87, + 89, 140, 93, 96, 97, 98, 99, 100, 101, 108, + 102, 103, 104, 105, 106, 107, 109, 110, 111, 112, + 113, 94, 95, 114, 144, 228, 0, 0, 162, 141, + 161, 172, 141, 0, 167, 0, 0, 163, 0, 0, + 0, 0, 0, 168, 0, 169, 0, 0, 0, 63, + 64, 170 +}; + +/* YYDEFGOTO[NTERM-NUM]. */ +static const yytype_int16 yydefgoto[] = +{ + -1, 14, 15, 17, 104, 105, 231, 232, 330, 425, + 357, 449, 107, 271, 185, 186, 317, 406, 415, 407, + 187, 195, 157, 305, 158, 106 +}; + +/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing + STATE-NUM. */ +#define YYPACT_NINF -458 +static const yytype_int16 yypact[] = +{ + 386, -458, -458, -458, -458, -458, -458, -458, -458, -458, + -458, -458, -458, -458, 11, -458, -458, 389, -458, -458, + -458, -458, -458, -458, -458, -458, -458, -458, -458, -458, + -458, -458, -458, -458, -458, -458, -458, -458, -458, -458, + -458, -458, -458, -458, -458, -458, -458, -458, -458, -458, + 334, -42, -28, -10, -34, -458, 95, -458, -458, 3, + -34, -34, -34, -34, -458, -458, -34, 3, -458, -458, + -458, -458, -458, -458, -458, -458, 247, -458, -458, -458, + -458, -458, -458, -458, -458, -458, -458, -458, -458, -458, + -458, -458, -458, -458, -458, -458, -458, -458, -458, -458, + -458, -458, 647, -55, -458, -458, 647, 505, 505, 505, + 505, 505, 505, 505, 505, 505, 505, 505, 505, 505, + 505, 505, 505, 505, 505, 505, 505, 505, 505, 505, + 505, 505, 505, 505, 505, 505, 505, 505, -458, -458, + -458, -458, -458, -458, -458, -458, -458, -458, -458, -458, + -458, -458, -458, -458, -458, -458, 123, 2, -458, -44, + -40, -39, -458, -458, -458, -458, -458, -458, -458, -458, + -458, -458, -458, -458, -458, -458, -458, -458, -458, -458, + -458, -458, 185, -45, 185, -38, -458, -37, -458, -458, + -458, -458, -458, -458, -38, -34, -34, -38, -38, -38, + -38, -38, 247, 505, 505, 505, 505, 505, 505, 505, + 505, -458, -458, -458, -458, -458, -458, -458, -458, -458, + -458, -458, -458, -458, -458, -458, -458, -458, -458, -458, + -458, -458, -76, 505, 505, 505, 505, 505, 505, 505, + 505, 505, 505, 505, 505, 505, 505, 505, 505, 505, + 505, 505, 505, 505, 505, 505, 505, -458, -57, 22, + -458, -458, -458, -458, -458, -458, -458, -458, -458, -458, + -35, -458, 1, 4, 8, 9, 10, 14, 16, 29, + 49, 50, 51, 54, 55, 57, 58, 60, 68, 69, + 70, 73, 74, 75, 76, 77, 78, 79, 89, 90, + 91, 93, -458, -458, -458, 94, 94, 142, 82, 5, + 96, 6, -57, 185, -37, -34, -58, -43, -38, -38, + 98, 119, 129, 130, 131, 132, 133, -458, 134, 100, + -458, -458, -458, 135, 136, 137, 138, 190, 191, 192, + 193, 194, 195, 204, 205, 343, 344, 345, 346, -458, + 378, 379, 380, 381, 382, 383, 388, 384, -57, -34, + -34, -34, -34, -34, -34, -34, -34, -34, -34, -34, + -34, -34, -34, -34, -34, -34, -34, -34, -34, -34, + -34, -34, -34, -34, -34, -34, -34, -34, -34, -34, + -458, -458, 94, -458, -458, -458, 385, -458, 387, -458, + -37, -43, -458, -458, -458, -458, -154, -57, -458, -458, + -458, -458, -458, -458, -458, -57, -34, -34, -34, -34, + -34, -34, -34, -34, -458, 390, -34, -34, -34, -34, + -34, -34, -34, -34, -34, -34, -34, -34, -34, -34, + -34, -34, -34, -34, -34, -34, -34, -34, -458, 393, + -458, 397, -38, -38, -38, -38, -38, -38, -38, -38, + -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, + -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, + -38, -38, -38, -458, 394, 395, -43, -458, -57, -30, + -458, -86, -458, -38, -38, -38, -38, -38, -38, -38, + -38, -458, -38, -38, -38, -38, -38, -38, -38, -38, + -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, + -38, -38, -38, -38, -458, -458, 448, 449, -458, -57, + -458, -458, -57, 396, -458, 453, 454, -458, -84, -63, + 452, 455, 396, -458, 456, -458, 457, 459, -59, -458, + -458, -458 +}; + +/* YYPGOTO[NTERM-NUM]. */ +static const yytype_int16 yypgoto[] = +{ + -458, -458, -458, -458, -458, 17, -92, -458, -293, -458, + -309, -458, 491, -458, -56, 306, -231, -457, -399, 146, + -132, 21, -458, -206, -458, -458 +}; + +/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If + positive, shift that token. If negative, reduce the rule which + number is the opposite. If YYTABLE_NINF, syntax error. */ +#define YYTABLE_NINF -1 +static const yytype_uint16 yytable[] = +{ + 194, 331, 488, 399, 197, 198, 199, 200, 414, 489, + 201, 16, 390, 391, 490, 270, 272, 273, 274, 275, + 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, + 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, + 296, 297, 298, 299, 300, 301, 403, 404, 159, 451, + 312, 258, 314, 162, 163, 164, 165, 166, 167, 168, + 169, 170, 171, 172, 160, 173, 174, 175, 176, 177, + 178, 179, 180, 181, 403, 404, 539, 533, 408, 542, + 196, 161, 534, 401, 543, 548, 259, 529, 202, 329, + 306, 316, 487, 409, 410, 411, 412, 413, 491, 483, + 544, 392, 395, 405, 544, 545, 492, 182, 356, 551, + 320, 321, 322, 323, 324, 325, 326, 327, 328, 257, + 309, 313, 356, 260, 310, 311, 315, 183, 358, 359, + 316, 531, 184, 188, 189, 190, 191, 192, 193, 318, + 319, 332, 333, 334, 335, 336, 337, 338, 339, 340, + 341, 342, 343, 344, 345, 346, 347, 348, 349, 350, + 351, 352, 353, 354, 355, 360, 396, 398, 361, 486, + 393, 302, 362, 363, 364, 303, 394, 528, 365, 530, + 366, 400, 162, 163, 164, 165, 166, 167, 168, 169, + 170, 171, 172, 367, 173, 174, 175, 176, 177, 178, + 179, 180, 181, 261, 262, 263, 264, 265, 266, 267, + 268, 269, 302, 368, 369, 370, 303, 304, 371, 372, + 537, 373, 374, 538, 375, 188, 189, 190, 191, 192, + 193, 302, 376, 377, 378, 303, 182, 379, 380, 381, + 382, 383, 384, 385, 261, 262, 263, 264, 265, 266, + 267, 268, 269, 386, 387, 388, 183, 389, 397, 329, + 424, 184, 416, 261, 262, 263, 264, 265, 266, 267, + 268, 269, 162, 163, 164, 165, 166, 167, 168, 169, + 170, 171, 172, 417, 173, 174, 175, 176, 177, 178, + 179, 180, 181, 418, 419, 420, 421, 422, 423, 426, + 427, 428, 429, 452, 453, 454, 455, 456, 457, 458, + 459, 460, 461, 462, 463, 464, 465, 466, 467, 468, + 469, 470, 471, 472, 473, 474, 475, 476, 477, 478, + 479, 480, 481, 482, 211, 212, 213, 214, 215, 216, + 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, + 227, 228, 229, 230, 430, 431, 432, 433, 434, 435, + 493, 494, 495, 496, 497, 498, 499, 500, 436, 437, + 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, + 512, 513, 514, 515, 516, 517, 518, 519, 520, 521, + 522, 523, 18, 19, 20, 21, 22, 23, 24, 25, + 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, + 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, + 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, + 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, + 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, + 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, + 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, + 96, 97, 98, 99, 100, 101, 138, 139, 140, 141, + 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, + 152, 153, 154, 155, 1, 2, 3, 4, 5, 6, + 7, 8, 9, 10, 11, 12, 13, 438, 439, 440, + 441, 108, 109, 110, 111, 112, 113, 114, 115, 116, + 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, + 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, + 137, 156, 442, 443, 444, 445, 446, 447, 448, 484, + 501, 485, 102, 524, 450, 526, 527, 405, 103, 203, + 204, 205, 206, 207, 208, 209, 210, 525, 233, 234, + 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, + 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, + 255, 256, 211, 212, 213, 214, 215, 216, 217, 218, + 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, + 229, 230, 535, 536, 540, 541, 546, 531, 549, 547, + 550, 402, 0, 0, 0, 0, 261, 262, 263, 264, + 265, 266, 267, 268, 269, 532, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 307, 308, + 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, + 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, + 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, + 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, + 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, + 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, + 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, + 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, + 98, 99, 100, 101 +}; + +#define yypact_value_is_default(yystate) \ + ((yystate) == (-458)) + +#define yytable_value_is_error(yytable_value) \ + YYID (0) + +static const yytype_int16 yycheck[] = +{ + 56, 232, 401, 312, 60, 61, 62, 63, 317, 163, + 66, 0, 305, 306, 168, 107, 108, 109, 110, 111, + 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, + 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, + 132, 133, 134, 135, 136, 137, 104, 105, 90, 358, + 182, 106, 184, 87, 88, 89, 90, 91, 92, 93, + 94, 95, 96, 97, 92, 99, 100, 101, 102, 103, + 104, 105, 106, 107, 104, 105, 533, 163, 121, 163, + 59, 91, 168, 314, 168, 542, 141, 486, 67, 165, + 88, 167, 401, 136, 137, 138, 139, 140, 407, 392, + 163, 307, 308, 161, 163, 168, 415, 141, 165, 168, + 202, 203, 204, 205, 206, 207, 208, 209, 210, 102, + 164, 166, 165, 106, 164, 164, 164, 161, 106, 164, + 167, 161, 166, 130, 131, 132, 133, 134, 135, 195, + 196, 233, 234, 235, 236, 237, 238, 239, 240, 241, + 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, + 252, 253, 254, 255, 256, 164, 161, 161, 164, 400, + 88, 89, 164, 164, 164, 93, 94, 486, 164, 488, + 164, 313, 87, 88, 89, 90, 91, 92, 93, 94, + 95, 96, 97, 164, 99, 100, 101, 102, 103, 104, + 105, 106, 107, 121, 122, 123, 124, 125, 126, 127, + 128, 129, 89, 164, 164, 164, 93, 94, 164, 164, + 529, 164, 164, 532, 164, 130, 131, 132, 133, 134, + 135, 89, 164, 164, 164, 93, 141, 164, 164, 164, + 164, 164, 164, 164, 121, 122, 123, 124, 125, 126, + 127, 128, 129, 164, 164, 164, 161, 164, 162, 165, + 160, 166, 164, 121, 122, 123, 124, 125, 126, 127, + 128, 129, 87, 88, 89, 90, 91, 92, 93, 94, + 95, 96, 97, 164, 99, 100, 101, 102, 103, 104, + 105, 106, 107, 164, 164, 164, 164, 164, 164, 164, + 164, 164, 164, 359, 360, 361, 362, 363, 364, 365, + 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, + 376, 377, 378, 379, 380, 381, 382, 383, 384, 385, + 386, 387, 388, 389, 87, 88, 89, 90, 91, 92, + 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, + 103, 104, 105, 106, 164, 164, 164, 164, 164, 164, + 416, 417, 418, 419, 420, 421, 422, 423, 164, 164, + 426, 427, 428, 429, 430, 431, 432, 433, 434, 435, + 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, + 446, 447, 3, 4, 5, 6, 7, 8, 9, 10, + 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, + 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, + 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, + 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, + 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, + 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, + 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, + 81, 82, 83, 84, 85, 86, 142, 143, 144, 145, + 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, + 156, 157, 158, 159, 108, 109, 110, 111, 112, 113, + 114, 115, 116, 117, 118, 119, 120, 164, 164, 164, + 164, 20, 21, 22, 23, 24, 25, 26, 27, 28, + 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, + 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, + 49, 50, 164, 164, 164, 164, 164, 164, 160, 164, + 160, 164, 163, 160, 170, 161, 161, 161, 169, 68, + 69, 70, 71, 72, 73, 74, 75, 170, 77, 78, + 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, + 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, + 99, 100, 87, 88, 89, 90, 91, 92, 93, 94, + 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, + 105, 106, 164, 164, 161, 161, 164, 161, 161, 164, + 161, 315, -1, -1, -1, -1, 121, 122, 123, 124, + 125, 126, 127, 128, 129, 489, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, 157, 158, + 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, + 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, + 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, + 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, + 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, + 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, + 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, + 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, + 83, 84, 85, 86 +}; + +/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing + symbol of state STATE-NUM. */ +static const yytype_uint8 yystos[] = +{ + 0, 108, 109, 110, 111, 112, 113, 114, 115, 116, + 117, 118, 119, 120, 172, 173, 0, 174, 3, 4, + 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, + 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, + 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, + 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, + 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, + 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, + 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, + 85, 86, 163, 169, 175, 176, 196, 183, 183, 183, + 183, 183, 183, 183, 183, 183, 183, 183, 183, 183, + 183, 183, 183, 183, 183, 183, 183, 183, 183, 183, + 183, 183, 183, 183, 183, 183, 183, 183, 142, 143, + 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, + 154, 155, 156, 157, 158, 159, 183, 193, 195, 90, + 92, 91, 87, 88, 89, 90, 91, 92, 93, 94, + 95, 96, 97, 99, 100, 101, 102, 103, 104, 105, + 106, 107, 141, 161, 166, 185, 186, 191, 130, 131, + 132, 133, 134, 135, 185, 192, 192, 185, 185, 185, + 185, 185, 192, 183, 183, 183, 183, 183, 183, 183, + 183, 87, 88, 89, 90, 91, 92, 93, 94, 95, + 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, + 106, 177, 178, 183, 183, 183, 183, 183, 183, 183, + 183, 183, 183, 183, 183, 183, 183, 183, 183, 183, + 183, 183, 183, 183, 183, 183, 183, 176, 106, 141, + 176, 121, 122, 123, 124, 125, 126, 127, 128, 129, + 177, 184, 177, 177, 177, 177, 177, 177, 177, 177, + 177, 177, 177, 177, 177, 177, 177, 177, 177, 177, + 177, 177, 177, 177, 177, 177, 177, 177, 177, 177, + 177, 177, 89, 93, 94, 194, 88, 183, 183, 164, + 164, 164, 191, 166, 191, 164, 167, 187, 185, 185, + 177, 177, 177, 177, 177, 177, 177, 177, 177, 165, + 179, 187, 177, 177, 177, 177, 177, 177, 177, 177, + 177, 177, 177, 177, 177, 177, 177, 177, 177, 177, + 177, 177, 177, 177, 177, 177, 165, 181, 106, 164, + 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, + 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, + 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, + 179, 179, 194, 88, 94, 194, 161, 162, 161, 181, + 191, 187, 186, 104, 105, 161, 188, 190, 121, 136, + 137, 138, 139, 140, 181, 189, 164, 164, 164, 164, + 164, 164, 164, 164, 160, 180, 164, 164, 164, 164, + 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, + 164, 164, 164, 164, 164, 164, 164, 164, 160, 182, + 170, 181, 185, 185, 185, 185, 185, 185, 185, 185, + 185, 185, 185, 185, 185, 185, 185, 185, 185, 185, + 185, 185, 185, 185, 185, 185, 185, 185, 185, 185, + 185, 185, 185, 179, 164, 164, 187, 181, 189, 163, + 168, 181, 181, 185, 185, 185, 185, 185, 185, 185, + 185, 160, 185, 185, 185, 185, 185, 185, 185, 185, + 185, 185, 185, 185, 185, 185, 185, 185, 185, 185, + 185, 185, 185, 185, 160, 170, 161, 161, 181, 189, + 181, 161, 190, 163, 168, 164, 164, 181, 181, 188, + 161, 161, 163, 168, 163, 168, 164, 164, 188, 161, + 161, 168 +}; + +#define yyerrok (yyerrstatus = 0) +#define yyclearin (yychar = YYEMPTY) +#define YYEMPTY (-2) +#define YYEOF 0 + +#define YYACCEPT goto yyacceptlab +#define YYABORT goto yyabortlab +#define YYERROR goto yyerrorlab + + +/* Like YYERROR except do call yyerror. This remains here temporarily + to ease the transition to the new meaning of YYERROR, for GCC. + Once GCC version 2 has supplanted version 1, this can go. However, + YYFAIL appears to be in use. Nevertheless, it is formally deprecated + in Bison 2.4.2's NEWS entry, where a plan to phase it out is + discussed. */ + +#define YYFAIL goto yyerrlab +#if defined YYFAIL + /* This is here to suppress warnings from the GCC cpp's + -Wunused-macros. Normally we don't worry about that warning, but + some users do, and we want to make it easy for users to remove + YYFAIL uses, which will produce warnings from Bison 2.5. */ +#endif + +#define YYRECOVERING() (!!yyerrstatus) + +#define YYBACKUP(Token, Value) \ +do \ + if (yychar == YYEMPTY && yylen == 1) \ + { \ + yychar = (Token); \ + yylval = (Value); \ + YYPOPSTACK (1); \ + goto yybackup; \ + } \ + else \ + { \ + yyerror (YY_("syntax error: cannot back up")); \ + YYERROR; \ + } \ +while (YYID (0)) + + +#define YYTERROR 1 +#define YYERRCODE 256 + + +/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. + If N is 0, then set CURRENT to the empty location which ends + the previous symbol: RHS[0] (always defined). */ + +#define YYRHSLOC(Rhs, K) ((Rhs)[K]) +#ifndef YYLLOC_DEFAULT +# define YYLLOC_DEFAULT(Current, Rhs, N) \ + do \ + if (YYID (N)) \ + { \ + (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \ + (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \ + (Current).last_line = YYRHSLOC (Rhs, N).last_line; \ + (Current).last_column = YYRHSLOC (Rhs, N).last_column; \ + } \ + else \ + { \ + (Current).first_line = (Current).last_line = \ + YYRHSLOC (Rhs, 0).last_line; \ + (Current).first_column = (Current).last_column = \ + YYRHSLOC (Rhs, 0).last_column; \ + } \ + while (YYID (0)) +#endif + + +/* This macro is provided for backward compatibility. */ + +#ifndef YY_LOCATION_PRINT +# define YY_LOCATION_PRINT(File, Loc) ((void) 0) +#endif + + +/* YYLEX -- calling `yylex' with the right arguments. */ + +#ifdef YYLEX_PARAM +# define YYLEX yylex (YYLEX_PARAM) +#else +# define YYLEX yylex () +#endif + +/* Enable debugging if requested. */ +#if YYDEBUG + +# ifndef YYFPRINTF +# include /* INFRINGES ON USER NAME SPACE */ +# define YYFPRINTF fprintf +# endif + +# define YYDPRINTF(Args) \ +do { \ + if (yydebug) \ + YYFPRINTF Args; \ +} while (YYID (0)) + +# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ +do { \ + if (yydebug) \ + { \ + YYFPRINTF (stderr, "%s ", Title); \ + yy_symbol_print (stderr, \ + Type, Value); \ + YYFPRINTF (stderr, "\n"); \ + } \ +} while (YYID (0)) + + +/*--------------------------------. +| Print this symbol on YYOUTPUT. | +`--------------------------------*/ + +/*ARGSUSED*/ +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static void +yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep) +#else +static void +yy_symbol_value_print (yyoutput, yytype, yyvaluep) + FILE *yyoutput; + int yytype; + YYSTYPE const * const yyvaluep; +#endif +{ + if (!yyvaluep) + return; +# ifdef YYPRINT + if (yytype < YYNTOKENS) + YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); +# else + YYUSE (yyoutput); +# endif + switch (yytype) + { + default: + break; + } +} + + +/*--------------------------------. +| Print this symbol on YYOUTPUT. | +`--------------------------------*/ + +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static void +yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep) +#else +static void +yy_symbol_print (yyoutput, yytype, yyvaluep) + FILE *yyoutput; + int yytype; + YYSTYPE const * const yyvaluep; +#endif +{ + if (yytype < YYNTOKENS) + YYFPRINTF (yyoutput, "token %s (", yytname[yytype]); + else + YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]); + + yy_symbol_value_print (yyoutput, yytype, yyvaluep); + YYFPRINTF (yyoutput, ")"); +} + +/*------------------------------------------------------------------. +| yy_stack_print -- Print the state stack from its BOTTOM up to its | +| TOP (included). | +`------------------------------------------------------------------*/ + +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static void +yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop) +#else +static void +yy_stack_print (yybottom, yytop) + yytype_int16 *yybottom; + yytype_int16 *yytop; +#endif +{ + YYFPRINTF (stderr, "Stack now"); + for (; yybottom <= yytop; yybottom++) + { + int yybot = *yybottom; + YYFPRINTF (stderr, " %d", yybot); + } + YYFPRINTF (stderr, "\n"); +} + +# define YY_STACK_PRINT(Bottom, Top) \ +do { \ + if (yydebug) \ + yy_stack_print ((Bottom), (Top)); \ +} while (YYID (0)) + + +/*------------------------------------------------. +| Report that the YYRULE is going to be reduced. | +`------------------------------------------------*/ + +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static void +yy_reduce_print (YYSTYPE *yyvsp, int yyrule) +#else +static void +yy_reduce_print (yyvsp, yyrule) + YYSTYPE *yyvsp; + int yyrule; +#endif +{ + int yynrhs = yyr2[yyrule]; + int yyi; + unsigned long int yylno = yyrline[yyrule]; + YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n", + yyrule - 1, yylno); + /* The symbols being reduced. */ + for (yyi = 0; yyi < yynrhs; yyi++) + { + YYFPRINTF (stderr, " $%d = ", yyi + 1); + yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi], + &(yyvsp[(yyi + 1) - (yynrhs)]) + ); + YYFPRINTF (stderr, "\n"); + } +} + +# define YY_REDUCE_PRINT(Rule) \ +do { \ + if (yydebug) \ + yy_reduce_print (yyvsp, Rule); \ +} while (YYID (0)) + +/* Nonzero means print parse trace. It is left uninitialized so that + multiple parsers can coexist. */ +int yydebug; +#else /* !YYDEBUG */ +# define YYDPRINTF(Args) +# define YY_SYMBOL_PRINT(Title, Type, Value, Location) +# define YY_STACK_PRINT(Bottom, Top) +# define YY_REDUCE_PRINT(Rule) +#endif /* !YYDEBUG */ + + +/* YYINITDEPTH -- initial size of the parser's stacks. */ +#ifndef YYINITDEPTH +# define YYINITDEPTH 200 +#endif + +/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only + if the built-in stack extension method is used). + + Do not make this value too large; the results are undefined if + YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH) + evaluated with infinite-precision integer arithmetic. */ + +#ifndef YYMAXDEPTH +# define YYMAXDEPTH 10000 +#endif + + +#if YYERROR_VERBOSE + +# ifndef yystrlen +# if defined __GLIBC__ && defined _STRING_H +# define yystrlen strlen +# else +/* Return the length of YYSTR. */ +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static YYSIZE_T +yystrlen (const char *yystr) +#else +static YYSIZE_T +yystrlen (yystr) + const char *yystr; +#endif +{ + YYSIZE_T yylen; + for (yylen = 0; yystr[yylen]; yylen++) + continue; + return yylen; +} +# endif +# endif + +# ifndef yystpcpy +# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE +# define yystpcpy stpcpy +# else +/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in + YYDEST. */ +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static char * +yystpcpy (char *yydest, const char *yysrc) +#else +static char * +yystpcpy (yydest, yysrc) + char *yydest; + const char *yysrc; +#endif +{ + char *yyd = yydest; + const char *yys = yysrc; + + while ((*yyd++ = *yys++) != '\0') + continue; + + return yyd - 1; +} +# endif +# endif + +# ifndef yytnamerr +/* Copy to YYRES the contents of YYSTR after stripping away unnecessary + quotes and backslashes, so that it's suitable for yyerror. The + heuristic is that double-quoting is unnecessary unless the string + contains an apostrophe, a comma, or backslash (other than + backslash-backslash). YYSTR is taken from yytname. If YYRES is + null, do not copy; instead, return the length of what the result + would have been. */ +static YYSIZE_T +yytnamerr (char *yyres, const char *yystr) +{ + if (*yystr == '"') + { + YYSIZE_T yyn = 0; + char const *yyp = yystr; + + for (;;) + switch (*++yyp) + { + case '\'': + case ',': + goto do_not_strip_quotes; + + case '\\': + if (*++yyp != '\\') + goto do_not_strip_quotes; + /* Fall through. */ + default: + if (yyres) + yyres[yyn] = *yyp; + yyn++; + break; + + case '"': + if (yyres) + yyres[yyn] = '\0'; + return yyn; + } + do_not_strip_quotes: ; + } + + if (! yyres) + return yystrlen (yystr); + + return yystpcpy (yyres, yystr) - yyres; +} +# endif + +/* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message + about the unexpected token YYTOKEN for the state stack whose top is + YYSSP. + + Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is + not large enough to hold the message. In that case, also set + *YYMSG_ALLOC to the required number of bytes. Return 2 if the + required number of bytes is too large to store. */ +static int +yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, + yytype_int16 *yyssp, int yytoken) +{ + YYSIZE_T yysize0 = yytnamerr (0, yytname[yytoken]); + YYSIZE_T yysize = yysize0; + YYSIZE_T yysize1; + enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; + /* Internationalized format string. */ + const char *yyformat = 0; + /* Arguments of yyformat. */ + char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; + /* Number of reported tokens (one for the "unexpected", one per + "expected"). */ + int yycount = 0; + + /* There are many possibilities here to consider: + - Assume YYFAIL is not used. It's too flawed to consider. See + + for details. YYERROR is fine as it does not invoke this + function. + - If this state is a consistent state with a default action, then + the only way this function was invoked is if the default action + is an error action. In that case, don't check for expected + tokens because there are none. + - The only way there can be no lookahead present (in yychar) is if + this state is a consistent state with a default action. Thus, + detecting the absence of a lookahead is sufficient to determine + that there is no unexpected or expected token to report. In that + case, just report a simple "syntax error". + - Don't assume there isn't a lookahead just because this state is a + consistent state with a default action. There might have been a + previous inconsistent state, consistent state with a non-default + action, or user semantic action that manipulated yychar. + - Of course, the expected token list depends on states to have + correct lookahead information, and it depends on the parser not + to perform extra reductions after fetching a lookahead from the + scanner and before detecting a syntax error. Thus, state merging + (from LALR or IELR) and default reductions corrupt the expected + token list. However, the list is correct for canonical LR with + one exception: it will still contain any token that will not be + accepted due to an error action in a later state. + */ + if (yytoken != YYEMPTY) + { + int yyn = yypact[*yyssp]; + yyarg[yycount++] = yytname[yytoken]; + if (!yypact_value_is_default (yyn)) + { + /* Start YYX at -YYN if negative to avoid negative indexes in + YYCHECK. In other words, skip the first -YYN actions for + this state because they are default actions. */ + int yyxbegin = yyn < 0 ? -yyn : 0; + /* Stay within bounds of both yycheck and yytname. */ + int yychecklim = YYLAST - yyn + 1; + int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; + int yyx; + + for (yyx = yyxbegin; yyx < yyxend; ++yyx) + if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR + && !yytable_value_is_error (yytable[yyx + yyn])) + { + if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) + { + yycount = 1; + yysize = yysize0; + break; + } + yyarg[yycount++] = yytname[yyx]; + yysize1 = yysize + yytnamerr (0, yytname[yyx]); + if (! (yysize <= yysize1 + && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) + return 2; + yysize = yysize1; + } + } + } + + switch (yycount) + { +# define YYCASE_(N, S) \ + case N: \ + yyformat = S; \ + break + YYCASE_(0, YY_("syntax error")); + YYCASE_(1, YY_("syntax error, unexpected %s")); + YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s")); + YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s")); + YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s")); + YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s")); +# undef YYCASE_ + } + + yysize1 = yysize + yystrlen (yyformat); + if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) + return 2; + yysize = yysize1; + + if (*yymsg_alloc < yysize) + { + *yymsg_alloc = 2 * yysize; + if (! (yysize <= *yymsg_alloc + && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM)) + *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM; + return 1; + } + + /* Avoid sprintf, as that infringes on the user's name space. + Don't have undefined behavior even if the translation + produced a string with the wrong number of "%s"s. */ + { + char *yyp = *yymsg; + int yyi = 0; + while ((*yyp = *yyformat) != '\0') + if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount) + { + yyp += yytnamerr (yyp, yyarg[yyi++]); + yyformat += 2; + } + else + { + yyp++; + yyformat++; + } + } + return 0; +} +#endif /* YYERROR_VERBOSE */ + +/*-----------------------------------------------. +| Release the memory associated to this symbol. | +`-----------------------------------------------*/ + +/*ARGSUSED*/ +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static void +yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep) +#else +static void +yydestruct (yymsg, yytype, yyvaluep) + const char *yymsg; + int yytype; + YYSTYPE *yyvaluep; +#endif +{ + YYUSE (yyvaluep); + + if (!yymsg) + yymsg = "Deleting"; + YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); + + switch (yytype) + { + + default: + break; + } +} + + +/* Prevent warnings from -Wmissing-prototypes. */ +#ifdef YYPARSE_PARAM +#if defined __STDC__ || defined __cplusplus +int yyparse (void *YYPARSE_PARAM); +#else +int yyparse (); +#endif +#else /* ! YYPARSE_PARAM */ +#if defined __STDC__ || defined __cplusplus +int yyparse (void); +#else +int yyparse (); +#endif +#endif /* ! YYPARSE_PARAM */ + + +/* The lookahead symbol. */ +int yychar; + +/* The semantic value of the lookahead symbol. */ +YYSTYPE yylval; + +/* Number of syntax errors so far. */ +int yynerrs; + + +/*----------. +| yyparse. | +`----------*/ + +#ifdef YYPARSE_PARAM +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +int +yyparse (void *YYPARSE_PARAM) +#else +int +yyparse (YYPARSE_PARAM) + void *YYPARSE_PARAM; +#endif +#else /* ! YYPARSE_PARAM */ +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +int +yyparse (void) +#else +int +yyparse () + +#endif +#endif +{ + int yystate; + /* Number of tokens to shift before error messages enabled. */ + int yyerrstatus; + + /* The stacks and their tools: + `yyss': related to states. + `yyvs': related to semantic values. + + Refer to the stacks thru separate pointers, to allow yyoverflow + to reallocate them elsewhere. */ + + /* The state stack. */ + yytype_int16 yyssa[YYINITDEPTH]; + yytype_int16 *yyss; + yytype_int16 *yyssp; + + /* The semantic value stack. */ + YYSTYPE yyvsa[YYINITDEPTH]; + YYSTYPE *yyvs; + YYSTYPE *yyvsp; + + YYSIZE_T yystacksize; + + int yyn; + int yyresult; + /* Lookahead token as an internal (translated) token number. */ + int yytoken; + /* The variables used to return semantic value and location from the + action routines. */ + YYSTYPE yyval; + +#if YYERROR_VERBOSE + /* Buffer for error messages, and its allocated size. */ + char yymsgbuf[128]; + char *yymsg = yymsgbuf; + YYSIZE_T yymsg_alloc = sizeof yymsgbuf; +#endif + +#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)) + + /* The number of symbols on the RHS of the reduced rule. + Keep to zero when no symbol should be popped. */ + int yylen = 0; + + yytoken = 0; + yyss = yyssa; + yyvs = yyvsa; + yystacksize = YYINITDEPTH; + + YYDPRINTF ((stderr, "Starting parse\n")); + + yystate = 0; + yyerrstatus = 0; + yynerrs = 0; + yychar = YYEMPTY; /* Cause a token to be read. */ + + /* Initialize stack pointers. + Waste one element of value and location stack + so that they stay on the same level as the state stack. + The wasted elements are never initialized. */ + yyssp = yyss; + yyvsp = yyvs; + + goto yysetstate; + +/*------------------------------------------------------------. +| yynewstate -- Push a new state, which is found in yystate. | +`------------------------------------------------------------*/ + yynewstate: + /* In all cases, when you get here, the value and location stacks + have just been pushed. So pushing a state here evens the stacks. */ + yyssp++; + + yysetstate: + *yyssp = yystate; + + if (yyss + yystacksize - 1 <= yyssp) + { + /* Get the current used size of the three stacks, in elements. */ + YYSIZE_T yysize = yyssp - yyss + 1; + +#ifdef yyoverflow + { + /* Give user a chance to reallocate the stack. Use copies of + these so that the &'s don't force the real ones into + memory. */ + YYSTYPE *yyvs1 = yyvs; + yytype_int16 *yyss1 = yyss; + + /* Each stack pointer address is followed by the size of the + data in use in that stack, in bytes. This used to be a + conditional around just the two extra args, but that might + be undefined if yyoverflow is a macro. */ + yyoverflow (YY_("memory exhausted"), + &yyss1, yysize * sizeof (*yyssp), + &yyvs1, yysize * sizeof (*yyvsp), + &yystacksize); + + yyss = yyss1; + yyvs = yyvs1; + } +#else /* no yyoverflow */ +# ifndef YYSTACK_RELOCATE + goto yyexhaustedlab; +# else + /* Extend the stack our own way. */ + if (YYMAXDEPTH <= yystacksize) + goto yyexhaustedlab; + yystacksize *= 2; + if (YYMAXDEPTH < yystacksize) + yystacksize = YYMAXDEPTH; + + { + yytype_int16 *yyss1 = yyss; + union yyalloc *yyptr = + (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); + if (! yyptr) + goto yyexhaustedlab; + YYSTACK_RELOCATE (yyss_alloc, yyss); + YYSTACK_RELOCATE (yyvs_alloc, yyvs); +# undef YYSTACK_RELOCATE + if (yyss1 != yyssa) + YYSTACK_FREE (yyss1); + } +# endif +#endif /* no yyoverflow */ + + yyssp = yyss + yysize - 1; + yyvsp = yyvs + yysize - 1; + + YYDPRINTF ((stderr, "Stack size increased to %lu\n", + (unsigned long int) yystacksize)); + + if (yyss + yystacksize - 1 <= yyssp) + YYABORT; + } + + YYDPRINTF ((stderr, "Entering state %d\n", yystate)); + + if (yystate == YYFINAL) + YYACCEPT; + + goto yybackup; + +/*-----------. +| yybackup. | +`-----------*/ +yybackup: + + /* Do appropriate processing given the current state. Read a + lookahead token if we need one and don't already have one. */ + + /* First try to decide what to do without reference to lookahead token. */ + yyn = yypact[yystate]; + if (yypact_value_is_default (yyn)) + goto yydefault; + + /* Not known => get a lookahead token if don't already have one. */ + + /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */ + if (yychar == YYEMPTY) + { + YYDPRINTF ((stderr, "Reading a token: ")); + yychar = YYLEX; + } + + if (yychar <= YYEOF) + { + yychar = yytoken = YYEOF; + YYDPRINTF ((stderr, "Now at end of input.\n")); + } + else + { + yytoken = YYTRANSLATE (yychar); + YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); + } + + /* If the proper action on seeing token YYTOKEN is to reduce or to + detect an error, take that action. */ + yyn += yytoken; + if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken) + goto yydefault; + yyn = yytable[yyn]; + if (yyn <= 0) + { + if (yytable_value_is_error (yyn)) + goto yyerrlab; + yyn = -yyn; + goto yyreduce; + } + + /* Count tokens shifted since error; after three, turn off error + status. */ + if (yyerrstatus) + yyerrstatus--; + + /* Shift the lookahead token. */ + YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); + + /* Discard the shifted token. */ + yychar = YYEMPTY; + + yystate = yyn; + *++yyvsp = yylval; + + goto yynewstate; + + +/*-----------------------------------------------------------. +| yydefault -- do the default action for the current state. | +`-----------------------------------------------------------*/ +yydefault: + yyn = yydefact[yystate]; + if (yyn == 0) + goto yyerrlab; + goto yyreduce; + + +/*-----------------------------. +| yyreduce -- Do a reduction. | +`-----------------------------*/ +yyreduce: + /* yyn is the number of a rule to reduce with. */ + yylen = yyr2[yyn]; + + /* If YYLEN is nonzero, implement the default value of the action: + `$$ = $1'. + + Otherwise, the following line sets YYVAL to garbage. + This behavior is undocumented and Bison + users should not rely upon it. Assigning to YYVAL + unconditionally makes the parser a bit smaller, and it avoids a + GCC warning that YYVAL may be used uninitialized. */ + yyval = yyvsp[1-yylen]; + + + YY_REDUCE_PRINT (yyn); + switch (yyn) + { + case 2: + +/* Line 1806 of yacc.c */ +#line 312 "asmshader.y" + { + asm_ctx.funcs->end(&asm_ctx); + } + break; + + case 3: + +/* Line 1806 of yacc.c */ +#line 317 "asmshader.y" + { + TRACE("Vertex shader 1.0\n"); + create_vs10_parser(&asm_ctx); + } + break; + + case 4: + +/* Line 1806 of yacc.c */ +#line 322 "asmshader.y" + { + TRACE("Vertex shader 1.1\n"); + create_vs11_parser(&asm_ctx); + } + break; + + case 5: + +/* Line 1806 of yacc.c */ +#line 327 "asmshader.y" + { + TRACE("Vertex shader 2.0\n"); + create_vs20_parser(&asm_ctx); + } + break; + + case 6: + +/* Line 1806 of yacc.c */ +#line 332 "asmshader.y" + { + TRACE("Vertex shader 2.x\n"); + create_vs2x_parser(&asm_ctx); + } + break; + + case 7: + +/* Line 1806 of yacc.c */ +#line 337 "asmshader.y" + { + TRACE("Vertex shader 3.0\n"); + create_vs30_parser(&asm_ctx); + } + break; + + case 8: + +/* Line 1806 of yacc.c */ +#line 342 "asmshader.y" + { + TRACE("Pixel shader 1.0\n"); + create_ps10_parser(&asm_ctx); + } + break; + + case 9: + +/* Line 1806 of yacc.c */ +#line 347 "asmshader.y" + { + TRACE("Pixel shader 1.1\n"); + create_ps11_parser(&asm_ctx); + } + break; + + case 10: + +/* Line 1806 of yacc.c */ +#line 352 "asmshader.y" + { + TRACE("Pixel shader 1.2\n"); + create_ps12_parser(&asm_ctx); + } + break; + + case 11: + +/* Line 1806 of yacc.c */ +#line 357 "asmshader.y" + { + TRACE("Pixel shader 1.3\n"); + create_ps13_parser(&asm_ctx); + } + break; + + case 12: + +/* Line 1806 of yacc.c */ +#line 362 "asmshader.y" + { + TRACE("Pixel shader 1.4\n"); + create_ps14_parser(&asm_ctx); + } + break; + + case 13: + +/* Line 1806 of yacc.c */ +#line 367 "asmshader.y" + { + TRACE("Pixel shader 2.0\n"); + create_ps20_parser(&asm_ctx); + } + break; + + case 14: + +/* Line 1806 of yacc.c */ +#line 372 "asmshader.y" + { + TRACE("Pixel shader 2.x\n"); + create_ps2x_parser(&asm_ctx); + } + break; + + case 15: + +/* Line 1806 of yacc.c */ +#line 377 "asmshader.y" + { + TRACE("Pixel shader 3.0\n"); + create_ps30_parser(&asm_ctx); + } + break; + + case 17: + +/* Line 1806 of yacc.c */ +#line 384 "asmshader.y" + { + /* Nothing to do */ + } + break; + + case 18: + +/* Line 1806 of yacc.c */ +#line 389 "asmshader.y" + { + + } + break; + + case 19: + +/* Line 1806 of yacc.c */ +#line 393 "asmshader.y" + { + TRACE("predicate\n"); + asm_ctx.funcs->predicate(&asm_ctx, &(yyvsp[(1) - (2)].reg)); + } + break; + + case 20: + +/* Line 1806 of yacc.c */ +#line 398 "asmshader.y" + { + TRACE("coissue\n"); + asm_ctx.funcs->coissue(&asm_ctx); + } + break; + + case 21: + +/* Line 1806 of yacc.c */ +#line 404 "asmshader.y" + { + TRACE("ADD\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_ADD, (yyvsp[(2) - (5)].modshift).mod, (yyvsp[(2) - (5)].modshift).shift, 0, &(yyvsp[(3) - (5)].reg), &(yyvsp[(5) - (5)].sregs), 2); + } + break; + + case 22: + +/* Line 1806 of yacc.c */ +#line 409 "asmshader.y" + { + TRACE("NOP\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_NOP, 0, 0, 0, 0, 0, 0); + } + break; + + case 23: + +/* Line 1806 of yacc.c */ +#line 414 "asmshader.y" + { + TRACE("MOV\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_MOV, (yyvsp[(2) - (5)].modshift).mod, (yyvsp[(2) - (5)].modshift).shift, 0, &(yyvsp[(3) - (5)].reg), &(yyvsp[(5) - (5)].sregs), 1); + } + break; + + case 24: + +/* Line 1806 of yacc.c */ +#line 419 "asmshader.y" + { + TRACE("SUB\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_SUB, (yyvsp[(2) - (5)].modshift).mod, (yyvsp[(2) - (5)].modshift).shift, 0, &(yyvsp[(3) - (5)].reg), &(yyvsp[(5) - (5)].sregs), 2); + } + break; + + case 25: + +/* Line 1806 of yacc.c */ +#line 424 "asmshader.y" + { + TRACE("MAD\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_MAD, (yyvsp[(2) - (5)].modshift).mod, (yyvsp[(2) - (5)].modshift).shift, 0, &(yyvsp[(3) - (5)].reg), &(yyvsp[(5) - (5)].sregs), 3); + } + break; + + case 26: + +/* Line 1806 of yacc.c */ +#line 429 "asmshader.y" + { + TRACE("MUL\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_MUL, (yyvsp[(2) - (5)].modshift).mod, (yyvsp[(2) - (5)].modshift).shift, 0, &(yyvsp[(3) - (5)].reg), &(yyvsp[(5) - (5)].sregs), 2); + } + break; + + case 27: + +/* Line 1806 of yacc.c */ +#line 434 "asmshader.y" + { + TRACE("RCP\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_RCP, (yyvsp[(2) - (5)].modshift).mod, (yyvsp[(2) - (5)].modshift).shift, 0, &(yyvsp[(3) - (5)].reg), &(yyvsp[(5) - (5)].sregs), 1); + } + break; + + case 28: + +/* Line 1806 of yacc.c */ +#line 439 "asmshader.y" + { + TRACE("RSQ\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_RSQ, (yyvsp[(2) - (5)].modshift).mod, (yyvsp[(2) - (5)].modshift).shift, 0, &(yyvsp[(3) - (5)].reg), &(yyvsp[(5) - (5)].sregs), 1); + } + break; + + case 29: + +/* Line 1806 of yacc.c */ +#line 444 "asmshader.y" + { + TRACE("DP3\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_DP3, (yyvsp[(2) - (5)].modshift).mod, (yyvsp[(2) - (5)].modshift).shift, 0, &(yyvsp[(3) - (5)].reg), &(yyvsp[(5) - (5)].sregs), 2); + } + break; + + case 30: + +/* Line 1806 of yacc.c */ +#line 449 "asmshader.y" + { + TRACE("DP4\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_DP4, (yyvsp[(2) - (5)].modshift).mod, (yyvsp[(2) - (5)].modshift).shift, 0, &(yyvsp[(3) - (5)].reg), &(yyvsp[(5) - (5)].sregs), 2); + } + break; + + case 31: + +/* Line 1806 of yacc.c */ +#line 454 "asmshader.y" + { + TRACE("MIN\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_MIN, (yyvsp[(2) - (5)].modshift).mod, (yyvsp[(2) - (5)].modshift).shift, 0, &(yyvsp[(3) - (5)].reg), &(yyvsp[(5) - (5)].sregs), 2); + } + break; + + case 32: + +/* Line 1806 of yacc.c */ +#line 459 "asmshader.y" + { + TRACE("MAX\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_MAX, (yyvsp[(2) - (5)].modshift).mod, (yyvsp[(2) - (5)].modshift).shift, 0, &(yyvsp[(3) - (5)].reg), &(yyvsp[(5) - (5)].sregs), 2); + } + break; + + case 33: + +/* Line 1806 of yacc.c */ +#line 464 "asmshader.y" + { + TRACE("SLT\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_SLT, (yyvsp[(2) - (5)].modshift).mod, (yyvsp[(2) - (5)].modshift).shift, 0, &(yyvsp[(3) - (5)].reg), &(yyvsp[(5) - (5)].sregs), 2); + } + break; + + case 34: + +/* Line 1806 of yacc.c */ +#line 469 "asmshader.y" + { + TRACE("SGE\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_SGE, (yyvsp[(2) - (5)].modshift).mod, (yyvsp[(2) - (5)].modshift).shift, 0, &(yyvsp[(3) - (5)].reg), &(yyvsp[(5) - (5)].sregs), 2); + } + break; + + case 35: + +/* Line 1806 of yacc.c */ +#line 474 "asmshader.y" + { + TRACE("ABS\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_ABS, (yyvsp[(2) - (5)].modshift).mod, (yyvsp[(2) - (5)].modshift).shift, 0, &(yyvsp[(3) - (5)].reg), &(yyvsp[(5) - (5)].sregs), 1); + } + break; + + case 36: + +/* Line 1806 of yacc.c */ +#line 479 "asmshader.y" + { + TRACE("EXP\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_EXP, (yyvsp[(2) - (5)].modshift).mod, (yyvsp[(2) - (5)].modshift).shift, 0, &(yyvsp[(3) - (5)].reg), &(yyvsp[(5) - (5)].sregs), 1); + } + break; + + case 37: + +/* Line 1806 of yacc.c */ +#line 484 "asmshader.y" + { + TRACE("LOG\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_LOG, (yyvsp[(2) - (5)].modshift).mod, (yyvsp[(2) - (5)].modshift).shift, 0, &(yyvsp[(3) - (5)].reg), &(yyvsp[(5) - (5)].sregs), 1); + } + break; + + case 38: + +/* Line 1806 of yacc.c */ +#line 489 "asmshader.y" + { + TRACE("LOGP\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_LOGP, (yyvsp[(2) - (5)].modshift).mod, (yyvsp[(2) - (5)].modshift).shift, 0, &(yyvsp[(3) - (5)].reg), &(yyvsp[(5) - (5)].sregs), 1); + } + break; + + case 39: + +/* Line 1806 of yacc.c */ +#line 494 "asmshader.y" + { + TRACE("EXPP\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_EXPP, (yyvsp[(2) - (5)].modshift).mod, (yyvsp[(2) - (5)].modshift).shift, 0, &(yyvsp[(3) - (5)].reg), &(yyvsp[(5) - (5)].sregs), 1); + } + break; + + case 40: + +/* Line 1806 of yacc.c */ +#line 499 "asmshader.y" + { + TRACE("DST\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_DST, (yyvsp[(2) - (5)].modshift).mod, (yyvsp[(2) - (5)].modshift).shift, 0, &(yyvsp[(3) - (5)].reg), &(yyvsp[(5) - (5)].sregs), 2); + } + break; + + case 41: + +/* Line 1806 of yacc.c */ +#line 504 "asmshader.y" + { + TRACE("LRP\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_LRP, (yyvsp[(2) - (5)].modshift).mod, (yyvsp[(2) - (5)].modshift).shift, 0, &(yyvsp[(3) - (5)].reg), &(yyvsp[(5) - (5)].sregs), 3); + } + break; + + case 42: + +/* Line 1806 of yacc.c */ +#line 509 "asmshader.y" + { + TRACE("FRC\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_FRC, (yyvsp[(2) - (5)].modshift).mod, (yyvsp[(2) - (5)].modshift).shift, 0, &(yyvsp[(3) - (5)].reg), &(yyvsp[(5) - (5)].sregs), 1); + } + break; + + case 43: + +/* Line 1806 of yacc.c */ +#line 514 "asmshader.y" + { + TRACE("POW\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_POW, (yyvsp[(2) - (5)].modshift).mod, (yyvsp[(2) - (5)].modshift).shift, 0, &(yyvsp[(3) - (5)].reg), &(yyvsp[(5) - (5)].sregs), 2); + } + break; + + case 44: + +/* Line 1806 of yacc.c */ +#line 519 "asmshader.y" + { + TRACE("CRS\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_CRS, (yyvsp[(2) - (5)].modshift).mod, (yyvsp[(2) - (5)].modshift).shift, 0, &(yyvsp[(3) - (5)].reg), &(yyvsp[(5) - (5)].sregs), 2); + } + break; + + case 45: + +/* Line 1806 of yacc.c */ +#line 524 "asmshader.y" + { + TRACE("SGN\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_SGN, (yyvsp[(2) - (5)].modshift).mod, (yyvsp[(2) - (5)].modshift).shift, 0, &(yyvsp[(3) - (5)].reg), &(yyvsp[(5) - (5)].sregs), 3); + } + break; + + case 46: + +/* Line 1806 of yacc.c */ +#line 529 "asmshader.y" + { + TRACE("NRM\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_NRM, (yyvsp[(2) - (5)].modshift).mod, (yyvsp[(2) - (5)].modshift).shift, 0, &(yyvsp[(3) - (5)].reg), &(yyvsp[(5) - (5)].sregs), 1); + } + break; + + case 47: + +/* Line 1806 of yacc.c */ +#line 534 "asmshader.y" + { + TRACE("SINCOS\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_SINCOS, (yyvsp[(2) - (5)].modshift).mod, (yyvsp[(2) - (5)].modshift).shift, 0, &(yyvsp[(3) - (5)].reg), &(yyvsp[(5) - (5)].sregs), 1); + } + break; + + case 48: + +/* Line 1806 of yacc.c */ +#line 539 "asmshader.y" + { + TRACE("M4x4\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_M4x4, (yyvsp[(2) - (5)].modshift).mod, (yyvsp[(2) - (5)].modshift).shift, 0, &(yyvsp[(3) - (5)].reg), &(yyvsp[(5) - (5)].sregs), 2); + } + break; + + case 49: + +/* Line 1806 of yacc.c */ +#line 544 "asmshader.y" + { + TRACE("M4x3\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_M4x3, (yyvsp[(2) - (5)].modshift).mod, (yyvsp[(2) - (5)].modshift).shift, 0, &(yyvsp[(3) - (5)].reg), &(yyvsp[(5) - (5)].sregs), 2); + } + break; + + case 50: + +/* Line 1806 of yacc.c */ +#line 549 "asmshader.y" + { + TRACE("M3x4\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_M3x4, (yyvsp[(2) - (5)].modshift).mod, (yyvsp[(2) - (5)].modshift).shift, 0, &(yyvsp[(3) - (5)].reg), &(yyvsp[(5) - (5)].sregs), 2); + } + break; + + case 51: + +/* Line 1806 of yacc.c */ +#line 554 "asmshader.y" + { + TRACE("M3x3\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_M3x3, (yyvsp[(2) - (5)].modshift).mod, (yyvsp[(2) - (5)].modshift).shift, 0, &(yyvsp[(3) - (5)].reg), &(yyvsp[(5) - (5)].sregs), 2); + } + break; + + case 52: + +/* Line 1806 of yacc.c */ +#line 559 "asmshader.y" + { + TRACE("M3x2\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_M3x2, (yyvsp[(2) - (5)].modshift).mod, (yyvsp[(2) - (5)].modshift).shift, 0, &(yyvsp[(3) - (5)].reg), &(yyvsp[(5) - (5)].sregs), 2); + } + break; + + case 53: + +/* Line 1806 of yacc.c */ +#line 564 "asmshader.y" + { + struct shader_reg reg; + TRACE("Output reg declaration\n"); + ZeroMemory(®, sizeof(reg)); + reg.type = BWRITERSPR_OUTPUT; + reg.regnum = (yyvsp[(3) - (3)].regnum); + reg.rel_reg = NULL; + reg.srcmod = 0; + reg.u.writemask = BWRITERSP_WRITEMASK_ALL; + asm_ctx.funcs->dcl_output(&asm_ctx, (yyvsp[(2) - (3)].declaration).dclusage, (yyvsp[(2) - (3)].declaration).regnum, ®); + } + break; + + case 54: + +/* Line 1806 of yacc.c */ +#line 576 "asmshader.y" + { + struct shader_reg reg; + TRACE("Output reg declaration\n"); + ZeroMemory(®, sizeof(reg)); + reg.type = BWRITERSPR_OUTPUT; + reg.regnum = (yyvsp[(3) - (4)].regnum); + reg.rel_reg = NULL; + reg.srcmod = 0; + reg.u.writemask = (yyvsp[(4) - (4)].writemask); + asm_ctx.funcs->dcl_output(&asm_ctx, (yyvsp[(2) - (4)].declaration).dclusage, (yyvsp[(2) - (4)].declaration).regnum, ®); + } + break; + + case 55: + +/* Line 1806 of yacc.c */ +#line 588 "asmshader.y" + { + struct shader_reg reg; + TRACE("Input reg declaration\n"); + if((yyvsp[(3) - (4)].modshift).shift != 0) { + asmparser_message(&asm_ctx, "Line %u: Shift modifier not allowed here\n", + asm_ctx.line_no); + set_parse_status(&asm_ctx.status, PARSE_ERR); + } + if(asm_ctx.shader->version == BWRITERPS_VERSION(2, 0) || + asm_ctx.shader->version == BWRITERPS_VERSION(2, 1)) { + asmparser_message(&asm_ctx, "Line %u: Declaration not supported in PS 2\n", + asm_ctx.line_no); + set_parse_status(&asm_ctx.status, PARSE_ERR); + } + ZeroMemory(®, sizeof(reg)); + reg.type = (yyvsp[(4) - (4)].reg).type; + reg.regnum = (yyvsp[(4) - (4)].reg).regnum; + reg.rel_reg = NULL; + reg.srcmod = 0; + reg.u.writemask = BWRITERSP_WRITEMASK_ALL; + asm_ctx.funcs->dcl_input(&asm_ctx, (yyvsp[(2) - (4)].declaration).dclusage, (yyvsp[(2) - (4)].declaration).regnum, (yyvsp[(3) - (4)].modshift).mod, ®); + } + break; + + case 56: + +/* Line 1806 of yacc.c */ +#line 611 "asmshader.y" + { + struct shader_reg reg; + TRACE("Input reg declaration\n"); + if((yyvsp[(3) - (5)].modshift).shift != 0) { + asmparser_message(&asm_ctx, "Line %u: Shift modifier not allowed here\n", + asm_ctx.line_no); + set_parse_status(&asm_ctx.status, PARSE_ERR); + } + if(asm_ctx.shader->version == BWRITERPS_VERSION(2, 0) || + asm_ctx.shader->version == BWRITERPS_VERSION(2, 1)) { + asmparser_message(&asm_ctx, "Line %u: Declaration not supported in PS 2\n", + asm_ctx.line_no); + set_parse_status(&asm_ctx.status, PARSE_ERR); + } + ZeroMemory(®, sizeof(reg)); + reg.type = (yyvsp[(4) - (5)].reg).type; + reg.regnum = (yyvsp[(4) - (5)].reg).regnum; + reg.rel_reg = NULL; + reg.srcmod = 0; + reg.u.writemask = (yyvsp[(5) - (5)].writemask); + asm_ctx.funcs->dcl_input(&asm_ctx, (yyvsp[(2) - (5)].declaration).dclusage, (yyvsp[(2) - (5)].declaration).regnum, (yyvsp[(3) - (5)].modshift).mod, ®); + } + break; + + case 57: + +/* Line 1806 of yacc.c */ +#line 634 "asmshader.y" + { + struct shader_reg reg; + TRACE("Input reg declaration\n"); + if((yyvsp[(2) - (3)].modshift).shift != 0) { + asmparser_message(&asm_ctx, "Line %u: Shift modifier not allowed here\n", + asm_ctx.line_no); + set_parse_status(&asm_ctx.status, PARSE_ERR); + } + if(asm_ctx.shader->type != ST_PIXEL) { + asmparser_message(&asm_ctx, "Line %u: Declaration needs a semantic\n", + asm_ctx.line_no); + set_parse_status(&asm_ctx.status, PARSE_ERR); + } + ZeroMemory(®, sizeof(reg)); + reg.type = (yyvsp[(3) - (3)].reg).type; + reg.regnum = (yyvsp[(3) - (3)].reg).regnum; + reg.rel_reg = NULL; + reg.srcmod = 0; + reg.u.writemask = BWRITERSP_WRITEMASK_ALL; + asm_ctx.funcs->dcl_input(&asm_ctx, 0, 0, (yyvsp[(2) - (3)].modshift).mod, ®); + } + break; + + case 58: + +/* Line 1806 of yacc.c */ +#line 656 "asmshader.y" + { + struct shader_reg reg; + TRACE("Input reg declaration\n"); + if((yyvsp[(2) - (4)].modshift).shift != 0) { + asmparser_message(&asm_ctx, "Line %u: Shift modifier not allowed here\n", + asm_ctx.line_no); + set_parse_status(&asm_ctx.status, PARSE_ERR); + } + if(asm_ctx.shader->type != ST_PIXEL) { + asmparser_message(&asm_ctx, "Line %u: Declaration needs a semantic\n", + asm_ctx.line_no); + set_parse_status(&asm_ctx.status, PARSE_ERR); + } + ZeroMemory(®, sizeof(reg)); + reg.type = (yyvsp[(3) - (4)].reg).type; + reg.regnum = (yyvsp[(3) - (4)].reg).regnum; + reg.rel_reg = NULL; + reg.srcmod = 0; + reg.u.writemask = (yyvsp[(4) - (4)].writemask); + asm_ctx.funcs->dcl_input(&asm_ctx, 0, 0, (yyvsp[(2) - (4)].modshift).mod, ®); + } + break; + + case 59: + +/* Line 1806 of yacc.c */ +#line 678 "asmshader.y" + { + TRACE("Sampler declared\n"); + if((yyvsp[(3) - (4)].modshift).shift != 0) { + asmparser_message(&asm_ctx, "Line %u: Shift modifier not allowed here\n", + asm_ctx.line_no); + set_parse_status(&asm_ctx.status, PARSE_ERR); + } + asm_ctx.funcs->dcl_sampler(&asm_ctx, (yyvsp[(2) - (4)].samplertype), (yyvsp[(3) - (4)].modshift).mod, (yyvsp[(4) - (4)].regnum), asm_ctx.line_no); + } + break; + + case 60: + +/* Line 1806 of yacc.c */ +#line 688 "asmshader.y" + { + TRACE("Sampler declared\n"); + if((yyvsp[(2) - (3)].modshift).shift != 0) { + asmparser_message(&asm_ctx, "Line %u: Shift modifier not allowed here\n", + asm_ctx.line_no); + set_parse_status(&asm_ctx.status, PARSE_ERR); + } + if(asm_ctx.shader->type != ST_PIXEL) { + asmparser_message(&asm_ctx, "Line %u: Declaration needs a sampler type\n", + asm_ctx.line_no); + set_parse_status(&asm_ctx.status, PARSE_ERR); + } + asm_ctx.funcs->dcl_sampler(&asm_ctx, BWRITERSTT_UNKNOWN, (yyvsp[(2) - (3)].modshift).mod, (yyvsp[(3) - (3)].regnum), asm_ctx.line_no); + } + break; + + case 61: + +/* Line 1806 of yacc.c */ +#line 703 "asmshader.y" + { + TRACE("Error rule: sampler decl of input reg\n"); + asmparser_message(&asm_ctx, "Line %u: Sampler declarations of input regs is not valid\n", + asm_ctx.line_no); + set_parse_status(&asm_ctx.status, PARSE_WARN); + } + break; + + case 62: + +/* Line 1806 of yacc.c */ +#line 710 "asmshader.y" + { + TRACE("Error rule: sampler decl of output reg\n"); + asmparser_message(&asm_ctx, "Line %u: Sampler declarations of output regs is not valid\n", + asm_ctx.line_no); + set_parse_status(&asm_ctx.status, PARSE_WARN); + } + break; + + case 63: + +/* Line 1806 of yacc.c */ +#line 717 "asmshader.y" + { + asm_ctx.funcs->constF(&asm_ctx, (yyvsp[(2) - (10)].regnum), (yyvsp[(4) - (10)].immval).val, (yyvsp[(6) - (10)].immval).val, (yyvsp[(8) - (10)].immval).val, (yyvsp[(10) - (10)].immval).val); + } + break; + + case 64: + +/* Line 1806 of yacc.c */ +#line 721 "asmshader.y" + { + asm_ctx.funcs->constI(&asm_ctx, (yyvsp[(2) - (10)].regnum), (yyvsp[(4) - (10)].immval).val, (yyvsp[(6) - (10)].immval).val, (yyvsp[(8) - (10)].immval).val, (yyvsp[(10) - (10)].immval).val); + } + break; + + case 65: + +/* Line 1806 of yacc.c */ +#line 725 "asmshader.y" + { + asm_ctx.funcs->constB(&asm_ctx, (yyvsp[(2) - (4)].regnum), (yyvsp[(4) - (4)].immbool)); + } + break; + + case 66: + +/* Line 1806 of yacc.c */ +#line 729 "asmshader.y" + { + TRACE("REP\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_REP, 0, 0, 0, 0, &(yyvsp[(2) - (2)].sregs), 1); + } + break; + + case 67: + +/* Line 1806 of yacc.c */ +#line 734 "asmshader.y" + { + TRACE("ENDREP\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_ENDREP, 0, 0, 0, 0, 0, 0); + } + break; + + case 68: + +/* Line 1806 of yacc.c */ +#line 739 "asmshader.y" + { + TRACE("IF\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_IF, 0, 0, 0, 0, &(yyvsp[(2) - (2)].sregs), 1); + } + break; + + case 69: + +/* Line 1806 of yacc.c */ +#line 744 "asmshader.y" + { + TRACE("IFC\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_IFC, 0, 0, (yyvsp[(2) - (3)].comptype), 0, &(yyvsp[(3) - (3)].sregs), 2); + } + break; + + case 70: + +/* Line 1806 of yacc.c */ +#line 749 "asmshader.y" + { + TRACE("ELSE\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_ELSE, 0, 0, 0, 0, 0, 0); + } + break; + + case 71: + +/* Line 1806 of yacc.c */ +#line 754 "asmshader.y" + { + TRACE("ENDIF\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_ENDIF, 0, 0, 0, 0, 0, 0); + } + break; + + case 72: + +/* Line 1806 of yacc.c */ +#line 759 "asmshader.y" + { + TRACE("BREAK\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_BREAK, 0, 0, 0, 0, 0, 0); + } + break; + + case 73: + +/* Line 1806 of yacc.c */ +#line 764 "asmshader.y" + { + TRACE("BREAKC\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_BREAKC, 0, 0, (yyvsp[(2) - (3)].comptype), 0, &(yyvsp[(3) - (3)].sregs), 2); + } + break; + + case 74: + +/* Line 1806 of yacc.c */ +#line 769 "asmshader.y" + { + TRACE("BREAKP\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_BREAKP, 0, 0, 0, 0, &(yyvsp[(2) - (2)].sregs), 1); + } + break; + + case 75: + +/* Line 1806 of yacc.c */ +#line 774 "asmshader.y" + { + TRACE("CALL\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_CALL, 0, 0, 0, 0, &(yyvsp[(2) - (2)].sregs), 1); + } + break; + + case 76: + +/* Line 1806 of yacc.c */ +#line 779 "asmshader.y" + { + TRACE("CALLNZ\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_CALLNZ, 0, 0, 0, 0, &(yyvsp[(2) - (2)].sregs), 2); + } + break; + + case 77: + +/* Line 1806 of yacc.c */ +#line 784 "asmshader.y" + { + TRACE("LOOP\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_LOOP, 0, 0, 0, 0, &(yyvsp[(2) - (2)].sregs), 2); + } + break; + + case 78: + +/* Line 1806 of yacc.c */ +#line 789 "asmshader.y" + { + TRACE("RET\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_RET, 0, 0, 0, 0, 0, 0); + } + break; + + case 79: + +/* Line 1806 of yacc.c */ +#line 794 "asmshader.y" + { + TRACE("ENDLOOP\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_ENDLOOP, 0, 0, 0, 0, 0, 0); + } + break; + + case 80: + +/* Line 1806 of yacc.c */ +#line 799 "asmshader.y" + { + TRACE("LABEL\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_LABEL, 0, 0, 0, 0, &(yyvsp[(2) - (2)].sregs), 1); + } + break; + + case 81: + +/* Line 1806 of yacc.c */ +#line 804 "asmshader.y" + { + TRACE("SETP\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_SETP, 0, 0, (yyvsp[(2) - (5)].comptype), &(yyvsp[(3) - (5)].reg), &(yyvsp[(5) - (5)].sregs), 2); + } + break; + + case 82: + +/* Line 1806 of yacc.c */ +#line 809 "asmshader.y" + { + TRACE("TEXLDL\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXLDL, (yyvsp[(2) - (5)].modshift).mod, (yyvsp[(2) - (5)].modshift).shift, 0, &(yyvsp[(3) - (5)].reg), &(yyvsp[(5) - (5)].sregs), 2); + } + break; + + case 83: + +/* Line 1806 of yacc.c */ +#line 814 "asmshader.y" + { + TRACE("LIT\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_LIT, (yyvsp[(2) - (5)].modshift).mod, (yyvsp[(2) - (5)].modshift).shift, 0, &(yyvsp[(3) - (5)].reg), &(yyvsp[(5) - (5)].sregs), 1); + } + break; + + case 84: + +/* Line 1806 of yacc.c */ +#line 819 "asmshader.y" + { + TRACE("MOVA\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_MOVA, (yyvsp[(2) - (5)].modshift).mod, (yyvsp[(2) - (5)].modshift).shift, 0, &(yyvsp[(3) - (5)].reg), &(yyvsp[(5) - (5)].sregs), 1); + } + break; + + case 85: + +/* Line 1806 of yacc.c */ +#line 824 "asmshader.y" + { + TRACE("CND\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_CND, (yyvsp[(2) - (5)].modshift).mod, (yyvsp[(2) - (5)].modshift).shift, 0, &(yyvsp[(3) - (5)].reg), &(yyvsp[(5) - (5)].sregs), 3); + } + break; + + case 86: + +/* Line 1806 of yacc.c */ +#line 829 "asmshader.y" + { + TRACE("CMP\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_CMP, (yyvsp[(2) - (5)].modshift).mod, (yyvsp[(2) - (5)].modshift).shift, 0, &(yyvsp[(3) - (5)].reg), &(yyvsp[(5) - (5)].sregs), 3); + } + break; + + case 87: + +/* Line 1806 of yacc.c */ +#line 834 "asmshader.y" + { + TRACE("DP2ADD\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_DP2ADD, (yyvsp[(2) - (5)].modshift).mod, (yyvsp[(2) - (5)].modshift).shift, 0, &(yyvsp[(3) - (5)].reg), &(yyvsp[(5) - (5)].sregs), 3); + } + break; + + case 88: + +/* Line 1806 of yacc.c */ +#line 839 "asmshader.y" + { + TRACE("TEXCOORD\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXCOORD, (yyvsp[(2) - (3)].modshift).mod, (yyvsp[(2) - (3)].modshift).shift, 0, &(yyvsp[(3) - (3)].reg), 0, 0); + } + break; + + case 89: + +/* Line 1806 of yacc.c */ +#line 844 "asmshader.y" + { + TRACE("TEXCRD\n"); + /* texcoord and texcrd share the same opcode */ + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXCOORD, (yyvsp[(2) - (5)].modshift).mod, (yyvsp[(2) - (5)].modshift).shift, 0, &(yyvsp[(3) - (5)].reg), &(yyvsp[(5) - (5)].sregs), 1); + } + break; + + case 90: + +/* Line 1806 of yacc.c */ +#line 850 "asmshader.y" + { + TRACE("TEXKILL\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXKILL, 0, 0, 0, &(yyvsp[(2) - (2)].reg), 0, 0); + } + break; + + case 91: + +/* Line 1806 of yacc.c */ +#line 855 "asmshader.y" + { + TRACE("TEX\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEX, (yyvsp[(2) - (3)].modshift).mod, (yyvsp[(2) - (3)].modshift).shift, 0, &(yyvsp[(3) - (3)].reg), 0, 0); + } + break; + + case 92: + +/* Line 1806 of yacc.c */ +#line 860 "asmshader.y" + { + TRACE("TEXDEPTH\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXDEPTH, (yyvsp[(2) - (3)].modshift).mod, (yyvsp[(2) - (3)].modshift).shift, 0, &(yyvsp[(3) - (3)].reg), 0, 0); + } + break; + + case 93: + +/* Line 1806 of yacc.c */ +#line 865 "asmshader.y" + { + TRACE("TEXLD\n"); + /* There is more than one acceptable syntax for texld: + with 1 sreg (PS 1.4) or + with 2 sregs (PS 2.0+) + Moreover, texld shares the same opcode as the tex instruction, + so there are a total of 3 valid syntaxes + These variations are handled in asmparser.c */ + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEX, (yyvsp[(2) - (5)].modshift).mod, (yyvsp[(2) - (5)].modshift).shift, 0, &(yyvsp[(3) - (5)].reg), &(yyvsp[(5) - (5)].sregs), 2); + } + break; + + case 94: + +/* Line 1806 of yacc.c */ +#line 876 "asmshader.y" + { + TRACE("TEXLDP\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXLDP, (yyvsp[(2) - (5)].modshift).mod, (yyvsp[(2) - (5)].modshift).shift, 0, &(yyvsp[(3) - (5)].reg), &(yyvsp[(5) - (5)].sregs), 2); + } + break; + + case 95: + +/* Line 1806 of yacc.c */ +#line 881 "asmshader.y" + { + TRACE("TEXLDB\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXLDB, (yyvsp[(2) - (5)].modshift).mod, (yyvsp[(2) - (5)].modshift).shift, 0, &(yyvsp[(3) - (5)].reg), &(yyvsp[(5) - (5)].sregs), 2); + } + break; + + case 96: + +/* Line 1806 of yacc.c */ +#line 886 "asmshader.y" + { + TRACE("TEXBEM\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXBEM, (yyvsp[(2) - (5)].modshift).mod, (yyvsp[(2) - (5)].modshift).shift, 0, &(yyvsp[(3) - (5)].reg), &(yyvsp[(5) - (5)].sregs), 1); + } + break; + + case 97: + +/* Line 1806 of yacc.c */ +#line 891 "asmshader.y" + { + TRACE("TEXBEML\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXBEML, (yyvsp[(2) - (5)].modshift).mod, (yyvsp[(2) - (5)].modshift).shift, 0, &(yyvsp[(3) - (5)].reg), &(yyvsp[(5) - (5)].sregs), 1); + } + break; + + case 98: + +/* Line 1806 of yacc.c */ +#line 896 "asmshader.y" + { + TRACE("TEXREG2AR\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXREG2AR, (yyvsp[(2) - (5)].modshift).mod, (yyvsp[(2) - (5)].modshift).shift, 0, &(yyvsp[(3) - (5)].reg), &(yyvsp[(5) - (5)].sregs), 1); + } + break; + + case 99: + +/* Line 1806 of yacc.c */ +#line 901 "asmshader.y" + { + TRACE("TEXREG2GB\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXREG2GB, (yyvsp[(2) - (5)].modshift).mod, (yyvsp[(2) - (5)].modshift).shift, 0, &(yyvsp[(3) - (5)].reg), &(yyvsp[(5) - (5)].sregs), 1); + } + break; + + case 100: + +/* Line 1806 of yacc.c */ +#line 906 "asmshader.y" + { + TRACE("TEXREG2RGB\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXREG2RGB, (yyvsp[(2) - (5)].modshift).mod, (yyvsp[(2) - (5)].modshift).shift, 0, &(yyvsp[(3) - (5)].reg), &(yyvsp[(5) - (5)].sregs), 1); + } + break; + + case 101: + +/* Line 1806 of yacc.c */ +#line 911 "asmshader.y" + { + TRACE("TEXM3x2PAD\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXM3x2PAD, (yyvsp[(2) - (5)].modshift).mod, (yyvsp[(2) - (5)].modshift).shift, 0, &(yyvsp[(3) - (5)].reg), &(yyvsp[(5) - (5)].sregs), 1); + } + break; + + case 102: + +/* Line 1806 of yacc.c */ +#line 916 "asmshader.y" + { + TRACE("INSTR_TEXM3x3PAD\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXM3x3PAD, (yyvsp[(2) - (5)].modshift).mod, (yyvsp[(2) - (5)].modshift).shift, 0, &(yyvsp[(3) - (5)].reg), &(yyvsp[(5) - (5)].sregs), 1); + } + break; + + case 103: + +/* Line 1806 of yacc.c */ +#line 921 "asmshader.y" + { + TRACE("TEXM3x3SPEC\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXM3x3SPEC, (yyvsp[(2) - (5)].modshift).mod, (yyvsp[(2) - (5)].modshift).shift, 0, &(yyvsp[(3) - (5)].reg), &(yyvsp[(5) - (5)].sregs), 2); + } + break; + + case 104: + +/* Line 1806 of yacc.c */ +#line 926 "asmshader.y" + { + TRACE("TEXM3x3VSPEC\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXM3x3VSPEC, (yyvsp[(2) - (5)].modshift).mod, (yyvsp[(2) - (5)].modshift).shift, 0, &(yyvsp[(3) - (5)].reg), &(yyvsp[(5) - (5)].sregs), 1); + } + break; + + case 105: + +/* Line 1806 of yacc.c */ +#line 931 "asmshader.y" + { + TRACE("TEXM3x3TEX\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXM3x3TEX, (yyvsp[(2) - (5)].modshift).mod, (yyvsp[(2) - (5)].modshift).shift, 0, &(yyvsp[(3) - (5)].reg), &(yyvsp[(5) - (5)].sregs), 1); + } + break; + + case 106: + +/* Line 1806 of yacc.c */ +#line 936 "asmshader.y" + { + TRACE("TEXDP3TEX\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXDP3TEX, (yyvsp[(2) - (5)].modshift).mod, (yyvsp[(2) - (5)].modshift).shift, 0, &(yyvsp[(3) - (5)].reg), &(yyvsp[(5) - (5)].sregs), 1); + } + break; + + case 107: + +/* Line 1806 of yacc.c */ +#line 941 "asmshader.y" + { + TRACE("TEXM3x2DEPTH\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXM3x2DEPTH, (yyvsp[(2) - (5)].modshift).mod, (yyvsp[(2) - (5)].modshift).shift, 0, &(yyvsp[(3) - (5)].reg), &(yyvsp[(5) - (5)].sregs), 1); + } + break; + + case 108: + +/* Line 1806 of yacc.c */ +#line 946 "asmshader.y" + { + TRACE("TEXM3x2TEX\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXM3x2TEX, (yyvsp[(2) - (5)].modshift).mod, (yyvsp[(2) - (5)].modshift).shift, 0, &(yyvsp[(3) - (5)].reg), &(yyvsp[(5) - (5)].sregs), 1); + } + break; + + case 109: + +/* Line 1806 of yacc.c */ +#line 951 "asmshader.y" + { + TRACE("TEXDP3\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXDP3, (yyvsp[(2) - (5)].modshift).mod, (yyvsp[(2) - (5)].modshift).shift, 0, &(yyvsp[(3) - (5)].reg), &(yyvsp[(5) - (5)].sregs), 1); + } + break; + + case 110: + +/* Line 1806 of yacc.c */ +#line 956 "asmshader.y" + { + TRACE("TEXM3x3\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXM3x3, (yyvsp[(2) - (5)].modshift).mod, (yyvsp[(2) - (5)].modshift).shift, 0, &(yyvsp[(3) - (5)].reg), &(yyvsp[(5) - (5)].sregs), 1); + } + break; + + case 111: + +/* Line 1806 of yacc.c */ +#line 961 "asmshader.y" + { + TRACE("BEM\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_BEM, (yyvsp[(2) - (5)].modshift).mod, (yyvsp[(2) - (5)].modshift).shift, 0, &(yyvsp[(3) - (5)].reg), &(yyvsp[(5) - (5)].sregs), 2); + } + break; + + case 112: + +/* Line 1806 of yacc.c */ +#line 966 "asmshader.y" + { + TRACE("DSX\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_DSX, (yyvsp[(2) - (5)].modshift).mod, (yyvsp[(2) - (5)].modshift).shift, 0, &(yyvsp[(3) - (5)].reg), &(yyvsp[(5) - (5)].sregs), 1); + } + break; + + case 113: + +/* Line 1806 of yacc.c */ +#line 971 "asmshader.y" + { + TRACE("DSY\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_DSY, (yyvsp[(2) - (5)].modshift).mod, (yyvsp[(2) - (5)].modshift).shift, 0, &(yyvsp[(3) - (5)].reg), &(yyvsp[(5) - (5)].sregs), 1); + } + break; + + case 114: + +/* Line 1806 of yacc.c */ +#line 976 "asmshader.y" + { + TRACE("TEXLDD\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXLDD, (yyvsp[(2) - (5)].modshift).mod, (yyvsp[(2) - (5)].modshift).shift, 0, &(yyvsp[(3) - (5)].reg), &(yyvsp[(5) - (5)].sregs), 4); + } + break; + + case 115: + +/* Line 1806 of yacc.c */ +#line 981 "asmshader.y" + { + TRACE("PHASE\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_PHASE, 0, 0, 0, 0, 0, 0); + } + break; + + case 116: + +/* Line 1806 of yacc.c */ +#line 988 "asmshader.y" + { + (yyval.reg).regnum = (yyvsp[(1) - (2)].reg).regnum; + (yyval.reg).type = (yyvsp[(1) - (2)].reg).type; + (yyval.reg).u.writemask = BWRITERSP_WRITEMASK_ALL; + (yyval.reg).srcmod = BWRITERSPSM_NONE; + set_rel_reg(&(yyval.reg), &(yyvsp[(2) - (2)].rel_reg)); + } + break; + + case 117: + +/* Line 1806 of yacc.c */ +#line 996 "asmshader.y" + { + (yyval.reg).regnum = (yyvsp[(1) - (2)].reg).regnum; + (yyval.reg).type = (yyvsp[(1) - (2)].reg).type; + (yyval.reg).u.writemask = (yyvsp[(2) - (2)].writemask); + (yyval.reg).srcmod = BWRITERSPSM_NONE; + (yyval.reg).rel_reg = NULL; + } + break; + + case 118: + +/* Line 1806 of yacc.c */ +#line 1005 "asmshader.y" + { + (yyval.reg).regnum = (yyvsp[(1) - (1)].regnum); (yyval.reg).type = BWRITERSPR_TEMP; + } + break; + + case 119: + +/* Line 1806 of yacc.c */ +#line 1009 "asmshader.y" + { + (yyval.reg).regnum = (yyvsp[(1) - (1)].regnum); (yyval.reg).type = BWRITERSPR_OUTPUT; + } + break; + + case 120: + +/* Line 1806 of yacc.c */ +#line 1013 "asmshader.y" + { + (yyval.reg).regnum = (yyvsp[(1) - (1)].regnum); (yyval.reg).type = BWRITERSPR_INPUT; + } + break; + + case 121: + +/* Line 1806 of yacc.c */ +#line 1017 "asmshader.y" + { + asmparser_message(&asm_ctx, "Line %u: Register c%u is not a valid destination register\n", + asm_ctx.line_no, (yyvsp[(1) - (1)].regnum)); + set_parse_status(&asm_ctx.status, PARSE_WARN); + } + break; + + case 122: + +/* Line 1806 of yacc.c */ +#line 1023 "asmshader.y" + { + asmparser_message(&asm_ctx, "Line %u: Register i%u is not a valid destination register\n", + asm_ctx.line_no, (yyvsp[(1) - (1)].regnum)); + set_parse_status(&asm_ctx.status, PARSE_WARN); + } + break; + + case 123: + +/* Line 1806 of yacc.c */ +#line 1029 "asmshader.y" + { + asmparser_message(&asm_ctx, "Line %u: Register b%u is not a valid destination register\n", + asm_ctx.line_no, (yyvsp[(1) - (1)].regnum)); + set_parse_status(&asm_ctx.status, PARSE_WARN); + } + break; + + case 124: + +/* Line 1806 of yacc.c */ +#line 1035 "asmshader.y" + { + (yyval.reg).regnum = (yyvsp[(1) - (1)].regnum); (yyval.reg).type = BWRITERSPR_TEXTURE; + } + break; + + case 125: + +/* Line 1806 of yacc.c */ +#line 1039 "asmshader.y" + { + (yyval.reg).regnum = (yyvsp[(1) - (1)].regnum); (yyval.reg).type = BWRITERSPR_TEXCRDOUT; + } + break; + + case 126: + +/* Line 1806 of yacc.c */ +#line 1043 "asmshader.y" + { + asmparser_message(&asm_ctx, "Line %u: Register s%u is not a valid destination register\n", + asm_ctx.line_no, (yyvsp[(1) - (1)].regnum)); + set_parse_status(&asm_ctx.status, PARSE_WARN); + } + break; + + case 127: + +/* Line 1806 of yacc.c */ +#line 1049 "asmshader.y" + { + (yyval.reg).regnum = BWRITERSRO_POSITION; (yyval.reg).type = BWRITERSPR_RASTOUT; + } + break; + + case 128: + +/* Line 1806 of yacc.c */ +#line 1053 "asmshader.y" + { + (yyval.reg).regnum = BWRITERSRO_POINT_SIZE; (yyval.reg).type = BWRITERSPR_RASTOUT; + } + break; + + case 129: + +/* Line 1806 of yacc.c */ +#line 1057 "asmshader.y" + { + (yyval.reg).regnum = BWRITERSRO_FOG; (yyval.reg).type = BWRITERSPR_RASTOUT; + } + break; + + case 130: + +/* Line 1806 of yacc.c */ +#line 1061 "asmshader.y" + { + (yyval.reg).regnum = (yyvsp[(1) - (1)].regnum); (yyval.reg).type = BWRITERSPR_ATTROUT; + } + break; + + case 131: + +/* Line 1806 of yacc.c */ +#line 1065 "asmshader.y" + { + (yyval.reg).regnum = (yyvsp[(1) - (1)].regnum); (yyval.reg).type = BWRITERSPR_COLOROUT; + } + break; + + case 132: + +/* Line 1806 of yacc.c */ +#line 1069 "asmshader.y" + { + (yyval.reg).regnum = 0; (yyval.reg).type = BWRITERSPR_DEPTHOUT; + } + break; + + case 133: + +/* Line 1806 of yacc.c */ +#line 1073 "asmshader.y" + { + (yyval.reg).regnum = 0; (yyval.reg).type = BWRITERSPR_PREDICATE; + } + break; + + case 134: + +/* Line 1806 of yacc.c */ +#line 1077 "asmshader.y" + { + asmparser_message(&asm_ctx, "Line %u: Register vPos is not a valid destination register\n", + asm_ctx.line_no); + set_parse_status(&asm_ctx.status, PARSE_WARN); + } + break; + + case 135: + +/* Line 1806 of yacc.c */ +#line 1083 "asmshader.y" + { + asmparser_message(&asm_ctx, "Line %u: Register vFace is not a valid destination register\n", + asm_ctx.line_no); + set_parse_status(&asm_ctx.status, PARSE_WARN); + } + break; + + case 136: + +/* Line 1806 of yacc.c */ +#line 1089 "asmshader.y" + { + /* index 0 is hardcoded for the addr register */ + (yyval.reg).regnum = 0; (yyval.reg).type = BWRITERSPR_ADDR; + } + break; + + case 137: + +/* Line 1806 of yacc.c */ +#line 1094 "asmshader.y" + { + asmparser_message(&asm_ctx, "Line %u: Register aL is not a valid destination register\n", + asm_ctx.line_no); + set_parse_status(&asm_ctx.status, PARSE_WARN); + } + break; + + case 138: + +/* Line 1806 of yacc.c */ +#line 1101 "asmshader.y" + { + if((yyvsp[(2) - (2)].wm_components).writemask == SWIZZLE_ERR) { + asmparser_message(&asm_ctx, "Line %u: Invalid writemask specified\n", + asm_ctx.line_no); + set_parse_status(&asm_ctx.status, PARSE_ERR); + /* Provide a correct writemask to prevent following complaints */ + (yyval.writemask) = BWRITERSP_WRITEMASK_ALL; + } + else { + (yyval.writemask) = (yyvsp[(2) - (2)].wm_components).writemask; + TRACE("Writemask: %x\n", (yyval.writemask)); + } + } + break; + + case 139: + +/* Line 1806 of yacc.c */ +#line 1116 "asmshader.y" + { + (yyval.wm_components).writemask = 1 << (yyvsp[(1) - (1)].component); + (yyval.wm_components).last = (yyvsp[(1) - (1)].component); + (yyval.wm_components).idx = 1; + } + break; + + case 140: + +/* Line 1806 of yacc.c */ +#line 1122 "asmshader.y" + { + if((yyvsp[(1) - (2)].wm_components).writemask == SWIZZLE_ERR || (yyvsp[(1) - (2)].wm_components).idx == 4) + /* Wrong writemask */ + (yyval.wm_components).writemask = SWIZZLE_ERR; + else { + if((yyvsp[(2) - (2)].component) <= (yyvsp[(1) - (2)].wm_components).last) + (yyval.wm_components).writemask = SWIZZLE_ERR; + else { + (yyval.wm_components).writemask = (yyvsp[(1) - (2)].wm_components).writemask | (1 << (yyvsp[(2) - (2)].component)); + (yyval.wm_components).idx = (yyvsp[(1) - (2)].wm_components).idx + 1; + } + } + } + break; + + case 141: + +/* Line 1806 of yacc.c */ +#line 1137 "asmshader.y" + { + (yyval.swizzle) = BWRITERVS_NOSWIZZLE; + TRACE("Default swizzle: %08x\n", (yyval.swizzle)); + } + break; + + case 142: + +/* Line 1806 of yacc.c */ +#line 1142 "asmshader.y" + { + if((yyvsp[(2) - (2)].sw_components).swizzle == SWIZZLE_ERR) { + asmparser_message(&asm_ctx, "Line %u: Invalid swizzle\n", + asm_ctx.line_no); + set_parse_status(&asm_ctx.status, PARSE_ERR); + /* Provide a correct swizzle to prevent following complaints */ + (yyval.swizzle) = BWRITERVS_NOSWIZZLE; + } + else { + DWORD last, i; + + (yyval.swizzle) = (yyvsp[(2) - (2)].sw_components).swizzle << BWRITERVS_SWIZZLE_SHIFT; + /* Fill the swizzle by extending the last component */ + last = ((yyvsp[(2) - (2)].sw_components).swizzle >> 2 * ((yyvsp[(2) - (2)].sw_components).idx - 1)) & 0x03; + for(i = (yyvsp[(2) - (2)].sw_components).idx; i < 4; i++){ + (yyval.swizzle) |= last << (BWRITERVS_SWIZZLE_SHIFT + 2 * i); + } + TRACE("Got a swizzle: %08x\n", (yyval.swizzle)); + } + } + break; + + case 143: + +/* Line 1806 of yacc.c */ +#line 1164 "asmshader.y" + { + (yyval.sw_components).swizzle = (yyvsp[(1) - (1)].component); + (yyval.sw_components).idx = 1; + } + break; + + case 144: + +/* Line 1806 of yacc.c */ +#line 1169 "asmshader.y" + { + if((yyvsp[(1) - (2)].sw_components).idx == 4) { + /* Too many sw_components */ + (yyval.sw_components).swizzle = SWIZZLE_ERR; + (yyval.sw_components).idx = 4; + } + else { + (yyval.sw_components).swizzle = (yyvsp[(1) - (2)].sw_components).swizzle | ((yyvsp[(2) - (2)].component) << 2 * (yyvsp[(1) - (2)].sw_components).idx); + (yyval.sw_components).idx = (yyvsp[(1) - (2)].sw_components).idx + 1; + } + } + break; + + case 145: + +/* Line 1806 of yacc.c */ +#line 1182 "asmshader.y" + { + (yyval.modshift).mod = 0; + (yyval.modshift).shift = 0; + } + break; + + case 146: + +/* Line 1806 of yacc.c */ +#line 1187 "asmshader.y" + { + (yyval.modshift).mod = (yyvsp[(1) - (2)].modshift).mod | (yyvsp[(2) - (2)].modshift).mod; + if((yyvsp[(1) - (2)].modshift).shift && (yyvsp[(2) - (2)].modshift).shift) { + asmparser_message(&asm_ctx, "Line %u: More than one shift flag\n", + asm_ctx.line_no); + set_parse_status(&asm_ctx.status, PARSE_ERR); + (yyval.modshift).shift = (yyvsp[(1) - (2)].modshift).shift; + } else { + (yyval.modshift).shift = (yyvsp[(1) - (2)].modshift).shift | (yyvsp[(2) - (2)].modshift).shift; + } + } + break; + + case 147: + +/* Line 1806 of yacc.c */ +#line 1200 "asmshader.y" + { + (yyval.modshift).mod = 0; + (yyval.modshift).shift = 1; + } + break; + + case 148: + +/* Line 1806 of yacc.c */ +#line 1205 "asmshader.y" + { + (yyval.modshift).mod = 0; + (yyval.modshift).shift = 2; + } + break; + + case 149: + +/* Line 1806 of yacc.c */ +#line 1210 "asmshader.y" + { + (yyval.modshift).mod = 0; + (yyval.modshift).shift = 3; + } + break; + + case 150: + +/* Line 1806 of yacc.c */ +#line 1215 "asmshader.y" + { + (yyval.modshift).mod = 0; + (yyval.modshift).shift = 15; + } + break; + + case 151: + +/* Line 1806 of yacc.c */ +#line 1220 "asmshader.y" + { + (yyval.modshift).mod = 0; + (yyval.modshift).shift = 14; + } + break; + + case 152: + +/* Line 1806 of yacc.c */ +#line 1225 "asmshader.y" + { + (yyval.modshift).mod = 0; + (yyval.modshift).shift = 13; + } + break; + + case 153: + +/* Line 1806 of yacc.c */ +#line 1230 "asmshader.y" + { + (yyval.modshift).mod = BWRITERSPDM_SATURATE; + (yyval.modshift).shift = 0; + } + break; + + case 154: + +/* Line 1806 of yacc.c */ +#line 1235 "asmshader.y" + { + (yyval.modshift).mod = BWRITERSPDM_PARTIALPRECISION; + (yyval.modshift).shift = 0; + } + break; + + case 155: + +/* Line 1806 of yacc.c */ +#line 1240 "asmshader.y" + { + (yyval.modshift).mod = BWRITERSPDM_MSAMPCENTROID; + (yyval.modshift).shift = 0; + } + break; + + case 156: + +/* Line 1806 of yacc.c */ +#line 1246 "asmshader.y" + { + (yyval.sregs).reg[0] = (yyvsp[(1) - (1)].reg); + (yyval.sregs).count = 1; + } + break; + + case 157: + +/* Line 1806 of yacc.c */ +#line 1251 "asmshader.y" + { + if((yyval.sregs).count == MAX_SRC_REGS){ + asmparser_message(&asm_ctx, "Line %u: Too many source registers in this instruction\n", + asm_ctx.line_no); + set_parse_status(&asm_ctx.status, PARSE_ERR); + } + else + (yyval.sregs).reg[(yyval.sregs).count++] = (yyvsp[(3) - (3)].reg); + } + break; + + case 158: + +/* Line 1806 of yacc.c */ +#line 1262 "asmshader.y" + { + (yyval.reg).type = (yyvsp[(1) - (3)].reg).type; + (yyval.reg).regnum = (yyvsp[(1) - (3)].reg).regnum; + (yyval.reg).u.swizzle = (yyvsp[(3) - (3)].swizzle); + (yyval.reg).srcmod = BWRITERSPSM_NONE; + set_rel_reg(&(yyval.reg), &(yyvsp[(2) - (3)].rel_reg)); + } + break; + + case 159: + +/* Line 1806 of yacc.c */ +#line 1270 "asmshader.y" + { + (yyval.reg).type = (yyvsp[(1) - (4)].reg).type; + (yyval.reg).regnum = (yyvsp[(1) - (4)].reg).regnum; + set_rel_reg(&(yyval.reg), &(yyvsp[(2) - (4)].rel_reg)); + (yyval.reg).srcmod = (yyvsp[(3) - (4)].srcmod); + (yyval.reg).u.swizzle = (yyvsp[(4) - (4)].swizzle); + } + break; + + case 160: + +/* Line 1806 of yacc.c */ +#line 1278 "asmshader.y" + { + (yyval.reg).type = (yyvsp[(2) - (4)].reg).type; + (yyval.reg).regnum = (yyvsp[(2) - (4)].reg).regnum; + (yyval.reg).srcmod = BWRITERSPSM_NEG; + set_rel_reg(&(yyval.reg), &(yyvsp[(3) - (4)].rel_reg)); + (yyval.reg).u.swizzle = (yyvsp[(4) - (4)].swizzle); + } + break; + + case 161: + +/* Line 1806 of yacc.c */ +#line 1286 "asmshader.y" + { + (yyval.reg).type = (yyvsp[(2) - (5)].reg).type; + (yyval.reg).regnum = (yyvsp[(2) - (5)].reg).regnum; + set_rel_reg(&(yyval.reg), &(yyvsp[(3) - (5)].rel_reg)); + switch((yyvsp[(4) - (5)].srcmod)) { + case BWRITERSPSM_BIAS: (yyval.reg).srcmod = BWRITERSPSM_BIASNEG; break; + case BWRITERSPSM_X2: (yyval.reg).srcmod = BWRITERSPSM_X2NEG; break; + case BWRITERSPSM_SIGN: (yyval.reg).srcmod = BWRITERSPSM_SIGNNEG; break; + case BWRITERSPSM_ABS: (yyval.reg).srcmod = BWRITERSPSM_ABSNEG; break; + case BWRITERSPSM_DZ: + asmparser_message(&asm_ctx, "Line %u: Incompatible source modifiers: NEG and DZ\n", + asm_ctx.line_no); + set_parse_status(&asm_ctx.status, PARSE_ERR); + break; + case BWRITERSPSM_DW: + asmparser_message(&asm_ctx, "Line %u: Incompatible source modifiers: NEG and DW\n", + asm_ctx.line_no); + set_parse_status(&asm_ctx.status, PARSE_ERR); + break; + default: + FIXME("Unhandled combination of NEGATE and %u\n", (yyvsp[(4) - (5)].srcmod)); + } + (yyval.reg).u.swizzle = (yyvsp[(5) - (5)].swizzle); + } + break; + + case 162: + +/* Line 1806 of yacc.c */ +#line 1311 "asmshader.y" + { + if((yyvsp[(1) - (5)].immval).val != 1.0 || (!(yyvsp[(1) - (5)].immval).integer)) { + asmparser_message(&asm_ctx, "Line %u: Only \"1 - reg\" is valid for D3DSPSM_COMP, " + "%g - reg found\n", asm_ctx.line_no, (yyvsp[(1) - (5)].immval).val); + set_parse_status(&asm_ctx.status, PARSE_ERR); + } + /* Complement - not compatible with other source modifiers */ + (yyval.reg).type = (yyvsp[(3) - (5)].reg).type; + (yyval.reg).regnum = (yyvsp[(3) - (5)].reg).regnum; + (yyval.reg).srcmod = BWRITERSPSM_COMP; + set_rel_reg(&(yyval.reg), &(yyvsp[(4) - (5)].rel_reg)); + (yyval.reg).u.swizzle = (yyvsp[(5) - (5)].swizzle); + } + break; + + case 163: + +/* Line 1806 of yacc.c */ +#line 1325 "asmshader.y" + { + /* For nicer error reporting */ + if((yyvsp[(1) - (6)].immval).val != 1.0 || (!(yyvsp[(1) - (6)].immval).integer)) { + asmparser_message(&asm_ctx, "Line %u: Only \"1 - reg\" is valid for D3DSPSM_COMP\n", + asm_ctx.line_no); + set_parse_status(&asm_ctx.status, PARSE_ERR); + } else { + asmparser_message(&asm_ctx, "Line %u: Incompatible source modifiers: D3DSPSM_COMP and %s\n", + asm_ctx.line_no, + debug_print_srcmod((yyvsp[(5) - (6)].srcmod))); + set_parse_status(&asm_ctx.status, PARSE_ERR); + } + } + break; + + case 164: + +/* Line 1806 of yacc.c */ +#line 1339 "asmshader.y" + { + (yyval.reg).type = (yyvsp[(2) - (3)].reg).type; + (yyval.reg).regnum = (yyvsp[(2) - (3)].reg).regnum; + (yyval.reg).rel_reg = NULL; + (yyval.reg).srcmod = BWRITERSPSM_NOT; + (yyval.reg).u.swizzle = (yyvsp[(3) - (3)].swizzle); + } + break; + + case 165: + +/* Line 1806 of yacc.c */ +#line 1348 "asmshader.y" + { + (yyval.rel_reg).has_rel_reg = FALSE; + (yyval.rel_reg).additional_offset = 0; + } + break; + + case 166: + +/* Line 1806 of yacc.c */ +#line 1353 "asmshader.y" + { + (yyval.rel_reg).has_rel_reg = FALSE; + (yyval.rel_reg).additional_offset = (yyvsp[(2) - (3)].immval).val; + } + break; + + case 167: + +/* Line 1806 of yacc.c */ +#line 1358 "asmshader.y" + { + (yyval.rel_reg).has_rel_reg = TRUE; + (yyval.rel_reg).type = (yyvsp[(2) - (4)].reg).type; + (yyval.rel_reg).additional_offset = 0; + (yyval.rel_reg).rel_regnum = (yyvsp[(2) - (4)].reg).regnum; + (yyval.rel_reg).swizzle = (yyvsp[(3) - (4)].swizzle); + } + break; + + case 168: + +/* Line 1806 of yacc.c */ +#line 1366 "asmshader.y" + { + (yyval.rel_reg).has_rel_reg = TRUE; + (yyval.rel_reg).type = (yyvsp[(4) - (6)].reg).type; + (yyval.rel_reg).additional_offset = (yyvsp[(2) - (6)].immval).val; + (yyval.rel_reg).rel_regnum = (yyvsp[(4) - (6)].reg).regnum; + (yyval.rel_reg).swizzle = (yyvsp[(5) - (6)].swizzle); + } + break; + + case 169: + +/* Line 1806 of yacc.c */ +#line 1374 "asmshader.y" + { + (yyval.rel_reg).has_rel_reg = TRUE; + (yyval.rel_reg).type = (yyvsp[(2) - (6)].reg).type; + (yyval.rel_reg).additional_offset = (yyvsp[(5) - (6)].immval).val; + (yyval.rel_reg).rel_regnum = (yyvsp[(2) - (6)].reg).regnum; + (yyval.rel_reg).swizzle = (yyvsp[(3) - (6)].swizzle); + } + break; + + case 170: + +/* Line 1806 of yacc.c */ +#line 1382 "asmshader.y" + { + (yyval.rel_reg).has_rel_reg = TRUE; + (yyval.rel_reg).type = (yyvsp[(4) - (8)].reg).type; + (yyval.rel_reg).additional_offset = (yyvsp[(2) - (8)].immval).val + (yyvsp[(7) - (8)].immval).val; + (yyval.rel_reg).rel_regnum = (yyvsp[(4) - (8)].reg).regnum; + (yyval.rel_reg).swizzle = (yyvsp[(5) - (8)].swizzle); + } + break; + + case 171: + +/* Line 1806 of yacc.c */ +#line 1391 "asmshader.y" + { + if(!(yyvsp[(1) - (1)].immval).integer) { + asmparser_message(&asm_ctx, "Line %u: Unexpected float %f\n", + asm_ctx.line_no, (yyvsp[(1) - (1)].immval).val); + set_parse_status(&asm_ctx.status, PARSE_ERR); + } + (yyval.immval).val = (yyvsp[(1) - (1)].immval).val; + } + break; + + case 172: + +/* Line 1806 of yacc.c */ +#line 1400 "asmshader.y" + { + if(!(yyvsp[(3) - (3)].immval).integer) { + asmparser_message(&asm_ctx, "Line %u: Unexpected float %f\n", + asm_ctx.line_no, (yyvsp[(3) - (3)].immval).val); + set_parse_status(&asm_ctx.status, PARSE_ERR); + } + (yyval.immval).val = (yyvsp[(1) - (3)].immval).val + (yyvsp[(3) - (3)].immval).val; + } + break; + + case 173: + +/* Line 1806 of yacc.c */ +#line 1410 "asmshader.y" + { + (yyval.srcmod) = BWRITERSPSM_BIAS; + } + break; + + case 174: + +/* Line 1806 of yacc.c */ +#line 1414 "asmshader.y" + { + (yyval.srcmod) = BWRITERSPSM_X2; + } + break; + + case 175: + +/* Line 1806 of yacc.c */ +#line 1418 "asmshader.y" + { + (yyval.srcmod) = BWRITERSPSM_SIGN; + } + break; + + case 176: + +/* Line 1806 of yacc.c */ +#line 1422 "asmshader.y" + { + (yyval.srcmod) = BWRITERSPSM_DZ; + } + break; + + case 177: + +/* Line 1806 of yacc.c */ +#line 1426 "asmshader.y" + { + (yyval.srcmod) = BWRITERSPSM_DW; + } + break; + + case 178: + +/* Line 1806 of yacc.c */ +#line 1430 "asmshader.y" + { + (yyval.srcmod) = BWRITERSPSM_ABS; + } + break; + + case 179: + +/* Line 1806 of yacc.c */ +#line 1435 "asmshader.y" + { + (yyval.reg).regnum = 0; (yyval.reg).type = BWRITERSPR_ADDR; + } + break; + + case 180: + +/* Line 1806 of yacc.c */ +#line 1439 "asmshader.y" + { + (yyval.reg).regnum = 0; (yyval.reg).type = BWRITERSPR_LOOP; + } + break; + + case 181: + +/* Line 1806 of yacc.c */ +#line 1444 "asmshader.y" + { + (yyval.reg).regnum = (yyvsp[(1) - (1)].regnum); (yyval.reg).type = BWRITERSPR_TEMP; + } + break; + + case 182: + +/* Line 1806 of yacc.c */ +#line 1448 "asmshader.y" + { + asmparser_message(&asm_ctx, "Line %u: Register o%u is not a valid source register\n", + asm_ctx.line_no, (yyvsp[(1) - (1)].regnum)); + set_parse_status(&asm_ctx.status, PARSE_WARN); + } + break; + + case 183: + +/* Line 1806 of yacc.c */ +#line 1454 "asmshader.y" + { + (yyval.reg).regnum = (yyvsp[(1) - (1)].regnum); (yyval.reg).type = BWRITERSPR_INPUT; + } + break; + + case 184: + +/* Line 1806 of yacc.c */ +#line 1458 "asmshader.y" + { + (yyval.reg).regnum = (yyvsp[(1) - (1)].regnum); (yyval.reg).type = BWRITERSPR_CONST; + } + break; + + case 185: + +/* Line 1806 of yacc.c */ +#line 1462 "asmshader.y" + { + (yyval.reg).regnum = (yyvsp[(1) - (1)].regnum); (yyval.reg).type = BWRITERSPR_CONSTINT; + } + break; + + case 186: + +/* Line 1806 of yacc.c */ +#line 1466 "asmshader.y" + { + (yyval.reg).regnum = (yyvsp[(1) - (1)].regnum); (yyval.reg).type = BWRITERSPR_CONSTBOOL; + } + break; + + case 187: + +/* Line 1806 of yacc.c */ +#line 1470 "asmshader.y" + { + (yyval.reg).regnum = (yyvsp[(1) - (1)].regnum); (yyval.reg).type = BWRITERSPR_TEXTURE; + } + break; + + case 188: + +/* Line 1806 of yacc.c */ +#line 1474 "asmshader.y" + { + asmparser_message(&asm_ctx, "Line %u: Register oT%u is not a valid source register\n", + asm_ctx.line_no, (yyvsp[(1) - (1)].regnum)); + set_parse_status(&asm_ctx.status, PARSE_WARN); + } + break; + + case 189: + +/* Line 1806 of yacc.c */ +#line 1480 "asmshader.y" + { + (yyval.reg).regnum = (yyvsp[(1) - (1)].regnum); (yyval.reg).type = BWRITERSPR_SAMPLER; + } + break; + + case 190: + +/* Line 1806 of yacc.c */ +#line 1484 "asmshader.y" + { + asmparser_message(&asm_ctx, "Line %u: Register oPos is not a valid source register\n", + asm_ctx.line_no); + set_parse_status(&asm_ctx.status, PARSE_WARN); + } + break; + + case 191: + +/* Line 1806 of yacc.c */ +#line 1490 "asmshader.y" + { + asmparser_message(&asm_ctx, "Line %u: Register oFog is not a valid source register\n", + asm_ctx.line_no); + set_parse_status(&asm_ctx.status, PARSE_WARN); + } + break; + + case 192: + +/* Line 1806 of yacc.c */ +#line 1496 "asmshader.y" + { + asmparser_message(&asm_ctx, "Line %u: Register oD%u is not a valid source register\n", + asm_ctx.line_no, (yyvsp[(1) - (1)].regnum)); + set_parse_status(&asm_ctx.status, PARSE_WARN); + } + break; + + case 193: + +/* Line 1806 of yacc.c */ +#line 1502 "asmshader.y" + { + asmparser_message(&asm_ctx, "Line %u: Register oC%u is not a valid source register\n", + asm_ctx.line_no, (yyvsp[(1) - (1)].regnum)); + set_parse_status(&asm_ctx.status, PARSE_WARN); + } + break; + + case 194: + +/* Line 1806 of yacc.c */ +#line 1508 "asmshader.y" + { + asmparser_message(&asm_ctx, "Line %u: Register oDepth is not a valid source register\n", + asm_ctx.line_no); + set_parse_status(&asm_ctx.status, PARSE_WARN); + } + break; + + case 195: + +/* Line 1806 of yacc.c */ +#line 1514 "asmshader.y" + { + (yyval.reg).regnum = 0; (yyval.reg).type = BWRITERSPR_PREDICATE; + } + break; + + case 196: + +/* Line 1806 of yacc.c */ +#line 1518 "asmshader.y" + { + (yyval.reg).regnum = 0; (yyval.reg).type = BWRITERSPR_MISCTYPE; + } + break; + + case 197: + +/* Line 1806 of yacc.c */ +#line 1522 "asmshader.y" + { + (yyval.reg).regnum = 1; (yyval.reg).type = BWRITERSPR_MISCTYPE; + } + break; + + case 198: + +/* Line 1806 of yacc.c */ +#line 1526 "asmshader.y" + { + (yyval.reg).regnum = 0; (yyval.reg).type = BWRITERSPR_ADDR; + } + break; + + case 199: + +/* Line 1806 of yacc.c */ +#line 1530 "asmshader.y" + { + (yyval.reg).regnum = 0; (yyval.reg).type = BWRITERSPR_LOOP; + } + break; + + case 200: + +/* Line 1806 of yacc.c */ +#line 1534 "asmshader.y" + { + (yyval.reg).regnum = (yyvsp[(1) - (1)].regnum); (yyval.reg).type = BWRITERSPR_LABEL; + } + break; + + case 201: + +/* Line 1806 of yacc.c */ +#line 1538 "asmshader.y" + { (yyval.comptype) = BWRITER_COMPARISON_GT; } + break; + + case 202: + +/* Line 1806 of yacc.c */ +#line 1539 "asmshader.y" + { (yyval.comptype) = BWRITER_COMPARISON_LT; } + break; + + case 203: + +/* Line 1806 of yacc.c */ +#line 1540 "asmshader.y" + { (yyval.comptype) = BWRITER_COMPARISON_GE; } + break; + + case 204: + +/* Line 1806 of yacc.c */ +#line 1541 "asmshader.y" + { (yyval.comptype) = BWRITER_COMPARISON_LE; } + break; + + case 205: + +/* Line 1806 of yacc.c */ +#line 1542 "asmshader.y" + { (yyval.comptype) = BWRITER_COMPARISON_EQ; } + break; + + case 206: + +/* Line 1806 of yacc.c */ +#line 1543 "asmshader.y" + { (yyval.comptype) = BWRITER_COMPARISON_NE; } + break; + + case 207: + +/* Line 1806 of yacc.c */ +#line 1546 "asmshader.y" + { + TRACE("dcl_position%u\n", (yyvsp[(1) - (1)].regnum)); + (yyval.declaration).regnum = (yyvsp[(1) - (1)].regnum); + (yyval.declaration).dclusage = BWRITERDECLUSAGE_POSITION; + } + break; + + case 208: + +/* Line 1806 of yacc.c */ +#line 1552 "asmshader.y" + { + TRACE("dcl_blendweight%u\n", (yyvsp[(1) - (1)].regnum)); + (yyval.declaration).regnum = (yyvsp[(1) - (1)].regnum); + (yyval.declaration).dclusage = BWRITERDECLUSAGE_BLENDWEIGHT; + } + break; + + case 209: + +/* Line 1806 of yacc.c */ +#line 1558 "asmshader.y" + { + TRACE("dcl_blendindices%u\n", (yyvsp[(1) - (1)].regnum)); + (yyval.declaration).regnum = (yyvsp[(1) - (1)].regnum); + (yyval.declaration).dclusage = BWRITERDECLUSAGE_BLENDINDICES; + } + break; + + case 210: + +/* Line 1806 of yacc.c */ +#line 1564 "asmshader.y" + { + TRACE("dcl_normal%u\n", (yyvsp[(1) - (1)].regnum)); + (yyval.declaration).regnum = (yyvsp[(1) - (1)].regnum); + (yyval.declaration).dclusage = BWRITERDECLUSAGE_NORMAL; + } + break; + + case 211: + +/* Line 1806 of yacc.c */ +#line 1570 "asmshader.y" + { + TRACE("dcl_psize%u\n", (yyvsp[(1) - (1)].regnum)); + (yyval.declaration).regnum = (yyvsp[(1) - (1)].regnum); + (yyval.declaration).dclusage = BWRITERDECLUSAGE_PSIZE; + } + break; + + case 212: + +/* Line 1806 of yacc.c */ +#line 1576 "asmshader.y" + { + TRACE("dcl_texcoord%u\n", (yyvsp[(1) - (1)].regnum)); + (yyval.declaration).regnum = (yyvsp[(1) - (1)].regnum); + (yyval.declaration).dclusage = BWRITERDECLUSAGE_TEXCOORD; + } + break; + + case 213: + +/* Line 1806 of yacc.c */ +#line 1582 "asmshader.y" + { + TRACE("dcl_tangent%u\n", (yyvsp[(1) - (1)].regnum)); + (yyval.declaration).regnum = (yyvsp[(1) - (1)].regnum); + (yyval.declaration).dclusage = BWRITERDECLUSAGE_TANGENT; + } + break; + + case 214: + +/* Line 1806 of yacc.c */ +#line 1588 "asmshader.y" + { + TRACE("dcl_binormal%u\n", (yyvsp[(1) - (1)].regnum)); + (yyval.declaration).regnum = (yyvsp[(1) - (1)].regnum); + (yyval.declaration).dclusage = BWRITERDECLUSAGE_BINORMAL; + } + break; + + case 215: + +/* Line 1806 of yacc.c */ +#line 1594 "asmshader.y" + { + TRACE("dcl_tessfactor%u\n", (yyvsp[(1) - (1)].regnum)); + (yyval.declaration).regnum = (yyvsp[(1) - (1)].regnum); + (yyval.declaration).dclusage = BWRITERDECLUSAGE_TESSFACTOR; + } + break; + + case 216: + +/* Line 1806 of yacc.c */ +#line 1600 "asmshader.y" + { + TRACE("dcl_positiont%u\n", (yyvsp[(1) - (1)].regnum)); + (yyval.declaration).regnum = (yyvsp[(1) - (1)].regnum); + (yyval.declaration).dclusage = BWRITERDECLUSAGE_POSITIONT; + } + break; + + case 217: + +/* Line 1806 of yacc.c */ +#line 1606 "asmshader.y" + { + TRACE("dcl_color%u\n", (yyvsp[(1) - (1)].regnum)); + (yyval.declaration).regnum = (yyvsp[(1) - (1)].regnum); + (yyval.declaration).dclusage = BWRITERDECLUSAGE_COLOR; + } + break; + + case 218: + +/* Line 1806 of yacc.c */ +#line 1612 "asmshader.y" + { + TRACE("dcl_fog%u\n", (yyvsp[(1) - (1)].regnum)); + (yyval.declaration).regnum = (yyvsp[(1) - (1)].regnum); + (yyval.declaration).dclusage = BWRITERDECLUSAGE_FOG; + } + break; + + case 219: + +/* Line 1806 of yacc.c */ +#line 1618 "asmshader.y" + { + TRACE("dcl_depth%u\n", (yyvsp[(1) - (1)].regnum)); + (yyval.declaration).regnum = (yyvsp[(1) - (1)].regnum); + (yyval.declaration).dclusage = BWRITERDECLUSAGE_DEPTH; + } + break; + + case 220: + +/* Line 1806 of yacc.c */ +#line 1624 "asmshader.y" + { + TRACE("dcl_sample%u\n", (yyvsp[(1) - (1)].regnum)); + (yyval.declaration).regnum = (yyvsp[(1) - (1)].regnum); + (yyval.declaration).dclusage = BWRITERDECLUSAGE_SAMPLE; + } + break; + + case 221: + +/* Line 1806 of yacc.c */ +#line 1631 "asmshader.y" + { + (yyval.reg).regnum = (yyvsp[(1) - (1)].regnum); (yyval.reg).type = BWRITERSPR_INPUT; + } + break; + + case 222: + +/* Line 1806 of yacc.c */ +#line 1635 "asmshader.y" + { + (yyval.reg).regnum = (yyvsp[(1) - (1)].regnum); (yyval.reg).type = BWRITERSPR_TEXTURE; + } + break; + + case 223: + +/* Line 1806 of yacc.c */ +#line 1640 "asmshader.y" + { + (yyval.samplertype) = BWRITERSTT_1D; + } + break; + + case 224: + +/* Line 1806 of yacc.c */ +#line 1644 "asmshader.y" + { + (yyval.samplertype) = BWRITERSTT_2D; + } + break; + + case 225: + +/* Line 1806 of yacc.c */ +#line 1648 "asmshader.y" + { + (yyval.samplertype) = BWRITERSTT_CUBE; + } + break; + + case 226: + +/* Line 1806 of yacc.c */ +#line 1652 "asmshader.y" + { + (yyval.samplertype) = BWRITERSTT_VOLUME; + } + break; + + case 227: + +/* Line 1806 of yacc.c */ +#line 1657 "asmshader.y" + { + (yyval.reg).type = BWRITERSPR_PREDICATE; + (yyval.reg).regnum = 0; + (yyval.reg).rel_reg = NULL; + (yyval.reg).srcmod = BWRITERSPSM_NONE; + (yyval.reg).u.swizzle = (yyvsp[(3) - (4)].swizzle); + } + break; + + case 228: + +/* Line 1806 of yacc.c */ +#line 1665 "asmshader.y" + { + (yyval.reg).type = BWRITERSPR_PREDICATE; + (yyval.reg).regnum = 0; + (yyval.reg).rel_reg = NULL; + (yyval.reg).srcmod = BWRITERSPSM_NOT; + (yyval.reg).u.swizzle = (yyvsp[(4) - (5)].swizzle); + } + break; + + + +/* Line 1806 of yacc.c */ +#line 4612 "asmshader.tab.c" + default: break; + } + /* User semantic actions sometimes alter yychar, and that requires + that yytoken be updated with the new translation. We take the + approach of translating immediately before every use of yytoken. + One alternative is translating here after every semantic action, + but that translation would be missed if the semantic action invokes + YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or + if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an + incorrect destructor might then be invoked immediately. In the + case of YYERROR or YYBACKUP, subsequent parser actions might lead + to an incorrect destructor call or verbose syntax error message + before the lookahead is translated. */ + YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); + + YYPOPSTACK (yylen); + yylen = 0; + YY_STACK_PRINT (yyss, yyssp); + + *++yyvsp = yyval; + + /* Now `shift' the result of the reduction. Determine what state + that goes to, based on the state we popped back to and the rule + number reduced by. */ + + yyn = yyr1[yyn]; + + yystate = yypgoto[yyn - YYNTOKENS] + *yyssp; + if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp) + yystate = yytable[yystate]; + else + yystate = yydefgoto[yyn - YYNTOKENS]; + + goto yynewstate; + + +/*------------------------------------. +| yyerrlab -- here on detecting error | +`------------------------------------*/ +yyerrlab: + /* Make sure we have latest lookahead translation. See comments at + user semantic actions for why this is necessary. */ + yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar); + + /* If not already recovering from an error, report this error. */ + if (!yyerrstatus) + { + ++yynerrs; +#if ! YYERROR_VERBOSE + yyerror (YY_("syntax error")); +#else +# define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \ + yyssp, yytoken) + { + char const *yymsgp = YY_("syntax error"); + int yysyntax_error_status; + yysyntax_error_status = YYSYNTAX_ERROR; + if (yysyntax_error_status == 0) + yymsgp = yymsg; + else if (yysyntax_error_status == 1) + { + if (yymsg != yymsgbuf) + YYSTACK_FREE (yymsg); + yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc); + if (!yymsg) + { + yymsg = yymsgbuf; + yymsg_alloc = sizeof yymsgbuf; + yysyntax_error_status = 2; + } + else + { + yysyntax_error_status = YYSYNTAX_ERROR; + yymsgp = yymsg; + } + } + yyerror (yymsgp); + if (yysyntax_error_status == 2) + goto yyexhaustedlab; + } +# undef YYSYNTAX_ERROR +#endif + } + + + + if (yyerrstatus == 3) + { + /* If just tried and failed to reuse lookahead token after an + error, discard it. */ + + if (yychar <= YYEOF) + { + /* Return failure if at end of input. */ + if (yychar == YYEOF) + YYABORT; + } + else + { + yydestruct ("Error: discarding", + yytoken, &yylval); + yychar = YYEMPTY; + } + } + + /* Else will try to reuse lookahead token after shifting the error + token. */ + goto yyerrlab1; + + +/*---------------------------------------------------. +| yyerrorlab -- error raised explicitly by YYERROR. | +`---------------------------------------------------*/ +yyerrorlab: + + /* Pacify compilers like GCC when the user code never invokes + YYERROR and the label yyerrorlab therefore never appears in user + code. */ + if (/*CONSTCOND*/ 0) + goto yyerrorlab; + + /* Do not reclaim the symbols of the rule which action triggered + this YYERROR. */ + YYPOPSTACK (yylen); + yylen = 0; + YY_STACK_PRINT (yyss, yyssp); + yystate = *yyssp; + goto yyerrlab1; + + +/*-------------------------------------------------------------. +| yyerrlab1 -- common code for both syntax error and YYERROR. | +`-------------------------------------------------------------*/ +yyerrlab1: + yyerrstatus = 3; /* Each real token shifted decrements this. */ + + for (;;) + { + yyn = yypact[yystate]; + if (!yypact_value_is_default (yyn)) + { + yyn += YYTERROR; + if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) + { + yyn = yytable[yyn]; + if (0 < yyn) + break; + } + } + + /* Pop the current state because it cannot handle the error token. */ + if (yyssp == yyss) + YYABORT; + + + yydestruct ("Error: popping", + yystos[yystate], yyvsp); + YYPOPSTACK (1); + yystate = *yyssp; + YY_STACK_PRINT (yyss, yyssp); + } + + *++yyvsp = yylval; + + + /* Shift the error token. */ + YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp); + + yystate = yyn; + goto yynewstate; + + +/*-------------------------------------. +| yyacceptlab -- YYACCEPT comes here. | +`-------------------------------------*/ +yyacceptlab: + yyresult = 0; + goto yyreturn; + +/*-----------------------------------. +| yyabortlab -- YYABORT comes here. | +`-----------------------------------*/ +yyabortlab: + yyresult = 1; + goto yyreturn; + +#if !defined(yyoverflow) || YYERROR_VERBOSE +/*-------------------------------------------------. +| yyexhaustedlab -- memory exhaustion comes here. | +`-------------------------------------------------*/ +yyexhaustedlab: + yyerror (YY_("memory exhausted")); + yyresult = 2; + /* Fall through. */ +#endif + +yyreturn: + if (yychar != YYEMPTY) + { + /* Make sure we have latest lookahead translation. See comments at + user semantic actions for why this is necessary. */ + yytoken = YYTRANSLATE (yychar); + yydestruct ("Cleanup: discarding lookahead", + yytoken, &yylval); + } + /* Do not reclaim the symbols of the rule which action triggered + this YYABORT or YYACCEPT. */ + YYPOPSTACK (yylen); + YY_STACK_PRINT (yyss, yyssp); + while (yyssp != yyss) + { + yydestruct ("Cleanup: popping", + yystos[*yyssp], yyvsp); + YYPOPSTACK (1); + } +#ifndef yyoverflow + if (yyss != yyssa) + YYSTACK_FREE (yyss); +#endif +#if YYERROR_VERBOSE + if (yymsg != yymsgbuf) + YYSTACK_FREE (yymsg); +#endif + /* Make sure YYID is used. */ + return YYID (yyresult); +} + + + +/* Line 2067 of yacc.c */ +#line 1673 "asmshader.y" + + +struct bwriter_shader *parse_asm_shader(char **messages) +{ + struct bwriter_shader *ret = NULL; + + asm_ctx.shader = NULL; + asm_ctx.status = PARSE_SUCCESS; + asm_ctx.messages.size = asm_ctx.messages.capacity = 0; + asm_ctx.line_no = 1; + + asmshader_parse(); + + if (asm_ctx.status != PARSE_ERR) + ret = asm_ctx.shader; + else if (asm_ctx.shader) + SlDeleteShader(asm_ctx.shader); + + if (messages) + { + if (asm_ctx.messages.size) + { + /* Shrink the buffer to the used size */ + *messages = d3dcompiler_realloc(asm_ctx.messages.string, asm_ctx.messages.size + 1); + if (!*messages) + { + ERR("Out of memory, no messages reported\n"); + d3dcompiler_free(asm_ctx.messages.string); + } + } + else + { + *messages = NULL; + } + } + else + { + if (asm_ctx.messages.capacity) + d3dcompiler_free(asm_ctx.messages.string); + } + + return ret; +} + diff --git a/reactos/dll/directx/wine/d3dcompiler_43/asmshader.tab.h b/reactos/dll/directx/wine/d3dcompiler_43/asmshader.tab.h new file mode 100644 index 00000000000..04e200d4e05 --- /dev/null +++ b/reactos/dll/directx/wine/d3dcompiler_43/asmshader.tab.h @@ -0,0 +1,257 @@ +/* A Bison parser, made by GNU Bison 2.5. */ + +/* Bison interface for Yacc-like parsers in C + + Copyright (C) 1984, 1989-1990, 2000-2011 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* As a special exception, you may create a larger work that contains + part or all of the Bison parser skeleton and distribute that work + under terms of your choice, so long as that work isn't itself a + parser generator using the skeleton or a modified version thereof + as a parser skeleton. Alternatively, if you modify or redistribute + the parser skeleton itself, you may (at your option) remove this + special exception, which will cause the skeleton and the resulting + Bison output files to be licensed under the GNU General Public + License without this special exception. + + This special exception was added by the Free Software Foundation in + version 2.2 of Bison. */ + + +/* Tokens. */ +#ifndef YYTOKENTYPE +# define YYTOKENTYPE + /* Put the tokens into the symbol table, so that GDB and other debuggers + know about them. */ + enum yytokentype { + INSTR_ADD = 258, + INSTR_NOP = 259, + INSTR_MOV = 260, + INSTR_SUB = 261, + INSTR_MAD = 262, + INSTR_MUL = 263, + INSTR_RCP = 264, + INSTR_RSQ = 265, + INSTR_DP3 = 266, + INSTR_DP4 = 267, + INSTR_MIN = 268, + INSTR_MAX = 269, + INSTR_SLT = 270, + INSTR_SGE = 271, + INSTR_ABS = 272, + INSTR_EXP = 273, + INSTR_LOG = 274, + INSTR_EXPP = 275, + INSTR_LOGP = 276, + INSTR_DST = 277, + INSTR_LRP = 278, + INSTR_FRC = 279, + INSTR_POW = 280, + INSTR_CRS = 281, + INSTR_SGN = 282, + INSTR_NRM = 283, + INSTR_SINCOS = 284, + INSTR_M4x4 = 285, + INSTR_M4x3 = 286, + INSTR_M3x4 = 287, + INSTR_M3x3 = 288, + INSTR_M3x2 = 289, + INSTR_DCL = 290, + INSTR_DEF = 291, + INSTR_DEFB = 292, + INSTR_DEFI = 293, + INSTR_REP = 294, + INSTR_ENDREP = 295, + INSTR_IF = 296, + INSTR_ELSE = 297, + INSTR_ENDIF = 298, + INSTR_BREAK = 299, + INSTR_BREAKP = 300, + INSTR_CALL = 301, + INSTR_CALLNZ = 302, + INSTR_LOOP = 303, + INSTR_RET = 304, + INSTR_ENDLOOP = 305, + INSTR_LABEL = 306, + INSTR_SETP = 307, + INSTR_TEXLDL = 308, + INSTR_LIT = 309, + INSTR_MOVA = 310, + INSTR_CND = 311, + INSTR_CMP = 312, + INSTR_DP2ADD = 313, + INSTR_TEXCOORD = 314, + INSTR_TEXCRD = 315, + INSTR_TEXKILL = 316, + INSTR_TEX = 317, + INSTR_TEXLD = 318, + INSTR_TEXBEM = 319, + INSTR_TEXBEML = 320, + INSTR_TEXREG2AR = 321, + INSTR_TEXREG2GB = 322, + INSTR_TEXREG2RGB = 323, + INSTR_TEXM3x2PAD = 324, + INSTR_TEXM3x2TEX = 325, + INSTR_TEXM3x3PAD = 326, + INSTR_TEXM3x3SPEC = 327, + INSTR_TEXM3x3VSPEC = 328, + INSTR_TEXM3x3TEX = 329, + INSTR_TEXDP3TEX = 330, + INSTR_TEXM3x2DEPTH = 331, + INSTR_TEXDP3 = 332, + INSTR_TEXM3x3 = 333, + INSTR_TEXDEPTH = 334, + INSTR_BEM = 335, + INSTR_DSX = 336, + INSTR_DSY = 337, + INSTR_TEXLDP = 338, + INSTR_TEXLDB = 339, + INSTR_TEXLDD = 340, + INSTR_PHASE = 341, + REG_TEMP = 342, + REG_OUTPUT = 343, + REG_INPUT = 344, + REG_CONSTFLOAT = 345, + REG_CONSTINT = 346, + REG_CONSTBOOL = 347, + REG_TEXTURE = 348, + REG_SAMPLER = 349, + REG_TEXCRDOUT = 350, + REG_OPOS = 351, + REG_OFOG = 352, + REG_OPTS = 353, + REG_VERTEXCOLOR = 354, + REG_FRAGCOLOR = 355, + REG_FRAGDEPTH = 356, + REG_VPOS = 357, + REG_VFACE = 358, + REG_ADDRESS = 359, + REG_LOOP = 360, + REG_PREDICATE = 361, + REG_LABEL = 362, + VER_VS10 = 363, + VER_VS11 = 364, + VER_VS20 = 365, + VER_VS2X = 366, + VER_VS30 = 367, + VER_PS10 = 368, + VER_PS11 = 369, + VER_PS12 = 370, + VER_PS13 = 371, + VER_PS14 = 372, + VER_PS20 = 373, + VER_PS2X = 374, + VER_PS30 = 375, + SHIFT_X2 = 376, + SHIFT_X4 = 377, + SHIFT_X8 = 378, + SHIFT_D2 = 379, + SHIFT_D4 = 380, + SHIFT_D8 = 381, + MOD_SAT = 382, + MOD_PP = 383, + MOD_CENTROID = 384, + COMP_GT = 385, + COMP_LT = 386, + COMP_GE = 387, + COMP_LE = 388, + COMP_EQ = 389, + COMP_NE = 390, + SMOD_BIAS = 391, + SMOD_SCALEBIAS = 392, + SMOD_DZ = 393, + SMOD_DW = 394, + SMOD_ABS = 395, + SMOD_NOT = 396, + SAMPTYPE_1D = 397, + SAMPTYPE_2D = 398, + SAMPTYPE_CUBE = 399, + SAMPTYPE_VOLUME = 400, + USAGE_POSITION = 401, + USAGE_BLENDWEIGHT = 402, + USAGE_BLENDINDICES = 403, + USAGE_NORMAL = 404, + USAGE_PSIZE = 405, + USAGE_TEXCOORD = 406, + USAGE_TANGENT = 407, + USAGE_BINORMAL = 408, + USAGE_TESSFACTOR = 409, + USAGE_POSITIONT = 410, + USAGE_COLOR = 411, + USAGE_FOG = 412, + USAGE_DEPTH = 413, + USAGE_SAMPLE = 414, + COMPONENT = 415, + IMMVAL = 416, + IMMBOOL = 417 + }; +#endif + + + +#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED +typedef union YYSTYPE +{ + +/* Line 2068 of yacc.c */ +#line 70 "asmshader.y" + + struct { + float val; + BOOL integer; + } immval; + BOOL immbool; + unsigned int regnum; + struct shader_reg reg; + DWORD srcmod; + DWORD writemask; + struct { + DWORD writemask; + DWORD idx; + DWORD last; + } wm_components; + DWORD swizzle; + struct { + DWORD swizzle; + DWORD idx; + } sw_components; + DWORD component; + struct { + DWORD mod; + DWORD shift; + } modshift; + BWRITER_COMPARISON_TYPE comptype; + struct { + DWORD dclusage; + unsigned int regnum; + } declaration; + BWRITERSAMPLER_TEXTURE_TYPE samplertype; + struct rel_reg rel_reg; + struct src_regs sregs; + + + +/* Line 2068 of yacc.c */ +#line 249 "asmshader.tab.h" +} YYSTYPE; +# define YYSTYPE_IS_TRIVIAL 1 +# define yystype YYSTYPE /* obsolescent; will be withdrawn */ +# define YYSTYPE_IS_DECLARED 1 +#endif + +extern YYSTYPE asmshader_lval; + + diff --git a/reactos/dll/directx/wine/d3dcompiler_43/asmshader.y b/reactos/dll/directx/wine/d3dcompiler_43/asmshader.y new file mode 100644 index 00000000000..4109745a6a8 --- /dev/null +++ b/reactos/dll/directx/wine/d3dcompiler_43/asmshader.y @@ -0,0 +1,1715 @@ + /* + * Direct3D shader assembler + * + * Copyright 2008 Stefan Dösinger + * Copyright 2009 Matteo Bruni + * + * 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" + +#include "d3dcompiler_private.h" + +WINE_DEFAULT_DEBUG_CHANNEL(asmshader); + +struct asm_parser asm_ctx; + +void asmparser_message(struct asm_parser *ctx, const char *fmt, ...) +{ + va_list args; + + va_start(args, fmt); + compilation_message(&ctx->messages, fmt, args); + va_end(args); +} + +static void asmshader_error(char const *s) { + asmparser_message(&asm_ctx, "Line %u: Error \"%s\" from bison\n", asm_ctx.line_no, s); + set_parse_status(&asm_ctx.status, PARSE_ERR); +} + +static void set_rel_reg(struct shader_reg *reg, struct rel_reg *rel) { + /* We can have an additional offset without true relative addressing + * ex. c2[ 4 ] */ + reg->regnum += rel->additional_offset; + if(!rel->has_rel_reg) { + reg->rel_reg = NULL; + } else { + reg->rel_reg = d3dcompiler_alloc(sizeof(*reg->rel_reg)); + if(!reg->rel_reg) { + return; + } + reg->rel_reg->type = rel->type; + reg->rel_reg->u.swizzle = rel->swizzle; + reg->rel_reg->regnum = rel->rel_regnum; + } +} + +/* Needed lexer functions declarations */ +int asmshader_lex(void); + + +%} + +%union { + struct { + float val; + BOOL integer; + } immval; + BOOL immbool; + unsigned int regnum; + struct shader_reg reg; + DWORD srcmod; + DWORD writemask; + struct { + DWORD writemask; + DWORD idx; + DWORD last; + } wm_components; + DWORD swizzle; + struct { + DWORD swizzle; + DWORD idx; + } sw_components; + DWORD component; + struct { + DWORD mod; + DWORD shift; + } modshift; + BWRITER_COMPARISON_TYPE comptype; + struct { + DWORD dclusage; + unsigned int regnum; + } declaration; + BWRITERSAMPLER_TEXTURE_TYPE samplertype; + struct rel_reg rel_reg; + struct src_regs sregs; +} + +/* Common instructions between vertex and pixel shaders */ +%token INSTR_ADD +%token INSTR_NOP +%token INSTR_MOV +%token INSTR_SUB +%token INSTR_MAD +%token INSTR_MUL +%token INSTR_RCP +%token INSTR_RSQ +%token INSTR_DP3 +%token INSTR_DP4 +%token INSTR_MIN +%token INSTR_MAX +%token INSTR_SLT +%token INSTR_SGE +%token INSTR_ABS +%token INSTR_EXP +%token INSTR_LOG +%token INSTR_EXPP +%token INSTR_LOGP +%token INSTR_DST +%token INSTR_LRP +%token INSTR_FRC +%token INSTR_POW +%token INSTR_CRS +%token INSTR_SGN +%token INSTR_NRM +%token INSTR_SINCOS +%token INSTR_M4x4 +%token INSTR_M4x3 +%token INSTR_M3x4 +%token INSTR_M3x3 +%token INSTR_M3x2 +%token INSTR_DCL +%token INSTR_DEF +%token INSTR_DEFB +%token INSTR_DEFI +%token INSTR_REP +%token INSTR_ENDREP +%token INSTR_IF +%token INSTR_ELSE +%token INSTR_ENDIF +%token INSTR_BREAK +%token INSTR_BREAKP +%token INSTR_CALL +%token INSTR_CALLNZ +%token INSTR_LOOP +%token INSTR_RET +%token INSTR_ENDLOOP +%token INSTR_LABEL +%token INSTR_SETP +%token INSTR_TEXLDL + +/* Vertex shader only instructions */ +%token INSTR_LIT +%token INSTR_MOVA + +/* Pixel shader only instructions */ +%token INSTR_CND +%token INSTR_CMP +%token INSTR_DP2ADD +%token INSTR_TEXCOORD +%token INSTR_TEXCRD +%token INSTR_TEXKILL +%token INSTR_TEX +%token INSTR_TEXLD +%token INSTR_TEXBEM +%token INSTR_TEXBEML +%token INSTR_TEXREG2AR +%token INSTR_TEXREG2GB +%token INSTR_TEXREG2RGB +%token INSTR_TEXM3x2PAD +%token INSTR_TEXM3x2TEX +%token INSTR_TEXM3x3PAD +%token INSTR_TEXM3x3SPEC +%token INSTR_TEXM3x3VSPEC +%token INSTR_TEXM3x3TEX +%token INSTR_TEXDP3TEX +%token INSTR_TEXM3x2DEPTH +%token INSTR_TEXDP3 +%token INSTR_TEXM3x3 +%token INSTR_TEXDEPTH +%token INSTR_BEM +%token INSTR_DSX +%token INSTR_DSY +%token INSTR_TEXLDP +%token INSTR_TEXLDB +%token INSTR_TEXLDD +%token INSTR_PHASE + +/* Registers */ +%token REG_TEMP +%token REG_OUTPUT +%token REG_INPUT +%token REG_CONSTFLOAT +%token REG_CONSTINT +%token REG_CONSTBOOL +%token REG_TEXTURE +%token REG_SAMPLER +%token REG_TEXCRDOUT +%token REG_OPOS +%token REG_OFOG +%token REG_OPTS +%token REG_VERTEXCOLOR +%token REG_FRAGCOLOR +%token REG_FRAGDEPTH +%token REG_VPOS +%token REG_VFACE +%token REG_ADDRESS +%token REG_LOOP +%token REG_PREDICATE +%token REG_LABEL + +/* Version tokens */ +%token VER_VS10 +%token VER_VS11 +%token VER_VS20 +%token VER_VS2X +%token VER_VS30 + +%token VER_PS10 +%token VER_PS11 +%token VER_PS12 +%token VER_PS13 +%token VER_PS14 +%token VER_PS20 +%token VER_PS2X +%token VER_PS30 + +/* Output modifiers */ +%token SHIFT_X2 +%token SHIFT_X4 +%token SHIFT_X8 +%token SHIFT_D2 +%token SHIFT_D4 +%token SHIFT_D8 +%token MOD_SAT +%token MOD_PP +%token MOD_CENTROID + +/* Compare tokens */ +%token COMP_GT +%token COMP_LT +%token COMP_GE +%token COMP_LE +%token COMP_EQ +%token COMP_NE + +/* Source register modifiers */ +%token SMOD_BIAS +%token SMOD_SCALEBIAS +%token SMOD_DZ +%token SMOD_DW +%token SMOD_ABS +%token SMOD_NOT + +/* Sampler types */ +%token SAMPTYPE_1D +%token SAMPTYPE_2D +%token SAMPTYPE_CUBE +%token SAMPTYPE_VOLUME + +/* Usage declaration tokens */ +%token USAGE_POSITION +%token USAGE_BLENDWEIGHT +%token USAGE_BLENDINDICES +%token USAGE_NORMAL +%token USAGE_PSIZE +%token USAGE_TEXCOORD +%token USAGE_TANGENT +%token USAGE_BINORMAL +%token USAGE_TESSFACTOR +%token USAGE_POSITIONT +%token USAGE_COLOR +%token USAGE_FOG +%token USAGE_DEPTH +%token USAGE_SAMPLE + +/* Misc stuff */ +%token COMPONENT +%token IMMVAL +%token IMMBOOL + +%type dreg_name +%type dreg +%type sreg_name +%type relreg_name +%type sreg +%type smod +%type writemask +%type wm_components +%type swizzle +%type sw_components +%type omods +%type omodifier +%type comp +%type dclusage +%type dcl_inputreg +%type sampdcl +%type rel_reg +%type predicate +%type immsum +%type sregs + +%% + +shader: version_marker instructions + { + asm_ctx.funcs->end(&asm_ctx); + } + +version_marker: VER_VS10 + { + TRACE("Vertex shader 1.0\n"); + create_vs10_parser(&asm_ctx); + } + | VER_VS11 + { + TRACE("Vertex shader 1.1\n"); + create_vs11_parser(&asm_ctx); + } + | VER_VS20 + { + TRACE("Vertex shader 2.0\n"); + create_vs20_parser(&asm_ctx); + } + | VER_VS2X + { + TRACE("Vertex shader 2.x\n"); + create_vs2x_parser(&asm_ctx); + } + | VER_VS30 + { + TRACE("Vertex shader 3.0\n"); + create_vs30_parser(&asm_ctx); + } + | VER_PS10 + { + TRACE("Pixel shader 1.0\n"); + create_ps10_parser(&asm_ctx); + } + | VER_PS11 + { + TRACE("Pixel shader 1.1\n"); + create_ps11_parser(&asm_ctx); + } + | VER_PS12 + { + TRACE("Pixel shader 1.2\n"); + create_ps12_parser(&asm_ctx); + } + | VER_PS13 + { + TRACE("Pixel shader 1.3\n"); + create_ps13_parser(&asm_ctx); + } + | VER_PS14 + { + TRACE("Pixel shader 1.4\n"); + create_ps14_parser(&asm_ctx); + } + | VER_PS20 + { + TRACE("Pixel shader 2.0\n"); + create_ps20_parser(&asm_ctx); + } + | VER_PS2X + { + TRACE("Pixel shader 2.x\n"); + create_ps2x_parser(&asm_ctx); + } + | VER_PS30 + { + TRACE("Pixel shader 3.0\n"); + create_ps30_parser(&asm_ctx); + } + +instructions: /* empty */ + | instructions complexinstr + { + /* Nothing to do */ + } + +complexinstr: instruction + { + + } + | predicate instruction + { + TRACE("predicate\n"); + asm_ctx.funcs->predicate(&asm_ctx, &$1); + } + | '+' instruction + { + TRACE("coissue\n"); + asm_ctx.funcs->coissue(&asm_ctx); + } + +instruction: INSTR_ADD omods dreg ',' sregs + { + TRACE("ADD\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_ADD, $2.mod, $2.shift, 0, &$3, &$5, 2); + } + | INSTR_NOP + { + TRACE("NOP\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_NOP, 0, 0, 0, 0, 0, 0); + } + | INSTR_MOV omods dreg ',' sregs + { + TRACE("MOV\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_MOV, $2.mod, $2.shift, 0, &$3, &$5, 1); + } + | INSTR_SUB omods dreg ',' sregs + { + TRACE("SUB\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_SUB, $2.mod, $2.shift, 0, &$3, &$5, 2); + } + | INSTR_MAD omods dreg ',' sregs + { + TRACE("MAD\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_MAD, $2.mod, $2.shift, 0, &$3, &$5, 3); + } + | INSTR_MUL omods dreg ',' sregs + { + TRACE("MUL\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_MUL, $2.mod, $2.shift, 0, &$3, &$5, 2); + } + | INSTR_RCP omods dreg ',' sregs + { + TRACE("RCP\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_RCP, $2.mod, $2.shift, 0, &$3, &$5, 1); + } + | INSTR_RSQ omods dreg ',' sregs + { + TRACE("RSQ\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_RSQ, $2.mod, $2.shift, 0, &$3, &$5, 1); + } + | INSTR_DP3 omods dreg ',' sregs + { + TRACE("DP3\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_DP3, $2.mod, $2.shift, 0, &$3, &$5, 2); + } + | INSTR_DP4 omods dreg ',' sregs + { + TRACE("DP4\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_DP4, $2.mod, $2.shift, 0, &$3, &$5, 2); + } + | INSTR_MIN omods dreg ',' sregs + { + TRACE("MIN\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_MIN, $2.mod, $2.shift, 0, &$3, &$5, 2); + } + | INSTR_MAX omods dreg ',' sregs + { + TRACE("MAX\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_MAX, $2.mod, $2.shift, 0, &$3, &$5, 2); + } + | INSTR_SLT omods dreg ',' sregs + { + TRACE("SLT\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_SLT, $2.mod, $2.shift, 0, &$3, &$5, 2); + } + | INSTR_SGE omods dreg ',' sregs + { + TRACE("SGE\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_SGE, $2.mod, $2.shift, 0, &$3, &$5, 2); + } + | INSTR_ABS omods dreg ',' sregs + { + TRACE("ABS\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_ABS, $2.mod, $2.shift, 0, &$3, &$5, 1); + } + | INSTR_EXP omods dreg ',' sregs + { + TRACE("EXP\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_EXP, $2.mod, $2.shift, 0, &$3, &$5, 1); + } + | INSTR_LOG omods dreg ',' sregs + { + TRACE("LOG\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_LOG, $2.mod, $2.shift, 0, &$3, &$5, 1); + } + | INSTR_LOGP omods dreg ',' sregs + { + TRACE("LOGP\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_LOGP, $2.mod, $2.shift, 0, &$3, &$5, 1); + } + | INSTR_EXPP omods dreg ',' sregs + { + TRACE("EXPP\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_EXPP, $2.mod, $2.shift, 0, &$3, &$5, 1); + } + | INSTR_DST omods dreg ',' sregs + { + TRACE("DST\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_DST, $2.mod, $2.shift, 0, &$3, &$5, 2); + } + | INSTR_LRP omods dreg ',' sregs + { + TRACE("LRP\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_LRP, $2.mod, $2.shift, 0, &$3, &$5, 3); + } + | INSTR_FRC omods dreg ',' sregs + { + TRACE("FRC\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_FRC, $2.mod, $2.shift, 0, &$3, &$5, 1); + } + | INSTR_POW omods dreg ',' sregs + { + TRACE("POW\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_POW, $2.mod, $2.shift, 0, &$3, &$5, 2); + } + | INSTR_CRS omods dreg ',' sregs + { + TRACE("CRS\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_CRS, $2.mod, $2.shift, 0, &$3, &$5, 2); + } + | INSTR_SGN omods dreg ',' sregs + { + TRACE("SGN\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_SGN, $2.mod, $2.shift, 0, &$3, &$5, 3); + } + | INSTR_NRM omods dreg ',' sregs + { + TRACE("NRM\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_NRM, $2.mod, $2.shift, 0, &$3, &$5, 1); + } + | INSTR_SINCOS omods dreg ',' sregs + { + TRACE("SINCOS\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_SINCOS, $2.mod, $2.shift, 0, &$3, &$5, 1); + } + | INSTR_M4x4 omods dreg ',' sregs + { + TRACE("M4x4\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_M4x4, $2.mod, $2.shift, 0, &$3, &$5, 2); + } + | INSTR_M4x3 omods dreg ',' sregs + { + TRACE("M4x3\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_M4x3, $2.mod, $2.shift, 0, &$3, &$5, 2); + } + | INSTR_M3x4 omods dreg ',' sregs + { + TRACE("M3x4\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_M3x4, $2.mod, $2.shift, 0, &$3, &$5, 2); + } + | INSTR_M3x3 omods dreg ',' sregs + { + TRACE("M3x3\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_M3x3, $2.mod, $2.shift, 0, &$3, &$5, 2); + } + | INSTR_M3x2 omods dreg ',' sregs + { + TRACE("M3x2\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_M3x2, $2.mod, $2.shift, 0, &$3, &$5, 2); + } + | INSTR_DCL dclusage REG_OUTPUT + { + struct shader_reg reg; + TRACE("Output reg declaration\n"); + ZeroMemory(®, sizeof(reg)); + reg.type = BWRITERSPR_OUTPUT; + reg.regnum = $3; + reg.rel_reg = NULL; + reg.srcmod = 0; + reg.u.writemask = BWRITERSP_WRITEMASK_ALL; + asm_ctx.funcs->dcl_output(&asm_ctx, $2.dclusage, $2.regnum, ®); + } + | INSTR_DCL dclusage REG_OUTPUT writemask + { + struct shader_reg reg; + TRACE("Output reg declaration\n"); + ZeroMemory(®, sizeof(reg)); + reg.type = BWRITERSPR_OUTPUT; + reg.regnum = $3; + reg.rel_reg = NULL; + reg.srcmod = 0; + reg.u.writemask = $4; + asm_ctx.funcs->dcl_output(&asm_ctx, $2.dclusage, $2.regnum, ®); + } + | INSTR_DCL dclusage omods dcl_inputreg + { + struct shader_reg reg; + TRACE("Input reg declaration\n"); + if($3.shift != 0) { + asmparser_message(&asm_ctx, "Line %u: Shift modifier not allowed here\n", + asm_ctx.line_no); + set_parse_status(&asm_ctx.status, PARSE_ERR); + } + if(asm_ctx.shader->version == BWRITERPS_VERSION(2, 0) || + asm_ctx.shader->version == BWRITERPS_VERSION(2, 1)) { + asmparser_message(&asm_ctx, "Line %u: Declaration not supported in PS 2\n", + asm_ctx.line_no); + set_parse_status(&asm_ctx.status, PARSE_ERR); + } + ZeroMemory(®, sizeof(reg)); + reg.type = $4.type; + reg.regnum = $4.regnum; + reg.rel_reg = NULL; + reg.srcmod = 0; + reg.u.writemask = BWRITERSP_WRITEMASK_ALL; + asm_ctx.funcs->dcl_input(&asm_ctx, $2.dclusage, $2.regnum, $3.mod, ®); + } + | INSTR_DCL dclusage omods dcl_inputreg writemask + { + struct shader_reg reg; + TRACE("Input reg declaration\n"); + if($3.shift != 0) { + asmparser_message(&asm_ctx, "Line %u: Shift modifier not allowed here\n", + asm_ctx.line_no); + set_parse_status(&asm_ctx.status, PARSE_ERR); + } + if(asm_ctx.shader->version == BWRITERPS_VERSION(2, 0) || + asm_ctx.shader->version == BWRITERPS_VERSION(2, 1)) { + asmparser_message(&asm_ctx, "Line %u: Declaration not supported in PS 2\n", + asm_ctx.line_no); + set_parse_status(&asm_ctx.status, PARSE_ERR); + } + ZeroMemory(®, sizeof(reg)); + reg.type = $4.type; + reg.regnum = $4.regnum; + reg.rel_reg = NULL; + reg.srcmod = 0; + reg.u.writemask = $5; + asm_ctx.funcs->dcl_input(&asm_ctx, $2.dclusage, $2.regnum, $3.mod, ®); + } + | INSTR_DCL omods dcl_inputreg + { + struct shader_reg reg; + TRACE("Input reg declaration\n"); + if($2.shift != 0) { + asmparser_message(&asm_ctx, "Line %u: Shift modifier not allowed here\n", + asm_ctx.line_no); + set_parse_status(&asm_ctx.status, PARSE_ERR); + } + if(asm_ctx.shader->type != ST_PIXEL) { + asmparser_message(&asm_ctx, "Line %u: Declaration needs a semantic\n", + asm_ctx.line_no); + set_parse_status(&asm_ctx.status, PARSE_ERR); + } + ZeroMemory(®, sizeof(reg)); + reg.type = $3.type; + reg.regnum = $3.regnum; + reg.rel_reg = NULL; + reg.srcmod = 0; + reg.u.writemask = BWRITERSP_WRITEMASK_ALL; + asm_ctx.funcs->dcl_input(&asm_ctx, 0, 0, $2.mod, ®); + } + | INSTR_DCL omods dcl_inputreg writemask + { + struct shader_reg reg; + TRACE("Input reg declaration\n"); + if($2.shift != 0) { + asmparser_message(&asm_ctx, "Line %u: Shift modifier not allowed here\n", + asm_ctx.line_no); + set_parse_status(&asm_ctx.status, PARSE_ERR); + } + if(asm_ctx.shader->type != ST_PIXEL) { + asmparser_message(&asm_ctx, "Line %u: Declaration needs a semantic\n", + asm_ctx.line_no); + set_parse_status(&asm_ctx.status, PARSE_ERR); + } + ZeroMemory(®, sizeof(reg)); + reg.type = $3.type; + reg.regnum = $3.regnum; + reg.rel_reg = NULL; + reg.srcmod = 0; + reg.u.writemask = $4; + asm_ctx.funcs->dcl_input(&asm_ctx, 0, 0, $2.mod, ®); + } + | INSTR_DCL sampdcl omods REG_SAMPLER + { + TRACE("Sampler declared\n"); + if($3.shift != 0) { + asmparser_message(&asm_ctx, "Line %u: Shift modifier not allowed here\n", + asm_ctx.line_no); + set_parse_status(&asm_ctx.status, PARSE_ERR); + } + asm_ctx.funcs->dcl_sampler(&asm_ctx, $2, $3.mod, $4, asm_ctx.line_no); + } + | INSTR_DCL omods REG_SAMPLER + { + TRACE("Sampler declared\n"); + if($2.shift != 0) { + asmparser_message(&asm_ctx, "Line %u: Shift modifier not allowed here\n", + asm_ctx.line_no); + set_parse_status(&asm_ctx.status, PARSE_ERR); + } + if(asm_ctx.shader->type != ST_PIXEL) { + asmparser_message(&asm_ctx, "Line %u: Declaration needs a sampler type\n", + asm_ctx.line_no); + set_parse_status(&asm_ctx.status, PARSE_ERR); + } + asm_ctx.funcs->dcl_sampler(&asm_ctx, BWRITERSTT_UNKNOWN, $2.mod, $3, asm_ctx.line_no); + } + | INSTR_DCL sampdcl omods dcl_inputreg + { + TRACE("Error rule: sampler decl of input reg\n"); + asmparser_message(&asm_ctx, "Line %u: Sampler declarations of input regs is not valid\n", + asm_ctx.line_no); + set_parse_status(&asm_ctx.status, PARSE_WARN); + } + | INSTR_DCL sampdcl omods REG_OUTPUT + { + TRACE("Error rule: sampler decl of output reg\n"); + asmparser_message(&asm_ctx, "Line %u: Sampler declarations of output regs is not valid\n", + asm_ctx.line_no); + set_parse_status(&asm_ctx.status, PARSE_WARN); + } + | INSTR_DEF REG_CONSTFLOAT ',' IMMVAL ',' IMMVAL ',' IMMVAL ',' IMMVAL + { + asm_ctx.funcs->constF(&asm_ctx, $2, $4.val, $6.val, $8.val, $10.val); + } + | INSTR_DEFI REG_CONSTINT ',' IMMVAL ',' IMMVAL ',' IMMVAL ',' IMMVAL + { + asm_ctx.funcs->constI(&asm_ctx, $2, $4.val, $6.val, $8.val, $10.val); + } + | INSTR_DEFB REG_CONSTBOOL ',' IMMBOOL + { + asm_ctx.funcs->constB(&asm_ctx, $2, $4); + } + | INSTR_REP sregs + { + TRACE("REP\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_REP, 0, 0, 0, 0, &$2, 1); + } + | INSTR_ENDREP + { + TRACE("ENDREP\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_ENDREP, 0, 0, 0, 0, 0, 0); + } + | INSTR_IF sregs + { + TRACE("IF\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_IF, 0, 0, 0, 0, &$2, 1); + } + | INSTR_IF comp sregs + { + TRACE("IFC\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_IFC, 0, 0, $2, 0, &$3, 2); + } + | INSTR_ELSE + { + TRACE("ELSE\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_ELSE, 0, 0, 0, 0, 0, 0); + } + | INSTR_ENDIF + { + TRACE("ENDIF\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_ENDIF, 0, 0, 0, 0, 0, 0); + } + | INSTR_BREAK + { + TRACE("BREAK\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_BREAK, 0, 0, 0, 0, 0, 0); + } + | INSTR_BREAK comp sregs + { + TRACE("BREAKC\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_BREAKC, 0, 0, $2, 0, &$3, 2); + } + | INSTR_BREAKP sregs + { + TRACE("BREAKP\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_BREAKP, 0, 0, 0, 0, &$2, 1); + } + | INSTR_CALL sregs + { + TRACE("CALL\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_CALL, 0, 0, 0, 0, &$2, 1); + } + | INSTR_CALLNZ sregs + { + TRACE("CALLNZ\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_CALLNZ, 0, 0, 0, 0, &$2, 2); + } + | INSTR_LOOP sregs + { + TRACE("LOOP\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_LOOP, 0, 0, 0, 0, &$2, 2); + } + | INSTR_RET + { + TRACE("RET\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_RET, 0, 0, 0, 0, 0, 0); + } + | INSTR_ENDLOOP + { + TRACE("ENDLOOP\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_ENDLOOP, 0, 0, 0, 0, 0, 0); + } + | INSTR_LABEL sregs + { + TRACE("LABEL\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_LABEL, 0, 0, 0, 0, &$2, 1); + } + | INSTR_SETP comp dreg ',' sregs + { + TRACE("SETP\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_SETP, 0, 0, $2, &$3, &$5, 2); + } + | INSTR_TEXLDL omods dreg ',' sregs + { + TRACE("TEXLDL\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXLDL, $2.mod, $2.shift, 0, &$3, &$5, 2); + } + | INSTR_LIT omods dreg ',' sregs + { + TRACE("LIT\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_LIT, $2.mod, $2.shift, 0, &$3, &$5, 1); + } + | INSTR_MOVA omods dreg ',' sregs + { + TRACE("MOVA\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_MOVA, $2.mod, $2.shift, 0, &$3, &$5, 1); + } + | INSTR_CND omods dreg ',' sregs + { + TRACE("CND\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_CND, $2.mod, $2.shift, 0, &$3, &$5, 3); + } + | INSTR_CMP omods dreg ',' sregs + { + TRACE("CMP\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_CMP, $2.mod, $2.shift, 0, &$3, &$5, 3); + } + | INSTR_DP2ADD omods dreg ',' sregs + { + TRACE("DP2ADD\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_DP2ADD, $2.mod, $2.shift, 0, &$3, &$5, 3); + } + | INSTR_TEXCOORD omods dreg + { + TRACE("TEXCOORD\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXCOORD, $2.mod, $2.shift, 0, &$3, 0, 0); + } + | INSTR_TEXCRD omods dreg ',' sregs + { + TRACE("TEXCRD\n"); + /* texcoord and texcrd share the same opcode */ + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXCOORD, $2.mod, $2.shift, 0, &$3, &$5, 1); + } + | INSTR_TEXKILL dreg + { + TRACE("TEXKILL\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXKILL, 0, 0, 0, &$2, 0, 0); + } + | INSTR_TEX omods dreg + { + TRACE("TEX\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEX, $2.mod, $2.shift, 0, &$3, 0, 0); + } + | INSTR_TEXDEPTH omods dreg + { + TRACE("TEXDEPTH\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXDEPTH, $2.mod, $2.shift, 0, &$3, 0, 0); + } + | INSTR_TEXLD omods dreg ',' sregs + { + TRACE("TEXLD\n"); + /* There is more than one acceptable syntax for texld: + with 1 sreg (PS 1.4) or + with 2 sregs (PS 2.0+) + Moreover, texld shares the same opcode as the tex instruction, + so there are a total of 3 valid syntaxes + These variations are handled in asmparser.c */ + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEX, $2.mod, $2.shift, 0, &$3, &$5, 2); + } + | INSTR_TEXLDP omods dreg ',' sregs + { + TRACE("TEXLDP\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXLDP, $2.mod, $2.shift, 0, &$3, &$5, 2); + } + | INSTR_TEXLDB omods dreg ',' sregs + { + TRACE("TEXLDB\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXLDB, $2.mod, $2.shift, 0, &$3, &$5, 2); + } + | INSTR_TEXBEM omods dreg ',' sregs + { + TRACE("TEXBEM\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXBEM, $2.mod, $2.shift, 0, &$3, &$5, 1); + } + | INSTR_TEXBEML omods dreg ',' sregs + { + TRACE("TEXBEML\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXBEML, $2.mod, $2.shift, 0, &$3, &$5, 1); + } + | INSTR_TEXREG2AR omods dreg ',' sregs + { + TRACE("TEXREG2AR\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXREG2AR, $2.mod, $2.shift, 0, &$3, &$5, 1); + } + | INSTR_TEXREG2GB omods dreg ',' sregs + { + TRACE("TEXREG2GB\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXREG2GB, $2.mod, $2.shift, 0, &$3, &$5, 1); + } + | INSTR_TEXREG2RGB omods dreg ',' sregs + { + TRACE("TEXREG2RGB\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXREG2RGB, $2.mod, $2.shift, 0, &$3, &$5, 1); + } + | INSTR_TEXM3x2PAD omods dreg ',' sregs + { + TRACE("TEXM3x2PAD\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXM3x2PAD, $2.mod, $2.shift, 0, &$3, &$5, 1); + } + | INSTR_TEXM3x3PAD omods dreg ',' sregs + { + TRACE("INSTR_TEXM3x3PAD\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXM3x3PAD, $2.mod, $2.shift, 0, &$3, &$5, 1); + } + | INSTR_TEXM3x3SPEC omods dreg ',' sregs + { + TRACE("TEXM3x3SPEC\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXM3x3SPEC, $2.mod, $2.shift, 0, &$3, &$5, 2); + } + | INSTR_TEXM3x3VSPEC omods dreg ',' sregs + { + TRACE("TEXM3x3VSPEC\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXM3x3VSPEC, $2.mod, $2.shift, 0, &$3, &$5, 1); + } + | INSTR_TEXM3x3TEX omods dreg ',' sregs + { + TRACE("TEXM3x3TEX\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXM3x3TEX, $2.mod, $2.shift, 0, &$3, &$5, 1); + } + | INSTR_TEXDP3TEX omods dreg ',' sregs + { + TRACE("TEXDP3TEX\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXDP3TEX, $2.mod, $2.shift, 0, &$3, &$5, 1); + } + | INSTR_TEXM3x2DEPTH omods dreg ',' sregs + { + TRACE("TEXM3x2DEPTH\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXM3x2DEPTH, $2.mod, $2.shift, 0, &$3, &$5, 1); + } + | INSTR_TEXM3x2TEX omods dreg ',' sregs + { + TRACE("TEXM3x2TEX\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXM3x2TEX, $2.mod, $2.shift, 0, &$3, &$5, 1); + } + | INSTR_TEXDP3 omods dreg ',' sregs + { + TRACE("TEXDP3\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXDP3, $2.mod, $2.shift, 0, &$3, &$5, 1); + } + | INSTR_TEXM3x3 omods dreg ',' sregs + { + TRACE("TEXM3x3\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXM3x3, $2.mod, $2.shift, 0, &$3, &$5, 1); + } + | INSTR_BEM omods dreg ',' sregs + { + TRACE("BEM\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_BEM, $2.mod, $2.shift, 0, &$3, &$5, 2); + } + | INSTR_DSX omods dreg ',' sregs + { + TRACE("DSX\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_DSX, $2.mod, $2.shift, 0, &$3, &$5, 1); + } + | INSTR_DSY omods dreg ',' sregs + { + TRACE("DSY\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_DSY, $2.mod, $2.shift, 0, &$3, &$5, 1); + } + | INSTR_TEXLDD omods dreg ',' sregs + { + TRACE("TEXLDD\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXLDD, $2.mod, $2.shift, 0, &$3, &$5, 4); + } + | INSTR_PHASE + { + TRACE("PHASE\n"); + asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_PHASE, 0, 0, 0, 0, 0, 0); + } + + +dreg: dreg_name rel_reg + { + $$.regnum = $1.regnum; + $$.type = $1.type; + $$.u.writemask = BWRITERSP_WRITEMASK_ALL; + $$.srcmod = BWRITERSPSM_NONE; + set_rel_reg(&$$, &$2); + } + | dreg_name writemask + { + $$.regnum = $1.regnum; + $$.type = $1.type; + $$.u.writemask = $2; + $$.srcmod = BWRITERSPSM_NONE; + $$.rel_reg = NULL; + } + +dreg_name: REG_TEMP + { + $$.regnum = $1; $$.type = BWRITERSPR_TEMP; + } + | REG_OUTPUT + { + $$.regnum = $1; $$.type = BWRITERSPR_OUTPUT; + } + | REG_INPUT + { + $$.regnum = $1; $$.type = BWRITERSPR_INPUT; + } + | REG_CONSTFLOAT + { + asmparser_message(&asm_ctx, "Line %u: Register c%u is not a valid destination register\n", + asm_ctx.line_no, $1); + set_parse_status(&asm_ctx.status, PARSE_WARN); + } + | REG_CONSTINT + { + asmparser_message(&asm_ctx, "Line %u: Register i%u is not a valid destination register\n", + asm_ctx.line_no, $1); + set_parse_status(&asm_ctx.status, PARSE_WARN); + } + | REG_CONSTBOOL + { + asmparser_message(&asm_ctx, "Line %u: Register b%u is not a valid destination register\n", + asm_ctx.line_no, $1); + set_parse_status(&asm_ctx.status, PARSE_WARN); + } + | REG_TEXTURE + { + $$.regnum = $1; $$.type = BWRITERSPR_TEXTURE; + } + | REG_TEXCRDOUT + { + $$.regnum = $1; $$.type = BWRITERSPR_TEXCRDOUT; + } + | REG_SAMPLER + { + asmparser_message(&asm_ctx, "Line %u: Register s%u is not a valid destination register\n", + asm_ctx.line_no, $1); + set_parse_status(&asm_ctx.status, PARSE_WARN); + } + | REG_OPOS + { + $$.regnum = BWRITERSRO_POSITION; $$.type = BWRITERSPR_RASTOUT; + } + | REG_OPTS + { + $$.regnum = BWRITERSRO_POINT_SIZE; $$.type = BWRITERSPR_RASTOUT; + } + | REG_OFOG + { + $$.regnum = BWRITERSRO_FOG; $$.type = BWRITERSPR_RASTOUT; + } + | REG_VERTEXCOLOR + { + $$.regnum = $1; $$.type = BWRITERSPR_ATTROUT; + } + | REG_FRAGCOLOR + { + $$.regnum = $1; $$.type = BWRITERSPR_COLOROUT; + } + | REG_FRAGDEPTH + { + $$.regnum = 0; $$.type = BWRITERSPR_DEPTHOUT; + } + | REG_PREDICATE + { + $$.regnum = 0; $$.type = BWRITERSPR_PREDICATE; + } + | REG_VPOS + { + asmparser_message(&asm_ctx, "Line %u: Register vPos is not a valid destination register\n", + asm_ctx.line_no); + set_parse_status(&asm_ctx.status, PARSE_WARN); + } + | REG_VFACE + { + asmparser_message(&asm_ctx, "Line %u: Register vFace is not a valid destination register\n", + asm_ctx.line_no); + set_parse_status(&asm_ctx.status, PARSE_WARN); + } + | REG_ADDRESS + { + /* index 0 is hardcoded for the addr register */ + $$.regnum = 0; $$.type = BWRITERSPR_ADDR; + } + | REG_LOOP + { + asmparser_message(&asm_ctx, "Line %u: Register aL is not a valid destination register\n", + asm_ctx.line_no); + set_parse_status(&asm_ctx.status, PARSE_WARN); + } + +writemask: '.' wm_components + { + if($2.writemask == SWIZZLE_ERR) { + asmparser_message(&asm_ctx, "Line %u: Invalid writemask specified\n", + asm_ctx.line_no); + set_parse_status(&asm_ctx.status, PARSE_ERR); + /* Provide a correct writemask to prevent following complaints */ + $$ = BWRITERSP_WRITEMASK_ALL; + } + else { + $$ = $2.writemask; + TRACE("Writemask: %x\n", $$); + } + } + +wm_components: COMPONENT + { + $$.writemask = 1 << $1; + $$.last = $1; + $$.idx = 1; + } + | wm_components COMPONENT + { + if($1.writemask == SWIZZLE_ERR || $1.idx == 4) + /* Wrong writemask */ + $$.writemask = SWIZZLE_ERR; + else { + if($2 <= $1.last) + $$.writemask = SWIZZLE_ERR; + else { + $$.writemask = $1.writemask | (1 << $2); + $$.idx = $1.idx + 1; + } + } + } + +swizzle: /* empty */ + { + $$ = BWRITERVS_NOSWIZZLE; + TRACE("Default swizzle: %08x\n", $$); + } + | '.' sw_components + { + if($2.swizzle == SWIZZLE_ERR) { + asmparser_message(&asm_ctx, "Line %u: Invalid swizzle\n", + asm_ctx.line_no); + set_parse_status(&asm_ctx.status, PARSE_ERR); + /* Provide a correct swizzle to prevent following complaints */ + $$ = BWRITERVS_NOSWIZZLE; + } + else { + DWORD last, i; + + $$ = $2.swizzle << BWRITERVS_SWIZZLE_SHIFT; + /* Fill the swizzle by extending the last component */ + last = ($2.swizzle >> 2 * ($2.idx - 1)) & 0x03; + for(i = $2.idx; i < 4; i++){ + $$ |= last << (BWRITERVS_SWIZZLE_SHIFT + 2 * i); + } + TRACE("Got a swizzle: %08x\n", $$); + } + } + +sw_components: COMPONENT + { + $$.swizzle = $1; + $$.idx = 1; + } + | sw_components COMPONENT + { + if($1.idx == 4) { + /* Too many sw_components */ + $$.swizzle = SWIZZLE_ERR; + $$.idx = 4; + } + else { + $$.swizzle = $1.swizzle | ($2 << 2 * $1.idx); + $$.idx = $1.idx + 1; + } + } + +omods: /* Empty */ + { + $$.mod = 0; + $$.shift = 0; + } + | omods omodifier + { + $$.mod = $1.mod | $2.mod; + if($1.shift && $2.shift) { + asmparser_message(&asm_ctx, "Line %u: More than one shift flag\n", + asm_ctx.line_no); + set_parse_status(&asm_ctx.status, PARSE_ERR); + $$.shift = $1.shift; + } else { + $$.shift = $1.shift | $2.shift; + } + } + +omodifier: SHIFT_X2 + { + $$.mod = 0; + $$.shift = 1; + } + | SHIFT_X4 + { + $$.mod = 0; + $$.shift = 2; + } + | SHIFT_X8 + { + $$.mod = 0; + $$.shift = 3; + } + | SHIFT_D2 + { + $$.mod = 0; + $$.shift = 15; + } + | SHIFT_D4 + { + $$.mod = 0; + $$.shift = 14; + } + | SHIFT_D8 + { + $$.mod = 0; + $$.shift = 13; + } + | MOD_SAT + { + $$.mod = BWRITERSPDM_SATURATE; + $$.shift = 0; + } + | MOD_PP + { + $$.mod = BWRITERSPDM_PARTIALPRECISION; + $$.shift = 0; + } + | MOD_CENTROID + { + $$.mod = BWRITERSPDM_MSAMPCENTROID; + $$.shift = 0; + } + +sregs: sreg + { + $$.reg[0] = $1; + $$.count = 1; + } + | sregs ',' sreg + { + if($$.count == MAX_SRC_REGS){ + asmparser_message(&asm_ctx, "Line %u: Too many source registers in this instruction\n", + asm_ctx.line_no); + set_parse_status(&asm_ctx.status, PARSE_ERR); + } + else + $$.reg[$$.count++] = $3; + } + +sreg: sreg_name rel_reg swizzle + { + $$.type = $1.type; + $$.regnum = $1.regnum; + $$.u.swizzle = $3; + $$.srcmod = BWRITERSPSM_NONE; + set_rel_reg(&$$, &$2); + } + | sreg_name rel_reg smod swizzle + { + $$.type = $1.type; + $$.regnum = $1.regnum; + set_rel_reg(&$$, &$2); + $$.srcmod = $3; + $$.u.swizzle = $4; + } + | '-' sreg_name rel_reg swizzle + { + $$.type = $2.type; + $$.regnum = $2.regnum; + $$.srcmod = BWRITERSPSM_NEG; + set_rel_reg(&$$, &$3); + $$.u.swizzle = $4; + } + | '-' sreg_name rel_reg smod swizzle + { + $$.type = $2.type; + $$.regnum = $2.regnum; + set_rel_reg(&$$, &$3); + switch($4) { + case BWRITERSPSM_BIAS: $$.srcmod = BWRITERSPSM_BIASNEG; break; + case BWRITERSPSM_X2: $$.srcmod = BWRITERSPSM_X2NEG; break; + case BWRITERSPSM_SIGN: $$.srcmod = BWRITERSPSM_SIGNNEG; break; + case BWRITERSPSM_ABS: $$.srcmod = BWRITERSPSM_ABSNEG; break; + case BWRITERSPSM_DZ: + asmparser_message(&asm_ctx, "Line %u: Incompatible source modifiers: NEG and DZ\n", + asm_ctx.line_no); + set_parse_status(&asm_ctx.status, PARSE_ERR); + break; + case BWRITERSPSM_DW: + asmparser_message(&asm_ctx, "Line %u: Incompatible source modifiers: NEG and DW\n", + asm_ctx.line_no); + set_parse_status(&asm_ctx.status, PARSE_ERR); + break; + default: + FIXME("Unhandled combination of NEGATE and %u\n", $4); + } + $$.u.swizzle = $5; + } + | IMMVAL '-' sreg_name rel_reg swizzle + { + if($1.val != 1.0 || (!$1.integer)) { + asmparser_message(&asm_ctx, "Line %u: Only \"1 - reg\" is valid for D3DSPSM_COMP, " + "%g - reg found\n", asm_ctx.line_no, $1.val); + set_parse_status(&asm_ctx.status, PARSE_ERR); + } + /* Complement - not compatible with other source modifiers */ + $$.type = $3.type; + $$.regnum = $3.regnum; + $$.srcmod = BWRITERSPSM_COMP; + set_rel_reg(&$$, &$4); + $$.u.swizzle = $5; + } + | IMMVAL '-' sreg_name rel_reg smod swizzle + { + /* For nicer error reporting */ + if($1.val != 1.0 || (!$1.integer)) { + asmparser_message(&asm_ctx, "Line %u: Only \"1 - reg\" is valid for D3DSPSM_COMP\n", + asm_ctx.line_no); + set_parse_status(&asm_ctx.status, PARSE_ERR); + } else { + asmparser_message(&asm_ctx, "Line %u: Incompatible source modifiers: D3DSPSM_COMP and %s\n", + asm_ctx.line_no, + debug_print_srcmod($5)); + set_parse_status(&asm_ctx.status, PARSE_ERR); + } + } + | SMOD_NOT sreg_name swizzle + { + $$.type = $2.type; + $$.regnum = $2.regnum; + $$.rel_reg = NULL; + $$.srcmod = BWRITERSPSM_NOT; + $$.u.swizzle = $3; + } + +rel_reg: /* empty */ + { + $$.has_rel_reg = FALSE; + $$.additional_offset = 0; + } + | '[' immsum ']' + { + $$.has_rel_reg = FALSE; + $$.additional_offset = $2.val; + } + | '[' relreg_name swizzle ']' + { + $$.has_rel_reg = TRUE; + $$.type = $2.type; + $$.additional_offset = 0; + $$.rel_regnum = $2.regnum; + $$.swizzle = $3; + } + | '[' immsum '+' relreg_name swizzle ']' + { + $$.has_rel_reg = TRUE; + $$.type = $4.type; + $$.additional_offset = $2.val; + $$.rel_regnum = $4.regnum; + $$.swizzle = $5; + } + | '[' relreg_name swizzle '+' immsum ']' + { + $$.has_rel_reg = TRUE; + $$.type = $2.type; + $$.additional_offset = $5.val; + $$.rel_regnum = $2.regnum; + $$.swizzle = $3; + } + | '[' immsum '+' relreg_name swizzle '+' immsum ']' + { + $$.has_rel_reg = TRUE; + $$.type = $4.type; + $$.additional_offset = $2.val + $7.val; + $$.rel_regnum = $4.regnum; + $$.swizzle = $5; + } + +immsum: IMMVAL + { + if(!$1.integer) { + asmparser_message(&asm_ctx, "Line %u: Unexpected float %f\n", + asm_ctx.line_no, $1.val); + set_parse_status(&asm_ctx.status, PARSE_ERR); + } + $$.val = $1.val; + } + | immsum '+' IMMVAL + { + if(!$3.integer) { + asmparser_message(&asm_ctx, "Line %u: Unexpected float %f\n", + asm_ctx.line_no, $3.val); + set_parse_status(&asm_ctx.status, PARSE_ERR); + } + $$.val = $1.val + $3.val; + } + +smod: SMOD_BIAS + { + $$ = BWRITERSPSM_BIAS; + } + | SHIFT_X2 + { + $$ = BWRITERSPSM_X2; + } + | SMOD_SCALEBIAS + { + $$ = BWRITERSPSM_SIGN; + } + | SMOD_DZ + { + $$ = BWRITERSPSM_DZ; + } + | SMOD_DW + { + $$ = BWRITERSPSM_DW; + } + | SMOD_ABS + { + $$ = BWRITERSPSM_ABS; + } + +relreg_name: REG_ADDRESS + { + $$.regnum = 0; $$.type = BWRITERSPR_ADDR; + } + | REG_LOOP + { + $$.regnum = 0; $$.type = BWRITERSPR_LOOP; + } + +sreg_name: REG_TEMP + { + $$.regnum = $1; $$.type = BWRITERSPR_TEMP; + } + | REG_OUTPUT + { + asmparser_message(&asm_ctx, "Line %u: Register o%u is not a valid source register\n", + asm_ctx.line_no, $1); + set_parse_status(&asm_ctx.status, PARSE_WARN); + } + | REG_INPUT + { + $$.regnum = $1; $$.type = BWRITERSPR_INPUT; + } + | REG_CONSTFLOAT + { + $$.regnum = $1; $$.type = BWRITERSPR_CONST; + } + | REG_CONSTINT + { + $$.regnum = $1; $$.type = BWRITERSPR_CONSTINT; + } + | REG_CONSTBOOL + { + $$.regnum = $1; $$.type = BWRITERSPR_CONSTBOOL; + } + | REG_TEXTURE + { + $$.regnum = $1; $$.type = BWRITERSPR_TEXTURE; + } + | REG_TEXCRDOUT + { + asmparser_message(&asm_ctx, "Line %u: Register oT%u is not a valid source register\n", + asm_ctx.line_no, $1); + set_parse_status(&asm_ctx.status, PARSE_WARN); + } + | REG_SAMPLER + { + $$.regnum = $1; $$.type = BWRITERSPR_SAMPLER; + } + | REG_OPOS + { + asmparser_message(&asm_ctx, "Line %u: Register oPos is not a valid source register\n", + asm_ctx.line_no); + set_parse_status(&asm_ctx.status, PARSE_WARN); + } + | REG_OFOG + { + asmparser_message(&asm_ctx, "Line %u: Register oFog is not a valid source register\n", + asm_ctx.line_no); + set_parse_status(&asm_ctx.status, PARSE_WARN); + } + | REG_VERTEXCOLOR + { + asmparser_message(&asm_ctx, "Line %u: Register oD%u is not a valid source register\n", + asm_ctx.line_no, $1); + set_parse_status(&asm_ctx.status, PARSE_WARN); + } + | REG_FRAGCOLOR + { + asmparser_message(&asm_ctx, "Line %u: Register oC%u is not a valid source register\n", + asm_ctx.line_no, $1); + set_parse_status(&asm_ctx.status, PARSE_WARN); + } + | REG_FRAGDEPTH + { + asmparser_message(&asm_ctx, "Line %u: Register oDepth is not a valid source register\n", + asm_ctx.line_no); + set_parse_status(&asm_ctx.status, PARSE_WARN); + } + | REG_PREDICATE + { + $$.regnum = 0; $$.type = BWRITERSPR_PREDICATE; + } + | REG_VPOS + { + $$.regnum = 0; $$.type = BWRITERSPR_MISCTYPE; + } + | REG_VFACE + { + $$.regnum = 1; $$.type = BWRITERSPR_MISCTYPE; + } + | REG_ADDRESS + { + $$.regnum = 0; $$.type = BWRITERSPR_ADDR; + } + | REG_LOOP + { + $$.regnum = 0; $$.type = BWRITERSPR_LOOP; + } + | REG_LABEL + { + $$.regnum = $1; $$.type = BWRITERSPR_LABEL; + } + +comp: COMP_GT { $$ = BWRITER_COMPARISON_GT; } + | COMP_LT { $$ = BWRITER_COMPARISON_LT; } + | COMP_GE { $$ = BWRITER_COMPARISON_GE; } + | COMP_LE { $$ = BWRITER_COMPARISON_LE; } + | COMP_EQ { $$ = BWRITER_COMPARISON_EQ; } + | COMP_NE { $$ = BWRITER_COMPARISON_NE; } + +dclusage: USAGE_POSITION + { + TRACE("dcl_position%u\n", $1); + $$.regnum = $1; + $$.dclusage = BWRITERDECLUSAGE_POSITION; + } + | USAGE_BLENDWEIGHT + { + TRACE("dcl_blendweight%u\n", $1); + $$.regnum = $1; + $$.dclusage = BWRITERDECLUSAGE_BLENDWEIGHT; + } + | USAGE_BLENDINDICES + { + TRACE("dcl_blendindices%u\n", $1); + $$.regnum = $1; + $$.dclusage = BWRITERDECLUSAGE_BLENDINDICES; + } + | USAGE_NORMAL + { + TRACE("dcl_normal%u\n", $1); + $$.regnum = $1; + $$.dclusage = BWRITERDECLUSAGE_NORMAL; + } + | USAGE_PSIZE + { + TRACE("dcl_psize%u\n", $1); + $$.regnum = $1; + $$.dclusage = BWRITERDECLUSAGE_PSIZE; + } + | USAGE_TEXCOORD + { + TRACE("dcl_texcoord%u\n", $1); + $$.regnum = $1; + $$.dclusage = BWRITERDECLUSAGE_TEXCOORD; + } + | USAGE_TANGENT + { + TRACE("dcl_tangent%u\n", $1); + $$.regnum = $1; + $$.dclusage = BWRITERDECLUSAGE_TANGENT; + } + | USAGE_BINORMAL + { + TRACE("dcl_binormal%u\n", $1); + $$.regnum = $1; + $$.dclusage = BWRITERDECLUSAGE_BINORMAL; + } + | USAGE_TESSFACTOR + { + TRACE("dcl_tessfactor%u\n", $1); + $$.regnum = $1; + $$.dclusage = BWRITERDECLUSAGE_TESSFACTOR; + } + | USAGE_POSITIONT + { + TRACE("dcl_positiont%u\n", $1); + $$.regnum = $1; + $$.dclusage = BWRITERDECLUSAGE_POSITIONT; + } + | USAGE_COLOR + { + TRACE("dcl_color%u\n", $1); + $$.regnum = $1; + $$.dclusage = BWRITERDECLUSAGE_COLOR; + } + | USAGE_FOG + { + TRACE("dcl_fog%u\n", $1); + $$.regnum = $1; + $$.dclusage = BWRITERDECLUSAGE_FOG; + } + | USAGE_DEPTH + { + TRACE("dcl_depth%u\n", $1); + $$.regnum = $1; + $$.dclusage = BWRITERDECLUSAGE_DEPTH; + } + | USAGE_SAMPLE + { + TRACE("dcl_sample%u\n", $1); + $$.regnum = $1; + $$.dclusage = BWRITERDECLUSAGE_SAMPLE; + } + +dcl_inputreg: REG_INPUT + { + $$.regnum = $1; $$.type = BWRITERSPR_INPUT; + } + | REG_TEXTURE + { + $$.regnum = $1; $$.type = BWRITERSPR_TEXTURE; + } + +sampdcl: SAMPTYPE_1D + { + $$ = BWRITERSTT_1D; + } + | SAMPTYPE_2D + { + $$ = BWRITERSTT_2D; + } + | SAMPTYPE_CUBE + { + $$ = BWRITERSTT_CUBE; + } + | SAMPTYPE_VOLUME + { + $$ = BWRITERSTT_VOLUME; + } + +predicate: '(' REG_PREDICATE swizzle ')' + { + $$.type = BWRITERSPR_PREDICATE; + $$.regnum = 0; + $$.rel_reg = NULL; + $$.srcmod = BWRITERSPSM_NONE; + $$.u.swizzle = $3; + } + | '(' SMOD_NOT REG_PREDICATE swizzle ')' + { + $$.type = BWRITERSPR_PREDICATE; + $$.regnum = 0; + $$.rel_reg = NULL; + $$.srcmod = BWRITERSPSM_NOT; + $$.u.swizzle = $4; + } + +%% + +struct bwriter_shader *parse_asm_shader(char **messages) +{ + struct bwriter_shader *ret = NULL; + + asm_ctx.shader = NULL; + asm_ctx.status = PARSE_SUCCESS; + asm_ctx.messages.size = asm_ctx.messages.capacity = 0; + asm_ctx.line_no = 1; + + asmshader_parse(); + + if (asm_ctx.status != PARSE_ERR) + ret = asm_ctx.shader; + else if (asm_ctx.shader) + SlDeleteShader(asm_ctx.shader); + + if (messages) + { + if (asm_ctx.messages.size) + { + /* Shrink the buffer to the used size */ + *messages = d3dcompiler_realloc(asm_ctx.messages.string, asm_ctx.messages.size + 1); + if (!*messages) + { + ERR("Out of memory, no messages reported\n"); + d3dcompiler_free(asm_ctx.messages.string); + } + } + else + { + *messages = NULL; + } + } + else + { + if (asm_ctx.messages.capacity) + d3dcompiler_free(asm_ctx.messages.string); + } + + return ret; +} diff --git a/reactos/dll/directx/wine/d3dcompiler_43/asmshader.yy.c b/reactos/dll/directx/wine/d3dcompiler_43/asmshader.yy.c new file mode 100644 index 00000000000..1b31cec460f --- /dev/null +++ b/reactos/dll/directx/wine/d3dcompiler_43/asmshader.yy.c @@ -0,0 +1,3183 @@ +#line 2 "asmshader.yy.c" + +#line 4 "asmshader.yy.c" + +#define YY_INT_ALIGNED short int + +/* A lexical scanner generated by flex */ + +#define yy_create_buffer asmshader__create_buffer +#define yy_delete_buffer asmshader__delete_buffer +#define yy_flex_debug asmshader__flex_debug +#define yy_init_buffer asmshader__init_buffer +#define yy_flush_buffer asmshader__flush_buffer +#define yy_load_buffer_state asmshader__load_buffer_state +#define yy_switch_to_buffer asmshader__switch_to_buffer +#define yyin asmshader_in +#define yyleng asmshader_leng +#define yylex asmshader_lex +#define yylineno asmshader_lineno +#define yyout asmshader_out +#define yyrestart asmshader_restart +#define yytext asmshader_text +#define yywrap asmshader_wrap +#define yyalloc asmshader_alloc +#define yyrealloc asmshader_realloc +#define yyfree asmshader_free + +#define FLEX_SCANNER +#define YY_FLEX_MAJOR_VERSION 2 +#define YY_FLEX_MINOR_VERSION 5 +#define YY_FLEX_SUBMINOR_VERSION 35 +#if YY_FLEX_SUBMINOR_VERSION > 0 +#define FLEX_BETA +#endif + +/* First, we deal with platform-specific or compiler-specific issues. */ + +/* begin standard C headers. */ +#include +#include +#include +#include + +/* end standard C headers. */ + +/* flex integer type definitions */ + +#ifndef FLEXINT_H +#define FLEXINT_H + +/* C99 systems have . Non-C99 systems may or may not. */ + +#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + +/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, + * if you want the limit (max/min) macros for int types. + */ +#ifndef __STDC_LIMIT_MACROS +#define __STDC_LIMIT_MACROS 1 +#endif + +#include +typedef int8_t flex_int8_t; +typedef uint8_t flex_uint8_t; +typedef int16_t flex_int16_t; +typedef uint16_t flex_uint16_t; +typedef int32_t flex_int32_t; +typedef uint32_t flex_uint32_t; +#else +typedef signed char flex_int8_t; +typedef short int flex_int16_t; +typedef int flex_int32_t; +typedef unsigned char flex_uint8_t; +typedef unsigned short int flex_uint16_t; +typedef unsigned int flex_uint32_t; + +/* Limits of integral types. */ +#ifndef INT8_MIN +#define INT8_MIN (-128) +#endif +#ifndef INT16_MIN +#define INT16_MIN (-32767-1) +#endif +#ifndef INT32_MIN +#define INT32_MIN (-2147483647-1) +#endif +#ifndef INT8_MAX +#define INT8_MAX (127) +#endif +#ifndef INT16_MAX +#define INT16_MAX (32767) +#endif +#ifndef INT32_MAX +#define INT32_MAX (2147483647) +#endif +#ifndef UINT8_MAX +#define UINT8_MAX (255U) +#endif +#ifndef UINT16_MAX +#define UINT16_MAX (65535U) +#endif +#ifndef UINT32_MAX +#define UINT32_MAX (4294967295U) +#endif + +#endif /* ! C99 */ + +#endif /* ! FLEXINT_H */ + +#ifdef __cplusplus + +/* The "const" storage-class-modifier is valid. */ +#define YY_USE_CONST + +#else /* ! __cplusplus */ + +/* C99 requires __STDC__ to be defined as 1. */ +#if defined (__STDC__) + +#define YY_USE_CONST + +#endif /* defined (__STDC__) */ +#endif /* ! __cplusplus */ + +#ifdef YY_USE_CONST +#define yyconst const +#else +#define yyconst +#endif + +/* Returned upon end-of-file. */ +#define YY_NULL 0 + +/* Promotes a possibly negative, possibly signed char to an unsigned + * integer for use as an array index. If the signed char is negative, + * we want to instead treat it as an 8-bit unsigned char, hence the + * double cast. + */ +#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c) + +/* Enter a start condition. This macro really ought to take a parameter, + * but we do it the disgusting crufty way forced on us by the ()-less + * definition of BEGIN. + */ +#define BEGIN (yy_start) = 1 + 2 * + +/* Translate the current start state into a value that can be later handed + * to BEGIN to return to the state. The YYSTATE alias is for lex + * compatibility. + */ +#define YY_START (((yy_start) - 1) / 2) +#define YYSTATE YY_START + +/* Action number for EOF rule of a given start state. */ +#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) + +/* Special action meaning "start processing a new file". */ +#define YY_NEW_FILE asmshader_restart(asmshader_in ) + +#define YY_END_OF_BUFFER_CHAR 0 + +/* Size of default input buffer. */ +#ifndef YY_BUF_SIZE +#ifdef __ia64__ +/* On IA-64, the buffer size is 16k, not 8k. + * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case. + * Ditto for the __ia64__ case accordingly. + */ +#define YY_BUF_SIZE 32768 +#else +#define YY_BUF_SIZE 16384 +#endif /* __ia64__ */ +#endif + +/* The state buf must be large enough to hold one state per character in the main buffer. + */ +#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type)) + +#ifndef YY_TYPEDEF_YY_BUFFER_STATE +#define YY_TYPEDEF_YY_BUFFER_STATE +typedef struct yy_buffer_state *YY_BUFFER_STATE; +#endif + +extern int asmshader_leng; + +extern FILE *asmshader_in, *asmshader_out; + +#define EOB_ACT_CONTINUE_SCAN 0 +#define EOB_ACT_END_OF_FILE 1 +#define EOB_ACT_LAST_MATCH 2 + + #define YY_LESS_LINENO(n) + +/* Return all but the first "n" matched characters back to the input stream. */ +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up asmshader_text. */ \ + int yyless_macro_arg = (n); \ + YY_LESS_LINENO(yyless_macro_arg);\ + *yy_cp = (yy_hold_char); \ + YY_RESTORE_YY_MORE_OFFSET \ + (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ + YY_DO_BEFORE_ACTION; /* set up asmshader_text again */ \ + } \ + while ( 0 ) + +#define unput(c) yyunput( c, (yytext_ptr) ) + +#ifndef YY_TYPEDEF_YY_SIZE_T +#define YY_TYPEDEF_YY_SIZE_T +typedef size_t yy_size_t; +#endif + +#ifndef YY_STRUCT_YY_BUFFER_STATE +#define YY_STRUCT_YY_BUFFER_STATE +struct yy_buffer_state + { + FILE *yy_input_file; + + char *yy_ch_buf; /* input buffer */ + char *yy_buf_pos; /* current position in input buffer */ + + /* Size of input buffer in bytes, not including room for EOB + * characters. + */ + yy_size_t yy_buf_size; + + /* Number of characters read into yy_ch_buf, not including EOB + * characters. + */ + int yy_n_chars; + + /* Whether we "own" the buffer - i.e., we know we created it, + * and can realloc() it to grow it, and should free() it to + * delete it. + */ + int yy_is_our_buffer; + + /* Whether this is an "interactive" input source; if so, and + * if we're using stdio for input, then we want to use getc() + * instead of fread(), to make sure we stop fetching input after + * each newline. + */ + int yy_is_interactive; + + /* Whether we're considered to be at the beginning of a line. + * If so, '^' rules will be active on the next match, otherwise + * not. + */ + int yy_at_bol; + + int yy_bs_lineno; /**< The line count. */ + int yy_bs_column; /**< The column count. */ + + /* Whether to try to fill the input buffer when we reach the + * end of it. + */ + int yy_fill_buffer; + + int yy_buffer_status; + +#define YY_BUFFER_NEW 0 +#define YY_BUFFER_NORMAL 1 + /* When an EOF's been seen but there's still some text to process + * then we mark the buffer as YY_EOF_PENDING, to indicate that we + * shouldn't try reading from the input source any more. We might + * still have a bunch of tokens to match, though, because of + * possible backing-up. + * + * When we actually see the EOF, we change the status to "new" + * (via asmshader_restart()), so that the user can continue scanning by + * just pointing asmshader_in at a new input file. + */ +#define YY_BUFFER_EOF_PENDING 2 + + }; +#endif /* !YY_STRUCT_YY_BUFFER_STATE */ + +/* Stack of input buffers. */ +static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */ +static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */ +static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */ + +/* We provide macros for accessing buffer states in case in the + * future we want to put the buffer states in a more general + * "scanner state". + * + * Returns the top of the stack, or NULL. + */ +#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \ + ? (yy_buffer_stack)[(yy_buffer_stack_top)] \ + : NULL) + +/* Same as previous macro, but useful when we know that the buffer stack is not + * NULL or when we need an lvalue. For internal use only. + */ +#define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)] + +/* yy_hold_char holds the character lost when asmshader_text is formed. */ +static char yy_hold_char; +static int yy_n_chars; /* number of characters read into yy_ch_buf */ +int asmshader_leng; + +/* Points to current character in buffer. */ +static char *yy_c_buf_p = (char *) 0; +static int yy_init = 0; /* whether we need to initialize */ +static int yy_start = 0; /* start state number */ + +/* Flag which is used to allow asmshader_wrap()'s to do buffer switches + * instead of setting up a fresh asmshader_in. A bit of a hack ... + */ +static int yy_did_buffer_switch_on_eof; + +void asmshader_restart (FILE *input_file ); +void asmshader__switch_to_buffer (YY_BUFFER_STATE new_buffer ); +YY_BUFFER_STATE asmshader__create_buffer (FILE *file,int size ); +void asmshader__delete_buffer (YY_BUFFER_STATE b ); +void asmshader__flush_buffer (YY_BUFFER_STATE b ); +void asmshader_push_buffer_state (YY_BUFFER_STATE new_buffer ); +void asmshader_pop_buffer_state (void ); + +static void asmshader_ensure_buffer_stack (void ); +static void asmshader__load_buffer_state (void ); +static void asmshader__init_buffer (YY_BUFFER_STATE b,FILE *file ); + +#define YY_FLUSH_BUFFER asmshader__flush_buffer(YY_CURRENT_BUFFER ) + +YY_BUFFER_STATE asmshader__scan_buffer (char *base,yy_size_t size ); +YY_BUFFER_STATE asmshader__scan_string (yyconst char *yy_str ); +YY_BUFFER_STATE asmshader__scan_bytes (yyconst char *bytes,int len ); + +void *asmshader_alloc (yy_size_t ); +void *asmshader_realloc (void *,yy_size_t ); +void asmshader_free (void * ); + +#define yy_new_buffer asmshader__create_buffer + +#define yy_set_interactive(is_interactive) \ + { \ + if ( ! YY_CURRENT_BUFFER ){ \ + asmshader_ensure_buffer_stack (); \ + YY_CURRENT_BUFFER_LVALUE = \ + asmshader__create_buffer(asmshader_in,YY_BUF_SIZE ); \ + } \ + YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ + } + +#define yy_set_bol(at_bol) \ + { \ + if ( ! YY_CURRENT_BUFFER ){\ + asmshader_ensure_buffer_stack (); \ + YY_CURRENT_BUFFER_LVALUE = \ + asmshader__create_buffer(asmshader_in,YY_BUF_SIZE ); \ + } \ + YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ + } + +#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol) + +/* Begin user sect3 */ + +#define asmshader_wrap(n) 1 +#define YY_SKIP_YYWRAP + +typedef unsigned char YY_CHAR; + +FILE *asmshader_in = (FILE *) 0, *asmshader_out = (FILE *) 0; + +typedef int yy_state_type; + +extern int asmshader_lineno; + +int asmshader_lineno = 1; + +extern char *asmshader_text; +#define yytext_ptr asmshader_text + +static yy_state_type yy_get_previous_state (void ); +static yy_state_type yy_try_NUL_trans (yy_state_type current_state ); +static int yy_get_next_buffer (void ); +static void yy_fatal_error (yyconst char msg[] ); + +/* Done after the current pattern has been matched and before the + * corresponding action - sets up asmshader_text. + */ +#define YY_DO_BEFORE_ACTION \ + (yytext_ptr) = yy_bp; \ + asmshader_leng = (size_t) (yy_cp - yy_bp); \ + (yy_hold_char) = *yy_cp; \ + *yy_cp = '\0'; \ + (yy_c_buf_p) = yy_cp; + +#define YY_NUM_RULES 174 +#define YY_END_OF_BUFFER 175 +/* This struct is not used in this scanner, + but its presence is necessary. */ +struct yy_trans_info + { + flex_int32_t yy_verify; + flex_int32_t yy_nxt; + }; +static yyconst flex_int16_t yy_accept[481] = + { 0, + 0, 0, 175, 173, 171, 172, 173, 149, 173, 141, + 142, 143, 139, 140, 119, 173, 136, 170, 173, 120, + 120, 88, 173, 173, 173, 120, 173, 173, 173, 173, + 86, 173, 120, 173, 173, 87, 171, 172, 0, 168, + 0, 136, 136, 169, 136, 136, 170, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 102, 103, 0, 0, 90, 0, 0, + 88, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 89, 39, 105, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 86, + + 0, 0, 0, 0, 0, 104, 0, 0, 0, 85, + 0, 0, 0, 93, 0, 0, 0, 0, 0, 91, + 0, 0, 87, 0, 0, 0, 169, 164, 165, 0, + 0, 0, 0, 0, 0, 0, 124, 125, 126, 0, + 147, 146, 134, 0, 132, 130, 133, 131, 135, 0, + 0, 128, 0, 0, 0, 0, 0, 121, 122, 123, + 15, 1, 78, 0, 0, 55, 54, 24, 33, 34, + 0, 9, 10, 20, 79, 80, 0, 0, 16, 0, + 22, 0, 52, 17, 0, 21, 0, 0, 5, 12, + 11, 3, 6, 2, 26, 98, 97, 0, 0, 0, + + 0, 92, 0, 23, 0, 0, 7, 37, 47, 8, + 0, 14, 25, 0, 13, 4, 60, 0, 0, 0, + 0, 0, 148, 0, 0, 0, 145, 0, 0, 0, + 0, 161, 0, 0, 0, 0, 127, 0, 0, 0, + 0, 0, 44, 35, 36, 0, 40, 0, 0, 0, + 18, 0, 0, 19, 46, 32, 31, 30, 29, 28, + 53, 0, 95, 94, 96, 0, 0, 0, 0, 0, + 0, 0, 50, 0, 0, 0, 0, 0, 0, 0, + 0, 137, 0, 100, 0, 0, 0, 0, 0, 0, + 144, 0, 0, 0, 0, 166, 0, 161, 0, 0, + + 0, 0, 0, 0, 0, 0, 42, 0, 0, 41, + 0, 0, 138, 49, 0, 84, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 61, + 0, 0, 101, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 160, 162, 0, 0, 154, 0, 0, 0, + 0, 0, 43, 45, 56, 0, 38, 99, 111, 112, + 113, 114, 115, 116, 117, 118, 27, 62, 0, 58, + 0, 75, 0, 82, 83, 51, 81, 0, 0, 106, + 107, 108, 109, 110, 0, 0, 0, 0, 160, 162, + 153, 0, 154, 163, 0, 0, 0, 167, 48, 63, + + 0, 0, 0, 59, 0, 76, 0, 0, 0, 0, + 0, 153, 0, 163, 156, 0, 0, 57, 77, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 157, 0, 0, 129, 150, 156, 0, 155, 73, 0, + 0, 0, 0, 0, 0, 0, 64, 65, 0, 157, + 0, 0, 150, 159, 0, 155, 0, 67, 68, 69, + 0, 72, 0, 66, 0, 0, 159, 158, 0, 70, + 0, 0, 151, 158, 74, 71, 152, 151, 152, 0 + } ; + +static yyconst flex_int32_t yy_ec[256] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, + 1, 1, 4, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 2, 5, 1, 6, 1, 1, 1, 1, 7, + 8, 1, 9, 10, 11, 12, 13, 14, 15, 16, + 17, 18, 19, 19, 19, 20, 19, 1, 21, 1, + 1, 1, 1, 1, 1, 1, 22, 23, 1, 24, + 1, 1, 1, 1, 1, 25, 1, 1, 1, 26, + 1, 1, 1, 27, 1, 1, 1, 1, 1, 1, + 28, 1, 29, 1, 30, 1, 31, 32, 33, 34, + + 35, 36, 37, 38, 39, 1, 40, 41, 42, 43, + 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, + 54, 55, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1 + } ; + +static yyconst flex_int32_t yy_meta[56] = + { 0, + 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, + 1, 3, 1, 4, 4, 4, 4, 4, 4, 4, + 1, 1, 1, 5, 1, 5, 1, 1, 1, 1, + 6, 1, 7, 1, 8, 3, 1, 1, 9, 1, + 1, 10, 10, 9, 1, 1, 11, 12, 1, 1, + 1, 1, 1, 1, 1 + } ; + +static yyconst flex_int16_t yy_base[491] = + { 0, + 0, 0, 889, 890, 886, 890, 884, 890, 883, 890, + 890, 890, 890, 44, 51, 872, 45, 0, 67, 59, + 39, 45, 61, 36, 64, 890, 107, 97, 114, 28, + 151, 91, 107, 165, 43, 124, 882, 890, 880, 890, + 172, 101, 193, 0, 202, 890, 0, 848, 847, 848, + 108, 189, 179, 833, 834, 84, 103, 116, 182, 846, + 99, 832, 178, 890, 890, 827, 840, 226, 831, 837, + 233, 830, 825, 835, 820, 826, 830, 219, 205, 817, + 830, 818, 821, 828, 246, 890, 253, 828, 810, 70, + 813, 804, 803, 123, 812, 803, 812, 807, 809, 260, + + 267, 274, 806, 36, 276, 890, 818, 796, 193, 283, + 802, 114, 800, 296, 796, 111, 801, 794, 810, 303, + 788, 790, 310, 808, 794, 319, 0, 890, 890, 789, + 301, 801, 819, 791, 792, 800, 890, 890, 890, 786, + 890, 890, 890, 793, 890, 890, 890, 890, 890, 782, + 780, 890, 788, 183, 783, 285, 784, 890, 890, 890, + 890, 890, 890, 793, 782, 890, 890, 890, 890, 302, + 791, 890, 890, 890, 890, 890, 786, 296, 775, 771, + 890, 783, 890, 772, 771, 890, 239, 287, 890, 890, + 890, 784, 890, 890, 890, 336, 890, 769, 776, 764, + + 763, 343, 762, 890, 291, 330, 890, 890, 890, 890, + 764, 890, 890, 775, 890, 890, 332, 772, 773, 757, + 352, 360, 890, 756, 759, 759, 890, 752, 756, 764, + 749, 366, 755, 757, 740, 749, 890, 756, 744, 758, + 740, 749, 745, 890, 890, 753, 890, 750, 741, 749, + 890, 748, 741, 890, 890, 890, 890, 890, 890, 890, + 890, 732, 890, 890, 890, 745, 767, 766, 765, 746, + 745, 744, 890, 729, 737, 292, 158, 732, 736, 752, + 733, 890, 732, 890, 754, 753, 752, 733, 732, 731, + 890, 713, 725, 711, 710, 890, 718, 373, 724, 705, + + 718, 711, 716, 714, 705, 706, 702, 691, 711, 890, + 700, 698, 890, 890, 704, 890, 380, 103, 727, 385, + 148, 726, 691, 696, 693, 702, 690, 717, 692, 372, + 679, 694, 890, 356, 391, 716, 393, 395, 715, 686, + 371, 683, 410, 417, 685, 686, 435, 689, 670, 679, + 665, 673, 890, 890, 890, 662, 890, 890, 890, 890, + 890, 890, 890, 890, 890, 890, 890, 665, 658, 890, + 652, 651, 657, 890, 890, 890, 890, 395, 681, 890, + 890, 890, 890, 890, 665, 650, 657, 652, 442, 449, + 456, 644, 463, 470, 638, 651, 635, 890, 890, 890, + + 647, 641, 640, 890, 457, 370, 461, 633, 639, 632, + 634, 495, 624, 502, 509, 616, 630, 890, 890, 610, + 616, 476, 470, 473, 458, 466, 452, 452, 465, 459, + 516, 456, 457, 890, 523, 530, 449, 537, 890, 402, + 412, 392, 409, 407, 388, 395, 890, 890, 407, 544, + 405, 384, 551, 559, 373, 566, 367, 890, 890, 890, + 381, 890, 343, 890, 313, 293, 573, 580, 302, 890, + 195, 49, 587, 594, 890, 890, 601, 608, 615, 890, + 635, 645, 649, 658, 666, 674, 682, 691, 699, 711 + } ; + +static yyconst flex_int16_t yy_def[491] = + { 0, + 480, 1, 480, 480, 480, 480, 480, 480, 481, 480, + 480, 480, 480, 480, 480, 480, 482, 483, 480, 480, + 484, 485, 480, 480, 480, 480, 480, 486, 480, 480, + 480, 480, 487, 480, 488, 489, 480, 480, 481, 480, + 480, 482, 480, 490, 480, 480, 483, 480, 480, 480, + 480, 480, 480, 480, 480, 480, 480, 480, 480, 480, + 480, 480, 480, 480, 480, 480, 480, 480, 480, 480, + 480, 480, 480, 480, 480, 480, 480, 480, 480, 480, + 480, 480, 480, 480, 480, 480, 480, 480, 480, 480, + 480, 480, 480, 480, 480, 480, 480, 480, 480, 480, + + 480, 480, 480, 480, 480, 480, 480, 480, 480, 480, + 480, 480, 480, 480, 480, 480, 480, 480, 480, 480, + 480, 480, 480, 480, 480, 480, 490, 480, 480, 480, + 480, 480, 480, 480, 480, 480, 480, 480, 480, 480, + 480, 480, 480, 480, 480, 480, 480, 480, 480, 480, + 480, 480, 480, 480, 480, 480, 480, 480, 480, 480, + 480, 480, 480, 480, 480, 480, 480, 480, 480, 480, + 480, 480, 480, 480, 480, 480, 480, 480, 480, 480, + 480, 480, 480, 480, 480, 480, 480, 480, 480, 480, + 480, 480, 480, 480, 480, 480, 480, 480, 480, 480, + + 480, 480, 480, 480, 480, 480, 480, 480, 480, 480, + 480, 480, 480, 480, 480, 480, 480, 480, 480, 480, + 480, 480, 480, 480, 480, 480, 480, 480, 480, 480, + 480, 480, 480, 480, 480, 480, 480, 480, 480, 480, + 480, 480, 480, 480, 480, 480, 480, 480, 480, 480, + 480, 480, 480, 480, 480, 480, 480, 480, 480, 480, + 480, 480, 480, 480, 480, 480, 480, 480, 480, 480, + 480, 480, 480, 480, 480, 480, 480, 480, 480, 480, + 480, 480, 480, 480, 480, 480, 480, 480, 480, 480, + 480, 480, 480, 480, 480, 480, 480, 480, 480, 480, + + 480, 480, 480, 480, 480, 480, 480, 480, 480, 480, + 480, 480, 480, 480, 480, 480, 480, 480, 480, 480, + 480, 480, 480, 480, 480, 480, 480, 480, 480, 480, + 480, 480, 480, 480, 480, 480, 480, 480, 480, 480, + 480, 480, 480, 480, 480, 480, 480, 480, 480, 480, + 480, 480, 480, 480, 480, 480, 480, 480, 480, 480, + 480, 480, 480, 480, 480, 480, 480, 480, 480, 480, + 480, 480, 480, 480, 480, 480, 480, 480, 480, 480, + 480, 480, 480, 480, 480, 480, 480, 480, 480, 480, + 480, 480, 480, 480, 480, 480, 480, 480, 480, 480, + + 480, 480, 480, 480, 480, 480, 480, 480, 480, 480, + 480, 480, 480, 480, 480, 480, 480, 480, 480, 480, + 480, 480, 480, 480, 480, 480, 480, 480, 480, 480, + 480, 480, 480, 480, 480, 480, 480, 480, 480, 480, + 480, 480, 480, 480, 480, 480, 480, 480, 480, 480, + 480, 480, 480, 480, 480, 480, 480, 480, 480, 480, + 480, 480, 480, 480, 480, 480, 480, 480, 480, 480, + 480, 480, 480, 480, 480, 480, 480, 480, 480, 0, + 480, 480, 480, 480, 480, 480, 480, 480, 480, 480 + } ; + +static yyconst flex_int16_t yy_nxt[946] = + { 0, + 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, + 14, 15, 16, 17, 17, 17, 17, 17, 17, 17, + 18, 4, 4, 4, 4, 4, 4, 12, 12, 19, + 20, 21, 22, 23, 24, 25, 26, 4, 27, 4, + 28, 29, 30, 31, 32, 4, 33, 34, 35, 4, + 36, 26, 26, 26, 26, 41, 45, 42, 42, 42, + 42, 42, 42, 42, 43, 43, 43, 43, 43, 43, + 43, 98, 64, 69, 99, 72, 80, 121, 81, 200, + 46, 48, 49, 65, 201, 70, 73, 74, 82, 122, + 66, 75, 67, 76, 83, 77, 477, 50, 51, 52, + + 53, 54, 55, 56, 106, 78, 184, 57, 79, 58, + 84, 59, 45, 185, 60, 61, 364, 62, 145, 63, + 85, 85, 85, 85, 85, 85, 85, 88, 107, 155, + 92, 93, 146, 156, 108, 89, 46, 147, 109, 111, + 90, 112, 86, 91, 94, 212, 131, 124, 132, 125, + 149, 148, 95, 213, 113, 365, 189, 96, 208, 150, + 133, 364, 209, 97, 100, 100, 100, 100, 100, 100, + 100, 126, 101, 102, 103, 190, 104, 105, 114, 114, + 114, 114, 114, 114, 114, 43, 43, 43, 43, 43, + 43, 43, 327, 158, 137, 159, 138, 160, 139, 115, + + 365, 116, 328, 117, 205, 118, 43, 43, 43, 43, + 43, 43, 43, 140, 119, 43, 43, 43, 43, 43, + 43, 43, 206, 134, 236, 151, 152, 476, 46, 153, + 141, 237, 135, 142, 171, 172, 173, 46, 136, 68, + 68, 68, 68, 68, 68, 68, 71, 71, 71, 71, + 71, 71, 71, 174, 256, 257, 258, 175, 176, 85, + 85, 85, 85, 85, 85, 85, 87, 87, 87, 87, + 87, 87, 87, 100, 100, 100, 100, 100, 100, 100, + 196, 196, 196, 196, 196, 196, 196, 197, 197, 202, + 202, 202, 202, 202, 202, 202, 110, 110, 110, 110, + + 110, 110, 110, 259, 260, 267, 268, 269, 198, 114, + 114, 114, 114, 114, 114, 114, 120, 120, 120, 120, + 120, 120, 120, 123, 123, 123, 123, 123, 123, 123, + 221, 224, 239, 244, 248, 325, 249, 240, 326, 475, + 245, 473, 250, 225, 270, 271, 272, 472, 222, 196, + 196, 196, 196, 196, 196, 196, 202, 202, 202, 202, + 202, 202, 202, 275, 276, 277, 285, 286, 287, 380, + 381, 278, 279, 280, 288, 289, 290, 471, 281, 298, + 298, 298, 298, 298, 298, 298, 298, 298, 298, 298, + 298, 298, 298, 359, 360, 361, 362, 363, 359, 360, + + 361, 362, 363, 374, 382, 375, 380, 381, 382, 386, + 405, 406, 376, 470, 424, 469, 377, 425, 426, 468, + 427, 466, 387, 389, 389, 389, 389, 389, 389, 389, + 390, 390, 390, 390, 390, 390, 390, 465, 464, 463, + 462, 461, 460, 383, 459, 458, 457, 383, 393, 393, + 393, 393, 393, 393, 393, 389, 389, 389, 389, 389, + 389, 389, 390, 390, 390, 390, 390, 390, 390, 412, + 412, 412, 412, 412, 412, 412, 393, 393, 393, 393, + 393, 393, 393, 414, 414, 414, 414, 414, 414, 414, + 421, 428, 455, 452, 451, 449, 448, 429, 447, 446, + + 445, 422, 444, 443, 442, 423, 441, 430, 412, 412, + 412, 412, 412, 412, 412, 414, 414, 414, 414, 414, + 414, 414, 436, 436, 436, 436, 436, 436, 436, 450, + 450, 450, 450, 450, 450, 450, 453, 453, 453, 453, + 453, 453, 453, 436, 436, 436, 436, 436, 436, 436, + 456, 456, 456, 456, 456, 456, 456, 450, 450, 450, + 450, 450, 450, 450, 453, 453, 453, 453, 453, 453, + 453, 454, 467, 467, 467, 467, 467, 467, 467, 456, + 456, 456, 456, 456, 456, 456, 467, 467, 467, 467, + 467, 467, 467, 474, 474, 474, 474, 474, 474, 474, + + 478, 478, 478, 478, 478, 478, 478, 474, 474, 474, + 474, 474, 474, 474, 479, 479, 479, 479, 479, 479, + 479, 478, 478, 478, 478, 478, 478, 478, 479, 479, + 479, 479, 479, 479, 479, 39, 39, 39, 39, 39, + 39, 39, 39, 39, 39, 39, 39, 42, 42, 47, + 440, 47, 47, 47, 47, 47, 47, 47, 47, 47, + 47, 68, 439, 438, 437, 68, 435, 434, 68, 71, + 433, 71, 432, 431, 420, 71, 71, 87, 419, 87, + 418, 417, 87, 416, 87, 110, 415, 413, 110, 110, + 411, 410, 409, 110, 120, 408, 407, 404, 120, 403, + + 402, 120, 123, 123, 401, 400, 399, 398, 397, 396, + 123, 127, 395, 127, 127, 127, 127, 127, 127, 127, + 127, 127, 127, 394, 392, 391, 388, 385, 384, 384, + 379, 378, 373, 372, 371, 370, 369, 368, 367, 366, + 366, 358, 357, 356, 355, 354, 353, 352, 351, 350, + 349, 348, 347, 346, 345, 344, 343, 342, 341, 340, + 339, 338, 337, 336, 335, 334, 333, 332, 331, 330, + 329, 324, 323, 322, 321, 320, 319, 318, 317, 316, + 315, 314, 313, 312, 311, 310, 309, 308, 307, 306, + 305, 304, 303, 302, 301, 300, 299, 297, 296, 295, + + 294, 293, 292, 291, 284, 283, 282, 274, 273, 266, + 265, 264, 263, 262, 261, 255, 254, 253, 252, 251, + 247, 246, 243, 242, 241, 238, 235, 234, 233, 232, + 231, 230, 229, 228, 227, 226, 223, 220, 219, 218, + 217, 216, 215, 214, 211, 210, 207, 204, 203, 199, + 195, 194, 193, 192, 191, 188, 187, 186, 183, 182, + 181, 180, 179, 178, 177, 170, 169, 168, 167, 166, + 165, 164, 163, 162, 161, 157, 154, 144, 143, 130, + 129, 128, 40, 37, 44, 40, 38, 37, 480, 3, + 480, 480, 480, 480, 480, 480, 480, 480, 480, 480, + + 480, 480, 480, 480, 480, 480, 480, 480, 480, 480, + 480, 480, 480, 480, 480, 480, 480, 480, 480, 480, + 480, 480, 480, 480, 480, 480, 480, 480, 480, 480, + 480, 480, 480, 480, 480, 480, 480, 480, 480, 480, + 480, 480, 480, 480, 480 + } ; + +static yyconst flex_int16_t yy_chk[946] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 14, 17, 14, 14, 14, + 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, + 15, 30, 20, 21, 30, 22, 24, 35, 24, 104, + 17, 19, 19, 20, 104, 21, 22, 22, 24, 35, + 20, 22, 20, 23, 25, 23, 472, 19, 19, 19, + + 19, 19, 19, 19, 32, 23, 90, 19, 23, 19, + 25, 19, 42, 90, 19, 19, 318, 19, 56, 19, + 27, 27, 27, 27, 27, 27, 27, 28, 32, 61, + 29, 29, 56, 61, 32, 28, 42, 57, 32, 33, + 28, 33, 27, 28, 29, 116, 51, 36, 51, 36, + 58, 57, 29, 116, 33, 318, 94, 29, 112, 58, + 51, 321, 112, 29, 31, 31, 31, 31, 31, 31, + 31, 36, 31, 31, 31, 94, 31, 31, 34, 34, + 34, 34, 34, 34, 34, 41, 41, 41, 41, 41, + 41, 41, 277, 63, 53, 63, 53, 63, 53, 34, + + 321, 34, 277, 34, 109, 34, 43, 43, 43, 43, + 43, 43, 43, 53, 34, 45, 45, 45, 45, 45, + 45, 45, 109, 52, 154, 59, 59, 471, 43, 59, + 53, 154, 52, 53, 78, 78, 78, 45, 52, 68, + 68, 68, 68, 68, 68, 68, 71, 71, 71, 71, + 71, 71, 71, 79, 187, 187, 187, 79, 79, 85, + 85, 85, 85, 85, 85, 85, 87, 87, 87, 87, + 87, 87, 87, 100, 100, 100, 100, 100, 100, 100, + 101, 101, 101, 101, 101, 101, 101, 102, 102, 105, + 105, 105, 105, 105, 105, 105, 110, 110, 110, 110, + + 110, 110, 110, 188, 188, 205, 205, 205, 102, 114, + 114, 114, 114, 114, 114, 114, 120, 120, 120, 120, + 120, 120, 120, 123, 123, 123, 123, 123, 123, 123, + 126, 131, 156, 170, 178, 276, 178, 156, 276, 469, + 170, 466, 178, 131, 206, 206, 206, 465, 126, 196, + 196, 196, 196, 196, 196, 196, 202, 202, 202, 202, + 202, 202, 202, 217, 217, 217, 221, 221, 221, 334, + 334, 217, 217, 217, 222, 222, 222, 463, 217, 232, + 232, 232, 232, 232, 232, 232, 298, 298, 298, 298, + 298, 298, 298, 317, 317, 317, 317, 317, 320, 320, + + 320, 320, 320, 330, 335, 330, 337, 337, 338, 341, + 378, 378, 330, 461, 406, 457, 330, 406, 406, 455, + 406, 452, 341, 343, 343, 343, 343, 343, 343, 343, + 344, 344, 344, 344, 344, 344, 344, 451, 449, 446, + 445, 444, 443, 335, 442, 441, 440, 338, 347, 347, + 347, 347, 347, 347, 347, 389, 389, 389, 389, 389, + 389, 389, 390, 390, 390, 390, 390, 390, 390, 391, + 391, 391, 391, 391, 391, 391, 393, 393, 393, 393, + 393, 393, 393, 394, 394, 394, 394, 394, 394, 394, + 405, 407, 437, 433, 432, 430, 429, 407, 428, 427, + + 426, 405, 425, 424, 423, 405, 422, 407, 412, 412, + 412, 412, 412, 412, 412, 414, 414, 414, 414, 414, + 414, 414, 415, 415, 415, 415, 415, 415, 415, 431, + 431, 431, 431, 431, 431, 431, 435, 435, 435, 435, + 435, 435, 435, 436, 436, 436, 436, 436, 436, 436, + 438, 438, 438, 438, 438, 438, 438, 450, 450, 450, + 450, 450, 450, 450, 453, 453, 453, 453, 453, 453, + 453, 435, 454, 454, 454, 454, 454, 454, 454, 456, + 456, 456, 456, 456, 456, 456, 467, 467, 467, 467, + 467, 467, 467, 468, 468, 468, 468, 468, 468, 468, + + 473, 473, 473, 473, 473, 473, 473, 474, 474, 474, + 474, 474, 474, 474, 477, 477, 477, 477, 477, 477, + 477, 478, 478, 478, 478, 478, 478, 478, 479, 479, + 479, 479, 479, 479, 479, 481, 481, 481, 481, 481, + 481, 481, 481, 481, 481, 481, 481, 482, 482, 483, + 421, 483, 483, 483, 483, 483, 483, 483, 483, 483, + 483, 484, 420, 417, 416, 484, 413, 411, 484, 485, + 410, 485, 409, 408, 403, 485, 485, 486, 402, 486, + 401, 397, 486, 396, 486, 487, 395, 392, 487, 487, + 388, 387, 386, 487, 488, 385, 379, 373, 488, 372, + + 371, 488, 489, 489, 369, 368, 356, 352, 351, 350, + 489, 490, 349, 490, 490, 490, 490, 490, 490, 490, + 490, 490, 490, 348, 346, 345, 342, 340, 339, 336, + 332, 331, 329, 328, 327, 326, 325, 324, 323, 322, + 319, 315, 312, 311, 309, 308, 307, 306, 305, 304, + 303, 302, 301, 300, 299, 297, 295, 294, 293, 292, + 290, 289, 288, 287, 286, 285, 283, 281, 280, 279, + 278, 275, 274, 272, 271, 270, 269, 268, 267, 266, + 262, 253, 252, 250, 249, 248, 246, 243, 242, 241, + 240, 239, 238, 236, 235, 234, 233, 231, 230, 229, + + 228, 226, 225, 224, 220, 219, 218, 214, 211, 203, + 201, 200, 199, 198, 192, 185, 184, 182, 180, 179, + 177, 171, 165, 164, 157, 155, 153, 151, 150, 144, + 140, 136, 135, 134, 133, 132, 130, 125, 124, 122, + 121, 119, 118, 117, 115, 113, 111, 108, 107, 103, + 99, 98, 97, 96, 95, 93, 92, 91, 89, 88, + 84, 83, 82, 81, 80, 77, 76, 75, 74, 73, + 72, 70, 69, 67, 66, 62, 60, 55, 54, 50, + 49, 48, 39, 37, 16, 9, 7, 5, 3, 480, + 480, 480, 480, 480, 480, 480, 480, 480, 480, 480, + + 480, 480, 480, 480, 480, 480, 480, 480, 480, 480, + 480, 480, 480, 480, 480, 480, 480, 480, 480, 480, + 480, 480, 480, 480, 480, 480, 480, 480, 480, 480, + 480, 480, 480, 480, 480, 480, 480, 480, 480, 480, + 480, 480, 480, 480, 480 + } ; + +static yy_state_type yy_last_accepting_state; +static char *yy_last_accepting_cpos; + +extern int asmshader__flex_debug; +int asmshader__flex_debug = 0; + +/* The intent behind this definition is that it'll catch + * any uses of REJECT which flex missed. + */ +#define REJECT reject_used_but_not_detected +#define yymore() yymore_used_but_not_detected +#define YY_MORE_ADJ 0 +#define YY_RESTORE_YY_MORE_OFFSET +char *asmshader_text; +#line 1 "asmshader.l" +/* + * Direct3D shader assembler + * + * Copyright 2008 Stefan Dösinger + * Copyright 2009 Matteo Bruni + * + * 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 + */ +#line 23 "asmshader.l" +#include "config.h" +#include "wine/port.h" +#include "wine/debug.h" + +#include "d3dcompiler_private.h" +#include "asmshader.tab.h" + +WINE_DEFAULT_DEBUG_CHANNEL(asmshader); +#define YY_NO_INPUT 1 +/* Swizzles and writemasks consist of a dot and up to 4 x, y, z or w characters, + * or up to 4 a, r, g, b characters. There are different rules for swizzles and + * writemasks wrt repetition, those are handled in the grammar. + */ +/* Registers */ +/* for relative addressing in the form o[x], v[x] and c[x] */ +/* Not really a register, but it is considered as such */ +/* Comments */ +/* Whitespaces are spaces, tabs and newlines */ +#line 886 "asmshader.yy.c" + +#define INITIAL 0 + +#ifndef YY_NO_UNISTD_H +/* Special case for "unistd.h", since it is non-ANSI. We include it way + * down here because we want the user's section 1 to have been scanned first. + * The user has a chance to override it with an option. + */ +#include +#endif + +#ifndef YY_EXTRA_TYPE +#define YY_EXTRA_TYPE void * +#endif + +static int yy_init_globals (void ); + +/* Accessor methods to globals. + These are made visible to non-reentrant scanners for convenience. */ + +int asmshader_lex_destroy (void ); + +int asmshader_get_debug (void ); + +void asmshader_set_debug (int debug_flag ); + +YY_EXTRA_TYPE asmshader_get_extra (void ); + +void asmshader_set_extra (YY_EXTRA_TYPE user_defined ); + +FILE *asmshader_get_in (void ); + +void asmshader_set_in (FILE * in_str ); + +FILE *asmshader_get_out (void ); + +void asmshader_set_out (FILE * out_str ); + +int asmshader_get_leng (void ); + +char *asmshader_get_text (void ); + +int asmshader_get_lineno (void ); + +void asmshader_set_lineno (int line_number ); + +/* Macros after this point can all be overridden by user definitions in + * section 1. + */ + +#ifndef YY_SKIP_YYWRAP +#ifdef __cplusplus +extern "C" int asmshader_wrap (void ); +#else +extern int asmshader_wrap (void ); +#endif +#endif + +#ifndef yytext_ptr +static void yy_flex_strncpy (char *,yyconst char *,int ); +#endif + +#ifdef YY_NEED_STRLEN +static int yy_flex_strlen (yyconst char * ); +#endif + +#ifndef YY_NO_INPUT + +#ifdef __cplusplus +static int yyinput (void ); +#else +static int input (void ); +#endif + +#endif + +/* Amount of stuff to slurp up with each read. */ +#ifndef YY_READ_BUF_SIZE +#ifdef __ia64__ +/* On IA-64, the buffer size is 16k, not 8k */ +#define YY_READ_BUF_SIZE 16384 +#else +#define YY_READ_BUF_SIZE 8192 +#endif /* __ia64__ */ +#endif + +/* Copy whatever the last rule matched to the standard output. */ +#ifndef ECHO +/* This used to be an fputs(), but since the string might contain NUL's, + * we now use fwrite(). + */ +#define ECHO do { if (fwrite( asmshader_text, asmshader_leng, 1, asmshader_out )) {} } while (0) +#endif + +/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, + * is returned in "result". + */ +#ifndef YY_INPUT +#define YY_INPUT(buf,result,max_size) \ + if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ + { \ + int c = '*'; \ + size_t n; \ + for ( n = 0; n < max_size && \ + (c = getc( asmshader_in )) != EOF && c != '\n'; ++n ) \ + buf[n] = (char) c; \ + if ( c == '\n' ) \ + buf[n++] = (char) c; \ + if ( c == EOF && ferror( asmshader_in ) ) \ + YY_FATAL_ERROR( "input in flex scanner failed" ); \ + result = n; \ + } \ + else \ + { \ + errno=0; \ + while ( (result = fread(buf, 1, max_size, asmshader_in))==0 && ferror(asmshader_in)) \ + { \ + if( errno != EINTR) \ + { \ + YY_FATAL_ERROR( "input in flex scanner failed" ); \ + break; \ + } \ + errno=0; \ + clearerr(asmshader_in); \ + } \ + }\ +\ + +#endif + +/* No semi-colon after return; correct usage is to write "yyterminate();" - + * we don't want an extra ';' after the "return" because that will cause + * some compilers to complain about unreachable statements. + */ +#ifndef yyterminate +#define yyterminate() return YY_NULL +#endif + +/* Number of entries by which start-condition stack grows. */ +#ifndef YY_START_STACK_INCR +#define YY_START_STACK_INCR 25 +#endif + +/* Report a fatal error. */ +#ifndef YY_FATAL_ERROR +#define YY_FATAL_ERROR(msg) yy_fatal_error( msg ) +#endif + +/* end tables serialization structures and prototypes */ + +/* Default declaration of generated scanner - a define so the user can + * easily add parameters. + */ +#ifndef YY_DECL +#define YY_DECL_IS_OURS 1 + +extern int asmshader_lex (void); + +#define YY_DECL int asmshader_lex (void) +#endif /* !YY_DECL */ + +/* Code executed at the beginning of each rule, after asmshader_text and asmshader_leng + * have been set up. + */ +#ifndef YY_USER_ACTION +#define YY_USER_ACTION +#endif + +/* Code executed at the end of each rule. */ +#ifndef YY_BREAK +#define YY_BREAK break; +#endif + +#define YY_RULE_SETUP \ + YY_USER_ACTION + +/** The main scanner function which does all the work. + */ +YY_DECL +{ + register yy_state_type yy_current_state; + register char *yy_cp, *yy_bp; + register int yy_act; + +#line 105 "asmshader.l" + + + /* Common instructions(vertex and pixel shaders) */ +#line 1075 "asmshader.yy.c" + + if ( !(yy_init) ) + { + (yy_init) = 1; + +#ifdef YY_USER_INIT + YY_USER_INIT; +#endif + + if ( ! (yy_start) ) + (yy_start) = 1; /* first start state */ + + if ( ! asmshader_in ) + asmshader_in = stdin; + + if ( ! asmshader_out ) + asmshader_out = stdout; + + if ( ! YY_CURRENT_BUFFER ) { + asmshader_ensure_buffer_stack (); + YY_CURRENT_BUFFER_LVALUE = + asmshader__create_buffer(asmshader_in,YY_BUF_SIZE ); + } + + asmshader__load_buffer_state( ); + } + + while ( 1 ) /* loops until end-of-file is reached */ + { + yy_cp = (yy_c_buf_p); + + /* Support of asmshader_text. */ + *yy_cp = (yy_hold_char); + + /* yy_bp points to the position in yy_ch_buf of the start of + * the current run. + */ + yy_bp = yy_cp; + + yy_current_state = (yy_start); +yy_match: + do + { + register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)]; + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 481 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + ++yy_cp; + } + while ( yy_current_state != 480 ); + yy_cp = (yy_last_accepting_cpos); + yy_current_state = (yy_last_accepting_state); + +yy_find_action: + yy_act = yy_accept[yy_current_state]; + + YY_DO_BEFORE_ACTION; + +do_action: /* This label is used only to access EOF actions. */ + + switch ( yy_act ) + { /* beginning of action switch */ + case 0: /* must back up */ + /* undo the effects of YY_DO_BEFORE_ACTION */ + *yy_cp = (yy_hold_char); + yy_cp = (yy_last_accepting_cpos); + yy_current_state = (yy_last_accepting_state); + goto yy_find_action; + +case 1: +YY_RULE_SETUP +#line 108 "asmshader.l" +{return INSTR_ADD; } + YY_BREAK +case 2: +YY_RULE_SETUP +#line 109 "asmshader.l" +{return INSTR_NOP; } + YY_BREAK +case 3: +YY_RULE_SETUP +#line 110 "asmshader.l" +{return INSTR_MOV; } + YY_BREAK +case 4: +YY_RULE_SETUP +#line 111 "asmshader.l" +{return INSTR_SUB; } + YY_BREAK +case 5: +YY_RULE_SETUP +#line 112 "asmshader.l" +{return INSTR_MAD; } + YY_BREAK +case 6: +YY_RULE_SETUP +#line 113 "asmshader.l" +{return INSTR_MUL; } + YY_BREAK +case 7: +YY_RULE_SETUP +#line 114 "asmshader.l" +{return INSTR_RCP; } + YY_BREAK +case 8: +YY_RULE_SETUP +#line 115 "asmshader.l" +{return INSTR_RSQ; } + YY_BREAK +case 9: +YY_RULE_SETUP +#line 116 "asmshader.l" +{return INSTR_DP3; } + YY_BREAK +case 10: +YY_RULE_SETUP +#line 117 "asmshader.l" +{return INSTR_DP4; } + YY_BREAK +case 11: +YY_RULE_SETUP +#line 118 "asmshader.l" +{return INSTR_MIN; } + YY_BREAK +case 12: +YY_RULE_SETUP +#line 119 "asmshader.l" +{return INSTR_MAX; } + YY_BREAK +case 13: +YY_RULE_SETUP +#line 120 "asmshader.l" +{return INSTR_SLT; } + YY_BREAK +case 14: +YY_RULE_SETUP +#line 121 "asmshader.l" +{return INSTR_SGE; } + YY_BREAK +case 15: +YY_RULE_SETUP +#line 122 "asmshader.l" +{return INSTR_ABS; } + YY_BREAK +case 16: +YY_RULE_SETUP +#line 123 "asmshader.l" +{return INSTR_EXP; } + YY_BREAK +case 17: +YY_RULE_SETUP +#line 124 "asmshader.l" +{return INSTR_LOG; } + YY_BREAK +case 18: +YY_RULE_SETUP +#line 125 "asmshader.l" +{return INSTR_EXPP; } + YY_BREAK +case 19: +YY_RULE_SETUP +#line 126 "asmshader.l" +{return INSTR_LOGP; } + YY_BREAK +case 20: +YY_RULE_SETUP +#line 127 "asmshader.l" +{return INSTR_DST; } + YY_BREAK +case 21: +YY_RULE_SETUP +#line 128 "asmshader.l" +{return INSTR_LRP; } + YY_BREAK +case 22: +YY_RULE_SETUP +#line 129 "asmshader.l" +{return INSTR_FRC; } + YY_BREAK +case 23: +YY_RULE_SETUP +#line 130 "asmshader.l" +{return INSTR_POW; } + YY_BREAK +case 24: +YY_RULE_SETUP +#line 131 "asmshader.l" +{return INSTR_CRS; } + YY_BREAK +case 25: +YY_RULE_SETUP +#line 132 "asmshader.l" +{return INSTR_SGN; } + YY_BREAK +case 26: +YY_RULE_SETUP +#line 133 "asmshader.l" +{return INSTR_NRM; } + YY_BREAK +case 27: +YY_RULE_SETUP +#line 134 "asmshader.l" +{return INSTR_SINCOS; } + YY_BREAK +case 28: +YY_RULE_SETUP +#line 135 "asmshader.l" +{return INSTR_M4x4; } + YY_BREAK +case 29: +YY_RULE_SETUP +#line 136 "asmshader.l" +{return INSTR_M4x3; } + YY_BREAK +case 30: +YY_RULE_SETUP +#line 137 "asmshader.l" +{return INSTR_M3x4; } + YY_BREAK +case 31: +YY_RULE_SETUP +#line 138 "asmshader.l" +{return INSTR_M3x3; } + YY_BREAK +case 32: +YY_RULE_SETUP +#line 139 "asmshader.l" +{return INSTR_M3x2; } + YY_BREAK +case 33: +YY_RULE_SETUP +#line 140 "asmshader.l" +{return INSTR_DCL; } + YY_BREAK +case 34: +YY_RULE_SETUP +#line 141 "asmshader.l" +{return INSTR_DEF; } + YY_BREAK +case 35: +YY_RULE_SETUP +#line 142 "asmshader.l" +{return INSTR_DEFB; } + YY_BREAK +case 36: +YY_RULE_SETUP +#line 143 "asmshader.l" +{return INSTR_DEFI; } + YY_BREAK +case 37: +YY_RULE_SETUP +#line 144 "asmshader.l" +{return INSTR_REP; } + YY_BREAK +case 38: +YY_RULE_SETUP +#line 145 "asmshader.l" +{return INSTR_ENDREP; } + YY_BREAK +case 39: +YY_RULE_SETUP +#line 146 "asmshader.l" +{return INSTR_IF; } + YY_BREAK +case 40: +YY_RULE_SETUP +#line 147 "asmshader.l" +{return INSTR_ELSE; } + YY_BREAK +case 41: +YY_RULE_SETUP +#line 148 "asmshader.l" +{return INSTR_ENDIF; } + YY_BREAK +case 42: +YY_RULE_SETUP +#line 149 "asmshader.l" +{return INSTR_BREAK; } + YY_BREAK +case 43: +YY_RULE_SETUP +#line 150 "asmshader.l" +{return INSTR_BREAKP; } + YY_BREAK +case 44: +YY_RULE_SETUP +#line 151 "asmshader.l" +{return INSTR_CALL; } + YY_BREAK +case 45: +YY_RULE_SETUP +#line 152 "asmshader.l" +{return INSTR_CALLNZ; } + YY_BREAK +case 46: +YY_RULE_SETUP +#line 153 "asmshader.l" +{return INSTR_LOOP; } + YY_BREAK +case 47: +YY_RULE_SETUP +#line 154 "asmshader.l" +{return INSTR_RET; } + YY_BREAK +case 48: +YY_RULE_SETUP +#line 155 "asmshader.l" +{return INSTR_ENDLOOP; } + YY_BREAK +case 49: +YY_RULE_SETUP +#line 156 "asmshader.l" +{return INSTR_LABEL; } + YY_BREAK +case 50: +YY_RULE_SETUP +#line 157 "asmshader.l" +{return INSTR_SETP; } + YY_BREAK +case 51: +YY_RULE_SETUP +#line 158 "asmshader.l" +{return INSTR_TEXLDL; } + YY_BREAK +/* Vertex shader only instructions */ +case 52: +YY_RULE_SETUP +#line 161 "asmshader.l" +{return INSTR_LIT; } + YY_BREAK +case 53: +YY_RULE_SETUP +#line 162 "asmshader.l" +{return INSTR_MOVA; } + YY_BREAK +/* Pixel shader only instructions */ +case 54: +YY_RULE_SETUP +#line 165 "asmshader.l" +{return INSTR_CND; } + YY_BREAK +case 55: +YY_RULE_SETUP +#line 166 "asmshader.l" +{return INSTR_CMP; } + YY_BREAK +case 56: +YY_RULE_SETUP +#line 167 "asmshader.l" +{return INSTR_DP2ADD; } + YY_BREAK +case 57: +YY_RULE_SETUP +#line 168 "asmshader.l" +{return INSTR_TEXCOORD; } + YY_BREAK +case 58: +YY_RULE_SETUP +#line 169 "asmshader.l" +{return INSTR_TEXCRD; } + YY_BREAK +case 59: +YY_RULE_SETUP +#line 170 "asmshader.l" +{return INSTR_TEXKILL; } + YY_BREAK +case 60: +YY_RULE_SETUP +#line 171 "asmshader.l" +{return INSTR_TEX; } + YY_BREAK +case 61: +YY_RULE_SETUP +#line 172 "asmshader.l" +{return INSTR_TEXLD; } + YY_BREAK +case 62: +YY_RULE_SETUP +#line 173 "asmshader.l" +{return INSTR_TEXBEM; } + YY_BREAK +case 63: +YY_RULE_SETUP +#line 174 "asmshader.l" +{return INSTR_TEXBEML; } + YY_BREAK +case 64: +YY_RULE_SETUP +#line 175 "asmshader.l" +{return INSTR_TEXREG2AR; } + YY_BREAK +case 65: +YY_RULE_SETUP +#line 176 "asmshader.l" +{return INSTR_TEXREG2GB; } + YY_BREAK +case 66: +YY_RULE_SETUP +#line 177 "asmshader.l" +{return INSTR_TEXREG2RGB; } + YY_BREAK +case 67: +YY_RULE_SETUP +#line 178 "asmshader.l" +{return INSTR_TEXM3x2PAD; } + YY_BREAK +case 68: +YY_RULE_SETUP +#line 179 "asmshader.l" +{return INSTR_TEXM3x2TEX; } + YY_BREAK +case 69: +YY_RULE_SETUP +#line 180 "asmshader.l" +{return INSTR_TEXM3x3PAD; } + YY_BREAK +case 70: +YY_RULE_SETUP +#line 181 "asmshader.l" +{return INSTR_TEXM3x3SPEC; } + YY_BREAK +case 71: +YY_RULE_SETUP +#line 182 "asmshader.l" +{return INSTR_TEXM3x3VSPEC; } + YY_BREAK +case 72: +YY_RULE_SETUP +#line 183 "asmshader.l" +{return INSTR_TEXM3x3TEX; } + YY_BREAK +case 73: +YY_RULE_SETUP +#line 184 "asmshader.l" +{return INSTR_TEXDP3TEX; } + YY_BREAK +case 74: +YY_RULE_SETUP +#line 185 "asmshader.l" +{return INSTR_TEXM3x2DEPTH; } + YY_BREAK +case 75: +YY_RULE_SETUP +#line 186 "asmshader.l" +{return INSTR_TEXDP3; } + YY_BREAK +case 76: +YY_RULE_SETUP +#line 187 "asmshader.l" +{return INSTR_TEXM3x3; } + YY_BREAK +case 77: +YY_RULE_SETUP +#line 188 "asmshader.l" +{return INSTR_TEXDEPTH; } + YY_BREAK +case 78: +YY_RULE_SETUP +#line 189 "asmshader.l" +{return INSTR_BEM; } + YY_BREAK +case 79: +YY_RULE_SETUP +#line 190 "asmshader.l" +{return INSTR_DSX; } + YY_BREAK +case 80: +YY_RULE_SETUP +#line 191 "asmshader.l" +{return INSTR_DSY; } + YY_BREAK +case 81: +YY_RULE_SETUP +#line 192 "asmshader.l" +{return INSTR_TEXLDP; } + YY_BREAK +case 82: +YY_RULE_SETUP +#line 193 "asmshader.l" +{return INSTR_TEXLDB; } + YY_BREAK +case 83: +YY_RULE_SETUP +#line 194 "asmshader.l" +{return INSTR_TEXLDD; } + YY_BREAK +case 84: +YY_RULE_SETUP +#line 195 "asmshader.l" +{return INSTR_PHASE; } + YY_BREAK +case 85: +YY_RULE_SETUP +#line 197 "asmshader.l" +{ + asmshader_lval.regnum = atoi(asmshader_text + 1); + return REG_TEMP; + } + YY_BREAK +case 86: +YY_RULE_SETUP +#line 201 "asmshader.l" +{ + asmshader_lval.regnum = atoi(asmshader_text + 1); + return REG_OUTPUT; + } + YY_BREAK +case 87: +YY_RULE_SETUP +#line 205 "asmshader.l" +{ + asmshader_lval.regnum = atoi(asmshader_text + 1); + return REG_INPUT; + } + YY_BREAK +case 88: +YY_RULE_SETUP +#line 209 "asmshader.l" +{ + asmshader_lval.regnum = atoi(asmshader_text + 1); + return REG_CONSTFLOAT; + } + YY_BREAK +case 89: +YY_RULE_SETUP +#line 213 "asmshader.l" +{ + asmshader_lval.regnum = atoi(asmshader_text + 1); + return REG_CONSTINT; + } + YY_BREAK +case 90: +YY_RULE_SETUP +#line 217 "asmshader.l" +{ + asmshader_lval.regnum = atoi(asmshader_text + 1); + return REG_CONSTBOOL; + } + YY_BREAK +case 91: +YY_RULE_SETUP +#line 221 "asmshader.l" +{ + asmshader_lval.regnum = atoi(asmshader_text + 1); + return REG_TEXTURE; + } + YY_BREAK +case 92: +YY_RULE_SETUP +#line 225 "asmshader.l" +{ + asmshader_lval.regnum = atoi(asmshader_text + 2); + return REG_TEXCRDOUT; + } + YY_BREAK +case 93: +YY_RULE_SETUP +#line 229 "asmshader.l" +{ + asmshader_lval.regnum = atoi(asmshader_text + 1); + return REG_SAMPLER; + } + YY_BREAK +case 94: +YY_RULE_SETUP +#line 233 "asmshader.l" +{return REG_OPOS; } + YY_BREAK +case 95: +YY_RULE_SETUP +#line 234 "asmshader.l" +{return REG_OFOG; } + YY_BREAK +case 96: +YY_RULE_SETUP +#line 235 "asmshader.l" +{return REG_OPTS; } + YY_BREAK +case 97: +YY_RULE_SETUP +#line 236 "asmshader.l" +{ + asmshader_lval.regnum = atoi(asmshader_text + 2); + return REG_VERTEXCOLOR; + } + YY_BREAK +case 98: +YY_RULE_SETUP +#line 240 "asmshader.l" +{ + asmshader_lval.regnum = atoi(asmshader_text + 2); + return REG_FRAGCOLOR; + } + YY_BREAK +case 99: +YY_RULE_SETUP +#line 244 "asmshader.l" +{return REG_FRAGDEPTH; } + YY_BREAK +case 100: +YY_RULE_SETUP +#line 245 "asmshader.l" +{return REG_VPOS; } + YY_BREAK +case 101: +YY_RULE_SETUP +#line 246 "asmshader.l" +{return REG_VFACE; } + YY_BREAK +case 102: +YY_RULE_SETUP +#line 247 "asmshader.l" +{return REG_ADDRESS; } + YY_BREAK +case 103: +YY_RULE_SETUP +#line 248 "asmshader.l" +{return REG_LOOP; } + YY_BREAK +case 104: +YY_RULE_SETUP +#line 249 "asmshader.l" +{return REG_PREDICATE; } + YY_BREAK +case 105: +YY_RULE_SETUP +#line 251 "asmshader.l" +{ + asmshader_lval.regnum = atoi(asmshader_text + 1); + return REG_LABEL; + } + YY_BREAK +/* Shader versions. These are important to select the correct + * parser profile. + */ +case 106: +YY_RULE_SETUP +#line 259 "asmshader.l" +{return VER_VS10; } + YY_BREAK +case 107: +YY_RULE_SETUP +#line 260 "asmshader.l" +{return VER_VS11; } + YY_BREAK +case 108: +YY_RULE_SETUP +#line 262 "asmshader.l" +{return VER_VS20; } + YY_BREAK +case 109: +YY_RULE_SETUP +#line 263 "asmshader.l" +{return VER_VS2X; } + YY_BREAK +case 110: +YY_RULE_SETUP +#line 264 "asmshader.l" +{return VER_VS30; } + YY_BREAK +case 111: +YY_RULE_SETUP +#line 266 "asmshader.l" +{return VER_PS10; } + YY_BREAK +case 112: +YY_RULE_SETUP +#line 267 "asmshader.l" +{return VER_PS11; } + YY_BREAK +case 113: +YY_RULE_SETUP +#line 268 "asmshader.l" +{return VER_PS12; } + YY_BREAK +case 114: +YY_RULE_SETUP +#line 269 "asmshader.l" +{return VER_PS13; } + YY_BREAK +case 115: +YY_RULE_SETUP +#line 270 "asmshader.l" +{return VER_PS14; } + YY_BREAK +case 116: +YY_RULE_SETUP +#line 272 "asmshader.l" +{return VER_PS20; } + YY_BREAK +case 117: +YY_RULE_SETUP +#line 273 "asmshader.l" +{return VER_PS2X; } + YY_BREAK +case 118: +YY_RULE_SETUP +#line 274 "asmshader.l" +{return VER_PS30; } + YY_BREAK +case 119: +YY_RULE_SETUP +#line 276 "asmshader.l" +{return asmshader_text[0]; } + YY_BREAK +case 120: +YY_RULE_SETUP +#line 277 "asmshader.l" +{ + switch(asmshader_text[0]) { + case 'x': + case 'r': + asmshader_lval.component = 0; + break; + case 'y': + case 'g': + asmshader_lval.component = 1; + break; + case 'z': + case 'b': + asmshader_lval.component = 2; + break; + case 'w': + case 'a': + asmshader_lval.component = 3; + break; + } + return COMPONENT; + } + YY_BREAK +/* Output modifiers */ +case 121: +YY_RULE_SETUP +#line 300 "asmshader.l" +{return SHIFT_X2; } + YY_BREAK +case 122: +YY_RULE_SETUP +#line 301 "asmshader.l" +{return SHIFT_X4; } + YY_BREAK +case 123: +YY_RULE_SETUP +#line 302 "asmshader.l" +{return SHIFT_X8; } + YY_BREAK +case 124: +YY_RULE_SETUP +#line 303 "asmshader.l" +{return SHIFT_D2; } + YY_BREAK +case 125: +YY_RULE_SETUP +#line 304 "asmshader.l" +{return SHIFT_D4; } + YY_BREAK +case 126: +YY_RULE_SETUP +#line 305 "asmshader.l" +{return SHIFT_D8; } + YY_BREAK +case 127: +YY_RULE_SETUP +#line 306 "asmshader.l" +{return MOD_SAT; } + YY_BREAK +case 128: +YY_RULE_SETUP +#line 307 "asmshader.l" +{return MOD_PP; } + YY_BREAK +case 129: +YY_RULE_SETUP +#line 308 "asmshader.l" +{return MOD_CENTROID; } + YY_BREAK +/* compare params */ +case 130: +YY_RULE_SETUP +#line 311 "asmshader.l" +{return COMP_GT; } + YY_BREAK +case 131: +YY_RULE_SETUP +#line 312 "asmshader.l" +{return COMP_LT; } + YY_BREAK +case 132: +YY_RULE_SETUP +#line 313 "asmshader.l" +{return COMP_GE; } + YY_BREAK +case 133: +YY_RULE_SETUP +#line 314 "asmshader.l" +{return COMP_LE; } + YY_BREAK +case 134: +YY_RULE_SETUP +#line 315 "asmshader.l" +{return COMP_EQ; } + YY_BREAK +case 135: +YY_RULE_SETUP +#line 316 "asmshader.l" +{return COMP_NE; } + YY_BREAK +case 136: +YY_RULE_SETUP +#line 318 "asmshader.l" +{ + asmshader_lval.immval.val = atof(asmshader_text); + asmshader_lval.immval.integer = ((strstr(asmshader_text, ".") == NULL) && (strstr(asmshader_text, "f") == NULL)); + return IMMVAL; + } + YY_BREAK +case 137: +YY_RULE_SETUP +#line 323 "asmshader.l" +{ + asmshader_lval.immbool = TRUE; + return IMMBOOL; + } + YY_BREAK +case 138: +YY_RULE_SETUP +#line 327 "asmshader.l" +{ + asmshader_lval.immbool = FALSE; + return IMMBOOL; + } + YY_BREAK +case 139: +YY_RULE_SETUP +#line 332 "asmshader.l" +{return asmshader_text[0]; } + YY_BREAK +case 140: +YY_RULE_SETUP +#line 333 "asmshader.l" +{return asmshader_text[0]; } + YY_BREAK +case 141: +YY_RULE_SETUP +#line 334 "asmshader.l" +{return asmshader_text[0]; } + YY_BREAK +case 142: +YY_RULE_SETUP +#line 335 "asmshader.l" +{return asmshader_text[0]; } + YY_BREAK +/* for relative addressing */ +case 143: +YY_RULE_SETUP +#line 338 "asmshader.l" +{return asmshader_text[0]; } + YY_BREAK +case 144: +YY_RULE_SETUP +#line 340 "asmshader.l" +{return SMOD_BIAS; } + YY_BREAK +/* No _x2 here; it is identical to MOD_X2 */ +case 145: +YY_RULE_SETUP +#line 342 "asmshader.l" +{return SMOD_SCALEBIAS; } + YY_BREAK +case 146: +YY_RULE_SETUP +#line 343 "asmshader.l" +{return SMOD_DZ; } + YY_BREAK +case 147: +YY_RULE_SETUP +#line 344 "asmshader.l" +{return SMOD_DW; } + YY_BREAK +case 148: +YY_RULE_SETUP +#line 345 "asmshader.l" +{return SMOD_ABS; } + YY_BREAK +case 149: +YY_RULE_SETUP +#line 347 "asmshader.l" +{return SMOD_NOT; } + YY_BREAK +case 150: +YY_RULE_SETUP +#line 349 "asmshader.l" +{ + if(asmshader_text[strlen("_position")] == '\0') { + asmshader_lval.regnum = 0; + } else { + asmshader_lval.regnum = atoi(asmshader_text + strlen("_position")); + } + return USAGE_POSITION; + } + YY_BREAK +case 151: +YY_RULE_SETUP +#line 357 "asmshader.l" +{ + if(asmshader_text[strlen("_blendweight")] == '\0') { + asmshader_lval.regnum = 0; + } else { + asmshader_lval.regnum = atoi(asmshader_text + strlen("_blendweight")); + } + return USAGE_BLENDWEIGHT; + } + YY_BREAK +case 152: +YY_RULE_SETUP +#line 365 "asmshader.l" +{ + if(asmshader_text[strlen("_blendindices")] == '\0') { + asmshader_lval.regnum = 0; + } else { + asmshader_lval.regnum = atoi(asmshader_text + strlen("_blendindices")); + } + return USAGE_BLENDINDICES; + } + YY_BREAK +case 153: +YY_RULE_SETUP +#line 373 "asmshader.l" +{ + if(asmshader_text[strlen("_normal")] == '\0') { + asmshader_lval.regnum = 0; + } else { + asmshader_lval.regnum = atoi(asmshader_text + strlen("_normal")); + } + return USAGE_NORMAL; + } + YY_BREAK +case 154: +YY_RULE_SETUP +#line 381 "asmshader.l" +{ + if(asmshader_text[strlen("_psize")] == '\0') { + asmshader_lval.regnum = 0; + } else { + asmshader_lval.regnum = atoi(asmshader_text + strlen("_psize")); + } + return USAGE_PSIZE; + } + YY_BREAK +case 155: +YY_RULE_SETUP +#line 389 "asmshader.l" +{ + if(asmshader_text[strlen("_texcoord")] == '\0') { + asmshader_lval.regnum = 0; + } else { + asmshader_lval.regnum = atoi(asmshader_text + strlen("_texcoord")); + } + return USAGE_TEXCOORD; + } + YY_BREAK +case 156: +YY_RULE_SETUP +#line 397 "asmshader.l" +{ + if(asmshader_text[strlen("_tangent")] == '\0') { + asmshader_lval.regnum = 0; + } else { + asmshader_lval.regnum = atoi(asmshader_text + strlen("_tangent")); + } + return USAGE_TANGENT; + } + YY_BREAK +case 157: +YY_RULE_SETUP +#line 405 "asmshader.l" +{ + if(asmshader_text[strlen("_binormal")] == '\0') { + asmshader_lval.regnum = 0; + } else { + asmshader_lval.regnum = atoi(asmshader_text + strlen("_binormal")); + } + return USAGE_BINORMAL; + } + YY_BREAK +case 158: +YY_RULE_SETUP +#line 413 "asmshader.l" +{ + if(asmshader_text[strlen("_tessfactor")] == '\0') { + asmshader_lval.regnum = 0; + } else { + asmshader_lval.regnum = atoi(asmshader_text + strlen("_tessfactor")); + } + return USAGE_TESSFACTOR; + } + YY_BREAK +case 159: +YY_RULE_SETUP +#line 421 "asmshader.l" +{ + if(asmshader_text[strlen("_positiont")] == '\0') { + asmshader_lval.regnum = 0; + } else { + asmshader_lval.regnum = atoi(asmshader_text + strlen("_positiont")); + } + return USAGE_POSITIONT; + } + YY_BREAK +case 160: +YY_RULE_SETUP +#line 429 "asmshader.l" +{ + if(asmshader_text[strlen("_color")] == '\0') { + asmshader_lval.regnum = 0; + } else { + asmshader_lval.regnum = atoi(asmshader_text + strlen("_color")); + } + return USAGE_COLOR; + } + YY_BREAK +case 161: +YY_RULE_SETUP +#line 437 "asmshader.l" +{ + if(asmshader_text[strlen("_fog")] == '\0') { + asmshader_lval.regnum = 0; + } else { + asmshader_lval.regnum = atoi(asmshader_text + strlen("_fog")); + } + return USAGE_FOG; + } + YY_BREAK +case 162: +YY_RULE_SETUP +#line 445 "asmshader.l" +{ + if(asmshader_text[strlen("_depth")] == '\0') { + asmshader_lval.regnum = 0; + } else { + asmshader_lval.regnum = atoi(asmshader_text + strlen("_depth")); + } + return USAGE_DEPTH; + } + YY_BREAK +case 163: +YY_RULE_SETUP +#line 453 "asmshader.l" +{ + if(asmshader_text[strlen("_sample")] == '\0') { + asmshader_lval.regnum = 0; + } else { + asmshader_lval.regnum = atoi(asmshader_text + strlen("_sample")); + } + return USAGE_SAMPLE; + } + YY_BREAK +case 164: +YY_RULE_SETUP +#line 462 "asmshader.l" +{ return SAMPTYPE_1D; } + YY_BREAK +case 165: +YY_RULE_SETUP +#line 463 "asmshader.l" +{ return SAMPTYPE_2D; } + YY_BREAK +case 166: +YY_RULE_SETUP +#line 464 "asmshader.l" +{ return SAMPTYPE_CUBE; } + YY_BREAK +case 167: +YY_RULE_SETUP +#line 465 "asmshader.l" +{ return SAMPTYPE_VOLUME; } + YY_BREAK +case 168: +/* rule 168 can match eol */ +YY_RULE_SETUP +#line 467 "asmshader.l" +{ + /* TODO: update current line information */ + TRACE("line info update: %s", asmshader_text); + } + YY_BREAK +/* Skip comments */ +case 169: +YY_RULE_SETUP +#line 473 "asmshader.l" +{ } + YY_BREAK +case 170: +YY_RULE_SETUP +#line 474 "asmshader.l" +{ } + YY_BREAK +case 171: +YY_RULE_SETUP +#line 476 "asmshader.l" +{ /* Do nothing */ } + YY_BREAK +case 172: +/* rule 172 can match eol */ +YY_RULE_SETUP +#line 477 "asmshader.l" +{ + asm_ctx.line_no++; + } + YY_BREAK +case 173: +YY_RULE_SETUP +#line 481 "asmshader.l" +{ + asmparser_message(&asm_ctx, "Line %u: Unexpected input %s\n", asm_ctx.line_no, asmshader_text); + set_parse_status(&asm_ctx.status, PARSE_ERR); + } + YY_BREAK +case 174: +YY_RULE_SETUP +#line 486 "asmshader.l" +ECHO; + YY_BREAK +#line 2208 "asmshader.yy.c" +case YY_STATE_EOF(INITIAL): + yyterminate(); + + case YY_END_OF_BUFFER: + { + /* Amount of text matched not including the EOB char. */ + int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1; + + /* Undo the effects of YY_DO_BEFORE_ACTION. */ + *yy_cp = (yy_hold_char); + YY_RESTORE_YY_MORE_OFFSET + + if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW ) + { + /* We're scanning a new file or input source. It's + * possible that this happened because the user + * just pointed asmshader_in at a new source and called + * asmshader_lex(). If so, then we have to assure + * consistency between YY_CURRENT_BUFFER and our + * globals. Here is the right place to do so, because + * this is the first action (other than possibly a + * back-up) that will match for the new input source. + */ + (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + YY_CURRENT_BUFFER_LVALUE->yy_input_file = asmshader_in; + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; + } + + /* Note that here we test for yy_c_buf_p "<=" to the position + * of the first EOB in the buffer, since yy_c_buf_p will + * already have been incremented past the NUL character + * (since all states make transitions on EOB to the + * end-of-buffer state). Contrast this with the test + * in input(). + */ + if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) + { /* This was really a NUL. */ + yy_state_type yy_next_state; + + (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state( ); + + /* Okay, we're now positioned to make the NUL + * transition. We couldn't have + * yy_get_previous_state() go ahead and do it + * for us because it doesn't know how to deal + * with the possibility of jamming (and we don't + * want to build jamming into it because then it + * will run more slowly). + */ + + yy_next_state = yy_try_NUL_trans( yy_current_state ); + + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + + if ( yy_next_state ) + { + /* Consume the NUL. */ + yy_cp = ++(yy_c_buf_p); + yy_current_state = yy_next_state; + goto yy_match; + } + + else + { + yy_cp = (yy_last_accepting_cpos); + yy_current_state = (yy_last_accepting_state); + goto yy_find_action; + } + } + + else switch ( yy_get_next_buffer( ) ) + { + case EOB_ACT_END_OF_FILE: + { + (yy_did_buffer_switch_on_eof) = 0; + + if ( asmshader_wrap( ) ) + { + /* Note: because we've taken care in + * yy_get_next_buffer() to have set up + * asmshader_text, we can now set up + * yy_c_buf_p so that if some total + * hoser (like flex itself) wants to + * call the scanner after we return the + * YY_NULL, it'll still work - another + * YY_NULL will get returned. + */ + (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ; + + yy_act = YY_STATE_EOF(YY_START); + goto do_action; + } + + else + { + if ( ! (yy_did_buffer_switch_on_eof) ) + YY_NEW_FILE; + } + break; + } + + case EOB_ACT_CONTINUE_SCAN: + (yy_c_buf_p) = + (yytext_ptr) + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state( ); + + yy_cp = (yy_c_buf_p); + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + goto yy_match; + + case EOB_ACT_LAST_MATCH: + (yy_c_buf_p) = + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)]; + + yy_current_state = yy_get_previous_state( ); + + yy_cp = (yy_c_buf_p); + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + goto yy_find_action; + } + break; + } + + default: + YY_FATAL_ERROR( + "fatal flex scanner internal error--no action found" ); + } /* end of action switch */ + } /* end of scanning one token */ +} /* end of asmshader_lex */ + +/* yy_get_next_buffer - try to read in a new buffer + * + * Returns a code representing an action: + * EOB_ACT_LAST_MATCH - + * EOB_ACT_CONTINUE_SCAN - continue scanning from current position + * EOB_ACT_END_OF_FILE - end of file + */ +static int yy_get_next_buffer (void) +{ + register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; + register char *source = (yytext_ptr); + register int number_to_move, i; + int ret_val; + + if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] ) + YY_FATAL_ERROR( + "fatal flex scanner internal error--end of buffer missed" ); + + if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 ) + { /* Don't try to fill the buffer, so this is an EOF. */ + if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 ) + { + /* We matched a single character, the EOB, so + * treat this as a final EOF. + */ + return EOB_ACT_END_OF_FILE; + } + + else + { + /* We matched some text prior to the EOB, first + * process it. + */ + return EOB_ACT_LAST_MATCH; + } + } + + /* Try to read more data. */ + + /* First move last chars to start of buffer. */ + number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr)) - 1; + + for ( i = 0; i < number_to_move; ++i ) + *(dest++) = *(source++); + + if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING ) + /* don't do the read, it's not guaranteed to return an EOF, + * just force an EOF + */ + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0; + + else + { + int num_to_read = + YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; + + while ( num_to_read <= 0 ) + { /* Not enough room in the buffer - grow it. */ + + /* just a shorter name for the current buffer */ + YY_BUFFER_STATE b = YY_CURRENT_BUFFER; + + int yy_c_buf_p_offset = + (int) ((yy_c_buf_p) - b->yy_ch_buf); + + if ( b->yy_is_our_buffer ) + { + int new_size = b->yy_buf_size * 2; + + if ( new_size <= 0 ) + b->yy_buf_size += b->yy_buf_size / 8; + else + b->yy_buf_size *= 2; + + b->yy_ch_buf = (char *) + /* Include room in for 2 EOB chars. */ + asmshader_realloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 ); + } + else + /* Can't grow it, we don't own it. */ + b->yy_ch_buf = 0; + + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( + "fatal error - scanner input buffer overflow" ); + + (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset]; + + num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - + number_to_move - 1; + + } + + if ( num_to_read > YY_READ_BUF_SIZE ) + num_to_read = YY_READ_BUF_SIZE; + + /* Read in more data. */ + YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), + (yy_n_chars), (size_t) num_to_read ); + + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + if ( (yy_n_chars) == 0 ) + { + if ( number_to_move == YY_MORE_ADJ ) + { + ret_val = EOB_ACT_END_OF_FILE; + asmshader_restart(asmshader_in ); + } + + else + { + ret_val = EOB_ACT_LAST_MATCH; + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = + YY_BUFFER_EOF_PENDING; + } + } + + else + ret_val = EOB_ACT_CONTINUE_SCAN; + + if ((yy_size_t) ((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { + /* Extend the array by 50%, plus the number we really need. */ + yy_size_t new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1); + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) asmshader_realloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ); + if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); + } + + (yy_n_chars) += number_to_move; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR; + + (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; + + return ret_val; +} + +/* yy_get_previous_state - get the state just before the EOB char was reached */ + + static yy_state_type yy_get_previous_state (void) +{ + register yy_state_type yy_current_state; + register char *yy_cp; + + yy_current_state = (yy_start); + + for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp ) + { + register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 481 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + } + + return yy_current_state; +} + +/* yy_try_NUL_trans - try to make a transition on the NUL character + * + * synopsis + * next_state = yy_try_NUL_trans( current_state ); + */ + static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state ) +{ + register int yy_is_jam; + register char *yy_cp = (yy_c_buf_p); + + register YY_CHAR yy_c = 1; + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 481 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + yy_is_jam = (yy_current_state == 480); + + return yy_is_jam ? 0 : yy_current_state; +} + +#ifndef YY_NO_INPUT +#ifdef __cplusplus + static int yyinput (void) +#else + static int input (void) +#endif + +{ + int c; + + *(yy_c_buf_p) = (yy_hold_char); + + if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR ) + { + /* yy_c_buf_p now points to the character we want to return. + * If this occurs *before* the EOB characters, then it's a + * valid NUL; if not, then we've hit the end of the buffer. + */ + if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) + /* This was really a NUL. */ + *(yy_c_buf_p) = '\0'; + + else + { /* need more input */ + int offset = (yy_c_buf_p) - (yytext_ptr); + ++(yy_c_buf_p); + + switch ( yy_get_next_buffer( ) ) + { + case EOB_ACT_LAST_MATCH: + /* This happens because yy_g_n_b() + * sees that we've accumulated a + * token and flags that we need to + * try matching the token before + * proceeding. But for input(), + * there's no matching to consider. + * So convert the EOB_ACT_LAST_MATCH + * to EOB_ACT_END_OF_FILE. + */ + + /* Reset buffer status. */ + asmshader_restart(asmshader_in ); + + /*FALLTHROUGH*/ + + case EOB_ACT_END_OF_FILE: + { + if ( asmshader_wrap( ) ) + return EOF; + + if ( ! (yy_did_buffer_switch_on_eof) ) + YY_NEW_FILE; +#ifdef __cplusplus + return yyinput(); +#else + return input(); +#endif + } + + case EOB_ACT_CONTINUE_SCAN: + (yy_c_buf_p) = (yytext_ptr) + offset; + break; + } + } + } + + c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */ + *(yy_c_buf_p) = '\0'; /* preserve asmshader_text */ + (yy_hold_char) = *++(yy_c_buf_p); + + return c; +} +#endif /* ifndef YY_NO_INPUT */ + +/** Immediately switch to a different input stream. + * @param input_file A readable stream. + * + * @note This function does not reset the start condition to @c INITIAL . + */ + void asmshader_restart (FILE * input_file ) +{ + + if ( ! YY_CURRENT_BUFFER ){ + asmshader_ensure_buffer_stack (); + YY_CURRENT_BUFFER_LVALUE = + asmshader__create_buffer(asmshader_in,YY_BUF_SIZE ); + } + + asmshader__init_buffer(YY_CURRENT_BUFFER,input_file ); + asmshader__load_buffer_state( ); +} + +/** Switch to a different input buffer. + * @param new_buffer The new input buffer. + * + */ + void asmshader__switch_to_buffer (YY_BUFFER_STATE new_buffer ) +{ + + /* TODO. We should be able to replace this entire function body + * with + * asmshader_pop_buffer_state(); + * asmshader_push_buffer_state(new_buffer); + */ + asmshader_ensure_buffer_stack (); + if ( YY_CURRENT_BUFFER == new_buffer ) + return; + + if ( YY_CURRENT_BUFFER ) + { + /* Flush out information for old buffer. */ + *(yy_c_buf_p) = (yy_hold_char); + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + YY_CURRENT_BUFFER_LVALUE = new_buffer; + asmshader__load_buffer_state( ); + + /* We don't actually know whether we did this switch during + * EOF (asmshader_wrap()) processing, but the only time this flag + * is looked at is after asmshader_wrap() is called, so it's safe + * to go ahead and always set it. + */ + (yy_did_buffer_switch_on_eof) = 1; +} + +static void asmshader__load_buffer_state (void) +{ + (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; + asmshader_in = YY_CURRENT_BUFFER_LVALUE->yy_input_file; + (yy_hold_char) = *(yy_c_buf_p); +} + +/** Allocate and initialize an input buffer state. + * @param file A readable stream. + * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. + * + * @return the allocated buffer state. + */ + YY_BUFFER_STATE asmshader__create_buffer (FILE * file, int size ) +{ + YY_BUFFER_STATE b; + + b = (YY_BUFFER_STATE) asmshader_alloc(sizeof( struct yy_buffer_state ) ); + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in asmshader__create_buffer()" ); + + b->yy_buf_size = size; + + /* yy_ch_buf has to be 2 characters longer than the size given because + * we need to put in 2 end-of-buffer characters. + */ + b->yy_ch_buf = (char *) asmshader_alloc(b->yy_buf_size + 2 ); + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in asmshader__create_buffer()" ); + + b->yy_is_our_buffer = 1; + + asmshader__init_buffer(b,file ); + + return b; +} + +/** Destroy the buffer. + * @param b a buffer created with asmshader__create_buffer() + * + */ + void asmshader__delete_buffer (YY_BUFFER_STATE b ) +{ + + if ( ! b ) + return; + + if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */ + YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; + + if ( b->yy_is_our_buffer ) + asmshader_free((void *) b->yy_ch_buf ); + + asmshader_free((void *) b ); +} + +/* Initializes or reinitializes a buffer. + * This function is sometimes called more than once on the same buffer, + * such as during a asmshader_restart() or at EOF. + */ + static void asmshader__init_buffer (YY_BUFFER_STATE b, FILE * file ) + +{ + int oerrno = errno; + + asmshader__flush_buffer(b ); + + b->yy_input_file = file; + b->yy_fill_buffer = 1; + + /* If b is the current buffer, then asmshader__init_buffer was _probably_ + * called from asmshader_restart() or through yy_get_next_buffer. + * In that case, we don't want to reset the lineno or column. + */ + if (b != YY_CURRENT_BUFFER){ + b->yy_bs_lineno = 1; + b->yy_bs_column = 0; + } + + b->yy_is_interactive = 0; + + errno = oerrno; +} + +/** Discard all buffered characters. On the next scan, YY_INPUT will be called. + * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER. + * + */ + void asmshader__flush_buffer (YY_BUFFER_STATE b ) +{ + if ( ! b ) + return; + + b->yy_n_chars = 0; + + /* We always need two end-of-buffer characters. The first causes + * a transition to the end-of-buffer state. The second causes + * a jam in that state. + */ + b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; + b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; + + b->yy_buf_pos = &b->yy_ch_buf[0]; + + b->yy_at_bol = 1; + b->yy_buffer_status = YY_BUFFER_NEW; + + if ( b == YY_CURRENT_BUFFER ) + asmshader__load_buffer_state( ); +} + +/** Pushes the new state onto the stack. The new state becomes + * the current state. This function will allocate the stack + * if necessary. + * @param new_buffer The new state. + * + */ +void asmshader_push_buffer_state (YY_BUFFER_STATE new_buffer ) +{ + if (new_buffer == NULL) + return; + + asmshader_ensure_buffer_stack(); + + /* This block is copied from asmshader__switch_to_buffer. */ + if ( YY_CURRENT_BUFFER ) + { + /* Flush out information for old buffer. */ + *(yy_c_buf_p) = (yy_hold_char); + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + /* Only push if top exists. Otherwise, replace top. */ + if (YY_CURRENT_BUFFER) + (yy_buffer_stack_top)++; + YY_CURRENT_BUFFER_LVALUE = new_buffer; + + /* copied from asmshader__switch_to_buffer. */ + asmshader__load_buffer_state( ); + (yy_did_buffer_switch_on_eof) = 1; +} + +/** Removes and deletes the top of the stack, if present. + * The next element becomes the new top. + * + */ +void asmshader_pop_buffer_state (void) +{ + if (!YY_CURRENT_BUFFER) + return; + + asmshader__delete_buffer(YY_CURRENT_BUFFER ); + YY_CURRENT_BUFFER_LVALUE = NULL; + if ((yy_buffer_stack_top) > 0) + --(yy_buffer_stack_top); + + if (YY_CURRENT_BUFFER) { + asmshader__load_buffer_state( ); + (yy_did_buffer_switch_on_eof) = 1; + } +} + +/* Allocates the stack if it does not exist. + * Guarantees space for at least one push. + */ +static void asmshader_ensure_buffer_stack (void) +{ + int num_to_alloc; + + if (!(yy_buffer_stack)) { + + /* First allocation is just for 2 elements, since we don't know if this + * scanner will even need a stack. We use 2 instead of 1 to avoid an + * immediate realloc on the next call. + */ + num_to_alloc = 1; + (yy_buffer_stack) = (struct yy_buffer_state**)asmshader_alloc + (num_to_alloc * sizeof(struct yy_buffer_state*) + ); + if ( ! (yy_buffer_stack) ) + YY_FATAL_ERROR( "out of dynamic memory in asmshader_ensure_buffer_stack()" ); + + memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*)); + + (yy_buffer_stack_max) = num_to_alloc; + (yy_buffer_stack_top) = 0; + return; + } + + if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){ + + /* Increase the buffer to prepare for a possible push. */ + int grow_size = 8 /* arbitrary grow size */; + + num_to_alloc = (yy_buffer_stack_max) + grow_size; + (yy_buffer_stack) = (struct yy_buffer_state**)asmshader_realloc + ((yy_buffer_stack), + num_to_alloc * sizeof(struct yy_buffer_state*) + ); + if ( ! (yy_buffer_stack) ) + YY_FATAL_ERROR( "out of dynamic memory in asmshader_ensure_buffer_stack()" ); + + /* zero only the new slots.*/ + memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*)); + (yy_buffer_stack_max) = num_to_alloc; + } +} + +/** Setup the input buffer state to scan directly from a user-specified character buffer. + * @param base the character buffer + * @param size the size in bytes of the character buffer + * + * @return the newly allocated buffer state object. + */ +YY_BUFFER_STATE asmshader__scan_buffer (char * base, yy_size_t size ) +{ + YY_BUFFER_STATE b; + + if ( size < 2 || + base[size-2] != YY_END_OF_BUFFER_CHAR || + base[size-1] != YY_END_OF_BUFFER_CHAR ) + /* They forgot to leave room for the EOB's. */ + return 0; + + b = (YY_BUFFER_STATE) asmshader_alloc(sizeof( struct yy_buffer_state ) ); + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in asmshader__scan_buffer()" ); + + b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */ + b->yy_buf_pos = b->yy_ch_buf = base; + b->yy_is_our_buffer = 0; + b->yy_input_file = 0; + b->yy_n_chars = b->yy_buf_size; + b->yy_is_interactive = 0; + b->yy_at_bol = 1; + b->yy_fill_buffer = 0; + b->yy_buffer_status = YY_BUFFER_NEW; + + asmshader__switch_to_buffer(b ); + + return b; +} + +/** Setup the input buffer state to scan a string. The next call to asmshader_lex() will + * scan from a @e copy of @a str. + * @param yystr a NUL-terminated string to scan + * + * @return the newly allocated buffer state object. + * @note If you want to scan bytes that may contain NUL values, then use + * asmshader__scan_bytes() instead. + */ +YY_BUFFER_STATE asmshader__scan_string (yyconst char * yystr ) +{ + + return asmshader__scan_bytes(yystr,strlen(yystr) ); +} + +/** Setup the input buffer state to scan the given bytes. The next call to asmshader_lex() will + * scan from a @e copy of @a bytes. + * @param yybytes the byte buffer to scan + * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes. + * + * @return the newly allocated buffer state object. + */ +YY_BUFFER_STATE asmshader__scan_bytes (yyconst char * yybytes, int _yybytes_len ) +{ + YY_BUFFER_STATE b; + char *buf; + yy_size_t n; + int i; + + /* Get memory for full buffer, including space for trailing EOB's. */ + n = _yybytes_len + 2; + buf = (char *) asmshader_alloc(n ); + if ( ! buf ) + YY_FATAL_ERROR( "out of dynamic memory in asmshader__scan_bytes()" ); + + for ( i = 0; i < _yybytes_len; ++i ) + buf[i] = yybytes[i]; + + buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR; + + b = asmshader__scan_buffer(buf,n ); + if ( ! b ) + YY_FATAL_ERROR( "bad buffer in asmshader__scan_bytes()" ); + + /* It's okay to grow etc. this buffer, and we should throw it + * away when we're done. + */ + b->yy_is_our_buffer = 1; + + return b; +} + +#ifndef YY_EXIT_FAILURE +#define YY_EXIT_FAILURE 2 +#endif + +static void yy_fatal_error (yyconst char* msg ) +{ + (void) fprintf( stderr, "%s\n", msg ); + exit( YY_EXIT_FAILURE ); +} + +/* Redefine yyless() so it works in section 3 code. */ + +#undef yyless +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up asmshader_text. */ \ + int yyless_macro_arg = (n); \ + YY_LESS_LINENO(yyless_macro_arg);\ + asmshader_text[asmshader_leng] = (yy_hold_char); \ + (yy_c_buf_p) = asmshader_text + yyless_macro_arg; \ + (yy_hold_char) = *(yy_c_buf_p); \ + *(yy_c_buf_p) = '\0'; \ + asmshader_leng = yyless_macro_arg; \ + } \ + while ( 0 ) + +/* Accessor methods (get/set functions) to struct members. */ + +/** Get the current line number. + * + */ +int asmshader_get_lineno (void) +{ + + return asmshader_lineno; +} + +/** Get the input stream. + * + */ +FILE *asmshader_get_in (void) +{ + return asmshader_in; +} + +/** Get the output stream. + * + */ +FILE *asmshader_get_out (void) +{ + return asmshader_out; +} + +/** Get the length of the current token. + * + */ +int asmshader_get_leng (void) +{ + return asmshader_leng; +} + +/** Get the current token. + * + */ + +char *asmshader_get_text (void) +{ + return asmshader_text; +} + +/** Set the current line number. + * @param line_number + * + */ +void asmshader_set_lineno (int line_number ) +{ + + asmshader_lineno = line_number; +} + +/** Set the input stream. This does not discard the current + * input buffer. + * @param in_str A readable stream. + * + * @see asmshader__switch_to_buffer + */ +void asmshader_set_in (FILE * in_str ) +{ + asmshader_in = in_str ; +} + +void asmshader_set_out (FILE * out_str ) +{ + asmshader_out = out_str ; +} + +int asmshader_get_debug (void) +{ + return asmshader__flex_debug; +} + +void asmshader_set_debug (int bdebug ) +{ + asmshader__flex_debug = bdebug ; +} + +static int yy_init_globals (void) +{ + /* Initialization is the same as for the non-reentrant scanner. + * This function is called from asmshader_lex_destroy(), so don't allocate here. + */ + + (yy_buffer_stack) = 0; + (yy_buffer_stack_top) = 0; + (yy_buffer_stack_max) = 0; + (yy_c_buf_p) = (char *) 0; + (yy_init) = 0; + (yy_start) = 0; + +/* Defined in main.c */ +#ifdef YY_STDINIT + asmshader_in = stdin; + asmshader_out = stdout; +#else + asmshader_in = (FILE *) 0; + asmshader_out = (FILE *) 0; +#endif + + /* For future reference: Set errno on error, since we are called by + * asmshader_lex_init() + */ + return 0; +} + +/* asmshader_lex_destroy is for both reentrant and non-reentrant scanners. */ +int asmshader_lex_destroy (void) +{ + + /* Pop the buffer stack, destroying each element. */ + while(YY_CURRENT_BUFFER){ + asmshader__delete_buffer(YY_CURRENT_BUFFER ); + YY_CURRENT_BUFFER_LVALUE = NULL; + asmshader_pop_buffer_state(); + } + + /* Destroy the stack itself. */ + asmshader_free((yy_buffer_stack) ); + (yy_buffer_stack) = NULL; + + /* Reset the globals. This is important in a non-reentrant scanner so the next time + * asmshader_lex() is called, initialization will occur. */ + yy_init_globals( ); + + return 0; +} + +/* + * Internal utility routines. + */ + +#ifndef yytext_ptr +static void yy_flex_strncpy (char* s1, yyconst char * s2, int n ) +{ + register int i; + for ( i = 0; i < n; ++i ) + s1[i] = s2[i]; +} +#endif + +#ifdef YY_NEED_STRLEN +static int yy_flex_strlen (yyconst char * s ) +{ + register int n; + for ( n = 0; s[n]; ++n ) + ; + + return n; +} +#endif + +void *asmshader_alloc (yy_size_t size ) +{ + return (void *) malloc( size ); +} + +void *asmshader_realloc (void * ptr, yy_size_t size ) +{ + /* The cast to (char *) in the following accommodates both + * implementations that use char* generic pointers, and those + * that use void* generic pointers. It works with the latter + * because both ANSI C and C++ allow castless assignment from + * any pointer type to void*, and deal with argument conversions + * as though doing an assignment. + */ + return (void *) realloc( (char *) ptr, size ); +} + +void asmshader_free (void * ptr ) +{ + free( (char *) ptr ); /* see asmshader_realloc() for (char *) cast */ +} + +#define YYTABLES_NAME "yytables" + +#line 486 "asmshader.l" + + + +struct bwriter_shader *SlAssembleShader(const char *text, char **messages) { + struct bwriter_shader *ret = NULL; + YY_BUFFER_STATE buffer; + TRACE("%p, %p\n", text, messages); + + buffer = asmshader__scan_string(text); + asmshader__switch_to_buffer(buffer); + + ret = parse_asm_shader(messages); + + asmshader__delete_buffer(buffer); + + return ret; +} + diff --git a/reactos/dll/directx/wine/d3dcompiler_43/blob.c b/reactos/dll/directx/wine/d3dcompiler_43/blob.c new file mode 100644 index 00000000000..865d139ccd8 --- /dev/null +++ b/reactos/dll/directx/wine/d3dcompiler_43/blob.c @@ -0,0 +1,465 @@ +/* + * Direct3D blob file + * + * Copyright 2010 Rico Schüller + * + * 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 "d3dcompiler_private.h" + +WINE_DEFAULT_DEBUG_CHANNEL(d3dcompiler); + +struct d3dcompiler_blob +{ + ID3DBlob ID3DBlob_iface; + LONG refcount; + + SIZE_T size; + void *data; +}; + +static inline struct d3dcompiler_blob *impl_from_ID3DBlob(ID3DBlob *iface) +{ + return CONTAINING_RECORD(iface, struct d3dcompiler_blob, ID3DBlob_iface); +} + +/* IUnknown methods */ + +static HRESULT STDMETHODCALLTYPE d3dcompiler_blob_QueryInterface(ID3DBlob *iface, REFIID riid, void **object) +{ + TRACE("iface %p, riid %s, object %p\n", iface, debugstr_guid(riid), object); + + if (IsEqualGUID(riid, &IID_ID3D10Blob) + || IsEqualGUID(riid, &IID_IUnknown)) + { + IUnknown_AddRef(iface); + *object = iface; + return S_OK; + } + + WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid)); + + *object = NULL; + return E_NOINTERFACE; +} + +static ULONG STDMETHODCALLTYPE d3dcompiler_blob_AddRef(ID3DBlob *iface) +{ + struct d3dcompiler_blob *blob = impl_from_ID3DBlob(iface); + ULONG refcount = InterlockedIncrement(&blob->refcount); + + TRACE("%p increasing refcount to %u\n", blob, refcount); + + return refcount; +} + +static ULONG STDMETHODCALLTYPE d3dcompiler_blob_Release(ID3DBlob *iface) +{ + struct d3dcompiler_blob *blob = impl_from_ID3DBlob(iface); + ULONG refcount = InterlockedDecrement(&blob->refcount); + + TRACE("%p decreasing refcount to %u\n", blob, refcount); + + if (!refcount) + { + HeapFree(GetProcessHeap(), 0, blob->data); + HeapFree(GetProcessHeap(), 0, blob); + } + + return refcount; +} + +/* ID3DBlob methods */ + +static void * STDMETHODCALLTYPE d3dcompiler_blob_GetBufferPointer(ID3DBlob *iface) +{ + struct d3dcompiler_blob *blob = impl_from_ID3DBlob(iface); + + TRACE("iface %p\n", iface); + + return blob->data; +} + +static SIZE_T STDMETHODCALLTYPE d3dcompiler_blob_GetBufferSize(ID3DBlob *iface) +{ + struct d3dcompiler_blob *blob = impl_from_ID3DBlob(iface); + + TRACE("iface %p\n", iface); + + return blob->size; +} + +static const struct ID3D10BlobVtbl d3dcompiler_blob_vtbl = +{ + /* IUnknown methods */ + d3dcompiler_blob_QueryInterface, + d3dcompiler_blob_AddRef, + d3dcompiler_blob_Release, + /* ID3DBlob methods */ + d3dcompiler_blob_GetBufferPointer, + d3dcompiler_blob_GetBufferSize, +}; + +static HRESULT d3dcompiler_blob_init(struct d3dcompiler_blob *blob, SIZE_T data_size) +{ + blob->ID3DBlob_iface.lpVtbl = &d3dcompiler_blob_vtbl; + blob->refcount = 1; + blob->size = data_size; + + blob->data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, data_size); + if (!blob->data) + { + ERR("Failed to allocate D3D blob data memory\n"); + return E_OUTOFMEMORY; + } + + return S_OK; +} + +HRESULT WINAPI D3DCreateBlob(SIZE_T data_size, ID3DBlob **blob) +{ + struct d3dcompiler_blob *object; + HRESULT hr; + + TRACE("data_size %lu, blob %p\n", data_size, blob); + + if (!blob) + { + WARN("Invalid blob specified.\n"); + return D3DERR_INVALIDCALL; + } + + object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object)); + if (!object) + return E_OUTOFMEMORY; + + hr = d3dcompiler_blob_init(object, data_size); + if (FAILED(hr)) + { + WARN("Failed to initialize blob, hr %#x.\n", hr); + HeapFree(GetProcessHeap(), 0, object); + return hr; + } + + *blob = &object->ID3DBlob_iface; + + TRACE("Created ID3DBlob %p\n", *blob); + + return S_OK; +} + +static BOOL check_blob_part(DWORD tag, D3D_BLOB_PART part) +{ + BOOL add = FALSE; + + switch(part) + { + case D3D_BLOB_INPUT_SIGNATURE_BLOB: + if (tag == TAG_ISGN) add = TRUE; + break; + + case D3D_BLOB_OUTPUT_SIGNATURE_BLOB: + if (tag == TAG_OSGN || tag == TAG_OSG5) add = TRUE; + break; + + case D3D_BLOB_INPUT_AND_OUTPUT_SIGNATURE_BLOB: + if (tag == TAG_ISGN || tag == TAG_OSGN || tag == TAG_OSG5) add = TRUE; + break; + + case D3D_BLOB_PATCH_CONSTANT_SIGNATURE_BLOB: + if (tag == TAG_PCSG) add = TRUE; + break; + + case D3D_BLOB_ALL_SIGNATURE_BLOB: + if (tag == TAG_ISGN || tag == TAG_OSGN || tag == TAG_OSG5 || tag == TAG_PCSG) add = TRUE; + break; + + case D3D_BLOB_DEBUG_INFO: + if (tag == TAG_SDBG) add = TRUE; + break; + + case D3D_BLOB_LEGACY_SHADER: + if (tag == TAG_Aon9) add = TRUE; + break; + + case D3D_BLOB_XNA_PREPASS_SHADER: + if (tag == TAG_XNAP) add = TRUE; + break; + + case D3D_BLOB_XNA_SHADER: + if (tag == TAG_XNAS) add = TRUE; + break; + + default: + FIXME("Unhandled D3D_BLOB_PART %s.\n", debug_d3dcompiler_d3d_blob_part(part)); + break; + } + + TRACE("%s tag %s\n", add ? "Add" : "Skip", debugstr_an((const char *)&tag, 4)); + + return add; +} + +static HRESULT d3dcompiler_get_blob_part(const void *data, SIZE_T data_size, D3D_BLOB_PART part, UINT flags, ID3DBlob **blob) +{ + struct dxbc src_dxbc, dst_dxbc; + HRESULT hr; + unsigned int i, count; + + if (!data || !data_size || flags || !blob) + { + WARN("Invalid arguments: data %p, data_size %lu, flags %#x, blob %p\n", data, data_size, flags, blob); + return D3DERR_INVALIDCALL; + } + + if (part > D3D_BLOB_TEST_COMPILE_PERF + || (part < D3D_BLOB_TEST_ALTERNATE_SHADER && part > D3D_BLOB_XNA_SHADER)) + { + WARN("Invalid D3D_BLOB_PART: part %s\n", debug_d3dcompiler_d3d_blob_part(part)); + return D3DERR_INVALIDCALL; + } + + hr = dxbc_parse(data, data_size, &src_dxbc); + if (FAILED(hr)) + { + WARN("Failed to parse blob part\n"); + return hr; + } + + hr = dxbc_init(&dst_dxbc, 0); + if (FAILED(hr)) + { + dxbc_destroy(&src_dxbc); + WARN("Failed to init dxbc\n"); + return hr; + } + + for (i = 0; i < src_dxbc.count; ++i) + { + struct dxbc_section *section = &src_dxbc.sections[i]; + + if (check_blob_part(section->tag, part)) + { + hr = dxbc_add_section(&dst_dxbc, section->tag, section->data, section->data_size); + if (FAILED(hr)) + { + dxbc_destroy(&src_dxbc); + dxbc_destroy(&dst_dxbc); + WARN("Failed to add section to dxbc\n"); + return hr; + } + } + } + + count = dst_dxbc.count; + + switch(part) + { + case D3D_BLOB_INPUT_SIGNATURE_BLOB: + case D3D_BLOB_OUTPUT_SIGNATURE_BLOB: + case D3D_BLOB_PATCH_CONSTANT_SIGNATURE_BLOB: + case D3D_BLOB_DEBUG_INFO: + case D3D_BLOB_LEGACY_SHADER: + case D3D_BLOB_XNA_PREPASS_SHADER: + case D3D_BLOB_XNA_SHADER: + if (count != 1) count = 0; + break; + + case D3D_BLOB_INPUT_AND_OUTPUT_SIGNATURE_BLOB: + if (count != 2) count = 0; + break; + + case D3D_BLOB_ALL_SIGNATURE_BLOB: + if (count != 3) count = 0; + break; + + default: + FIXME("Unhandled D3D_BLOB_PART %s.\n", debug_d3dcompiler_d3d_blob_part(part)); + break; + } + + if (count == 0) + { + dxbc_destroy(&src_dxbc); + dxbc_destroy(&dst_dxbc); + WARN("Nothing to write into the blob (count = 0)\n"); + return E_FAIL; + } + + /* some parts aren't full DXBCs, they contain only the data */ + if (count == 1 && (part == D3D_BLOB_DEBUG_INFO || part == D3D_BLOB_LEGACY_SHADER || part == D3D_BLOB_XNA_PREPASS_SHADER + || part == D3D_BLOB_XNA_SHADER)) + { + hr = D3DCreateBlob(dst_dxbc.sections[0].data_size, blob); + if (SUCCEEDED(hr)) + { + memcpy(ID3D10Blob_GetBufferPointer(*blob), dst_dxbc.sections[0].data, dst_dxbc.sections[0].data_size); + } + else + { + WARN("Could not create blob\n"); + } + } + else + { + hr = dxbc_write_blob(&dst_dxbc, blob); + if (FAILED(hr)) + { + WARN("Failed to write blob part\n"); + } + } + + dxbc_destroy(&src_dxbc); + dxbc_destroy(&dst_dxbc); + + return hr; +} + +static BOOL check_blob_strip(DWORD tag, UINT flags) +{ + BOOL add = TRUE; + + if (flags & D3DCOMPILER_STRIP_TEST_BLOBS) FIXME("Unhandled flag D3DCOMPILER_STRIP_TEST_BLOBS.\n"); + + switch(tag) + { + case TAG_RDEF: + case TAG_STAT: + if (flags & D3DCOMPILER_STRIP_REFLECTION_DATA) add = FALSE; + break; + + case TAG_SDBG: + if (flags & D3DCOMPILER_STRIP_DEBUG_INFO) add = FALSE; + break; + + default: + break; + } + + TRACE("%s tag %s\n", add ? "Add" : "Skip", debugstr_an((const char *)&tag, 4)); + + return add; +} + +static HRESULT d3dcompiler_strip_shader(const void *data, SIZE_T data_size, UINT flags, ID3DBlob **blob) +{ + struct dxbc src_dxbc, dst_dxbc; + HRESULT hr; + unsigned int i; + + if (!blob) + { + WARN("NULL for blob specified\n"); + return E_FAIL; + } + + if (!data || !data_size) + { + WARN("Invalid arguments: data %p, data_size %lu\n", data, data_size); + return D3DERR_INVALIDCALL; + } + + hr = dxbc_parse(data, data_size, &src_dxbc); + if (FAILED(hr)) + { + WARN("Failed to parse blob part\n"); + return hr; + } + + /* src_dxbc.count >= dst_dxbc.count */ + hr = dxbc_init(&dst_dxbc, src_dxbc.count); + if (FAILED(hr)) + { + dxbc_destroy(&src_dxbc); + WARN("Failed to init dxbc\n"); + return hr; + } + + for (i = 0; i < src_dxbc.count; ++i) + { + struct dxbc_section *section = &src_dxbc.sections[i]; + + if (check_blob_strip(section->tag, flags)) + { + hr = dxbc_add_section(&dst_dxbc, section->tag, section->data, section->data_size); + if (FAILED(hr)) + { + dxbc_destroy(&src_dxbc); + dxbc_destroy(&dst_dxbc); + WARN("Failed to add section to dxbc\n"); + return hr; + } + } + } + + hr = dxbc_write_blob(&dst_dxbc, blob); + if (FAILED(hr)) + { + WARN("Failed to write blob part\n"); + } + + dxbc_destroy(&src_dxbc); + dxbc_destroy(&dst_dxbc); + + return hr; +} + +HRESULT WINAPI D3DGetBlobPart(const void *data, SIZE_T data_size, D3D_BLOB_PART part, UINT flags, ID3DBlob **blob) +{ + TRACE("data %p, data_size %lu, part %s, flags %#x, blob %p\n", data, + data_size, debug_d3dcompiler_d3d_blob_part(part), flags, blob); + + return d3dcompiler_get_blob_part(data, data_size, part, flags, blob); +} + +HRESULT WINAPI D3DGetInputSignatureBlob(const void *data, SIZE_T data_size, ID3DBlob **blob) +{ + TRACE("data %p, data_size %lu, blob %p\n", data, data_size, blob); + + return d3dcompiler_get_blob_part(data, data_size, D3D_BLOB_INPUT_SIGNATURE_BLOB, 0, blob); +} + +HRESULT WINAPI D3DGetOutputSignatureBlob(const void *data, SIZE_T data_size, ID3DBlob **blob) +{ + TRACE("data %p, data_size %lu, blob %p\n", data, data_size, blob); + + return d3dcompiler_get_blob_part(data, data_size, D3D_BLOB_OUTPUT_SIGNATURE_BLOB, 0, blob); +} + +HRESULT WINAPI D3DGetInputAndOutputSignatureBlob(const void *data, SIZE_T data_size, ID3DBlob **blob) +{ + TRACE("data %p, data_size %lu, blob %p\n", data, data_size, blob); + + return d3dcompiler_get_blob_part(data, data_size, D3D_BLOB_INPUT_AND_OUTPUT_SIGNATURE_BLOB, 0, blob); +} + +HRESULT WINAPI D3DGetDebugInfo(const void *data, SIZE_T data_size, ID3DBlob **blob) +{ + TRACE("data %p, data_size %lu, blob %p\n", data, data_size, blob); + + return d3dcompiler_get_blob_part(data, data_size, D3D_BLOB_DEBUG_INFO, 0, blob); +} + +HRESULT WINAPI D3DStripShader(const void *data, SIZE_T data_size, UINT flags, ID3D10Blob **blob) +{ + TRACE("data %p, data_size %lu, flags %#x, blob %p\n", data, data_size, flags, blob); + + return d3dcompiler_strip_shader(data, data_size, flags, blob); +} diff --git a/reactos/dll/directx/wine/d3dcompiler_43/bytecodewriter.c b/reactos/dll/directx/wine/d3dcompiler_43/bytecodewriter.c new file mode 100644 index 00000000000..17289d230b6 --- /dev/null +++ b/reactos/dll/directx/wine/d3dcompiler_43/bytecodewriter.c @@ -0,0 +1,2630 @@ +/* + * Direct3D bytecode output functions + * + * Copyright 2008 Stefan Dösinger + * Copyright 2009 Matteo Bruni + * + * 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" + +#include "d3d9types.h" +#include "d3dcompiler_private.h" + +WINE_DEFAULT_DEBUG_CHANNEL(bytecodewriter); + +/**************************************************************** + * General assembler shader construction helper routines follow * + ****************************************************************/ +/* struct instruction *alloc_instr + * + * Allocates a new instruction structure with srcs registers + * + * Parameters: + * srcs: Number of source registers to allocate + * + * Returns: + * A pointer to the allocated instruction structure + * NULL in case of an allocation failure + */ +struct instruction *alloc_instr(unsigned int srcs) { + struct instruction *ret = d3dcompiler_alloc(sizeof(*ret)); + if(!ret) { + ERR("Failed to allocate memory for an instruction structure\n"); + return NULL; + } + + if(srcs) { + ret->src = d3dcompiler_alloc(srcs * sizeof(*ret->src)); + if(!ret->src) { + ERR("Failed to allocate memory for instruction registers\n"); + d3dcompiler_free(ret); + return NULL; + } + ret->num_srcs = srcs; + } + return ret; +} + +/* void add_instruction + * + * Adds a new instruction to the shader's instructions array and grows the instruction array + * if needed. + * + * The function does NOT copy the instruction structure. Make sure not to release the + * instruction or any of its substructures like registers. + * + * Parameters: + * shader: Shader to add the instruction to + * instr: Instruction to add to the shader + */ +BOOL add_instruction(struct bwriter_shader *shader, struct instruction *instr) { + struct instruction **new_instructions; + + if(!shader) return FALSE; + + if(shader->instr_alloc_size == 0) { + shader->instr = d3dcompiler_alloc(sizeof(*shader->instr) * INSTRARRAY_INITIAL_SIZE); + if(!shader->instr) { + ERR("Failed to allocate the shader instruction array\n"); + return FALSE; + } + shader->instr_alloc_size = INSTRARRAY_INITIAL_SIZE; + } else if(shader->instr_alloc_size == shader->num_instrs) { + new_instructions = d3dcompiler_realloc(shader->instr, + sizeof(*shader->instr) * (shader->instr_alloc_size) * 2); + if(!new_instructions) { + ERR("Failed to grow the shader instruction array\n"); + return FALSE; + } + shader->instr = new_instructions; + shader->instr_alloc_size = shader->instr_alloc_size * 2; + } else if(shader->num_instrs > shader->instr_alloc_size) { + ERR("More instructions than allocated. This should not happen\n"); + return FALSE; + } + + shader->instr[shader->num_instrs] = instr; + shader->num_instrs++; + return TRUE; +} + +BOOL add_constF(struct bwriter_shader *shader, DWORD reg, float x, float y, float z, float w) { + struct constant *newconst; + + if(shader->num_cf) { + struct constant **newarray; + newarray = d3dcompiler_realloc(shader->constF, + sizeof(*shader->constF) * (shader->num_cf + 1)); + if(!newarray) { + ERR("Failed to grow the constants array\n"); + return FALSE; + } + shader->constF = newarray; + } else { + shader->constF = d3dcompiler_alloc(sizeof(*shader->constF)); + if(!shader->constF) { + ERR("Failed to allocate the constants array\n"); + return FALSE; + } + } + + newconst = d3dcompiler_alloc(sizeof(*newconst)); + if(!newconst) { + ERR("Failed to allocate a new constant\n"); + return FALSE; + } + newconst->regnum = reg; + newconst->value[0].f = x; + newconst->value[1].f = y; + newconst->value[2].f = z; + newconst->value[3].f = w; + shader->constF[shader->num_cf] = newconst; + + shader->num_cf++; + return TRUE; +} + +BOOL add_constI(struct bwriter_shader *shader, DWORD reg, INT x, INT y, INT z, INT w) { + struct constant *newconst; + + if(shader->num_ci) { + struct constant **newarray; + newarray = d3dcompiler_realloc(shader->constI, + sizeof(*shader->constI) * (shader->num_ci + 1)); + if(!newarray) { + ERR("Failed to grow the constants array\n"); + return FALSE; + } + shader->constI = newarray; + } else { + shader->constI = d3dcompiler_alloc(sizeof(*shader->constI)); + if(!shader->constI) { + ERR("Failed to allocate the constants array\n"); + return FALSE; + } + } + + newconst = d3dcompiler_alloc(sizeof(*newconst)); + if(!newconst) { + ERR("Failed to allocate a new constant\n"); + return FALSE; + } + newconst->regnum = reg; + newconst->value[0].i = x; + newconst->value[1].i = y; + newconst->value[2].i = z; + newconst->value[3].i = w; + shader->constI[shader->num_ci] = newconst; + + shader->num_ci++; + return TRUE; +} + +BOOL add_constB(struct bwriter_shader *shader, DWORD reg, BOOL x) { + struct constant *newconst; + + if(shader->num_cb) { + struct constant **newarray; + newarray = d3dcompiler_realloc(shader->constB, + sizeof(*shader->constB) * (shader->num_cb + 1)); + if(!newarray) { + ERR("Failed to grow the constants array\n"); + return FALSE; + } + shader->constB = newarray; + } else { + shader->constB = d3dcompiler_alloc(sizeof(*shader->constB)); + if(!shader->constB) { + ERR("Failed to allocate the constants array\n"); + return FALSE; + } + } + + newconst = d3dcompiler_alloc(sizeof(*newconst)); + if(!newconst) { + ERR("Failed to allocate a new constant\n"); + return FALSE; + } + newconst->regnum = reg; + newconst->value[0].b = x; + shader->constB[shader->num_cb] = newconst; + + shader->num_cb++; + return TRUE; +} + +BOOL record_declaration(struct bwriter_shader *shader, DWORD usage, + DWORD usage_idx, DWORD mod, BOOL output, + DWORD regnum, DWORD writemask, BOOL builtin) { + unsigned int *num; + struct declaration **decl; + unsigned int i; + + if(!shader) return FALSE; + + if(output) { + num = &shader->num_outputs; + decl = &shader->outputs; + } else { + num = &shader->num_inputs; + decl = &shader->inputs; + } + + if(*num == 0) { + *decl = d3dcompiler_alloc(sizeof(**decl)); + if(!*decl) { + ERR("Error allocating declarations array\n"); + return FALSE; + } + } else { + struct declaration *newdecl; + for(i = 0; i < *num; i++) { + if((*decl)[i].regnum == regnum && ((*decl)[i].writemask & writemask)) { + WARN("Declaration of register %u already exists, writemask match 0x%x\n", + regnum, (*decl)[i].writemask & writemask); + } + } + + newdecl = d3dcompiler_realloc(*decl, + sizeof(**decl) * ((*num) + 1)); + if(!newdecl) { + ERR("Error reallocating declarations array\n"); + return FALSE; + } + *decl = newdecl; + } + (*decl)[*num].usage = usage; + (*decl)[*num].usage_idx = usage_idx; + (*decl)[*num].regnum = regnum; + (*decl)[*num].mod = mod; + (*decl)[*num].writemask = writemask; + (*decl)[*num].builtin = builtin; + (*num)++; + + return TRUE; +} + +BOOL record_sampler(struct bwriter_shader *shader, DWORD samptype, DWORD mod, DWORD regnum) { + unsigned int i; + + if(!shader) return FALSE; + + if(shader->num_samplers == 0) { + shader->samplers = d3dcompiler_alloc(sizeof(*shader->samplers)); + if(!shader->samplers) { + ERR("Error allocating samplers array\n"); + return FALSE; + } + } else { + struct samplerdecl *newarray; + + for(i = 0; i < shader->num_samplers; i++) { + if(shader->samplers[i].regnum == regnum) { + WARN("Sampler %u already declared\n", regnum); + /* This is not an error as far as the assembler is concerned. + * Direct3D might refuse to load the compiled shader though + */ + } + } + + newarray = d3dcompiler_realloc(shader->samplers, + sizeof(*shader->samplers) * (shader->num_samplers + 1)); + if(!newarray) { + ERR("Error reallocating samplers array\n"); + return FALSE; + } + shader->samplers = newarray; + } + + shader->samplers[shader->num_samplers].type = samptype; + shader->samplers[shader->num_samplers].mod = mod; + shader->samplers[shader->num_samplers].regnum = regnum; + shader->num_samplers++; + return TRUE; +} + + +/* shader bytecode buffer manipulation functions. + * allocate_buffer creates a new buffer structure, put_dword adds a new + * DWORD to the buffer. In the rare case of a memory allocation failure + * when trying to grow the buffer a flag is set in the buffer to mark it + * invalid. This avoids return value checking and passing in many places + */ +static struct bytecode_buffer *allocate_buffer(void) { + struct bytecode_buffer *ret; + + ret = d3dcompiler_alloc(sizeof(*ret)); + if(!ret) return NULL; + + ret->alloc_size = BYTECODEBUFFER_INITIAL_SIZE; + ret->data = d3dcompiler_alloc(sizeof(DWORD) * ret->alloc_size); + if(!ret->data) { + d3dcompiler_free(ret); + return NULL; + } + ret->state = S_OK; + return ret; +} + +static void put_dword(struct bytecode_buffer *buffer, DWORD value) { + if(FAILED(buffer->state)) return; + + if(buffer->alloc_size == buffer->size) { + DWORD *newarray; + buffer->alloc_size *= 2; + newarray = d3dcompiler_realloc(buffer->data, + sizeof(DWORD) * buffer->alloc_size); + if(!newarray) { + ERR("Failed to grow the buffer data memory\n"); + buffer->state = E_OUTOFMEMORY; + return; + } + buffer->data = newarray; + } + buffer->data[buffer->size++] = value; +} + +/* bwriter -> d3d9 conversion functions. */ +static DWORD d3d9_swizzle(DWORD bwriter_swizzle) +{ + /* Currently a NOP, but this allows changing the internal definitions + * without side effects. */ + DWORD ret = 0; + + if ((bwriter_swizzle & BWRITERVS_X_X) == BWRITERVS_X_X) ret |= D3DVS_X_X; + if ((bwriter_swizzle & BWRITERVS_X_Y) == BWRITERVS_X_Y) ret |= D3DVS_X_Y; + if ((bwriter_swizzle & BWRITERVS_X_Z) == BWRITERVS_X_Z) ret |= D3DVS_X_Z; + if ((bwriter_swizzle & BWRITERVS_X_W) == BWRITERVS_X_W) ret |= D3DVS_X_W; + + if ((bwriter_swizzle & BWRITERVS_Y_X) == BWRITERVS_Y_X) ret |= D3DVS_Y_X; + if ((bwriter_swizzle & BWRITERVS_Y_Y) == BWRITERVS_Y_Y) ret |= D3DVS_Y_Y; + if ((bwriter_swizzle & BWRITERVS_Y_Z) == BWRITERVS_Y_Z) ret |= D3DVS_Y_Z; + if ((bwriter_swizzle & BWRITERVS_Y_W) == BWRITERVS_Y_W) ret |= D3DVS_Y_W; + + if ((bwriter_swizzle & BWRITERVS_Z_X) == BWRITERVS_Z_X) ret |= D3DVS_Z_X; + if ((bwriter_swizzle & BWRITERVS_Z_Y) == BWRITERVS_Z_Y) ret |= D3DVS_Z_Y; + if ((bwriter_swizzle & BWRITERVS_Z_Z) == BWRITERVS_Z_Z) ret |= D3DVS_Z_Z; + if ((bwriter_swizzle & BWRITERVS_Z_W) == BWRITERVS_Z_W) ret |= D3DVS_Z_W; + + if ((bwriter_swizzle & BWRITERVS_W_X) == BWRITERVS_W_X) ret |= D3DVS_W_X; + if ((bwriter_swizzle & BWRITERVS_W_Y) == BWRITERVS_W_Y) ret |= D3DVS_W_Y; + if ((bwriter_swizzle & BWRITERVS_W_Z) == BWRITERVS_W_Z) ret |= D3DVS_W_Z; + if ((bwriter_swizzle & BWRITERVS_W_W) == BWRITERVS_W_W) ret |= D3DVS_W_W; + + return ret; +} + +static DWORD d3d9_writemask(DWORD bwriter_writemask) +{ + DWORD ret = 0; + + if (bwriter_writemask & BWRITERSP_WRITEMASK_0) ret |= D3DSP_WRITEMASK_0; + if (bwriter_writemask & BWRITERSP_WRITEMASK_1) ret |= D3DSP_WRITEMASK_1; + if (bwriter_writemask & BWRITERSP_WRITEMASK_2) ret |= D3DSP_WRITEMASK_2; + if (bwriter_writemask & BWRITERSP_WRITEMASK_3) ret |= D3DSP_WRITEMASK_3; + + return ret; +} + +static DWORD d3d9_srcmod(DWORD bwriter_srcmod) +{ + switch (bwriter_srcmod) + { + case BWRITERSPSM_NONE: return D3DSPSM_NONE; + case BWRITERSPSM_NEG: return D3DSPSM_NEG; + case BWRITERSPSM_BIAS: return D3DSPSM_BIAS; + case BWRITERSPSM_BIASNEG: return D3DSPSM_BIASNEG; + case BWRITERSPSM_SIGN: return D3DSPSM_SIGN; + case BWRITERSPSM_SIGNNEG: return D3DSPSM_SIGNNEG; + case BWRITERSPSM_COMP: return D3DSPSM_COMP; + case BWRITERSPSM_X2: return D3DSPSM_X2; + case BWRITERSPSM_X2NEG: return D3DSPSM_X2NEG; + case BWRITERSPSM_DZ: return D3DSPSM_DZ; + case BWRITERSPSM_DW: return D3DSPSM_DW; + case BWRITERSPSM_ABS: return D3DSPSM_ABS; + case BWRITERSPSM_ABSNEG: return D3DSPSM_ABSNEG; + case BWRITERSPSM_NOT: return D3DSPSM_NOT; + default: + FIXME("Unhandled BWRITERSPSM token %#x.\n", bwriter_srcmod); + return 0; + } +} + +static DWORD d3d9_dstmod(DWORD bwriter_mod) +{ + DWORD ret = 0; + + if (bwriter_mod & BWRITERSPDM_SATURATE) ret |= D3DSPDM_SATURATE; + if (bwriter_mod & BWRITERSPDM_PARTIALPRECISION) ret |= D3DSPDM_PARTIALPRECISION; + if (bwriter_mod & BWRITERSPDM_MSAMPCENTROID) ret |= D3DSPDM_MSAMPCENTROID; + + return ret; +} + +static DWORD d3d9_comparetype(DWORD asmshader_comparetype) +{ + switch (asmshader_comparetype) + { + case BWRITER_COMPARISON_GT: return D3DSPC_GT; + case BWRITER_COMPARISON_EQ: return D3DSPC_EQ; + case BWRITER_COMPARISON_GE: return D3DSPC_GE; + case BWRITER_COMPARISON_LT: return D3DSPC_LT; + case BWRITER_COMPARISON_NE: return D3DSPC_NE; + case BWRITER_COMPARISON_LE: return D3DSPC_LE; + default: + FIXME("Unexpected BWRITER_COMPARISON type %#x.\n", asmshader_comparetype); + return 0; + } +} + +static DWORD d3d9_sampler(DWORD bwriter_sampler) +{ + if (bwriter_sampler == BWRITERSTT_UNKNOWN) return D3DSTT_UNKNOWN; + if (bwriter_sampler == BWRITERSTT_1D) return D3DSTT_1D; + if (bwriter_sampler == BWRITERSTT_2D) return D3DSTT_2D; + if (bwriter_sampler == BWRITERSTT_CUBE) return D3DSTT_CUBE; + if (bwriter_sampler == BWRITERSTT_VOLUME) return D3DSTT_VOLUME; + FIXME("Unexpected BWRITERSAMPLER_TEXTURE_TYPE type %#x.\n", bwriter_sampler); + + return 0; +} + +static DWORD d3d9_register(DWORD bwriter_register) +{ + if (bwriter_register == BWRITERSPR_TEMP) return D3DSPR_TEMP; + if (bwriter_register == BWRITERSPR_INPUT) return D3DSPR_INPUT; + if (bwriter_register == BWRITERSPR_CONST) return D3DSPR_CONST; + if (bwriter_register == BWRITERSPR_ADDR) return D3DSPR_ADDR; + if (bwriter_register == BWRITERSPR_TEXTURE) return D3DSPR_TEXTURE; + if (bwriter_register == BWRITERSPR_RASTOUT) return D3DSPR_RASTOUT; + if (bwriter_register == BWRITERSPR_ATTROUT) return D3DSPR_ATTROUT; + if (bwriter_register == BWRITERSPR_TEXCRDOUT) return D3DSPR_TEXCRDOUT; + if (bwriter_register == BWRITERSPR_OUTPUT) return D3DSPR_OUTPUT; + if (bwriter_register == BWRITERSPR_CONSTINT) return D3DSPR_CONSTINT; + if (bwriter_register == BWRITERSPR_COLOROUT) return D3DSPR_COLOROUT; + if (bwriter_register == BWRITERSPR_DEPTHOUT) return D3DSPR_DEPTHOUT; + if (bwriter_register == BWRITERSPR_SAMPLER) return D3DSPR_SAMPLER; + if (bwriter_register == BWRITERSPR_CONSTBOOL) return D3DSPR_CONSTBOOL; + if (bwriter_register == BWRITERSPR_LOOP) return D3DSPR_LOOP; + if (bwriter_register == BWRITERSPR_MISCTYPE) return D3DSPR_MISCTYPE; + if (bwriter_register == BWRITERSPR_LABEL) return D3DSPR_LABEL; + if (bwriter_register == BWRITERSPR_PREDICATE) return D3DSPR_PREDICATE; + + FIXME("Unexpected BWRITERSPR %#x.\n", bwriter_register); + return ~0U; +} + +static DWORD d3d9_opcode(DWORD bwriter_opcode) +{ + switch (bwriter_opcode) + { + case BWRITERSIO_NOP: return D3DSIO_NOP; + case BWRITERSIO_MOV: return D3DSIO_MOV; + case BWRITERSIO_ADD: return D3DSIO_ADD; + case BWRITERSIO_SUB: return D3DSIO_SUB; + case BWRITERSIO_MAD: return D3DSIO_MAD; + case BWRITERSIO_MUL: return D3DSIO_MUL; + case BWRITERSIO_RCP: return D3DSIO_RCP; + case BWRITERSIO_RSQ: return D3DSIO_RSQ; + case BWRITERSIO_DP3: return D3DSIO_DP3; + case BWRITERSIO_DP4: return D3DSIO_DP4; + case BWRITERSIO_MIN: return D3DSIO_MIN; + case BWRITERSIO_MAX: return D3DSIO_MAX; + case BWRITERSIO_SLT: return D3DSIO_SLT; + case BWRITERSIO_SGE: return D3DSIO_SGE; + case BWRITERSIO_EXP: return D3DSIO_EXP; + case BWRITERSIO_LOG: return D3DSIO_LOG; + case BWRITERSIO_LIT: return D3DSIO_LIT; + case BWRITERSIO_DST: return D3DSIO_DST; + case BWRITERSIO_LRP: return D3DSIO_LRP; + case BWRITERSIO_FRC: return D3DSIO_FRC; + case BWRITERSIO_M4x4: return D3DSIO_M4x4; + case BWRITERSIO_M4x3: return D3DSIO_M4x3; + case BWRITERSIO_M3x4: return D3DSIO_M3x4; + case BWRITERSIO_M3x3: return D3DSIO_M3x3; + case BWRITERSIO_M3x2: return D3DSIO_M3x2; + case BWRITERSIO_CALL: return D3DSIO_CALL; + case BWRITERSIO_CALLNZ: return D3DSIO_CALLNZ; + case BWRITERSIO_LOOP: return D3DSIO_LOOP; + case BWRITERSIO_RET: return D3DSIO_RET; + case BWRITERSIO_ENDLOOP: return D3DSIO_ENDLOOP; + case BWRITERSIO_LABEL: return D3DSIO_LABEL; + case BWRITERSIO_DCL: return D3DSIO_DCL; + case BWRITERSIO_POW: return D3DSIO_POW; + case BWRITERSIO_CRS: return D3DSIO_CRS; + case BWRITERSIO_SGN: return D3DSIO_SGN; + case BWRITERSIO_ABS: return D3DSIO_ABS; + case BWRITERSIO_NRM: return D3DSIO_NRM; + case BWRITERSIO_SINCOS: return D3DSIO_SINCOS; + case BWRITERSIO_REP: return D3DSIO_REP; + case BWRITERSIO_ENDREP: return D3DSIO_ENDREP; + case BWRITERSIO_IF: return D3DSIO_IF; + case BWRITERSIO_IFC: return D3DSIO_IFC; + case BWRITERSIO_ELSE: return D3DSIO_ELSE; + case BWRITERSIO_ENDIF: return D3DSIO_ENDIF; + case BWRITERSIO_BREAK: return D3DSIO_BREAK; + case BWRITERSIO_BREAKC: return D3DSIO_BREAKC; + case BWRITERSIO_MOVA: return D3DSIO_MOVA; + case BWRITERSIO_DEFB: return D3DSIO_DEFB; + case BWRITERSIO_DEFI: return D3DSIO_DEFI; + + case BWRITERSIO_TEXCOORD: return D3DSIO_TEXCOORD; + case BWRITERSIO_TEXKILL: return D3DSIO_TEXKILL; + case BWRITERSIO_TEX: return D3DSIO_TEX; + case BWRITERSIO_TEXBEM: return D3DSIO_TEXBEM; + case BWRITERSIO_TEXBEML: return D3DSIO_TEXBEML; + case BWRITERSIO_TEXREG2AR: return D3DSIO_TEXREG2AR; + case BWRITERSIO_TEXREG2GB: return D3DSIO_TEXREG2GB; + case BWRITERSIO_TEXM3x2PAD: return D3DSIO_TEXM3x2PAD; + case BWRITERSIO_TEXM3x2TEX: return D3DSIO_TEXM3x2TEX; + case BWRITERSIO_TEXM3x3PAD: return D3DSIO_TEXM3x3PAD; + case BWRITERSIO_TEXM3x3TEX: return D3DSIO_TEXM3x3TEX; + case BWRITERSIO_TEXM3x3SPEC: return D3DSIO_TEXM3x3SPEC; + case BWRITERSIO_TEXM3x3VSPEC:return D3DSIO_TEXM3x3VSPEC; + case BWRITERSIO_EXPP: return D3DSIO_EXPP; + case BWRITERSIO_LOGP: return D3DSIO_LOGP; + case BWRITERSIO_CND: return D3DSIO_CND; + case BWRITERSIO_DEF: return D3DSIO_DEF; + case BWRITERSIO_TEXREG2RGB: return D3DSIO_TEXREG2RGB; + case BWRITERSIO_TEXDP3TEX: return D3DSIO_TEXDP3TEX; + case BWRITERSIO_TEXM3x2DEPTH:return D3DSIO_TEXM3x2DEPTH; + case BWRITERSIO_TEXDP3: return D3DSIO_TEXDP3; + case BWRITERSIO_TEXM3x3: return D3DSIO_TEXM3x3; + case BWRITERSIO_TEXDEPTH: return D3DSIO_TEXDEPTH; + case BWRITERSIO_CMP: return D3DSIO_CMP; + case BWRITERSIO_BEM: return D3DSIO_BEM; + case BWRITERSIO_DP2ADD: return D3DSIO_DP2ADD; + case BWRITERSIO_DSX: return D3DSIO_DSX; + case BWRITERSIO_DSY: return D3DSIO_DSY; + case BWRITERSIO_TEXLDD: return D3DSIO_TEXLDD; + case BWRITERSIO_SETP: return D3DSIO_SETP; + case BWRITERSIO_TEXLDL: return D3DSIO_TEXLDL; + case BWRITERSIO_BREAKP: return D3DSIO_BREAKP; + + case BWRITERSIO_PHASE: return D3DSIO_PHASE; + case BWRITERSIO_COMMENT: return D3DSIO_COMMENT; + case BWRITERSIO_END: return D3DSIO_END; + + case BWRITERSIO_TEXLDP: return D3DSIO_TEX | D3DSI_TEXLD_PROJECT; + case BWRITERSIO_TEXLDB: return D3DSIO_TEX | D3DSI_TEXLD_BIAS; + + default: + FIXME("Unhandled BWRITERSIO token %#x.\n", bwriter_opcode); + return ~0U; + } +} + +/****************************************************** + * Implementation of the writer functions starts here * + ******************************************************/ +static void write_declarations(struct bc_writer *This, + struct bytecode_buffer *buffer, BOOL len, + const struct declaration *decls, unsigned int num, DWORD type) { + DWORD i; + DWORD instr_dcl = D3DSIO_DCL; + DWORD token; + struct shader_reg reg; + + ZeroMemory(®, sizeof(reg)); + + if(len) { + instr_dcl |= 2 << D3DSI_INSTLENGTH_SHIFT; + } + + for(i = 0; i < num; i++) { + if(decls[i].builtin) continue; + + /* Write the DCL instruction */ + put_dword(buffer, instr_dcl); + + /* Write the usage and index */ + token = (1 << 31); /* Bit 31 of non-instruction opcodes is 1 */ + token |= (decls[i].usage << D3DSP_DCL_USAGE_SHIFT) & D3DSP_DCL_USAGE_MASK; + token |= (decls[i].usage_idx << D3DSP_DCL_USAGEINDEX_SHIFT) & D3DSP_DCL_USAGEINDEX_MASK; + put_dword(buffer, token); + + /* Write the dest register */ + reg.type = type; + reg.regnum = decls[i].regnum; + reg.u.writemask = decls[i].writemask; + This->funcs->dstreg(This, ®, buffer, 0, decls[i].mod); + } +} + +static void write_const(struct constant **consts, int num, DWORD opcode, DWORD reg_type, struct bytecode_buffer *buffer, BOOL len) { + int i; + DWORD instr_def = opcode; + const DWORD reg = (1<<31) | + ((reg_type << D3DSP_REGTYPE_SHIFT) & D3DSP_REGTYPE_MASK) | + ((reg_type << D3DSP_REGTYPE_SHIFT2) & D3DSP_REGTYPE_MASK2) | + D3DSP_WRITEMASK_ALL; + + if(len) { + if(opcode == D3DSIO_DEFB) + instr_def |= 2 << D3DSI_INSTLENGTH_SHIFT; + else + instr_def |= 5 << D3DSI_INSTLENGTH_SHIFT; + } + + for(i = 0; i < num; i++) { + /* Write the DEF instruction */ + put_dword(buffer, instr_def); + + put_dword(buffer, reg | (consts[i]->regnum & D3DSP_REGNUM_MASK)); + put_dword(buffer, consts[i]->value[0].d); + if(opcode != D3DSIO_DEFB) { + put_dword(buffer, consts[i]->value[1].d); + put_dword(buffer, consts[i]->value[2].d); + put_dword(buffer, consts[i]->value[3].d); + } + } +} + +static void write_constF(const struct bwriter_shader *shader, struct bytecode_buffer *buffer, BOOL len) { + write_const(shader->constF, shader->num_cf, D3DSIO_DEF, D3DSPR_CONST, buffer, len); +} + +/* This function looks for VS 1/2 registers mapping to VS 3 output registers */ +static HRESULT vs_find_builtin_varyings(struct bc_writer *This, const struct bwriter_shader *shader) { + DWORD i; + DWORD usage, usage_idx, writemask, regnum; + + for(i = 0; i < shader->num_outputs; i++) { + if(!shader->outputs[i].builtin) continue; + + usage = shader->outputs[i].usage; + usage_idx = shader->outputs[i].usage_idx; + writemask = shader->outputs[i].writemask; + regnum = shader->outputs[i].regnum; + + switch(usage) { + case BWRITERDECLUSAGE_POSITION: + case BWRITERDECLUSAGE_POSITIONT: + if(usage_idx > 0) { + WARN("dcl_position%u not supported in sm 1/2 shaders\n", usage_idx); + return E_INVALIDARG; + } + TRACE("o%u is oPos\n", regnum); + This->oPos_regnum = regnum; + break; + + case BWRITERDECLUSAGE_COLOR: + if(usage_idx > 1) { + WARN("dcl_color%u not supported in sm 1/2 shaders\n", usage_idx); + return E_INVALIDARG; + } + if(writemask != BWRITERSP_WRITEMASK_ALL) { + WARN("Only WRITEMASK_ALL is supported on color in sm 1/2\n"); + return E_INVALIDARG; + } + TRACE("o%u is oD%u\n", regnum, usage_idx); + This->oD_regnum[usage_idx] = regnum; + break; + + case BWRITERDECLUSAGE_TEXCOORD: + if(usage_idx >= 8) { + WARN("dcl_color%u not supported in sm 1/2 shaders\n", usage_idx); + return E_INVALIDARG; + } + if(writemask != (BWRITERSP_WRITEMASK_0) && + writemask != (BWRITERSP_WRITEMASK_0 | BWRITERSP_WRITEMASK_1) && + writemask != (BWRITERSP_WRITEMASK_0 | BWRITERSP_WRITEMASK_1 | BWRITERSP_WRITEMASK_2) && + writemask != (BWRITERSP_WRITEMASK_ALL)) { + WARN("Partial writemasks not supported on texture coordinates in sm 1 and 2\n"); + return E_INVALIDARG; + } + TRACE("o%u is oT%u\n", regnum, usage_idx); + This->oT_regnum[usage_idx] = regnum; + break; + + case BWRITERDECLUSAGE_PSIZE: + if(usage_idx > 0) { + WARN("dcl_psize%u not supported in sm 1/2 shaders\n", usage_idx); + return E_INVALIDARG; + } + TRACE("o%u writemask 0x%08x is oPts\n", regnum, writemask); + This->oPts_regnum = regnum; + This->oPts_mask = writemask; + break; + + case BWRITERDECLUSAGE_FOG: + if(usage_idx > 0) { + WARN("dcl_fog%u not supported in sm 1 shaders\n", usage_idx); + return E_INVALIDARG; + } + if(writemask != BWRITERSP_WRITEMASK_0 && writemask != BWRITERSP_WRITEMASK_1 && + writemask != BWRITERSP_WRITEMASK_2 && writemask != BWRITERSP_WRITEMASK_3) { + WARN("Unsupported fog writemask\n"); + return E_INVALIDARG; + } + TRACE("o%u writemask 0x%08x is oFog\n", regnum, writemask); + This->oFog_regnum = regnum; + This->oFog_mask = writemask; + break; + + default: + WARN("Varying type %u is not supported in shader model 1.x\n", usage); + return E_INVALIDARG; + } + } + + return S_OK; +} + +static void vs_1_x_header(struct bc_writer *This, const struct bwriter_shader *shader, struct bytecode_buffer *buffer) { + HRESULT hr; + + if(shader->num_ci || shader->num_cb) { + WARN("Int and bool constants are not supported in shader model 1 shaders\n"); + WARN("Got %u int and %u boolean constants\n", shader->num_ci, shader->num_cb); + This->state = E_INVALIDARG; + return; + } + + hr = vs_find_builtin_varyings(This, shader); + if(FAILED(hr)) { + This->state = hr; + return; + } + + write_declarations(This, buffer, FALSE, shader->inputs, shader->num_inputs, BWRITERSPR_INPUT); + write_constF(shader, buffer, FALSE); +} + +static HRESULT find_ps_builtin_semantics(struct bc_writer *This, + const struct bwriter_shader *shader, + DWORD texcoords) { + DWORD i; + DWORD usage, usage_idx, writemask, regnum; + + This->v_regnum[0] = -1; This->v_regnum[1] = -1; + for(i = 0; i < 8; i++) This->t_regnum[i] = -1; + + for(i = 0; i < shader->num_inputs; i++) { + if(!shader->inputs[i].builtin) continue; + + usage = shader->inputs[i].usage; + usage_idx = shader->inputs[i].usage_idx; + writemask = shader->inputs[i].writemask; + regnum = shader->inputs[i].regnum; + + switch(usage) { + case BWRITERDECLUSAGE_COLOR: + if(usage_idx > 1) { + WARN("dcl_color%u not supported in sm 1 shaders\n", usage_idx); + return E_INVALIDARG; + } + if(writemask != BWRITERSP_WRITEMASK_ALL) { + WARN("Only WRITEMASK_ALL is supported on color in sm 1\n"); + return E_INVALIDARG; + } + TRACE("v%u is v%u\n", regnum, usage_idx); + This->v_regnum[usage_idx] = regnum; + break; + + case BWRITERDECLUSAGE_TEXCOORD: + if(usage_idx > texcoords) { + WARN("dcl_texcoord%u not supported in this shader version\n", usage_idx); + return E_INVALIDARG; + } + if(writemask != (BWRITERSP_WRITEMASK_0) && + writemask != (BWRITERSP_WRITEMASK_0 | BWRITERSP_WRITEMASK_1) && + writemask != (BWRITERSP_WRITEMASK_0 | BWRITERSP_WRITEMASK_1 | BWRITERSP_WRITEMASK_2) && + writemask != (BWRITERSP_WRITEMASK_ALL)) { + WARN("Partial writemasks not supported on texture coordinates in sm 1 and 2\n"); + } else { + writemask = BWRITERSP_WRITEMASK_ALL; + } + TRACE("v%u is t%u\n", regnum, usage_idx); + This->t_regnum[usage_idx] = regnum; + break; + + default: + WARN("Varying type %u is not supported in shader model 1.x\n", usage); + return E_INVALIDARG; + } + } + + return S_OK; +} + +static void ps_1_x_header(struct bc_writer *This, const struct bwriter_shader *shader, struct bytecode_buffer *buffer) { + HRESULT hr; + + /* First check the constants and varyings, and complain if unsupported things are used */ + if(shader->num_ci || shader->num_cb) { + WARN("Int and bool constants are not supported in shader model 1 shaders\n"); + WARN("Got %u int and %u boolean constants\n", shader->num_ci, shader->num_cb); + This->state = E_INVALIDARG; + return; + } + + hr = find_ps_builtin_semantics(This, shader, 4); + if(FAILED(hr)) { + This->state = hr; + return; + } + + write_constF(shader, buffer, FALSE); +} + +static void ps_1_4_header(struct bc_writer *This, const struct bwriter_shader *shader, struct bytecode_buffer *buffer) { + HRESULT hr; + + /* First check the constants and varyings, and complain if unsupported things are used */ + if(shader->num_ci || shader->num_cb) { + WARN("Int and bool constants are not supported in shader model 1 shaders\n"); + WARN("Got %u int and %u boolean constants\n", shader->num_ci, shader->num_cb); + This->state = E_INVALIDARG; + return; + } + hr = find_ps_builtin_semantics(This, shader, 6); + if(FAILED(hr)) { + This->state = hr; + return; + } + + write_constF(shader, buffer, FALSE); +} + +static void end(struct bc_writer *This, const struct bwriter_shader *shader, struct bytecode_buffer *buffer) { + put_dword(buffer, D3DSIO_END); +} + +static DWORD map_vs_output(struct bc_writer *This, DWORD regnum, DWORD mask, DWORD *has_components) { + DWORD token = 0; + DWORD i; + + *has_components = TRUE; + if(regnum == This->oPos_regnum) { + token |= (D3DSPR_RASTOUT << D3DSP_REGTYPE_SHIFT) & D3DSP_REGTYPE_MASK; + token |= D3DSRO_POSITION & D3DSP_REGNUM_MASK; /* No shift */ + return token; + } + if(regnum == This->oFog_regnum && mask == This->oFog_mask) { + token |= (D3DSPR_RASTOUT << D3DSP_REGTYPE_SHIFT) & D3DSP_REGTYPE_MASK; + token |= D3DSRO_FOG & D3DSP_REGNUM_MASK; /* No shift */ + token |= D3DSP_WRITEMASK_ALL; + *has_components = FALSE; + return token; + } + if(regnum == This->oPts_regnum && mask == This->oPts_mask) { + token |= (D3DSPR_RASTOUT << D3DSP_REGTYPE_SHIFT) & D3DSP_REGTYPE_MASK; + token |= D3DSRO_POINT_SIZE & D3DSP_REGNUM_MASK; /* No shift */ + token |= D3DSP_WRITEMASK_ALL; + *has_components = FALSE; + return token; + } + for(i = 0; i < 2; i++) { + if(regnum == This->oD_regnum[i]) { + token |= (D3DSPR_ATTROUT << D3DSP_REGTYPE_SHIFT) & D3DSP_REGTYPE_MASK; + token |= i & D3DSP_REGNUM_MASK; /* No shift */ + return token; + } + } + for(i = 0; i < 8; i++) { + if(regnum == This->oT_regnum[i]) { + token |= (D3DSPR_TEXCRDOUT << D3DSP_REGTYPE_SHIFT) & D3DSP_REGTYPE_MASK; + token |= i & D3DSP_REGNUM_MASK; /* No shift */ + return token; + } + } + + /* The varying must be undeclared - if an unsupported varying was declared, + * the vs_find_builtin_varyings function would have caught it and this code + * would not run */ + WARN("Undeclared varying %u\n", regnum); + This->state = E_INVALIDARG; + return -1; +} + +static void vs_12_dstreg(struct bc_writer *This, const struct shader_reg *reg, + struct bytecode_buffer *buffer, + DWORD shift, DWORD mod) { + DWORD token = (1 << 31); /* Bit 31 of registers is 1 */ + DWORD has_wmask; + + if(reg->rel_reg) { + WARN("Relative addressing not supported for destination registers\n"); + This->state = E_INVALIDARG; + return; + } + + switch(reg->type) { + case BWRITERSPR_OUTPUT: + token |= map_vs_output(This, reg->regnum, reg->u.writemask, &has_wmask); + break; + + case BWRITERSPR_RASTOUT: + case BWRITERSPR_ATTROUT: + /* These registers are mapped to input and output regs. They can be encoded in the bytecode, + * but are unexpected. If we hit this path it might be due to an error. + */ + FIXME("Unexpected register type %u\n", reg->type); + /* drop through */ + case BWRITERSPR_INPUT: + case BWRITERSPR_TEMP: + case BWRITERSPR_CONST: + token |= (reg->type << D3DSP_REGTYPE_SHIFT) & D3DSP_REGTYPE_MASK; + token |= reg->regnum & D3DSP_REGNUM_MASK; /* No shift */ + has_wmask = TRUE; + break; + + case BWRITERSPR_ADDR: + if(reg->regnum != 0) { + WARN("Only a0 exists\n"); + This->state = E_INVALIDARG; + return; + } + token |= (D3DSPR_ADDR << D3DSP_REGTYPE_SHIFT) & D3DSP_REGTYPE_MASK; + token |= 0 & D3DSP_REGNUM_MASK; /* No shift */ + has_wmask = TRUE; + break; + + case BWRITERSPR_PREDICATE: + if(This->version != BWRITERVS_VERSION(2, 1)){ + WARN("Predicate register is allowed only in vs_2_x\n"); + This->state = E_INVALIDARG; + return; + } + if(reg->regnum != 0) { + WARN("Only predicate register p0 exists\n"); + This->state = E_INVALIDARG; + return; + } + token |= (D3DSPR_PREDICATE << D3DSP_REGTYPE_SHIFT) & D3DSP_REGTYPE_MASK; + token |= (D3DSPR_PREDICATE << D3DSP_REGTYPE_SHIFT2) & D3DSP_REGTYPE_MASK2; + token |= 0 & D3DSP_REGNUM_MASK; /* No shift */ + has_wmask = TRUE; + break; + + default: + WARN("Invalid register type for 1.x-2.x vertex shader\n"); + This->state = E_INVALIDARG; + return; + } + + /* strictly speaking there are no modifiers in vs_2_0 and vs_1_x, but they can be written + * into the bytecode and since the compiler doesn't do such checks write them + * (the checks are done by the undocumented shader validator) + */ + token |= (shift << D3DSP_DSTSHIFT_SHIFT) & D3DSP_DSTSHIFT_MASK; + token |= d3d9_dstmod(mod); + + if(has_wmask) { + token |= d3d9_writemask(reg->u.writemask); + } + put_dword(buffer, token); +} + +static void vs_1_x_srcreg(struct bc_writer *This, const struct shader_reg *reg, + struct bytecode_buffer *buffer) { + DWORD token = (1 << 31); /* Bit 31 of registers is 1 */ + DWORD has_swizzle; + DWORD component; + + switch(reg->type) { + case BWRITERSPR_OUTPUT: + /* Map the swizzle to a writemask, the format expected + by map_vs_output + */ + switch(reg->u.swizzle) { + case BWRITERVS_SWIZZLE_X: + component = BWRITERSP_WRITEMASK_0; + break; + case BWRITERVS_SWIZZLE_Y: + component = BWRITERSP_WRITEMASK_1; + break; + case BWRITERVS_SWIZZLE_Z: + component = BWRITERSP_WRITEMASK_2; + break; + case BWRITERVS_SWIZZLE_W: + component = BWRITERSP_WRITEMASK_3; + break; + default: + component = 0; + } + token |= map_vs_output(This, reg->regnum, component, &has_swizzle); + break; + + case BWRITERSPR_RASTOUT: + case BWRITERSPR_ATTROUT: + /* These registers are mapped to input and output regs. They can be encoded in the bytecode, + * but are unexpected. If we hit this path it might be due to an error. + */ + FIXME("Unexpected register type %u\n", reg->type); + /* drop through */ + case BWRITERSPR_INPUT: + case BWRITERSPR_TEMP: + case BWRITERSPR_CONST: + case BWRITERSPR_ADDR: + token |= (reg->type << D3DSP_REGTYPE_SHIFT) & D3DSP_REGTYPE_MASK; + token |= reg->regnum & D3DSP_REGNUM_MASK; /* No shift */ + if(reg->rel_reg) { + if(reg->rel_reg->type != BWRITERSPR_ADDR || + reg->rel_reg->regnum != 0 || + reg->rel_reg->u.swizzle != BWRITERVS_SWIZZLE_X) { + WARN("Relative addressing in vs_1_x is only allowed with a0.x\n"); + This->state = E_INVALIDARG; + return; + } + token |= D3DVS_ADDRMODE_RELATIVE & D3DVS_ADDRESSMODE_MASK; + } + break; + + default: + WARN("Invalid register type for 1.x vshader\n"); + This->state = E_INVALIDARG; + return; + } + + token |= d3d9_swizzle(reg->u.swizzle) & D3DVS_SWIZZLE_MASK; /* already shifted */ + + token |= d3d9_srcmod(reg->srcmod); + put_dword(buffer, token); +} + +static void write_srcregs(struct bc_writer *This, const struct instruction *instr, + struct bytecode_buffer *buffer){ + unsigned int i; + if(instr->has_predicate){ + This->funcs->srcreg(This, &instr->predicate, buffer); + } + for(i = 0; i < instr->num_srcs; i++){ + This->funcs->srcreg(This, &instr->src[i], buffer); + } +} + +static DWORD map_ps13_temp(struct bc_writer *This, const struct shader_reg *reg) { + DWORD token = 0; + if(reg->regnum == T0_REG) { + token |= (D3DSPR_TEXTURE << D3DSP_REGTYPE_SHIFT) & D3DSP_REGTYPE_MASK; + token |= 0 & D3DSP_REGNUM_MASK; /* No shift */ + } else if(reg->regnum == T1_REG) { + token |= (D3DSPR_TEXTURE << D3DSP_REGTYPE_SHIFT) & D3DSP_REGTYPE_MASK; + token |= 1 & D3DSP_REGNUM_MASK; /* No shift */ + } else if(reg->regnum == T2_REG) { + token |= (D3DSPR_TEXTURE << D3DSP_REGTYPE_SHIFT) & D3DSP_REGTYPE_MASK; + token |= 2 & D3DSP_REGNUM_MASK; /* No shift */ + } else if(reg->regnum == T3_REG) { + token |= (D3DSPR_TEXTURE << D3DSP_REGTYPE_SHIFT) & D3DSP_REGTYPE_MASK; + token |= 3 & D3DSP_REGNUM_MASK; /* No shift */ + } else { + token |= (D3DSPR_TEMP << D3DSP_REGTYPE_SHIFT) & D3DSP_REGTYPE_MASK; + token |= reg->regnum & D3DSP_REGNUM_MASK; /* No shift */ + } + return token; +} + +static DWORD map_ps_input(struct bc_writer *This, + const struct shader_reg *reg) { + DWORD i, token = 0; + /* Map color interpolators */ + for(i = 0; i < 2; i++) { + if(reg->regnum == This->v_regnum[i]) { + token |= (D3DSPR_INPUT << D3DSP_REGTYPE_SHIFT) & D3DSP_REGTYPE_MASK; + token |= i & D3DSP_REGNUM_MASK; /* No shift */ + return token; + } + } + for(i = 0; i < 8; i++) { + if(reg->regnum == This->t_regnum[i]) { + token |= (D3DSPR_TEXTURE << D3DSP_REGTYPE_SHIFT) & D3DSP_REGTYPE_MASK; + token |= i & D3DSP_REGNUM_MASK; /* No shift */ + return token; + } + } + + WARN("Invalid ps 1/2 varying\n"); + This->state = E_INVALIDARG; + return token; +} + +static void ps_1_0123_srcreg(struct bc_writer *This, const struct shader_reg *reg, + struct bytecode_buffer *buffer) { + DWORD token = (1 << 31); /* Bit 31 of registers is 1 */ + if(reg->rel_reg) { + WARN("Relative addressing not supported in <= ps_3_0\n"); + This->state = E_INVALIDARG; + return; + } + + switch(reg->type) { + case BWRITERSPR_INPUT: + token |= map_ps_input(This, reg); + break; + + /* Take care about the texture temporaries. There's a problem: They aren't + * declared anywhere, so we can only hardcode the values that are used + * to map ps_1_3 shaders to the common shader structure + */ + case BWRITERSPR_TEMP: + token |= map_ps13_temp(This, reg); + break; + + case BWRITERSPR_CONST: /* Can be mapped 1:1 */ + token |= (reg->type << D3DSP_REGTYPE_SHIFT) & D3DSP_REGTYPE_MASK; + token |= reg->regnum & D3DSP_REGNUM_MASK; /* No shift */ + break; + + default: + WARN("Invalid register type for <= ps_1_3 shader\n"); + This->state = E_INVALIDARG; + return; + } + + token |= d3d9_swizzle(reg->u.swizzle) & D3DVS_SWIZZLE_MASK; /* already shifted */ + + if(reg->srcmod == BWRITERSPSM_DZ || reg->srcmod == BWRITERSPSM_DW || + reg->srcmod == BWRITERSPSM_ABS || reg->srcmod == BWRITERSPSM_ABSNEG || + reg->srcmod == BWRITERSPSM_NOT) { + WARN("Invalid source modifier %u for <= ps_1_3\n", reg->srcmod); + This->state = E_INVALIDARG; + return; + } + token |= d3d9_srcmod(reg->srcmod); + put_dword(buffer, token); +} + +static void ps_1_0123_dstreg(struct bc_writer *This, const struct shader_reg *reg, + struct bytecode_buffer *buffer, + DWORD shift, DWORD mod) { + DWORD token = (1 << 31); /* Bit 31 of registers is 1 */ + + if(reg->rel_reg) { + WARN("Relative addressing not supported for destination registers\n"); + This->state = E_INVALIDARG; + return; + } + + switch(reg->type) { + case BWRITERSPR_TEMP: + token |= map_ps13_temp(This, reg); + break; + + /* texkill uses the input register as a destination parameter */ + case BWRITERSPR_INPUT: + token |= map_ps_input(This, reg); + break; + + default: + WARN("Invalid dest register type for 1.x pshader\n"); + This->state = E_INVALIDARG; + return; + } + + token |= (shift << D3DSP_DSTSHIFT_SHIFT) & D3DSP_DSTSHIFT_MASK; + token |= d3d9_dstmod(mod); + + token |= d3d9_writemask(reg->u.writemask); + put_dword(buffer, token); +} + +/* The length of an instruction consists of the destination register (if any), + * the number of source registers, the number of address registers used for + * indirect addressing, and optionally the predicate register + */ +static DWORD instrlen(const struct instruction *instr, unsigned int srcs, unsigned int dsts) { + unsigned int i; + DWORD ret = srcs + dsts + (instr->has_predicate ? 1 : 0); + + if(dsts){ + if(instr->dst.rel_reg) ret++; + } + for(i = 0; i < srcs; i++) { + if(instr->src[i].rel_reg) ret++; + } + return ret; +} + +static void sm_1_x_opcode(struct bc_writer *This, + const struct instruction *instr, + DWORD token, struct bytecode_buffer *buffer) { + /* In sm_1_x instruction length isn't encoded */ + if(instr->coissue){ + token |= D3DSI_COISSUE; + } + put_dword(buffer, token); +} + +static void instr_handler(struct bc_writer *This, + const struct instruction *instr, + struct bytecode_buffer *buffer) { + DWORD token = d3d9_opcode(instr->opcode); + + This->funcs->opcode(This, instr, token, buffer); + if(instr->has_dst) This->funcs->dstreg(This, &instr->dst, buffer, instr->shift, instr->dstmod); + write_srcregs(This, instr, buffer); +} + +static const struct instr_handler_table vs_1_x_handlers[] = { + {BWRITERSIO_ADD, instr_handler}, + {BWRITERSIO_NOP, instr_handler}, + {BWRITERSIO_MOV, instr_handler}, + {BWRITERSIO_SUB, instr_handler}, + {BWRITERSIO_MAD, instr_handler}, + {BWRITERSIO_MUL, instr_handler}, + {BWRITERSIO_RCP, instr_handler}, + {BWRITERSIO_RSQ, instr_handler}, + {BWRITERSIO_DP3, instr_handler}, + {BWRITERSIO_DP4, instr_handler}, + {BWRITERSIO_MIN, instr_handler}, + {BWRITERSIO_MAX, instr_handler}, + {BWRITERSIO_SLT, instr_handler}, + {BWRITERSIO_SGE, instr_handler}, + {BWRITERSIO_EXP, instr_handler}, + {BWRITERSIO_LOG, instr_handler}, + {BWRITERSIO_EXPP, instr_handler}, + {BWRITERSIO_LOGP, instr_handler}, + {BWRITERSIO_DST, instr_handler}, + {BWRITERSIO_FRC, instr_handler}, + {BWRITERSIO_M4x4, instr_handler}, + {BWRITERSIO_M4x3, instr_handler}, + {BWRITERSIO_M3x4, instr_handler}, + {BWRITERSIO_M3x3, instr_handler}, + {BWRITERSIO_M3x2, instr_handler}, + {BWRITERSIO_LIT, instr_handler}, + + {BWRITERSIO_END, NULL}, /* Sentinel value, it signals + the end of the list */ +}; + +static const struct bytecode_backend vs_1_x_backend = { + vs_1_x_header, + end, + vs_1_x_srcreg, + vs_12_dstreg, + sm_1_x_opcode, + vs_1_x_handlers +}; + +static void instr_ps_1_0123_texld(struct bc_writer *This, + const struct instruction *instr, + struct bytecode_buffer *buffer) { + DWORD idx; + struct shader_reg reg; + DWORD swizzlemask; + + if(instr->src[1].type != BWRITERSPR_SAMPLER || + instr->src[1].regnum > 3) { + WARN("Unsupported sampler type %u regnum %u\n", + instr->src[1].type, instr->src[1].regnum); + This->state = E_INVALIDARG; + return; + } else if(instr->dst.type != BWRITERSPR_TEMP) { + WARN("Can only sample into a temp register\n"); + This->state = E_INVALIDARG; + return; + } + + idx = instr->src[1].regnum; + if((idx == 0 && instr->dst.regnum != T0_REG) || + (idx == 1 && instr->dst.regnum != T1_REG) || + (idx == 2 && instr->dst.regnum != T2_REG) || + (idx == 3 && instr->dst.regnum != T3_REG)) { + WARN("Sampling from sampler s%u to register r%u is not possible in ps_1_x\n", + idx, instr->dst.regnum); + This->state = E_INVALIDARG; + return; + } + if(instr->src[0].type == BWRITERSPR_INPUT) { + /* A simple non-dependent read tex instruction */ + if(instr->src[0].regnum != This->t_regnum[idx]) { + WARN("Cannot sample from s%u with texture address data from interpolator %u\n", + idx, instr->src[0].regnum); + This->state = E_INVALIDARG; + return; + } + This->funcs->opcode(This, instr, D3DSIO_TEX & D3DSI_OPCODE_MASK, buffer); + + /* map the temp dstreg to the ps_1_3 texture temporary register */ + This->funcs->dstreg(This, &instr->dst, buffer, instr->shift, instr->dstmod); + } else if(instr->src[0].type == BWRITERSPR_TEMP) { + + swizzlemask = (3 << BWRITERVS_SWIZZLE_SHIFT) | + (3 << (BWRITERVS_SWIZZLE_SHIFT + 2)) | + (3 << (BWRITERVS_SWIZZLE_SHIFT + 4)); + if((instr->src[0].u.swizzle & swizzlemask) == (BWRITERVS_X_X | BWRITERVS_Y_Y | BWRITERVS_Z_Z)) { + TRACE("writing texreg2rgb\n"); + This->funcs->opcode(This, instr, D3DSIO_TEXREG2RGB & D3DSI_OPCODE_MASK, buffer); + } else if(instr->src[0].u.swizzle == (BWRITERVS_X_W | BWRITERVS_Y_X | BWRITERVS_Z_X | BWRITERVS_W_X)) { + TRACE("writing texreg2ar\n"); + This->funcs->opcode(This, instr, D3DSIO_TEXREG2AR & D3DSI_OPCODE_MASK, buffer); + } else if(instr->src[0].u.swizzle == (BWRITERVS_X_Y | BWRITERVS_Y_Z | BWRITERVS_Z_Z | BWRITERVS_W_Z)) { + TRACE("writing texreg2gb\n"); + This->funcs->opcode(This, instr, D3DSIO_TEXREG2GB & D3DSI_OPCODE_MASK, buffer); + } else { + WARN("Unsupported src addr swizzle in dependent texld: 0x%08x\n", instr->src[0].u.swizzle); + This->state = E_INVALIDARG; + return; + } + + /* Dst and src reg can be mapped normally. Both registers are temporary registers in the + * source shader and have to be mapped to the temporary form of the texture registers. However, + * the src reg doesn't have a swizzle + */ + This->funcs->dstreg(This, &instr->dst, buffer, instr->shift, instr->dstmod); + reg = instr->src[0]; + reg.u.swizzle = BWRITERVS_NOSWIZZLE; + This->funcs->srcreg(This, ®, buffer); + } else { + WARN("Invalid address data source register\n"); + This->state = E_INVALIDARG; + return; + } +} + +static void instr_ps_1_0123_mov(struct bc_writer *This, + const struct instruction *instr, + struct bytecode_buffer *buffer) { + DWORD token = D3DSIO_MOV & D3DSI_OPCODE_MASK; + + if(instr->dst.type == BWRITERSPR_TEMP && instr->src[0].type == BWRITERSPR_INPUT) { + if((instr->dst.regnum == T0_REG && instr->src[0].regnum == This->t_regnum[0]) || + (instr->dst.regnum == T1_REG && instr->src[0].regnum == This->t_regnum[1]) || + (instr->dst.regnum == T2_REG && instr->src[0].regnum == This->t_regnum[2]) || + (instr->dst.regnum == T3_REG && instr->src[0].regnum == This->t_regnum[3])) { + if(instr->dstmod & BWRITERSPDM_SATURATE) { + This->funcs->opcode(This, instr, D3DSIO_TEXCOORD & D3DSI_OPCODE_MASK, buffer); + /* Remove the SATURATE flag, it's implicit to the instruction */ + This->funcs->dstreg(This, &instr->dst, buffer, instr->shift, instr->dstmod & (~BWRITERSPDM_SATURATE)); + return; + } else { + WARN("A varying -> temp copy is only supported with the SATURATE modifier in <=ps_1_3\n"); + This->state = E_INVALIDARG; + return; + } + } else if(instr->src[0].regnum == This->v_regnum[0] || + instr->src[0].regnum == This->v_regnum[1]) { + /* Handled by the normal mov below. Just drop out of the if condition */ + } else { + WARN("Unsupported varying -> temp mov in <= ps_1_3\n"); + This->state = E_INVALIDARG; + return; + } + } + + This->funcs->opcode(This, instr, token, buffer); + This->funcs->dstreg(This, &instr->dst, buffer, instr->shift, instr->dstmod); + This->funcs->srcreg(This, &instr->src[0], buffer); +} + +static const struct instr_handler_table ps_1_0123_handlers[] = { + {BWRITERSIO_ADD, instr_handler}, + {BWRITERSIO_NOP, instr_handler}, + {BWRITERSIO_MOV, instr_ps_1_0123_mov}, + {BWRITERSIO_SUB, instr_handler}, + {BWRITERSIO_MAD, instr_handler}, + {BWRITERSIO_MUL, instr_handler}, + {BWRITERSIO_DP3, instr_handler}, + {BWRITERSIO_DP4, instr_handler}, + {BWRITERSIO_LRP, instr_handler}, + + /* pshader instructions */ + {BWRITERSIO_CND, instr_handler}, + {BWRITERSIO_CMP, instr_handler}, + {BWRITERSIO_TEXKILL, instr_handler}, + {BWRITERSIO_TEX, instr_ps_1_0123_texld}, + {BWRITERSIO_TEXBEM, instr_handler}, + {BWRITERSIO_TEXBEML, instr_handler}, + {BWRITERSIO_TEXM3x2PAD, instr_handler}, + {BWRITERSIO_TEXM3x3PAD, instr_handler}, + {BWRITERSIO_TEXM3x3SPEC, instr_handler}, + {BWRITERSIO_TEXM3x3VSPEC, instr_handler}, + {BWRITERSIO_TEXM3x3TEX, instr_handler}, + {BWRITERSIO_TEXM3x3, instr_handler}, + {BWRITERSIO_TEXM3x2DEPTH, instr_handler}, + {BWRITERSIO_TEXM3x2TEX, instr_handler}, + {BWRITERSIO_TEXDP3, instr_handler}, + {BWRITERSIO_TEXDP3TEX, instr_handler}, + {BWRITERSIO_END, NULL}, +}; + +static const struct bytecode_backend ps_1_0123_backend = { + ps_1_x_header, + end, + ps_1_0123_srcreg, + ps_1_0123_dstreg, + sm_1_x_opcode, + ps_1_0123_handlers +}; + +static void ps_1_4_srcreg(struct bc_writer *This, const struct shader_reg *reg, + struct bytecode_buffer *buffer) { + DWORD token = (1 << 31); /* Bit 31 of registers is 1 */ + if(reg->rel_reg) { + WARN("Relative addressing not supported in <= ps_3_0\n"); + This->state = E_INVALIDARG; + return; + } + + switch(reg->type) { + case BWRITERSPR_INPUT: + token |= map_ps_input(This, reg); + break; + + /* Can be mapped 1:1 */ + case BWRITERSPR_TEMP: + case BWRITERSPR_CONST: + token |= (reg->type << D3DSP_REGTYPE_SHIFT) & D3DSP_REGTYPE_MASK; + token |= reg->regnum & D3DSP_REGNUM_MASK; /* No shift */ + break; + + default: + WARN("Invalid register type for ps_1_4 shader\n"); + This->state = E_INVALIDARG; + return; + } + + token |= d3d9_swizzle(reg->u.swizzle) & D3DVS_SWIZZLE_MASK; /* already shifted */ + + if(reg->srcmod == BWRITERSPSM_ABS || reg->srcmod == BWRITERSPSM_ABSNEG || + reg->srcmod == BWRITERSPSM_NOT) { + WARN("Invalid source modifier %u for ps_1_4\n", reg->srcmod); + This->state = E_INVALIDARG; + return; + } + token |= d3d9_srcmod(reg->srcmod); + put_dword(buffer, token); +} + +static void ps_1_4_dstreg(struct bc_writer *This, const struct shader_reg *reg, + struct bytecode_buffer *buffer, + DWORD shift, DWORD mod) { + DWORD token = (1 << 31); /* Bit 31 of registers is 1 */ + + if(reg->rel_reg) { + WARN("Relative addressing not supported for destination registers\n"); + This->state = E_INVALIDARG; + return; + } + + switch(reg->type) { + case BWRITERSPR_TEMP: /* 1:1 mapping */ + token |= (reg->type << D3DSP_REGTYPE_SHIFT) & D3DSP_REGTYPE_MASK; + token |= reg->regnum & D3DSP_REGNUM_MASK; /* No shift */ + break; + + /* For texkill */ + case BWRITERSPR_INPUT: + token |= map_ps_input(This, reg); + break; + + default: + WARN("Invalid dest register type for 1.x pshader\n"); + This->state = E_INVALIDARG; + return; + } + + token |= (shift << D3DSP_DSTSHIFT_SHIFT) & D3DSP_DSTSHIFT_MASK; + token |= d3d9_dstmod(mod); + + token |= d3d9_writemask(reg->u.writemask); + put_dword(buffer, token); +} + +static void instr_ps_1_4_mov(struct bc_writer *This, + const struct instruction *instr, + struct bytecode_buffer *buffer) { + DWORD token = D3DSIO_MOV & D3DSI_OPCODE_MASK; + + if(instr->dst.type == BWRITERSPR_TEMP && instr->src[0].type == BWRITERSPR_INPUT) { + if(instr->src[0].regnum == This->t_regnum[0] || + instr->src[0].regnum == This->t_regnum[1] || + instr->src[0].regnum == This->t_regnum[2] || + instr->src[0].regnum == This->t_regnum[3] || + instr->src[0].regnum == This->t_regnum[4] || + instr->src[0].regnum == This->t_regnum[5]) { + /* Similar to a regular mov, but a different opcode */ + token = D3DSIO_TEXCOORD & D3DSI_OPCODE_MASK; + } else if(instr->src[0].regnum == This->v_regnum[0] || + instr->src[0].regnum == This->v_regnum[1]) { + /* Handled by the normal mov below. Just drop out of the if condition */ + } else { + WARN("Unsupported varying -> temp mov in ps_1_4\n"); + This->state = E_INVALIDARG; + return; + } + } + + This->funcs->opcode(This, instr, token, buffer); + This->funcs->dstreg(This, &instr->dst, buffer, instr->shift, instr->dstmod); + This->funcs->srcreg(This, &instr->src[0], buffer); +} + +static void instr_ps_1_4_texld(struct bc_writer *This, + const struct instruction *instr, + struct bytecode_buffer *buffer) { + if(instr->src[1].type != BWRITERSPR_SAMPLER || + instr->src[1].regnum > 5) { + WARN("Unsupported sampler type %u regnum %u\n", + instr->src[1].type, instr->src[1].regnum); + This->state = E_INVALIDARG; + return; + } else if(instr->dst.type != BWRITERSPR_TEMP) { + WARN("Can only sample into a temp register\n"); + This->state = E_INVALIDARG; + return; + } + + if(instr->src[1].regnum != instr->dst.regnum) { + WARN("Sampling from sampler s%u to register r%u is not possible in ps_1_4\n", + instr->src[1].regnum, instr->dst.regnum); + This->state = E_INVALIDARG; + return; + } + + This->funcs->opcode(This, instr, D3DSIO_TEX & D3DSI_OPCODE_MASK, buffer); + This->funcs->dstreg(This, &instr->dst, buffer, instr->shift, instr->dstmod); + This->funcs->srcreg(This, &instr->src[0], buffer); +} + +static const struct instr_handler_table ps_1_4_handlers[] = { + {BWRITERSIO_ADD, instr_handler}, + {BWRITERSIO_NOP, instr_handler}, + {BWRITERSIO_MOV, instr_ps_1_4_mov}, + {BWRITERSIO_SUB, instr_handler}, + {BWRITERSIO_MAD, instr_handler}, + {BWRITERSIO_MUL, instr_handler}, + {BWRITERSIO_DP3, instr_handler}, + {BWRITERSIO_DP4, instr_handler}, + {BWRITERSIO_LRP, instr_handler}, + + /* pshader instructions */ + {BWRITERSIO_CND, instr_handler}, + {BWRITERSIO_CMP, instr_handler}, + {BWRITERSIO_TEXKILL, instr_handler}, + {BWRITERSIO_TEX, instr_ps_1_4_texld}, + {BWRITERSIO_TEXDEPTH, instr_handler}, + {BWRITERSIO_BEM, instr_handler}, + + {BWRITERSIO_PHASE, instr_handler}, + {BWRITERSIO_END, NULL}, +}; + +static const struct bytecode_backend ps_1_4_backend = { + ps_1_4_header, + end, + ps_1_4_srcreg, + ps_1_4_dstreg, + sm_1_x_opcode, + ps_1_4_handlers +}; + +static void write_constB(const struct bwriter_shader *shader, struct bytecode_buffer *buffer, BOOL len) { + write_const(shader->constB, shader->num_cb, D3DSIO_DEFB, D3DSPR_CONSTBOOL, buffer, len); +} + +static void write_constI(const struct bwriter_shader *shader, struct bytecode_buffer *buffer, BOOL len) { + write_const(shader->constI, shader->num_ci, D3DSIO_DEFI, D3DSPR_CONSTINT, buffer, len); +} + +static void vs_2_header(struct bc_writer *This, + const struct bwriter_shader *shader, + struct bytecode_buffer *buffer) { + HRESULT hr; + + hr = vs_find_builtin_varyings(This, shader); + if(FAILED(hr)) { + This->state = hr; + return; + } + + write_declarations(This, buffer, TRUE, shader->inputs, shader->num_inputs, BWRITERSPR_INPUT); + write_constF(shader, buffer, TRUE); + write_constB(shader, buffer, TRUE); + write_constI(shader, buffer, TRUE); +} + +static void vs_2_srcreg(struct bc_writer *This, + const struct shader_reg *reg, + struct bytecode_buffer *buffer) { + DWORD token = (1 << 31); /* Bit 31 of registers is 1 */ + DWORD has_swizzle; + DWORD component; + DWORD d3d9reg; + + switch(reg->type) { + case BWRITERSPR_OUTPUT: + /* Map the swizzle to a writemask, the format expected + by map_vs_output + */ + switch(reg->u.swizzle) { + case BWRITERVS_SWIZZLE_X: + component = BWRITERSP_WRITEMASK_0; + break; + case BWRITERVS_SWIZZLE_Y: + component = BWRITERSP_WRITEMASK_1; + break; + case BWRITERVS_SWIZZLE_Z: + component = BWRITERSP_WRITEMASK_2; + break; + case BWRITERVS_SWIZZLE_W: + component = BWRITERSP_WRITEMASK_3; + break; + default: + component = 0; + } + token |= map_vs_output(This, reg->regnum, component, &has_swizzle); + break; + + case BWRITERSPR_RASTOUT: + case BWRITERSPR_ATTROUT: + /* These registers are mapped to input and output regs. They can be encoded in the bytecode, + * but are unexpected. If we hit this path it might be due to an error. + */ + FIXME("Unexpected register type %u\n", reg->type); + /* drop through */ + case BWRITERSPR_INPUT: + case BWRITERSPR_TEMP: + case BWRITERSPR_CONST: + case BWRITERSPR_ADDR: + case BWRITERSPR_CONSTINT: + case BWRITERSPR_CONSTBOOL: + case BWRITERSPR_LABEL: + d3d9reg = d3d9_register(reg->type); + token |= (d3d9reg << D3DSP_REGTYPE_SHIFT) & D3DSP_REGTYPE_MASK; + token |= (d3d9reg << D3DSP_REGTYPE_SHIFT2) & D3DSP_REGTYPE_MASK2; + token |= reg->regnum & D3DSP_REGNUM_MASK; /* No shift */ + break; + + case BWRITERSPR_LOOP: + if(reg->regnum != 0) { + WARN("Only regnum 0 is supported for the loop index register in vs_2_0\n"); + This->state = E_INVALIDARG; + return; + } + token |= (D3DSPR_LOOP << D3DSP_REGTYPE_SHIFT) & D3DSP_REGTYPE_MASK; + token |= (D3DSPR_LOOP << D3DSP_REGTYPE_SHIFT2) & D3DSP_REGTYPE_MASK2; + token |= 0 & D3DSP_REGNUM_MASK; /* No shift */ + break; + + case BWRITERSPR_PREDICATE: + if(This->version != BWRITERVS_VERSION(2, 1)){ + WARN("Predicate register is allowed only in vs_2_x\n"); + This->state = E_INVALIDARG; + return; + } + if(reg->regnum > 0) { + WARN("Only predicate register 0 is supported\n"); + This->state = E_INVALIDARG; + return; + } + token |= (D3DSPR_PREDICATE << D3DSP_REGTYPE_SHIFT) & D3DSP_REGTYPE_MASK; + token |= (D3DSPR_PREDICATE << D3DSP_REGTYPE_SHIFT2) & D3DSP_REGTYPE_MASK2; + token |= 0 & D3DSP_REGNUM_MASK; /* No shift */ + + break; + + default: + WARN("Invalid register type for 2.0 vshader\n"); + This->state = E_INVALIDARG; + return; + } + + token |= d3d9_swizzle(reg->u.swizzle) & D3DVS_SWIZZLE_MASK; /* already shifted */ + + token |= d3d9_srcmod(reg->srcmod); + + if(reg->rel_reg) + token |= D3DVS_ADDRMODE_RELATIVE & D3DVS_ADDRESSMODE_MASK; + + put_dword(buffer, token); + + /* vs_2_0 and newer write the register containing the index explicitly in the + * binary code + */ + if(token & D3DVS_ADDRMODE_RELATIVE) + vs_2_srcreg(This, reg->rel_reg, buffer); +} + +static void sm_2_opcode(struct bc_writer *This, + const struct instruction *instr, + DWORD token, struct bytecode_buffer *buffer) { + /* From sm 2 onwards instruction length is encoded in the opcode field */ + int dsts = instr->has_dst ? 1 : 0; + token |= instrlen(instr, instr->num_srcs, dsts) << D3DSI_INSTLENGTH_SHIFT; + if(instr->comptype) + token |= (d3d9_comparetype(instr->comptype) << 16) & (0xf << 16); + if(instr->has_predicate) + token |= D3DSHADER_INSTRUCTION_PREDICATED; + put_dword(buffer,token); +} + +static const struct instr_handler_table vs_2_0_handlers[] = { + {BWRITERSIO_ADD, instr_handler}, + {BWRITERSIO_NOP, instr_handler}, + {BWRITERSIO_MOV, instr_handler}, + {BWRITERSIO_SUB, instr_handler}, + {BWRITERSIO_MAD, instr_handler}, + {BWRITERSIO_MUL, instr_handler}, + {BWRITERSIO_RCP, instr_handler}, + {BWRITERSIO_RSQ, instr_handler}, + {BWRITERSIO_DP3, instr_handler}, + {BWRITERSIO_DP4, instr_handler}, + {BWRITERSIO_MIN, instr_handler}, + {BWRITERSIO_MAX, instr_handler}, + {BWRITERSIO_SLT, instr_handler}, + {BWRITERSIO_SGE, instr_handler}, + {BWRITERSIO_ABS, instr_handler}, + {BWRITERSIO_EXP, instr_handler}, + {BWRITERSIO_LOG, instr_handler}, + {BWRITERSIO_EXPP, instr_handler}, + {BWRITERSIO_LOGP, instr_handler}, + {BWRITERSIO_DST, instr_handler}, + {BWRITERSIO_LRP, instr_handler}, + {BWRITERSIO_FRC, instr_handler}, + {BWRITERSIO_CRS, instr_handler}, + {BWRITERSIO_SGN, instr_handler}, + {BWRITERSIO_NRM, instr_handler}, + {BWRITERSIO_SINCOS, instr_handler}, + {BWRITERSIO_M4x4, instr_handler}, + {BWRITERSIO_M4x3, instr_handler}, + {BWRITERSIO_M3x4, instr_handler}, + {BWRITERSIO_M3x3, instr_handler}, + {BWRITERSIO_M3x2, instr_handler}, + {BWRITERSIO_LIT, instr_handler}, + {BWRITERSIO_POW, instr_handler}, + {BWRITERSIO_MOVA, instr_handler}, + + {BWRITERSIO_CALL, instr_handler}, + {BWRITERSIO_CALLNZ, instr_handler}, + {BWRITERSIO_REP, instr_handler}, + {BWRITERSIO_ENDREP, instr_handler}, + {BWRITERSIO_IF, instr_handler}, + {BWRITERSIO_LABEL, instr_handler}, + {BWRITERSIO_ELSE, instr_handler}, + {BWRITERSIO_ENDIF, instr_handler}, + {BWRITERSIO_LOOP, instr_handler}, + {BWRITERSIO_RET, instr_handler}, + {BWRITERSIO_ENDLOOP, instr_handler}, + + {BWRITERSIO_END, NULL}, +}; + +static const struct bytecode_backend vs_2_0_backend = { + vs_2_header, + end, + vs_2_srcreg, + vs_12_dstreg, + sm_2_opcode, + vs_2_0_handlers +}; + +static const struct instr_handler_table vs_2_x_handlers[] = { + {BWRITERSIO_ADD, instr_handler}, + {BWRITERSIO_NOP, instr_handler}, + {BWRITERSIO_MOV, instr_handler}, + {BWRITERSIO_SUB, instr_handler}, + {BWRITERSIO_MAD, instr_handler}, + {BWRITERSIO_MUL, instr_handler}, + {BWRITERSIO_RCP, instr_handler}, + {BWRITERSIO_RSQ, instr_handler}, + {BWRITERSIO_DP3, instr_handler}, + {BWRITERSIO_DP4, instr_handler}, + {BWRITERSIO_MIN, instr_handler}, + {BWRITERSIO_MAX, instr_handler}, + {BWRITERSIO_SLT, instr_handler}, + {BWRITERSIO_SGE, instr_handler}, + {BWRITERSIO_ABS, instr_handler}, + {BWRITERSIO_EXP, instr_handler}, + {BWRITERSIO_LOG, instr_handler}, + {BWRITERSIO_EXPP, instr_handler}, + {BWRITERSIO_LOGP, instr_handler}, + {BWRITERSIO_DST, instr_handler}, + {BWRITERSIO_LRP, instr_handler}, + {BWRITERSIO_FRC, instr_handler}, + {BWRITERSIO_CRS, instr_handler}, + {BWRITERSIO_SGN, instr_handler}, + {BWRITERSIO_NRM, instr_handler}, + {BWRITERSIO_SINCOS, instr_handler}, + {BWRITERSIO_M4x4, instr_handler}, + {BWRITERSIO_M4x3, instr_handler}, + {BWRITERSIO_M3x4, instr_handler}, + {BWRITERSIO_M3x3, instr_handler}, + {BWRITERSIO_M3x2, instr_handler}, + {BWRITERSIO_LIT, instr_handler}, + {BWRITERSIO_POW, instr_handler}, + {BWRITERSIO_MOVA, instr_handler}, + + {BWRITERSIO_CALL, instr_handler}, + {BWRITERSIO_CALLNZ, instr_handler}, + {BWRITERSIO_REP, instr_handler}, + {BWRITERSIO_ENDREP, instr_handler}, + {BWRITERSIO_IF, instr_handler}, + {BWRITERSIO_LABEL, instr_handler}, + {BWRITERSIO_IFC, instr_handler}, + {BWRITERSIO_ELSE, instr_handler}, + {BWRITERSIO_ENDIF, instr_handler}, + {BWRITERSIO_BREAK, instr_handler}, + {BWRITERSIO_BREAKC, instr_handler}, + {BWRITERSIO_LOOP, instr_handler}, + {BWRITERSIO_RET, instr_handler}, + {BWRITERSIO_ENDLOOP, instr_handler}, + + {BWRITERSIO_SETP, instr_handler}, + {BWRITERSIO_BREAKP, instr_handler}, + + {BWRITERSIO_END, NULL}, +}; + +static const struct bytecode_backend vs_2_x_backend = { + vs_2_header, + end, + vs_2_srcreg, + vs_12_dstreg, + sm_2_opcode, + vs_2_x_handlers +}; + +static void write_samplers(const struct bwriter_shader *shader, struct bytecode_buffer *buffer) { + DWORD i; + DWORD instr_dcl = D3DSIO_DCL | (2 << D3DSI_INSTLENGTH_SHIFT); + DWORD token; + const DWORD reg = (1<<31) | + ((D3DSPR_SAMPLER << D3DSP_REGTYPE_SHIFT) & D3DSP_REGTYPE_MASK) | + ((D3DSPR_SAMPLER << D3DSP_REGTYPE_SHIFT2) & D3DSP_REGTYPE_MASK2) | + D3DSP_WRITEMASK_ALL; + + for(i = 0; i < shader->num_samplers; i++) { + /* Write the DCL instruction */ + put_dword(buffer, instr_dcl); + token = (1<<31); + /* Already shifted */ + token |= (d3d9_sampler(shader->samplers[i].type)) & D3DSP_TEXTURETYPE_MASK; + put_dword(buffer, token); + token = reg | (shader->samplers[i].regnum & D3DSP_REGNUM_MASK); + token |= d3d9_dstmod(shader->samplers[i].mod); + put_dword(buffer, token); + } +} + +static void ps_2_header(struct bc_writer *This, const struct bwriter_shader *shader, struct bytecode_buffer *buffer) { + HRESULT hr = find_ps_builtin_semantics(This, shader, 8); + if(FAILED(hr)) { + This->state = hr; + return; + } + + write_declarations(This, buffer, TRUE, shader->inputs, shader->num_inputs, BWRITERSPR_INPUT); + write_samplers(shader, buffer); + write_constF(shader, buffer, TRUE); + write_constB(shader, buffer, TRUE); + write_constI(shader, buffer, TRUE); +} + +static void ps_2_srcreg(struct bc_writer *This, + const struct shader_reg *reg, + struct bytecode_buffer *buffer) { + DWORD token = (1 << 31); /* Bit 31 of registers is 1 */ + DWORD d3d9reg; + if(reg->rel_reg) { + WARN("Relative addressing not supported in <= ps_3_0\n"); + This->state = E_INVALIDARG; + return; + } + + switch(reg->type) { + case BWRITERSPR_INPUT: + token |= map_ps_input(This, reg); + break; + + /* Can be mapped 1:1 */ + case BWRITERSPR_TEMP: + case BWRITERSPR_CONST: + case BWRITERSPR_COLOROUT: + case BWRITERSPR_CONSTBOOL: + case BWRITERSPR_CONSTINT: + case BWRITERSPR_SAMPLER: + case BWRITERSPR_LABEL: + case BWRITERSPR_DEPTHOUT: + d3d9reg = d3d9_register(reg->type); + token |= (d3d9reg << D3DSP_REGTYPE_SHIFT) & D3DSP_REGTYPE_MASK; + token |= (d3d9reg << D3DSP_REGTYPE_SHIFT2) & D3DSP_REGTYPE_MASK2; + token |= reg->regnum & D3DSP_REGNUM_MASK; /* No shift */ + break; + + case BWRITERSPR_PREDICATE: + if(This->version != BWRITERPS_VERSION(2, 1)){ + WARN("Predicate register not supported in ps_2_0\n"); + This->state = E_INVALIDARG; + } + if(reg->regnum) { + WARN("Predicate register with regnum %u not supported\n", + reg->regnum); + This->state = E_INVALIDARG; + } + token |= (D3DSPR_PREDICATE << D3DSP_REGTYPE_SHIFT) & D3DSP_REGTYPE_MASK; + token |= (D3DSPR_PREDICATE << D3DSP_REGTYPE_SHIFT2) & D3DSP_REGTYPE_MASK2; + token |= 0 & D3DSP_REGNUM_MASK; /* No shift */ + break; + + default: + WARN("Invalid register type for ps_2_0 shader\n"); + This->state = E_INVALIDARG; + return; + } + + token |= d3d9_swizzle(reg->u.swizzle) & D3DVS_SWIZZLE_MASK; /* already shifted */ + + token |= d3d9_srcmod(reg->srcmod); + put_dword(buffer, token); +} + +static void ps_2_0_dstreg(struct bc_writer *This, + const struct shader_reg *reg, + struct bytecode_buffer *buffer, + DWORD shift, DWORD mod) { + DWORD token = (1 << 31); /* Bit 31 of registers is 1 */ + DWORD d3d9reg; + + if(reg->rel_reg) { + WARN("Relative addressing not supported for destination registers\n"); + This->state = E_INVALIDARG; + return; + } + + switch(reg->type) { + case BWRITERSPR_TEMP: /* 1:1 mapping */ + case BWRITERSPR_COLOROUT: + case BWRITERSPR_DEPTHOUT: + d3d9reg = d3d9_register(reg->type); + token |= (d3d9reg << D3DSP_REGTYPE_SHIFT) & D3DSP_REGTYPE_MASK; + token |= (d3d9reg << D3DSP_REGTYPE_SHIFT2) & D3DSP_REGTYPE_MASK2; + token |= reg->regnum & D3DSP_REGNUM_MASK; /* No shift */ + break; + + case BWRITERSPR_PREDICATE: + if(This->version != BWRITERPS_VERSION(2, 1)){ + WARN("Predicate register not supported in ps_2_0\n"); + This->state = E_INVALIDARG; + } + token |= (D3DSPR_PREDICATE << D3DSP_REGTYPE_SHIFT) & D3DSP_REGTYPE_MASK; + token |= (D3DSPR_PREDICATE << D3DSP_REGTYPE_SHIFT2) & D3DSP_REGTYPE_MASK2; + token |= reg->regnum & D3DSP_REGNUM_MASK; /* No shift */ + break; + + /* texkill uses the input register as a destination parameter */ + case BWRITERSPR_INPUT: + token |= map_ps_input(This, reg); + break; + + default: + WARN("Invalid dest register type for 2.x pshader\n"); + This->state = E_INVALIDARG; + return; + } + + token |= (shift << D3DSP_DSTSHIFT_SHIFT) & D3DSP_DSTSHIFT_MASK; + token |= d3d9_dstmod(mod); + + token |= d3d9_writemask(reg->u.writemask); + put_dword(buffer, token); +} + +static const struct instr_handler_table ps_2_0_handlers[] = { + {BWRITERSIO_ADD, instr_handler}, + {BWRITERSIO_NOP, instr_handler}, + {BWRITERSIO_MOV, instr_handler}, + {BWRITERSIO_SUB, instr_handler}, + {BWRITERSIO_MAD, instr_handler}, + {BWRITERSIO_MUL, instr_handler}, + {BWRITERSIO_RCP, instr_handler}, + {BWRITERSIO_RSQ, instr_handler}, + {BWRITERSIO_DP3, instr_handler}, + {BWRITERSIO_DP4, instr_handler}, + {BWRITERSIO_MIN, instr_handler}, + {BWRITERSIO_MAX, instr_handler}, + {BWRITERSIO_ABS, instr_handler}, + {BWRITERSIO_EXP, instr_handler}, + {BWRITERSIO_LOG, instr_handler}, + {BWRITERSIO_EXPP, instr_handler}, + {BWRITERSIO_LOGP, instr_handler}, + {BWRITERSIO_LRP, instr_handler}, + {BWRITERSIO_FRC, instr_handler}, + {BWRITERSIO_CRS, instr_handler}, + {BWRITERSIO_NRM, instr_handler}, + {BWRITERSIO_SINCOS, instr_handler}, + {BWRITERSIO_M4x4, instr_handler}, + {BWRITERSIO_M4x3, instr_handler}, + {BWRITERSIO_M3x4, instr_handler}, + {BWRITERSIO_M3x3, instr_handler}, + {BWRITERSIO_M3x2, instr_handler}, + {BWRITERSIO_POW, instr_handler}, + {BWRITERSIO_DP2ADD, instr_handler}, + {BWRITERSIO_CMP, instr_handler}, + + {BWRITERSIO_TEX, instr_handler}, + {BWRITERSIO_TEXLDP, instr_handler}, + {BWRITERSIO_TEXLDB, instr_handler}, + {BWRITERSIO_TEXKILL, instr_handler}, + + {BWRITERSIO_END, NULL}, +}; + +static const struct bytecode_backend ps_2_0_backend = { + ps_2_header, + end, + ps_2_srcreg, + ps_2_0_dstreg, + sm_2_opcode, + ps_2_0_handlers +}; + +static const struct instr_handler_table ps_2_x_handlers[] = { + {BWRITERSIO_ADD, instr_handler}, + {BWRITERSIO_NOP, instr_handler}, + {BWRITERSIO_MOV, instr_handler}, + {BWRITERSIO_SUB, instr_handler}, + {BWRITERSIO_MAD, instr_handler}, + {BWRITERSIO_MUL, instr_handler}, + {BWRITERSIO_RCP, instr_handler}, + {BWRITERSIO_RSQ, instr_handler}, + {BWRITERSIO_DP3, instr_handler}, + {BWRITERSIO_DP4, instr_handler}, + {BWRITERSIO_MIN, instr_handler}, + {BWRITERSIO_MAX, instr_handler}, + {BWRITERSIO_ABS, instr_handler}, + {BWRITERSIO_EXP, instr_handler}, + {BWRITERSIO_LOG, instr_handler}, + {BWRITERSIO_EXPP, instr_handler}, + {BWRITERSIO_LOGP, instr_handler}, + {BWRITERSIO_LRP, instr_handler}, + {BWRITERSIO_FRC, instr_handler}, + {BWRITERSIO_CRS, instr_handler}, + {BWRITERSIO_NRM, instr_handler}, + {BWRITERSIO_SINCOS, instr_handler}, + {BWRITERSIO_M4x4, instr_handler}, + {BWRITERSIO_M4x3, instr_handler}, + {BWRITERSIO_M3x4, instr_handler}, + {BWRITERSIO_M3x3, instr_handler}, + {BWRITERSIO_M3x2, instr_handler}, + {BWRITERSIO_POW, instr_handler}, + {BWRITERSIO_DP2ADD, instr_handler}, + {BWRITERSIO_CMP, instr_handler}, + + {BWRITERSIO_CALL, instr_handler}, + {BWRITERSIO_CALLNZ, instr_handler}, + {BWRITERSIO_REP, instr_handler}, + {BWRITERSIO_ENDREP, instr_handler}, + {BWRITERSIO_IF, instr_handler}, + {BWRITERSIO_LABEL, instr_handler}, + {BWRITERSIO_IFC, instr_handler}, + {BWRITERSIO_ELSE, instr_handler}, + {BWRITERSIO_ENDIF, instr_handler}, + {BWRITERSIO_BREAK, instr_handler}, + {BWRITERSIO_BREAKC, instr_handler}, + {BWRITERSIO_RET, instr_handler}, + + {BWRITERSIO_TEX, instr_handler}, + {BWRITERSIO_TEXLDP, instr_handler}, + {BWRITERSIO_TEXLDB, instr_handler}, + {BWRITERSIO_TEXKILL, instr_handler}, + {BWRITERSIO_DSX, instr_handler}, + {BWRITERSIO_DSY, instr_handler}, + + {BWRITERSIO_SETP, instr_handler}, + {BWRITERSIO_BREAKP, instr_handler}, + + {BWRITERSIO_TEXLDD, instr_handler}, + + {BWRITERSIO_END, NULL}, +}; + +static const struct bytecode_backend ps_2_x_backend = { + ps_2_header, + end, + ps_2_srcreg, + ps_2_0_dstreg, + sm_2_opcode, + ps_2_x_handlers +}; + +static void sm_3_header(struct bc_writer *This, const struct bwriter_shader *shader, struct bytecode_buffer *buffer) { + write_declarations(This, buffer, TRUE, shader->inputs, shader->num_inputs, BWRITERSPR_INPUT); + write_declarations(This, buffer, TRUE, shader->outputs, shader->num_outputs, BWRITERSPR_OUTPUT); + write_constF(shader, buffer, TRUE); + write_constB(shader, buffer, TRUE); + write_constI(shader, buffer, TRUE); + write_samplers(shader, buffer); +} + +static void sm_3_srcreg(struct bc_writer *This, + const struct shader_reg *reg, + struct bytecode_buffer *buffer) { + DWORD token = (1 << 31); /* Bit 31 of registers is 1 */ + DWORD d3d9reg; + + d3d9reg = d3d9_register(reg->type); + token |= (d3d9reg << D3DSP_REGTYPE_SHIFT) & D3DSP_REGTYPE_MASK; + token |= (d3d9reg << D3DSP_REGTYPE_SHIFT2) & D3DSP_REGTYPE_MASK2; + token |= reg->regnum & D3DSP_REGNUM_MASK; + + token |= d3d9_swizzle(reg->u.swizzle) & D3DVS_SWIZZLE_MASK; + token |= d3d9_srcmod(reg->srcmod); + + if(reg->rel_reg) { + if(reg->type == BWRITERSPR_CONST && This->version == BWRITERPS_VERSION(3, 0)) { + WARN("c%u[...] is unsupported in ps_3_0\n", reg->regnum); + This->state = E_INVALIDARG; + return; + } + if(((reg->rel_reg->type == BWRITERSPR_ADDR && This->version == BWRITERVS_VERSION(3, 0)) || + reg->rel_reg->type == BWRITERSPR_LOOP) && + reg->rel_reg->regnum == 0) { + token |= D3DVS_ADDRMODE_RELATIVE & D3DVS_ADDRESSMODE_MASK; + } else { + WARN("Unsupported relative addressing register\n"); + This->state = E_INVALIDARG; + return; + } + } + + put_dword(buffer, token); + + /* vs_2_0 and newer write the register containing the index explicitly in the + * binary code + */ + if(token & D3DVS_ADDRMODE_RELATIVE) { + sm_3_srcreg(This, reg->rel_reg, buffer); + } +} + +static void sm_3_dstreg(struct bc_writer *This, + const struct shader_reg *reg, + struct bytecode_buffer *buffer, + DWORD shift, DWORD mod) { + DWORD token = (1 << 31); /* Bit 31 of registers is 1 */ + DWORD d3d9reg; + + if(reg->rel_reg) { + if(This->version == BWRITERVS_VERSION(3, 0) && + reg->type == BWRITERSPR_OUTPUT) { + token |= D3DVS_ADDRMODE_RELATIVE & D3DVS_ADDRESSMODE_MASK; + } else { + WARN("Relative addressing not supported for this shader type or register type\n"); + This->state = E_INVALIDARG; + return; + } + } + + d3d9reg = d3d9_register(reg->type); + token |= (d3d9reg << D3DSP_REGTYPE_SHIFT) & D3DSP_REGTYPE_MASK; + token |= (d3d9reg << D3DSP_REGTYPE_SHIFT2) & D3DSP_REGTYPE_MASK2; + token |= reg->regnum & D3DSP_REGNUM_MASK; /* No shift */ + + token |= d3d9_dstmod(mod); + + token |= d3d9_writemask(reg->u.writemask); + put_dword(buffer, token); + + /* vs_2_0 and newer write the register containing the index explicitly in the + * binary code + */ + if(token & D3DVS_ADDRMODE_RELATIVE) { + sm_3_srcreg(This, reg->rel_reg, buffer); + } +} + +static const struct instr_handler_table vs_3_handlers[] = { + {BWRITERSIO_ADD, instr_handler}, + {BWRITERSIO_NOP, instr_handler}, + {BWRITERSIO_MOV, instr_handler}, + {BWRITERSIO_SUB, instr_handler}, + {BWRITERSIO_MAD, instr_handler}, + {BWRITERSIO_MUL, instr_handler}, + {BWRITERSIO_RCP, instr_handler}, + {BWRITERSIO_RSQ, instr_handler}, + {BWRITERSIO_DP3, instr_handler}, + {BWRITERSIO_DP4, instr_handler}, + {BWRITERSIO_MIN, instr_handler}, + {BWRITERSIO_MAX, instr_handler}, + {BWRITERSIO_SLT, instr_handler}, + {BWRITERSIO_SGE, instr_handler}, + {BWRITERSIO_ABS, instr_handler}, + {BWRITERSIO_EXP, instr_handler}, + {BWRITERSIO_LOG, instr_handler}, + {BWRITERSIO_EXPP, instr_handler}, + {BWRITERSIO_LOGP, instr_handler}, + {BWRITERSIO_DST, instr_handler}, + {BWRITERSIO_LRP, instr_handler}, + {BWRITERSIO_FRC, instr_handler}, + {BWRITERSIO_CRS, instr_handler}, + {BWRITERSIO_SGN, instr_handler}, + {BWRITERSIO_NRM, instr_handler}, + {BWRITERSIO_SINCOS, instr_handler}, + {BWRITERSIO_M4x4, instr_handler}, + {BWRITERSIO_M4x3, instr_handler}, + {BWRITERSIO_M3x4, instr_handler}, + {BWRITERSIO_M3x3, instr_handler}, + {BWRITERSIO_M3x2, instr_handler}, + {BWRITERSIO_LIT, instr_handler}, + {BWRITERSIO_POW, instr_handler}, + {BWRITERSIO_MOVA, instr_handler}, + + {BWRITERSIO_CALL, instr_handler}, + {BWRITERSIO_CALLNZ, instr_handler}, + {BWRITERSIO_REP, instr_handler}, + {BWRITERSIO_ENDREP, instr_handler}, + {BWRITERSIO_IF, instr_handler}, + {BWRITERSIO_LABEL, instr_handler}, + {BWRITERSIO_IFC, instr_handler}, + {BWRITERSIO_ELSE, instr_handler}, + {BWRITERSIO_ENDIF, instr_handler}, + {BWRITERSIO_BREAK, instr_handler}, + {BWRITERSIO_BREAKC, instr_handler}, + {BWRITERSIO_LOOP, instr_handler}, + {BWRITERSIO_RET, instr_handler}, + {BWRITERSIO_ENDLOOP, instr_handler}, + + {BWRITERSIO_SETP, instr_handler}, + {BWRITERSIO_BREAKP, instr_handler}, + {BWRITERSIO_TEXLDL, instr_handler}, + + {BWRITERSIO_END, NULL}, +}; + +static const struct bytecode_backend vs_3_backend = { + sm_3_header, + end, + sm_3_srcreg, + sm_3_dstreg, + sm_2_opcode, + vs_3_handlers +}; + +static const struct instr_handler_table ps_3_handlers[] = { + {BWRITERSIO_ADD, instr_handler}, + {BWRITERSIO_NOP, instr_handler}, + {BWRITERSIO_MOV, instr_handler}, + {BWRITERSIO_SUB, instr_handler}, + {BWRITERSIO_MAD, instr_handler}, + {BWRITERSIO_MUL, instr_handler}, + {BWRITERSIO_RCP, instr_handler}, + {BWRITERSIO_RSQ, instr_handler}, + {BWRITERSIO_DP3, instr_handler}, + {BWRITERSIO_DP4, instr_handler}, + {BWRITERSIO_MIN, instr_handler}, + {BWRITERSIO_MAX, instr_handler}, + {BWRITERSIO_ABS, instr_handler}, + {BWRITERSIO_EXP, instr_handler}, + {BWRITERSIO_LOG, instr_handler}, + {BWRITERSIO_EXPP, instr_handler}, + {BWRITERSIO_LOGP, instr_handler}, + {BWRITERSIO_LRP, instr_handler}, + {BWRITERSIO_FRC, instr_handler}, + {BWRITERSIO_CRS, instr_handler}, + {BWRITERSIO_NRM, instr_handler}, + {BWRITERSIO_SINCOS, instr_handler}, + {BWRITERSIO_M4x4, instr_handler}, + {BWRITERSIO_M4x3, instr_handler}, + {BWRITERSIO_M3x4, instr_handler}, + {BWRITERSIO_M3x3, instr_handler}, + {BWRITERSIO_M3x2, instr_handler}, + {BWRITERSIO_POW, instr_handler}, + {BWRITERSIO_DP2ADD, instr_handler}, + {BWRITERSIO_CMP, instr_handler}, + + {BWRITERSIO_CALL, instr_handler}, + {BWRITERSIO_CALLNZ, instr_handler}, + {BWRITERSIO_REP, instr_handler}, + {BWRITERSIO_ENDREP, instr_handler}, + {BWRITERSIO_IF, instr_handler}, + {BWRITERSIO_LABEL, instr_handler}, + {BWRITERSIO_IFC, instr_handler}, + {BWRITERSIO_ELSE, instr_handler}, + {BWRITERSIO_ENDIF, instr_handler}, + {BWRITERSIO_BREAK, instr_handler}, + {BWRITERSIO_BREAKC, instr_handler}, + {BWRITERSIO_LOOP, instr_handler}, + {BWRITERSIO_RET, instr_handler}, + {BWRITERSIO_ENDLOOP, instr_handler}, + + {BWRITERSIO_SETP, instr_handler}, + {BWRITERSIO_BREAKP, instr_handler}, + {BWRITERSIO_TEXLDL, instr_handler}, + + {BWRITERSIO_TEX, instr_handler}, + {BWRITERSIO_TEXLDP, instr_handler}, + {BWRITERSIO_TEXLDB, instr_handler}, + {BWRITERSIO_TEXKILL, instr_handler}, + {BWRITERSIO_DSX, instr_handler}, + {BWRITERSIO_DSY, instr_handler}, + {BWRITERSIO_TEXLDD, instr_handler}, + + {BWRITERSIO_END, NULL}, +}; + +static const struct bytecode_backend ps_3_backend = { + sm_3_header, + end, + sm_3_srcreg, + sm_3_dstreg, + sm_2_opcode, + ps_3_handlers +}; + +static void init_vs10_dx9_writer(struct bc_writer *writer) { + TRACE("Creating DirectX9 vertex shader 1.0 writer\n"); + writer->funcs = &vs_1_x_backend; +} + +static void init_vs11_dx9_writer(struct bc_writer *writer) { + TRACE("Creating DirectX9 vertex shader 1.1 writer\n"); + writer->funcs = &vs_1_x_backend; +} + +static void init_vs20_dx9_writer(struct bc_writer *writer) { + TRACE("Creating DirectX9 vertex shader 2.0 writer\n"); + writer->funcs = &vs_2_0_backend; +} + +static void init_vs2x_dx9_writer(struct bc_writer *writer) { + TRACE("Creating DirectX9 vertex shader 2.x writer\n"); + writer->funcs = &vs_2_x_backend; +} + +static void init_vs30_dx9_writer(struct bc_writer *writer) { + TRACE("Creating DirectX9 vertex shader 3.0 writer\n"); + writer->funcs = &vs_3_backend; +} + +static void init_ps10_dx9_writer(struct bc_writer *writer) { + TRACE("Creating DirectX9 pixel shader 1.0 writer\n"); + writer->funcs = &ps_1_0123_backend; +} + +static void init_ps11_dx9_writer(struct bc_writer *writer) { + TRACE("Creating DirectX9 pixel shader 1.1 writer\n"); + writer->funcs = &ps_1_0123_backend; +} + +static void init_ps12_dx9_writer(struct bc_writer *writer) { + TRACE("Creating DirectX9 pixel shader 1.2 writer\n"); + writer->funcs = &ps_1_0123_backend; +} + +static void init_ps13_dx9_writer(struct bc_writer *writer) { + TRACE("Creating DirectX9 pixel shader 1.3 writer\n"); + writer->funcs = &ps_1_0123_backend; +} + +static void init_ps14_dx9_writer(struct bc_writer *writer) { + TRACE("Creating DirectX9 pixel shader 1.4 writer\n"); + writer->funcs = &ps_1_4_backend; +} + +static void init_ps20_dx9_writer(struct bc_writer *writer) { + TRACE("Creating DirectX9 pixel shader 2.0 writer\n"); + writer->funcs = &ps_2_0_backend; +} + +static void init_ps2x_dx9_writer(struct bc_writer *writer) { + TRACE("Creating DirectX9 pixel shader 2.x writer\n"); + writer->funcs = &ps_2_x_backend; +} + +static void init_ps30_dx9_writer(struct bc_writer *writer) { + TRACE("Creating DirectX9 pixel shader 3.0 writer\n"); + writer->funcs = &ps_3_backend; +} + +static struct bc_writer *create_writer(DWORD version, DWORD dxversion) { + struct bc_writer *ret = d3dcompiler_alloc(sizeof(*ret)); + + if(!ret) { + WARN("Failed to allocate a bytecode writer instance\n"); + return NULL; + } + + switch(version) { + case BWRITERVS_VERSION(1, 0): + if(dxversion != 9) { + WARN("Unsupported dxversion for vertex shader 1.0 requested: %u\n", dxversion); + goto fail; + } + init_vs10_dx9_writer(ret); + break; + case BWRITERVS_VERSION(1, 1): + if(dxversion != 9) { + WARN("Unsupported dxversion for vertex shader 1.1 requested: %u\n", dxversion); + goto fail; + } + init_vs11_dx9_writer(ret); + break; + case BWRITERVS_VERSION(2, 0): + if(dxversion != 9) { + WARN("Unsupported dxversion for vertex shader 2.0 requested: %u\n", dxversion); + goto fail; + } + init_vs20_dx9_writer(ret); + break; + case BWRITERVS_VERSION(2, 1): + if(dxversion != 9) { + WARN("Unsupported dxversion for vertex shader 2.x requested: %u\n", dxversion); + goto fail; + } + init_vs2x_dx9_writer(ret); + break; + case BWRITERVS_VERSION(3, 0): + if(dxversion != 9) { + WARN("Unsupported dxversion for vertex shader 3.0 requested: %u\n", dxversion); + goto fail; + } + init_vs30_dx9_writer(ret); + break; + + case BWRITERPS_VERSION(1, 0): + if(dxversion != 9) { + WARN("Unsupported dxversion for pixel shader 1.0 requested: %u\n", dxversion); + goto fail; + } + init_ps10_dx9_writer(ret); + break; + case BWRITERPS_VERSION(1, 1): + if(dxversion != 9) { + WARN("Unsupported dxversion for pixel shader 1.1 requested: %u\n", dxversion); + goto fail; + } + init_ps11_dx9_writer(ret); + break; + case BWRITERPS_VERSION(1, 2): + if(dxversion != 9) { + WARN("Unsupported dxversion for pixel shader 1.2 requested: %u\n", dxversion); + goto fail; + } + init_ps12_dx9_writer(ret); + break; + case BWRITERPS_VERSION(1, 3): + if(dxversion != 9) { + WARN("Unsupported dxversion for pixel shader 1.3 requested: %u\n", dxversion); + goto fail; + } + init_ps13_dx9_writer(ret); + break; + case BWRITERPS_VERSION(1, 4): + if(dxversion != 9) { + WARN("Unsupported dxversion for pixel shader 1.4 requested: %u\n", dxversion); + goto fail; + } + init_ps14_dx9_writer(ret); + break; + + case BWRITERPS_VERSION(2, 0): + if(dxversion != 9) { + WARN("Unsupported dxversion for pixel shader 2.0 requested: %u\n", dxversion); + goto fail; + } + init_ps20_dx9_writer(ret); + break; + + case BWRITERPS_VERSION(2, 1): + if(dxversion != 9) { + WARN("Unsupported dxversion for pixel shader 2.x requested: %u\n", dxversion); + goto fail; + } + init_ps2x_dx9_writer(ret); + break; + + case BWRITERPS_VERSION(3, 0): + if(dxversion != 9) { + WARN("Unsupported dxversion for pixel shader 3.0 requested: %u\n", dxversion); + goto fail; + } + init_ps30_dx9_writer(ret); + break; + + default: + WARN("Unexpected shader version requested: %08x\n", version); + goto fail; + } + ret->version = version; + return ret; + +fail: + d3dcompiler_free(ret); + return NULL; +} + +static HRESULT call_instr_handler(struct bc_writer *writer, + const struct instruction *instr, + struct bytecode_buffer *buffer) { + DWORD i=0; + + while(writer->funcs->instructions[i].opcode != BWRITERSIO_END) { + if(instr->opcode == writer->funcs->instructions[i].opcode) { + if(!writer->funcs->instructions[i].func) { + WARN("Opcode %u not supported by this profile\n", instr->opcode); + return E_INVALIDARG; + } + writer->funcs->instructions[i].func(writer, instr, buffer); + return S_OK; + } + i++; + } + + FIXME("Unhandled instruction %u - %s\n", instr->opcode, + debug_print_opcode(instr->opcode)); + return E_INVALIDARG; +} + +HRESULT SlWriteBytecode(const struct bwriter_shader *shader, int dxversion, DWORD **result, DWORD *size) +{ + struct bc_writer *writer; + struct bytecode_buffer *buffer = NULL; + HRESULT hr; + unsigned int i; + + if(!shader){ + ERR("NULL shader structure, aborting\n"); + return E_FAIL; + } + writer = create_writer(shader->version, dxversion); + *result = NULL; + + if(!writer) { + WARN("Could not create a bytecode writer instance. Either unsupported version\n"); + WARN("or out of memory\n"); + hr = E_FAIL; + goto error; + } + + buffer = allocate_buffer(); + if(!buffer) { + WARN("Failed to allocate a buffer for the shader bytecode\n"); + hr = E_FAIL; + goto error; + } + + /* Write shader type and version */ + put_dword(buffer, shader->version); + + writer->funcs->header(writer, shader, buffer); + if(FAILED(writer->state)) { + hr = writer->state; + goto error; + } + + for(i = 0; i < shader->num_instrs; i++) { + hr = call_instr_handler(writer, shader->instr[i], buffer); + if(FAILED(hr)) { + goto error; + } + } + + if(FAILED(writer->state)) { + hr = writer->state; + goto error; + } + + writer->funcs->end(writer, shader, buffer); + + if(FAILED(buffer->state)) { + hr = buffer->state; + goto error; + } + + *size = buffer->size * sizeof(DWORD); + *result = buffer->data; + buffer->data = NULL; + hr = S_OK; + +error: + if(buffer) { + d3dcompiler_free(buffer->data); + d3dcompiler_free(buffer); + } + d3dcompiler_free(writer); + return hr; +} + +void SlDeleteShader(struct bwriter_shader *shader) { + unsigned int i, j; + + TRACE("Deleting shader %p\n", shader); + + for(i = 0; i < shader->num_cf; i++) { + d3dcompiler_free(shader->constF[i]); + } + d3dcompiler_free(shader->constF); + for(i = 0; i < shader->num_ci; i++) { + d3dcompiler_free(shader->constI[i]); + } + d3dcompiler_free(shader->constI); + for(i = 0; i < shader->num_cb; i++) { + d3dcompiler_free(shader->constB[i]); + } + d3dcompiler_free(shader->constB); + + d3dcompiler_free(shader->inputs); + d3dcompiler_free(shader->outputs); + d3dcompiler_free(shader->samplers); + + for(i = 0; i < shader->num_instrs; i++) { + for(j = 0; j < shader->instr[i]->num_srcs; j++) { + d3dcompiler_free(shader->instr[i]->src[j].rel_reg); + } + d3dcompiler_free(shader->instr[i]->src); + d3dcompiler_free(shader->instr[i]); + } + d3dcompiler_free(shader->instr); + + d3dcompiler_free(shader); +} diff --git a/reactos/dll/directx/wine/d3dcompiler_43/compiler.c b/reactos/dll/directx/wine/d3dcompiler_43/compiler.c new file mode 100644 index 00000000000..14fa652b65e --- /dev/null +++ b/reactos/dll/directx/wine/d3dcompiler_43/compiler.c @@ -0,0 +1,763 @@ +/* + * Copyright 2009 Matteo Bruni + * Copyright 2010 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 + */ + +#define COBJMACROS +#include "config.h" +#include "wine/port.h" +#include "wine/debug.h" +#include "wine/unicode.h" + +#include "d3dcompiler_private.h" +#include "wine/wpp.h" + +WINE_DEFAULT_DEBUG_CHANNEL(d3dcompiler); + +#define D3DXERR_INVALIDDATA 0x88760b59 + +#define BUFFER_INITIAL_CAPACITY 256 + +struct mem_file_desc +{ + const char *buffer; + unsigned int size; + unsigned int pos; +}; + +static struct mem_file_desc current_shader; +static ID3DInclude *current_include; +static const char *initial_filename; + +#define INCLUDES_INITIAL_CAPACITY 4 + +struct loaded_include +{ + const char *name; + const char *data; +}; + +static struct loaded_include *includes; +static int includes_capacity, includes_size; +static const char *parent_include; + +static char *wpp_output; +static int wpp_output_capacity, wpp_output_size; + +static char *wpp_messages; +static int wpp_messages_capacity, wpp_messages_size; + +/* Mutex used to guarantee a single invocation + of the D3DXAssembleShader function (or its variants) at a time. + This is needed as wpp isn't thread-safe */ +static CRITICAL_SECTION wpp_mutex; +static CRITICAL_SECTION_DEBUG wpp_mutex_debug = +{ + 0, 0, &wpp_mutex, + { &wpp_mutex_debug.ProcessLocksList, + &wpp_mutex_debug.ProcessLocksList }, + 0, 0, { (DWORD_PTR)(__FILE__ ": wpp_mutex") } +}; +static CRITICAL_SECTION wpp_mutex = { &wpp_mutex_debug, -1, 0, 0, 0, 0 }; + +/* Preprocessor error reporting functions */ +static void wpp_write_message(const char *fmt, va_list args) +{ + char* newbuffer; + int rc, newsize; + + if(wpp_messages_capacity == 0) + { + wpp_messages = HeapAlloc(GetProcessHeap(), 0, MESSAGEBUFFER_INITIAL_SIZE); + if(wpp_messages == NULL) + return; + + wpp_messages_capacity = MESSAGEBUFFER_INITIAL_SIZE; + } + + while(1) + { + rc = vsnprintf(wpp_messages + wpp_messages_size, + wpp_messages_capacity - wpp_messages_size, fmt, args); + + if (rc < 0 || /* C89 */ + rc >= wpp_messages_capacity - wpp_messages_size) { /* C99 */ + /* Resize the buffer */ + newsize = wpp_messages_capacity * 2; + newbuffer = HeapReAlloc(GetProcessHeap(), 0, wpp_messages, newsize); + if(newbuffer == NULL) + { + ERR("Error reallocating memory for parser messages\n"); + return; + } + wpp_messages = newbuffer; + wpp_messages_capacity = newsize; + } + else + { + wpp_messages_size += rc; + return; + } + } +} + +static void PRINTF_ATTR(1,2) wpp_write_message_var(const char *fmt, ...) +{ + va_list args; + + va_start(args, fmt); + wpp_write_message(fmt, args); + va_end(args); +} + +static void wpp_error(const char *file, int line, int col, const char *_near, + const char *msg, va_list ap) +{ + wpp_write_message_var("%s:%d:%d: %s: ", file ? file : "'main file'", + line, col, "Error"); + wpp_write_message(msg, ap); + wpp_write_message_var("\n"); +} + +static void wpp_warning(const char *file, int line, int col, const char *_near, + const char *msg, va_list ap) +{ + wpp_write_message_var("%s:%d:%d: %s: ", file ? file : "'main file'", + line, col, "Warning"); + wpp_write_message(msg, ap); + wpp_write_message_var("\n"); +} + +static char *wpp_lookup_mem(const char *filename, int type, const char *parent_name, + char **include_path, int include_path_count) +{ + /* Here we return always ok. We will maybe fail on the next wpp_open_mem */ + char *path; + int i; + + parent_include = NULL; + if(parent_name[0] != '\0') + { + for(i = 0; i < includes_size; i++) + { + if(!strcmp(parent_name, includes[i].name)) + { + parent_include = includes[i].data; + break; + } + } + if(parent_include == NULL) + { + ERR("Parent include file missing\n"); + return NULL; + } + } + + path = malloc(strlen(filename) + 1); + if(path) + memcpy(path, filename, strlen(filename) + 1); + return path; +} + +static void *wpp_open_mem(const char *filename, int type) +{ + struct mem_file_desc *desc; + HRESULT hr; + + if(!strcmp(filename, initial_filename)) + { + current_shader.pos = 0; + return ¤t_shader; + } + + if(current_include == NULL) return NULL; + desc = HeapAlloc(GetProcessHeap(), 0, sizeof(*desc)); + if(!desc) + return NULL; + + hr = ID3DInclude_Open(current_include, + type ? D3D_INCLUDE_LOCAL : D3D_INCLUDE_SYSTEM, + filename, parent_include, (LPCVOID *)&desc->buffer, + &desc->size); + if(FAILED(hr)) + { + HeapFree(GetProcessHeap(), 0, desc); + return NULL; + } + + if(includes_capacity == includes_size) + { + if(includes_capacity == 0) + { + includes = HeapAlloc(GetProcessHeap(), 0, INCLUDES_INITIAL_CAPACITY * sizeof(*includes)); + if(includes == NULL) + { + ERR("Error allocating memory for the loaded includes structure\n"); + goto error; + } + includes_capacity = INCLUDES_INITIAL_CAPACITY * sizeof(*includes); + } + else + { + int newcapacity = includes_capacity * 2; + struct loaded_include *newincludes = + HeapReAlloc(GetProcessHeap(), 0, includes, newcapacity); + if(newincludes == NULL) + { + ERR("Error reallocating memory for the loaded includes structure\n"); + goto error; + } + includes = newincludes; + includes_capacity = newcapacity; + } + } + includes[includes_size].name = filename; + includes[includes_size++].data = desc->buffer; + + desc->pos = 0; + return desc; + +error: + ID3DInclude_Close(current_include, desc->buffer); + HeapFree(GetProcessHeap(), 0, desc); + return NULL; +} + +static void wpp_close_mem(void *file) +{ + struct mem_file_desc *desc = file; + + if(desc != ¤t_shader) + { + if(current_include) + ID3DInclude_Close(current_include, desc->buffer); + else + ERR("current_include == NULL, desc == %p, buffer = %s\n", + desc, desc->buffer); + + HeapFree(GetProcessHeap(), 0, desc); + } +} + +static int wpp_read_mem(void *file, char *buffer, unsigned int len) +{ + struct mem_file_desc *desc = file; + + len = min(len, desc->size - desc->pos); + memcpy(buffer, desc->buffer + desc->pos, len); + desc->pos += len; + return len; +} + +static void wpp_write_mem(const char *buffer, unsigned int len) +{ + char *new_wpp_output; + + if(wpp_output_capacity == 0) + { + wpp_output = HeapAlloc(GetProcessHeap(), 0, BUFFER_INITIAL_CAPACITY); + if(!wpp_output) + return; + + wpp_output_capacity = BUFFER_INITIAL_CAPACITY; + } + if(len > wpp_output_capacity - wpp_output_size) + { + while(len > wpp_output_capacity - wpp_output_size) + { + wpp_output_capacity *= 2; + } + new_wpp_output = HeapReAlloc(GetProcessHeap(), 0, wpp_output, + wpp_output_capacity); + if(!new_wpp_output) + { + ERR("Error allocating memory\n"); + return; + } + wpp_output = new_wpp_output; + } + memcpy(wpp_output + wpp_output_size, buffer, len); + wpp_output_size += len; +} + +static int wpp_close_output(void) +{ + char *new_wpp_output = HeapReAlloc(GetProcessHeap(), 0, wpp_output, + wpp_output_size + 1); + if(!new_wpp_output) return 0; + wpp_output = new_wpp_output; + wpp_output[wpp_output_size]='\0'; + wpp_output_size++; + return 1; +} + +static HRESULT preprocess_shader(const void *data, SIZE_T data_size, const char *filename, + const D3D_SHADER_MACRO *defines, ID3DInclude *include, ID3DBlob **error_messages) +{ + int ret; + HRESULT hr = S_OK; + const D3D_SHADER_MACRO *def = defines; + + static const struct wpp_callbacks wpp_callbacks = + { + wpp_lookup_mem, + wpp_open_mem, + wpp_close_mem, + wpp_read_mem, + wpp_write_mem, + wpp_error, + wpp_warning, + }; + + if (def != NULL) + { + while (def->Name != NULL) + { + wpp_add_define(def->Name, def->Definition); + def++; + } + } + current_include = include; + includes_size = 0; + + wpp_output_size = wpp_output_capacity = 0; + wpp_output = NULL; + + wpp_set_callbacks(&wpp_callbacks); + wpp_messages_size = wpp_messages_capacity = 0; + wpp_messages = NULL; + current_shader.buffer = data; + current_shader.size = data_size; + initial_filename = filename ? filename : ""; + + ret = wpp_parse(initial_filename, NULL); + if (!wpp_close_output()) + ret = 1; + if (ret) + { + TRACE("Error during shader preprocessing\n"); + if (wpp_messages) + { + int size; + ID3DBlob *buffer; + + TRACE("Preprocessor messages:\n%s\n", debugstr_a(wpp_messages)); + + if (error_messages) + { + size = strlen(wpp_messages) + 1; + hr = D3DCreateBlob(size, &buffer); + if (FAILED(hr)) + goto cleanup; + CopyMemory(ID3D10Blob_GetBufferPointer(buffer), wpp_messages, size); + *error_messages = buffer; + } + } + if (data) + TRACE("Shader source:\n%s\n", debugstr_an(data, data_size)); + hr = E_FAIL; + } + +cleanup: + /* Remove the previously added defines */ + if (defines != NULL) + { + while (defines->Name != NULL) + { + wpp_del_define(defines->Name); + defines++; + } + } + HeapFree(GetProcessHeap(), 0, wpp_messages); + return hr; +} + +static HRESULT assemble_shader(const char *preproc_shader, + ID3DBlob **shader_blob, ID3DBlob **error_messages) +{ + struct bwriter_shader *shader; + char *messages = NULL; + HRESULT hr; + DWORD *res, size; + ID3DBlob *buffer; + char *pos; + + shader = SlAssembleShader(preproc_shader, &messages); + + if (messages) + { + TRACE("Assembler messages:\n"); + TRACE("%s\n", debugstr_a(messages)); + + TRACE("Shader source:\n"); + TRACE("%s\n", debugstr_a(preproc_shader)); + + if (error_messages) + { + const char *preproc_messages = *error_messages ? ID3D10Blob_GetBufferPointer(*error_messages) : NULL; + + size = strlen(messages) + (preproc_messages ? strlen(preproc_messages) : 0) + 1; + hr = D3DCreateBlob(size, &buffer); + if (FAILED(hr)) + { + HeapFree(GetProcessHeap(), 0, messages); + if (shader) SlDeleteShader(shader); + return hr; + } + pos = ID3D10Blob_GetBufferPointer(buffer); + if (preproc_messages) + { + CopyMemory(pos, preproc_messages, strlen(preproc_messages) + 1); + pos += strlen(preproc_messages); + } + CopyMemory(pos, messages, strlen(messages) + 1); + + if (*error_messages) ID3D10Blob_Release(*error_messages); + *error_messages = buffer; + } + HeapFree(GetProcessHeap(), 0, messages); + } + + if (shader == NULL) + { + ERR("Asm reading failed\n"); + return D3DXERR_INVALIDDATA; + } + + hr = SlWriteBytecode(shader, 9, &res, &size); + SlDeleteShader(shader); + if (FAILED(hr)) + { + ERR("SlWriteBytecode failed with 0x%08x\n", hr); + return D3DXERR_INVALIDDATA; + } + + if (shader_blob) + { + hr = D3DCreateBlob(size, &buffer); + if (FAILED(hr)) + { + HeapFree(GetProcessHeap(), 0, res); + return hr; + } + CopyMemory(ID3D10Blob_GetBufferPointer(buffer), res, size); + *shader_blob = buffer; + } + + HeapFree(GetProcessHeap(), 0, res); + + return S_OK; +} + +HRESULT WINAPI D3DAssemble(const void *data, SIZE_T datasize, const char *filename, + const D3D_SHADER_MACRO *defines, ID3DInclude *include, UINT flags, + ID3DBlob **shader, ID3DBlob **error_messages) +{ + HRESULT hr; + + TRACE("data %p, datasize %lu, filename %s, defines %p, include %p, sflags %#x,\n" + "shader %p, error_messages %p\n", + data, datasize, debugstr_a(filename), defines, include, flags, shader, error_messages); + + EnterCriticalSection(&wpp_mutex); + + /* TODO: flags */ + if (flags) FIXME("flags %x\n", flags); + + if (shader) *shader = NULL; + if (error_messages) *error_messages = NULL; + + hr = preprocess_shader(data, datasize, filename, defines, include, error_messages); + if (SUCCEEDED(hr)) + hr = assemble_shader(wpp_output, shader, error_messages); + + HeapFree(GetProcessHeap(), 0, wpp_output); + LeaveCriticalSection(&wpp_mutex); + return hr; +} + +struct target_info { + const char *name; + enum shader_type type; + DWORD sm_major; + DWORD sm_minor; + DWORD level_major; + DWORD level_minor; + BOOL sw; + BOOL support; +}; + +/* Must be kept sorted for binary search */ +static const struct target_info targets_info[] = { + { "cs_4_0", ST_UNKNOWN, 4, 0, 0, 0, FALSE, FALSE }, + { "cs_4_1", ST_UNKNOWN, 4, 1, 0, 0, FALSE, FALSE }, + { "cs_5_0", ST_UNKNOWN, 5, 0, 0, 0, FALSE, FALSE }, + { "ds_5_0", ST_UNKNOWN, 5, 0, 0, 0, FALSE, FALSE }, + { "fx_2_0", ST_UNKNOWN, 2, 0, 0, 0, FALSE, FALSE }, + { "fx_4_0", ST_UNKNOWN, 4, 0, 0, 0, FALSE, FALSE }, + { "fx_4_1", ST_UNKNOWN, 4, 1, 0, 0, FALSE, FALSE }, + { "fx_5_0", ST_UNKNOWN, 5, 0, 0, 0, FALSE, FALSE }, + { "gs_4_0", ST_UNKNOWN, 4, 0, 0, 0, FALSE, FALSE }, + { "gs_4_1", ST_UNKNOWN, 4, 1, 0, 0, FALSE, FALSE }, + { "gs_5_0", ST_UNKNOWN, 5, 0, 0, 0, FALSE, FALSE }, + { "hs_5_0", ST_UNKNOWN, 5, 0, 0, 0, FALSE, FALSE }, + { "ps.1.0", ST_PIXEL, 1, 0, 0, 0, FALSE, TRUE }, + { "ps.1.1", ST_PIXEL, 1, 1, 0, 0, FALSE, FALSE }, + { "ps.1.2", ST_PIXEL, 1, 2, 0, 0, FALSE, FALSE }, + { "ps.1.3", ST_PIXEL, 1, 3, 0, 0, FALSE, FALSE }, + { "ps.1.4", ST_PIXEL, 1, 4, 0, 0, FALSE, FALSE }, + { "ps.2.0", ST_PIXEL, 2, 0, 0, 0, FALSE, TRUE }, + { "ps.2.a", ST_PIXEL, 2, 1, 0, 0, FALSE, FALSE }, + { "ps.2.b", ST_PIXEL, 2, 2, 0, 0, FALSE, FALSE }, + { "ps.2.sw", ST_PIXEL, 2, 0, 0, 0, TRUE, FALSE }, + { "ps.3.0", ST_PIXEL, 3, 0, 0, 0, FALSE, TRUE }, + { "ps_1_0", ST_PIXEL, 1, 0, 0, 0, FALSE, TRUE }, + { "ps_1_1", ST_PIXEL, 1, 1, 0, 0, FALSE, FALSE }, + { "ps_1_2", ST_PIXEL, 1, 2, 0, 0, FALSE, FALSE }, + { "ps_1_3", ST_PIXEL, 1, 3, 0, 0, FALSE, FALSE }, + { "ps_1_4", ST_PIXEL, 1, 4, 0, 0, FALSE, FALSE }, + { "ps_2_0", ST_PIXEL, 2, 0, 0, 0, FALSE, TRUE }, + { "ps_2_a", ST_PIXEL, 2, 1, 0, 0, FALSE, FALSE }, + { "ps_2_b", ST_PIXEL, 2, 2, 0, 0, FALSE, FALSE }, + { "ps_2_sw", ST_PIXEL, 2, 0, 0, 0, TRUE, FALSE }, + { "ps_3_0", ST_PIXEL, 3, 0, 0, 0, FALSE, TRUE }, + { "ps_3_sw", ST_PIXEL, 3, 0, 0, 0, TRUE, FALSE }, + { "ps_4_0", ST_PIXEL, 4, 0, 0, 0, FALSE, TRUE }, + { "ps_4_0_level_9_0", ST_PIXEL, 4, 0, 9, 0, FALSE, FALSE }, + { "ps_4_0_level_9_1", ST_PIXEL, 4, 0, 9, 1, FALSE, FALSE }, + { "ps_4_0_level_9_3", ST_PIXEL, 4, 0, 9, 3, FALSE, FALSE }, + { "ps_4_1", ST_PIXEL, 4, 1, 0, 0, FALSE, TRUE }, + { "ps_5_0", ST_PIXEL, 5, 0, 0, 0, FALSE, TRUE }, + { "tx_1_0", ST_UNKNOWN, 1, 0, 0, 0, FALSE, FALSE }, + { "vs.1.0", ST_VERTEX, 1, 0, 0, 0, FALSE, TRUE }, + { "vs.1.1", ST_VERTEX, 1, 1, 0, 0, FALSE, TRUE }, + { "vs.2.0", ST_VERTEX, 2, 0, 0, 0, FALSE, TRUE }, + { "vs.2.a", ST_VERTEX, 2, 1, 0, 0, FALSE, FALSE }, + { "vs.2.sw", ST_VERTEX, 2, 0, 0, 0, TRUE, FALSE }, + { "vs.3.0", ST_VERTEX, 3, 0, 0, 0, FALSE, TRUE }, + { "vs.3.sw", ST_VERTEX, 3, 0, 0, 0, TRUE, FALSE }, + { "vs_1_0", ST_VERTEX, 1, 0, 0, 0, FALSE, TRUE }, + { "vs_1_1", ST_VERTEX, 1, 1, 0, 0, FALSE, TRUE }, + { "vs_2_0", ST_VERTEX, 2, 0, 0, 0, FALSE, TRUE }, + { "vs_2_a", ST_VERTEX, 2, 1, 0, 0, FALSE, FALSE }, + { "vs_2_sw", ST_VERTEX, 2, 0, 0, 0, TRUE, FALSE }, + { "vs_3_0", ST_VERTEX, 3, 0, 0, 0, FALSE, TRUE }, + { "vs_3_sw", ST_VERTEX, 3, 0, 0, 0, TRUE, FALSE }, + { "vs_4_0", ST_VERTEX, 4, 0, 0, 0, FALSE, TRUE }, + { "vs_4_0_level_9_0", ST_VERTEX, 4, 0, 9, 0, FALSE, FALSE }, + { "vs_4_0_level_9_1", ST_VERTEX, 4, 0, 9, 1, FALSE, FALSE }, + { "vs_4_0_level_9_3", ST_VERTEX, 4, 0, 9, 3, FALSE, FALSE }, + { "vs_4_1", ST_VERTEX, 4, 1, 0, 0, FALSE, TRUE }, + { "vs_5_0", ST_VERTEX, 5, 0, 0, 0, FALSE, TRUE }, +}; + +static const struct target_info * get_target_info(const char *target) +{ + LONG min = 0; + LONG max = sizeof(targets_info) / sizeof(targets_info[0]) - 1; + LONG cur; + int res; + + while (min <= max) + { + cur = (min + max) / 2; + res = strcmp(target, targets_info[cur].name); + if (res < 0) + max = cur - 1; + else if (res > 0) + min = cur + 1; + else + return &targets_info[cur]; + } + + return NULL; +} + +static HRESULT compile_shader(const char *preproc_shader, const char *target, const char *entrypoint, + ID3DBlob **shader_blob, ID3DBlob **error_messages) +{ + struct bwriter_shader *shader; + char *messages = NULL; + HRESULT hr; + DWORD *res, size, major, minor; + ID3DBlob *buffer; + char *pos; + enum shader_type shader_type; + const struct target_info *info; + + TRACE("Preprocessed shader source: %s\n", debugstr_a(preproc_shader)); + + TRACE("Checking compilation target %s\n", debugstr_a(target)); + info = get_target_info(target); + if (!info) + { + FIXME("Unknown compilation target %s\n", debugstr_a(target)); + return D3DERR_INVALIDCALL; + } + else + { + if (!info->support) + { + FIXME("Compilation target %s not yet supported\n", debugstr_a(target)); + return D3DERR_INVALIDCALL; + } + else + { + shader_type = info->type; + major = info->sm_major; + minor = info->sm_minor; + } + } + + shader = parse_hlsl_shader(preproc_shader, shader_type, major, minor, entrypoint, &messages); + + if (messages) + { + TRACE("Compiler messages:\n"); + TRACE("%s\n", debugstr_a(messages)); + + TRACE("Shader source:\n"); + TRACE("%s\n", debugstr_a(preproc_shader)); + + if (error_messages) + { + const char *preproc_messages = *error_messages ? ID3D10Blob_GetBufferPointer(*error_messages) : NULL; + + size = strlen(messages) + (preproc_messages ? strlen(preproc_messages) : 0) + 1; + hr = D3DCreateBlob(size, &buffer); + if (FAILED(hr)) + { + HeapFree(GetProcessHeap(), 0, messages); + if (shader) SlDeleteShader(shader); + return hr; + } + pos = ID3D10Blob_GetBufferPointer(buffer); + if (preproc_messages) + { + memcpy(pos, preproc_messages, strlen(preproc_messages) + 1); + pos += strlen(preproc_messages); + } + memcpy(pos, messages, strlen(messages) + 1); + + if (*error_messages) ID3D10Blob_Release(*error_messages); + *error_messages = buffer; + } + HeapFree(GetProcessHeap(), 0, messages); + } + + if (!shader) + { + ERR("HLSL shader parsing failed.\n"); + return D3DXERR_INVALIDDATA; + } + + hr = SlWriteBytecode(shader, 9, &res, &size); + SlDeleteShader(shader); + if (FAILED(hr)) + { + ERR("SlWriteBytecode failed with error 0x%08x.\n", hr); + return D3DXERR_INVALIDDATA; + } + + if (shader_blob) + { + hr = D3DCreateBlob(size, &buffer); + if (FAILED(hr)) + { + HeapFree(GetProcessHeap(), 0, res); + return hr; + } + memcpy(ID3D10Blob_GetBufferPointer(buffer), res, size); + *shader_blob = buffer; + } + + HeapFree(GetProcessHeap(), 0, res); + + return S_OK; +} + +HRESULT WINAPI D3DCompile(const void *data, SIZE_T data_size, const char *filename, + const D3D_SHADER_MACRO *defines, ID3DInclude *include, const char *entrypoint, + const char *target, UINT sflags, UINT eflags, ID3DBlob **shader, ID3DBlob **error_messages) +{ + HRESULT hr; + + TRACE("data %p, data_size %lu, filename %s, defines %p, include %p, entrypoint %s,\n" + "target %s, sflags %#x, eflags %#x, shader %p, error_messages %p\n", + data, data_size, debugstr_a(filename), defines, include, debugstr_a(entrypoint), + debugstr_a(target), sflags, eflags, shader, error_messages); + + if (shader) *shader = NULL; + if (error_messages) *error_messages = NULL; + + EnterCriticalSection(&wpp_mutex); + + hr = preprocess_shader(data, data_size, filename, defines, include, error_messages); + if (SUCCEEDED(hr)) + hr = compile_shader(wpp_output, target, entrypoint, shader, error_messages); + + HeapFree(GetProcessHeap(), 0, wpp_output); + LeaveCriticalSection(&wpp_mutex); + return hr; +} + +HRESULT WINAPI D3DPreprocess(const void *data, SIZE_T size, const char *filename, + const D3D_SHADER_MACRO *defines, ID3DInclude *include, + ID3DBlob **shader, ID3DBlob **error_messages) +{ + HRESULT hr; + ID3DBlob *buffer; + + TRACE("data %p, size %lu, filename %s, defines %p, include %p, shader %p, error_messages %p\n", + data, size, debugstr_a(filename), defines, include, shader, error_messages); + + if (!data) + return E_INVALIDARG; + + EnterCriticalSection(&wpp_mutex); + + if (shader) *shader = NULL; + if (error_messages) *error_messages = NULL; + + hr = preprocess_shader(data, size, filename, defines, include, error_messages); + + if (SUCCEEDED(hr)) + { + if (shader) + { + hr = D3DCreateBlob(wpp_output_size, &buffer); + if (FAILED(hr)) + goto cleanup; + CopyMemory(ID3D10Blob_GetBufferPointer(buffer), wpp_output, wpp_output_size); + *shader = buffer; + } + else + hr = E_INVALIDARG; + } + +cleanup: + HeapFree(GetProcessHeap(), 0, wpp_output); + LeaveCriticalSection(&wpp_mutex); + return hr; +} + +HRESULT WINAPI D3DDisassemble(const void *data, SIZE_T size, UINT flags, const char *comments, ID3DBlob **disassembly) +{ + FIXME("data %p, size %lu, flags %#x, comments %p, disassembly %p stub!\n", + data, size, flags, comments, disassembly); + return E_NOTIMPL; +} diff --git a/reactos/dll/directx/wine/d3dcompiler_43/d3dcompiler_43.spec b/reactos/dll/directx/wine/d3dcompiler_43/d3dcompiler_43.spec new file mode 100644 index 00000000000..21ff9b4a81e --- /dev/null +++ b/reactos/dll/directx/wine/d3dcompiler_43/d3dcompiler_43.spec @@ -0,0 +1,17 @@ +@ stdcall D3DAssemble(ptr long str ptr ptr long ptr ptr) +@ stub DebugSetMute +@ stdcall D3DCompile(ptr long str ptr ptr str str long long ptr ptr) +@ stub D3DCompressShaders +@ stdcall D3DCreateBlob(long ptr) +@ stub D3DDecompressShaders +@ stdcall -stub D3DDisassemble10Effect(ptr long ptr) +@ stdcall D3DDisassemble(ptr long long ptr ptr) +@ stdcall D3DGetBlobPart(ptr long long long ptr) +@ stdcall D3DGetDebugInfo(ptr long ptr) +@ stdcall D3DGetInputAndOutputSignatureBlob(ptr long ptr) +@ stdcall D3DGetInputSignatureBlob(ptr long ptr) +@ stdcall D3DGetOutputSignatureBlob(ptr long ptr) +@ stdcall D3DPreprocess(ptr long str ptr ptr ptr ptr) +@ stdcall D3DReflect(ptr long ptr ptr) +@ stub D3DReturnFailure1 +@ stdcall D3DStripShader(ptr long long ptr) diff --git a/reactos/dll/directx/wine/d3dcompiler_43/d3dcompiler_43_main.c b/reactos/dll/directx/wine/d3dcompiler_43/d3dcompiler_43_main.c new file mode 100644 index 00000000000..0c664710935 --- /dev/null +++ b/reactos/dll/directx/wine/d3dcompiler_43/d3dcompiler_43_main.c @@ -0,0 +1,42 @@ +/* + * Direct3D shader compiler main file + * + * Copyright 2010 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 + +#include "windef.h" +#include "winbase.h" + +#include "d3dcompiler_private.h" + +BOOL WINAPI DllMain(HINSTANCE inst, DWORD reason, LPVOID reserved) +{ + switch (reason) + { + case DLL_WINE_PREATTACH: + return FALSE; /* prefer native version */ + case DLL_PROCESS_ATTACH: + DisableThreadLibraryCalls(inst); + break; + } + return TRUE; +} diff --git a/reactos/dll/directx/wine/d3dcompiler_43/d3dcompiler_private.h b/reactos/dll/directx/wine/d3dcompiler_43/d3dcompiler_private.h new file mode 100644 index 00000000000..d25b4e54d56 --- /dev/null +++ b/reactos/dll/directx/wine/d3dcompiler_43/d3dcompiler_private.h @@ -0,0 +1,1215 @@ +/* + * Copyright 2008 Stefan Dösinger + * Copyright 2009 Matteo Bruni + * Copyright 2010 Rico Schüller + * 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 + */ + +#ifndef __WINE_D3DCOMPILER_PRIVATE_H +#define __WINE_D3DCOMPILER_PRIVATE_H + +#include "wine/debug.h" +#include "wine/list.h" +#include "wine/rbtree.h" + +#define COBJMACROS +#include "windef.h" +#include "winbase.h" +#include "objbase.h" + +#include "d3dcompiler.h" + +#include + +/* + * This doesn't belong here, but for some functions it is possible to return that value, + * see http://msdn.microsoft.com/en-us/library/bb205278%28v=VS.85%29.aspx + * The original definition is in D3DX10core.h. + */ +#define D3DERR_INVALIDCALL 0x8876086c + +/* TRACE helper functions */ +const char *debug_d3dcompiler_d3d_blob_part(D3D_BLOB_PART part) DECLSPEC_HIDDEN; +const char *debug_d3dcompiler_shader_variable_class(D3D_SHADER_VARIABLE_CLASS c) DECLSPEC_HIDDEN; +const char *debug_d3dcompiler_shader_variable_type(D3D_SHADER_VARIABLE_TYPE t) DECLSPEC_HIDDEN; + +enum shader_type +{ + ST_UNKNOWN, + ST_VERTEX, + ST_PIXEL +}; + +typedef enum BWRITER_COMPARISON_TYPE { + BWRITER_COMPARISON_NONE, + BWRITER_COMPARISON_GT, + BWRITER_COMPARISON_EQ, + BWRITER_COMPARISON_GE, + BWRITER_COMPARISON_LT, + BWRITER_COMPARISON_NE, + BWRITER_COMPARISON_LE +} BWRITER_COMPARISON_TYPE; + +struct constant { + DWORD regnum; + union { + float f; + INT i; + BOOL b; + DWORD d; + } value[4]; +}; + +struct shader_reg { + DWORD type; + DWORD regnum; + struct shader_reg *rel_reg; + DWORD srcmod; + union { + DWORD swizzle; + DWORD writemask; + } u; +}; + +struct instruction { + DWORD opcode; + DWORD dstmod; + DWORD shift; + BWRITER_COMPARISON_TYPE comptype; + BOOL has_dst; + struct shader_reg dst; + struct shader_reg *src; + unsigned int num_srcs; /* For freeing the rel_regs */ + BOOL has_predicate; + struct shader_reg predicate; + BOOL coissue; +}; + +struct declaration { + DWORD usage, usage_idx; + DWORD regnum; + DWORD mod; + DWORD writemask; + BOOL builtin; +}; + +struct samplerdecl { + DWORD type; + DWORD regnum; + DWORD mod; +}; + +#define INSTRARRAY_INITIAL_SIZE 8 +struct bwriter_shader { + enum shader_type type; + + /* Shader version selected */ + DWORD version; + + /* Local constants. Every constant that is not defined below is loaded from + * the global constant set at shader runtime + */ + struct constant **constF; + struct constant **constI; + struct constant **constB; + unsigned int num_cf, num_ci, num_cb; + + /* Declared input and output varyings */ + struct declaration *inputs, *outputs; + unsigned int num_inputs, num_outputs; + struct samplerdecl *samplers; + unsigned int num_samplers; + + /* Are special pixel shader 3.0 registers declared? */ + BOOL vPos, vFace; + + /* Array of shader instructions - The shader code itself */ + struct instruction **instr; + unsigned int num_instrs, instr_alloc_size; +}; + +static inline void *d3dcompiler_alloc(SIZE_T size) +{ + return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size); +} + +static inline void *d3dcompiler_realloc(void *ptr, SIZE_T size) +{ + return HeapReAlloc(GetProcessHeap(), 0, ptr, size); +} + +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 + * too it has to know it as well + */ +struct rel_reg { + BOOL has_rel_reg; + DWORD type; + DWORD additional_offset; + DWORD rel_regnum; + DWORD swizzle; +}; + +#define MAX_SRC_REGS 4 + +struct src_regs { + struct shader_reg reg[MAX_SRC_REGS]; + unsigned int count; +}; + +struct asmparser_backend { + void (*constF)(struct asm_parser *This, DWORD reg, float x, float y, float z, float w); + void (*constI)(struct asm_parser *This, DWORD reg, INT x, INT y, INT z, INT w); + void (*constB)(struct asm_parser *This, DWORD reg, BOOL x); + + void (*dstreg)(struct asm_parser *This, struct instruction *instr, + const struct shader_reg *dst); + void (*srcreg)(struct asm_parser *This, struct instruction *instr, int num, + const struct shader_reg *src); + + void (*predicate)(struct asm_parser *This, + const struct shader_reg *predicate); + void (*coissue)(struct asm_parser *This); + + void (*dcl_output)(struct asm_parser *This, DWORD usage, DWORD num, + const struct shader_reg *reg); + void (*dcl_input)(struct asm_parser *This, DWORD usage, DWORD num, + DWORD mod, const struct shader_reg *reg); + void (*dcl_sampler)(struct asm_parser *This, DWORD samptype, DWORD mod, + DWORD regnum, unsigned int line_no); + + void (*end)(struct asm_parser *This); + + void (*instr)(struct asm_parser *This, DWORD opcode, DWORD mod, DWORD shift, + BWRITER_COMPARISON_TYPE comp, const struct shader_reg *dst, + const struct src_regs *srcs, int expectednsrcs); +}; + +struct instruction *alloc_instr(unsigned int srcs) DECLSPEC_HIDDEN; +BOOL add_instruction(struct bwriter_shader *shader, struct instruction *instr) DECLSPEC_HIDDEN; +BOOL add_constF(struct bwriter_shader *shader, DWORD reg, float x, float y, float z, float w) DECLSPEC_HIDDEN; +BOOL add_constI(struct bwriter_shader *shader, DWORD reg, INT x, INT y, INT z, INT w) DECLSPEC_HIDDEN; +BOOL add_constB(struct bwriter_shader *shader, DWORD reg, BOOL x) DECLSPEC_HIDDEN; +BOOL record_declaration(struct bwriter_shader *shader, DWORD usage, DWORD usage_idx, + DWORD mod, BOOL output, DWORD regnum, DWORD writemask, BOOL builtin) DECLSPEC_HIDDEN; +BOOL record_sampler(struct bwriter_shader *shader, DWORD samptype, DWORD mod, DWORD regnum) DECLSPEC_HIDDEN; + +#define MESSAGEBUFFER_INITIAL_SIZE 256 + +enum parse_status +{ + PARSE_SUCCESS = 0, + PARSE_WARN = 1, + PARSE_ERR = 2 +}; + +struct compilation_messages +{ + char *string; + unsigned int size; + unsigned int capacity; +}; + +struct asm_parser +{ + /* The function table of the parser implementation */ + const struct asmparser_backend *funcs; + + /* Private data follows */ + struct bwriter_shader *shader; + unsigned int m3x3pad_count; + + enum parse_status status; + struct compilation_messages messages; + unsigned int line_no; +}; + +extern struct asm_parser asm_ctx DECLSPEC_HIDDEN; + +void create_vs10_parser(struct asm_parser *ret) DECLSPEC_HIDDEN; +void create_vs11_parser(struct asm_parser *ret) DECLSPEC_HIDDEN; +void create_vs20_parser(struct asm_parser *ret) DECLSPEC_HIDDEN; +void create_vs2x_parser(struct asm_parser *ret) DECLSPEC_HIDDEN; +void create_vs30_parser(struct asm_parser *ret) DECLSPEC_HIDDEN; +void create_ps10_parser(struct asm_parser *ret) DECLSPEC_HIDDEN; +void create_ps11_parser(struct asm_parser *ret) DECLSPEC_HIDDEN; +void create_ps12_parser(struct asm_parser *ret) DECLSPEC_HIDDEN; +void create_ps13_parser(struct asm_parser *ret) DECLSPEC_HIDDEN; +void create_ps14_parser(struct asm_parser *ret) DECLSPEC_HIDDEN; +void create_ps20_parser(struct asm_parser *ret) DECLSPEC_HIDDEN; +void create_ps2x_parser(struct asm_parser *ret) DECLSPEC_HIDDEN; +void create_ps30_parser(struct asm_parser *ret) DECLSPEC_HIDDEN; + +struct bwriter_shader *parse_asm_shader(char **messages) DECLSPEC_HIDDEN; + +#ifdef __GNUC__ +#define PRINTF_ATTR(fmt,args) __attribute__((format (printf,fmt,args))) +#else +#define PRINTF_ATTR(fmt,args) +#endif + +void compilation_message(struct compilation_messages *msg, const char *fmt, va_list args) DECLSPEC_HIDDEN; +void asmparser_message(struct asm_parser *ctx, const char *fmt, ...) PRINTF_ATTR(2,3) DECLSPEC_HIDDEN; +static inline void set_parse_status(enum parse_status *current, enum parse_status update) +{ + if (update == PARSE_ERR) + *current = PARSE_ERR; + else if (update == PARSE_WARN && *current == PARSE_SUCCESS) + *current = PARSE_WARN; +} + +/* A reasonable value as initial size */ +#define BYTECODEBUFFER_INITIAL_SIZE 32 +struct bytecode_buffer { + DWORD *data; + DWORD size; + DWORD alloc_size; + /* For tracking rare out of memory situations without passing + * return values around everywhere + */ + HRESULT state; +}; + +struct bc_writer; /* Predeclaration for use in vtable parameters */ + +typedef void (*instr_writer)(struct bc_writer *This, + const struct instruction *instr, + struct bytecode_buffer *buffer); + +struct bytecode_backend { + void (*header)(struct bc_writer *This, const struct bwriter_shader *shader, + struct bytecode_buffer *buffer); + void (*end)(struct bc_writer *This, const struct bwriter_shader *shader, + struct bytecode_buffer *buffer); + void (*srcreg)(struct bc_writer *This, const struct shader_reg *reg, + struct bytecode_buffer *buffer); + void (*dstreg)(struct bc_writer *This, const struct shader_reg *reg, + struct bytecode_buffer *buffer, DWORD shift, DWORD mod); + void (*opcode)(struct bc_writer *This, const struct instruction *instr, + DWORD token, struct bytecode_buffer *buffer); + + const struct instr_handler_table { + DWORD opcode; + instr_writer func; + } *instructions; +}; + +/* Bytecode writing stuff */ +struct bc_writer { + const struct bytecode_backend *funcs; + + /* Avoid result checking */ + HRESULT state; + + DWORD version; + + /* Vertex shader varying mapping */ + DWORD oPos_regnum; + DWORD oD_regnum[2]; + DWORD oT_regnum[8]; + DWORD oFog_regnum; + DWORD oFog_mask; + DWORD oPts_regnum; + DWORD oPts_mask; + + /* Pixel shader specific members */ + DWORD t_regnum[8]; + DWORD v_regnum[2]; +}; + +/* Debug utility routines */ +const char *debug_print_srcmod(DWORD mod) DECLSPEC_HIDDEN; +const char *debug_print_dstmod(DWORD mod) DECLSPEC_HIDDEN; +const char *debug_print_shift(DWORD shift) DECLSPEC_HIDDEN; +const char *debug_print_dstreg(const struct shader_reg *reg) DECLSPEC_HIDDEN; +const char *debug_print_srcreg(const struct shader_reg *reg) DECLSPEC_HIDDEN; +const char *debug_print_comp(DWORD comp) DECLSPEC_HIDDEN; +const char *debug_print_opcode(DWORD opcode) DECLSPEC_HIDDEN; + +/* Used to signal an incorrect swizzle/writemask */ +#define SWIZZLE_ERR ~0U + +/* + Enumerations and defines used in the bytecode writer + intermediate representation +*/ +typedef enum _BWRITERSHADER_INSTRUCTION_OPCODE_TYPE { + BWRITERSIO_NOP, + BWRITERSIO_MOV, + BWRITERSIO_ADD, + BWRITERSIO_SUB, + BWRITERSIO_MAD, + BWRITERSIO_MUL, + BWRITERSIO_RCP, + BWRITERSIO_RSQ, + BWRITERSIO_DP3, + BWRITERSIO_DP4, + BWRITERSIO_MIN, + BWRITERSIO_MAX, + BWRITERSIO_SLT, + BWRITERSIO_SGE, + BWRITERSIO_EXP, + BWRITERSIO_LOG, + BWRITERSIO_LIT, + BWRITERSIO_DST, + BWRITERSIO_LRP, + BWRITERSIO_FRC, + BWRITERSIO_M4x4, + BWRITERSIO_M4x3, + BWRITERSIO_M3x4, + BWRITERSIO_M3x3, + BWRITERSIO_M3x2, + BWRITERSIO_CALL, + BWRITERSIO_CALLNZ, + BWRITERSIO_LOOP, + BWRITERSIO_RET, + BWRITERSIO_ENDLOOP, + BWRITERSIO_LABEL, + BWRITERSIO_DCL, + BWRITERSIO_POW, + BWRITERSIO_CRS, + BWRITERSIO_SGN, + BWRITERSIO_ABS, + BWRITERSIO_NRM, + BWRITERSIO_SINCOS, + BWRITERSIO_REP, + BWRITERSIO_ENDREP, + BWRITERSIO_IF, + BWRITERSIO_IFC, + BWRITERSIO_ELSE, + BWRITERSIO_ENDIF, + BWRITERSIO_BREAK, + BWRITERSIO_BREAKC, + BWRITERSIO_MOVA, + BWRITERSIO_DEFB, + BWRITERSIO_DEFI, + + BWRITERSIO_TEXCOORD, + BWRITERSIO_TEXKILL, + BWRITERSIO_TEX, + BWRITERSIO_TEXBEM, + BWRITERSIO_TEXBEML, + BWRITERSIO_TEXREG2AR, + BWRITERSIO_TEXREG2GB, + BWRITERSIO_TEXM3x2PAD, + BWRITERSIO_TEXM3x2TEX, + BWRITERSIO_TEXM3x3PAD, + BWRITERSIO_TEXM3x3TEX, + BWRITERSIO_TEXM3x3SPEC, + BWRITERSIO_TEXM3x3VSPEC, + BWRITERSIO_EXPP, + BWRITERSIO_LOGP, + BWRITERSIO_CND, + BWRITERSIO_DEF, + BWRITERSIO_TEXREG2RGB, + BWRITERSIO_TEXDP3TEX, + BWRITERSIO_TEXM3x2DEPTH, + BWRITERSIO_TEXDP3, + BWRITERSIO_TEXM3x3, + BWRITERSIO_TEXDEPTH, + BWRITERSIO_CMP, + BWRITERSIO_BEM, + BWRITERSIO_DP2ADD, + BWRITERSIO_DSX, + BWRITERSIO_DSY, + BWRITERSIO_TEXLDD, + BWRITERSIO_SETP, + BWRITERSIO_TEXLDL, + BWRITERSIO_BREAKP, + BWRITERSIO_TEXLDP, + BWRITERSIO_TEXLDB, + + BWRITERSIO_PHASE, + BWRITERSIO_COMMENT, + BWRITERSIO_END, +} BWRITERSHADER_INSTRUCTION_OPCODE_TYPE; + +typedef enum _BWRITERSHADER_PARAM_REGISTER_TYPE { + BWRITERSPR_TEMP, + BWRITERSPR_INPUT, + BWRITERSPR_CONST, + BWRITERSPR_ADDR, + BWRITERSPR_TEXTURE, + BWRITERSPR_RASTOUT, + BWRITERSPR_ATTROUT, + BWRITERSPR_TEXCRDOUT, + BWRITERSPR_OUTPUT, + BWRITERSPR_CONSTINT, + BWRITERSPR_COLOROUT, + BWRITERSPR_DEPTHOUT, + BWRITERSPR_SAMPLER, + BWRITERSPR_CONSTBOOL, + BWRITERSPR_LOOP, + BWRITERSPR_MISCTYPE, + BWRITERSPR_LABEL, + BWRITERSPR_PREDICATE +} BWRITERSHADER_PARAM_REGISTER_TYPE; + +typedef enum _BWRITERVS_RASTOUT_OFFSETS +{ + BWRITERSRO_POSITION, + BWRITERSRO_FOG, + BWRITERSRO_POINT_SIZE +} BWRITERVS_RASTOUT_OFFSETS; + +#define BWRITERSP_WRITEMASK_0 0x1 /* .x r */ +#define BWRITERSP_WRITEMASK_1 0x2 /* .y g */ +#define BWRITERSP_WRITEMASK_2 0x4 /* .z b */ +#define BWRITERSP_WRITEMASK_3 0x8 /* .w a */ +#define BWRITERSP_WRITEMASK_ALL 0xf /* all */ + +typedef enum _BWRITERSHADER_PARAM_DSTMOD_TYPE { + BWRITERSPDM_NONE = 0, + BWRITERSPDM_SATURATE = 1, + BWRITERSPDM_PARTIALPRECISION = 2, + BWRITERSPDM_MSAMPCENTROID = 4, +} BWRITERSHADER_PARAM_DSTMOD_TYPE; + +typedef enum _BWRITERSAMPLER_TEXTURE_TYPE { + BWRITERSTT_UNKNOWN = 0, + BWRITERSTT_1D = 1, + BWRITERSTT_2D = 2, + BWRITERSTT_CUBE = 3, + BWRITERSTT_VOLUME = 4, +} BWRITERSAMPLER_TEXTURE_TYPE; + +#define BWRITERSI_TEXLD_PROJECT 1 +#define BWRITERSI_TEXLD_BIAS 2 + +typedef enum _BWRITERSHADER_PARAM_SRCMOD_TYPE { + BWRITERSPSM_NONE = 0, + BWRITERSPSM_NEG, + BWRITERSPSM_BIAS, + BWRITERSPSM_BIASNEG, + BWRITERSPSM_SIGN, + BWRITERSPSM_SIGNNEG, + BWRITERSPSM_COMP, + BWRITERSPSM_X2, + BWRITERSPSM_X2NEG, + BWRITERSPSM_DZ, + BWRITERSPSM_DW, + BWRITERSPSM_ABS, + BWRITERSPSM_ABSNEG, + BWRITERSPSM_NOT, +} BWRITERSHADER_PARAM_SRCMOD_TYPE; + +#define BWRITER_SM1_VS 0xfffe +#define BWRITER_SM1_PS 0xffff + +#define BWRITERPS_VERSION(major, minor) ((BWRITER_SM1_PS << 16) | ((major) << 8) | (minor)) +#define BWRITERVS_VERSION(major, minor) ((BWRITER_SM1_VS << 16) | ((major) << 8) | (minor)) + +#define BWRITERVS_SWIZZLE_SHIFT 16 +#define BWRITERVS_SWIZZLE_MASK (0xFF << BWRITERVS_SWIZZLE_SHIFT) + +#define BWRITERVS_X_X (0 << BWRITERVS_SWIZZLE_SHIFT) +#define BWRITERVS_X_Y (1 << BWRITERVS_SWIZZLE_SHIFT) +#define BWRITERVS_X_Z (2 << BWRITERVS_SWIZZLE_SHIFT) +#define BWRITERVS_X_W (3 << BWRITERVS_SWIZZLE_SHIFT) + +#define BWRITERVS_Y_X (0 << (BWRITERVS_SWIZZLE_SHIFT + 2)) +#define BWRITERVS_Y_Y (1 << (BWRITERVS_SWIZZLE_SHIFT + 2)) +#define BWRITERVS_Y_Z (2 << (BWRITERVS_SWIZZLE_SHIFT + 2)) +#define BWRITERVS_Y_W (3 << (BWRITERVS_SWIZZLE_SHIFT + 2)) + +#define BWRITERVS_Z_X (0 << (BWRITERVS_SWIZZLE_SHIFT + 4)) +#define BWRITERVS_Z_Y (1 << (BWRITERVS_SWIZZLE_SHIFT + 4)) +#define BWRITERVS_Z_Z (2 << (BWRITERVS_SWIZZLE_SHIFT + 4)) +#define BWRITERVS_Z_W (3 << (BWRITERVS_SWIZZLE_SHIFT + 4)) + +#define BWRITERVS_W_X (0 << (BWRITERVS_SWIZZLE_SHIFT + 6)) +#define BWRITERVS_W_Y (1 << (BWRITERVS_SWIZZLE_SHIFT + 6)) +#define BWRITERVS_W_Z (2 << (BWRITERVS_SWIZZLE_SHIFT + 6)) +#define BWRITERVS_W_W (3 << (BWRITERVS_SWIZZLE_SHIFT + 6)) + +#define BWRITERVS_NOSWIZZLE (BWRITERVS_X_X | BWRITERVS_Y_Y | BWRITERVS_Z_Z | BWRITERVS_W_W) + +#define BWRITERVS_SWIZZLE_X (BWRITERVS_X_X | BWRITERVS_Y_X | BWRITERVS_Z_X | BWRITERVS_W_X) +#define BWRITERVS_SWIZZLE_Y (BWRITERVS_X_Y | BWRITERVS_Y_Y | BWRITERVS_Z_Y | BWRITERVS_W_Y) +#define BWRITERVS_SWIZZLE_Z (BWRITERVS_X_Z | BWRITERVS_Y_Z | BWRITERVS_Z_Z | BWRITERVS_W_Z) +#define BWRITERVS_SWIZZLE_W (BWRITERVS_X_W | BWRITERVS_Y_W | BWRITERVS_Z_W | BWRITERVS_W_W) + +typedef enum _BWRITERDECLUSAGE { + BWRITERDECLUSAGE_POSITION, + BWRITERDECLUSAGE_BLENDWEIGHT, + BWRITERDECLUSAGE_BLENDINDICES, + BWRITERDECLUSAGE_NORMAL, + BWRITERDECLUSAGE_PSIZE, + BWRITERDECLUSAGE_TEXCOORD, + BWRITERDECLUSAGE_TANGENT, + BWRITERDECLUSAGE_BINORMAL, + BWRITERDECLUSAGE_TESSFACTOR, + BWRITERDECLUSAGE_POSITIONT, + BWRITERDECLUSAGE_COLOR, + BWRITERDECLUSAGE_FOG, + BWRITERDECLUSAGE_DEPTH, + BWRITERDECLUSAGE_SAMPLE +} BWRITERDECLUSAGE; + +/* ps 1.x texture registers mappings */ +#define T0_REG 2 +#define T1_REG 3 +#define T2_REG 4 +#define T3_REG 5 + +struct bwriter_shader *SlAssembleShader(const char *text, char **messages) DECLSPEC_HIDDEN; +HRESULT SlWriteBytecode(const struct bwriter_shader *shader, int dxversion, DWORD **result, DWORD *size) DECLSPEC_HIDDEN; +void SlDeleteShader(struct bwriter_shader *shader) DECLSPEC_HIDDEN; + +/* The general IR structure is inspired by Mesa GLSL hir, even though the code + * ends up being quite different in practice. Anyway, here comes the relevant + * licensing information. + * + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +enum hlsl_type_class +{ + HLSL_CLASS_SCALAR, + HLSL_CLASS_VECTOR, + HLSL_CLASS_MATRIX, + HLSL_CLASS_LAST_NUMERIC = HLSL_CLASS_MATRIX, + HLSL_CLASS_STRUCT, + HLSL_CLASS_ARRAY, + HLSL_CLASS_OBJECT, +}; + +enum hlsl_base_type +{ + HLSL_TYPE_FLOAT, + HLSL_TYPE_HALF, + HLSL_TYPE_DOUBLE, + HLSL_TYPE_INT, + HLSL_TYPE_UINT, + HLSL_TYPE_BOOL, + HLSL_TYPE_LAST_SCALAR = HLSL_TYPE_BOOL, + HLSL_TYPE_SAMPLER, + HLSL_TYPE_TEXTURE, + HLSL_TYPE_PIXELSHADER, + HLSL_TYPE_VERTEXSHADER, + HLSL_TYPE_STRING, + HLSL_TYPE_VOID, +}; + +enum hlsl_sampler_dim +{ + HLSL_SAMPLER_DIM_GENERIC, + HLSL_SAMPLER_DIM_1D, + HLSL_SAMPLER_DIM_2D, + HLSL_SAMPLER_DIM_3D, + HLSL_SAMPLER_DIM_CUBE, +}; + +enum hlsl_matrix_majority +{ + HLSL_COLUMN_MAJOR, + HLSL_ROW_MAJOR +}; + +struct hlsl_type +{ + struct list entry; + struct wine_rb_entry scope_entry; + enum hlsl_type_class type; + enum hlsl_base_type base_type; + enum hlsl_sampler_dim sampler_dim; + const char *name; + unsigned int modifiers; + unsigned int dimx; + unsigned int dimy; + union + { + struct list *elements; + struct + { + struct hlsl_type *type; + unsigned int elements_count; + } array; + } e; +}; + +struct hlsl_struct_field +{ + struct list entry; + struct hlsl_type *type; + const char *name; + const char *semantic; + DWORD modifiers; +}; + +struct source_location +{ + const char *file; + unsigned int line; + unsigned int col; +}; + +enum hlsl_ir_node_type +{ + HLSL_IR_VAR = 0, + HLSL_IR_ASSIGNMENT, + HLSL_IR_CONSTANT, + HLSL_IR_CONSTRUCTOR, + HLSL_IR_DEREF, + HLSL_IR_EXPR, + HLSL_IR_FUNCTION_DECL, + HLSL_IR_IF, + HLSL_IR_LOOP, + HLSL_IR_JUMP, + HLSL_IR_SWIZZLE, +}; + +struct hlsl_ir_node +{ + struct list entry; + enum hlsl_ir_node_type type; + struct hlsl_type *data_type; + + struct source_location loc; +}; + +#define HLSL_STORAGE_EXTERN 0x00000001 +#define HLSL_STORAGE_NOINTERPOLATION 0x00000002 +#define HLSL_MODIFIER_PRECISE 0x00000004 +#define HLSL_STORAGE_SHARED 0x00000008 +#define HLSL_STORAGE_GROUPSHARED 0x00000010 +#define HLSL_STORAGE_STATIC 0x00000020 +#define HLSL_STORAGE_UNIFORM 0x00000040 +#define HLSL_STORAGE_VOLATILE 0x00000080 +#define HLSL_MODIFIER_CONST 0x00000100 +#define HLSL_MODIFIER_ROW_MAJOR 0x00000200 +#define HLSL_MODIFIER_COLUMN_MAJOR 0x00000400 +#define HLSL_MODIFIER_IN 0x00000800 +#define HLSL_MODIFIER_OUT 0x00001000 + +#define HLSL_TYPE_MODIFIERS_MASK (HLSL_MODIFIER_PRECISE | HLSL_STORAGE_VOLATILE | \ + HLSL_MODIFIER_CONST | HLSL_MODIFIER_ROW_MAJOR | \ + HLSL_MODIFIER_COLUMN_MAJOR) + +#define HLSL_MODIFIERS_COMPARISON_MASK (HLSL_MODIFIER_ROW_MAJOR | HLSL_MODIFIER_COLUMN_MAJOR) + +struct hlsl_ir_var +{ + struct hlsl_ir_node node; + const char *name; + const char *semantic; + unsigned int modifiers; + struct list scope_entry; + + struct hlsl_var_allocation *allocation; +}; + +struct hlsl_ir_function +{ + struct wine_rb_entry entry; + const char *name; + struct wine_rb_tree overloads; + BOOL intrinsic; +}; + +struct hlsl_ir_function_decl +{ + struct hlsl_ir_node node; + struct wine_rb_entry entry; + struct hlsl_ir_function *func; + const char *semantic; + struct list *parameters; + struct list *body; +}; + +struct hlsl_ir_if +{ + struct hlsl_ir_node node; + struct hlsl_ir_node *condition; + struct list *then_instrs; + struct list *else_instrs; +}; + +struct hlsl_ir_loop +{ + struct hlsl_ir_node node; + /* loop condition is stored in the body (as "if (!condition) break;") */ + struct list *body; +}; + +struct hlsl_ir_assignment +{ + struct hlsl_ir_node node; + struct hlsl_ir_node *lhs; + struct hlsl_ir_node *rhs; + unsigned char writemask; +}; + +enum hlsl_ir_expr_op { + HLSL_IR_UNOP_BIT_NOT = 0, + HLSL_IR_UNOP_LOGIC_NOT, + HLSL_IR_UNOP_NEG, + HLSL_IR_UNOP_ABS, + HLSL_IR_UNOP_SIGN, + HLSL_IR_UNOP_RCP, + HLSL_IR_UNOP_RSQ, + HLSL_IR_UNOP_SQRT, + HLSL_IR_UNOP_NRM, + HLSL_IR_UNOP_EXP2, + HLSL_IR_UNOP_LOG2, + + HLSL_IR_UNOP_CAST, + + HLSL_IR_UNOP_FRACT, + + HLSL_IR_UNOP_SIN, + HLSL_IR_UNOP_COS, + HLSL_IR_UNOP_SIN_REDUCED, /* Reduced range [-pi, pi] */ + HLSL_IR_UNOP_COS_REDUCED, /* Reduced range [-pi, pi] */ + + HLSL_IR_UNOP_DSX, + HLSL_IR_UNOP_DSY, + + HLSL_IR_UNOP_SAT, + + HLSL_IR_BINOP_ADD, + HLSL_IR_BINOP_SUB, + HLSL_IR_BINOP_MUL, + HLSL_IR_BINOP_DIV, + + HLSL_IR_BINOP_MOD, + + HLSL_IR_BINOP_LESS, + HLSL_IR_BINOP_GREATER, + HLSL_IR_BINOP_LEQUAL, + HLSL_IR_BINOP_GEQUAL, + HLSL_IR_BINOP_EQUAL, + HLSL_IR_BINOP_NEQUAL, + + HLSL_IR_BINOP_LOGIC_AND, + HLSL_IR_BINOP_LOGIC_OR, + + HLSL_IR_BINOP_LSHIFT, + HLSL_IR_BINOP_RSHIFT, + HLSL_IR_BINOP_BIT_AND, + HLSL_IR_BINOP_BIT_OR, + HLSL_IR_BINOP_BIT_XOR, + + HLSL_IR_BINOP_DOT, + HLSL_IR_BINOP_CRS, + HLSL_IR_BINOP_MIN, + HLSL_IR_BINOP_MAX, + + HLSL_IR_BINOP_POW, + + HLSL_IR_BINOP_PREINC, + HLSL_IR_BINOP_PREDEC, + HLSL_IR_BINOP_POSTINC, + HLSL_IR_BINOP_POSTDEC, + + HLSL_IR_TEROP_LERP, + + HLSL_IR_SEQUENCE, +}; + +struct hlsl_ir_expr +{ + struct hlsl_ir_node node; + enum hlsl_ir_expr_op op; + struct hlsl_ir_node *operands[3]; + struct list *subexpressions; +}; + +enum hlsl_ir_jump_type +{ + HLSL_IR_JUMP_BREAK, + HLSL_IR_JUMP_CONTINUE, + HLSL_IR_JUMP_DISCARD, + HLSL_IR_JUMP_RETURN, +}; + +struct hlsl_ir_jump +{ + struct hlsl_ir_node node; + enum hlsl_ir_jump_type type; + struct hlsl_ir_node *return_value; +}; + +struct hlsl_ir_swizzle +{ + struct hlsl_ir_node node; + struct hlsl_ir_node *val; + DWORD swizzle; +}; + +enum hlsl_ir_deref_type +{ + HLSL_IR_DEREF_VAR, + HLSL_IR_DEREF_ARRAY, + HLSL_IR_DEREF_RECORD, +}; + +struct hlsl_ir_deref +{ + struct hlsl_ir_node node; + enum hlsl_ir_deref_type type; + union + { + struct hlsl_ir_var *var; + struct + { + struct hlsl_ir_node *array; + struct hlsl_ir_node *index; + } array; + struct + { + struct hlsl_ir_node *record; + struct hlsl_struct_field *field; + } record; + } v; +}; + +struct hlsl_ir_constant +{ + struct hlsl_ir_node node; + union + { + union + { + unsigned u[16]; + int i[16]; + float f[16]; + double d[16]; + BOOL b[16]; + } value; + struct hlsl_ir_constant *array_elements; + struct list *struct_elements; + } v; +}; + +struct hlsl_ir_constructor +{ + struct hlsl_ir_node node; + struct list *arguments; +}; + +struct hlsl_scope +{ + struct list entry; + struct list vars; + struct wine_rb_tree types; + struct hlsl_scope *upper; +}; + +/* Structures used only during parsing */ +struct parse_parameter +{ + struct hlsl_type *type; + const char *name; + const char *semantic; + unsigned int modifiers; +}; + +struct parse_variable_def +{ + struct list entry; + struct source_location loc; + + char *name; + unsigned int array_size; + char *semantic; + struct list *initializer; +}; + +struct parse_function +{ + char *name; + struct hlsl_ir_function_decl *decl; +}; + +struct parse_if_body +{ + struct list *then_instrs; + struct list *else_instrs; +}; + +enum parse_unary_op +{ + UNARY_OP_PLUS, + UNARY_OP_MINUS, + UNARY_OP_LOGICNOT, + UNARY_OP_BITNOT, +}; + +enum parse_assign_op +{ + ASSIGN_OP_ASSIGN, + ASSIGN_OP_ADD, + ASSIGN_OP_SUB, + ASSIGN_OP_MUL, + ASSIGN_OP_DIV, + ASSIGN_OP_MOD, + ASSIGN_OP_LSHIFT, + ASSIGN_OP_RSHIFT, + ASSIGN_OP_AND, + ASSIGN_OP_OR, + ASSIGN_OP_XOR, +}; + +struct hlsl_parse_ctx +{ + const char **source_files; + unsigned int source_files_count; + const char *source_file; + unsigned int line_no; + unsigned int column; + enum parse_status status; + struct compilation_messages messages; + + struct hlsl_scope *cur_scope; + struct hlsl_scope *globals; + struct list scopes; + + struct list types; + struct wine_rb_tree functions; + + enum hlsl_matrix_majority matrix_majority; +}; + +extern struct hlsl_parse_ctx hlsl_ctx DECLSPEC_HIDDEN; + +enum hlsl_error_level +{ + HLSL_LEVEL_ERROR = 0, + HLSL_LEVEL_WARNING, + HLSL_LEVEL_NOTE, +}; + +void hlsl_message(const char *fmt, ...) PRINTF_ATTR(1,2) DECLSPEC_HIDDEN; +void hlsl_report_message(const char *filename, DWORD line, DWORD column, + enum hlsl_error_level level, const char *fmt, ...) PRINTF_ATTR(5,6) DECLSPEC_HIDDEN; + +static inline struct hlsl_ir_var *var_from_node(const struct hlsl_ir_node *node) +{ + assert(node->type == HLSL_IR_VAR); + return CONTAINING_RECORD(node, struct hlsl_ir_var, node); +} + +static inline struct hlsl_ir_expr *expr_from_node(const struct hlsl_ir_node *node) +{ + assert(node->type == HLSL_IR_EXPR); + return CONTAINING_RECORD(node, struct hlsl_ir_expr, node); +} + +static inline struct hlsl_ir_deref *deref_from_node(const struct hlsl_ir_node *node) +{ + assert(node->type == HLSL_IR_DEREF); + return CONTAINING_RECORD(node, struct hlsl_ir_deref, node); +} + +static inline struct hlsl_ir_constant *constant_from_node(const struct hlsl_ir_node *node) +{ + assert(node->type == HLSL_IR_CONSTANT); + return CONTAINING_RECORD(node, struct hlsl_ir_constant, node); +} + +static inline struct hlsl_ir_jump *jump_from_node(const struct hlsl_ir_node *node) +{ + assert(node->type == HLSL_IR_JUMP); + return CONTAINING_RECORD(node, struct hlsl_ir_jump, node); +} + +static inline struct hlsl_ir_assignment *assignment_from_node(const struct hlsl_ir_node *node) +{ + assert(node->type == HLSL_IR_ASSIGNMENT); + return CONTAINING_RECORD(node, struct hlsl_ir_assignment, node); +} + +static inline struct hlsl_ir_swizzle *swizzle_from_node(const struct hlsl_ir_node *node) +{ + assert(node->type == HLSL_IR_SWIZZLE); + return CONTAINING_RECORD(node, struct hlsl_ir_swizzle, node); +} + +static inline struct hlsl_ir_constructor *constructor_from_node(const struct hlsl_ir_node *node) +{ + assert(node->type == HLSL_IR_CONSTRUCTOR); + return CONTAINING_RECORD(node, struct hlsl_ir_constructor, node); +} + +static inline struct hlsl_ir_if *if_from_node(const struct hlsl_ir_node *node) +{ + assert(node->type == HLSL_IR_IF); + return CONTAINING_RECORD(node, struct hlsl_ir_if, node); +} + +static inline struct hlsl_ir_loop *loop_from_node(const struct hlsl_ir_node *node) +{ + assert(node->type == HLSL_IR_LOOP); + return CONTAINING_RECORD(node, struct hlsl_ir_loop, node); +} + +BOOL add_declaration(struct hlsl_scope *scope, struct hlsl_ir_var *decl, BOOL local_var) DECLSPEC_HIDDEN; +struct hlsl_ir_var *get_variable(struct hlsl_scope *scope, const char *name) DECLSPEC_HIDDEN; +void free_declaration(struct hlsl_ir_var *decl) DECLSPEC_HIDDEN; +BOOL add_func_parameter(struct list *list, struct parse_parameter *param, + const struct source_location *loc) DECLSPEC_HIDDEN; +struct hlsl_type *new_hlsl_type(const char *name, enum hlsl_type_class type_class, + enum hlsl_base_type base_type, unsigned dimx, unsigned dimy) DECLSPEC_HIDDEN; +struct hlsl_type *new_array_type(struct hlsl_type *basic_type, unsigned int array_size) DECLSPEC_HIDDEN; +struct hlsl_type *clone_hlsl_type(struct hlsl_type *old) DECLSPEC_HIDDEN; +struct hlsl_type *get_type(struct hlsl_scope *scope, const char *name, BOOL recursive) DECLSPEC_HIDDEN; +BOOL find_function(const char *name) DECLSPEC_HIDDEN; +unsigned int components_count_type(struct hlsl_type *type) DECLSPEC_HIDDEN; +BOOL compare_hlsl_types(const struct hlsl_type *t1, const struct hlsl_type *t2) DECLSPEC_HIDDEN; +BOOL compatible_data_types(struct hlsl_type *s1, struct hlsl_type *s2) DECLSPEC_HIDDEN; +struct hlsl_ir_expr *new_expr(enum hlsl_ir_expr_op op, struct hlsl_ir_node **operands, + struct source_location *loc) DECLSPEC_HIDDEN; +struct hlsl_ir_expr *new_cast(struct hlsl_ir_node *node, struct hlsl_type *type, + struct source_location *loc) DECLSPEC_HIDDEN; +struct hlsl_ir_expr *hlsl_mul(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2, + struct source_location *loc) DECLSPEC_HIDDEN; +struct hlsl_ir_expr *hlsl_div(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2, + struct source_location *loc) DECLSPEC_HIDDEN; +struct hlsl_ir_expr *hlsl_mod(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2, + struct source_location *loc) DECLSPEC_HIDDEN; +struct hlsl_ir_expr *hlsl_add(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2, + struct source_location *loc) DECLSPEC_HIDDEN; +struct hlsl_ir_expr *hlsl_sub(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2, + struct source_location *loc) DECLSPEC_HIDDEN; +struct hlsl_ir_expr *hlsl_lt(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2, + struct source_location *loc) DECLSPEC_HIDDEN; +struct hlsl_ir_expr *hlsl_gt(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2, + struct source_location *loc) DECLSPEC_HIDDEN; +struct hlsl_ir_expr *hlsl_le(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2, + struct source_location *loc) DECLSPEC_HIDDEN; +struct hlsl_ir_expr *hlsl_ge(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2, + struct source_location *loc) DECLSPEC_HIDDEN; +struct hlsl_ir_expr *hlsl_eq(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2, + struct source_location *loc) DECLSPEC_HIDDEN; +struct hlsl_ir_expr *hlsl_ne(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2, + struct source_location *loc) DECLSPEC_HIDDEN; +struct hlsl_ir_deref *new_var_deref(struct hlsl_ir_var *var) DECLSPEC_HIDDEN; +struct hlsl_ir_deref *new_record_deref(struct hlsl_ir_node *record, struct hlsl_struct_field *field) DECLSPEC_HIDDEN; +struct hlsl_ir_node *make_assignment(struct hlsl_ir_node *left, enum parse_assign_op assign_op, + DWORD writemask, struct hlsl_ir_node *right) DECLSPEC_HIDDEN; +void push_scope(struct hlsl_parse_ctx *ctx) DECLSPEC_HIDDEN; +BOOL pop_scope(struct hlsl_parse_ctx *ctx) DECLSPEC_HIDDEN; +struct hlsl_ir_function_decl *new_func_decl(struct hlsl_type *return_type, struct list *parameters) DECLSPEC_HIDDEN; +void init_functions_tree(struct wine_rb_tree *funcs) DECLSPEC_HIDDEN; +void add_function_decl(struct wine_rb_tree *funcs, char *name, struct hlsl_ir_function_decl *decl, + BOOL intrinsic) DECLSPEC_HIDDEN; +struct bwriter_shader *parse_hlsl_shader(const char *text, enum shader_type type, DWORD major, DWORD minor, + const char *entrypoint, char **messages) DECLSPEC_HIDDEN; + +const char *debug_hlsl_type(const struct hlsl_type *type) DECLSPEC_HIDDEN; +const char *debug_modifiers(DWORD modifiers) DECLSPEC_HIDDEN; +void debug_dump_ir_function_decl(const struct hlsl_ir_function_decl *func) DECLSPEC_HIDDEN; + +void free_hlsl_type(struct hlsl_type *type) DECLSPEC_HIDDEN; +void free_instr(struct hlsl_ir_node *node) DECLSPEC_HIDDEN; +void free_instr_list(struct list *list) DECLSPEC_HIDDEN; +void free_function_rb(struct wine_rb_entry *entry, void *context) DECLSPEC_HIDDEN; + + +#define MAKE_TAG(ch0, ch1, ch2, ch3) \ + ((DWORD)(ch0) | ((DWORD)(ch1) << 8) | \ + ((DWORD)(ch2) << 16) | ((DWORD)(ch3) << 24 )) +#define TAG_Aon9 MAKE_TAG('A', 'o', 'n', '9') +#define TAG_DXBC MAKE_TAG('D', 'X', 'B', 'C') +#define TAG_ISGN MAKE_TAG('I', 'S', 'G', 'N') +#define TAG_OSGN MAKE_TAG('O', 'S', 'G', 'N') +#define TAG_OSG5 MAKE_TAG('O', 'S', 'G', '5') +#define TAG_PCSG MAKE_TAG('P', 'C', 'S', 'G') +#define TAG_RDEF MAKE_TAG('R', 'D', 'E', 'F') +#define TAG_SDBG MAKE_TAG('S', 'D', 'B', 'G') +#define TAG_SHDR MAKE_TAG('S', 'H', 'D', 'R') +#define TAG_SHEX MAKE_TAG('S', 'H', 'E', 'X') +#define TAG_STAT MAKE_TAG('S', 'T', 'A', 'T') +#define TAG_XNAP MAKE_TAG('X', 'N', 'A', 'P') +#define TAG_XNAS MAKE_TAG('X', 'N', 'A', 'S') + +struct dxbc_section +{ + DWORD tag; + const char *data; + DWORD data_size; +}; + +struct dxbc +{ + UINT size; + UINT count; + struct dxbc_section *sections; +}; + +HRESULT dxbc_write_blob(struct dxbc *dxbc, ID3DBlob **blob) DECLSPEC_HIDDEN; +void dxbc_destroy(struct dxbc *dxbc) DECLSPEC_HIDDEN; +HRESULT dxbc_parse(const char *data, SIZE_T data_size, struct dxbc *dxbc) DECLSPEC_HIDDEN; +HRESULT dxbc_add_section(struct dxbc *dxbc, DWORD tag, const char *data, DWORD data_size) DECLSPEC_HIDDEN; +HRESULT dxbc_init(struct dxbc *dxbc, DWORD count) DECLSPEC_HIDDEN; + +static inline void read_dword(const char **ptr, DWORD *d) +{ + memcpy(d, *ptr, sizeof(*d)); + *ptr += sizeof(*d); +} + +static inline void write_dword(char **ptr, DWORD d) +{ + memcpy(*ptr, &d, sizeof(d)); + *ptr += sizeof(d); +} + +void skip_dword_unknown(const char **ptr, unsigned int count) DECLSPEC_HIDDEN; + +#endif /* __WINE_D3DCOMPILER_PRIVATE_H */ diff --git a/reactos/dll/directx/wine/d3dcompiler_43/hlsl.l b/reactos/dll/directx/wine/d3dcompiler_43/hlsl.l new file mode 100644 index 00000000000..f40e3c9a049 --- /dev/null +++ b/reactos/dll/directx/wine/d3dcompiler_43/hlsl.l @@ -0,0 +1,294 @@ +/* + * 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); + +#define YY_USER_ACTION \ + do { \ + hlsl_lloc.first_column = hlsl_ctx.column; \ + hlsl_lloc.first_line = hlsl_ctx.line_no; \ + hlsl_ctx.column += yyleng; \ + } while(0); + +%} + +%option noyywrap nounput noinput never-interactive +%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) +DOUBLESLASHCOMMENT "//"[^\n]* +STRING \"[^\"]*\" +IDENTIFIER [A-Za-z_][A-Za-z0-9_]* + +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); + } + +BlendState {return KW_BLENDSTATE; } +break {return KW_BREAK; } +Buffer {return KW_BUFFER; } +cbuffer {return KW_CBUFFER; } +compile {return KW_COMPILE; } +const {return KW_CONST; } +continue {return KW_CONTINUE; } +DepthStencilState {return KW_DEPTHSTENCILSTATE; } +DepthStencilView {return KW_DEPTHSTENCILVIEW; } +discard {return KW_DISCARD; } +do {return KW_DO; } +double {return KW_DOUBLE; } +else {return KW_ELSE; } +extern {return KW_EXTERN; } +false {return KW_FALSE; } +for {return KW_FOR; } +GeometryShader {return KW_GEOMETRYSHADER; } +groupshared {return KW_GROUPSHARED; } +if {return KW_IF; } +in {return KW_IN; } +inline {return KW_INLINE; } +inout {return KW_INOUT; } +matrix {return KW_MATRIX; } +namespace {return KW_NAMESPACE; } +nointerpolation {return KW_NOINTERPOLATION; } +out {return KW_OUT; } +pass {return KW_PASS; } +PixelShader {return KW_PIXELSHADER; } +precise {return KW_PRECISE; } +RasterizerState {return KW_RASTERIZERSTATE; } +RenderTargetView {return KW_RENDERTARGETVIEW; } +return {return KW_RETURN; } +register {return KW_REGISTER; } +sampler {return KW_SAMPLER; } +sampler1D {return KW_SAMPLER1D; } +sampler2D {return KW_SAMPLER2D; } +sampler3D {return KW_SAMPLER3D; } +samplerCUBE {return KW_SAMPLERCUBE; } +sampler_state {return KW_SAMPLER_STATE; } +SamplerComparisonState {return KW_SAMPLERCOMPARISONSTATE;} +shared {return KW_SHARED; } +stateblock {return KW_STATEBLOCK; } +stateblock_state {return KW_STATEBLOCK_STATE; } +static {return KW_STATIC; } +string {return KW_STRING; } +struct {return KW_STRUCT; } +switch {return KW_SWITCH; } +tbuffer {return KW_TBUFFER; } +technique {return KW_TECHNIQUE; } +technique10 {return KW_TECHNIQUE10; } +texture {return KW_TEXTURE; } +texture1D {return KW_TEXTURE1D; } +Texture1DArray {return KW_TEXTURE1DARRAY; } +texture2D {return KW_TEXTURE2D; } +Texture2DArray {return KW_TEXTURE2DARRAY; } +Texture2DMS {return KW_TEXTURE2DMS; } +Texture2DMSArray {return KW_TEXTURE2DMSARRAY; } +texture3D {return KW_TEXTURE3D; } +Texture3DArray {return KW_TEXTURE3DARRAY; } +textureCUBE {return KW_TEXTURECUBE; } +true {return KW_TRUE; } +typedef {return KW_TYPEDEF; } +uniform {return KW_UNIFORM; } +vector {return KW_VECTOR; } +VertexShader {return KW_VERTEXSHADER; } +void {return KW_VOID; } +volatile {return KW_VOLATILE; } +while {return KW_WHILE; } + +\+\+ {return OP_INC; } +\-\- {return OP_DEC; } +&& {return OP_AND; } +\|\| {return OP_OR; } +== {return OP_EQ; } +\<\< {return OP_LEFTSHIFT; } +\<\<= {return OP_LEFTSHIFTASSIGN; } +\>\> {return OP_RIGHTSHIFT; } +\>\>= {return OP_RIGHTSHIFTASSIGN; } +\.\.\. {return OP_ELLIPSIS; } +\<= {return OP_LE; } +\>= {return OP_GE; } +!= {return OP_NE; } +\+= {return OP_ADDASSIGN; } +\-= {return OP_SUBASSIGN; } +\*= {return OP_MULASSIGN; } +\/= {return OP_DIVASSIGN; } +%= {return OP_MODASSIGN; } +&= {return OP_ANDASSIGN; } +\|= {return OP_ORASSIGN; } +^= {return OP_XORASSIGN; } +## {return OP_UNKNOWN1; } +#@ {return OP_UNKNOWN2; } +:: {return OP_UNKNOWN3; } +\-\> {return OP_UNKNOWN4; } + +column_major {return KW_COLUMN_MAJOR; } +row_major {return KW_ROW_MAJOR; } + +{IDENTIFIER} { + hlsl_lval.name = d3dcompiler_strdup(yytext); + if (get_variable(hlsl_ctx.cur_scope, yytext) + || find_function(yytext)) + return VAR_IDENTIFIER; + else if (get_type(hlsl_ctx.cur_scope, yytext, TRUE)) + return TYPE_IDENTIFIER; + else + return NEW_IDENTIFIER; + } + +[0-9]*\.[0-9]+([eE][+-]?[0-9]+)?[h|H|f|F]? { + hlsl_lval.floatval = atof(yytext); + return C_FLOAT; + } +[0-9]+\.([eE][+-]?[0-9]+)?[h|H|f|F]? { + hlsl_lval.floatval = atof(yytext); + return C_FLOAT; + } +[0-9]+([eE][+-]?[0-9]+)?[h|H|f|F] { + hlsl_lval.floatval = atof(yytext); + return C_FLOAT; + } +0x[0-9a-fA-F]+ { + sscanf(yytext, "0x%x", &hlsl_lval.intval); + return C_INTEGER; + } +0[0-7]+ { + sscanf(yytext, "0%o", &hlsl_lval.intval); + return C_INTEGER; + } +[0-9]+ { + hlsl_lval.intval = (atoi(yytext)); + return C_INTEGER; + } + +{DOUBLESLASHCOMMENT} {} + +{WS}+ {} +{NEWLINE} { + hlsl_ctx.line_no++; + hlsl_ctx.column = 1; + } + +^# { + BEGIN pp; + } + +pragma{WS}+ { + TRACE("Got a #pragma.\n"); + BEGIN 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; + } +pack_matrix{WS}*\({WS}*column_major{WS}*\) { + TRACE("#pragma setting column_major mode.\n"); + hlsl_ctx.matrix_majority = HLSL_COLUMN_MAJOR; + BEGIN pp_ignore; + } +{NEWLINE} { + FIXME("Unsupported preprocessor #pragma directive at line %u.\n", hlsl_ctx.line_no); + BEGIN INITIAL; + } +{ANY} {} +[0-9]+ { + TRACE("Preprocessor line info.\n"); + BEGIN pp_line; + hlsl_lval.intval = (atoi(yytext)); + return PRE_LINE; + } +{STRING} { + char *string = d3dcompiler_strdup(yytext + 1); + + BEGIN pp_ignore; + string[strlen(string) - 1] = 0; + hlsl_lval.name = string; + return STRING; + } +{WS}+ {} +{NEWLINE} { + FIXME("Malformed preprocessor line directive?\n"); + BEGIN INITIAL; + } +{NEWLINE} { + BEGIN INITIAL; + } +{ANY} {} +{NEWLINE} { + FIXME("Unexpected preprocessor directive.\n"); + BEGIN INITIAL; + } +{ANY} {} + +{ANY} { + return yytext[0]; + } + +%% + +struct bwriter_shader *parse_hlsl(enum shader_type type, DWORD major, DWORD minor, + const char *entrypoint, char **messages); + +struct bwriter_shader *parse_hlsl_shader(const char *text, enum shader_type type, DWORD major, DWORD minor, + 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, major, minor, entrypoint, messages); + + hlsl__delete_buffer(buffer); + return ret; +} diff --git a/reactos/dll/directx/wine/d3dcompiler_43/hlsl.tab.c b/reactos/dll/directx/wine/d3dcompiler_43/hlsl.tab.c new file mode 100644 index 00000000000..5f64755876d --- /dev/null +++ b/reactos/dll/directx/wine/d3dcompiler_43/hlsl.tab.c @@ -0,0 +1,5187 @@ +/* A Bison parser, made by GNU Bison 2.5. */ + +/* Bison implementation for Yacc-like parsers in C + + Copyright (C) 1984, 1989-1990, 2000-2011 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* As a special exception, you may create a larger work that contains + part or all of the Bison parser skeleton and distribute that work + under terms of your choice, so long as that work isn't itself a + parser generator using the skeleton or a modified version thereof + as a parser skeleton. Alternatively, if you modify or redistribute + the parser skeleton itself, you may (at your option) remove this + special exception, which will cause the skeleton and the resulting + Bison output files to be licensed under the GNU General Public + License without this special exception. + + This special exception was added by the Free Software Foundation in + version 2.2 of Bison. */ + +/* C LALR(1) parser skeleton written by Richard Stallman, by + simplifying the original so-called "semantic" parser. */ + +/* All symbols defined below should begin with yy or YY, to avoid + infringing on user name space. This should be done even for local + variables, as they might otherwise be expanded by user macros. + There are some unavoidable exceptions within include files to + define necessary library symbols; they are noted "INFRINGES ON + USER NAME SPACE" below. */ + +/* Identify Bison output. */ +#define YYBISON 1 + +/* Bison version. */ +#define YYBISON_VERSION "2.5" + +/* Skeleton name. */ +#define YYSKELETON_NAME "yacc.c" + +/* Pure parsers. */ +#define YYPURE 0 + +/* Push parsers. */ +#define YYPUSH 0 + +/* Pull parsers. */ +#define YYPULL 1 + +/* Using locations. */ +#define YYLSP_NEEDED 1 + +/* Substitute the variable and function names. */ +#define yyparse hlsl_parse +#define yylex hlsl_lex +#define yyerror hlsl_error +#define yylval hlsl_lval +#define yychar hlsl_char +#define yydebug hlsl_debug +#define yynerrs hlsl_nerrs +#define yylloc hlsl_lloc + +/* Copy the first part of user declarations. */ + +/* Line 268 of yacc.c */ +#line 21 "hlsl.y" + +#include "config.h" +#include "wine/debug.h" + +#include + +#include "d3dcompiler_private.h" + +WINE_DEFAULT_DEBUG_CHANNEL(hlsl_parser); + +int hlsl_lex(void); + +struct hlsl_parse_ctx hlsl_ctx; + +struct YYLTYPE; +static void set_location(struct source_location *loc, const struct YYLTYPE *l); + +void hlsl_message(const char *fmt, ...) +{ + va_list args; + + va_start(args, fmt); + compilation_message(&hlsl_ctx.messages, fmt, args); + va_end(args); +} + +static const char *hlsl_get_error_level_name(enum hlsl_error_level level) +{ + const char *names[] = + { + "error", + "warning", + "note", + }; + return names[level]; +} + +void hlsl_report_message(const char *filename, DWORD line, DWORD column, + enum hlsl_error_level level, const char *fmt, ...) +{ + va_list args; + char *string = NULL; + int rc, size = 0; + + while (1) + { + va_start(args, fmt); + rc = vsnprintf(string, size, fmt, args); + va_end(args); + + if (rc >= 0 && rc < size) + break; + + if (rc >= size) + size = rc + 1; + else + size = size ? size * 2 : 32; + + if (!string) + string = d3dcompiler_alloc(size); + else + string = d3dcompiler_realloc(string, size); + if (!string) + { + ERR("Error reallocating memory for a string.\n"); + return; + } + } + + hlsl_message("%s:%u:%u: %s: %s\n", filename, line, column, hlsl_get_error_level_name(level), string); + d3dcompiler_free(string); + + if (level == HLSL_LEVEL_ERROR) + set_parse_status(&hlsl_ctx.status, PARSE_ERR); + else if (level == HLSL_LEVEL_WARNING) + set_parse_status(&hlsl_ctx.status, PARSE_WARN); +} + +static void hlsl_error(const char *s) +{ + hlsl_report_message(hlsl_ctx.source_file, hlsl_ctx.line_no, hlsl_ctx.column, HLSL_LEVEL_ERROR, "%s", s); +} + +static void debug_dump_decl(struct hlsl_type *type, DWORD modifiers, const char *declname, unsigned int line_no) +{ + TRACE("Line %u: ", line_no); + if (modifiers) + TRACE("%s ", debug_modifiers(modifiers)); + TRACE("%s %s;\n", debug_hlsl_type(type), declname); +} + +static void check_invalid_matrix_modifiers(DWORD modifiers, struct source_location *loc) +{ + if (modifiers & (HLSL_MODIFIER_ROW_MAJOR | HLSL_MODIFIER_COLUMN_MAJOR)) + { + hlsl_report_message(loc->file, loc->line, loc->col, HLSL_LEVEL_ERROR, + "'row_major' or 'column_major' modifiers are only allowed for matrices"); + } +} + +static BOOL declare_variable(struct hlsl_ir_var *decl, BOOL local) +{ + BOOL ret; + + TRACE("Declaring variable %s.\n", decl->name); + if (decl->node.data_type->type == HLSL_CLASS_MATRIX) + { + if (!(decl->modifiers & (HLSL_MODIFIER_ROW_MAJOR | HLSL_MODIFIER_COLUMN_MAJOR))) + { + decl->modifiers |= hlsl_ctx.matrix_majority == HLSL_ROW_MAJOR + ? HLSL_MODIFIER_ROW_MAJOR : HLSL_MODIFIER_COLUMN_MAJOR; + } + } + else + check_invalid_matrix_modifiers(decl->modifiers, &decl->node.loc); + + if (local) + { + DWORD invalid = decl->modifiers & (HLSL_STORAGE_EXTERN | HLSL_STORAGE_SHARED + | HLSL_STORAGE_GROUPSHARED | HLSL_STORAGE_UNIFORM); + if (invalid) + { + hlsl_report_message(decl->node.loc.file, decl->node.loc.line, decl->node.loc.col, HLSL_LEVEL_ERROR, + "modifier '%s' invalid for local variables", debug_modifiers(invalid)); + } + if (decl->semantic) + { + hlsl_report_message(decl->node.loc.file, decl->node.loc.line, decl->node.loc.col, HLSL_LEVEL_ERROR, + "semantics are not allowed on local variables"); + return FALSE; + } + } + else + { + if (find_function(decl->name)) + { + hlsl_report_message(decl->node.loc.file, decl->node.loc.line, decl->node.loc.col, HLSL_LEVEL_ERROR, + "redefinition of '%s'", decl->name); + return FALSE; + } + } + ret = add_declaration(hlsl_ctx.cur_scope, decl, local); + if (!ret) + { + struct hlsl_ir_var *old = get_variable(hlsl_ctx.cur_scope, decl->name); + + hlsl_report_message(decl->node.loc.file, decl->node.loc.line, decl->node.loc.col, HLSL_LEVEL_ERROR, + "\"%s\" already declared", decl->name); + hlsl_report_message(old->node.loc.file, old->node.loc.line, old->node.loc.col, HLSL_LEVEL_NOTE, + "\"%s\" was previously declared here", old->name); + return FALSE; + } + return TRUE; +} + +static DWORD add_modifier(DWORD modifiers, DWORD mod, const struct YYLTYPE *loc); + +static BOOL check_type_modifiers(DWORD modifiers, struct source_location *loc) +{ + if (modifiers & ~HLSL_TYPE_MODIFIERS_MASK) + { + hlsl_report_message(loc->file, loc->line, loc->col, HLSL_LEVEL_ERROR, + "modifier not allowed on typedefs"); + return FALSE; + } + return TRUE; +} + +static BOOL add_type_to_scope(struct hlsl_scope *scope, struct hlsl_type *def) +{ + if (get_type(scope, def->name, FALSE)) + return FALSE; + + wine_rb_put(&scope->types, def->name, &def->scope_entry); + return TRUE; +} + +static void declare_predefined_types(struct hlsl_scope *scope) +{ + struct hlsl_type *type; + unsigned int x, y, bt; + static const char *names[] = + { + "float", + "half", + "double", + "int", + "uint", + "bool", + }; + char name[10]; + + for (bt = 0; bt <= HLSL_TYPE_LAST_SCALAR; ++bt) + { + for (y = 1; y <= 4; ++y) + { + for (x = 1; x <= 4; ++x) + { + sprintf(name, "%s%ux%u", names[bt], x, y); + type = new_hlsl_type(d3dcompiler_strdup(name), HLSL_CLASS_MATRIX, bt, x, y); + add_type_to_scope(scope, type); + + if (y == 1) + { + sprintf(name, "%s%u", names[bt], x); + type = new_hlsl_type(d3dcompiler_strdup(name), HLSL_CLASS_VECTOR, bt, x, y); + add_type_to_scope(scope, type); + + if (x == 1) + { + sprintf(name, "%s", names[bt]); + type = new_hlsl_type(d3dcompiler_strdup(name), HLSL_CLASS_SCALAR, bt, x, y); + add_type_to_scope(scope, type); + } + } + } + } + } + + /* DX8 effects predefined types */ + type = new_hlsl_type(d3dcompiler_strdup("DWORD"), HLSL_CLASS_SCALAR, HLSL_TYPE_INT, 1, 1); + add_type_to_scope(scope, type); + type = new_hlsl_type(d3dcompiler_strdup("FLOAT"), HLSL_CLASS_SCALAR, HLSL_TYPE_FLOAT, 1, 1); + add_type_to_scope(scope, type); + type = new_hlsl_type(d3dcompiler_strdup("VECTOR"), HLSL_CLASS_VECTOR, HLSL_TYPE_FLOAT, 4, 1); + add_type_to_scope(scope, type); + type = new_hlsl_type(d3dcompiler_strdup("MATRIX"), HLSL_CLASS_MATRIX, HLSL_TYPE_FLOAT, 4, 4); + add_type_to_scope(scope, type); + type = new_hlsl_type(d3dcompiler_strdup("STRING"), HLSL_CLASS_OBJECT, HLSL_TYPE_STRING, 1, 1); + add_type_to_scope(scope, type); + type = new_hlsl_type(d3dcompiler_strdup("TEXTURE"), HLSL_CLASS_OBJECT, HLSL_TYPE_TEXTURE, 1, 1); + add_type_to_scope(scope, type); + type = new_hlsl_type(d3dcompiler_strdup("PIXELSHADER"), HLSL_CLASS_OBJECT, HLSL_TYPE_PIXELSHADER, 1, 1); + add_type_to_scope(scope, type); + type = new_hlsl_type(d3dcompiler_strdup("VERTEXSHADER"), HLSL_CLASS_OBJECT, HLSL_TYPE_VERTEXSHADER, 1, 1); + add_type_to_scope(scope, type); +} + +static struct hlsl_ir_if *loop_condition(struct list *cond_list) +{ + struct hlsl_ir_if *out_cond; + struct hlsl_ir_expr *not_cond; + struct hlsl_ir_node *cond, *operands[3]; + struct hlsl_ir_jump *jump; + unsigned int count = list_count(cond_list); + + if (!count) + return NULL; + if (count != 1) + ERR("Got multiple expressions in a for condition.\n"); + + cond = LIST_ENTRY(list_head(cond_list), struct hlsl_ir_node, entry); + out_cond = d3dcompiler_alloc(sizeof(*out_cond)); + if (!out_cond) + { + ERR("Out of memory.\n"); + return NULL; + } + out_cond->node.type = HLSL_IR_IF; + operands[0] = cond; + operands[1] = operands[2] = NULL; + not_cond = new_expr(HLSL_IR_UNOP_LOGIC_NOT, operands, &cond->loc); + if (!not_cond) + { + ERR("Out of memory.\n"); + d3dcompiler_free(out_cond); + return NULL; + } + out_cond->condition = ¬_cond->node; + jump = d3dcompiler_alloc(sizeof(*jump)); + if (!jump) + { + ERR("Out of memory.\n"); + d3dcompiler_free(out_cond); + d3dcompiler_free(not_cond); + return NULL; + } + jump->node.type = HLSL_IR_JUMP; + jump->type = HLSL_IR_JUMP_BREAK; + out_cond->then_instrs = d3dcompiler_alloc(sizeof(*out_cond->then_instrs)); + if (!out_cond->then_instrs) + { + ERR("Out of memory.\n"); + d3dcompiler_free(out_cond); + d3dcompiler_free(not_cond); + d3dcompiler_free(jump); + return NULL; + } + list_init(out_cond->then_instrs); + list_add_head(out_cond->then_instrs, &jump->node.entry); + + return out_cond; +} + +enum loop_type +{ + LOOP_FOR, + LOOP_WHILE, + LOOP_DO_WHILE +}; + +static struct list *create_loop(enum loop_type type, struct list *init, struct list *cond, + struct hlsl_ir_node *iter, struct list *body, struct source_location *loc) +{ + struct list *list = NULL; + struct hlsl_ir_loop *loop = NULL; + struct hlsl_ir_if *cond_jump = NULL; + + list = d3dcompiler_alloc(sizeof(*list)); + if (!list) + goto oom; + list_init(list); + + if (init) + list_move_head(list, init); + + loop = d3dcompiler_alloc(sizeof(*loop)); + if (!loop) + goto oom; + loop->node.type = HLSL_IR_LOOP; + loop->node.loc = *loc; + list_add_tail(list, &loop->node.entry); + loop->body = d3dcompiler_alloc(sizeof(*loop->body)); + if (!loop->body) + goto oom; + list_init(loop->body); + + cond_jump = loop_condition(cond); + if (!cond_jump) + goto oom; + + if (type != LOOP_DO_WHILE) + list_add_tail(loop->body, &cond_jump->node.entry); + + list_move_tail(loop->body, body); + + if (iter) + list_add_tail(loop->body, &iter->entry); + + if (type == LOOP_DO_WHILE) + list_add_tail(loop->body, &cond_jump->node.entry); + + d3dcompiler_free(init); + d3dcompiler_free(cond); + d3dcompiler_free(body); + return list; + +oom: + ERR("Out of memory.\n"); + if (loop) + d3dcompiler_free(loop->body); + d3dcompiler_free(loop); + d3dcompiler_free(cond_jump); + d3dcompiler_free(list); + free_instr_list(init); + free_instr_list(cond); + free_instr(iter); + free_instr_list(body); + return NULL; +} + +static unsigned int initializer_size(struct list *initializer) +{ + unsigned int count = 0; + struct hlsl_ir_node *node; + + LIST_FOR_EACH_ENTRY(node, initializer, struct hlsl_ir_node, entry) + { + count += components_count_type(node->data_type); + } + TRACE("Initializer size = %u\n", count); + return count; +} + +static unsigned int components_count_expr_list(struct list *list) +{ + struct hlsl_ir_node *node; + unsigned int count = 0; + + LIST_FOR_EACH_ENTRY(node, list, struct hlsl_ir_node, entry) + { + count += components_count_type(node->data_type); + } + return count; +} + +static struct hlsl_ir_swizzle *new_swizzle(DWORD s, unsigned int components, + struct hlsl_ir_node *val, struct source_location *loc) +{ + struct hlsl_ir_swizzle *swizzle = d3dcompiler_alloc(sizeof(*swizzle)); + + if (!swizzle) + return NULL; + swizzle->node.type = HLSL_IR_SWIZZLE; + swizzle->node.loc = *loc; + swizzle->node.data_type = new_hlsl_type(NULL, HLSL_CLASS_VECTOR, val->data_type->base_type, components, 1); + swizzle->val = val; + swizzle->swizzle = s; + return swizzle; +} + +static struct hlsl_ir_swizzle *get_swizzle(struct hlsl_ir_node *value, const char *swizzle, + struct source_location *loc) +{ + unsigned int len = strlen(swizzle), component = 0; + unsigned int i, set, swiz = 0; + BOOL valid; + + if (value->data_type->type == HLSL_CLASS_MATRIX) + { + /* Matrix swizzle */ + BOOL m_swizzle; + unsigned int inc, x, y; + + if (len < 3 || swizzle[0] != '_') + return NULL; + m_swizzle = swizzle[1] == 'm'; + inc = m_swizzle ? 4 : 3; + + if (len % inc || len > inc * 4) + return NULL; + + for (i = 0; i < len; i += inc) + { + if (swizzle[i] != '_') + return NULL; + if (m_swizzle) + { + if (swizzle[i + 1] != 'm') + return NULL; + x = swizzle[i + 2] - '0'; + y = swizzle[i + 3] - '0'; + } + else + { + x = swizzle[i + 1] - '1'; + y = swizzle[i + 2] - '1'; + } + + if (x >= value->data_type->dimx || y >= value->data_type->dimy) + return NULL; + swiz |= (y << 4 | x) << component * 8; + component++; + } + return new_swizzle(swiz, component, value, loc); + } + + /* Vector swizzle */ + if (len > 4) + return NULL; + + for (set = 0; set < 2; ++set) + { + valid = TRUE; + component = 0; + for (i = 0; i < len; ++i) + { + char c[2][4] = {{'x', 'y', 'z', 'w'}, {'r', 'g', 'b', 'a'}}; + unsigned int s = 0; + + for (s = 0; s < 4; ++s) + { + if (swizzle[i] == c[set][s]) + break; + } + if (s == 4) + { + valid = FALSE; + break; + } + + if (s >= value->data_type->dimx) + return NULL; + swiz |= s << component * 2; + component++; + } + if (valid) + return new_swizzle(swiz, component, value, loc); + } + + return NULL; +} + +static void struct_var_initializer(struct list *list, struct hlsl_ir_var *var, struct list *initializer) +{ + struct hlsl_type *type = var->node.data_type; + struct hlsl_ir_node *node; + struct hlsl_struct_field *field; + struct list *cur_node; + struct hlsl_ir_node *assignment; + struct hlsl_ir_deref *deref; + + if (initializer_size(initializer) != components_count_type(type)) + { + hlsl_report_message(var->node.loc.file, var->node.loc.line, var->node.loc.col, HLSL_LEVEL_ERROR, + "structure initializer mismatch"); + free_instr_list(initializer); + return; + } + cur_node = list_head(initializer); + assert(cur_node); + node = LIST_ENTRY(cur_node, struct hlsl_ir_node, entry); + LIST_FOR_EACH_ENTRY(field, type->e.elements, struct hlsl_struct_field, entry) + { + if (!cur_node) + { + d3dcompiler_free(initializer); + return; + } + if (components_count_type(field->type) == components_count_type(node->data_type)) + { + deref = new_record_deref(&var->node, field); + if (!deref) + { + ERR("Out of memory.\n"); + break; + } + deref->node.loc = node->loc; + assignment = make_assignment(&deref->node, ASSIGN_OP_ASSIGN, BWRITERSP_WRITEMASK_ALL, node); + list_add_tail(list, &assignment->entry); + } + else + FIXME("Initializing with \"mismatched\" fields is not supported yet.\n"); + cur_node = list_next(initializer, cur_node); + node = LIST_ENTRY(cur_node, struct hlsl_ir_node, entry); + } + + /* Free initializer elements in excess. */ + while (cur_node) + { + struct list *next = list_next(initializer, cur_node); + free_instr(node); + cur_node = next; + node = LIST_ENTRY(cur_node, struct hlsl_ir_node, entry); + } + d3dcompiler_free(initializer); +} + +static struct list *declare_vars(struct hlsl_type *basic_type, DWORD modifiers, struct list *var_list) +{ + struct hlsl_type *type; + struct parse_variable_def *v, *v_next; + struct hlsl_ir_var *var; + struct hlsl_ir_node *assignment; + BOOL ret, local = TRUE; + struct list *statements_list = d3dcompiler_alloc(sizeof(*statements_list)); + + if (!statements_list) + { + ERR("Out of memory.\n"); + LIST_FOR_EACH_ENTRY_SAFE(v, v_next, var_list, struct parse_variable_def, entry) + d3dcompiler_free(v); + d3dcompiler_free(var_list); + return NULL; + } + list_init(statements_list); + + if (!var_list) + return statements_list; + + LIST_FOR_EACH_ENTRY_SAFE(v, v_next, var_list, struct parse_variable_def, entry) + { + var = d3dcompiler_alloc(sizeof(*var)); + if (!var) + { + ERR("Out of memory.\n"); + d3dcompiler_free(v); + continue; + } + var->node.type = HLSL_IR_VAR; + if (v->array_size) + type = new_array_type(basic_type, v->array_size); + else + type = basic_type; + var->node.data_type = type; + var->node.loc = v->loc; + var->name = v->name; + var->modifiers = modifiers; + var->semantic = v->semantic; + debug_dump_decl(type, modifiers, v->name, v->loc.line); + + if (hlsl_ctx.cur_scope == hlsl_ctx.globals) + { + var->modifiers |= HLSL_STORAGE_UNIFORM; + local = FALSE; + } + + if (var->modifiers & HLSL_MODIFIER_CONST && !(var->modifiers & HLSL_STORAGE_UNIFORM) && !v->initializer) + { + hlsl_report_message(v->loc.file, v->loc.line, v->loc.col, + HLSL_LEVEL_ERROR, "const variable without initializer"); + free_declaration(var); + d3dcompiler_free(v); + continue; + } + + ret = declare_variable(var, local); + if (!ret) + { + free_declaration(var); + d3dcompiler_free(v); + continue; + } + TRACE("Declared variable %s.\n", var->name); + + if (v->initializer) + { + unsigned int size = initializer_size(v->initializer); + struct hlsl_ir_node *node; + + TRACE("Variable with initializer.\n"); + if (type->type <= HLSL_CLASS_LAST_NUMERIC + && type->dimx * type->dimy != size && size != 1) + { + if (size < type->dimx * type->dimy) + { + hlsl_report_message(v->loc.file, v->loc.line, v->loc.col, HLSL_LEVEL_ERROR, + "'%s' initializer does not match", v->name); + free_instr_list(v->initializer); + d3dcompiler_free(v); + continue; + } + } + if ((type->type == HLSL_CLASS_STRUCT || type->type == HLSL_CLASS_ARRAY) + && components_count_type(type) != size) + { + hlsl_report_message(v->loc.file, v->loc.line, v->loc.col, HLSL_LEVEL_ERROR, + "'%s' initializer does not match", v->name); + free_instr_list(v->initializer); + d3dcompiler_free(v); + continue; + } + + if (type->type == HLSL_CLASS_STRUCT) + { + struct_var_initializer(statements_list, var, v->initializer); + d3dcompiler_free(v); + continue; + } + if (type->type > HLSL_CLASS_LAST_NUMERIC) + { + FIXME("Initializers for non scalar/struct variables not supported yet.\n"); + free_instr_list(v->initializer); + d3dcompiler_free(v); + continue; + } + if (v->array_size > 0) + { + FIXME("Initializing arrays is not supported yet.\n"); + free_instr_list(v->initializer); + d3dcompiler_free(v); + continue; + } + if (list_count(v->initializer) > 1) + { + FIXME("Complex initializers are not supported yet.\n"); + free_instr_list(v->initializer); + d3dcompiler_free(v); + continue; + } + node = LIST_ENTRY(list_head(v->initializer), struct hlsl_ir_node, entry); + assignment = make_assignment(&var->node, ASSIGN_OP_ASSIGN, + BWRITERSP_WRITEMASK_ALL, node); + list_add_tail(statements_list, &assignment->entry); + d3dcompiler_free(v->initializer); + } + d3dcompiler_free(v); + } + d3dcompiler_free(var_list); + return statements_list; +} + +static BOOL add_struct_field(struct list *fields, struct hlsl_struct_field *field) +{ + struct hlsl_struct_field *f; + + LIST_FOR_EACH_ENTRY(f, fields, struct hlsl_struct_field, entry) + { + if (!strcmp(f->name, field->name)) + return FALSE; + } + list_add_tail(fields, &field->entry); + return TRUE; +} + +static struct list *gen_struct_fields(struct hlsl_type *type, DWORD modifiers, struct list *fields) +{ + struct parse_variable_def *v, *v_next; + struct hlsl_struct_field *field; + struct list *list; + + list = d3dcompiler_alloc(sizeof(*list)); + if (!list) + { + ERR("Out of memory.\n"); + return NULL; + } + list_init(list); + LIST_FOR_EACH_ENTRY_SAFE(v, v_next, fields, struct parse_variable_def, entry) + { + debug_dump_decl(type, 0, v->name, v->loc.line); + field = d3dcompiler_alloc(sizeof(*field)); + if (!field) + { + ERR("Out of memory.\n"); + d3dcompiler_free(v); + return list; + } + field->type = type; + field->name = v->name; + field->modifiers = modifiers; + field->semantic = v->semantic; + if (v->initializer) + { + hlsl_report_message(v->loc.file, v->loc.line, v->loc.col, HLSL_LEVEL_ERROR, + "struct field with an initializer.\n"); + free_instr_list(v->initializer); + } + list_add_tail(list, &field->entry); + d3dcompiler_free(v); + } + d3dcompiler_free(fields); + return list; +} + +static struct hlsl_type *new_struct_type(const char *name, DWORD modifiers, struct list *fields) +{ + struct hlsl_type *type = d3dcompiler_alloc(sizeof(*type)); + + if (!type) + { + ERR("Out of memory.\n"); + return NULL; + } + type->type = HLSL_CLASS_STRUCT; + type->name = name; + type->dimx = type->dimy = 1; + type->modifiers = modifiers; + type->e.elements = fields; + + list_add_tail(&hlsl_ctx.types, &type->entry); + + return type; +} + +static BOOL add_typedef(DWORD modifiers, struct hlsl_type *orig_type, struct list *list, + struct source_location *loc) +{ + BOOL ret; + struct hlsl_type *type; + struct parse_variable_def *v, *v_next; + + if (!check_type_modifiers(modifiers, loc)) + { + LIST_FOR_EACH_ENTRY_SAFE(v, v_next, list, struct parse_variable_def, entry) + d3dcompiler_free(v); + d3dcompiler_free(list); + return FALSE; + } + + LIST_FOR_EACH_ENTRY_SAFE(v, v_next, list, struct parse_variable_def, entry) + { + if (v->array_size) + type = new_array_type(orig_type, v->array_size); + else + type = clone_hlsl_type(orig_type); + if (!type) + { + ERR("Out of memory\n"); + return FALSE; + } + d3dcompiler_free((void *)type->name); + type->name = v->name; + type->modifiers |= modifiers; + + if (type->type != HLSL_CLASS_MATRIX) + check_invalid_matrix_modifiers(type->modifiers, &v->loc); + + ret = add_type_to_scope(hlsl_ctx.cur_scope, type); + if (!ret) + { + hlsl_report_message(v->loc.file, v->loc.line, v->loc.col, HLSL_LEVEL_ERROR, + "redefinition of custom type '%s'", v->name); + } + d3dcompiler_free(v); + } + d3dcompiler_free(list); + return TRUE; +} + +static const struct hlsl_ir_function_decl *get_overloaded_func(struct wine_rb_tree *funcs, char *name, + struct list *params, BOOL exact_signature) +{ + struct hlsl_ir_function *func; + struct wine_rb_entry *entry; + + entry = wine_rb_get(funcs, name); + if (entry) + { + func = WINE_RB_ENTRY_VALUE(entry, struct hlsl_ir_function, entry); + + entry = wine_rb_get(&func->overloads, params); + if (!entry) + { + if (!exact_signature) + FIXME("No exact match, search for a compatible overloaded function (if any).\n"); + return NULL; + } + return WINE_RB_ENTRY_VALUE(entry, struct hlsl_ir_function_decl, entry); + } + return NULL; +} + + + +/* Line 268 of yacc.c */ +#line 895 "hlsl.tab.c" + +/* Enabling traces. */ +#ifndef YYDEBUG +# define YYDEBUG 0 +#endif + +/* Enabling verbose error messages. */ +#ifdef YYERROR_VERBOSE +# undef YYERROR_VERBOSE +# define YYERROR_VERBOSE 1 +#else +# define YYERROR_VERBOSE 1 +#endif + +/* Enabling the token table. */ +#ifndef YYTOKEN_TABLE +# define YYTOKEN_TABLE 0 +#endif + + +/* Tokens. */ +#ifndef YYTOKENTYPE +# define YYTOKENTYPE + /* Put the tokens into the symbol table, so that GDB and other debuggers + know about them. */ + enum yytokentype { + KW_BLENDSTATE = 258, + KW_BREAK = 259, + KW_BUFFER = 260, + KW_CBUFFER = 261, + KW_COLUMN_MAJOR = 262, + KW_COMPILE = 263, + KW_CONST = 264, + KW_CONTINUE = 265, + KW_DEPTHSTENCILSTATE = 266, + KW_DEPTHSTENCILVIEW = 267, + KW_DISCARD = 268, + KW_DO = 269, + KW_DOUBLE = 270, + KW_ELSE = 271, + KW_EXTERN = 272, + KW_FALSE = 273, + KW_FOR = 274, + KW_GEOMETRYSHADER = 275, + KW_GROUPSHARED = 276, + KW_IF = 277, + KW_IN = 278, + KW_INLINE = 279, + KW_INOUT = 280, + KW_MATRIX = 281, + KW_NAMESPACE = 282, + KW_NOINTERPOLATION = 283, + KW_OUT = 284, + KW_PASS = 285, + KW_PIXELSHADER = 286, + KW_PRECISE = 287, + KW_RASTERIZERSTATE = 288, + KW_RENDERTARGETVIEW = 289, + KW_RETURN = 290, + KW_REGISTER = 291, + KW_ROW_MAJOR = 292, + KW_SAMPLER = 293, + KW_SAMPLER1D = 294, + KW_SAMPLER2D = 295, + KW_SAMPLER3D = 296, + KW_SAMPLERCUBE = 297, + KW_SAMPLER_STATE = 298, + KW_SAMPLERCOMPARISONSTATE = 299, + KW_SHARED = 300, + KW_STATEBLOCK = 301, + KW_STATEBLOCK_STATE = 302, + KW_STATIC = 303, + KW_STRING = 304, + KW_STRUCT = 305, + KW_SWITCH = 306, + KW_TBUFFER = 307, + KW_TECHNIQUE = 308, + KW_TECHNIQUE10 = 309, + KW_TEXTURE = 310, + KW_TEXTURE1D = 311, + KW_TEXTURE1DARRAY = 312, + KW_TEXTURE2D = 313, + KW_TEXTURE2DARRAY = 314, + KW_TEXTURE2DMS = 315, + KW_TEXTURE2DMSARRAY = 316, + KW_TEXTURE3D = 317, + KW_TEXTURE3DARRAY = 318, + KW_TEXTURECUBE = 319, + KW_TRUE = 320, + KW_TYPEDEF = 321, + KW_UNIFORM = 322, + KW_VECTOR = 323, + KW_VERTEXSHADER = 324, + KW_VOID = 325, + KW_VOLATILE = 326, + KW_WHILE = 327, + OP_INC = 328, + OP_DEC = 329, + OP_AND = 330, + OP_OR = 331, + OP_EQ = 332, + OP_LEFTSHIFT = 333, + OP_LEFTSHIFTASSIGN = 334, + OP_RIGHTSHIFT = 335, + OP_RIGHTSHIFTASSIGN = 336, + OP_ELLIPSIS = 337, + OP_LE = 338, + OP_GE = 339, + OP_NE = 340, + OP_ADDASSIGN = 341, + OP_SUBASSIGN = 342, + OP_MULASSIGN = 343, + OP_DIVASSIGN = 344, + OP_MODASSIGN = 345, + OP_ANDASSIGN = 346, + OP_ORASSIGN = 347, + OP_XORASSIGN = 348, + OP_UNKNOWN1 = 349, + OP_UNKNOWN2 = 350, + OP_UNKNOWN3 = 351, + OP_UNKNOWN4 = 352, + PRE_LINE = 353, + VAR_IDENTIFIER = 354, + TYPE_IDENTIFIER = 355, + NEW_IDENTIFIER = 356, + STRING = 357, + C_FLOAT = 358, + C_INTEGER = 359 + }; +#endif + + + +#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED +typedef union YYSTYPE +{ + +/* Line 293 of yacc.c */ +#line 841 "hlsl.y" + + struct hlsl_type *type; + INT intval; + FLOAT floatval; + BOOL boolval; + char *name; + DWORD modifiers; + struct hlsl_ir_var *var; + struct hlsl_ir_node *instr; + struct list *list; + struct parse_function function; + struct parse_parameter parameter; + struct parse_variable_def *variable_def; + struct parse_if_body if_body; + enum parse_unary_op unary_op; + enum parse_assign_op assign_op; + + + +/* Line 293 of yacc.c */ +#line 1055 "hlsl.tab.c" +} YYSTYPE; +# define YYSTYPE_IS_TRIVIAL 1 +# define yystype YYSTYPE /* obsolescent; will be withdrawn */ +# define YYSTYPE_IS_DECLARED 1 +#endif + +#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED +typedef struct YYLTYPE +{ + int first_line; + int first_column; + int last_line; + int last_column; +} YYLTYPE; +# define yyltype YYLTYPE /* obsolescent; will be withdrawn */ +# define YYLTYPE_IS_DECLARED 1 +# define YYLTYPE_IS_TRIVIAL 1 +#endif + + +/* Copy the second part of user declarations. */ + + +/* Line 343 of yacc.c */ +#line 1080 "hlsl.tab.c" + +#ifdef short +# undef short +#endif + +#ifdef YYTYPE_UINT8 +typedef YYTYPE_UINT8 yytype_uint8; +#else +typedef unsigned char yytype_uint8; +#endif + +#ifdef YYTYPE_INT8 +typedef YYTYPE_INT8 yytype_int8; +#elif (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +typedef signed char yytype_int8; +#else +typedef short int yytype_int8; +#endif + +#ifdef YYTYPE_UINT16 +typedef YYTYPE_UINT16 yytype_uint16; +#else +typedef unsigned short int yytype_uint16; +#endif + +#ifdef YYTYPE_INT16 +typedef YYTYPE_INT16 yytype_int16; +#else +typedef short int yytype_int16; +#endif + +#ifndef YYSIZE_T +# ifdef __SIZE_TYPE__ +# define YYSIZE_T __SIZE_TYPE__ +# elif defined size_t +# define YYSIZE_T size_t +# elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +# include /* INFRINGES ON USER NAME SPACE */ +# define YYSIZE_T size_t +# else +# define YYSIZE_T unsigned int +# endif +#endif + +#define YYSIZE_MAXIMUM ((YYSIZE_T) -1) + +#ifndef YY_ +# if defined YYENABLE_NLS && YYENABLE_NLS +# if ENABLE_NLS +# include /* INFRINGES ON USER NAME SPACE */ +# define YY_(msgid) dgettext ("bison-runtime", msgid) +# endif +# endif +# ifndef YY_ +# define YY_(msgid) msgid +# endif +#endif + +/* Suppress unused-variable warnings by "using" E. */ +#if ! defined lint || defined __GNUC__ +# define YYUSE(e) ((void) (e)) +#else +# define YYUSE(e) /* empty */ +#endif + +/* Identity function, used to suppress warnings about constant conditions. */ +#ifndef lint +# define YYID(n) (n) +#else +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static int +YYID (int yyi) +#else +static int +YYID (yyi) + int yyi; +#endif +{ + return yyi; +} +#endif + +#if ! defined yyoverflow || YYERROR_VERBOSE + +/* The parser invokes alloca or malloc; define the necessary symbols. */ + +# ifdef YYSTACK_USE_ALLOCA +# if YYSTACK_USE_ALLOCA +# ifdef __GNUC__ +# define YYSTACK_ALLOC __builtin_alloca +# elif defined __BUILTIN_VA_ARG_INCR +# include /* INFRINGES ON USER NAME SPACE */ +# elif defined _AIX +# define YYSTACK_ALLOC __alloca +# elif defined _MSC_VER +# include /* INFRINGES ON USER NAME SPACE */ +# define alloca _alloca +# else +# define YYSTACK_ALLOC alloca +# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +# include /* INFRINGES ON USER NAME SPACE */ +# ifndef EXIT_SUCCESS +# define EXIT_SUCCESS 0 +# endif +# endif +# endif +# endif +# endif + +# ifdef YYSTACK_ALLOC + /* Pacify GCC's `empty if-body' warning. */ +# define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0)) +# ifndef YYSTACK_ALLOC_MAXIMUM + /* The OS might guarantee only one guard page at the bottom of the stack, + and a page size can be as small as 4096 bytes. So we cannot safely + invoke alloca (N) if N exceeds 4096. Use a slightly smaller number + to allow for a few compiler-allocated temporary stack slots. */ +# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */ +# endif +# else +# define YYSTACK_ALLOC YYMALLOC +# define YYSTACK_FREE YYFREE +# ifndef YYSTACK_ALLOC_MAXIMUM +# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM +# endif +# if (defined __cplusplus && ! defined EXIT_SUCCESS \ + && ! ((defined YYMALLOC || defined malloc) \ + && (defined YYFREE || defined free))) +# include /* INFRINGES ON USER NAME SPACE */ +# ifndef EXIT_SUCCESS +# define EXIT_SUCCESS 0 +# endif +# endif +# ifndef YYMALLOC +# define YYMALLOC malloc +# if ! defined malloc && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ +# endif +# endif +# ifndef YYFREE +# define YYFREE free +# if ! defined free && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +void free (void *); /* INFRINGES ON USER NAME SPACE */ +# endif +# endif +# endif +#endif /* ! defined yyoverflow || YYERROR_VERBOSE */ + + +#if (! defined yyoverflow \ + && (! defined __cplusplus \ + || (defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL \ + && defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) + +/* A type that is properly aligned for any stack member. */ +union yyalloc +{ + yytype_int16 yyss_alloc; + YYSTYPE yyvs_alloc; + YYLTYPE yyls_alloc; +}; + +/* The size of the maximum gap between one aligned stack and the next. */ +# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1) + +/* The size of an array large to enough to hold all stacks, each with + N elements. */ +# define YYSTACK_BYTES(N) \ + ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \ + + 2 * YYSTACK_GAP_MAXIMUM) + +# define YYCOPY_NEEDED 1 + +/* Relocate STACK from its old location to the new one. The + local variables YYSIZE and YYSTACKSIZE give the old and new number of + elements in the stack, and YYPTR gives the new location of the + stack. Advance YYPTR to a properly aligned location for the next + stack. */ +# define YYSTACK_RELOCATE(Stack_alloc, Stack) \ + do \ + { \ + YYSIZE_T yynewbytes; \ + YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \ + Stack = &yyptr->Stack_alloc; \ + yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \ + yyptr += yynewbytes / sizeof (*yyptr); \ + } \ + while (YYID (0)) + +#endif + +#if defined YYCOPY_NEEDED && YYCOPY_NEEDED +/* Copy COUNT objects from FROM to TO. The source and destination do + not overlap. */ +# ifndef YYCOPY +# if defined __GNUC__ && 1 < __GNUC__ +# define YYCOPY(To, From, Count) \ + __builtin_memcpy (To, From, (Count) * sizeof (*(From))) +# else +# define YYCOPY(To, From, Count) \ + do \ + { \ + YYSIZE_T yyi; \ + for (yyi = 0; yyi < (Count); yyi++) \ + (To)[yyi] = (From)[yyi]; \ + } \ + while (YYID (0)) +# endif +# endif +#endif /* !YYCOPY_NEEDED */ + +/* YYFINAL -- State number of the termination state. */ +#define YYFINAL 2 +/* YYLAST -- Last index in YYTABLE. */ +#define YYLAST 848 + +/* YYNTOKENS -- Number of terminals. */ +#define YYNTOKENS 129 +/* YYNNTS -- Number of nonterminals. */ +#define YYNNTS 63 +/* YYNRULES -- Number of rules. */ +#define YYNRULES 171 +/* YYNRULES -- Number of states. */ +#define YYNSTATES 312 + +/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ +#define YYUNDEFTOK 2 +#define YYMAXUTOK 359 + +#define YYTRANSLATE(YYX) \ + ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) + +/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */ +static const yytype_uint8 yytranslate[] = +{ + 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 120, 2, 2, 2, 124, 125, 2, + 108, 109, 122, 118, 111, 119, 117, 123, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 110, 105, + 112, 114, 113, 128, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 115, 2, 116, 126, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 106, 127, 107, 121, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, + 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, + 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, + 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, + 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, + 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, + 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, + 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, + 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, + 95, 96, 97, 98, 99, 100, 101, 102, 103, 104 +}; + +#if YYDEBUG +/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in + YYRHS. */ +static const yytype_uint16 yyprhs[] = +{ + 0, 0, 3, 4, 7, 10, 13, 16, 19, 23, + 25, 27, 34, 40, 42, 44, 46, 47, 50, 55, + 59, 62, 65, 73, 76, 81, 82, 84, 86, 87, + 90, 92, 95, 97, 101, 107, 108, 111, 113, 115, + 117, 119, 126, 135, 137, 139, 141, 143, 145, 147, + 149, 152, 154, 156, 158, 164, 169, 171, 175, 178, + 183, 184, 186, 188, 192, 196, 202, 203, 207, 208, + 211, 214, 217, 220, 223, 226, 229, 232, 235, 238, + 241, 243, 247, 252, 254, 256, 260, 262, 264, 266, + 269, 271, 273, 275, 277, 279, 281, 285, 291, 293, + 297, 303, 311, 320, 329, 331, 334, 336, 338, 340, + 342, 346, 348, 350, 353, 356, 360, 365, 371, 373, + 376, 379, 382, 389, 391, 393, 395, 397, 399, 403, + 407, 411, 413, 417, 421, 423, 427, 431, 433, 437, + 441, 445, 449, 451, 455, 459, 461, 465, 467, 471, + 473, 477, 479, 483, 485, 489, 491, 497, 499, 503, + 505, 507, 509, 511, 513, 515, 517, 519, 521, 523, + 525, 527 +}; + +/* YYRHS -- A `-1'-separated list of the rules' RHS. */ +static const yytype_int16 yyrhs[] = +{ + 130, 0, -1, -1, 130, 139, -1, 130, 152, -1, + 130, 131, -1, 130, 105, -1, 98, 102, -1, 133, + 157, 105, -1, 134, -1, 135, -1, 161, 50, 136, + 106, 137, 107, -1, 161, 50, 106, 137, 107, -1, + 99, -1, 100, -1, 101, -1, -1, 137, 138, -1, + 161, 150, 158, 105, -1, 135, 158, 105, -1, 140, + 141, -1, 140, 105, -1, 161, 150, 143, 108, 145, + 109, 144, -1, 106, 107, -1, 106, 142, 166, 107, + -1, -1, 99, -1, 101, -1, -1, 110, 136, -1, + 142, -1, 142, 146, -1, 147, -1, 146, 111, 147, + -1, 148, 161, 150, 136, 144, -1, -1, 148, 149, + -1, 23, -1, 29, -1, 25, -1, 151, -1, 68, + 112, 151, 111, 104, 113, -1, 26, 112, 151, 111, + 104, 111, 104, 113, -1, 70, -1, 38, -1, 39, + -1, 40, -1, 41, -1, 42, -1, 100, -1, 50, + 100, -1, 156, -1, 132, -1, 153, -1, 66, 161, + 150, 154, 105, -1, 66, 133, 154, 105, -1, 155, + -1, 154, 111, 155, -1, 136, 160, -1, 161, 150, + 158, 105, -1, -1, 158, -1, 159, -1, 158, 111, + 159, -1, 136, 160, 144, -1, 136, 160, 144, 114, + 162, -1, -1, 115, 191, 116, -1, -1, 17, 161, + -1, 28, 161, -1, 32, 161, -1, 45, 161, -1, + 21, 161, -1, 48, 161, -1, 67, 161, -1, 71, + 161, -1, 9, 161, -1, 37, 161, -1, 7, 161, + -1, 163, -1, 106, 164, 107, -1, 106, 164, 111, + 107, -1, 189, -1, 163, -1, 164, 111, 163, -1, + 65, -1, 18, -1, 167, -1, 166, 167, -1, 152, + -1, 172, -1, 141, -1, 168, -1, 169, -1, 171, + -1, 35, 191, 105, -1, 22, 108, 191, 109, 170, + -1, 167, -1, 167, 16, 167, -1, 72, 108, 191, + 109, 167, -1, 14, 167, 72, 108, 191, 109, 105, + -1, 19, 108, 142, 172, 172, 191, 109, 167, -1, + 19, 108, 142, 156, 172, 191, 109, 167, -1, 105, + -1, 191, 105, -1, 103, -1, 104, -1, 165, -1, + 174, -1, 108, 191, 109, -1, 99, -1, 173, -1, + 175, 73, -1, 175, 74, -1, 175, 117, 136, -1, + 175, 115, 191, 116, -1, 161, 150, 108, 164, 109, + -1, 175, -1, 73, 176, -1, 74, 176, -1, 177, + 176, -1, 108, 161, 150, 160, 109, 176, -1, 118, + -1, 119, -1, 120, -1, 121, -1, 176, -1, 178, + 122, 176, -1, 178, 123, 176, -1, 178, 124, 176, + -1, 178, -1, 179, 118, 178, -1, 179, 119, 178, + -1, 179, -1, 180, 78, 179, -1, 180, 80, 179, + -1, 180, -1, 181, 112, 180, -1, 181, 113, 180, + -1, 181, 83, 180, -1, 181, 84, 180, -1, 181, + -1, 182, 77, 181, -1, 182, 85, 181, -1, 182, + -1, 183, 125, 182, -1, 183, -1, 184, 126, 183, + -1, 184, -1, 185, 127, 184, -1, 185, -1, 186, + 75, 185, -1, 186, -1, 187, 76, 186, -1, 187, + -1, 187, 128, 191, 110, 189, -1, 188, -1, 176, + 190, 189, -1, 114, -1, 86, -1, 87, -1, 88, + -1, 89, -1, 90, -1, 79, -1, 81, -1, 91, + -1, 92, -1, 93, -1, 189, -1, 191, 111, 189, + -1 +}; + +/* YYRLINE[YYN] -- source line where rule number YYN was defined. */ +static const yytype_uint16 yyrline[] = +{ + 0, 1022, 1022, 1024, 1061, 1065, 1068, 1073, 1092, 1109, + 1110, 1112, 1138, 1148, 1149, 1150, 1153, 1157, 1176, 1180, + 1185, 1192, 1199, 1224, 1229, 1236, 1240, 1241, 1244, 1247, + 1252, 1257, 1262, 1276, 1290, 1300, 1303, 1314, 1318, 1322, + 1327, 1331, 1350, 1370, 1374, 1379, 1384, 1389, 1394, 1399, + 1408, 1427, 1428, 1429, 1440, 1448, 1457, 1463, 1469, 1477, + 1483, 1486, 1491, 1497, 1503, 1511, 1523, 1526, 1534, 1537, + 1541, 1545, 1549, 1553, 1557, 1561, 1565, 1569, 1573, 1577, + 1582, 1588, 1592, 1597, 1602, 1608, 1614, 1618, 1623, 1627, + 1634, 1635, 1636, 1637, 1638, 1639, 1642, 1665, 1689, 1694, + 1700, 1715, 1730, 1738, 1750, 1755, 1763, 1777, 1791, 1805, + 1816, 1821, 1835, 1839, 1858, 1877, 1931, 1991, 2027, 2031, + 2047, 2063, 2083, 2115, 2119, 2123, 2127, 2132, 2136, 2143, + 2150, 2158, 2162, 2169, 2177, 2181, 2185, 2190, 2194, 2201, + 2208, 2215, 2223, 2227, 2234, 2242, 2246, 2251, 2255, 2260, + 2264, 2269, 2273, 2278, 2282, 2287, 2291, 2296, 2300, 2317, + 2321, 2325, 2329, 2333, 2337, 2341, 2345, 2349, 2353, 2357, + 2362, 2366 +}; +#endif + +#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE +/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. + First, the terminals, then, starting at YYNTOKENS, nonterminals. */ +static const char *const yytname[] = +{ + "$end", "error", "$undefined", "KW_BLENDSTATE", "KW_BREAK", "KW_BUFFER", + "KW_CBUFFER", "KW_COLUMN_MAJOR", "KW_COMPILE", "KW_CONST", "KW_CONTINUE", + "KW_DEPTHSTENCILSTATE", "KW_DEPTHSTENCILVIEW", "KW_DISCARD", "KW_DO", + "KW_DOUBLE", "KW_ELSE", "KW_EXTERN", "KW_FALSE", "KW_FOR", + "KW_GEOMETRYSHADER", "KW_GROUPSHARED", "KW_IF", "KW_IN", "KW_INLINE", + "KW_INOUT", "KW_MATRIX", "KW_NAMESPACE", "KW_NOINTERPOLATION", "KW_OUT", + "KW_PASS", "KW_PIXELSHADER", "KW_PRECISE", "KW_RASTERIZERSTATE", + "KW_RENDERTARGETVIEW", "KW_RETURN", "KW_REGISTER", "KW_ROW_MAJOR", + "KW_SAMPLER", "KW_SAMPLER1D", "KW_SAMPLER2D", "KW_SAMPLER3D", + "KW_SAMPLERCUBE", "KW_SAMPLER_STATE", "KW_SAMPLERCOMPARISONSTATE", + "KW_SHARED", "KW_STATEBLOCK", "KW_STATEBLOCK_STATE", "KW_STATIC", + "KW_STRING", "KW_STRUCT", "KW_SWITCH", "KW_TBUFFER", "KW_TECHNIQUE", + "KW_TECHNIQUE10", "KW_TEXTURE", "KW_TEXTURE1D", "KW_TEXTURE1DARRAY", + "KW_TEXTURE2D", "KW_TEXTURE2DARRAY", "KW_TEXTURE2DMS", + "KW_TEXTURE2DMSARRAY", "KW_TEXTURE3D", "KW_TEXTURE3DARRAY", + "KW_TEXTURECUBE", "KW_TRUE", "KW_TYPEDEF", "KW_UNIFORM", "KW_VECTOR", + "KW_VERTEXSHADER", "KW_VOID", "KW_VOLATILE", "KW_WHILE", "OP_INC", + "OP_DEC", "OP_AND", "OP_OR", "OP_EQ", "OP_LEFTSHIFT", + "OP_LEFTSHIFTASSIGN", "OP_RIGHTSHIFT", "OP_RIGHTSHIFTASSIGN", + "OP_ELLIPSIS", "OP_LE", "OP_GE", "OP_NE", "OP_ADDASSIGN", "OP_SUBASSIGN", + "OP_MULASSIGN", "OP_DIVASSIGN", "OP_MODASSIGN", "OP_ANDASSIGN", + "OP_ORASSIGN", "OP_XORASSIGN", "OP_UNKNOWN1", "OP_UNKNOWN2", + "OP_UNKNOWN3", "OP_UNKNOWN4", "PRE_LINE", "VAR_IDENTIFIER", + "TYPE_IDENTIFIER", "NEW_IDENTIFIER", "STRING", "C_FLOAT", "C_INTEGER", + "';'", "'{'", "'}'", "'('", "')'", "':'", "','", "'<'", "'>'", "'='", + "'['", "']'", "'.'", "'+'", "'-'", "'!'", "'~'", "'*'", "'/'", "'%'", + "'&'", "'^'", "'|'", "'?'", "$accept", "hlsl_prog", "preproc_directive", + "struct_declaration", "struct_spec", "named_struct_spec", + "unnamed_struct_spec", "any_identifier", "fields_list", "field", + "func_declaration", "func_prototype", "compound_statement", + "scope_start", "var_identifier", "semantic", "parameters", "param_list", + "parameter", "input_mods", "input_mod", "type", "base_type", + "declaration_statement", "typedef", "type_specs", "type_spec", + "declaration", "variables_def_optional", "variables_def", "variable_def", + "array", "var_modifiers", "complex_initializer", "initializer_expr", + "initializer_expr_list", "boolean", "statement_list", "statement", + "jump_statement", "selection_statement", "if_body", "loop_statement", + "expr_statement", "primary_expr", "variable", "postfix_expr", + "unary_expr", "unary_op", "mul_expr", "add_expr", "shift_expr", + "relational_expr", "equality_expr", "bitand_expr", "bitxor_expr", + "bitor_expr", "logicand_expr", "logicor_expr", "conditional_expr", + "assignment_expr", "assign_op", "expr", 0 +}; +#endif + +# ifdef YYPRINT +/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to + token YYLEX-NUM. */ +static const yytype_uint16 yytoknum[] = +{ + 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, + 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, + 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, + 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, + 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, + 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, + 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, + 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, + 335, 336, 337, 338, 339, 340, 341, 342, 343, 344, + 345, 346, 347, 348, 349, 350, 351, 352, 353, 354, + 355, 356, 357, 358, 359, 59, 123, 125, 40, 41, + 58, 44, 60, 62, 61, 91, 93, 46, 43, 45, + 33, 126, 42, 47, 37, 38, 94, 124, 63 +}; +# endif + +/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ +static const yytype_uint8 yyr1[] = +{ + 0, 129, 130, 130, 130, 130, 130, 131, 132, 133, + 133, 134, 135, 136, 136, 136, 137, 137, 138, 138, + 139, 139, 140, 141, 141, 142, 143, 143, 144, 144, + 145, 145, 146, 146, 147, 148, 148, 149, 149, 149, + 150, 150, 150, 151, 151, 151, 151, 151, 151, 151, + 151, 152, 152, 152, 153, 153, 154, 154, 155, 156, + 157, 157, 158, 158, 159, 159, 160, 160, 161, 161, + 161, 161, 161, 161, 161, 161, 161, 161, 161, 161, + 162, 162, 162, 163, 164, 164, 165, 165, 166, 166, + 167, 167, 167, 167, 167, 167, 168, 169, 170, 170, + 171, 171, 171, 171, 172, 172, 173, 173, 173, 173, + 173, 174, 175, 175, 175, 175, 175, 175, 176, 176, + 176, 176, 176, 177, 177, 177, 177, 178, 178, 178, + 178, 179, 179, 179, 180, 180, 180, 181, 181, 181, + 181, 181, 182, 182, 182, 183, 183, 184, 184, 185, + 185, 186, 186, 187, 187, 188, 188, 189, 189, 190, + 190, 190, 190, 190, 190, 190, 190, 190, 190, 190, + 191, 191 +}; + +/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ +static const yytype_uint8 yyr2[] = +{ + 0, 2, 0, 2, 2, 2, 2, 2, 3, 1, + 1, 6, 5, 1, 1, 1, 0, 2, 4, 3, + 2, 2, 7, 2, 4, 0, 1, 1, 0, 2, + 1, 2, 1, 3, 5, 0, 2, 1, 1, 1, + 1, 6, 8, 1, 1, 1, 1, 1, 1, 1, + 2, 1, 1, 1, 5, 4, 1, 3, 2, 4, + 0, 1, 1, 3, 3, 5, 0, 3, 0, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 1, 3, 4, 1, 1, 3, 1, 1, 1, 2, + 1, 1, 1, 1, 1, 1, 3, 5, 1, 3, + 5, 7, 8, 8, 1, 2, 1, 1, 1, 1, + 3, 1, 1, 2, 2, 3, 4, 5, 1, 2, + 2, 2, 6, 1, 1, 1, 1, 1, 3, 3, + 3, 1, 3, 3, 1, 3, 3, 1, 3, 3, + 3, 3, 1, 3, 3, 1, 3, 1, 3, 1, + 3, 1, 3, 1, 3, 1, 5, 1, 3, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 3 +}; + +/* YYDEFACT[STATE-NAME] -- Default reduction number in state STATE-NUM. + Performed when YYTABLE doesn't specify something else to do. Zero + means the default is an error. */ +static const yytype_uint8 yydefact[] = +{ + 2, 68, 1, 68, 68, 68, 68, 68, 68, 68, + 68, 68, 68, 68, 68, 0, 6, 5, 52, 60, + 9, 10, 3, 0, 4, 53, 51, 0, 79, 77, + 69, 73, 70, 71, 78, 72, 74, 0, 0, 75, + 76, 7, 13, 14, 15, 66, 0, 61, 62, 21, + 25, 20, 0, 44, 45, 46, 47, 48, 0, 0, + 43, 49, 0, 40, 66, 0, 56, 0, 68, 28, + 8, 0, 23, 68, 0, 50, 16, 0, 0, 13, + 15, 0, 0, 58, 55, 0, 0, 87, 86, 68, + 68, 111, 106, 107, 68, 123, 124, 125, 126, 0, + 108, 112, 109, 118, 127, 68, 131, 134, 137, 142, + 145, 147, 149, 151, 153, 155, 157, 170, 0, 0, + 64, 63, 68, 0, 0, 68, 0, 104, 92, 90, + 0, 68, 88, 93, 94, 95, 91, 0, 0, 0, + 68, 16, 0, 25, 59, 57, 54, 119, 120, 0, + 0, 0, 113, 114, 68, 0, 165, 166, 160, 161, + 162, 163, 164, 167, 168, 169, 159, 68, 121, 68, + 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, + 68, 68, 68, 68, 68, 68, 68, 68, 68, 67, + 29, 68, 0, 25, 68, 0, 68, 0, 24, 89, + 105, 50, 0, 12, 0, 17, 0, 68, 0, 35, + 0, 66, 110, 68, 0, 115, 158, 128, 129, 130, + 127, 132, 133, 135, 136, 140, 141, 138, 139, 143, + 144, 146, 148, 150, 152, 154, 0, 171, 68, 65, + 80, 83, 0, 68, 0, 96, 0, 0, 0, 0, + 0, 11, 0, 31, 32, 68, 28, 0, 84, 0, + 116, 68, 0, 68, 68, 0, 68, 68, 68, 0, + 19, 0, 41, 35, 37, 39, 38, 36, 0, 22, + 68, 117, 68, 156, 81, 68, 0, 68, 68, 98, + 97, 100, 0, 18, 33, 0, 122, 85, 82, 0, + 0, 0, 68, 42, 28, 101, 68, 68, 99, 34, + 103, 102 +}; + +/* YYDEFGOTO[NTERM-NUM]. */ +static const yytype_int16 yydefgoto[] = +{ + -1, 1, 17, 18, 19, 20, 21, 45, 140, 205, + 22, 23, 128, 73, 81, 120, 210, 253, 254, 255, + 277, 197, 63, 129, 25, 65, 66, 26, 46, 82, + 48, 69, 99, 239, 258, 259, 100, 131, 132, 133, + 134, 290, 135, 136, 101, 102, 103, 104, 105, 106, + 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, + 117, 167, 137 +}; + +/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing + STATE-NUM. */ +#define YYPACT_NINF -231 +static const yytype_int16 yypact[] = +{ + -231, 640, -231, 777, 777, 777, 777, 777, 777, 777, + 777, 777, 777, 777, 777, -69, -231, -231, -231, 32, + -231, -231, -231, 118, -231, -231, -231, 12, -231, -231, + -231, -231, -231, -231, -231, -231, -231, 32, 12, -231, + -231, -231, -231, -231, -231, -67, -41, -26, -231, -231, + 8, -231, -20, -231, -231, -231, -231, -231, -60, 14, + -231, -231, 72, -231, -67, -81, -231, 32, 579, -39, + -231, 32, -231, 320, 145, 28, -231, 34, 145, 15, + 35, 74, -15, -231, -231, 32, -10, -231, -231, 579, + 579, -231, -231, -231, 579, -231, -231, -231, -231, 37, + -231, -231, -231, -18, 182, 579, 52, 86, -19, -55, + -40, 66, 70, 90, 126, -44, -231, -231, 2, 32, + 127, -231, 320, 105, 124, 579, 135, -231, -231, -231, + 12, 212, -231, -231, -231, -231, -231, -7, 125, 137, + 684, -231, 141, -231, -231, -231, -231, -231, -231, 37, + 79, 147, -231, -231, 579, 32, -231, -231, -231, -231, + -231, -231, -231, -231, -231, -231, -231, 579, -231, 579, + 579, 579, 579, 579, 579, 579, 579, 579, 579, 579, + 579, 579, 579, 579, 579, 579, 579, 579, 579, -231, + -231, 399, 181, -231, 579, -5, 579, -65, -231, -231, + -231, -231, 154, -231, 32, -231, 139, 716, 158, 155, + 167, -48, -231, 579, 11, -231, -231, -231, -231, -231, + -231, 52, 52, 86, 86, -19, -19, -19, -19, -55, + -55, -40, 66, 70, 90, 126, 117, -231, 579, -231, + -231, -231, 174, 439, 83, -231, 88, 176, -2, 10, + 32, -231, 175, 178, -231, 745, -39, 183, -231, 99, + -231, 579, 17, 579, 439, 37, 439, 320, 320, 186, + -231, 9, -231, -231, -231, -231, -231, -231, 37, -231, + 579, -231, 579, -231, -231, 518, 103, 579, 579, 275, + -231, -231, 180, -231, -231, 32, -231, -231, -231, 189, + 107, 111, 320, -231, -39, -231, 320, 320, -231, -231, + -231, -231 +}; + +/* YYPGOTO[NTERM-NUM]. */ +static const yytype_int16 yypgoto[] = +{ + -231, -231, -231, -231, 283, -231, -119, -36, 156, -231, + -231, -231, 276, -123, -231, -230, -231, -231, 25, -231, + -231, -13, 51, 299, -231, 235, 218, 61, -231, -4, + 236, -45, -1, -231, -174, 71, -231, -231, -104, -231, + -231, -231, -231, -175, -231, -231, -231, -24, -231, 65, + 76, -9, 100, 128, 129, 130, 123, 136, -231, -231, + -144, -231, -52 +}; + +/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If + positive, shift that token. If negative, reduce the rule which + number is the opposite. If YYTABLE_NINF, syntax error. */ +#define YYTABLE_NINF -31 +static const yytype_int16 yytable[] = +{ + 27, 64, 28, 29, 30, 31, 32, 33, 34, 35, + 36, 38, 39, 40, 62, 47, 118, 240, 192, 83, + 209, 204, 77, 216, 84, 67, 279, 199, 176, 177, + 85, 64, 186, 41, 42, 43, 44, 180, 52, 42, + 75, 44, 150, 213, 237, 181, 76, 241, 68, 64, + 53, 54, 55, 56, 57, 152, 153, 178, 179, 174, + 213, 175, 58, 52, 70, 147, 148, 68, 266, 241, + 243, 119, 130, 195, 309, 53, 54, 55, 56, 57, + 59, 168, 60, 190, 187, 71, 151, 138, 204, 287, + 144, 288, 74, 149, 241, 146, 71, 154, 200, 155, + 245, 85, 214, 270, 188, 59, 188, 60, 297, 71, + 201, 297, 61, 188, 293, 72, 76, 283, 189, 215, + 71, 130, 188, -26, 284, 139, 78, 260, 285, 142, + 130, 42, 43, 44, -14, 236, 211, 61, 241, 206, + 141, 241, 244, -27, 246, 217, 218, 219, 220, 220, + 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, + 220, 220, 220, 289, 291, 52, 257, 225, 226, 227, + 228, 79, 43, 80, 169, 170, 171, 53, 54, 55, + 56, 57, 143, 53, 54, 55, 56, 57, 212, 249, + 188, 182, 267, 250, 188, 138, 183, 268, 308, 188, + 248, 185, 310, 311, 172, 173, 206, 59, 281, 60, + 282, 286, 299, 193, 188, 60, 306, 184, 188, 3, + 307, 4, 188, 49, 50, 201, 122, 261, 188, 5, + 87, 123, 194, 6, 124, 300, 301, 221, 222, 61, + 7, 191, 265, 196, 8, 61, 271, 125, 202, 9, + 223, 224, 208, 242, 278, 213, 296, 10, 247, 304, + 11, 156, 252, 157, -30, 295, 130, 130, 158, 159, + 160, 161, 162, 163, 164, 165, 256, 88, 12, 13, + 229, 230, 263, 14, 126, 89, 90, 269, 272, 273, + 292, 302, 280, 303, 305, 37, 166, 207, 294, 51, + 24, 130, 86, 145, 264, 130, 130, 121, 234, 262, + 231, 91, 232, 0, 233, 92, 93, 127, 50, 198, + 94, 0, 235, 0, 0, 0, 0, 3, 0, 4, + 95, 96, 97, 98, 122, 0, 0, 5, 87, 123, + 0, 6, 124, 0, 0, 0, 0, 0, 7, 0, + 0, 0, 8, 0, 0, 125, 0, 9, 0, 0, + 0, 0, 0, 0, 0, 10, 0, 0, 11, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 88, 12, 13, 0, 0, + 0, 14, 126, 89, 90, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 3, 0, 4, 0, + 0, 0, 0, 0, 0, 0, 5, 87, 0, 91, + 6, 0, 0, 92, 93, 127, 50, 7, 94, 0, + 0, 8, 0, 0, 0, 0, 9, 0, 95, 96, + 97, 98, 0, 0, 10, 0, 3, 11, 4, 0, + 0, 0, 0, 0, 0, 0, 5, 87, 0, 0, + 6, 0, 0, 0, 88, 0, 13, 7, 0, 0, + 14, 8, 89, 90, 0, 0, 9, 0, 0, 0, + 0, 0, 0, 0, 10, 0, 0, 11, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 91, 0, + 0, 0, 92, 93, 88, 238, 13, 94, 0, 0, + 14, 0, 89, 90, 0, 0, 0, 95, 96, 97, + 98, 0, 0, 0, 0, 3, 0, 4, 0, 0, + 0, 0, 0, 0, 0, 5, 87, 0, 91, 6, + 0, 0, 92, 93, 127, 0, 7, 94, 0, 0, + 8, 0, 0, 0, 0, 9, 0, 95, 96, 97, + 98, 0, 0, 10, 0, 0, 11, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 88, 0, 13, 3, 0, 4, 14, + 0, 89, 90, 0, 0, 0, 5, 87, 0, 0, + 6, 0, 0, 0, 0, 0, 0, 7, 0, 0, + 0, 8, 0, 0, 0, 0, 9, 91, 0, 0, + 0, 92, 93, 0, 10, 298, 94, 11, 0, 0, + 0, 0, 0, 0, 0, 0, 95, 96, 97, 98, + 2, 0, 0, 0, 88, 0, 13, 3, 0, 4, + 14, 0, 89, 90, 0, 0, 0, 5, 0, 0, + 0, 6, 0, 0, 0, 0, 0, 0, 7, 0, + 0, 0, 8, 0, 0, 0, 0, 9, 91, 0, + 0, 0, 92, 93, 0, 10, 0, 94, 11, 0, + 0, 3, 0, 4, 0, 0, 0, 95, 96, 97, + 98, 5, 0, 0, 0, 6, 12, 13, 0, 0, + 0, 14, 7, 0, 0, 0, 8, 0, 0, 0, + 0, 9, 0, 3, 0, 4, 0, 0, 0, 10, + 0, 0, 11, 5, 0, 0, 0, 6, 15, 0, + 0, 0, 0, 0, 7, 16, 0, 0, 8, 0, + 0, 13, 3, 9, 4, 14, 0, 0, 0, 0, + 0, 10, 5, 0, 11, 0, 6, 0, 274, 0, + 275, 0, 0, 7, 276, 0, 0, 8, 0, 0, + 0, 0, 9, 13, 3, 0, 4, 14, 0, 0, + 10, 203, 0, 11, 5, 0, 0, 0, 6, 0, + 0, 0, 0, 0, 0, 7, 0, 0, 0, 8, + 0, 0, 13, 0, 9, 0, 14, 0, 0, 0, + 0, 0, 10, 251, 0, 11, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 13, 0, 0, 0, 14 +}; + +#define yypact_value_is_default(yystate) \ + ((yystate) == (-231)) + +#define yytable_value_is_error(yytable_value) \ + YYID (0) + +static const yytype_int16 yycheck[] = +{ + 1, 37, 3, 4, 5, 6, 7, 8, 9, 10, + 11, 12, 13, 14, 27, 19, 68, 191, 122, 64, + 143, 140, 58, 167, 105, 38, 256, 131, 83, 84, + 111, 67, 76, 102, 99, 100, 101, 77, 26, 99, + 100, 101, 94, 108, 188, 85, 106, 191, 115, 85, + 38, 39, 40, 41, 42, 73, 74, 112, 113, 78, + 108, 80, 50, 26, 105, 89, 90, 115, 243, 213, + 193, 110, 73, 125, 304, 38, 39, 40, 41, 42, + 68, 105, 70, 119, 128, 111, 99, 50, 207, 264, + 105, 266, 112, 94, 238, 105, 111, 115, 105, 117, + 105, 111, 154, 105, 111, 68, 111, 70, 282, 111, + 100, 285, 100, 111, 105, 107, 106, 261, 116, 155, + 111, 122, 111, 108, 107, 74, 112, 116, 111, 78, + 131, 99, 100, 101, 106, 187, 149, 100, 282, 140, + 106, 285, 194, 108, 196, 169, 170, 171, 172, 173, + 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, + 184, 185, 186, 267, 268, 26, 211, 176, 177, 178, + 179, 99, 100, 101, 122, 123, 124, 38, 39, 40, + 41, 42, 108, 38, 39, 40, 41, 42, 109, 50, + 111, 125, 109, 206, 111, 50, 126, 109, 302, 111, + 204, 75, 306, 307, 118, 119, 207, 68, 109, 70, + 111, 263, 109, 108, 111, 70, 109, 127, 111, 7, + 109, 9, 111, 105, 106, 100, 14, 110, 111, 17, + 18, 19, 108, 21, 22, 287, 288, 172, 173, 100, + 28, 114, 243, 108, 32, 100, 250, 35, 111, 37, + 174, 175, 111, 72, 255, 108, 280, 45, 104, 295, + 48, 79, 104, 81, 109, 278, 267, 268, 86, 87, + 88, 89, 90, 91, 92, 93, 109, 65, 66, 67, + 180, 181, 108, 71, 72, 73, 74, 111, 113, 111, + 104, 16, 109, 113, 105, 12, 114, 141, 273, 23, + 1, 302, 67, 85, 243, 306, 307, 71, 185, 238, + 182, 99, 183, -1, 184, 103, 104, 105, 106, 107, + 108, -1, 186, -1, -1, -1, -1, 7, -1, 9, + 118, 119, 120, 121, 14, -1, -1, 17, 18, 19, + -1, 21, 22, -1, -1, -1, -1, -1, 28, -1, + -1, -1, 32, -1, -1, 35, -1, 37, -1, -1, + -1, -1, -1, -1, -1, 45, -1, -1, 48, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, 65, 66, 67, -1, -1, + -1, 71, 72, 73, 74, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 7, -1, 9, -1, + -1, -1, -1, -1, -1, -1, 17, 18, -1, 99, + 21, -1, -1, 103, 104, 105, 106, 28, 108, -1, + -1, 32, -1, -1, -1, -1, 37, -1, 118, 119, + 120, 121, -1, -1, 45, -1, 7, 48, 9, -1, + -1, -1, -1, -1, -1, -1, 17, 18, -1, -1, + 21, -1, -1, -1, 65, -1, 67, 28, -1, -1, + 71, 32, 73, 74, -1, -1, 37, -1, -1, -1, + -1, -1, -1, -1, 45, -1, -1, 48, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, 99, -1, + -1, -1, 103, 104, 65, 106, 67, 108, -1, -1, + 71, -1, 73, 74, -1, -1, -1, 118, 119, 120, + 121, -1, -1, -1, -1, 7, -1, 9, -1, -1, + -1, -1, -1, -1, -1, 17, 18, -1, 99, 21, + -1, -1, 103, 104, 105, -1, 28, 108, -1, -1, + 32, -1, -1, -1, -1, 37, -1, 118, 119, 120, + 121, -1, -1, 45, -1, -1, 48, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 65, -1, 67, 7, -1, 9, 71, + -1, 73, 74, -1, -1, -1, 17, 18, -1, -1, + 21, -1, -1, -1, -1, -1, -1, 28, -1, -1, + -1, 32, -1, -1, -1, -1, 37, 99, -1, -1, + -1, 103, 104, -1, 45, 107, 108, 48, -1, -1, + -1, -1, -1, -1, -1, -1, 118, 119, 120, 121, + 0, -1, -1, -1, 65, -1, 67, 7, -1, 9, + 71, -1, 73, 74, -1, -1, -1, 17, -1, -1, + -1, 21, -1, -1, -1, -1, -1, -1, 28, -1, + -1, -1, 32, -1, -1, -1, -1, 37, 99, -1, + -1, -1, 103, 104, -1, 45, -1, 108, 48, -1, + -1, 7, -1, 9, -1, -1, -1, 118, 119, 120, + 121, 17, -1, -1, -1, 21, 66, 67, -1, -1, + -1, 71, 28, -1, -1, -1, 32, -1, -1, -1, + -1, 37, -1, 7, -1, 9, -1, -1, -1, 45, + -1, -1, 48, 17, -1, -1, -1, 21, 98, -1, + -1, -1, -1, -1, 28, 105, -1, -1, 32, -1, + -1, 67, 7, 37, 9, 71, -1, -1, -1, -1, + -1, 45, 17, -1, 48, -1, 21, -1, 23, -1, + 25, -1, -1, 28, 29, -1, -1, 32, -1, -1, + -1, -1, 37, 67, 7, -1, 9, 71, -1, -1, + 45, 107, -1, 48, 17, -1, -1, -1, 21, -1, + -1, -1, -1, -1, -1, 28, -1, -1, -1, 32, + -1, -1, 67, -1, 37, -1, 71, -1, -1, -1, + -1, -1, 45, 107, -1, 48, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, 67, -1, -1, -1, 71 +}; + +/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing + symbol of state STATE-NUM. */ +static const yytype_uint8 yystos[] = +{ + 0, 130, 0, 7, 9, 17, 21, 28, 32, 37, + 45, 48, 66, 67, 71, 98, 105, 131, 132, 133, + 134, 135, 139, 140, 152, 153, 156, 161, 161, 161, + 161, 161, 161, 161, 161, 161, 161, 133, 161, 161, + 161, 102, 99, 100, 101, 136, 157, 158, 159, 105, + 106, 141, 26, 38, 39, 40, 41, 42, 50, 68, + 70, 100, 150, 151, 136, 154, 155, 150, 115, 160, + 105, 111, 107, 142, 112, 100, 106, 136, 112, 99, + 101, 143, 158, 160, 105, 111, 154, 18, 65, 73, + 74, 99, 103, 104, 108, 118, 119, 120, 121, 161, + 165, 173, 174, 175, 176, 177, 178, 179, 180, 181, + 182, 183, 184, 185, 186, 187, 188, 189, 191, 110, + 144, 159, 14, 19, 22, 35, 72, 105, 141, 152, + 161, 166, 167, 168, 169, 171, 172, 191, 50, 151, + 137, 106, 151, 108, 105, 155, 105, 176, 176, 161, + 191, 150, 73, 74, 115, 117, 79, 81, 86, 87, + 88, 89, 90, 91, 92, 93, 114, 190, 176, 122, + 123, 124, 118, 119, 78, 80, 83, 84, 112, 113, + 77, 85, 125, 126, 127, 75, 76, 128, 111, 116, + 136, 114, 167, 108, 108, 191, 108, 150, 107, 167, + 105, 100, 111, 107, 135, 138, 161, 137, 111, 142, + 145, 150, 109, 108, 191, 136, 189, 176, 176, 176, + 176, 178, 178, 179, 179, 180, 180, 180, 180, 181, + 181, 182, 183, 184, 185, 186, 191, 189, 106, 162, + 163, 189, 72, 142, 191, 105, 191, 104, 158, 50, + 150, 107, 104, 146, 147, 148, 109, 160, 163, 164, + 116, 110, 164, 108, 156, 161, 172, 109, 109, 111, + 105, 158, 113, 111, 23, 25, 29, 149, 161, 144, + 109, 109, 111, 189, 107, 111, 191, 172, 172, 167, + 170, 167, 104, 105, 147, 150, 176, 163, 107, 109, + 191, 191, 16, 113, 136, 105, 109, 109, 167, 144, + 167, 167 +}; + +#define yyerrok (yyerrstatus = 0) +#define yyclearin (yychar = YYEMPTY) +#define YYEMPTY (-2) +#define YYEOF 0 + +#define YYACCEPT goto yyacceptlab +#define YYABORT goto yyabortlab +#define YYERROR goto yyerrorlab + + +/* Like YYERROR except do call yyerror. This remains here temporarily + to ease the transition to the new meaning of YYERROR, for GCC. + Once GCC version 2 has supplanted version 1, this can go. However, + YYFAIL appears to be in use. Nevertheless, it is formally deprecated + in Bison 2.4.2's NEWS entry, where a plan to phase it out is + discussed. */ + +#define YYFAIL goto yyerrlab +#if defined YYFAIL + /* This is here to suppress warnings from the GCC cpp's + -Wunused-macros. Normally we don't worry about that warning, but + some users do, and we want to make it easy for users to remove + YYFAIL uses, which will produce warnings from Bison 2.5. */ +#endif + +#define YYRECOVERING() (!!yyerrstatus) + +#define YYBACKUP(Token, Value) \ +do \ + if (yychar == YYEMPTY && yylen == 1) \ + { \ + yychar = (Token); \ + yylval = (Value); \ + YYPOPSTACK (1); \ + goto yybackup; \ + } \ + else \ + { \ + yyerror (YY_("syntax error: cannot back up")); \ + YYERROR; \ + } \ +while (YYID (0)) + + +#define YYTERROR 1 +#define YYERRCODE 256 + + +/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. + If N is 0, then set CURRENT to the empty location which ends + the previous symbol: RHS[0] (always defined). */ + +#define YYRHSLOC(Rhs, K) ((Rhs)[K]) +#ifndef YYLLOC_DEFAULT +# define YYLLOC_DEFAULT(Current, Rhs, N) \ + do \ + if (YYID (N)) \ + { \ + (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \ + (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \ + (Current).last_line = YYRHSLOC (Rhs, N).last_line; \ + (Current).last_column = YYRHSLOC (Rhs, N).last_column; \ + } \ + else \ + { \ + (Current).first_line = (Current).last_line = \ + YYRHSLOC (Rhs, 0).last_line; \ + (Current).first_column = (Current).last_column = \ + YYRHSLOC (Rhs, 0).last_column; \ + } \ + while (YYID (0)) +#endif + + +/* YY_LOCATION_PRINT -- Print the location on the stream. + This macro was not mandated originally: define only if we know + we won't break user code: when these are the locations we know. */ + +#ifndef YY_LOCATION_PRINT +# if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL +# define YY_LOCATION_PRINT(File, Loc) \ + fprintf (File, "%d.%d-%d.%d", \ + (Loc).first_line, (Loc).first_column, \ + (Loc).last_line, (Loc).last_column) +# else +# define YY_LOCATION_PRINT(File, Loc) ((void) 0) +# endif +#endif + + +/* YYLEX -- calling `yylex' with the right arguments. */ + +#ifdef YYLEX_PARAM +# define YYLEX yylex (YYLEX_PARAM) +#else +# define YYLEX yylex () +#endif + +/* Enable debugging if requested. */ +#if YYDEBUG + +# ifndef YYFPRINTF +# include /* INFRINGES ON USER NAME SPACE */ +# define YYFPRINTF fprintf +# endif + +# define YYDPRINTF(Args) \ +do { \ + if (yydebug) \ + YYFPRINTF Args; \ +} while (YYID (0)) + +# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ +do { \ + if (yydebug) \ + { \ + YYFPRINTF (stderr, "%s ", Title); \ + yy_symbol_print (stderr, \ + Type, Value, Location); \ + YYFPRINTF (stderr, "\n"); \ + } \ +} while (YYID (0)) + + +/*--------------------------------. +| Print this symbol on YYOUTPUT. | +`--------------------------------*/ + +/*ARGSUSED*/ +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static void +yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp) +#else +static void +yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp) + FILE *yyoutput; + int yytype; + YYSTYPE const * const yyvaluep; + YYLTYPE const * const yylocationp; +#endif +{ + if (!yyvaluep) + return; + YYUSE (yylocationp); +# ifdef YYPRINT + if (yytype < YYNTOKENS) + YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); +# else + YYUSE (yyoutput); +# endif + switch (yytype) + { + default: + break; + } +} + + +/*--------------------------------. +| Print this symbol on YYOUTPUT. | +`--------------------------------*/ + +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static void +yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp) +#else +static void +yy_symbol_print (yyoutput, yytype, yyvaluep, yylocationp) + FILE *yyoutput; + int yytype; + YYSTYPE const * const yyvaluep; + YYLTYPE const * const yylocationp; +#endif +{ + if (yytype < YYNTOKENS) + YYFPRINTF (yyoutput, "token %s (", yytname[yytype]); + else + YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]); + + YY_LOCATION_PRINT (yyoutput, *yylocationp); + YYFPRINTF (yyoutput, ": "); + yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp); + YYFPRINTF (yyoutput, ")"); +} + +/*------------------------------------------------------------------. +| yy_stack_print -- Print the state stack from its BOTTOM up to its | +| TOP (included). | +`------------------------------------------------------------------*/ + +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static void +yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop) +#else +static void +yy_stack_print (yybottom, yytop) + yytype_int16 *yybottom; + yytype_int16 *yytop; +#endif +{ + YYFPRINTF (stderr, "Stack now"); + for (; yybottom <= yytop; yybottom++) + { + int yybot = *yybottom; + YYFPRINTF (stderr, " %d", yybot); + } + YYFPRINTF (stderr, "\n"); +} + +# define YY_STACK_PRINT(Bottom, Top) \ +do { \ + if (yydebug) \ + yy_stack_print ((Bottom), (Top)); \ +} while (YYID (0)) + + +/*------------------------------------------------. +| Report that the YYRULE is going to be reduced. | +`------------------------------------------------*/ + +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static void +yy_reduce_print (YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule) +#else +static void +yy_reduce_print (yyvsp, yylsp, yyrule) + YYSTYPE *yyvsp; + YYLTYPE *yylsp; + int yyrule; +#endif +{ + int yynrhs = yyr2[yyrule]; + int yyi; + unsigned long int yylno = yyrline[yyrule]; + YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n", + yyrule - 1, yylno); + /* The symbols being reduced. */ + for (yyi = 0; yyi < yynrhs; yyi++) + { + YYFPRINTF (stderr, " $%d = ", yyi + 1); + yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi], + &(yyvsp[(yyi + 1) - (yynrhs)]) + , &(yylsp[(yyi + 1) - (yynrhs)]) ); + YYFPRINTF (stderr, "\n"); + } +} + +# define YY_REDUCE_PRINT(Rule) \ +do { \ + if (yydebug) \ + yy_reduce_print (yyvsp, yylsp, Rule); \ +} while (YYID (0)) + +/* Nonzero means print parse trace. It is left uninitialized so that + multiple parsers can coexist. */ +int yydebug; +#else /* !YYDEBUG */ +# define YYDPRINTF(Args) +# define YY_SYMBOL_PRINT(Title, Type, Value, Location) +# define YY_STACK_PRINT(Bottom, Top) +# define YY_REDUCE_PRINT(Rule) +#endif /* !YYDEBUG */ + + +/* YYINITDEPTH -- initial size of the parser's stacks. */ +#ifndef YYINITDEPTH +# define YYINITDEPTH 200 +#endif + +/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only + if the built-in stack extension method is used). + + Do not make this value too large; the results are undefined if + YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH) + evaluated with infinite-precision integer arithmetic. */ + +#ifndef YYMAXDEPTH +# define YYMAXDEPTH 10000 +#endif + + +#if YYERROR_VERBOSE + +# ifndef yystrlen +# if defined __GLIBC__ && defined _STRING_H +# define yystrlen strlen +# else +/* Return the length of YYSTR. */ +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static YYSIZE_T +yystrlen (const char *yystr) +#else +static YYSIZE_T +yystrlen (yystr) + const char *yystr; +#endif +{ + YYSIZE_T yylen; + for (yylen = 0; yystr[yylen]; yylen++) + continue; + return yylen; +} +# endif +# endif + +# ifndef yystpcpy +# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE +# define yystpcpy stpcpy +# else +/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in + YYDEST. */ +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static char * +yystpcpy (char *yydest, const char *yysrc) +#else +static char * +yystpcpy (yydest, yysrc) + char *yydest; + const char *yysrc; +#endif +{ + char *yyd = yydest; + const char *yys = yysrc; + + while ((*yyd++ = *yys++) != '\0') + continue; + + return yyd - 1; +} +# endif +# endif + +# ifndef yytnamerr +/* Copy to YYRES the contents of YYSTR after stripping away unnecessary + quotes and backslashes, so that it's suitable for yyerror. The + heuristic is that double-quoting is unnecessary unless the string + contains an apostrophe, a comma, or backslash (other than + backslash-backslash). YYSTR is taken from yytname. If YYRES is + null, do not copy; instead, return the length of what the result + would have been. */ +static YYSIZE_T +yytnamerr (char *yyres, const char *yystr) +{ + if (*yystr == '"') + { + YYSIZE_T yyn = 0; + char const *yyp = yystr; + + for (;;) + switch (*++yyp) + { + case '\'': + case ',': + goto do_not_strip_quotes; + + case '\\': + if (*++yyp != '\\') + goto do_not_strip_quotes; + /* Fall through. */ + default: + if (yyres) + yyres[yyn] = *yyp; + yyn++; + break; + + case '"': + if (yyres) + yyres[yyn] = '\0'; + return yyn; + } + do_not_strip_quotes: ; + } + + if (! yyres) + return yystrlen (yystr); + + return yystpcpy (yyres, yystr) - yyres; +} +# endif + +/* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message + about the unexpected token YYTOKEN for the state stack whose top is + YYSSP. + + Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is + not large enough to hold the message. In that case, also set + *YYMSG_ALLOC to the required number of bytes. Return 2 if the + required number of bytes is too large to store. */ +static int +yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, + yytype_int16 *yyssp, int yytoken) +{ + YYSIZE_T yysize0 = yytnamerr (0, yytname[yytoken]); + YYSIZE_T yysize = yysize0; + YYSIZE_T yysize1; + enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; + /* Internationalized format string. */ + const char *yyformat = 0; + /* Arguments of yyformat. */ + char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; + /* Number of reported tokens (one for the "unexpected", one per + "expected"). */ + int yycount = 0; + + /* There are many possibilities here to consider: + - Assume YYFAIL is not used. It's too flawed to consider. See + + for details. YYERROR is fine as it does not invoke this + function. + - If this state is a consistent state with a default action, then + the only way this function was invoked is if the default action + is an error action. In that case, don't check for expected + tokens because there are none. + - The only way there can be no lookahead present (in yychar) is if + this state is a consistent state with a default action. Thus, + detecting the absence of a lookahead is sufficient to determine + that there is no unexpected or expected token to report. In that + case, just report a simple "syntax error". + - Don't assume there isn't a lookahead just because this state is a + consistent state with a default action. There might have been a + previous inconsistent state, consistent state with a non-default + action, or user semantic action that manipulated yychar. + - Of course, the expected token list depends on states to have + correct lookahead information, and it depends on the parser not + to perform extra reductions after fetching a lookahead from the + scanner and before detecting a syntax error. Thus, state merging + (from LALR or IELR) and default reductions corrupt the expected + token list. However, the list is correct for canonical LR with + one exception: it will still contain any token that will not be + accepted due to an error action in a later state. + */ + if (yytoken != YYEMPTY) + { + int yyn = yypact[*yyssp]; + yyarg[yycount++] = yytname[yytoken]; + if (!yypact_value_is_default (yyn)) + { + /* Start YYX at -YYN if negative to avoid negative indexes in + YYCHECK. In other words, skip the first -YYN actions for + this state because they are default actions. */ + int yyxbegin = yyn < 0 ? -yyn : 0; + /* Stay within bounds of both yycheck and yytname. */ + int yychecklim = YYLAST - yyn + 1; + int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; + int yyx; + + for (yyx = yyxbegin; yyx < yyxend; ++yyx) + if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR + && !yytable_value_is_error (yytable[yyx + yyn])) + { + if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) + { + yycount = 1; + yysize = yysize0; + break; + } + yyarg[yycount++] = yytname[yyx]; + yysize1 = yysize + yytnamerr (0, yytname[yyx]); + if (! (yysize <= yysize1 + && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) + return 2; + yysize = yysize1; + } + } + } + + switch (yycount) + { +# define YYCASE_(N, S) \ + case N: \ + yyformat = S; \ + break + YYCASE_(0, YY_("syntax error")); + YYCASE_(1, YY_("syntax error, unexpected %s")); + YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s")); + YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s")); + YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s")); + YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s")); +# undef YYCASE_ + } + + yysize1 = yysize + yystrlen (yyformat); + if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) + return 2; + yysize = yysize1; + + if (*yymsg_alloc < yysize) + { + *yymsg_alloc = 2 * yysize; + if (! (yysize <= *yymsg_alloc + && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM)) + *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM; + return 1; + } + + /* Avoid sprintf, as that infringes on the user's name space. + Don't have undefined behavior even if the translation + produced a string with the wrong number of "%s"s. */ + { + char *yyp = *yymsg; + int yyi = 0; + while ((*yyp = *yyformat) != '\0') + if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount) + { + yyp += yytnamerr (yyp, yyarg[yyi++]); + yyformat += 2; + } + else + { + yyp++; + yyformat++; + } + } + return 0; +} +#endif /* YYERROR_VERBOSE */ + +/*-----------------------------------------------. +| Release the memory associated to this symbol. | +`-----------------------------------------------*/ + +/*ARGSUSED*/ +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static void +yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp) +#else +static void +yydestruct (yymsg, yytype, yyvaluep, yylocationp) + const char *yymsg; + int yytype; + YYSTYPE *yyvaluep; + YYLTYPE *yylocationp; +#endif +{ + YYUSE (yyvaluep); + YYUSE (yylocationp); + + if (!yymsg) + yymsg = "Deleting"; + YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); + + switch (yytype) + { + + default: + break; + } +} + + +/* Prevent warnings from -Wmissing-prototypes. */ +#ifdef YYPARSE_PARAM +#if defined __STDC__ || defined __cplusplus +int yyparse (void *YYPARSE_PARAM); +#else +int yyparse (); +#endif +#else /* ! YYPARSE_PARAM */ +#if defined __STDC__ || defined __cplusplus +int yyparse (void); +#else +int yyparse (); +#endif +#endif /* ! YYPARSE_PARAM */ + + +/* The lookahead symbol. */ +int yychar; + +/* The semantic value of the lookahead symbol. */ +YYSTYPE yylval; + +/* Location data for the lookahead symbol. */ +YYLTYPE yylloc; + +/* Number of syntax errors so far. */ +int yynerrs; + + +/*----------. +| yyparse. | +`----------*/ + +#ifdef YYPARSE_PARAM +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +int +yyparse (void *YYPARSE_PARAM) +#else +int +yyparse (YYPARSE_PARAM) + void *YYPARSE_PARAM; +#endif +#else /* ! YYPARSE_PARAM */ +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +int +yyparse (void) +#else +int +yyparse () + +#endif +#endif +{ + int yystate; + /* Number of tokens to shift before error messages enabled. */ + int yyerrstatus; + + /* The stacks and their tools: + `yyss': related to states. + `yyvs': related to semantic values. + `yyls': related to locations. + + Refer to the stacks thru separate pointers, to allow yyoverflow + to reallocate them elsewhere. */ + + /* The state stack. */ + yytype_int16 yyssa[YYINITDEPTH]; + yytype_int16 *yyss; + yytype_int16 *yyssp; + + /* The semantic value stack. */ + YYSTYPE yyvsa[YYINITDEPTH]; + YYSTYPE *yyvs; + YYSTYPE *yyvsp; + + /* The location stack. */ + YYLTYPE yylsa[YYINITDEPTH]; + YYLTYPE *yyls; + YYLTYPE *yylsp; + + /* The locations where the error started and ended. */ + YYLTYPE yyerror_range[3]; + + YYSIZE_T yystacksize; + + int yyn; + int yyresult; + /* Lookahead token as an internal (translated) token number. */ + int yytoken; + /* The variables used to return semantic value and location from the + action routines. */ + YYSTYPE yyval; + YYLTYPE yyloc; + +#if YYERROR_VERBOSE + /* Buffer for error messages, and its allocated size. */ + char yymsgbuf[128]; + char *yymsg = yymsgbuf; + YYSIZE_T yymsg_alloc = sizeof yymsgbuf; +#endif + +#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N), yylsp -= (N)) + + /* The number of symbols on the RHS of the reduced rule. + Keep to zero when no symbol should be popped. */ + int yylen = 0; + + yytoken = 0; + yyss = yyssa; + yyvs = yyvsa; + yyls = yylsa; + yystacksize = YYINITDEPTH; + + YYDPRINTF ((stderr, "Starting parse\n")); + + yystate = 0; + yyerrstatus = 0; + yynerrs = 0; + yychar = YYEMPTY; /* Cause a token to be read. */ + + /* Initialize stack pointers. + Waste one element of value and location stack + so that they stay on the same level as the state stack. + The wasted elements are never initialized. */ + yyssp = yyss; + yyvsp = yyvs; + yylsp = yyls; + +#if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL + /* Initialize the default location before parsing starts. */ + yylloc.first_line = yylloc.last_line = 1; + yylloc.first_column = yylloc.last_column = 1; +#endif + + goto yysetstate; + +/*------------------------------------------------------------. +| yynewstate -- Push a new state, which is found in yystate. | +`------------------------------------------------------------*/ + yynewstate: + /* In all cases, when you get here, the value and location stacks + have just been pushed. So pushing a state here evens the stacks. */ + yyssp++; + + yysetstate: + *yyssp = yystate; + + if (yyss + yystacksize - 1 <= yyssp) + { + /* Get the current used size of the three stacks, in elements. */ + YYSIZE_T yysize = yyssp - yyss + 1; + +#ifdef yyoverflow + { + /* Give user a chance to reallocate the stack. Use copies of + these so that the &'s don't force the real ones into + memory. */ + YYSTYPE *yyvs1 = yyvs; + yytype_int16 *yyss1 = yyss; + YYLTYPE *yyls1 = yyls; + + /* Each stack pointer address is followed by the size of the + data in use in that stack, in bytes. This used to be a + conditional around just the two extra args, but that might + be undefined if yyoverflow is a macro. */ + yyoverflow (YY_("memory exhausted"), + &yyss1, yysize * sizeof (*yyssp), + &yyvs1, yysize * sizeof (*yyvsp), + &yyls1, yysize * sizeof (*yylsp), + &yystacksize); + + yyls = yyls1; + yyss = yyss1; + yyvs = yyvs1; + } +#else /* no yyoverflow */ +# ifndef YYSTACK_RELOCATE + goto yyexhaustedlab; +# else + /* Extend the stack our own way. */ + if (YYMAXDEPTH <= yystacksize) + goto yyexhaustedlab; + yystacksize *= 2; + if (YYMAXDEPTH < yystacksize) + yystacksize = YYMAXDEPTH; + + { + yytype_int16 *yyss1 = yyss; + union yyalloc *yyptr = + (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); + if (! yyptr) + goto yyexhaustedlab; + YYSTACK_RELOCATE (yyss_alloc, yyss); + YYSTACK_RELOCATE (yyvs_alloc, yyvs); + YYSTACK_RELOCATE (yyls_alloc, yyls); +# undef YYSTACK_RELOCATE + if (yyss1 != yyssa) + YYSTACK_FREE (yyss1); + } +# endif +#endif /* no yyoverflow */ + + yyssp = yyss + yysize - 1; + yyvsp = yyvs + yysize - 1; + yylsp = yyls + yysize - 1; + + YYDPRINTF ((stderr, "Stack size increased to %lu\n", + (unsigned long int) yystacksize)); + + if (yyss + yystacksize - 1 <= yyssp) + YYABORT; + } + + YYDPRINTF ((stderr, "Entering state %d\n", yystate)); + + if (yystate == YYFINAL) + YYACCEPT; + + goto yybackup; + +/*-----------. +| yybackup. | +`-----------*/ +yybackup: + + /* Do appropriate processing given the current state. Read a + lookahead token if we need one and don't already have one. */ + + /* First try to decide what to do without reference to lookahead token. */ + yyn = yypact[yystate]; + if (yypact_value_is_default (yyn)) + goto yydefault; + + /* Not known => get a lookahead token if don't already have one. */ + + /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */ + if (yychar == YYEMPTY) + { + YYDPRINTF ((stderr, "Reading a token: ")); + yychar = YYLEX; + } + + if (yychar <= YYEOF) + { + yychar = yytoken = YYEOF; + YYDPRINTF ((stderr, "Now at end of input.\n")); + } + else + { + yytoken = YYTRANSLATE (yychar); + YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); + } + + /* If the proper action on seeing token YYTOKEN is to reduce or to + detect an error, take that action. */ + yyn += yytoken; + if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken) + goto yydefault; + yyn = yytable[yyn]; + if (yyn <= 0) + { + if (yytable_value_is_error (yyn)) + goto yyerrlab; + yyn = -yyn; + goto yyreduce; + } + + /* Count tokens shifted since error; after three, turn off error + status. */ + if (yyerrstatus) + yyerrstatus--; + + /* Shift the lookahead token. */ + YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); + + /* Discard the shifted token. */ + yychar = YYEMPTY; + + yystate = yyn; + *++yyvsp = yylval; + *++yylsp = yylloc; + goto yynewstate; + + +/*-----------------------------------------------------------. +| yydefault -- do the default action for the current state. | +`-----------------------------------------------------------*/ +yydefault: + yyn = yydefact[yystate]; + if (yyn == 0) + goto yyerrlab; + goto yyreduce; + + +/*-----------------------------. +| yyreduce -- Do a reduction. | +`-----------------------------*/ +yyreduce: + /* yyn is the number of a rule to reduce with. */ + yylen = yyr2[yyn]; + + /* If YYLEN is nonzero, implement the default value of the action: + `$$ = $1'. + + Otherwise, the following line sets YYVAL to garbage. + This behavior is undocumented and Bison + users should not rely upon it. Assigning to YYVAL + unconditionally makes the parser a bit smaller, and it avoids a + GCC warning that YYVAL may be used uninitialized. */ + yyval = yyvsp[1-yylen]; + + /* Default location. */ + YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen); + YY_REDUCE_PRINT (yyn); + switch (yyn) + { + case 2: + +/* Line 1806 of yacc.c */ +#line 1022 "hlsl.y" + { + } + break; + + case 3: + +/* Line 1806 of yacc.c */ +#line 1025 "hlsl.y" + { + const struct hlsl_ir_function_decl *decl; + + decl = get_overloaded_func(&hlsl_ctx.functions, (yyvsp[(2) - (2)].function).name, (yyvsp[(2) - (2)].function).decl->parameters, TRUE); + if (decl && !decl->func->intrinsic) + { + if (decl->body && (yyvsp[(2) - (2)].function).decl->body) + { + hlsl_report_message((yyvsp[(2) - (2)].function).decl->node.loc.file, (yyvsp[(2) - (2)].function).decl->node.loc.line, + (yyvsp[(2) - (2)].function).decl->node.loc.col, HLSL_LEVEL_ERROR, + "redefinition of function %s", debugstr_a((yyvsp[(2) - (2)].function).name)); + return 1; + } + else if (!compare_hlsl_types(decl->node.data_type, (yyvsp[(2) - (2)].function).decl->node.data_type)) + { + hlsl_report_message((yyvsp[(2) - (2)].function).decl->node.loc.file, (yyvsp[(2) - (2)].function).decl->node.loc.line, + (yyvsp[(2) - (2)].function).decl->node.loc.col, HLSL_LEVEL_ERROR, + "redefining function %s with a different return type", + debugstr_a((yyvsp[(2) - (2)].function).name)); + hlsl_report_message(decl->node.loc.file, decl->node.loc.line, decl->node.loc.col, HLSL_LEVEL_NOTE, + "%s previously declared here", + debugstr_a((yyvsp[(2) - (2)].function).name)); + return 1; + } + } + + if ((yyvsp[(2) - (2)].function).decl->node.data_type->base_type == HLSL_TYPE_VOID && (yyvsp[(2) - (2)].function).decl->semantic) + { + hlsl_report_message((yyvsp[(2) - (2)].function).decl->node.loc.file, (yyvsp[(2) - (2)].function).decl->node.loc.line, + (yyvsp[(2) - (2)].function).decl->node.loc.col, HLSL_LEVEL_ERROR, + "void function with a semantic"); + } + + TRACE("Adding function '%s' to the function list.\n", (yyvsp[(2) - (2)].function).name); + add_function_decl(&hlsl_ctx.functions, (yyvsp[(2) - (2)].function).name, (yyvsp[(2) - (2)].function).decl, FALSE); + } + break; + + case 4: + +/* Line 1806 of yacc.c */ +#line 1062 "hlsl.y" + { + TRACE("Declaration statement parsed.\n"); + } + break; + + case 5: + +/* Line 1806 of yacc.c */ +#line 1066 "hlsl.y" + { + } + break; + + case 6: + +/* Line 1806 of yacc.c */ +#line 1069 "hlsl.y" + { + TRACE("Skipping stray semicolon.\n"); + } + break; + + case 7: + +/* Line 1806 of yacc.c */ +#line 1074 "hlsl.y" + { + TRACE("Updating line information to file %s, line %u\n", debugstr_a((yyvsp[(2) - (2)].name)), (yyvsp[(1) - (2)].intval)); + hlsl_ctx.line_no = (yyvsp[(1) - (2)].intval); + if (strcmp((yyvsp[(2) - (2)].name), hlsl_ctx.source_file)) + { + const char **new_array; + + hlsl_ctx.source_file = (yyvsp[(2) - (2)].name); + new_array = d3dcompiler_realloc(hlsl_ctx.source_files, + sizeof(*hlsl_ctx.source_files) * hlsl_ctx.source_files_count + 1); + if (new_array) + { + hlsl_ctx.source_files = new_array; + hlsl_ctx.source_files[hlsl_ctx.source_files_count++] = (yyvsp[(2) - (2)].name); + } + } + } + break; + + case 8: + +/* Line 1806 of yacc.c */ +#line 1093 "hlsl.y" + { + struct source_location loc; + + set_location(&loc, &(yylsp[(3) - (3)])); + if (!(yyvsp[(2) - (3)].list)) + { + if (!(yyvsp[(1) - (3)].type)->name) + { + hlsl_report_message(loc.file, loc.line, loc.col, + HLSL_LEVEL_ERROR, "anonymous struct declaration with no variables"); + } + check_type_modifiers((yyvsp[(1) - (3)].type)->modifiers, &loc); + } + (yyval.list) = declare_vars((yyvsp[(1) - (3)].type), 0, (yyvsp[(2) - (3)].list)); + } + break; + + case 11: + +/* Line 1806 of yacc.c */ +#line 1113 "hlsl.y" + { + BOOL ret; + struct source_location loc; + + TRACE("Structure %s declaration.\n", debugstr_a((yyvsp[(3) - (6)].name))); + set_location(&loc, &(yylsp[(1) - (6)])); + check_invalid_matrix_modifiers((yyvsp[(1) - (6)].modifiers), &loc); + (yyval.type) = new_struct_type((yyvsp[(3) - (6)].name), (yyvsp[(1) - (6)].modifiers), (yyvsp[(5) - (6)].list)); + + if (get_variable(hlsl_ctx.cur_scope, (yyvsp[(3) - (6)].name))) + { + hlsl_report_message(hlsl_ctx.source_file, (yylsp[(3) - (6)]).first_line, (yylsp[(3) - (6)]).first_column, + HLSL_LEVEL_ERROR, "redefinition of '%s'", (yyvsp[(3) - (6)].name)); + return 1; + } + + ret = add_type_to_scope(hlsl_ctx.cur_scope, (yyval.type)); + if (!ret) + { + hlsl_report_message(hlsl_ctx.source_file, (yylsp[(3) - (6)]).first_line, (yylsp[(3) - (6)]).first_column, + HLSL_LEVEL_ERROR, "redefinition of struct '%s'", (yyvsp[(3) - (6)].name)); + return 1; + } + } + break; + + case 12: + +/* Line 1806 of yacc.c */ +#line 1139 "hlsl.y" + { + struct source_location loc; + + TRACE("Anonymous structure declaration.\n"); + set_location(&loc, &(yylsp[(1) - (5)])); + check_invalid_matrix_modifiers((yyvsp[(1) - (5)].modifiers), &loc); + (yyval.type) = new_struct_type(NULL, (yyvsp[(1) - (5)].modifiers), (yyvsp[(4) - (5)].list)); + } + break; + + case 16: + +/* Line 1806 of yacc.c */ +#line 1153 "hlsl.y" + { + (yyval.list) = d3dcompiler_alloc(sizeof(*(yyval.list))); + list_init((yyval.list)); + } + break; + + case 17: + +/* Line 1806 of yacc.c */ +#line 1158 "hlsl.y" + { + BOOL ret; + struct hlsl_struct_field *field, *next; + + (yyval.list) = (yyvsp[(1) - (2)].list); + LIST_FOR_EACH_ENTRY_SAFE(field, next, (yyvsp[(2) - (2)].list), struct hlsl_struct_field, entry) + { + ret = add_struct_field((yyval.list), field); + if (ret == FALSE) + { + hlsl_report_message(hlsl_ctx.source_file, (yylsp[(2) - (2)]).first_line, (yylsp[(2) - (2)]).first_column, + HLSL_LEVEL_ERROR, "redefinition of '%s'", field->name); + d3dcompiler_free(field); + } + } + d3dcompiler_free((yyvsp[(2) - (2)].list)); + } + break; + + case 18: + +/* Line 1806 of yacc.c */ +#line 1177 "hlsl.y" + { + (yyval.list) = gen_struct_fields((yyvsp[(2) - (4)].type), (yyvsp[(1) - (4)].modifiers), (yyvsp[(3) - (4)].list)); + } + break; + + case 19: + +/* Line 1806 of yacc.c */ +#line 1181 "hlsl.y" + { + (yyval.list) = gen_struct_fields((yyvsp[(1) - (3)].type), 0, (yyvsp[(2) - (3)].list)); + } + break; + + case 20: + +/* Line 1806 of yacc.c */ +#line 1186 "hlsl.y" + { + TRACE("Function %s parsed.\n", (yyvsp[(1) - (2)].function).name); + (yyval.function) = (yyvsp[(1) - (2)].function); + (yyval.function).decl->body = (yyvsp[(2) - (2)].list); + pop_scope(&hlsl_ctx); + } + break; + + case 21: + +/* Line 1806 of yacc.c */ +#line 1193 "hlsl.y" + { + TRACE("Function prototype for %s.\n", (yyvsp[(1) - (2)].function).name); + (yyval.function) = (yyvsp[(1) - (2)].function); + pop_scope(&hlsl_ctx); + } + break; + + case 22: + +/* Line 1806 of yacc.c */ +#line 1200 "hlsl.y" + { + if (get_variable(hlsl_ctx.globals, (yyvsp[(3) - (7)].name))) + { + hlsl_report_message(hlsl_ctx.source_file, (yylsp[(3) - (7)]).first_line, (yylsp[(3) - (7)]).first_column, + HLSL_LEVEL_ERROR, "redefinition of '%s'\n", (yyvsp[(3) - (7)].name)); + return 1; + } + if ((yyvsp[(2) - (7)].type)->base_type == HLSL_TYPE_VOID && (yyvsp[(7) - (7)].name)) + { + hlsl_report_message(hlsl_ctx.source_file, (yylsp[(7) - (7)]).first_line, (yylsp[(7) - (7)]).first_column, + HLSL_LEVEL_ERROR, "void function with a semantic"); + } + + (yyval.function).decl = new_func_decl((yyvsp[(2) - (7)].type), (yyvsp[(5) - (7)].list)); + if (!(yyval.function).decl) + { + ERR("Out of memory.\n"); + return -1; + } + (yyval.function).name = (yyvsp[(3) - (7)].name); + (yyval.function).decl->semantic = (yyvsp[(7) - (7)].name); + set_location(&(yyval.function).decl->node.loc, &(yylsp[(3) - (7)])); + } + break; + + case 23: + +/* Line 1806 of yacc.c */ +#line 1225 "hlsl.y" + { + (yyval.list) = d3dcompiler_alloc(sizeof(*(yyval.list))); + list_init((yyval.list)); + } + break; + + case 24: + +/* Line 1806 of yacc.c */ +#line 1230 "hlsl.y" + { + pop_scope(&hlsl_ctx); + (yyval.list) = (yyvsp[(3) - (4)].list); + } + break; + + case 25: + +/* Line 1806 of yacc.c */ +#line 1236 "hlsl.y" + { + push_scope(&hlsl_ctx); + } + break; + + case 28: + +/* Line 1806 of yacc.c */ +#line 1244 "hlsl.y" + { + (yyval.name) = NULL; + } + break; + + case 29: + +/* Line 1806 of yacc.c */ +#line 1248 "hlsl.y" + { + (yyval.name) = (yyvsp[(2) - (2)].name); + } + break; + + case 30: + +/* Line 1806 of yacc.c */ +#line 1253 "hlsl.y" + { + (yyval.list) = d3dcompiler_alloc(sizeof(*(yyval.list))); + list_init((yyval.list)); + } + break; + + case 31: + +/* Line 1806 of yacc.c */ +#line 1258 "hlsl.y" + { + (yyval.list) = (yyvsp[(2) - (2)].list); + } + break; + + case 32: + +/* Line 1806 of yacc.c */ +#line 1263 "hlsl.y" + { + struct source_location loc; + + (yyval.list) = d3dcompiler_alloc(sizeof(*(yyval.list))); + list_init((yyval.list)); + set_location(&loc, &(yylsp[(1) - (1)])); + if (!add_func_parameter((yyval.list), &(yyvsp[(1) - (1)].parameter), &loc)) + { + ERR("Error adding function parameter %s.\n", (yyvsp[(1) - (1)].parameter).name); + set_parse_status(&hlsl_ctx.status, PARSE_ERR); + return -1; + } + } + break; + + case 33: + +/* Line 1806 of yacc.c */ +#line 1277 "hlsl.y" + { + struct source_location loc; + + (yyval.list) = (yyvsp[(1) - (3)].list); + set_location(&loc, &(yylsp[(3) - (3)])); + if (!add_func_parameter((yyval.list), &(yyvsp[(3) - (3)].parameter), &loc)) + { + hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR, + "duplicate parameter %s", (yyvsp[(3) - (3)].parameter).name); + return 1; + } + } + break; + + case 34: + +/* Line 1806 of yacc.c */ +#line 1291 "hlsl.y" + { + (yyval.parameter).modifiers = (yyvsp[(1) - (5)].modifiers) ? (yyvsp[(1) - (5)].modifiers) : HLSL_MODIFIER_IN; + (yyval.parameter).modifiers |= (yyvsp[(2) - (5)].modifiers); + (yyval.parameter).type = (yyvsp[(3) - (5)].type); + (yyval.parameter).name = (yyvsp[(4) - (5)].name); + (yyval.parameter).semantic = (yyvsp[(5) - (5)].name); + } + break; + + case 35: + +/* Line 1806 of yacc.c */ +#line 1300 "hlsl.y" + { + (yyval.modifiers) = 0; + } + break; + + case 36: + +/* Line 1806 of yacc.c */ +#line 1304 "hlsl.y" + { + if ((yyvsp[(1) - (2)].modifiers) & (yyvsp[(2) - (2)].modifiers)) + { + hlsl_report_message(hlsl_ctx.source_file, (yylsp[(2) - (2)]).first_line, (yylsp[(2) - (2)]).first_column, + HLSL_LEVEL_ERROR, "duplicate input-output modifiers"); + return 1; + } + (yyval.modifiers) = (yyvsp[(1) - (2)].modifiers) | (yyvsp[(2) - (2)].modifiers); + } + break; + + case 37: + +/* Line 1806 of yacc.c */ +#line 1315 "hlsl.y" + { + (yyval.modifiers) = HLSL_MODIFIER_IN; + } + break; + + case 38: + +/* Line 1806 of yacc.c */ +#line 1319 "hlsl.y" + { + (yyval.modifiers) = HLSL_MODIFIER_OUT; + } + break; + + case 39: + +/* Line 1806 of yacc.c */ +#line 1323 "hlsl.y" + { + (yyval.modifiers) = HLSL_MODIFIER_IN | HLSL_MODIFIER_OUT; + } + break; + + case 40: + +/* Line 1806 of yacc.c */ +#line 1328 "hlsl.y" + { + (yyval.type) = (yyvsp[(1) - (1)].type); + } + break; + + case 41: + +/* Line 1806 of yacc.c */ +#line 1332 "hlsl.y" + { + if ((yyvsp[(3) - (6)].type)->type != HLSL_CLASS_SCALAR) + { + hlsl_message("Line %u: vectors of non-scalar types are not allowed.\n", + hlsl_ctx.line_no); + set_parse_status(&hlsl_ctx.status, PARSE_ERR); + return 1; + } + if ((yyvsp[(5) - (6)].intval) < 1 || (yyvsp[(5) - (6)].intval) > 4) + { + hlsl_message("Line %u: vector size must be between 1 and 4.\n", + hlsl_ctx.line_no); + set_parse_status(&hlsl_ctx.status, PARSE_ERR); + return 1; + } + + (yyval.type) = new_hlsl_type(NULL, HLSL_CLASS_VECTOR, (yyvsp[(3) - (6)].type)->base_type, (yyvsp[(5) - (6)].intval), 1); + } + break; + + case 42: + +/* Line 1806 of yacc.c */ +#line 1351 "hlsl.y" + { + if ((yyvsp[(3) - (8)].type)->type != HLSL_CLASS_SCALAR) + { + hlsl_message("Line %u: matrices of non-scalar types are not allowed.\n", + hlsl_ctx.line_no); + set_parse_status(&hlsl_ctx.status, PARSE_ERR); + return 1; + } + if ((yyvsp[(5) - (8)].intval) < 1 || (yyvsp[(5) - (8)].intval) > 4 || (yyvsp[(7) - (8)].intval) < 1 || (yyvsp[(7) - (8)].intval) > 4) + { + hlsl_message("Line %u: matrix dimensions must be between 1 and 4.\n", + hlsl_ctx.line_no); + set_parse_status(&hlsl_ctx.status, PARSE_ERR); + return 1; + } + + (yyval.type) = new_hlsl_type(NULL, HLSL_CLASS_MATRIX, (yyvsp[(3) - (8)].type)->base_type, (yyvsp[(5) - (8)].intval), (yyvsp[(7) - (8)].intval)); + } + break; + + case 43: + +/* Line 1806 of yacc.c */ +#line 1371 "hlsl.y" + { + (yyval.type) = new_hlsl_type(d3dcompiler_strdup("void"), HLSL_CLASS_OBJECT, HLSL_TYPE_VOID, 1, 1); + } + break; + + case 44: + +/* Line 1806 of yacc.c */ +#line 1375 "hlsl.y" + { + (yyval.type) = new_hlsl_type(d3dcompiler_strdup("sampler"), HLSL_CLASS_OBJECT, HLSL_TYPE_SAMPLER, 1, 1); + (yyval.type)->sampler_dim = HLSL_SAMPLER_DIM_GENERIC; + } + break; + + case 45: + +/* Line 1806 of yacc.c */ +#line 1380 "hlsl.y" + { + (yyval.type) = new_hlsl_type(d3dcompiler_strdup("sampler1D"), HLSL_CLASS_OBJECT, HLSL_TYPE_SAMPLER, 1, 1); + (yyval.type)->sampler_dim = HLSL_SAMPLER_DIM_1D; + } + break; + + case 46: + +/* Line 1806 of yacc.c */ +#line 1385 "hlsl.y" + { + (yyval.type) = new_hlsl_type(d3dcompiler_strdup("sampler2D"), HLSL_CLASS_OBJECT, HLSL_TYPE_SAMPLER, 1, 1); + (yyval.type)->sampler_dim = HLSL_SAMPLER_DIM_2D; + } + break; + + case 47: + +/* Line 1806 of yacc.c */ +#line 1390 "hlsl.y" + { + (yyval.type) = new_hlsl_type(d3dcompiler_strdup("sampler3D"), HLSL_CLASS_OBJECT, HLSL_TYPE_SAMPLER, 1, 1); + (yyval.type)->sampler_dim = HLSL_SAMPLER_DIM_3D; + } + break; + + case 48: + +/* Line 1806 of yacc.c */ +#line 1395 "hlsl.y" + { + (yyval.type) = new_hlsl_type(d3dcompiler_strdup("samplerCUBE"), HLSL_CLASS_OBJECT, HLSL_TYPE_SAMPLER, 1, 1); + (yyval.type)->sampler_dim = HLSL_SAMPLER_DIM_CUBE; + } + break; + + case 49: + +/* Line 1806 of yacc.c */ +#line 1400 "hlsl.y" + { + struct hlsl_type *type; + + TRACE("Type %s.\n", (yyvsp[(1) - (1)].name)); + type = get_type(hlsl_ctx.cur_scope, (yyvsp[(1) - (1)].name), TRUE); + (yyval.type) = type; + d3dcompiler_free((yyvsp[(1) - (1)].name)); + } + break; + + case 50: + +/* Line 1806 of yacc.c */ +#line 1409 "hlsl.y" + { + struct hlsl_type *type; + + TRACE("Struct type %s.\n", (yyvsp[(2) - (2)].name)); + type = get_type(hlsl_ctx.cur_scope, (yyvsp[(2) - (2)].name), TRUE); + if (type->type != HLSL_CLASS_STRUCT) + { + hlsl_message("Line %u: redefining %s as a structure.\n", + hlsl_ctx.line_no, (yyvsp[(2) - (2)].name)); + set_parse_status(&hlsl_ctx.status, PARSE_ERR); + } + else + { + (yyval.type) = type; + } + d3dcompiler_free((yyvsp[(2) - (2)].name)); + } + break; + + case 53: + +/* Line 1806 of yacc.c */ +#line 1430 "hlsl.y" + { + (yyval.list) = d3dcompiler_alloc(sizeof(*(yyval.list))); + if (!(yyval.list)) + { + ERR("Out of memory\n"); + return -1; + } + list_init((yyval.list)); + } + break; + + case 54: + +/* Line 1806 of yacc.c */ +#line 1441 "hlsl.y" + { + struct source_location loc; + + set_location(&loc, &(yylsp[(1) - (5)])); + if (!add_typedef((yyvsp[(2) - (5)].modifiers), (yyvsp[(3) - (5)].type), (yyvsp[(4) - (5)].list), &loc)) + return 1; + } + break; + + case 55: + +/* Line 1806 of yacc.c */ +#line 1449 "hlsl.y" + { + struct source_location loc; + + set_location(&loc, &(yylsp[(1) - (4)])); + if (!add_typedef(0, (yyvsp[(2) - (4)].type), (yyvsp[(3) - (4)].list), &loc)) + return 1; + } + break; + + case 56: + +/* Line 1806 of yacc.c */ +#line 1458 "hlsl.y" + { + (yyval.list) = d3dcompiler_alloc(sizeof(*(yyval.list))); + list_init((yyval.list)); + list_add_head((yyval.list), &(yyvsp[(1) - (1)].variable_def)->entry); + } + break; + + case 57: + +/* Line 1806 of yacc.c */ +#line 1464 "hlsl.y" + { + (yyval.list) = (yyvsp[(1) - (3)].list); + list_add_tail((yyval.list), &(yyvsp[(3) - (3)].variable_def)->entry); + } + break; + + case 58: + +/* Line 1806 of yacc.c */ +#line 1470 "hlsl.y" + { + (yyval.variable_def) = d3dcompiler_alloc(sizeof(*(yyval.variable_def))); + set_location(&(yyval.variable_def)->loc, &(yylsp[(1) - (2)])); + (yyval.variable_def)->name = (yyvsp[(1) - (2)].name); + (yyval.variable_def)->array_size = (yyvsp[(2) - (2)].intval); + } + break; + + case 59: + +/* Line 1806 of yacc.c */ +#line 1478 "hlsl.y" + { + (yyval.list) = declare_vars((yyvsp[(2) - (4)].type), (yyvsp[(1) - (4)].modifiers), (yyvsp[(3) - (4)].list)); + } + break; + + case 60: + +/* Line 1806 of yacc.c */ +#line 1483 "hlsl.y" + { + (yyval.list) = NULL; + } + break; + + case 61: + +/* Line 1806 of yacc.c */ +#line 1487 "hlsl.y" + { + (yyval.list) = (yyvsp[(1) - (1)].list); + } + break; + + case 62: + +/* Line 1806 of yacc.c */ +#line 1492 "hlsl.y" + { + (yyval.list) = d3dcompiler_alloc(sizeof(*(yyval.list))); + list_init((yyval.list)); + list_add_head((yyval.list), &(yyvsp[(1) - (1)].variable_def)->entry); + } + break; + + case 63: + +/* Line 1806 of yacc.c */ +#line 1498 "hlsl.y" + { + (yyval.list) = (yyvsp[(1) - (3)].list); + list_add_tail((yyval.list), &(yyvsp[(3) - (3)].variable_def)->entry); + } + break; + + case 64: + +/* Line 1806 of yacc.c */ +#line 1504 "hlsl.y" + { + (yyval.variable_def) = d3dcompiler_alloc(sizeof(*(yyval.variable_def))); + set_location(&(yyval.variable_def)->loc, &(yylsp[(1) - (3)])); + (yyval.variable_def)->name = (yyvsp[(1) - (3)].name); + (yyval.variable_def)->array_size = (yyvsp[(2) - (3)].intval); + (yyval.variable_def)->semantic = (yyvsp[(3) - (3)].name); + } + break; + + case 65: + +/* Line 1806 of yacc.c */ +#line 1512 "hlsl.y" + { + TRACE("Declaration with initializer.\n"); + (yyval.variable_def) = d3dcompiler_alloc(sizeof(*(yyval.variable_def))); + set_location(&(yyval.variable_def)->loc, &(yylsp[(1) - (5)])); + (yyval.variable_def)->name = (yyvsp[(1) - (5)].name); + (yyval.variable_def)->array_size = (yyvsp[(2) - (5)].intval); + (yyval.variable_def)->semantic = (yyvsp[(3) - (5)].name); + (yyval.variable_def)->initializer = (yyvsp[(5) - (5)].list); + } + break; + + case 66: + +/* Line 1806 of yacc.c */ +#line 1523 "hlsl.y" + { + (yyval.intval) = 0; + } + break; + + case 67: + +/* Line 1806 of yacc.c */ +#line 1527 "hlsl.y" + { + FIXME("Array.\n"); + (yyval.intval) = 0; + free_instr((yyvsp[(2) - (3)].instr)); + } + break; + + case 68: + +/* Line 1806 of yacc.c */ +#line 1534 "hlsl.y" + { + (yyval.modifiers) = 0; + } + break; + + case 69: + +/* Line 1806 of yacc.c */ +#line 1538 "hlsl.y" + { + (yyval.modifiers) = add_modifier((yyvsp[(2) - (2)].modifiers), HLSL_STORAGE_EXTERN, &(yylsp[(1) - (2)])); + } + break; + + case 70: + +/* Line 1806 of yacc.c */ +#line 1542 "hlsl.y" + { + (yyval.modifiers) = add_modifier((yyvsp[(2) - (2)].modifiers), HLSL_STORAGE_NOINTERPOLATION, &(yylsp[(1) - (2)])); + } + break; + + case 71: + +/* Line 1806 of yacc.c */ +#line 1546 "hlsl.y" + { + (yyval.modifiers) = add_modifier((yyvsp[(2) - (2)].modifiers), HLSL_MODIFIER_PRECISE, &(yylsp[(1) - (2)])); + } + break; + + case 72: + +/* Line 1806 of yacc.c */ +#line 1550 "hlsl.y" + { + (yyval.modifiers) = add_modifier((yyvsp[(2) - (2)].modifiers), HLSL_STORAGE_SHARED, &(yylsp[(1) - (2)])); + } + break; + + case 73: + +/* Line 1806 of yacc.c */ +#line 1554 "hlsl.y" + { + (yyval.modifiers) = add_modifier((yyvsp[(2) - (2)].modifiers), HLSL_STORAGE_GROUPSHARED, &(yylsp[(1) - (2)])); + } + break; + + case 74: + +/* Line 1806 of yacc.c */ +#line 1558 "hlsl.y" + { + (yyval.modifiers) = add_modifier((yyvsp[(2) - (2)].modifiers), HLSL_STORAGE_STATIC, &(yylsp[(1) - (2)])); + } + break; + + case 75: + +/* Line 1806 of yacc.c */ +#line 1562 "hlsl.y" + { + (yyval.modifiers) = add_modifier((yyvsp[(2) - (2)].modifiers), HLSL_STORAGE_UNIFORM, &(yylsp[(1) - (2)])); + } + break; + + case 76: + +/* Line 1806 of yacc.c */ +#line 1566 "hlsl.y" + { + (yyval.modifiers) = add_modifier((yyvsp[(2) - (2)].modifiers), HLSL_STORAGE_VOLATILE, &(yylsp[(1) - (2)])); + } + break; + + case 77: + +/* Line 1806 of yacc.c */ +#line 1570 "hlsl.y" + { + (yyval.modifiers) = add_modifier((yyvsp[(2) - (2)].modifiers), HLSL_MODIFIER_CONST, &(yylsp[(1) - (2)])); + } + break; + + case 78: + +/* Line 1806 of yacc.c */ +#line 1574 "hlsl.y" + { + (yyval.modifiers) = add_modifier((yyvsp[(2) - (2)].modifiers), HLSL_MODIFIER_ROW_MAJOR, &(yylsp[(1) - (2)])); + } + break; + + case 79: + +/* Line 1806 of yacc.c */ +#line 1578 "hlsl.y" + { + (yyval.modifiers) = add_modifier((yyvsp[(2) - (2)].modifiers), HLSL_MODIFIER_COLUMN_MAJOR, &(yylsp[(1) - (2)])); + } + break; + + case 80: + +/* Line 1806 of yacc.c */ +#line 1583 "hlsl.y" + { + (yyval.list) = d3dcompiler_alloc(sizeof(*(yyval.list))); + list_init((yyval.list)); + list_add_head((yyval.list), &(yyvsp[(1) - (1)].instr)->entry); + } + break; + + case 81: + +/* Line 1806 of yacc.c */ +#line 1589 "hlsl.y" + { + (yyval.list) = (yyvsp[(2) - (3)].list); + } + break; + + case 82: + +/* Line 1806 of yacc.c */ +#line 1593 "hlsl.y" + { + (yyval.list) = (yyvsp[(2) - (4)].list); + } + break; + + case 83: + +/* Line 1806 of yacc.c */ +#line 1598 "hlsl.y" + { + (yyval.instr) = (yyvsp[(1) - (1)].instr); + } + break; + + case 84: + +/* Line 1806 of yacc.c */ +#line 1603 "hlsl.y" + { + (yyval.list) = d3dcompiler_alloc(sizeof(*(yyval.list))); + list_init((yyval.list)); + list_add_head((yyval.list), &(yyvsp[(1) - (1)].instr)->entry); + } + break; + + case 85: + +/* Line 1806 of yacc.c */ +#line 1609 "hlsl.y" + { + (yyval.list) = (yyvsp[(1) - (3)].list); + list_add_tail((yyval.list), &(yyvsp[(3) - (3)].instr)->entry); + } + break; + + case 86: + +/* Line 1806 of yacc.c */ +#line 1615 "hlsl.y" + { + (yyval.boolval) = TRUE; + } + break; + + case 87: + +/* Line 1806 of yacc.c */ +#line 1619 "hlsl.y" + { + (yyval.boolval) = FALSE; + } + break; + + case 88: + +/* Line 1806 of yacc.c */ +#line 1624 "hlsl.y" + { + (yyval.list) = (yyvsp[(1) - (1)].list); + } + break; + + case 89: + +/* Line 1806 of yacc.c */ +#line 1628 "hlsl.y" + { + (yyval.list) = (yyvsp[(1) - (2)].list); + list_move_tail((yyval.list), (yyvsp[(2) - (2)].list)); + d3dcompiler_free((yyvsp[(2) - (2)].list)); + } + break; + + case 96: + +/* Line 1806 of yacc.c */ +#line 1643 "hlsl.y" + { + struct hlsl_ir_jump *jump = d3dcompiler_alloc(sizeof(*jump)); + if (!jump) + { + ERR("Out of memory\n"); + return -1; + } + jump->node.type = HLSL_IR_JUMP; + set_location(&jump->node.loc, &(yylsp[(1) - (3)])); + jump->type = HLSL_IR_JUMP_RETURN; + jump->node.data_type = (yyvsp[(2) - (3)].instr)->data_type; + jump->return_value = (yyvsp[(2) - (3)].instr); + + FIXME("Check for valued return on void function.\n"); + FIXME("Implicit conversion to the return type if needed, " + "error out if conversion not possible.\n"); + + (yyval.list) = d3dcompiler_alloc(sizeof(*(yyval.list))); + list_init((yyval.list)); + list_add_tail((yyval.list), &jump->node.entry); + } + break; + + case 97: + +/* Line 1806 of yacc.c */ +#line 1666 "hlsl.y" + { + struct hlsl_ir_if *instr = d3dcompiler_alloc(sizeof(*instr)); + if (!instr) + { + ERR("Out of memory\n"); + return -1; + } + instr->node.type = HLSL_IR_IF; + set_location(&instr->node.loc, &(yylsp[(1) - (5)])); + instr->condition = (yyvsp[(3) - (5)].instr); + instr->then_instrs = (yyvsp[(5) - (5)].if_body).then_instrs; + instr->else_instrs = (yyvsp[(5) - (5)].if_body).else_instrs; + if ((yyvsp[(3) - (5)].instr)->data_type->dimx > 1 || (yyvsp[(3) - (5)].instr)->data_type->dimy > 1) + { + hlsl_report_message(instr->node.loc.file, instr->node.loc.line, + instr->node.loc.col, HLSL_LEVEL_ERROR, + "if condition requires a scalar"); + } + (yyval.list) = d3dcompiler_alloc(sizeof(*(yyval.list))); + list_init((yyval.list)); + list_add_head((yyval.list), &instr->node.entry); + } + break; + + case 98: + +/* Line 1806 of yacc.c */ +#line 1690 "hlsl.y" + { + (yyval.if_body).then_instrs = (yyvsp[(1) - (1)].list); + (yyval.if_body).else_instrs = NULL; + } + break; + + case 99: + +/* Line 1806 of yacc.c */ +#line 1695 "hlsl.y" + { + (yyval.if_body).then_instrs = (yyvsp[(1) - (3)].list); + (yyval.if_body).else_instrs = (yyvsp[(3) - (3)].list); + } + break; + + case 100: + +/* Line 1806 of yacc.c */ +#line 1701 "hlsl.y" + { + struct source_location loc; + struct list *cond = d3dcompiler_alloc(sizeof(*cond)); + + if (!cond) + { + ERR("Out of memory.\n"); + return -1; + } + list_init(cond); + list_add_head(cond, &(yyvsp[(3) - (5)].instr)->entry); + set_location(&loc, &(yylsp[(1) - (5)])); + (yyval.list) = create_loop(LOOP_WHILE, NULL, cond, NULL, (yyvsp[(5) - (5)].list), &loc); + } + break; + + case 101: + +/* Line 1806 of yacc.c */ +#line 1716 "hlsl.y" + { + struct source_location loc; + struct list *cond = d3dcompiler_alloc(sizeof(*cond)); + + if (!cond) + { + ERR("Out of memory.\n"); + return -1; + } + list_init(cond); + list_add_head(cond, &(yyvsp[(5) - (7)].instr)->entry); + set_location(&loc, &(yylsp[(1) - (7)])); + (yyval.list) = create_loop(LOOP_DO_WHILE, NULL, cond, NULL, (yyvsp[(2) - (7)].list), &loc); + } + break; + + case 102: + +/* Line 1806 of yacc.c */ +#line 1731 "hlsl.y" + { + struct source_location loc; + + set_location(&loc, &(yylsp[(1) - (8)])); + (yyval.list) = create_loop(LOOP_FOR, (yyvsp[(4) - (8)].list), (yyvsp[(5) - (8)].list), (yyvsp[(6) - (8)].instr), (yyvsp[(8) - (8)].list), &loc); + pop_scope(&hlsl_ctx); + } + break; + + case 103: + +/* Line 1806 of yacc.c */ +#line 1739 "hlsl.y" + { + struct source_location loc; + + set_location(&loc, &(yylsp[(1) - (8)])); + if (!(yyvsp[(4) - (8)].list)) + hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_WARNING, + "no expressions in for loop initializer"); + (yyval.list) = create_loop(LOOP_FOR, (yyvsp[(4) - (8)].list), (yyvsp[(5) - (8)].list), (yyvsp[(6) - (8)].instr), (yyvsp[(8) - (8)].list), &loc); + pop_scope(&hlsl_ctx); + } + break; + + case 104: + +/* Line 1806 of yacc.c */ +#line 1751 "hlsl.y" + { + (yyval.list) = d3dcompiler_alloc(sizeof(*(yyval.list))); + list_init((yyval.list)); + } + break; + + case 105: + +/* Line 1806 of yacc.c */ +#line 1756 "hlsl.y" + { + (yyval.list) = d3dcompiler_alloc(sizeof(*(yyval.list))); + list_init((yyval.list)); + if ((yyvsp[(1) - (2)].instr)) + list_add_head((yyval.list), &(yyvsp[(1) - (2)].instr)->entry); + } + break; + + case 106: + +/* Line 1806 of yacc.c */ +#line 1764 "hlsl.y" + { + struct hlsl_ir_constant *c = d3dcompiler_alloc(sizeof(*c)); + if (!c) + { + ERR("Out of memory.\n"); + return -1; + } + c->node.type = HLSL_IR_CONSTANT; + set_location(&c->node.loc, &yylloc); + c->node.data_type = new_hlsl_type(d3dcompiler_strdup("float"), HLSL_CLASS_SCALAR, HLSL_TYPE_FLOAT, 1, 1); + c->v.value.f[0] = (yyvsp[(1) - (1)].floatval); + (yyval.instr) = &c->node; + } + break; + + case 107: + +/* Line 1806 of yacc.c */ +#line 1778 "hlsl.y" + { + struct hlsl_ir_constant *c = d3dcompiler_alloc(sizeof(*c)); + if (!c) + { + ERR("Out of memory.\n"); + return -1; + } + c->node.type = HLSL_IR_CONSTANT; + set_location(&c->node.loc, &yylloc); + c->node.data_type = new_hlsl_type(d3dcompiler_strdup("int"), HLSL_CLASS_SCALAR, HLSL_TYPE_INT, 1, 1); + c->v.value.i[0] = (yyvsp[(1) - (1)].intval); + (yyval.instr) = &c->node; + } + break; + + case 108: + +/* Line 1806 of yacc.c */ +#line 1792 "hlsl.y" + { + struct hlsl_ir_constant *c = d3dcompiler_alloc(sizeof(*c)); + if (!c) + { + ERR("Out of memory.\n"); + return -1; + } + c->node.type = HLSL_IR_CONSTANT; + set_location(&c->node.loc, &yylloc); + c->node.data_type = new_hlsl_type(d3dcompiler_strdup("bool"), HLSL_CLASS_SCALAR, HLSL_TYPE_BOOL, 1, 1); + c->v.value.b[0] = (yyvsp[(1) - (1)].boolval); + (yyval.instr) = &c->node; + } + break; + + case 109: + +/* Line 1806 of yacc.c */ +#line 1806 "hlsl.y" + { + struct hlsl_ir_deref *deref = new_var_deref((yyvsp[(1) - (1)].var)); + if (deref) + { + (yyval.instr) = &deref->node; + set_location(&(yyval.instr)->loc, &(yylsp[(1) - (1)])); + } + else + (yyval.instr) = NULL; + } + break; + + case 110: + +/* Line 1806 of yacc.c */ +#line 1817 "hlsl.y" + { + (yyval.instr) = (yyvsp[(2) - (3)].instr); + } + break; + + case 111: + +/* Line 1806 of yacc.c */ +#line 1822 "hlsl.y" + { + struct hlsl_ir_var *var; + var = get_variable(hlsl_ctx.cur_scope, (yyvsp[(1) - (1)].name)); + if (!var) + { + hlsl_message("Line %d: variable '%s' not declared\n", + hlsl_ctx.line_no, (yyvsp[(1) - (1)].name)); + set_parse_status(&hlsl_ctx.status, PARSE_ERR); + return 1; + } + (yyval.var) = var; + } + break; + + case 112: + +/* Line 1806 of yacc.c */ +#line 1836 "hlsl.y" + { + (yyval.instr) = (yyvsp[(1) - (1)].instr); + } + break; + + case 113: + +/* Line 1806 of yacc.c */ +#line 1840 "hlsl.y" + { + struct hlsl_ir_node *operands[3]; + struct source_location loc; + + set_location(&loc, &(yylsp[(2) - (2)])); + if ((yyvsp[(1) - (2)].instr)->data_type->modifiers & HLSL_MODIFIER_CONST) + { + hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR, + "modifying a const expression"); + return 1; + } + operands[0] = (yyvsp[(1) - (2)].instr); + operands[1] = operands[2] = NULL; + (yyval.instr) = &new_expr(HLSL_IR_BINOP_POSTINC, operands, &loc)->node; + /* Post increment/decrement expressions are considered const */ + (yyval.instr)->data_type = clone_hlsl_type((yyval.instr)->data_type); + (yyval.instr)->data_type->modifiers |= HLSL_MODIFIER_CONST; + } + break; + + case 114: + +/* Line 1806 of yacc.c */ +#line 1859 "hlsl.y" + { + struct hlsl_ir_node *operands[3]; + struct source_location loc; + + set_location(&loc, &(yylsp[(2) - (2)])); + if ((yyvsp[(1) - (2)].instr)->data_type->modifiers & HLSL_MODIFIER_CONST) + { + hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR, + "modifying a const expression"); + return 1; + } + operands[0] = (yyvsp[(1) - (2)].instr); + operands[1] = operands[2] = NULL; + (yyval.instr) = &new_expr(HLSL_IR_BINOP_POSTDEC, operands, &loc)->node; + /* Post increment/decrement expressions are considered const */ + (yyval.instr)->data_type = clone_hlsl_type((yyval.instr)->data_type); + (yyval.instr)->data_type->modifiers |= HLSL_MODIFIER_CONST; + } + break; + + case 115: + +/* Line 1806 of yacc.c */ +#line 1878 "hlsl.y" + { + struct source_location loc; + + set_location(&loc, &(yylsp[(2) - (3)])); + if ((yyvsp[(1) - (3)].instr)->data_type->type == HLSL_CLASS_STRUCT) + { + struct hlsl_type *type = (yyvsp[(1) - (3)].instr)->data_type; + struct hlsl_struct_field *field; + + (yyval.instr) = NULL; + LIST_FOR_EACH_ENTRY(field, type->e.elements, struct hlsl_struct_field, entry) + { + if (!strcmp((yyvsp[(3) - (3)].name), field->name)) + { + struct hlsl_ir_deref *deref = new_record_deref((yyvsp[(1) - (3)].instr), field); + + if (!deref) + { + ERR("Out of memory\n"); + return -1; + } + deref->node.loc = loc; + (yyval.instr) = &deref->node; + break; + } + } + if (!(yyval.instr)) + { + hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR, + "invalid subscript %s", debugstr_a((yyvsp[(3) - (3)].name))); + return 1; + } + } + else if ((yyvsp[(1) - (3)].instr)->data_type->type <= HLSL_CLASS_LAST_NUMERIC) + { + struct hlsl_ir_swizzle *swizzle; + + swizzle = get_swizzle((yyvsp[(1) - (3)].instr), (yyvsp[(3) - (3)].name), &loc); + if (!swizzle) + { + hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR, + "invalid swizzle %s", debugstr_a((yyvsp[(3) - (3)].name))); + return 1; + } + (yyval.instr) = &swizzle->node; + } + else + { + hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR, + "invalid subscript %s", debugstr_a((yyvsp[(3) - (3)].name))); + return 1; + } + } + break; + + case 116: + +/* Line 1806 of yacc.c */ +#line 1932 "hlsl.y" + { + /* This may be an array dereference or a vector/matrix + * subcomponent access. + * We store it as an array dereference in any case. */ + struct hlsl_ir_deref *deref = d3dcompiler_alloc(sizeof(*deref)); + struct hlsl_type *expr_type = (yyvsp[(1) - (4)].instr)->data_type; + struct source_location loc; + + TRACE("Array dereference from type %s\n", debug_hlsl_type(expr_type)); + if (!deref) + { + ERR("Out of memory\n"); + return -1; + } + deref->node.type = HLSL_IR_DEREF; + set_location(&loc, &(yylsp[(2) - (4)])); + deref->node.loc = loc; + if (expr_type->type == HLSL_CLASS_ARRAY) + { + deref->node.data_type = expr_type->e.array.type; + } + else if (expr_type->type == HLSL_CLASS_MATRIX) + { + deref->node.data_type = new_hlsl_type(NULL, HLSL_CLASS_VECTOR, expr_type->base_type, expr_type->dimx, 1); + } + else if (expr_type->type == HLSL_CLASS_VECTOR) + { + deref->node.data_type = new_hlsl_type(NULL, HLSL_CLASS_SCALAR, expr_type->base_type, 1, 1); + } + else + { + if (expr_type->type == HLSL_CLASS_SCALAR) + hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR, + "array-indexed expression is scalar"); + else + hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR, + "expression is not array-indexable"); + d3dcompiler_free(deref); + free_instr((yyvsp[(1) - (4)].instr)); + free_instr((yyvsp[(3) - (4)].instr)); + return 1; + } + if ((yyvsp[(3) - (4)].instr)->data_type->type != HLSL_CLASS_SCALAR) + { + hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR, + "array index is not scalar"); + d3dcompiler_free(deref); + free_instr((yyvsp[(1) - (4)].instr)); + free_instr((yyvsp[(3) - (4)].instr)); + return 1; + } + deref->type = HLSL_IR_DEREF_ARRAY; + deref->v.array.array = (yyvsp[(1) - (4)].instr); + deref->v.array.index = (yyvsp[(3) - (4)].instr); + + (yyval.instr) = &deref->node; + } + break; + + case 117: + +/* Line 1806 of yacc.c */ +#line 1992 "hlsl.y" + { + struct hlsl_ir_constructor *constructor; + + TRACE("%s constructor.\n", debug_hlsl_type((yyvsp[(2) - (5)].type))); + if ((yyvsp[(1) - (5)].modifiers)) + { + hlsl_message("Line %u: unexpected modifier in a constructor.\n", + hlsl_ctx.line_no); + set_parse_status(&hlsl_ctx.status, PARSE_ERR); + return -1; + } + if ((yyvsp[(2) - (5)].type)->type > HLSL_CLASS_LAST_NUMERIC) + { + hlsl_message("Line %u: constructors are allowed only for numeric data types.\n", + hlsl_ctx.line_no); + set_parse_status(&hlsl_ctx.status, PARSE_ERR); + return -1; + } + if ((yyvsp[(2) - (5)].type)->dimx * (yyvsp[(2) - (5)].type)->dimy != components_count_expr_list((yyvsp[(4) - (5)].list))) + { + hlsl_message("Line %u: wrong number of components in constructor.\n", + hlsl_ctx.line_no); + set_parse_status(&hlsl_ctx.status, PARSE_ERR); + return -1; + } + + constructor = d3dcompiler_alloc(sizeof(*constructor)); + constructor->node.type = HLSL_IR_CONSTRUCTOR; + set_location(&constructor->node.loc, &(yylsp[(3) - (5)])); + constructor->node.data_type = (yyvsp[(2) - (5)].type); + constructor->arguments = (yyvsp[(4) - (5)].list); + + (yyval.instr) = &constructor->node; + } + break; + + case 118: + +/* Line 1806 of yacc.c */ +#line 2028 "hlsl.y" + { + (yyval.instr) = (yyvsp[(1) - (1)].instr); + } + break; + + case 119: + +/* Line 1806 of yacc.c */ +#line 2032 "hlsl.y" + { + struct hlsl_ir_node *operands[3]; + struct source_location loc; + + set_location(&loc, &(yylsp[(1) - (2)])); + if ((yyvsp[(2) - (2)].instr)->data_type->modifiers & HLSL_MODIFIER_CONST) + { + hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR, + "modifying a const expression"); + return 1; + } + operands[0] = (yyvsp[(2) - (2)].instr); + operands[1] = operands[2] = NULL; + (yyval.instr) = &new_expr(HLSL_IR_BINOP_PREINC, operands, &loc)->node; + } + break; + + case 120: + +/* Line 1806 of yacc.c */ +#line 2048 "hlsl.y" + { + struct hlsl_ir_node *operands[3]; + struct source_location loc; + + set_location(&loc, &(yylsp[(1) - (2)])); + if ((yyvsp[(2) - (2)].instr)->data_type->modifiers & HLSL_MODIFIER_CONST) + { + hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR, + "modifying a const expression"); + return 1; + } + operands[0] = (yyvsp[(2) - (2)].instr); + operands[1] = operands[2] = NULL; + (yyval.instr) = &new_expr(HLSL_IR_BINOP_PREDEC, operands, &loc)->node; + } + break; + + case 121: + +/* Line 1806 of yacc.c */ +#line 2064 "hlsl.y" + { + enum hlsl_ir_expr_op ops[] = {0, HLSL_IR_UNOP_NEG, + HLSL_IR_UNOP_LOGIC_NOT, HLSL_IR_UNOP_BIT_NOT}; + struct hlsl_ir_node *operands[3]; + struct source_location loc; + + if ((yyvsp[(1) - (2)].unary_op) == UNARY_OP_PLUS) + { + (yyval.instr) = (yyvsp[(2) - (2)].instr); + } + else + { + operands[0] = (yyvsp[(2) - (2)].instr); + operands[1] = operands[2] = NULL; + set_location(&loc, &(yylsp[(1) - (2)])); + (yyval.instr) = &new_expr(ops[(yyvsp[(1) - (2)].unary_op)], operands, &loc)->node; + } + } + break; + + case 122: + +/* Line 1806 of yacc.c */ +#line 2084 "hlsl.y" + { + struct hlsl_ir_expr *expr; + struct hlsl_type *src_type = (yyvsp[(6) - (6)].instr)->data_type; + struct hlsl_type *dst_type; + struct source_location loc; + + set_location(&loc, &(yylsp[(3) - (6)])); + if ((yyvsp[(2) - (6)].modifiers)) + { + hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR, + "unexpected modifier in a cast"); + return 1; + } + + if ((yyvsp[(4) - (6)].intval)) + dst_type = new_array_type((yyvsp[(3) - (6)].type), (yyvsp[(4) - (6)].intval)); + else + dst_type = (yyvsp[(3) - (6)].type); + + if (!compatible_data_types(src_type, dst_type)) + { + hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR, + "can't cast from %s to %s", + debug_hlsl_type(src_type), debug_hlsl_type(dst_type)); + return 1; + } + + expr = new_cast((yyvsp[(6) - (6)].instr), dst_type, &loc); + (yyval.instr) = expr ? &expr->node : NULL; + } + break; + + case 123: + +/* Line 1806 of yacc.c */ +#line 2116 "hlsl.y" + { + (yyval.unary_op) = UNARY_OP_PLUS; + } + break; + + case 124: + +/* Line 1806 of yacc.c */ +#line 2120 "hlsl.y" + { + (yyval.unary_op) = UNARY_OP_MINUS; + } + break; + + case 125: + +/* Line 1806 of yacc.c */ +#line 2124 "hlsl.y" + { + (yyval.unary_op) = UNARY_OP_LOGICNOT; + } + break; + + case 126: + +/* Line 1806 of yacc.c */ +#line 2128 "hlsl.y" + { + (yyval.unary_op) = UNARY_OP_BITNOT; + } + break; + + case 127: + +/* Line 1806 of yacc.c */ +#line 2133 "hlsl.y" + { + (yyval.instr) = (yyvsp[(1) - (1)].instr); + } + break; + + case 128: + +/* Line 1806 of yacc.c */ +#line 2137 "hlsl.y" + { + struct source_location loc; + + set_location(&loc, &(yylsp[(2) - (3)])); + (yyval.instr) = &hlsl_mul((yyvsp[(1) - (3)].instr), (yyvsp[(3) - (3)].instr), &loc)->node; + } + break; + + case 129: + +/* Line 1806 of yacc.c */ +#line 2144 "hlsl.y" + { + struct source_location loc; + + set_location(&loc, &(yylsp[(2) - (3)])); + (yyval.instr) = &hlsl_div((yyvsp[(1) - (3)].instr), (yyvsp[(3) - (3)].instr), &loc)->node; + } + break; + + case 130: + +/* Line 1806 of yacc.c */ +#line 2151 "hlsl.y" + { + struct source_location loc; + + set_location(&loc, &(yylsp[(2) - (3)])); + (yyval.instr) = &hlsl_mod((yyvsp[(1) - (3)].instr), (yyvsp[(3) - (3)].instr), &loc)->node; + } + break; + + case 131: + +/* Line 1806 of yacc.c */ +#line 2159 "hlsl.y" + { + (yyval.instr) = (yyvsp[(1) - (1)].instr); + } + break; + + case 132: + +/* Line 1806 of yacc.c */ +#line 2163 "hlsl.y" + { + struct source_location loc; + + set_location(&loc, &(yylsp[(2) - (3)])); + (yyval.instr) = &hlsl_add((yyvsp[(1) - (3)].instr), (yyvsp[(3) - (3)].instr), &loc)->node; + } + break; + + case 133: + +/* Line 1806 of yacc.c */ +#line 2170 "hlsl.y" + { + struct source_location loc; + + set_location(&loc, &(yylsp[(2) - (3)])); + (yyval.instr) = &hlsl_sub((yyvsp[(1) - (3)].instr), (yyvsp[(3) - (3)].instr), &loc)->node; + } + break; + + case 134: + +/* Line 1806 of yacc.c */ +#line 2178 "hlsl.y" + { + (yyval.instr) = (yyvsp[(1) - (1)].instr); + } + break; + + case 135: + +/* Line 1806 of yacc.c */ +#line 2182 "hlsl.y" + { + FIXME("Left shift\n"); + } + break; + + case 136: + +/* Line 1806 of yacc.c */ +#line 2186 "hlsl.y" + { + FIXME("Right shift\n"); + } + break; + + case 137: + +/* Line 1806 of yacc.c */ +#line 2191 "hlsl.y" + { + (yyval.instr) = (yyvsp[(1) - (1)].instr); + } + break; + + case 138: + +/* Line 1806 of yacc.c */ +#line 2195 "hlsl.y" + { + struct source_location loc; + + set_location(&loc, &(yylsp[(2) - (3)])); + (yyval.instr) = &hlsl_lt((yyvsp[(1) - (3)].instr), (yyvsp[(3) - (3)].instr), &loc)->node; + } + break; + + case 139: + +/* Line 1806 of yacc.c */ +#line 2202 "hlsl.y" + { + struct source_location loc; + + set_location(&loc, &(yylsp[(2) - (3)])); + (yyval.instr) = &hlsl_gt((yyvsp[(1) - (3)].instr), (yyvsp[(3) - (3)].instr), &loc)->node; + } + break; + + case 140: + +/* Line 1806 of yacc.c */ +#line 2209 "hlsl.y" + { + struct source_location loc; + + set_location(&loc, &(yylsp[(2) - (3)])); + (yyval.instr) = &hlsl_le((yyvsp[(1) - (3)].instr), (yyvsp[(3) - (3)].instr), &loc)->node; + } + break; + + case 141: + +/* Line 1806 of yacc.c */ +#line 2216 "hlsl.y" + { + struct source_location loc; + + set_location(&loc, &(yylsp[(2) - (3)])); + (yyval.instr) = &hlsl_ge((yyvsp[(1) - (3)].instr), (yyvsp[(3) - (3)].instr), &loc)->node; + } + break; + + case 142: + +/* Line 1806 of yacc.c */ +#line 2224 "hlsl.y" + { + (yyval.instr) = (yyvsp[(1) - (1)].instr); + } + break; + + case 143: + +/* Line 1806 of yacc.c */ +#line 2228 "hlsl.y" + { + struct source_location loc; + + set_location(&loc, &(yylsp[(2) - (3)])); + (yyval.instr) = &hlsl_eq((yyvsp[(1) - (3)].instr), (yyvsp[(3) - (3)].instr), &loc)->node; + } + break; + + case 144: + +/* Line 1806 of yacc.c */ +#line 2235 "hlsl.y" + { + struct source_location loc; + + set_location(&loc, &(yylsp[(2) - (3)])); + (yyval.instr) = &hlsl_ne((yyvsp[(1) - (3)].instr), (yyvsp[(3) - (3)].instr), &loc)->node; + } + break; + + case 145: + +/* Line 1806 of yacc.c */ +#line 2243 "hlsl.y" + { + (yyval.instr) = (yyvsp[(1) - (1)].instr); + } + break; + + case 146: + +/* Line 1806 of yacc.c */ +#line 2247 "hlsl.y" + { + FIXME("bitwise AND\n"); + } + break; + + case 147: + +/* Line 1806 of yacc.c */ +#line 2252 "hlsl.y" + { + (yyval.instr) = (yyvsp[(1) - (1)].instr); + } + break; + + case 148: + +/* Line 1806 of yacc.c */ +#line 2256 "hlsl.y" + { + FIXME("bitwise XOR\n"); + } + break; + + case 149: + +/* Line 1806 of yacc.c */ +#line 2261 "hlsl.y" + { + (yyval.instr) = (yyvsp[(1) - (1)].instr); + } + break; + + case 150: + +/* Line 1806 of yacc.c */ +#line 2265 "hlsl.y" + { + FIXME("bitwise OR\n"); + } + break; + + case 151: + +/* Line 1806 of yacc.c */ +#line 2270 "hlsl.y" + { + (yyval.instr) = (yyvsp[(1) - (1)].instr); + } + break; + + case 152: + +/* Line 1806 of yacc.c */ +#line 2274 "hlsl.y" + { + FIXME("logic AND\n"); + } + break; + + case 153: + +/* Line 1806 of yacc.c */ +#line 2279 "hlsl.y" + { + (yyval.instr) = (yyvsp[(1) - (1)].instr); + } + break; + + case 154: + +/* Line 1806 of yacc.c */ +#line 2283 "hlsl.y" + { + FIXME("logic OR\n"); + } + break; + + case 155: + +/* Line 1806 of yacc.c */ +#line 2288 "hlsl.y" + { + (yyval.instr) = (yyvsp[(1) - (1)].instr); + } + break; + + case 156: + +/* Line 1806 of yacc.c */ +#line 2292 "hlsl.y" + { + FIXME("ternary operator\n"); + } + break; + + case 157: + +/* Line 1806 of yacc.c */ +#line 2297 "hlsl.y" + { + (yyval.instr) = (yyvsp[(1) - (1)].instr); + } + break; + + case 158: + +/* Line 1806 of yacc.c */ +#line 2301 "hlsl.y" + { + struct source_location loc; + + set_location(&loc, &(yylsp[(2) - (3)])); + if ((yyvsp[(1) - (3)].instr)->data_type->modifiers & HLSL_MODIFIER_CONST) + { + hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR, + "l-value is const"); + return 1; + } + (yyval.instr) = make_assignment((yyvsp[(1) - (3)].instr), (yyvsp[(2) - (3)].assign_op), BWRITERSP_WRITEMASK_ALL, (yyvsp[(3) - (3)].instr)); + if (!(yyval.instr)) + return 1; + (yyval.instr)->loc = loc; + } + break; + + case 159: + +/* Line 1806 of yacc.c */ +#line 2318 "hlsl.y" + { + (yyval.assign_op) = ASSIGN_OP_ASSIGN; + } + break; + + case 160: + +/* Line 1806 of yacc.c */ +#line 2322 "hlsl.y" + { + (yyval.assign_op) = ASSIGN_OP_ADD; + } + break; + + case 161: + +/* Line 1806 of yacc.c */ +#line 2326 "hlsl.y" + { + (yyval.assign_op) = ASSIGN_OP_SUB; + } + break; + + case 162: + +/* Line 1806 of yacc.c */ +#line 2330 "hlsl.y" + { + (yyval.assign_op) = ASSIGN_OP_MUL; + } + break; + + case 163: + +/* Line 1806 of yacc.c */ +#line 2334 "hlsl.y" + { + (yyval.assign_op) = ASSIGN_OP_DIV; + } + break; + + case 164: + +/* Line 1806 of yacc.c */ +#line 2338 "hlsl.y" + { + (yyval.assign_op) = ASSIGN_OP_MOD; + } + break; + + case 165: + +/* Line 1806 of yacc.c */ +#line 2342 "hlsl.y" + { + (yyval.assign_op) = ASSIGN_OP_LSHIFT; + } + break; + + case 166: + +/* Line 1806 of yacc.c */ +#line 2346 "hlsl.y" + { + (yyval.assign_op) = ASSIGN_OP_RSHIFT; + } + break; + + case 167: + +/* Line 1806 of yacc.c */ +#line 2350 "hlsl.y" + { + (yyval.assign_op) = ASSIGN_OP_AND; + } + break; + + case 168: + +/* Line 1806 of yacc.c */ +#line 2354 "hlsl.y" + { + (yyval.assign_op) = ASSIGN_OP_OR; + } + break; + + case 169: + +/* Line 1806 of yacc.c */ +#line 2358 "hlsl.y" + { + (yyval.assign_op) = ASSIGN_OP_XOR; + } + break; + + case 170: + +/* Line 1806 of yacc.c */ +#line 2363 "hlsl.y" + { + (yyval.instr) = (yyvsp[(1) - (1)].instr); + } + break; + + case 171: + +/* Line 1806 of yacc.c */ +#line 2367 "hlsl.y" + { + FIXME("Comma expression\n"); + } + break; + + + +/* Line 1806 of yacc.c */ +#line 4835 "hlsl.tab.c" + default: break; + } + /* User semantic actions sometimes alter yychar, and that requires + that yytoken be updated with the new translation. We take the + approach of translating immediately before every use of yytoken. + One alternative is translating here after every semantic action, + but that translation would be missed if the semantic action invokes + YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or + if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an + incorrect destructor might then be invoked immediately. In the + case of YYERROR or YYBACKUP, subsequent parser actions might lead + to an incorrect destructor call or verbose syntax error message + before the lookahead is translated. */ + YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); + + YYPOPSTACK (yylen); + yylen = 0; + YY_STACK_PRINT (yyss, yyssp); + + *++yyvsp = yyval; + *++yylsp = yyloc; + + /* Now `shift' the result of the reduction. Determine what state + that goes to, based on the state we popped back to and the rule + number reduced by. */ + + yyn = yyr1[yyn]; + + yystate = yypgoto[yyn - YYNTOKENS] + *yyssp; + if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp) + yystate = yytable[yystate]; + else + yystate = yydefgoto[yyn - YYNTOKENS]; + + goto yynewstate; + + +/*------------------------------------. +| yyerrlab -- here on detecting error | +`------------------------------------*/ +yyerrlab: + /* Make sure we have latest lookahead translation. See comments at + user semantic actions for why this is necessary. */ + yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar); + + /* If not already recovering from an error, report this error. */ + if (!yyerrstatus) + { + ++yynerrs; +#if ! YYERROR_VERBOSE + yyerror (YY_("syntax error")); +#else +# define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \ + yyssp, yytoken) + { + char const *yymsgp = YY_("syntax error"); + int yysyntax_error_status; + yysyntax_error_status = YYSYNTAX_ERROR; + if (yysyntax_error_status == 0) + yymsgp = yymsg; + else if (yysyntax_error_status == 1) + { + if (yymsg != yymsgbuf) + YYSTACK_FREE (yymsg); + yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc); + if (!yymsg) + { + yymsg = yymsgbuf; + yymsg_alloc = sizeof yymsgbuf; + yysyntax_error_status = 2; + } + else + { + yysyntax_error_status = YYSYNTAX_ERROR; + yymsgp = yymsg; + } + } + yyerror (yymsgp); + if (yysyntax_error_status == 2) + goto yyexhaustedlab; + } +# undef YYSYNTAX_ERROR +#endif + } + + yyerror_range[1] = yylloc; + + if (yyerrstatus == 3) + { + /* If just tried and failed to reuse lookahead token after an + error, discard it. */ + + if (yychar <= YYEOF) + { + /* Return failure if at end of input. */ + if (yychar == YYEOF) + YYABORT; + } + else + { + yydestruct ("Error: discarding", + yytoken, &yylval, &yylloc); + yychar = YYEMPTY; + } + } + + /* Else will try to reuse lookahead token after shifting the error + token. */ + goto yyerrlab1; + + +/*---------------------------------------------------. +| yyerrorlab -- error raised explicitly by YYERROR. | +`---------------------------------------------------*/ +yyerrorlab: + + /* Pacify compilers like GCC when the user code never invokes + YYERROR and the label yyerrorlab therefore never appears in user + code. */ + if (/*CONSTCOND*/ 0) + goto yyerrorlab; + + yyerror_range[1] = yylsp[1-yylen]; + /* Do not reclaim the symbols of the rule which action triggered + this YYERROR. */ + YYPOPSTACK (yylen); + yylen = 0; + YY_STACK_PRINT (yyss, yyssp); + yystate = *yyssp; + goto yyerrlab1; + + +/*-------------------------------------------------------------. +| yyerrlab1 -- common code for both syntax error and YYERROR. | +`-------------------------------------------------------------*/ +yyerrlab1: + yyerrstatus = 3; /* Each real token shifted decrements this. */ + + for (;;) + { + yyn = yypact[yystate]; + if (!yypact_value_is_default (yyn)) + { + yyn += YYTERROR; + if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) + { + yyn = yytable[yyn]; + if (0 < yyn) + break; + } + } + + /* Pop the current state because it cannot handle the error token. */ + if (yyssp == yyss) + YYABORT; + + yyerror_range[1] = *yylsp; + yydestruct ("Error: popping", + yystos[yystate], yyvsp, yylsp); + YYPOPSTACK (1); + yystate = *yyssp; + YY_STACK_PRINT (yyss, yyssp); + } + + *++yyvsp = yylval; + + yyerror_range[2] = yylloc; + /* Using YYLLOC is tempting, but would change the location of + the lookahead. YYLOC is available though. */ + YYLLOC_DEFAULT (yyloc, yyerror_range, 2); + *++yylsp = yyloc; + + /* Shift the error token. */ + YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp); + + yystate = yyn; + goto yynewstate; + + +/*-------------------------------------. +| yyacceptlab -- YYACCEPT comes here. | +`-------------------------------------*/ +yyacceptlab: + yyresult = 0; + goto yyreturn; + +/*-----------------------------------. +| yyabortlab -- YYABORT comes here. | +`-----------------------------------*/ +yyabortlab: + yyresult = 1; + goto yyreturn; + +#if !defined(yyoverflow) || YYERROR_VERBOSE +/*-------------------------------------------------. +| yyexhaustedlab -- memory exhaustion comes here. | +`-------------------------------------------------*/ +yyexhaustedlab: + yyerror (YY_("memory exhausted")); + yyresult = 2; + /* Fall through. */ +#endif + +yyreturn: + if (yychar != YYEMPTY) + { + /* Make sure we have latest lookahead translation. See comments at + user semantic actions for why this is necessary. */ + yytoken = YYTRANSLATE (yychar); + yydestruct ("Cleanup: discarding lookahead", + yytoken, &yylval, &yylloc); + } + /* Do not reclaim the symbols of the rule which action triggered + this YYABORT or YYACCEPT. */ + YYPOPSTACK (yylen); + YY_STACK_PRINT (yyss, yyssp); + while (yyssp != yyss) + { + yydestruct ("Cleanup: popping", + yystos[*yyssp], yyvsp, yylsp); + YYPOPSTACK (1); + } +#ifndef yyoverflow + if (yyss != yyssa) + YYSTACK_FREE (yyss); +#endif +#if YYERROR_VERBOSE + if (yymsg != yymsgbuf) + YYSTACK_FREE (yymsg); +#endif + /* Make sure YYID is used. */ + return YYID (yyresult); +} + + + +/* Line 2067 of yacc.c */ +#line 2371 "hlsl.y" + + +static void set_location(struct source_location *loc, const struct YYLTYPE *l) +{ + loc->file = hlsl_ctx.source_file; + loc->line = l->first_line; + loc->col = l->first_column; +} + +static DWORD add_modifier(DWORD modifiers, DWORD mod, const struct YYLTYPE *loc) +{ + if (modifiers & mod) + { + hlsl_report_message(hlsl_ctx.source_file, loc->first_line, loc->first_column, HLSL_LEVEL_ERROR, + "modifier '%s' already specified", debug_modifiers(mod)); + return modifiers; + } + if (mod & (HLSL_MODIFIER_ROW_MAJOR | HLSL_MODIFIER_COLUMN_MAJOR) + && modifiers & (HLSL_MODIFIER_ROW_MAJOR | HLSL_MODIFIER_COLUMN_MAJOR)) + { + hlsl_report_message(hlsl_ctx.source_file, loc->first_line, loc->first_column, HLSL_LEVEL_ERROR, + "more than one matrix majority keyword"); + return modifiers; + } + return modifiers | mod; +} + +static void dump_function_decl(struct wine_rb_entry *entry, void *context) +{ + struct hlsl_ir_function_decl *func = WINE_RB_ENTRY_VALUE(entry, struct hlsl_ir_function_decl, entry); + if (func->body) + debug_dump_ir_function_decl(func); +} + +static void dump_function(struct wine_rb_entry *entry, void *context) +{ + struct hlsl_ir_function *func = WINE_RB_ENTRY_VALUE(entry, struct hlsl_ir_function, entry); + wine_rb_for_each_entry(&func->overloads, dump_function_decl, NULL); +} + +struct bwriter_shader *parse_hlsl(enum shader_type type, DWORD major, DWORD minor, + const char *entrypoint, char **messages) +{ + struct hlsl_scope *scope, *next_scope; + struct hlsl_type *hlsl_type, *next_type; + struct hlsl_ir_var *var, *next_var; + unsigned int i; + + hlsl_ctx.status = PARSE_SUCCESS; + hlsl_ctx.messages.size = hlsl_ctx.messages.capacity = 0; + hlsl_ctx.line_no = hlsl_ctx.column = 1; + hlsl_ctx.source_file = d3dcompiler_strdup(""); + hlsl_ctx.source_files = d3dcompiler_alloc(sizeof(*hlsl_ctx.source_files)); + if (hlsl_ctx.source_files) + hlsl_ctx.source_files[0] = hlsl_ctx.source_file; + hlsl_ctx.source_files_count = 1; + hlsl_ctx.cur_scope = NULL; + hlsl_ctx.matrix_majority = HLSL_COLUMN_MAJOR; + list_init(&hlsl_ctx.scopes); + list_init(&hlsl_ctx.types); + init_functions_tree(&hlsl_ctx.functions); + + push_scope(&hlsl_ctx); + hlsl_ctx.globals = hlsl_ctx.cur_scope; + declare_predefined_types(hlsl_ctx.globals); + + hlsl_parse(); + + if (TRACE_ON(hlsl_parser)) + { + TRACE("IR dump.\n"); + wine_rb_for_each_entry(&hlsl_ctx.functions, dump_function, NULL); + } + + TRACE("Compilation status = %d\n", hlsl_ctx.status); + if (messages) + { + if (hlsl_ctx.messages.size) + *messages = hlsl_ctx.messages.string; + else + *messages = NULL; + } + else + { + if (hlsl_ctx.messages.capacity) + d3dcompiler_free(hlsl_ctx.messages.string); + } + + for (i = 0; i < hlsl_ctx.source_files_count; ++i) + d3dcompiler_free((void *)hlsl_ctx.source_files[i]); + d3dcompiler_free(hlsl_ctx.source_files); + + TRACE("Freeing functions IR.\n"); + wine_rb_destroy(&hlsl_ctx.functions, free_function_rb, NULL); + + TRACE("Freeing variables.\n"); + LIST_FOR_EACH_ENTRY_SAFE(scope, next_scope, &hlsl_ctx.scopes, struct hlsl_scope, entry) + { + LIST_FOR_EACH_ENTRY_SAFE(var, next_var, &scope->vars, struct hlsl_ir_var, scope_entry) + { + free_declaration(var); + } + wine_rb_destroy(&scope->types, NULL, NULL); + d3dcompiler_free(scope); + } + + TRACE("Freeing types.\n"); + LIST_FOR_EACH_ENTRY_SAFE(hlsl_type, next_type, &hlsl_ctx.types, struct hlsl_type, entry) + { + free_hlsl_type(hlsl_type); + } + + return NULL; +} + diff --git a/reactos/dll/directx/wine/d3dcompiler_43/hlsl.tab.h b/reactos/dll/directx/wine/d3dcompiler_43/hlsl.tab.h new file mode 100644 index 00000000000..22dddd841af --- /dev/null +++ b/reactos/dll/directx/wine/d3dcompiler_43/hlsl.tab.h @@ -0,0 +1,196 @@ +/* A Bison parser, made by GNU Bison 2.5. */ + +/* Bison interface for Yacc-like parsers in C + + Copyright (C) 1984, 1989-1990, 2000-2011 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* As a special exception, you may create a larger work that contains + part or all of the Bison parser skeleton and distribute that work + under terms of your choice, so long as that work isn't itself a + parser generator using the skeleton or a modified version thereof + as a parser skeleton. Alternatively, if you modify or redistribute + the parser skeleton itself, you may (at your option) remove this + special exception, which will cause the skeleton and the resulting + Bison output files to be licensed under the GNU General Public + License without this special exception. + + This special exception was added by the Free Software Foundation in + version 2.2 of Bison. */ + + +/* Tokens. */ +#ifndef YYTOKENTYPE +# define YYTOKENTYPE + /* Put the tokens into the symbol table, so that GDB and other debuggers + know about them. */ + enum yytokentype { + KW_BLENDSTATE = 258, + KW_BREAK = 259, + KW_BUFFER = 260, + KW_CBUFFER = 261, + KW_COLUMN_MAJOR = 262, + KW_COMPILE = 263, + KW_CONST = 264, + KW_CONTINUE = 265, + KW_DEPTHSTENCILSTATE = 266, + KW_DEPTHSTENCILVIEW = 267, + KW_DISCARD = 268, + KW_DO = 269, + KW_DOUBLE = 270, + KW_ELSE = 271, + KW_EXTERN = 272, + KW_FALSE = 273, + KW_FOR = 274, + KW_GEOMETRYSHADER = 275, + KW_GROUPSHARED = 276, + KW_IF = 277, + KW_IN = 278, + KW_INLINE = 279, + KW_INOUT = 280, + KW_MATRIX = 281, + KW_NAMESPACE = 282, + KW_NOINTERPOLATION = 283, + KW_OUT = 284, + KW_PASS = 285, + KW_PIXELSHADER = 286, + KW_PRECISE = 287, + KW_RASTERIZERSTATE = 288, + KW_RENDERTARGETVIEW = 289, + KW_RETURN = 290, + KW_REGISTER = 291, + KW_ROW_MAJOR = 292, + KW_SAMPLER = 293, + KW_SAMPLER1D = 294, + KW_SAMPLER2D = 295, + KW_SAMPLER3D = 296, + KW_SAMPLERCUBE = 297, + KW_SAMPLER_STATE = 298, + KW_SAMPLERCOMPARISONSTATE = 299, + KW_SHARED = 300, + KW_STATEBLOCK = 301, + KW_STATEBLOCK_STATE = 302, + KW_STATIC = 303, + KW_STRING = 304, + KW_STRUCT = 305, + KW_SWITCH = 306, + KW_TBUFFER = 307, + KW_TECHNIQUE = 308, + KW_TECHNIQUE10 = 309, + KW_TEXTURE = 310, + KW_TEXTURE1D = 311, + KW_TEXTURE1DARRAY = 312, + KW_TEXTURE2D = 313, + KW_TEXTURE2DARRAY = 314, + KW_TEXTURE2DMS = 315, + KW_TEXTURE2DMSARRAY = 316, + KW_TEXTURE3D = 317, + KW_TEXTURE3DARRAY = 318, + KW_TEXTURECUBE = 319, + KW_TRUE = 320, + KW_TYPEDEF = 321, + KW_UNIFORM = 322, + KW_VECTOR = 323, + KW_VERTEXSHADER = 324, + KW_VOID = 325, + KW_VOLATILE = 326, + KW_WHILE = 327, + OP_INC = 328, + OP_DEC = 329, + OP_AND = 330, + OP_OR = 331, + OP_EQ = 332, + OP_LEFTSHIFT = 333, + OP_LEFTSHIFTASSIGN = 334, + OP_RIGHTSHIFT = 335, + OP_RIGHTSHIFTASSIGN = 336, + OP_ELLIPSIS = 337, + OP_LE = 338, + OP_GE = 339, + OP_NE = 340, + OP_ADDASSIGN = 341, + OP_SUBASSIGN = 342, + OP_MULASSIGN = 343, + OP_DIVASSIGN = 344, + OP_MODASSIGN = 345, + OP_ANDASSIGN = 346, + OP_ORASSIGN = 347, + OP_XORASSIGN = 348, + OP_UNKNOWN1 = 349, + OP_UNKNOWN2 = 350, + OP_UNKNOWN3 = 351, + OP_UNKNOWN4 = 352, + PRE_LINE = 353, + VAR_IDENTIFIER = 354, + TYPE_IDENTIFIER = 355, + NEW_IDENTIFIER = 356, + STRING = 357, + C_FLOAT = 358, + C_INTEGER = 359 + }; +#endif + + + +#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED +typedef union YYSTYPE +{ + +/* Line 2068 of yacc.c */ +#line 841 "hlsl.y" + + struct hlsl_type *type; + INT intval; + FLOAT floatval; + BOOL boolval; + char *name; + DWORD modifiers; + struct hlsl_ir_var *var; + struct hlsl_ir_node *instr; + struct list *list; + struct parse_function function; + struct parse_parameter parameter; + struct parse_variable_def *variable_def; + struct parse_if_body if_body; + enum parse_unary_op unary_op; + enum parse_assign_op assign_op; + + + +/* Line 2068 of yacc.c */ +#line 174 "hlsl.tab.h" +} YYSTYPE; +# define YYSTYPE_IS_TRIVIAL 1 +# define yystype YYSTYPE /* obsolescent; will be withdrawn */ +# define YYSTYPE_IS_DECLARED 1 +#endif + +extern YYSTYPE hlsl_lval; + +#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED +typedef struct YYLTYPE +{ + int first_line; + int first_column; + int last_line; + int last_column; +} YYLTYPE; +# define yyltype YYLTYPE /* obsolescent; will be withdrawn */ +# define YYLTYPE_IS_DECLARED 1 +# define YYLTYPE_IS_TRIVIAL 1 +#endif + +extern YYLTYPE hlsl_lloc; + diff --git a/reactos/dll/directx/wine/d3dcompiler_43/hlsl.y b/reactos/dll/directx/wine/d3dcompiler_43/hlsl.y new file mode 100644 index 00000000000..777fb4e2871 --- /dev/null +++ b/reactos/dll/directx/wine/d3dcompiler_43/hlsl.y @@ -0,0 +1,2484 @@ +/* + * 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/debug.h" + +#include + +#include "d3dcompiler_private.h" + +WINE_DEFAULT_DEBUG_CHANNEL(hlsl_parser); + +int hlsl_lex(void); + +struct hlsl_parse_ctx hlsl_ctx; + +struct YYLTYPE; +static void set_location(struct source_location *loc, const struct YYLTYPE *l); + +void hlsl_message(const char *fmt, ...) +{ + va_list args; + + va_start(args, fmt); + compilation_message(&hlsl_ctx.messages, fmt, args); + va_end(args); +} + +static const char *hlsl_get_error_level_name(enum hlsl_error_level level) +{ + const char *names[] = + { + "error", + "warning", + "note", + }; + return names[level]; +} + +void hlsl_report_message(const char *filename, DWORD line, DWORD column, + enum hlsl_error_level level, const char *fmt, ...) +{ + va_list args; + char *string = NULL; + int rc, size = 0; + + while (1) + { + va_start(args, fmt); + rc = vsnprintf(string, size, fmt, args); + va_end(args); + + if (rc >= 0 && rc < size) + break; + + if (rc >= size) + size = rc + 1; + else + size = size ? size * 2 : 32; + + if (!string) + string = d3dcompiler_alloc(size); + else + string = d3dcompiler_realloc(string, size); + if (!string) + { + ERR("Error reallocating memory for a string.\n"); + return; + } + } + + hlsl_message("%s:%u:%u: %s: %s\n", filename, line, column, hlsl_get_error_level_name(level), string); + d3dcompiler_free(string); + + if (level == HLSL_LEVEL_ERROR) + set_parse_status(&hlsl_ctx.status, PARSE_ERR); + else if (level == HLSL_LEVEL_WARNING) + set_parse_status(&hlsl_ctx.status, PARSE_WARN); +} + +static void hlsl_error(const char *s) +{ + hlsl_report_message(hlsl_ctx.source_file, hlsl_ctx.line_no, hlsl_ctx.column, HLSL_LEVEL_ERROR, "%s", s); +} + +static void debug_dump_decl(struct hlsl_type *type, DWORD modifiers, const char *declname, unsigned int line_no) +{ + TRACE("Line %u: ", line_no); + if (modifiers) + TRACE("%s ", debug_modifiers(modifiers)); + TRACE("%s %s;\n", debug_hlsl_type(type), declname); +} + +static void check_invalid_matrix_modifiers(DWORD modifiers, struct source_location *loc) +{ + if (modifiers & (HLSL_MODIFIER_ROW_MAJOR | HLSL_MODIFIER_COLUMN_MAJOR)) + { + hlsl_report_message(loc->file, loc->line, loc->col, HLSL_LEVEL_ERROR, + "'row_major' or 'column_major' modifiers are only allowed for matrices"); + } +} + +static BOOL declare_variable(struct hlsl_ir_var *decl, BOOL local) +{ + BOOL ret; + + TRACE("Declaring variable %s.\n", decl->name); + if (decl->node.data_type->type == HLSL_CLASS_MATRIX) + { + if (!(decl->modifiers & (HLSL_MODIFIER_ROW_MAJOR | HLSL_MODIFIER_COLUMN_MAJOR))) + { + decl->modifiers |= hlsl_ctx.matrix_majority == HLSL_ROW_MAJOR + ? HLSL_MODIFIER_ROW_MAJOR : HLSL_MODIFIER_COLUMN_MAJOR; + } + } + else + check_invalid_matrix_modifiers(decl->modifiers, &decl->node.loc); + + if (local) + { + DWORD invalid = decl->modifiers & (HLSL_STORAGE_EXTERN | HLSL_STORAGE_SHARED + | HLSL_STORAGE_GROUPSHARED | HLSL_STORAGE_UNIFORM); + if (invalid) + { + hlsl_report_message(decl->node.loc.file, decl->node.loc.line, decl->node.loc.col, HLSL_LEVEL_ERROR, + "modifier '%s' invalid for local variables", debug_modifiers(invalid)); + } + if (decl->semantic) + { + hlsl_report_message(decl->node.loc.file, decl->node.loc.line, decl->node.loc.col, HLSL_LEVEL_ERROR, + "semantics are not allowed on local variables"); + return FALSE; + } + } + else + { + if (find_function(decl->name)) + { + hlsl_report_message(decl->node.loc.file, decl->node.loc.line, decl->node.loc.col, HLSL_LEVEL_ERROR, + "redefinition of '%s'", decl->name); + return FALSE; + } + } + ret = add_declaration(hlsl_ctx.cur_scope, decl, local); + if (!ret) + { + struct hlsl_ir_var *old = get_variable(hlsl_ctx.cur_scope, decl->name); + + hlsl_report_message(decl->node.loc.file, decl->node.loc.line, decl->node.loc.col, HLSL_LEVEL_ERROR, + "\"%s\" already declared", decl->name); + hlsl_report_message(old->node.loc.file, old->node.loc.line, old->node.loc.col, HLSL_LEVEL_NOTE, + "\"%s\" was previously declared here", old->name); + return FALSE; + } + return TRUE; +} + +static DWORD add_modifier(DWORD modifiers, DWORD mod, const struct YYLTYPE *loc); + +static BOOL check_type_modifiers(DWORD modifiers, struct source_location *loc) +{ + if (modifiers & ~HLSL_TYPE_MODIFIERS_MASK) + { + hlsl_report_message(loc->file, loc->line, loc->col, HLSL_LEVEL_ERROR, + "modifier not allowed on typedefs"); + return FALSE; + } + return TRUE; +} + +static BOOL add_type_to_scope(struct hlsl_scope *scope, struct hlsl_type *def) +{ + if (get_type(scope, def->name, FALSE)) + return FALSE; + + wine_rb_put(&scope->types, def->name, &def->scope_entry); + return TRUE; +} + +static void declare_predefined_types(struct hlsl_scope *scope) +{ + struct hlsl_type *type; + unsigned int x, y, bt; + static const char *names[] = + { + "float", + "half", + "double", + "int", + "uint", + "bool", + }; + char name[10]; + + for (bt = 0; bt <= HLSL_TYPE_LAST_SCALAR; ++bt) + { + for (y = 1; y <= 4; ++y) + { + for (x = 1; x <= 4; ++x) + { + sprintf(name, "%s%ux%u", names[bt], x, y); + type = new_hlsl_type(d3dcompiler_strdup(name), HLSL_CLASS_MATRIX, bt, x, y); + add_type_to_scope(scope, type); + + if (y == 1) + { + sprintf(name, "%s%u", names[bt], x); + type = new_hlsl_type(d3dcompiler_strdup(name), HLSL_CLASS_VECTOR, bt, x, y); + add_type_to_scope(scope, type); + + if (x == 1) + { + sprintf(name, "%s", names[bt]); + type = new_hlsl_type(d3dcompiler_strdup(name), HLSL_CLASS_SCALAR, bt, x, y); + add_type_to_scope(scope, type); + } + } + } + } + } + + /* DX8 effects predefined types */ + type = new_hlsl_type(d3dcompiler_strdup("DWORD"), HLSL_CLASS_SCALAR, HLSL_TYPE_INT, 1, 1); + add_type_to_scope(scope, type); + type = new_hlsl_type(d3dcompiler_strdup("FLOAT"), HLSL_CLASS_SCALAR, HLSL_TYPE_FLOAT, 1, 1); + add_type_to_scope(scope, type); + type = new_hlsl_type(d3dcompiler_strdup("VECTOR"), HLSL_CLASS_VECTOR, HLSL_TYPE_FLOAT, 4, 1); + add_type_to_scope(scope, type); + type = new_hlsl_type(d3dcompiler_strdup("MATRIX"), HLSL_CLASS_MATRIX, HLSL_TYPE_FLOAT, 4, 4); + add_type_to_scope(scope, type); + type = new_hlsl_type(d3dcompiler_strdup("STRING"), HLSL_CLASS_OBJECT, HLSL_TYPE_STRING, 1, 1); + add_type_to_scope(scope, type); + type = new_hlsl_type(d3dcompiler_strdup("TEXTURE"), HLSL_CLASS_OBJECT, HLSL_TYPE_TEXTURE, 1, 1); + add_type_to_scope(scope, type); + type = new_hlsl_type(d3dcompiler_strdup("PIXELSHADER"), HLSL_CLASS_OBJECT, HLSL_TYPE_PIXELSHADER, 1, 1); + add_type_to_scope(scope, type); + type = new_hlsl_type(d3dcompiler_strdup("VERTEXSHADER"), HLSL_CLASS_OBJECT, HLSL_TYPE_VERTEXSHADER, 1, 1); + add_type_to_scope(scope, type); +} + +static struct hlsl_ir_if *loop_condition(struct list *cond_list) +{ + struct hlsl_ir_if *out_cond; + struct hlsl_ir_expr *not_cond; + struct hlsl_ir_node *cond, *operands[3]; + struct hlsl_ir_jump *jump; + unsigned int count = list_count(cond_list); + + if (!count) + return NULL; + if (count != 1) + ERR("Got multiple expressions in a for condition.\n"); + + cond = LIST_ENTRY(list_head(cond_list), struct hlsl_ir_node, entry); + out_cond = d3dcompiler_alloc(sizeof(*out_cond)); + if (!out_cond) + { + ERR("Out of memory.\n"); + return NULL; + } + out_cond->node.type = HLSL_IR_IF; + operands[0] = cond; + operands[1] = operands[2] = NULL; + not_cond = new_expr(HLSL_IR_UNOP_LOGIC_NOT, operands, &cond->loc); + if (!not_cond) + { + ERR("Out of memory.\n"); + d3dcompiler_free(out_cond); + return NULL; + } + out_cond->condition = ¬_cond->node; + jump = d3dcompiler_alloc(sizeof(*jump)); + if (!jump) + { + ERR("Out of memory.\n"); + d3dcompiler_free(out_cond); + d3dcompiler_free(not_cond); + return NULL; + } + jump->node.type = HLSL_IR_JUMP; + jump->type = HLSL_IR_JUMP_BREAK; + out_cond->then_instrs = d3dcompiler_alloc(sizeof(*out_cond->then_instrs)); + if (!out_cond->then_instrs) + { + ERR("Out of memory.\n"); + d3dcompiler_free(out_cond); + d3dcompiler_free(not_cond); + d3dcompiler_free(jump); + return NULL; + } + list_init(out_cond->then_instrs); + list_add_head(out_cond->then_instrs, &jump->node.entry); + + return out_cond; +} + +enum loop_type +{ + LOOP_FOR, + LOOP_WHILE, + LOOP_DO_WHILE +}; + +static struct list *create_loop(enum loop_type type, struct list *init, struct list *cond, + struct hlsl_ir_node *iter, struct list *body, struct source_location *loc) +{ + struct list *list = NULL; + struct hlsl_ir_loop *loop = NULL; + struct hlsl_ir_if *cond_jump = NULL; + + list = d3dcompiler_alloc(sizeof(*list)); + if (!list) + goto oom; + list_init(list); + + if (init) + list_move_head(list, init); + + loop = d3dcompiler_alloc(sizeof(*loop)); + if (!loop) + goto oom; + loop->node.type = HLSL_IR_LOOP; + loop->node.loc = *loc; + list_add_tail(list, &loop->node.entry); + loop->body = d3dcompiler_alloc(sizeof(*loop->body)); + if (!loop->body) + goto oom; + list_init(loop->body); + + cond_jump = loop_condition(cond); + if (!cond_jump) + goto oom; + + if (type != LOOP_DO_WHILE) + list_add_tail(loop->body, &cond_jump->node.entry); + + list_move_tail(loop->body, body); + + if (iter) + list_add_tail(loop->body, &iter->entry); + + if (type == LOOP_DO_WHILE) + list_add_tail(loop->body, &cond_jump->node.entry); + + d3dcompiler_free(init); + d3dcompiler_free(cond); + d3dcompiler_free(body); + return list; + +oom: + ERR("Out of memory.\n"); + if (loop) + d3dcompiler_free(loop->body); + d3dcompiler_free(loop); + d3dcompiler_free(cond_jump); + d3dcompiler_free(list); + free_instr_list(init); + free_instr_list(cond); + free_instr(iter); + free_instr_list(body); + return NULL; +} + +static unsigned int initializer_size(struct list *initializer) +{ + unsigned int count = 0; + struct hlsl_ir_node *node; + + LIST_FOR_EACH_ENTRY(node, initializer, struct hlsl_ir_node, entry) + { + count += components_count_type(node->data_type); + } + TRACE("Initializer size = %u\n", count); + return count; +} + +static unsigned int components_count_expr_list(struct list *list) +{ + struct hlsl_ir_node *node; + unsigned int count = 0; + + LIST_FOR_EACH_ENTRY(node, list, struct hlsl_ir_node, entry) + { + count += components_count_type(node->data_type); + } + return count; +} + +static struct hlsl_ir_swizzle *new_swizzle(DWORD s, unsigned int components, + struct hlsl_ir_node *val, struct source_location *loc) +{ + struct hlsl_ir_swizzle *swizzle = d3dcompiler_alloc(sizeof(*swizzle)); + + if (!swizzle) + return NULL; + swizzle->node.type = HLSL_IR_SWIZZLE; + swizzle->node.loc = *loc; + swizzle->node.data_type = new_hlsl_type(NULL, HLSL_CLASS_VECTOR, val->data_type->base_type, components, 1); + swizzle->val = val; + swizzle->swizzle = s; + return swizzle; +} + +static struct hlsl_ir_swizzle *get_swizzle(struct hlsl_ir_node *value, const char *swizzle, + struct source_location *loc) +{ + unsigned int len = strlen(swizzle), component = 0; + unsigned int i, set, swiz = 0; + BOOL valid; + + if (value->data_type->type == HLSL_CLASS_MATRIX) + { + /* Matrix swizzle */ + BOOL m_swizzle; + unsigned int inc, x, y; + + if (len < 3 || swizzle[0] != '_') + return NULL; + m_swizzle = swizzle[1] == 'm'; + inc = m_swizzle ? 4 : 3; + + if (len % inc || len > inc * 4) + return NULL; + + for (i = 0; i < len; i += inc) + { + if (swizzle[i] != '_') + return NULL; + if (m_swizzle) + { + if (swizzle[i + 1] != 'm') + return NULL; + x = swizzle[i + 2] - '0'; + y = swizzle[i + 3] - '0'; + } + else + { + x = swizzle[i + 1] - '1'; + y = swizzle[i + 2] - '1'; + } + + if (x >= value->data_type->dimx || y >= value->data_type->dimy) + return NULL; + swiz |= (y << 4 | x) << component * 8; + component++; + } + return new_swizzle(swiz, component, value, loc); + } + + /* Vector swizzle */ + if (len > 4) + return NULL; + + for (set = 0; set < 2; ++set) + { + valid = TRUE; + component = 0; + for (i = 0; i < len; ++i) + { + char c[2][4] = {{'x', 'y', 'z', 'w'}, {'r', 'g', 'b', 'a'}}; + unsigned int s = 0; + + for (s = 0; s < 4; ++s) + { + if (swizzle[i] == c[set][s]) + break; + } + if (s == 4) + { + valid = FALSE; + break; + } + + if (s >= value->data_type->dimx) + return NULL; + swiz |= s << component * 2; + component++; + } + if (valid) + return new_swizzle(swiz, component, value, loc); + } + + return NULL; +} + +static void struct_var_initializer(struct list *list, struct hlsl_ir_var *var, struct list *initializer) +{ + struct hlsl_type *type = var->node.data_type; + struct hlsl_ir_node *node; + struct hlsl_struct_field *field; + struct list *cur_node; + struct hlsl_ir_node *assignment; + struct hlsl_ir_deref *deref; + + if (initializer_size(initializer) != components_count_type(type)) + { + hlsl_report_message(var->node.loc.file, var->node.loc.line, var->node.loc.col, HLSL_LEVEL_ERROR, + "structure initializer mismatch"); + free_instr_list(initializer); + return; + } + cur_node = list_head(initializer); + assert(cur_node); + node = LIST_ENTRY(cur_node, struct hlsl_ir_node, entry); + LIST_FOR_EACH_ENTRY(field, type->e.elements, struct hlsl_struct_field, entry) + { + if (!cur_node) + { + d3dcompiler_free(initializer); + return; + } + if (components_count_type(field->type) == components_count_type(node->data_type)) + { + deref = new_record_deref(&var->node, field); + if (!deref) + { + ERR("Out of memory.\n"); + break; + } + deref->node.loc = node->loc; + assignment = make_assignment(&deref->node, ASSIGN_OP_ASSIGN, BWRITERSP_WRITEMASK_ALL, node); + list_add_tail(list, &assignment->entry); + } + else + FIXME("Initializing with \"mismatched\" fields is not supported yet.\n"); + cur_node = list_next(initializer, cur_node); + node = LIST_ENTRY(cur_node, struct hlsl_ir_node, entry); + } + + /* Free initializer elements in excess. */ + while (cur_node) + { + struct list *next = list_next(initializer, cur_node); + free_instr(node); + cur_node = next; + node = LIST_ENTRY(cur_node, struct hlsl_ir_node, entry); + } + d3dcompiler_free(initializer); +} + +static struct list *declare_vars(struct hlsl_type *basic_type, DWORD modifiers, struct list *var_list) +{ + struct hlsl_type *type; + struct parse_variable_def *v, *v_next; + struct hlsl_ir_var *var; + struct hlsl_ir_node *assignment; + BOOL ret, local = TRUE; + struct list *statements_list = d3dcompiler_alloc(sizeof(*statements_list)); + + if (!statements_list) + { + ERR("Out of memory.\n"); + LIST_FOR_EACH_ENTRY_SAFE(v, v_next, var_list, struct parse_variable_def, entry) + d3dcompiler_free(v); + d3dcompiler_free(var_list); + return NULL; + } + list_init(statements_list); + + if (!var_list) + return statements_list; + + LIST_FOR_EACH_ENTRY_SAFE(v, v_next, var_list, struct parse_variable_def, entry) + { + var = d3dcompiler_alloc(sizeof(*var)); + if (!var) + { + ERR("Out of memory.\n"); + d3dcompiler_free(v); + continue; + } + var->node.type = HLSL_IR_VAR; + if (v->array_size) + type = new_array_type(basic_type, v->array_size); + else + type = basic_type; + var->node.data_type = type; + var->node.loc = v->loc; + var->name = v->name; + var->modifiers = modifiers; + var->semantic = v->semantic; + debug_dump_decl(type, modifiers, v->name, v->loc.line); + + if (hlsl_ctx.cur_scope == hlsl_ctx.globals) + { + var->modifiers |= HLSL_STORAGE_UNIFORM; + local = FALSE; + } + + if (var->modifiers & HLSL_MODIFIER_CONST && !(var->modifiers & HLSL_STORAGE_UNIFORM) && !v->initializer) + { + hlsl_report_message(v->loc.file, v->loc.line, v->loc.col, + HLSL_LEVEL_ERROR, "const variable without initializer"); + free_declaration(var); + d3dcompiler_free(v); + continue; + } + + ret = declare_variable(var, local); + if (!ret) + { + free_declaration(var); + d3dcompiler_free(v); + continue; + } + TRACE("Declared variable %s.\n", var->name); + + if (v->initializer) + { + unsigned int size = initializer_size(v->initializer); + struct hlsl_ir_node *node; + + TRACE("Variable with initializer.\n"); + if (type->type <= HLSL_CLASS_LAST_NUMERIC + && type->dimx * type->dimy != size && size != 1) + { + if (size < type->dimx * type->dimy) + { + hlsl_report_message(v->loc.file, v->loc.line, v->loc.col, HLSL_LEVEL_ERROR, + "'%s' initializer does not match", v->name); + free_instr_list(v->initializer); + d3dcompiler_free(v); + continue; + } + } + if ((type->type == HLSL_CLASS_STRUCT || type->type == HLSL_CLASS_ARRAY) + && components_count_type(type) != size) + { + hlsl_report_message(v->loc.file, v->loc.line, v->loc.col, HLSL_LEVEL_ERROR, + "'%s' initializer does not match", v->name); + free_instr_list(v->initializer); + d3dcompiler_free(v); + continue; + } + + if (type->type == HLSL_CLASS_STRUCT) + { + struct_var_initializer(statements_list, var, v->initializer); + d3dcompiler_free(v); + continue; + } + if (type->type > HLSL_CLASS_LAST_NUMERIC) + { + FIXME("Initializers for non scalar/struct variables not supported yet.\n"); + free_instr_list(v->initializer); + d3dcompiler_free(v); + continue; + } + if (v->array_size > 0) + { + FIXME("Initializing arrays is not supported yet.\n"); + free_instr_list(v->initializer); + d3dcompiler_free(v); + continue; + } + if (list_count(v->initializer) > 1) + { + FIXME("Complex initializers are not supported yet.\n"); + free_instr_list(v->initializer); + d3dcompiler_free(v); + continue; + } + node = LIST_ENTRY(list_head(v->initializer), struct hlsl_ir_node, entry); + assignment = make_assignment(&var->node, ASSIGN_OP_ASSIGN, + BWRITERSP_WRITEMASK_ALL, node); + list_add_tail(statements_list, &assignment->entry); + d3dcompiler_free(v->initializer); + } + d3dcompiler_free(v); + } + d3dcompiler_free(var_list); + return statements_list; +} + +static BOOL add_struct_field(struct list *fields, struct hlsl_struct_field *field) +{ + struct hlsl_struct_field *f; + + LIST_FOR_EACH_ENTRY(f, fields, struct hlsl_struct_field, entry) + { + if (!strcmp(f->name, field->name)) + return FALSE; + } + list_add_tail(fields, &field->entry); + return TRUE; +} + +static struct list *gen_struct_fields(struct hlsl_type *type, DWORD modifiers, struct list *fields) +{ + struct parse_variable_def *v, *v_next; + struct hlsl_struct_field *field; + struct list *list; + + list = d3dcompiler_alloc(sizeof(*list)); + if (!list) + { + ERR("Out of memory.\n"); + return NULL; + } + list_init(list); + LIST_FOR_EACH_ENTRY_SAFE(v, v_next, fields, struct parse_variable_def, entry) + { + debug_dump_decl(type, 0, v->name, v->loc.line); + field = d3dcompiler_alloc(sizeof(*field)); + if (!field) + { + ERR("Out of memory.\n"); + d3dcompiler_free(v); + return list; + } + field->type = type; + field->name = v->name; + field->modifiers = modifiers; + field->semantic = v->semantic; + if (v->initializer) + { + hlsl_report_message(v->loc.file, v->loc.line, v->loc.col, HLSL_LEVEL_ERROR, + "struct field with an initializer.\n"); + free_instr_list(v->initializer); + } + list_add_tail(list, &field->entry); + d3dcompiler_free(v); + } + d3dcompiler_free(fields); + return list; +} + +static struct hlsl_type *new_struct_type(const char *name, DWORD modifiers, struct list *fields) +{ + struct hlsl_type *type = d3dcompiler_alloc(sizeof(*type)); + + if (!type) + { + ERR("Out of memory.\n"); + return NULL; + } + type->type = HLSL_CLASS_STRUCT; + type->name = name; + type->dimx = type->dimy = 1; + type->modifiers = modifiers; + type->e.elements = fields; + + list_add_tail(&hlsl_ctx.types, &type->entry); + + return type; +} + +static BOOL add_typedef(DWORD modifiers, struct hlsl_type *orig_type, struct list *list, + struct source_location *loc) +{ + BOOL ret; + struct hlsl_type *type; + struct parse_variable_def *v, *v_next; + + if (!check_type_modifiers(modifiers, loc)) + { + LIST_FOR_EACH_ENTRY_SAFE(v, v_next, list, struct parse_variable_def, entry) + d3dcompiler_free(v); + d3dcompiler_free(list); + return FALSE; + } + + LIST_FOR_EACH_ENTRY_SAFE(v, v_next, list, struct parse_variable_def, entry) + { + if (v->array_size) + type = new_array_type(orig_type, v->array_size); + else + type = clone_hlsl_type(orig_type); + if (!type) + { + ERR("Out of memory\n"); + return FALSE; + } + d3dcompiler_free((void *)type->name); + type->name = v->name; + type->modifiers |= modifiers; + + if (type->type != HLSL_CLASS_MATRIX) + check_invalid_matrix_modifiers(type->modifiers, &v->loc); + + ret = add_type_to_scope(hlsl_ctx.cur_scope, type); + if (!ret) + { + hlsl_report_message(v->loc.file, v->loc.line, v->loc.col, HLSL_LEVEL_ERROR, + "redefinition of custom type '%s'", v->name); + } + d3dcompiler_free(v); + } + d3dcompiler_free(list); + return TRUE; +} + +static const struct hlsl_ir_function_decl *get_overloaded_func(struct wine_rb_tree *funcs, char *name, + struct list *params, BOOL exact_signature) +{ + struct hlsl_ir_function *func; + struct wine_rb_entry *entry; + + entry = wine_rb_get(funcs, name); + if (entry) + { + func = WINE_RB_ENTRY_VALUE(entry, struct hlsl_ir_function, entry); + + entry = wine_rb_get(&func->overloads, params); + if (!entry) + { + if (!exact_signature) + FIXME("No exact match, search for a compatible overloaded function (if any).\n"); + return NULL; + } + return WINE_RB_ENTRY_VALUE(entry, struct hlsl_ir_function_decl, entry); + } + return NULL; +} + +%} + +%locations +%error-verbose +%expect 1 + +%union +{ + struct hlsl_type *type; + INT intval; + FLOAT floatval; + BOOL boolval; + char *name; + DWORD modifiers; + struct hlsl_ir_var *var; + struct hlsl_ir_node *instr; + struct list *list; + struct parse_function function; + struct parse_parameter parameter; + struct parse_variable_def *variable_def; + struct parse_if_body if_body; + enum parse_unary_op unary_op; + enum parse_assign_op assign_op; +} + +%token KW_BLENDSTATE +%token KW_BREAK +%token KW_BUFFER +%token KW_CBUFFER +%token KW_COLUMN_MAJOR +%token KW_COMPILE +%token KW_CONST +%token KW_CONTINUE +%token KW_DEPTHSTENCILSTATE +%token KW_DEPTHSTENCILVIEW +%token KW_DISCARD +%token KW_DO +%token KW_DOUBLE +%token KW_ELSE +%token KW_EXTERN +%token KW_FALSE +%token KW_FOR +%token KW_GEOMETRYSHADER +%token KW_GROUPSHARED +%token KW_IF +%token KW_IN +%token KW_INLINE +%token KW_INOUT +%token KW_MATRIX +%token KW_NAMESPACE +%token KW_NOINTERPOLATION +%token KW_OUT +%token KW_PASS +%token KW_PIXELSHADER +%token KW_PRECISE +%token KW_RASTERIZERSTATE +%token KW_RENDERTARGETVIEW +%token KW_RETURN +%token KW_REGISTER +%token KW_ROW_MAJOR +%token KW_SAMPLER +%token KW_SAMPLER1D +%token KW_SAMPLER2D +%token KW_SAMPLER3D +%token KW_SAMPLERCUBE +%token KW_SAMPLER_STATE +%token KW_SAMPLERCOMPARISONSTATE +%token KW_SHARED +%token KW_STATEBLOCK +%token KW_STATEBLOCK_STATE +%token KW_STATIC +%token KW_STRING +%token KW_STRUCT +%token KW_SWITCH +%token KW_TBUFFER +%token KW_TECHNIQUE +%token KW_TECHNIQUE10 +%token KW_TEXTURE +%token KW_TEXTURE1D +%token KW_TEXTURE1DARRAY +%token KW_TEXTURE2D +%token KW_TEXTURE2DARRAY +%token KW_TEXTURE2DMS +%token KW_TEXTURE2DMSARRAY +%token KW_TEXTURE3D +%token KW_TEXTURE3DARRAY +%token KW_TEXTURECUBE +%token KW_TRUE +%token KW_TYPEDEF +%token KW_UNIFORM +%token KW_VECTOR +%token KW_VERTEXSHADER +%token KW_VOID +%token KW_VOLATILE +%token KW_WHILE + +%token OP_INC +%token OP_DEC +%token OP_AND +%token OP_OR +%token OP_EQ +%token OP_LEFTSHIFT +%token OP_LEFTSHIFTASSIGN +%token OP_RIGHTSHIFT +%token OP_RIGHTSHIFTASSIGN +%token OP_ELLIPSIS +%token OP_LE +%token OP_GE +%token OP_NE +%token OP_ADDASSIGN +%token OP_SUBASSIGN +%token OP_MULASSIGN +%token OP_DIVASSIGN +%token OP_MODASSIGN +%token OP_ANDASSIGN +%token OP_ORASSIGN +%token OP_XORASSIGN +%token OP_UNKNOWN1 +%token OP_UNKNOWN2 +%token OP_UNKNOWN3 +%token OP_UNKNOWN4 + +%token PRE_LINE + +%token VAR_IDENTIFIER TYPE_IDENTIFIER NEW_IDENTIFIER +%type any_identifier var_identifier +%token STRING +%token C_FLOAT +%token C_INTEGER +%type boolean +%type base_type +%type type +%type declaration_statement +%type declaration +%type struct_declaration +%type struct_spec +%type named_struct_spec +%type unnamed_struct_spec +%type type_specs +%type type_spec +%type complex_initializer +%type initializer_expr_list +%type initializer_expr +%type var_modifiers +%type field +%type parameters +%type param_list +%type expr +%type variable +%type array +%type statement +%type statement_list +%type compound_statement +%type jump_statement +%type selection_statement +%type loop_statement +%type func_declaration +%type func_prototype +%type fields_list +%type parameter +%type semantic +%type variable_def +%type variables_def +%type variables_def_optional +%type if_body +%type primary_expr +%type postfix_expr +%type unary_expr +%type mul_expr +%type add_expr +%type shift_expr +%type relational_expr +%type equality_expr +%type bitand_expr +%type bitxor_expr +%type bitor_expr +%type logicand_expr +%type logicor_expr +%type conditional_expr +%type assignment_expr +%type expr_statement +%type unary_op +%type assign_op +%type input_mods +%type input_mod +%% + +hlsl_prog: /* empty */ + { + } + | hlsl_prog func_declaration + { + const struct hlsl_ir_function_decl *decl; + + decl = get_overloaded_func(&hlsl_ctx.functions, $2.name, $2.decl->parameters, TRUE); + if (decl && !decl->func->intrinsic) + { + if (decl->body && $2.decl->body) + { + hlsl_report_message($2.decl->node.loc.file, $2.decl->node.loc.line, + $2.decl->node.loc.col, HLSL_LEVEL_ERROR, + "redefinition of function %s", debugstr_a($2.name)); + return 1; + } + else if (!compare_hlsl_types(decl->node.data_type, $2.decl->node.data_type)) + { + hlsl_report_message($2.decl->node.loc.file, $2.decl->node.loc.line, + $2.decl->node.loc.col, HLSL_LEVEL_ERROR, + "redefining function %s with a different return type", + debugstr_a($2.name)); + hlsl_report_message(decl->node.loc.file, decl->node.loc.line, decl->node.loc.col, HLSL_LEVEL_NOTE, + "%s previously declared here", + debugstr_a($2.name)); + return 1; + } + } + + if ($2.decl->node.data_type->base_type == HLSL_TYPE_VOID && $2.decl->semantic) + { + hlsl_report_message($2.decl->node.loc.file, $2.decl->node.loc.line, + $2.decl->node.loc.col, HLSL_LEVEL_ERROR, + "void function with a semantic"); + } + + TRACE("Adding function '%s' to the function list.\n", $2.name); + add_function_decl(&hlsl_ctx.functions, $2.name, $2.decl, FALSE); + } + | hlsl_prog declaration_statement + { + TRACE("Declaration statement parsed.\n"); + } + | hlsl_prog preproc_directive + { + } + | hlsl_prog ';' + { + TRACE("Skipping stray semicolon.\n"); + } + +preproc_directive: PRE_LINE STRING + { + TRACE("Updating line information to file %s, line %u\n", debugstr_a($2), $1); + hlsl_ctx.line_no = $1; + if (strcmp($2, hlsl_ctx.source_file)) + { + const char **new_array; + + hlsl_ctx.source_file = $2; + new_array = d3dcompiler_realloc(hlsl_ctx.source_files, + sizeof(*hlsl_ctx.source_files) * hlsl_ctx.source_files_count + 1); + if (new_array) + { + hlsl_ctx.source_files = new_array; + hlsl_ctx.source_files[hlsl_ctx.source_files_count++] = $2; + } + } + } + +struct_declaration: struct_spec variables_def_optional ';' + { + struct source_location loc; + + set_location(&loc, &@3); + if (!$2) + { + if (!$1->name) + { + hlsl_report_message(loc.file, loc.line, loc.col, + HLSL_LEVEL_ERROR, "anonymous struct declaration with no variables"); + } + check_type_modifiers($1->modifiers, &loc); + } + $$ = declare_vars($1, 0, $2); + } + +struct_spec: named_struct_spec + | unnamed_struct_spec + +named_struct_spec: var_modifiers KW_STRUCT any_identifier '{' fields_list '}' + { + BOOL ret; + struct source_location loc; + + TRACE("Structure %s declaration.\n", debugstr_a($3)); + set_location(&loc, &@1); + check_invalid_matrix_modifiers($1, &loc); + $$ = new_struct_type($3, $1, $5); + + if (get_variable(hlsl_ctx.cur_scope, $3)) + { + hlsl_report_message(hlsl_ctx.source_file, @3.first_line, @3.first_column, + HLSL_LEVEL_ERROR, "redefinition of '%s'", $3); + return 1; + } + + ret = add_type_to_scope(hlsl_ctx.cur_scope, $$); + if (!ret) + { + hlsl_report_message(hlsl_ctx.source_file, @3.first_line, @3.first_column, + HLSL_LEVEL_ERROR, "redefinition of struct '%s'", $3); + return 1; + } + } + +unnamed_struct_spec: var_modifiers KW_STRUCT '{' fields_list '}' + { + struct source_location loc; + + TRACE("Anonymous structure declaration.\n"); + set_location(&loc, &@1); + check_invalid_matrix_modifiers($1, &loc); + $$ = new_struct_type(NULL, $1, $4); + } + +any_identifier: VAR_IDENTIFIER + | TYPE_IDENTIFIER + | NEW_IDENTIFIER + +fields_list: /* Empty */ + { + $$ = d3dcompiler_alloc(sizeof(*$$)); + list_init($$); + } + | fields_list field + { + BOOL ret; + struct hlsl_struct_field *field, *next; + + $$ = $1; + LIST_FOR_EACH_ENTRY_SAFE(field, next, $2, struct hlsl_struct_field, entry) + { + ret = add_struct_field($$, field); + if (ret == FALSE) + { + hlsl_report_message(hlsl_ctx.source_file, @2.first_line, @2.first_column, + HLSL_LEVEL_ERROR, "redefinition of '%s'", field->name); + d3dcompiler_free(field); + } + } + d3dcompiler_free($2); + } + +field: var_modifiers type variables_def ';' + { + $$ = gen_struct_fields($2, $1, $3); + } + | unnamed_struct_spec variables_def ';' + { + $$ = gen_struct_fields($1, 0, $2); + } + +func_declaration: func_prototype compound_statement + { + TRACE("Function %s parsed.\n", $1.name); + $$ = $1; + $$.decl->body = $2; + pop_scope(&hlsl_ctx); + } + | func_prototype ';' + { + TRACE("Function prototype for %s.\n", $1.name); + $$ = $1; + pop_scope(&hlsl_ctx); + } + +func_prototype: var_modifiers type var_identifier '(' parameters ')' semantic + { + if (get_variable(hlsl_ctx.globals, $3)) + { + hlsl_report_message(hlsl_ctx.source_file, @3.first_line, @3.first_column, + HLSL_LEVEL_ERROR, "redefinition of '%s'\n", $3); + return 1; + } + if ($2->base_type == HLSL_TYPE_VOID && $7) + { + hlsl_report_message(hlsl_ctx.source_file, @7.first_line, @7.first_column, + HLSL_LEVEL_ERROR, "void function with a semantic"); + } + + $$.decl = new_func_decl($2, $5); + if (!$$.decl) + { + ERR("Out of memory.\n"); + return -1; + } + $$.name = $3; + $$.decl->semantic = $7; + set_location(&$$.decl->node.loc, &@3); + } + +compound_statement: '{' '}' + { + $$ = d3dcompiler_alloc(sizeof(*$$)); + list_init($$); + } + | '{' scope_start statement_list '}' + { + pop_scope(&hlsl_ctx); + $$ = $3; + } + +scope_start: /* Empty */ + { + push_scope(&hlsl_ctx); + } + +var_identifier: VAR_IDENTIFIER + | NEW_IDENTIFIER + +semantic: /* Empty */ + { + $$ = NULL; + } + | ':' any_identifier + { + $$ = $2; + } + +parameters: scope_start + { + $$ = d3dcompiler_alloc(sizeof(*$$)); + list_init($$); + } + | scope_start param_list + { + $$ = $2; + } + +param_list: parameter + { + struct source_location loc; + + $$ = d3dcompiler_alloc(sizeof(*$$)); + list_init($$); + set_location(&loc, &@1); + if (!add_func_parameter($$, &$1, &loc)) + { + ERR("Error adding function parameter %s.\n", $1.name); + set_parse_status(&hlsl_ctx.status, PARSE_ERR); + return -1; + } + } + | param_list ',' parameter + { + struct source_location loc; + + $$ = $1; + set_location(&loc, &@3); + if (!add_func_parameter($$, &$3, &loc)) + { + hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR, + "duplicate parameter %s", $3.name); + return 1; + } + } + +parameter: input_mods var_modifiers type any_identifier semantic + { + $$.modifiers = $1 ? $1 : HLSL_MODIFIER_IN; + $$.modifiers |= $2; + $$.type = $3; + $$.name = $4; + $$.semantic = $5; + } + +input_mods: /* Empty */ + { + $$ = 0; + } + | input_mods input_mod + { + if ($1 & $2) + { + hlsl_report_message(hlsl_ctx.source_file, @2.first_line, @2.first_column, + HLSL_LEVEL_ERROR, "duplicate input-output modifiers"); + return 1; + } + $$ = $1 | $2; + } + +input_mod: KW_IN + { + $$ = HLSL_MODIFIER_IN; + } + | KW_OUT + { + $$ = HLSL_MODIFIER_OUT; + } + | KW_INOUT + { + $$ = HLSL_MODIFIER_IN | HLSL_MODIFIER_OUT; + } + +type: base_type + { + $$ = $1; + } + | KW_VECTOR '<' base_type ',' C_INTEGER '>' + { + if ($3->type != HLSL_CLASS_SCALAR) + { + hlsl_message("Line %u: vectors of non-scalar types are not allowed.\n", + hlsl_ctx.line_no); + set_parse_status(&hlsl_ctx.status, PARSE_ERR); + return 1; + } + if ($5 < 1 || $5 > 4) + { + hlsl_message("Line %u: vector size must be between 1 and 4.\n", + hlsl_ctx.line_no); + set_parse_status(&hlsl_ctx.status, PARSE_ERR); + return 1; + } + + $$ = new_hlsl_type(NULL, HLSL_CLASS_VECTOR, $3->base_type, $5, 1); + } + | KW_MATRIX '<' base_type ',' C_INTEGER ',' C_INTEGER '>' + { + if ($3->type != HLSL_CLASS_SCALAR) + { + hlsl_message("Line %u: matrices of non-scalar types are not allowed.\n", + hlsl_ctx.line_no); + set_parse_status(&hlsl_ctx.status, PARSE_ERR); + return 1; + } + if ($5 < 1 || $5 > 4 || $7 < 1 || $7 > 4) + { + hlsl_message("Line %u: matrix dimensions must be between 1 and 4.\n", + hlsl_ctx.line_no); + set_parse_status(&hlsl_ctx.status, PARSE_ERR); + return 1; + } + + $$ = new_hlsl_type(NULL, HLSL_CLASS_MATRIX, $3->base_type, $5, $7); + } + +base_type: KW_VOID + { + $$ = new_hlsl_type(d3dcompiler_strdup("void"), HLSL_CLASS_OBJECT, HLSL_TYPE_VOID, 1, 1); + } + | KW_SAMPLER + { + $$ = new_hlsl_type(d3dcompiler_strdup("sampler"), HLSL_CLASS_OBJECT, HLSL_TYPE_SAMPLER, 1, 1); + $$->sampler_dim = HLSL_SAMPLER_DIM_GENERIC; + } + | KW_SAMPLER1D + { + $$ = new_hlsl_type(d3dcompiler_strdup("sampler1D"), HLSL_CLASS_OBJECT, HLSL_TYPE_SAMPLER, 1, 1); + $$->sampler_dim = HLSL_SAMPLER_DIM_1D; + } + | KW_SAMPLER2D + { + $$ = new_hlsl_type(d3dcompiler_strdup("sampler2D"), HLSL_CLASS_OBJECT, HLSL_TYPE_SAMPLER, 1, 1); + $$->sampler_dim = HLSL_SAMPLER_DIM_2D; + } + | KW_SAMPLER3D + { + $$ = new_hlsl_type(d3dcompiler_strdup("sampler3D"), HLSL_CLASS_OBJECT, HLSL_TYPE_SAMPLER, 1, 1); + $$->sampler_dim = HLSL_SAMPLER_DIM_3D; + } + | KW_SAMPLERCUBE + { + $$ = new_hlsl_type(d3dcompiler_strdup("samplerCUBE"), HLSL_CLASS_OBJECT, HLSL_TYPE_SAMPLER, 1, 1); + $$->sampler_dim = HLSL_SAMPLER_DIM_CUBE; + } + | TYPE_IDENTIFIER + { + struct hlsl_type *type; + + TRACE("Type %s.\n", $1); + type = get_type(hlsl_ctx.cur_scope, $1, TRUE); + $$ = type; + d3dcompiler_free($1); + } + | KW_STRUCT TYPE_IDENTIFIER + { + struct hlsl_type *type; + + TRACE("Struct type %s.\n", $2); + type = get_type(hlsl_ctx.cur_scope, $2, TRUE); + if (type->type != HLSL_CLASS_STRUCT) + { + hlsl_message("Line %u: redefining %s as a structure.\n", + hlsl_ctx.line_no, $2); + set_parse_status(&hlsl_ctx.status, PARSE_ERR); + } + else + { + $$ = type; + } + d3dcompiler_free($2); + } + +declaration_statement: declaration + | struct_declaration + | typedef + { + $$ = d3dcompiler_alloc(sizeof(*$$)); + if (!$$) + { + ERR("Out of memory\n"); + return -1; + } + list_init($$); + } + +typedef: KW_TYPEDEF var_modifiers type type_specs ';' + { + struct source_location loc; + + set_location(&loc, &@1); + if (!add_typedef($2, $3, $4, &loc)) + return 1; + } + | KW_TYPEDEF struct_spec type_specs ';' + { + struct source_location loc; + + set_location(&loc, &@1); + if (!add_typedef(0, $2, $3, &loc)) + return 1; + } + +type_specs: type_spec + { + $$ = d3dcompiler_alloc(sizeof(*$$)); + list_init($$); + list_add_head($$, &$1->entry); + } + | type_specs ',' type_spec + { + $$ = $1; + list_add_tail($$, &$3->entry); + } + +type_spec: any_identifier array + { + $$ = d3dcompiler_alloc(sizeof(*$$)); + set_location(&$$->loc, &@1); + $$->name = $1; + $$->array_size = $2; + } + +declaration: var_modifiers type variables_def ';' + { + $$ = declare_vars($2, $1, $3); + } + +variables_def_optional: /* Empty */ + { + $$ = NULL; + } + | variables_def + { + $$ = $1; + } + +variables_def: variable_def + { + $$ = d3dcompiler_alloc(sizeof(*$$)); + list_init($$); + list_add_head($$, &$1->entry); + } + | variables_def ',' variable_def + { + $$ = $1; + list_add_tail($$, &$3->entry); + } + +variable_def: any_identifier array semantic + { + $$ = d3dcompiler_alloc(sizeof(*$$)); + set_location(&$$->loc, &@1); + $$->name = $1; + $$->array_size = $2; + $$->semantic = $3; + } + | any_identifier array semantic '=' complex_initializer + { + TRACE("Declaration with initializer.\n"); + $$ = d3dcompiler_alloc(sizeof(*$$)); + set_location(&$$->loc, &@1); + $$->name = $1; + $$->array_size = $2; + $$->semantic = $3; + $$->initializer = $5; + } + +array: /* Empty */ + { + $$ = 0; + } + | '[' expr ']' + { + FIXME("Array.\n"); + $$ = 0; + free_instr($2); + } + +var_modifiers: /* Empty */ + { + $$ = 0; + } + | KW_EXTERN var_modifiers + { + $$ = add_modifier($2, HLSL_STORAGE_EXTERN, &@1); + } + | KW_NOINTERPOLATION var_modifiers + { + $$ = add_modifier($2, HLSL_STORAGE_NOINTERPOLATION, &@1); + } + | KW_PRECISE var_modifiers + { + $$ = add_modifier($2, HLSL_MODIFIER_PRECISE, &@1); + } + | KW_SHARED var_modifiers + { + $$ = add_modifier($2, HLSL_STORAGE_SHARED, &@1); + } + | KW_GROUPSHARED var_modifiers + { + $$ = add_modifier($2, HLSL_STORAGE_GROUPSHARED, &@1); + } + | KW_STATIC var_modifiers + { + $$ = add_modifier($2, HLSL_STORAGE_STATIC, &@1); + } + | KW_UNIFORM var_modifiers + { + $$ = add_modifier($2, HLSL_STORAGE_UNIFORM, &@1); + } + | KW_VOLATILE var_modifiers + { + $$ = add_modifier($2, HLSL_STORAGE_VOLATILE, &@1); + } + | KW_CONST var_modifiers + { + $$ = add_modifier($2, HLSL_MODIFIER_CONST, &@1); + } + | KW_ROW_MAJOR var_modifiers + { + $$ = add_modifier($2, HLSL_MODIFIER_ROW_MAJOR, &@1); + } + | KW_COLUMN_MAJOR var_modifiers + { + $$ = add_modifier($2, HLSL_MODIFIER_COLUMN_MAJOR, &@1); + } + +complex_initializer: initializer_expr + { + $$ = d3dcompiler_alloc(sizeof(*$$)); + list_init($$); + list_add_head($$, &$1->entry); + } + | '{' initializer_expr_list '}' + { + $$ = $2; + } + | '{' initializer_expr_list ',' '}' + { + $$ = $2; + } + +initializer_expr: assignment_expr + { + $$ = $1; + } + +initializer_expr_list: initializer_expr + { + $$ = d3dcompiler_alloc(sizeof(*$$)); + list_init($$); + list_add_head($$, &$1->entry); + } + | initializer_expr_list ',' initializer_expr + { + $$ = $1; + list_add_tail($$, &$3->entry); + } + +boolean: KW_TRUE + { + $$ = TRUE; + } + | KW_FALSE + { + $$ = FALSE; + } + +statement_list: statement + { + $$ = $1; + } + | statement_list statement + { + $$ = $1; + list_move_tail($$, $2); + d3dcompiler_free($2); + } + +statement: declaration_statement + | expr_statement + | compound_statement + | jump_statement + | selection_statement + | loop_statement + + /* FIXME: add rule for return with no value */ +jump_statement: KW_RETURN expr ';' + { + struct hlsl_ir_jump *jump = d3dcompiler_alloc(sizeof(*jump)); + if (!jump) + { + ERR("Out of memory\n"); + return -1; + } + jump->node.type = HLSL_IR_JUMP; + set_location(&jump->node.loc, &@1); + jump->type = HLSL_IR_JUMP_RETURN; + jump->node.data_type = $2->data_type; + jump->return_value = $2; + + FIXME("Check for valued return on void function.\n"); + FIXME("Implicit conversion to the return type if needed, " + "error out if conversion not possible.\n"); + + $$ = d3dcompiler_alloc(sizeof(*$$)); + list_init($$); + list_add_tail($$, &jump->node.entry); + } + +selection_statement: KW_IF '(' expr ')' if_body + { + struct hlsl_ir_if *instr = d3dcompiler_alloc(sizeof(*instr)); + if (!instr) + { + ERR("Out of memory\n"); + return -1; + } + instr->node.type = HLSL_IR_IF; + set_location(&instr->node.loc, &@1); + instr->condition = $3; + instr->then_instrs = $5.then_instrs; + instr->else_instrs = $5.else_instrs; + if ($3->data_type->dimx > 1 || $3->data_type->dimy > 1) + { + hlsl_report_message(instr->node.loc.file, instr->node.loc.line, + instr->node.loc.col, HLSL_LEVEL_ERROR, + "if condition requires a scalar"); + } + $$ = d3dcompiler_alloc(sizeof(*$$)); + list_init($$); + list_add_head($$, &instr->node.entry); + } + +if_body: statement + { + $$.then_instrs = $1; + $$.else_instrs = NULL; + } + | statement KW_ELSE statement + { + $$.then_instrs = $1; + $$.else_instrs = $3; + } + +loop_statement: KW_WHILE '(' expr ')' statement + { + struct source_location loc; + struct list *cond = d3dcompiler_alloc(sizeof(*cond)); + + if (!cond) + { + ERR("Out of memory.\n"); + return -1; + } + list_init(cond); + list_add_head(cond, &$3->entry); + set_location(&loc, &@1); + $$ = create_loop(LOOP_WHILE, NULL, cond, NULL, $5, &loc); + } + | KW_DO statement KW_WHILE '(' expr ')' ';' + { + struct source_location loc; + struct list *cond = d3dcompiler_alloc(sizeof(*cond)); + + if (!cond) + { + ERR("Out of memory.\n"); + return -1; + } + list_init(cond); + list_add_head(cond, &$5->entry); + set_location(&loc, &@1); + $$ = create_loop(LOOP_DO_WHILE, NULL, cond, NULL, $2, &loc); + } + | KW_FOR '(' scope_start expr_statement expr_statement expr ')' statement + { + struct source_location loc; + + set_location(&loc, &@1); + $$ = create_loop(LOOP_FOR, $4, $5, $6, $8, &loc); + pop_scope(&hlsl_ctx); + } + | KW_FOR '(' scope_start declaration expr_statement expr ')' statement + { + struct source_location loc; + + set_location(&loc, &@1); + if (!$4) + hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_WARNING, + "no expressions in for loop initializer"); + $$ = create_loop(LOOP_FOR, $4, $5, $6, $8, &loc); + pop_scope(&hlsl_ctx); + } + +expr_statement: ';' + { + $$ = d3dcompiler_alloc(sizeof(*$$)); + list_init($$); + } + | expr ';' + { + $$ = d3dcompiler_alloc(sizeof(*$$)); + list_init($$); + if ($1) + list_add_head($$, &$1->entry); + } + +primary_expr: C_FLOAT + { + struct hlsl_ir_constant *c = d3dcompiler_alloc(sizeof(*c)); + if (!c) + { + ERR("Out of memory.\n"); + return -1; + } + c->node.type = HLSL_IR_CONSTANT; + set_location(&c->node.loc, &yylloc); + c->node.data_type = new_hlsl_type(d3dcompiler_strdup("float"), HLSL_CLASS_SCALAR, HLSL_TYPE_FLOAT, 1, 1); + c->v.value.f[0] = $1; + $$ = &c->node; + } + | C_INTEGER + { + struct hlsl_ir_constant *c = d3dcompiler_alloc(sizeof(*c)); + if (!c) + { + ERR("Out of memory.\n"); + return -1; + } + c->node.type = HLSL_IR_CONSTANT; + set_location(&c->node.loc, &yylloc); + c->node.data_type = new_hlsl_type(d3dcompiler_strdup("int"), HLSL_CLASS_SCALAR, HLSL_TYPE_INT, 1, 1); + c->v.value.i[0] = $1; + $$ = &c->node; + } + | boolean + { + struct hlsl_ir_constant *c = d3dcompiler_alloc(sizeof(*c)); + if (!c) + { + ERR("Out of memory.\n"); + return -1; + } + c->node.type = HLSL_IR_CONSTANT; + set_location(&c->node.loc, &yylloc); + c->node.data_type = new_hlsl_type(d3dcompiler_strdup("bool"), HLSL_CLASS_SCALAR, HLSL_TYPE_BOOL, 1, 1); + c->v.value.b[0] = $1; + $$ = &c->node; + } + | variable + { + struct hlsl_ir_deref *deref = new_var_deref($1); + if (deref) + { + $$ = &deref->node; + set_location(&$$->loc, &@1); + } + else + $$ = NULL; + } + | '(' expr ')' + { + $$ = $2; + } + +variable: VAR_IDENTIFIER + { + struct hlsl_ir_var *var; + var = get_variable(hlsl_ctx.cur_scope, $1); + if (!var) + { + hlsl_message("Line %d: variable '%s' not declared\n", + hlsl_ctx.line_no, $1); + set_parse_status(&hlsl_ctx.status, PARSE_ERR); + return 1; + } + $$ = var; + } + +postfix_expr: primary_expr + { + $$ = $1; + } + | postfix_expr OP_INC + { + struct hlsl_ir_node *operands[3]; + struct source_location loc; + + set_location(&loc, &@2); + if ($1->data_type->modifiers & HLSL_MODIFIER_CONST) + { + hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR, + "modifying a const expression"); + return 1; + } + operands[0] = $1; + operands[1] = operands[2] = NULL; + $$ = &new_expr(HLSL_IR_BINOP_POSTINC, operands, &loc)->node; + /* Post increment/decrement expressions are considered const */ + $$->data_type = clone_hlsl_type($$->data_type); + $$->data_type->modifiers |= HLSL_MODIFIER_CONST; + } + | postfix_expr OP_DEC + { + struct hlsl_ir_node *operands[3]; + struct source_location loc; + + set_location(&loc, &@2); + if ($1->data_type->modifiers & HLSL_MODIFIER_CONST) + { + hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR, + "modifying a const expression"); + return 1; + } + operands[0] = $1; + operands[1] = operands[2] = NULL; + $$ = &new_expr(HLSL_IR_BINOP_POSTDEC, operands, &loc)->node; + /* Post increment/decrement expressions are considered const */ + $$->data_type = clone_hlsl_type($$->data_type); + $$->data_type->modifiers |= HLSL_MODIFIER_CONST; + } + | postfix_expr '.' any_identifier + { + struct source_location loc; + + set_location(&loc, &@2); + if ($1->data_type->type == HLSL_CLASS_STRUCT) + { + struct hlsl_type *type = $1->data_type; + struct hlsl_struct_field *field; + + $$ = NULL; + LIST_FOR_EACH_ENTRY(field, type->e.elements, struct hlsl_struct_field, entry) + { + if (!strcmp($3, field->name)) + { + struct hlsl_ir_deref *deref = new_record_deref($1, field); + + if (!deref) + { + ERR("Out of memory\n"); + return -1; + } + deref->node.loc = loc; + $$ = &deref->node; + break; + } + } + if (!$$) + { + hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR, + "invalid subscript %s", debugstr_a($3)); + return 1; + } + } + else if ($1->data_type->type <= HLSL_CLASS_LAST_NUMERIC) + { + struct hlsl_ir_swizzle *swizzle; + + swizzle = get_swizzle($1, $3, &loc); + if (!swizzle) + { + hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR, + "invalid swizzle %s", debugstr_a($3)); + return 1; + } + $$ = &swizzle->node; + } + else + { + hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR, + "invalid subscript %s", debugstr_a($3)); + return 1; + } + } + | postfix_expr '[' expr ']' + { + /* This may be an array dereference or a vector/matrix + * subcomponent access. + * We store it as an array dereference in any case. */ + struct hlsl_ir_deref *deref = d3dcompiler_alloc(sizeof(*deref)); + struct hlsl_type *expr_type = $1->data_type; + struct source_location loc; + + TRACE("Array dereference from type %s\n", debug_hlsl_type(expr_type)); + if (!deref) + { + ERR("Out of memory\n"); + return -1; + } + deref->node.type = HLSL_IR_DEREF; + set_location(&loc, &@2); + deref->node.loc = loc; + if (expr_type->type == HLSL_CLASS_ARRAY) + { + deref->node.data_type = expr_type->e.array.type; + } + else if (expr_type->type == HLSL_CLASS_MATRIX) + { + deref->node.data_type = new_hlsl_type(NULL, HLSL_CLASS_VECTOR, expr_type->base_type, expr_type->dimx, 1); + } + else if (expr_type->type == HLSL_CLASS_VECTOR) + { + deref->node.data_type = new_hlsl_type(NULL, HLSL_CLASS_SCALAR, expr_type->base_type, 1, 1); + } + else + { + if (expr_type->type == HLSL_CLASS_SCALAR) + hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR, + "array-indexed expression is scalar"); + else + hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR, + "expression is not array-indexable"); + d3dcompiler_free(deref); + free_instr($1); + free_instr($3); + return 1; + } + if ($3->data_type->type != HLSL_CLASS_SCALAR) + { + hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR, + "array index is not scalar"); + d3dcompiler_free(deref); + free_instr($1); + free_instr($3); + return 1; + } + deref->type = HLSL_IR_DEREF_ARRAY; + deref->v.array.array = $1; + deref->v.array.index = $3; + + $$ = &deref->node; + } + /* "var_modifiers" doesn't make sense in this case, but it's needed + in the grammar to avoid shift/reduce conflicts. */ + | var_modifiers type '(' initializer_expr_list ')' + { + struct hlsl_ir_constructor *constructor; + + TRACE("%s constructor.\n", debug_hlsl_type($2)); + if ($1) + { + hlsl_message("Line %u: unexpected modifier in a constructor.\n", + hlsl_ctx.line_no); + set_parse_status(&hlsl_ctx.status, PARSE_ERR); + return -1; + } + if ($2->type > HLSL_CLASS_LAST_NUMERIC) + { + hlsl_message("Line %u: constructors are allowed only for numeric data types.\n", + hlsl_ctx.line_no); + set_parse_status(&hlsl_ctx.status, PARSE_ERR); + return -1; + } + if ($2->dimx * $2->dimy != components_count_expr_list($4)) + { + hlsl_message("Line %u: wrong number of components in constructor.\n", + hlsl_ctx.line_no); + set_parse_status(&hlsl_ctx.status, PARSE_ERR); + return -1; + } + + constructor = d3dcompiler_alloc(sizeof(*constructor)); + constructor->node.type = HLSL_IR_CONSTRUCTOR; + set_location(&constructor->node.loc, &@3); + constructor->node.data_type = $2; + constructor->arguments = $4; + + $$ = &constructor->node; + } + +unary_expr: postfix_expr + { + $$ = $1; + } + | OP_INC unary_expr + { + struct hlsl_ir_node *operands[3]; + struct source_location loc; + + set_location(&loc, &@1); + if ($2->data_type->modifiers & HLSL_MODIFIER_CONST) + { + hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR, + "modifying a const expression"); + return 1; + } + operands[0] = $2; + operands[1] = operands[2] = NULL; + $$ = &new_expr(HLSL_IR_BINOP_PREINC, operands, &loc)->node; + } + | OP_DEC unary_expr + { + struct hlsl_ir_node *operands[3]; + struct source_location loc; + + set_location(&loc, &@1); + if ($2->data_type->modifiers & HLSL_MODIFIER_CONST) + { + hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR, + "modifying a const expression"); + return 1; + } + operands[0] = $2; + operands[1] = operands[2] = NULL; + $$ = &new_expr(HLSL_IR_BINOP_PREDEC, operands, &loc)->node; + } + | unary_op unary_expr + { + enum hlsl_ir_expr_op ops[] = {0, HLSL_IR_UNOP_NEG, + HLSL_IR_UNOP_LOGIC_NOT, HLSL_IR_UNOP_BIT_NOT}; + struct hlsl_ir_node *operands[3]; + struct source_location loc; + + if ($1 == UNARY_OP_PLUS) + { + $$ = $2; + } + else + { + operands[0] = $2; + operands[1] = operands[2] = NULL; + set_location(&loc, &@1); + $$ = &new_expr(ops[$1], operands, &loc)->node; + } + } + /* var_modifiers just to avoid shift/reduce conflicts */ + | '(' var_modifiers type array ')' unary_expr + { + struct hlsl_ir_expr *expr; + struct hlsl_type *src_type = $6->data_type; + struct hlsl_type *dst_type; + struct source_location loc; + + set_location(&loc, &@3); + if ($2) + { + hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR, + "unexpected modifier in a cast"); + return 1; + } + + if ($4) + dst_type = new_array_type($3, $4); + else + dst_type = $3; + + if (!compatible_data_types(src_type, dst_type)) + { + hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR, + "can't cast from %s to %s", + debug_hlsl_type(src_type), debug_hlsl_type(dst_type)); + return 1; + } + + expr = new_cast($6, dst_type, &loc); + $$ = expr ? &expr->node : NULL; + } + +unary_op: '+' + { + $$ = UNARY_OP_PLUS; + } + | '-' + { + $$ = UNARY_OP_MINUS; + } + | '!' + { + $$ = UNARY_OP_LOGICNOT; + } + | '~' + { + $$ = UNARY_OP_BITNOT; + } + +mul_expr: unary_expr + { + $$ = $1; + } + | mul_expr '*' unary_expr + { + struct source_location loc; + + set_location(&loc, &@2); + $$ = &hlsl_mul($1, $3, &loc)->node; + } + | mul_expr '/' unary_expr + { + struct source_location loc; + + set_location(&loc, &@2); + $$ = &hlsl_div($1, $3, &loc)->node; + } + | mul_expr '%' unary_expr + { + struct source_location loc; + + set_location(&loc, &@2); + $$ = &hlsl_mod($1, $3, &loc)->node; + } + +add_expr: mul_expr + { + $$ = $1; + } + | add_expr '+' mul_expr + { + struct source_location loc; + + set_location(&loc, &@2); + $$ = &hlsl_add($1, $3, &loc)->node; + } + | add_expr '-' mul_expr + { + struct source_location loc; + + set_location(&loc, &@2); + $$ = &hlsl_sub($1, $3, &loc)->node; + } + +shift_expr: add_expr + { + $$ = $1; + } + | shift_expr OP_LEFTSHIFT add_expr + { + FIXME("Left shift\n"); + } + | shift_expr OP_RIGHTSHIFT add_expr + { + FIXME("Right shift\n"); + } + +relational_expr: shift_expr + { + $$ = $1; + } + | relational_expr '<' shift_expr + { + struct source_location loc; + + set_location(&loc, &@2); + $$ = &hlsl_lt($1, $3, &loc)->node; + } + | relational_expr '>' shift_expr + { + struct source_location loc; + + set_location(&loc, &@2); + $$ = &hlsl_gt($1, $3, &loc)->node; + } + | relational_expr OP_LE shift_expr + { + struct source_location loc; + + set_location(&loc, &@2); + $$ = &hlsl_le($1, $3, &loc)->node; + } + | relational_expr OP_GE shift_expr + { + struct source_location loc; + + set_location(&loc, &@2); + $$ = &hlsl_ge($1, $3, &loc)->node; + } + +equality_expr: relational_expr + { + $$ = $1; + } + | equality_expr OP_EQ relational_expr + { + struct source_location loc; + + set_location(&loc, &@2); + $$ = &hlsl_eq($1, $3, &loc)->node; + } + | equality_expr OP_NE relational_expr + { + struct source_location loc; + + set_location(&loc, &@2); + $$ = &hlsl_ne($1, $3, &loc)->node; + } + +bitand_expr: equality_expr + { + $$ = $1; + } + | bitand_expr '&' equality_expr + { + FIXME("bitwise AND\n"); + } + +bitxor_expr: bitand_expr + { + $$ = $1; + } + | bitxor_expr '^' bitand_expr + { + FIXME("bitwise XOR\n"); + } + +bitor_expr: bitxor_expr + { + $$ = $1; + } + | bitor_expr '|' bitxor_expr + { + FIXME("bitwise OR\n"); + } + +logicand_expr: bitor_expr + { + $$ = $1; + } + | logicand_expr OP_AND bitor_expr + { + FIXME("logic AND\n"); + } + +logicor_expr: logicand_expr + { + $$ = $1; + } + | logicor_expr OP_OR logicand_expr + { + FIXME("logic OR\n"); + } + +conditional_expr: logicor_expr + { + $$ = $1; + } + | logicor_expr '?' expr ':' assignment_expr + { + FIXME("ternary operator\n"); + } + +assignment_expr: conditional_expr + { + $$ = $1; + } + | unary_expr assign_op assignment_expr + { + struct source_location loc; + + set_location(&loc, &@2); + if ($1->data_type->modifiers & HLSL_MODIFIER_CONST) + { + hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR, + "l-value is const"); + return 1; + } + $$ = make_assignment($1, $2, BWRITERSP_WRITEMASK_ALL, $3); + if (!$$) + return 1; + $$->loc = loc; + } + +assign_op: '=' + { + $$ = ASSIGN_OP_ASSIGN; + } + | OP_ADDASSIGN + { + $$ = ASSIGN_OP_ADD; + } + | OP_SUBASSIGN + { + $$ = ASSIGN_OP_SUB; + } + | OP_MULASSIGN + { + $$ = ASSIGN_OP_MUL; + } + | OP_DIVASSIGN + { + $$ = ASSIGN_OP_DIV; + } + | OP_MODASSIGN + { + $$ = ASSIGN_OP_MOD; + } + | OP_LEFTSHIFTASSIGN + { + $$ = ASSIGN_OP_LSHIFT; + } + | OP_RIGHTSHIFTASSIGN + { + $$ = ASSIGN_OP_RSHIFT; + } + | OP_ANDASSIGN + { + $$ = ASSIGN_OP_AND; + } + | OP_ORASSIGN + { + $$ = ASSIGN_OP_OR; + } + | OP_XORASSIGN + { + $$ = ASSIGN_OP_XOR; + } + +expr: assignment_expr + { + $$ = $1; + } + | expr ',' assignment_expr + { + FIXME("Comma expression\n"); + } + +%% + +static void set_location(struct source_location *loc, const struct YYLTYPE *l) +{ + loc->file = hlsl_ctx.source_file; + loc->line = l->first_line; + loc->col = l->first_column; +} + +static DWORD add_modifier(DWORD modifiers, DWORD mod, const struct YYLTYPE *loc) +{ + if (modifiers & mod) + { + hlsl_report_message(hlsl_ctx.source_file, loc->first_line, loc->first_column, HLSL_LEVEL_ERROR, + "modifier '%s' already specified", debug_modifiers(mod)); + return modifiers; + } + if (mod & (HLSL_MODIFIER_ROW_MAJOR | HLSL_MODIFIER_COLUMN_MAJOR) + && modifiers & (HLSL_MODIFIER_ROW_MAJOR | HLSL_MODIFIER_COLUMN_MAJOR)) + { + hlsl_report_message(hlsl_ctx.source_file, loc->first_line, loc->first_column, HLSL_LEVEL_ERROR, + "more than one matrix majority keyword"); + return modifiers; + } + return modifiers | mod; +} + +static void dump_function_decl(struct wine_rb_entry *entry, void *context) +{ + struct hlsl_ir_function_decl *func = WINE_RB_ENTRY_VALUE(entry, struct hlsl_ir_function_decl, entry); + if (func->body) + debug_dump_ir_function_decl(func); +} + +static void dump_function(struct wine_rb_entry *entry, void *context) +{ + struct hlsl_ir_function *func = WINE_RB_ENTRY_VALUE(entry, struct hlsl_ir_function, entry); + wine_rb_for_each_entry(&func->overloads, dump_function_decl, NULL); +} + +struct bwriter_shader *parse_hlsl(enum shader_type type, DWORD major, DWORD minor, + const char *entrypoint, char **messages) +{ + struct hlsl_scope *scope, *next_scope; + struct hlsl_type *hlsl_type, *next_type; + struct hlsl_ir_var *var, *next_var; + unsigned int i; + + hlsl_ctx.status = PARSE_SUCCESS; + hlsl_ctx.messages.size = hlsl_ctx.messages.capacity = 0; + hlsl_ctx.line_no = hlsl_ctx.column = 1; + hlsl_ctx.source_file = d3dcompiler_strdup(""); + hlsl_ctx.source_files = d3dcompiler_alloc(sizeof(*hlsl_ctx.source_files)); + if (hlsl_ctx.source_files) + hlsl_ctx.source_files[0] = hlsl_ctx.source_file; + hlsl_ctx.source_files_count = 1; + hlsl_ctx.cur_scope = NULL; + hlsl_ctx.matrix_majority = HLSL_COLUMN_MAJOR; + list_init(&hlsl_ctx.scopes); + list_init(&hlsl_ctx.types); + init_functions_tree(&hlsl_ctx.functions); + + push_scope(&hlsl_ctx); + hlsl_ctx.globals = hlsl_ctx.cur_scope; + declare_predefined_types(hlsl_ctx.globals); + + hlsl_parse(); + + if (TRACE_ON(hlsl_parser)) + { + TRACE("IR dump.\n"); + wine_rb_for_each_entry(&hlsl_ctx.functions, dump_function, NULL); + } + + TRACE("Compilation status = %d\n", hlsl_ctx.status); + if (messages) + { + if (hlsl_ctx.messages.size) + *messages = hlsl_ctx.messages.string; + else + *messages = NULL; + } + else + { + if (hlsl_ctx.messages.capacity) + d3dcompiler_free(hlsl_ctx.messages.string); + } + + for (i = 0; i < hlsl_ctx.source_files_count; ++i) + d3dcompiler_free((void *)hlsl_ctx.source_files[i]); + d3dcompiler_free(hlsl_ctx.source_files); + + TRACE("Freeing functions IR.\n"); + wine_rb_destroy(&hlsl_ctx.functions, free_function_rb, NULL); + + TRACE("Freeing variables.\n"); + LIST_FOR_EACH_ENTRY_SAFE(scope, next_scope, &hlsl_ctx.scopes, struct hlsl_scope, entry) + { + LIST_FOR_EACH_ENTRY_SAFE(var, next_var, &scope->vars, struct hlsl_ir_var, scope_entry) + { + free_declaration(var); + } + wine_rb_destroy(&scope->types, NULL, NULL); + d3dcompiler_free(scope); + } + + TRACE("Freeing types.\n"); + LIST_FOR_EACH_ENTRY_SAFE(hlsl_type, next_type, &hlsl_ctx.types, struct hlsl_type, entry) + { + free_hlsl_type(hlsl_type); + } + + return NULL; +} diff --git a/reactos/dll/directx/wine/d3dcompiler_43/hlsl.yy.c b/reactos/dll/directx/wine/d3dcompiler_43/hlsl.yy.c new file mode 100644 index 00000000000..a3e98d5543c --- /dev/null +++ b/reactos/dll/directx/wine/d3dcompiler_43/hlsl.yy.c @@ -0,0 +1,2954 @@ +#line 2 "hlsl.yy.c" + +#line 4 "hlsl.yy.c" + +#define YY_INT_ALIGNED short int + +/* A lexical scanner generated by flex */ + +#define yy_create_buffer hlsl__create_buffer +#define yy_delete_buffer hlsl__delete_buffer +#define yy_flex_debug hlsl__flex_debug +#define yy_init_buffer hlsl__init_buffer +#define yy_flush_buffer hlsl__flush_buffer +#define yy_load_buffer_state hlsl__load_buffer_state +#define yy_switch_to_buffer hlsl__switch_to_buffer +#define yyin hlsl_in +#define yyleng hlsl_leng +#define yylex hlsl_lex +#define yylineno hlsl_lineno +#define yyout hlsl_out +#define yyrestart hlsl_restart +#define yytext hlsl_text +#define yywrap hlsl_wrap +#define yyalloc hlsl_alloc +#define yyrealloc hlsl_realloc +#define yyfree hlsl_free + +#define FLEX_SCANNER +#define YY_FLEX_MAJOR_VERSION 2 +#define YY_FLEX_MINOR_VERSION 5 +#define YY_FLEX_SUBMINOR_VERSION 35 +#if YY_FLEX_SUBMINOR_VERSION > 0 +#define FLEX_BETA +#endif + +/* First, we deal with platform-specific or compiler-specific issues. */ + +/* begin standard C headers. */ +#include +#include +#include +#include + +/* end standard C headers. */ + +/* flex integer type definitions */ + +#ifndef FLEXINT_H +#define FLEXINT_H + +/* C99 systems have . Non-C99 systems may or may not. */ + +#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + +/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, + * if you want the limit (max/min) macros for int types. + */ +#ifndef __STDC_LIMIT_MACROS +#define __STDC_LIMIT_MACROS 1 +#endif + +#include +typedef int8_t flex_int8_t; +typedef uint8_t flex_uint8_t; +typedef int16_t flex_int16_t; +typedef uint16_t flex_uint16_t; +typedef int32_t flex_int32_t; +typedef uint32_t flex_uint32_t; +#else +typedef signed char flex_int8_t; +typedef short int flex_int16_t; +typedef int flex_int32_t; +typedef unsigned char flex_uint8_t; +typedef unsigned short int flex_uint16_t; +typedef unsigned int flex_uint32_t; + +/* Limits of integral types. */ +#ifndef INT8_MIN +#define INT8_MIN (-128) +#endif +#ifndef INT16_MIN +#define INT16_MIN (-32767-1) +#endif +#ifndef INT32_MIN +#define INT32_MIN (-2147483647-1) +#endif +#ifndef INT8_MAX +#define INT8_MAX (127) +#endif +#ifndef INT16_MAX +#define INT16_MAX (32767) +#endif +#ifndef INT32_MAX +#define INT32_MAX (2147483647) +#endif +#ifndef UINT8_MAX +#define UINT8_MAX (255U) +#endif +#ifndef UINT16_MAX +#define UINT16_MAX (65535U) +#endif +#ifndef UINT32_MAX +#define UINT32_MAX (4294967295U) +#endif + +#endif /* ! C99 */ + +#endif /* ! FLEXINT_H */ + +#ifdef __cplusplus + +/* The "const" storage-class-modifier is valid. */ +#define YY_USE_CONST + +#else /* ! __cplusplus */ + +/* C99 requires __STDC__ to be defined as 1. */ +#if defined (__STDC__) + +#define YY_USE_CONST + +#endif /* defined (__STDC__) */ +#endif /* ! __cplusplus */ + +#ifdef YY_USE_CONST +#define yyconst const +#else +#define yyconst +#endif + +/* Returned upon end-of-file. */ +#define YY_NULL 0 + +/* Promotes a possibly negative, possibly signed char to an unsigned + * integer for use as an array index. If the signed char is negative, + * we want to instead treat it as an 8-bit unsigned char, hence the + * double cast. + */ +#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c) + +/* Enter a start condition. This macro really ought to take a parameter, + * but we do it the disgusting crufty way forced on us by the ()-less + * definition of BEGIN. + */ +#define BEGIN (yy_start) = 1 + 2 * + +/* Translate the current start state into a value that can be later handed + * to BEGIN to return to the state. The YYSTATE alias is for lex + * compatibility. + */ +#define YY_START (((yy_start) - 1) / 2) +#define YYSTATE YY_START + +/* Action number for EOF rule of a given start state. */ +#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) + +/* Special action meaning "start processing a new file". */ +#define YY_NEW_FILE hlsl_restart(hlsl_in ) + +#define YY_END_OF_BUFFER_CHAR 0 + +/* Size of default input buffer. */ +#ifndef YY_BUF_SIZE +#ifdef __ia64__ +/* On IA-64, the buffer size is 16k, not 8k. + * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case. + * Ditto for the __ia64__ case accordingly. + */ +#define YY_BUF_SIZE 32768 +#else +#define YY_BUF_SIZE 16384 +#endif /* __ia64__ */ +#endif + +/* The state buf must be large enough to hold one state per character in the main buffer. + */ +#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type)) + +#ifndef YY_TYPEDEF_YY_BUFFER_STATE +#define YY_TYPEDEF_YY_BUFFER_STATE +typedef struct yy_buffer_state *YY_BUFFER_STATE; +#endif + +extern int hlsl_leng; + +extern FILE *hlsl_in, *hlsl_out; + +#define EOB_ACT_CONTINUE_SCAN 0 +#define EOB_ACT_END_OF_FILE 1 +#define EOB_ACT_LAST_MATCH 2 + + #define YY_LESS_LINENO(n) + +/* Return all but the first "n" matched characters back to the input stream. */ +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up hlsl_text. */ \ + int yyless_macro_arg = (n); \ + YY_LESS_LINENO(yyless_macro_arg);\ + *yy_cp = (yy_hold_char); \ + YY_RESTORE_YY_MORE_OFFSET \ + (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ + YY_DO_BEFORE_ACTION; /* set up hlsl_text again */ \ + } \ + while ( 0 ) + +#define unput(c) yyunput( c, (yytext_ptr) ) + +#ifndef YY_TYPEDEF_YY_SIZE_T +#define YY_TYPEDEF_YY_SIZE_T +typedef size_t yy_size_t; +#endif + +#ifndef YY_STRUCT_YY_BUFFER_STATE +#define YY_STRUCT_YY_BUFFER_STATE +struct yy_buffer_state + { + FILE *yy_input_file; + + char *yy_ch_buf; /* input buffer */ + char *yy_buf_pos; /* current position in input buffer */ + + /* Size of input buffer in bytes, not including room for EOB + * characters. + */ + yy_size_t yy_buf_size; + + /* Number of characters read into yy_ch_buf, not including EOB + * characters. + */ + int yy_n_chars; + + /* Whether we "own" the buffer - i.e., we know we created it, + * and can realloc() it to grow it, and should free() it to + * delete it. + */ + int yy_is_our_buffer; + + /* Whether this is an "interactive" input source; if so, and + * if we're using stdio for input, then we want to use getc() + * instead of fread(), to make sure we stop fetching input after + * each newline. + */ + int yy_is_interactive; + + /* Whether we're considered to be at the beginning of a line. + * If so, '^' rules will be active on the next match, otherwise + * not. + */ + int yy_at_bol; + + int yy_bs_lineno; /**< The line count. */ + int yy_bs_column; /**< The column count. */ + + /* Whether to try to fill the input buffer when we reach the + * end of it. + */ + int yy_fill_buffer; + + int yy_buffer_status; + +#define YY_BUFFER_NEW 0 +#define YY_BUFFER_NORMAL 1 + /* When an EOF's been seen but there's still some text to process + * then we mark the buffer as YY_EOF_PENDING, to indicate that we + * shouldn't try reading from the input source any more. We might + * still have a bunch of tokens to match, though, because of + * possible backing-up. + * + * When we actually see the EOF, we change the status to "new" + * (via hlsl_restart()), so that the user can continue scanning by + * just pointing hlsl_in at a new input file. + */ +#define YY_BUFFER_EOF_PENDING 2 + + }; +#endif /* !YY_STRUCT_YY_BUFFER_STATE */ + +/* Stack of input buffers. */ +static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */ +static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */ +static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */ + +/* We provide macros for accessing buffer states in case in the + * future we want to put the buffer states in a more general + * "scanner state". + * + * Returns the top of the stack, or NULL. + */ +#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \ + ? (yy_buffer_stack)[(yy_buffer_stack_top)] \ + : NULL) + +/* Same as previous macro, but useful when we know that the buffer stack is not + * NULL or when we need an lvalue. For internal use only. + */ +#define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)] + +/* yy_hold_char holds the character lost when hlsl_text is formed. */ +static char yy_hold_char; +static int yy_n_chars; /* number of characters read into yy_ch_buf */ +int hlsl_leng; + +/* Points to current character in buffer. */ +static char *yy_c_buf_p = (char *) 0; +static int yy_init = 0; /* whether we need to initialize */ +static int yy_start = 0; /* start state number */ + +/* Flag which is used to allow hlsl_wrap()'s to do buffer switches + * instead of setting up a fresh hlsl_in. A bit of a hack ... + */ +static int yy_did_buffer_switch_on_eof; + +void hlsl_restart (FILE *input_file ); +void hlsl__switch_to_buffer (YY_BUFFER_STATE new_buffer ); +YY_BUFFER_STATE hlsl__create_buffer (FILE *file,int size ); +void hlsl__delete_buffer (YY_BUFFER_STATE b ); +void hlsl__flush_buffer (YY_BUFFER_STATE b ); +void hlsl_push_buffer_state (YY_BUFFER_STATE new_buffer ); +void hlsl_pop_buffer_state (void ); + +static void hlsl_ensure_buffer_stack (void ); +static void hlsl__load_buffer_state (void ); +static void hlsl__init_buffer (YY_BUFFER_STATE b,FILE *file ); + +#define YY_FLUSH_BUFFER hlsl__flush_buffer(YY_CURRENT_BUFFER ) + +YY_BUFFER_STATE hlsl__scan_buffer (char *base,yy_size_t size ); +YY_BUFFER_STATE hlsl__scan_string (yyconst char *yy_str ); +YY_BUFFER_STATE hlsl__scan_bytes (yyconst char *bytes,int len ); + +void *hlsl_alloc (yy_size_t ); +void *hlsl_realloc (void *,yy_size_t ); +void hlsl_free (void * ); + +#define yy_new_buffer hlsl__create_buffer + +#define yy_set_interactive(is_interactive) \ + { \ + if ( ! YY_CURRENT_BUFFER ){ \ + hlsl_ensure_buffer_stack (); \ + YY_CURRENT_BUFFER_LVALUE = \ + hlsl__create_buffer(hlsl_in,YY_BUF_SIZE ); \ + } \ + YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ + } + +#define yy_set_bol(at_bol) \ + { \ + if ( ! YY_CURRENT_BUFFER ){\ + hlsl_ensure_buffer_stack (); \ + YY_CURRENT_BUFFER_LVALUE = \ + hlsl__create_buffer(hlsl_in,YY_BUF_SIZE ); \ + } \ + YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ + } + +#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol) + +/* Begin user sect3 */ + +#define hlsl_wrap(n) 1 +#define YY_SKIP_YYWRAP + +typedef unsigned char YY_CHAR; + +FILE *hlsl_in = (FILE *) 0, *hlsl_out = (FILE *) 0; + +typedef int yy_state_type; + +extern int hlsl_lineno; + +int hlsl_lineno = 1; + +extern char *hlsl_text; +#define yytext_ptr hlsl_text + +static yy_state_type yy_get_previous_state (void ); +static yy_state_type yy_try_NUL_trans (yy_state_type current_state ); +static int yy_get_next_buffer (void ); +static void yy_fatal_error (yyconst char msg[] ); + +/* Done after the current pattern has been matched and before the + * corresponding action - sets up hlsl_text. + */ +#define YY_DO_BEFORE_ACTION \ + (yytext_ptr) = yy_bp; \ + hlsl_leng = (size_t) (yy_cp - yy_bp); \ + (yy_hold_char) = *yy_cp; \ + *yy_cp = '\0'; \ + (yy_c_buf_p) = yy_cp; + +#define YY_NUM_RULES 125 +#define YY_END_OF_BUFFER 126 +/* This struct is not used in this scanner, + but its presence is necessary. */ +struct yy_trans_info + { + flex_int32_t yy_verify; + flex_int32_t yy_nxt; + }; +static yyconst flex_int16_t yy_accept[717] = + { 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 126, 124, 108, 109, 124, 124, 124, 124, 124, 124, + 124, 124, 124, 124, 106, 106, 124, 124, 124, 124, + 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, + 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, + 100, 100, 100, 100, 100, 100, 100, 100, 124, 110, + 93, 123, 122, 123, 116, 123, 125, 118, 119, 125, + 125, 115, 114, 115, 115, 121, 120, 121, 108, 109, + 85, 94, 95, 90, 75, 91, 88, 73, 86, 74, + 87, 97, 0, 101, 107, 89, 102, 105, 106, 0, + + 103, 0, 96, 78, 83, 77, 84, 80, 100, 100, + 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, + 100, 100, 100, 100, 100, 100, 100, 100, 15, 100, + 100, 100, 100, 100, 100, 100, 100, 100, 23, 24, + 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, + 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, + 100, 100, 100, 100, 100, 100, 100, 100, 100, 92, + 76, 122, 116, 0, 118, 119, 0, 117, 114, 0, + 120, 82, 0, 101, 107, 0, 102, 0, 0, 104, + 79, 81, 100, 100, 100, 100, 100, 100, 100, 100, + + 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, + 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, + 100, 100, 20, 100, 100, 100, 100, 100, 100, 100, + 100, 100, 2, 100, 100, 30, 100, 100, 100, 100, + 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, + 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, + 3, 100, 100, 100, 100, 100, 100, 100, 100, 100, + 0, 0, 0, 101, 0, 102, 100, 100, 100, 100, + 100, 100, 100, 100, 100, 100, 1, 100, 100, 100, + 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, + + 17, 100, 100, 100, 100, 100, 100, 100, 100, 100, + 100, 100, 100, 31, 100, 100, 100, 100, 100, 100, + 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, + 100, 100, 100, 100, 100, 100, 65, 100, 100, 100, + 100, 100, 100, 100, 70, 100, 100, 0, 0, 100, + 100, 100, 100, 100, 100, 100, 100, 100, 100, 6, + 100, 100, 100, 10, 100, 100, 100, 100, 100, 100, + 100, 100, 19, 100, 100, 100, 26, 100, 100, 100, + 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, + 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, + + 100, 100, 100, 100, 100, 100, 4, 100, 100, 100, + 100, 72, 0, 0, 100, 7, 100, 100, 100, 100, + 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, + 100, 16, 100, 100, 18, 100, 25, 27, 100, 100, + 100, 100, 100, 100, 100, 100, 100, 36, 100, 100, + 45, 100, 48, 49, 50, 51, 100, 100, 100, 100, + 100, 100, 100, 100, 68, 100, 100, 0, 0, 100, + 100, 100, 100, 100, 100, 100, 100, 100, 8, 100, + 9, 100, 100, 14, 100, 100, 100, 100, 100, 100, + 33, 100, 100, 100, 100, 38, 100, 100, 52, 100, + + 100, 55, 66, 100, 67, 100, 100, 111, 0, 100, + 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, + 100, 100, 11, 100, 100, 100, 100, 100, 37, 100, + 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, + 100, 100, 100, 71, 0, 100, 100, 100, 100, 100, + 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, + 28, 100, 100, 99, 39, 40, 41, 100, 100, 100, + 100, 53, 56, 58, 62, 100, 0, 5, 100, 100, + 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, + 100, 100, 100, 100, 100, 100, 46, 100, 100, 100, + + 0, 100, 100, 32, 100, 100, 100, 100, 100, 60, + 100, 100, 100, 100, 22, 100, 100, 42, 100, 100, + 54, 64, 0, 100, 100, 100, 100, 100, 100, 100, + 100, 100, 69, 98, 100, 100, 100, 100, 0, 0, + 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, + 100, 100, 43, 100, 0, 0, 0, 100, 100, 21, + 100, 100, 100, 57, 59, 100, 63, 100, 100, 100, + 0, 0, 100, 100, 34, 100, 100, 100, 29, 100, + 100, 0, 0, 100, 13, 35, 100, 61, 47, 0, + 0, 12, 100, 0, 0, 100, 0, 0, 100, 0, + + 0, 100, 0, 0, 100, 0, 0, 44, 0, 0, + 112, 0, 0, 0, 113, 0 + } ; + +static yyconst flex_int32_t yy_ec[256] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, + 1, 1, 4, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 2, 5, 6, 7, 1, 8, 9, 1, 10, + 11, 12, 13, 1, 14, 15, 16, 17, 18, 19, + 20, 21, 21, 21, 21, 22, 22, 23, 1, 24, + 25, 26, 1, 27, 28, 29, 30, 31, 32, 33, + 34, 35, 36, 36, 36, 36, 37, 36, 36, 38, + 36, 39, 40, 41, 42, 43, 36, 36, 36, 36, + 1, 1, 1, 1, 44, 1, 45, 46, 47, 48, + + 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, + 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, + 69, 70, 1, 71, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1 + } ; + +static yyconst flex_int32_t yy_meta[72] = + { 0, + 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, + 3, 3, 1, 1, 1, 1, 1, 3, 3, 3, + 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 1 + } ; + +static yyconst flex_int16_t yy_base[725] = + { 0, + 0, 65, 74, 80, 83, 101, 70, 72, 76, 78, + 938, 939, 935, 939, 933, 910, 81, 909, 97, 908, + 96, 98, 96, 94, 126, 118, 909, 101, 906, 102, + 0, 64, 881, 880, 875, 104, 882, 877, 876, 859, + 861, 110, 101, 109, 112, 120, 114, 863, 86, 136, + 103, 128, 93, 135, 152, 126, 147, 869, 158, 184, + 895, 939, 939, 916, 198, 856, 939, 915, 939, 913, + 909, 939, 939, 911, 868, 939, 939, 909, 909, 939, + 939, 939, 939, 939, 939, 939, 939, 939, 939, 939, + 939, 939, 895, 213, 0, 939, 268, 841, 0, 236, + + 939, 0, 939, 883, 939, 939, 939, 882, 0, 857, + 855, 844, 844, 834, 838, 842, 842, 830, 835, 832, + 846, 144, 829, 848, 847, 166, 153, 828, 825, 831, + 825, 822, 176, 830, 823, 831, 819, 823, 0, 154, + 823, 816, 815, 821, 810, 823, 826, 810, 810, 188, + 826, 174, 804, 813, 167, 191, 198, 816, 803, 212, + 211, 201, 807, 214, 813, 818, 802, 215, 810, 939, + 939, 939, 274, 817, 859, 939, 854, 939, 939, 812, + 939, 939, 291, 939, 0, 308, 939, 314, 323, 0, + 939, 939, 800, 807, 792, 798, 805, 789, 804, 791, + + 786, 785, 789, 802, 797, 798, 794, 781, 779, 776, + 780, 188, 794, 789, 790, 790, 790, 785, 776, 776, + 782, 767, 0, 780, 769, 762, 773, 760, 773, 761, + 777, 772, 0, 762, 757, 0, 755, 770, 750, 751, + 758, 760, 754, 746, 766, 749, 746, 745, 748, 756, + 740, 249, 739, 752, 749, 740, 735, 735, 738, 747, + 0, 746, 222, 741, 735, 728, 727, 742, 744, 732, + 736, 731, 329, 378, 342, 433, 737, 735, 731, 733, + 725, 731, 730, 722, 712, 727, 0, 720, 722, 723, + 709, 714, 717, 705, 715, 702, 702, 720, 708, 706, + + 0, 709, 699, 711, 701, 698, 699, 692, 702, 708, + 690, 688, 706, 0, 697, 704, 699, 694, 683, 681, + 682, 686, 686, 692, 676, 690, 679, 225, 679, 689, + 688, 684, 675, 676, 666, 663, 0, 249, 670, 670, + 676, 675, 666, 659, 0, 659, 673, 664, 676, 679, + 656, 677, 652, 675, 652, 651, 663, 649, 642, 0, + 660, 650, 651, 662, 647, 648, 654, 640, 652, 647, + 652, 640, 0, 649, 633, 646, 0, 626, 637, 632, + 642, 626, 626, 624, 640, 639, 621, 635, 625, 637, + 632, 632, 631, 628, 631, 629, 624, 610, 621, 623, + + 618, 625, 607, 619, 622, 604, 0, 607, 602, 618, + 609, 0, 616, 603, 595, 0, 594, 595, 604, 602, + 613, 591, 603, 611, 588, 605, 599, 600, 581, 581, + 596, 0, 596, 589, 0, 589, 0, 0, 591, 594, + 576, 578, 587, 586, 570, 584, 570, 0, 577, 568, + 0, 573, 584, 0, 0, 0, 565, 565, 561, 575, + 573, 565, 564, 571, 0, 563, 562, 615, 571, 570, + 565, 544, 567, 541, 565, 579, 334, 556, 0, 550, + 0, 561, 556, 0, 560, 539, 557, 554, 540, 537, + 0, 549, 535, 536, 536, 347, 535, 546, 0, 527, + + 542, 350, 0, 541, 0, 541, 539, 585, 522, 521, + 526, 543, 534, 532, 518, 520, 547, 546, 545, 530, + 529, 510, 0, 525, 509, 521, 510, 520, 0, 505, + 504, 534, 533, 532, 520, 498, 513, 514, 509, 526, + 525, 524, 512, 0, 491, 503, 504, 498, 500, 486, + 496, 489, 517, 278, 516, 495, 488, 477, 495, 490, + 0, 482, 488, 0, 0, 0, 0, 507, 471, 479, + 470, 514, 0, 0, 0, 502, 475, 0, 450, 457, + 439, 460, 450, 438, 435, 434, 455, 432, 444, 433, + 428, 442, 444, 424, 455, 441, 440, 418, 464, 448, + + 411, 422, 429, 0, 412, 411, 429, 411, 410, 443, + 408, 407, 405, 401, 0, 400, 419, 0, 398, 398, + 0, 0, 273, 236, 411, 414, 415, 395, 411, 403, + 385, 401, 0, 0, 392, 397, 394, 378, 314, 355, + 377, 387, 377, 374, 384, 383, 366, 365, 371, 363, + 370, 382, 0, 381, 369, 366, 365, 378, 373, 0, + 372, 371, 356, 0, 0, 373, 0, 357, 351, 348, + 354, 342, 344, 340, 0, 339, 346, 335, 0, 339, + 352, 328, 346, 340, 0, 0, 329, 0, 0, 329, + 327, 0, 93, 134, 160, 164, 195, 190, 237, 241, + + 240, 255, 278, 275, 289, 301, 370, 0, 315, 374, + 939, 316, 377, 381, 939, 939, 504, 508, 512, 516, + 518, 522, 526, 379 + } ; + +static yyconst flex_int16_t yy_def[725] = + { 0, + 716, 1, 717, 717, 718, 718, 719, 719, 720, 720, + 716, 716, 716, 716, 716, 716, 716, 716, 716, 716, + 716, 716, 716, 716, 716, 25, 716, 716, 716, 716, + 721, 721, 721, 721, 721, 721, 721, 721, 721, 721, + 721, 721, 721, 721, 721, 721, 721, 721, 721, 721, + 721, 721, 721, 721, 721, 721, 721, 721, 716, 716, + 716, 716, 716, 716, 716, 716, 716, 716, 716, 716, + 722, 716, 716, 716, 716, 716, 716, 716, 716, 716, + 716, 716, 716, 716, 716, 716, 716, 716, 716, 716, + 716, 716, 716, 716, 723, 716, 716, 25, 26, 716, + + 716, 724, 716, 716, 716, 716, 716, 716, 721, 721, + 721, 721, 721, 721, 721, 721, 721, 721, 721, 721, + 721, 721, 721, 721, 721, 721, 721, 721, 721, 721, + 721, 721, 721, 721, 721, 721, 721, 721, 721, 721, + 721, 721, 721, 721, 721, 721, 721, 721, 721, 721, + 721, 721, 721, 721, 721, 721, 721, 721, 721, 721, + 721, 721, 721, 721, 721, 721, 721, 721, 721, 716, + 716, 716, 716, 716, 716, 716, 722, 716, 716, 716, + 716, 716, 716, 716, 723, 716, 716, 716, 716, 724, + 716, 716, 721, 721, 721, 721, 721, 721, 721, 721, + + 721, 721, 721, 721, 721, 721, 721, 721, 721, 721, + 721, 721, 721, 721, 721, 721, 721, 721, 721, 721, + 721, 721, 721, 721, 721, 721, 721, 721, 721, 721, + 721, 721, 721, 721, 721, 721, 721, 721, 721, 721, + 721, 721, 721, 721, 721, 721, 721, 721, 721, 721, + 721, 721, 721, 721, 721, 721, 721, 721, 721, 721, + 721, 721, 721, 721, 721, 721, 721, 721, 721, 721, + 716, 716, 716, 716, 716, 716, 721, 721, 721, 721, + 721, 721, 721, 721, 721, 721, 721, 721, 721, 721, + 721, 721, 721, 721, 721, 721, 721, 721, 721, 721, + + 721, 721, 721, 721, 721, 721, 721, 721, 721, 721, + 721, 721, 721, 721, 721, 721, 721, 721, 721, 721, + 721, 721, 721, 721, 721, 721, 721, 721, 721, 721, + 721, 721, 721, 721, 721, 721, 721, 721, 721, 721, + 721, 721, 721, 721, 721, 721, 721, 716, 716, 721, + 721, 721, 721, 721, 721, 721, 721, 721, 721, 721, + 721, 721, 721, 721, 721, 721, 721, 721, 721, 721, + 721, 721, 721, 721, 721, 721, 721, 721, 721, 721, + 721, 721, 721, 721, 721, 721, 721, 721, 721, 721, + 721, 721, 721, 721, 721, 721, 721, 721, 721, 721, + + 721, 721, 721, 721, 721, 721, 721, 721, 721, 721, + 721, 721, 716, 716, 721, 721, 721, 721, 721, 721, + 721, 721, 721, 721, 721, 721, 721, 721, 721, 721, + 721, 721, 721, 721, 721, 721, 721, 721, 721, 721, + 721, 721, 721, 721, 721, 721, 721, 721, 721, 721, + 721, 721, 721, 721, 721, 721, 721, 721, 721, 721, + 721, 721, 721, 721, 721, 721, 721, 716, 716, 721, + 721, 721, 721, 721, 721, 721, 721, 721, 721, 721, + 721, 721, 721, 721, 721, 721, 721, 721, 721, 721, + 721, 721, 721, 721, 721, 721, 721, 721, 721, 721, + + 721, 721, 721, 721, 721, 721, 721, 716, 716, 721, + 721, 721, 721, 721, 721, 721, 721, 721, 721, 721, + 721, 721, 721, 721, 721, 721, 721, 721, 721, 721, + 721, 721, 721, 721, 721, 721, 721, 721, 721, 721, + 721, 721, 721, 721, 716, 721, 721, 721, 721, 721, + 721, 721, 721, 721, 721, 721, 721, 721, 721, 721, + 721, 721, 721, 721, 721, 721, 721, 721, 721, 721, + 721, 721, 721, 721, 721, 721, 716, 721, 721, 721, + 721, 721, 721, 721, 721, 721, 721, 721, 721, 721, + 721, 721, 721, 721, 721, 721, 721, 721, 721, 721, + + 716, 721, 721, 721, 721, 721, 721, 721, 721, 721, + 721, 721, 721, 721, 721, 721, 721, 721, 721, 721, + 721, 721, 716, 721, 721, 721, 721, 721, 721, 721, + 721, 721, 721, 721, 721, 721, 721, 721, 716, 716, + 721, 721, 721, 721, 721, 721, 721, 721, 721, 721, + 721, 721, 721, 721, 716, 716, 716, 721, 721, 721, + 721, 721, 721, 721, 721, 721, 721, 721, 721, 721, + 716, 716, 721, 721, 721, 721, 721, 721, 721, 721, + 721, 716, 716, 721, 721, 721, 721, 721, 721, 716, + 716, 721, 721, 716, 716, 721, 716, 716, 721, 716, + + 716, 721, 716, 716, 721, 716, 716, 721, 716, 716, + 716, 716, 716, 716, 716, 0, 716, 716, 716, 716, + 716, 716, 716, 716 + } ; + +static yyconst flex_int16_t yy_nxt[1011] = + { 0, + 12, 13, 14, 15, 16, 12, 17, 18, 19, 12, + 12, 20, 21, 22, 23, 24, 25, 26, 26, 26, + 26, 26, 27, 28, 29, 30, 12, 31, 32, 31, + 33, 31, 31, 34, 31, 31, 31, 35, 36, 37, + 38, 31, 39, 31, 40, 41, 42, 43, 44, 45, + 46, 31, 47, 31, 31, 48, 49, 50, 51, 52, + 31, 53, 54, 55, 56, 57, 58, 31, 31, 31, + 59, 60, 73, 74, 73, 74, 63, 64, 77, 78, + 77, 78, 63, 64, 68, 69, 70, 82, 71, 61, + 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, + + 65, 65, 68, 69, 70, 85, 71, 83, 88, 95, + 93, 90, 94, 94, 94, 94, 94, 94, 96, 110, + 89, 86, 91, 92, 104, 105, 107, 108, 111, 75, + 142, 75, 696, 66, 99, 99, 99, 99, 99, 66, + 97, 152, 98, 98, 98, 98, 98, 99, 115, 127, + 143, 153, 116, 128, 122, 123, 134, 100, 101, 129, + 101, 124, 147, 139, 131, 125, 132, 148, 126, 130, + 135, 140, 149, 136, 100, 101, 133, 101, 137, 154, + 144, 138, 170, 164, 145, 716, 155, 156, 165, 150, + 82, 697, 151, 102, 146, 166, 101, 159, 157, 167, + + 160, 158, 213, 161, 698, 168, 205, 206, 214, 227, + 83, 247, 228, 162, 173, 173, 173, 173, 173, 173, + 163, 210, 211, 212, 242, 248, 243, 699, 171, 94, + 94, 94, 94, 94, 94, 220, 238, 244, 700, 221, + 239, 249, 251, 701, 183, 184, 240, 184, 188, 188, + 294, 295, 189, 189, 189, 189, 189, 189, 255, 252, + 250, 183, 184, 258, 184, 260, 263, 268, 256, 261, + 269, 339, 259, 395, 639, 641, 264, 396, 642, 257, + 340, 702, 640, 184, 94, 94, 94, 94, 94, 94, + 173, 173, 173, 173, 173, 173, 404, 703, 704, 186, + + 187, 329, 187, 273, 273, 586, 405, 274, 274, 274, + 274, 274, 274, 330, 587, 639, 186, 187, 705, 187, + 275, 275, 706, 640, 276, 276, 276, 276, 276, 276, + 189, 189, 189, 189, 189, 189, 707, 708, 187, 189, + 189, 189, 189, 189, 189, 274, 274, 274, 274, 274, + 274, 517, 518, 519, 709, 101, 655, 101, 276, 276, + 276, 276, 276, 276, 532, 533, 534, 540, 541, 542, + 655, 710, 101, 712, 101, 710, 535, 713, 714, 543, + 711, 190, 714, 695, 711, 694, 693, 715, 692, 691, + 536, 715, 690, 101, 274, 274, 274, 274, 274, 274, + + 689, 656, 261, 688, 687, 686, 685, 684, 683, 682, + 184, 681, 184, 680, 679, 656, 657, 678, 677, 676, + 675, 674, 673, 672, 671, 670, 669, 184, 668, 184, + 657, 667, 666, 665, 664, 663, 662, 661, 660, 659, + 658, 654, 653, 652, 651, 650, 649, 648, 184, 276, + 276, 276, 276, 276, 276, 647, 646, 645, 644, 643, + 638, 637, 636, 635, 287, 187, 634, 187, 633, 632, + 631, 630, 629, 628, 627, 626, 625, 624, 623, 622, + 621, 261, 187, 620, 187, 619, 618, 617, 616, 615, + 614, 613, 612, 611, 610, 609, 608, 607, 606, 605, + + 604, 603, 602, 187, 62, 62, 62, 62, 67, 67, + 67, 67, 72, 72, 72, 72, 76, 76, 76, 76, + 109, 109, 177, 177, 177, 177, 185, 601, 185, 185, + 600, 599, 598, 597, 596, 595, 594, 593, 592, 591, + 287, 590, 589, 588, 585, 584, 583, 582, 581, 580, + 579, 578, 577, 576, 575, 574, 573, 572, 571, 570, + 569, 568, 567, 566, 565, 564, 563, 233, 562, 561, + 560, 559, 558, 557, 556, 555, 554, 553, 552, 551, + 550, 549, 548, 547, 546, 545, 508, 544, 407, 407, + 261, 539, 538, 537, 531, 530, 529, 528, 233, 527, + + 526, 525, 233, 524, 523, 522, 521, 520, 516, 515, + 514, 513, 512, 511, 510, 509, 508, 507, 407, 506, + 505, 504, 503, 502, 501, 500, 499, 498, 497, 496, + 495, 494, 493, 492, 233, 491, 490, 489, 488, 233, + 487, 486, 485, 484, 287, 483, 482, 481, 480, 479, + 478, 477, 476, 475, 474, 473, 472, 471, 470, 469, + 468, 467, 466, 465, 464, 463, 462, 461, 460, 459, + 458, 457, 456, 455, 454, 453, 452, 261, 261, 451, + 450, 449, 448, 447, 446, 233, 445, 444, 443, 442, + 441, 440, 439, 438, 437, 436, 233, 435, 434, 433, + + 432, 431, 287, 430, 429, 428, 427, 426, 425, 424, + 423, 422, 421, 420, 419, 418, 417, 416, 415, 414, + 413, 412, 411, 410, 409, 407, 408, 407, 406, 261, + 403, 402, 401, 400, 399, 398, 397, 394, 393, 261, + 392, 391, 390, 389, 388, 387, 386, 385, 384, 383, + 382, 381, 380, 379, 378, 377, 376, 375, 374, 373, + 372, 371, 370, 369, 368, 367, 366, 365, 364, 363, + 362, 287, 361, 287, 360, 359, 358, 357, 356, 355, + 354, 353, 352, 351, 350, 349, 348, 347, 346, 345, + 344, 343, 342, 341, 338, 337, 336, 261, 335, 334, + + 333, 332, 331, 328, 327, 326, 325, 324, 323, 322, + 321, 320, 319, 318, 317, 316, 315, 314, 313, 312, + 311, 310, 309, 233, 308, 307, 306, 233, 305, 304, + 303, 302, 287, 301, 300, 299, 298, 297, 296, 293, + 292, 291, 287, 290, 289, 287, 288, 287, 286, 285, + 284, 283, 282, 281, 280, 279, 278, 277, 272, 178, + 175, 271, 270, 267, 266, 265, 262, 254, 253, 246, + 245, 241, 237, 236, 235, 234, 233, 232, 231, 230, + 229, 226, 225, 224, 223, 222, 219, 218, 217, 216, + 215, 209, 208, 207, 204, 203, 202, 201, 200, 199, + + 198, 197, 196, 195, 194, 193, 192, 191, 716, 182, + 79, 181, 180, 179, 178, 176, 175, 174, 172, 106, + 169, 141, 121, 120, 119, 118, 117, 114, 113, 112, + 106, 103, 87, 84, 81, 80, 79, 716, 11, 716, + 716, 716, 716, 716, 716, 716, 716, 716, 716, 716, + 716, 716, 716, 716, 716, 716, 716, 716, 716, 716, + 716, 716, 716, 716, 716, 716, 716, 716, 716, 716, + 716, 716, 716, 716, 716, 716, 716, 716, 716, 716, + 716, 716, 716, 716, 716, 716, 716, 716, 716, 716, + 716, 716, 716, 716, 716, 716, 716, 716, 716, 716, + + 716, 716, 716, 716, 716, 716, 716, 716, 716, 716 + } ; + +static yyconst flex_int16_t yy_chk[1011] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 2, 7, 7, 8, 8, 3, 3, 9, 9, + 10, 10, 4, 4, 5, 5, 5, 17, 5, 2, + 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, + + 4, 4, 6, 6, 6, 19, 6, 17, 21, 24, + 23, 22, 23, 23, 23, 23, 23, 23, 24, 32, + 21, 19, 22, 22, 28, 28, 30, 30, 32, 7, + 49, 8, 693, 3, 26, 26, 26, 26, 26, 4, + 25, 53, 25, 25, 25, 25, 25, 25, 36, 43, + 49, 53, 36, 43, 42, 42, 45, 25, 25, 43, + 25, 42, 51, 47, 44, 42, 44, 51, 42, 43, + 45, 47, 52, 45, 25, 25, 44, 25, 46, 54, + 50, 46, 59, 56, 50, 26, 54, 54, 56, 52, + 60, 694, 52, 25, 50, 57, 25, 55, 54, 57, + + 55, 54, 127, 55, 695, 57, 122, 122, 127, 140, + 60, 155, 140, 55, 65, 65, 65, 65, 65, 65, + 55, 126, 126, 126, 152, 155, 152, 696, 59, 94, + 94, 94, 94, 94, 94, 133, 150, 152, 697, 133, + 150, 156, 157, 698, 94, 94, 150, 94, 100, 100, + 212, 212, 100, 100, 100, 100, 100, 100, 160, 157, + 156, 94, 94, 161, 94, 162, 164, 168, 160, 162, + 168, 263, 161, 328, 623, 624, 164, 328, 624, 160, + 263, 699, 623, 94, 97, 97, 97, 97, 97, 97, + 173, 173, 173, 173, 173, 173, 338, 700, 701, 97, + + 97, 252, 97, 183, 183, 554, 338, 183, 183, 183, + 183, 183, 183, 252, 554, 639, 97, 97, 702, 97, + 186, 186, 703, 639, 186, 186, 186, 186, 186, 186, + 188, 188, 188, 188, 188, 188, 704, 705, 97, 189, + 189, 189, 189, 189, 189, 273, 273, 273, 273, 273, + 273, 477, 477, 477, 706, 189, 640, 189, 275, 275, + 275, 275, 275, 275, 496, 496, 496, 502, 502, 502, + 655, 707, 189, 709, 189, 710, 496, 712, 713, 502, + 707, 724, 714, 691, 710, 690, 687, 713, 684, 683, + 496, 714, 682, 189, 274, 274, 274, 274, 274, 274, + + 681, 640, 680, 678, 677, 676, 674, 673, 672, 671, + 274, 670, 274, 669, 668, 655, 640, 666, 663, 662, + 661, 659, 658, 657, 656, 654, 652, 274, 651, 274, + 655, 650, 649, 648, 647, 646, 645, 644, 643, 642, + 641, 638, 637, 636, 635, 632, 631, 630, 274, 276, + 276, 276, 276, 276, 276, 629, 628, 627, 626, 625, + 620, 619, 617, 616, 614, 276, 613, 276, 612, 611, + 610, 609, 608, 607, 606, 605, 603, 602, 601, 600, + 599, 598, 276, 597, 276, 596, 595, 594, 593, 592, + 591, 590, 589, 588, 587, 586, 585, 584, 583, 582, + + 581, 580, 579, 276, 717, 717, 717, 717, 718, 718, + 718, 718, 719, 719, 719, 719, 720, 720, 720, 720, + 721, 721, 722, 722, 722, 722, 723, 577, 723, 723, + 576, 572, 571, 570, 569, 568, 563, 562, 560, 559, + 558, 557, 556, 555, 553, 552, 551, 550, 549, 548, + 547, 546, 545, 543, 542, 541, 540, 539, 538, 537, + 536, 535, 534, 533, 532, 531, 530, 528, 527, 526, + 525, 524, 522, 521, 520, 519, 518, 517, 516, 515, + 514, 513, 512, 511, 510, 509, 508, 507, 506, 504, + 501, 500, 498, 497, 495, 494, 493, 492, 490, 489, + + 488, 487, 486, 485, 483, 482, 480, 478, 476, 475, + 474, 473, 472, 471, 470, 469, 468, 467, 466, 464, + 463, 462, 461, 460, 459, 458, 457, 453, 452, 450, + 449, 447, 446, 445, 444, 443, 442, 441, 440, 439, + 436, 434, 433, 431, 430, 429, 428, 427, 426, 425, + 424, 423, 422, 421, 420, 419, 418, 417, 415, 414, + 413, 411, 410, 409, 408, 406, 405, 404, 403, 402, + 401, 400, 399, 398, 397, 396, 395, 394, 393, 392, + 391, 390, 389, 388, 387, 386, 385, 384, 383, 382, + 381, 380, 379, 378, 376, 375, 374, 372, 371, 370, + + 369, 368, 367, 366, 365, 364, 363, 362, 361, 359, + 358, 357, 356, 355, 354, 353, 352, 351, 350, 349, + 348, 347, 346, 344, 343, 342, 341, 340, 339, 336, + 335, 334, 333, 332, 331, 330, 329, 327, 326, 325, + 324, 323, 322, 321, 320, 319, 318, 317, 316, 315, + 313, 312, 311, 310, 309, 308, 307, 306, 305, 304, + 303, 302, 300, 299, 298, 297, 296, 295, 294, 293, + 292, 291, 290, 289, 288, 286, 285, 284, 283, 282, + 281, 280, 279, 278, 277, 272, 271, 270, 269, 268, + 267, 266, 265, 264, 262, 260, 259, 258, 257, 256, + + 255, 254, 253, 251, 250, 249, 248, 247, 246, 245, + 244, 243, 242, 241, 240, 239, 238, 237, 235, 234, + 232, 231, 230, 229, 228, 227, 226, 225, 224, 222, + 221, 220, 219, 218, 217, 216, 215, 214, 213, 211, + 210, 209, 208, 207, 206, 205, 204, 203, 202, 201, + 200, 199, 198, 197, 196, 195, 194, 193, 180, 177, + 175, 174, 169, 167, 166, 165, 163, 159, 158, 154, + 153, 151, 149, 148, 147, 146, 145, 144, 143, 142, + 141, 138, 137, 136, 135, 134, 132, 131, 130, 129, + 128, 125, 124, 123, 121, 120, 119, 118, 117, 116, + + 115, 114, 113, 112, 111, 110, 108, 104, 98, 93, + 79, 78, 75, 74, 71, 70, 68, 66, 64, 61, + 58, 48, 41, 40, 39, 38, 37, 35, 34, 33, + 29, 27, 20, 18, 16, 15, 13, 11, 716, 716, + 716, 716, 716, 716, 716, 716, 716, 716, 716, 716, + 716, 716, 716, 716, 716, 716, 716, 716, 716, 716, + 716, 716, 716, 716, 716, 716, 716, 716, 716, 716, + 716, 716, 716, 716, 716, 716, 716, 716, 716, 716, + 716, 716, 716, 716, 716, 716, 716, 716, 716, 716, + 716, 716, 716, 716, 716, 716, 716, 716, 716, 716, + + 716, 716, 716, 716, 716, 716, 716, 716, 716, 716 + } ; + +static yy_state_type yy_last_accepting_state; +static char *yy_last_accepting_cpos; + +extern int hlsl__flex_debug; +int hlsl__flex_debug = 0; + +/* The intent behind this definition is that it'll catch + * any uses of REJECT which flex missed. + */ +#define REJECT reject_used_but_not_detected +#define yymore() yymore_used_but_not_detected +#define YY_MORE_ADJ 0 +#define YY_RESTORE_YY_MORE_OFFSET +char *hlsl_text; +#line 1 "hlsl.l" +/* + * 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 + */ +#line 23 "hlsl.l" +#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); + +#define YY_USER_ACTION \ + do { \ + hlsl_lloc.first_column = hlsl_ctx.column; \ + hlsl_lloc.first_line = hlsl_ctx.line_no; \ + hlsl_ctx.column += hlsl_leng; \ + } while(0); + +#define YY_NO_INPUT 1 + +#line 984 "hlsl.yy.c" + +#define INITIAL 0 +#define pp 1 +#define pp_line 2 +#define pp_pragma 3 +#define pp_ignore 4 + +#ifndef YY_NO_UNISTD_H +/* Special case for "unistd.h", since it is non-ANSI. We include it way + * down here because we want the user's section 1 to have been scanned first. + * The user has a chance to override it with an option. + */ +#include +#endif + +#ifndef YY_EXTRA_TYPE +#define YY_EXTRA_TYPE void * +#endif + +static int yy_init_globals (void ); + +/* Accessor methods to globals. + These are made visible to non-reentrant scanners for convenience. */ + +int hlsl_lex_destroy (void ); + +int hlsl_get_debug (void ); + +void hlsl_set_debug (int debug_flag ); + +YY_EXTRA_TYPE hlsl_get_extra (void ); + +void hlsl_set_extra (YY_EXTRA_TYPE user_defined ); + +FILE *hlsl_get_in (void ); + +void hlsl_set_in (FILE * in_str ); + +FILE *hlsl_get_out (void ); + +void hlsl_set_out (FILE * out_str ); + +int hlsl_get_leng (void ); + +char *hlsl_get_text (void ); + +int hlsl_get_lineno (void ); + +void hlsl_set_lineno (int line_number ); + +/* Macros after this point can all be overridden by user definitions in + * section 1. + */ + +#ifndef YY_SKIP_YYWRAP +#ifdef __cplusplus +extern "C" int hlsl_wrap (void ); +#else +extern int hlsl_wrap (void ); +#endif +#endif + +#ifndef yytext_ptr +static void yy_flex_strncpy (char *,yyconst char *,int ); +#endif + +#ifdef YY_NEED_STRLEN +static int yy_flex_strlen (yyconst char * ); +#endif + +#ifndef YY_NO_INPUT + +#ifdef __cplusplus +static int yyinput (void ); +#else +static int input (void ); +#endif + +#endif + +/* Amount of stuff to slurp up with each read. */ +#ifndef YY_READ_BUF_SIZE +#ifdef __ia64__ +/* On IA-64, the buffer size is 16k, not 8k */ +#define YY_READ_BUF_SIZE 16384 +#else +#define YY_READ_BUF_SIZE 8192 +#endif /* __ia64__ */ +#endif + +/* Copy whatever the last rule matched to the standard output. */ +#ifndef ECHO +/* This used to be an fputs(), but since the string might contain NUL's, + * we now use fwrite(). + */ +#define ECHO do { if (fwrite( hlsl_text, hlsl_leng, 1, hlsl_out )) {} } while (0) +#endif + +/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, + * is returned in "result". + */ +#ifndef YY_INPUT +#define YY_INPUT(buf,result,max_size) \ + if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ + { \ + int c = '*'; \ + size_t n; \ + for ( n = 0; n < max_size && \ + (c = getc( hlsl_in )) != EOF && c != '\n'; ++n ) \ + buf[n] = (char) c; \ + if ( c == '\n' ) \ + buf[n++] = (char) c; \ + if ( c == EOF && ferror( hlsl_in ) ) \ + YY_FATAL_ERROR( "input in flex scanner failed" ); \ + result = n; \ + } \ + else \ + { \ + errno=0; \ + while ( (result = fread(buf, 1, max_size, hlsl_in))==0 && ferror(hlsl_in)) \ + { \ + if( errno != EINTR) \ + { \ + YY_FATAL_ERROR( "input in flex scanner failed" ); \ + break; \ + } \ + errno=0; \ + clearerr(hlsl_in); \ + } \ + }\ +\ + +#endif + +/* No semi-colon after return; correct usage is to write "yyterminate();" - + * we don't want an extra ';' after the "return" because that will cause + * some compilers to complain about unreachable statements. + */ +#ifndef yyterminate +#define yyterminate() return YY_NULL +#endif + +/* Number of entries by which start-condition stack grows. */ +#ifndef YY_START_STACK_INCR +#define YY_START_STACK_INCR 25 +#endif + +/* Report a fatal error. */ +#ifndef YY_FATAL_ERROR +#define YY_FATAL_ERROR(msg) yy_fatal_error( msg ) +#endif + +/* end tables serialization structures and prototypes */ + +/* Default declaration of generated scanner - a define so the user can + * easily add parameters. + */ +#ifndef YY_DECL +#define YY_DECL_IS_OURS 1 + +extern int hlsl_lex (void); + +#define YY_DECL int hlsl_lex (void) +#endif /* !YY_DECL */ + +/* Code executed at the beginning of each rule, after hlsl_text and hlsl_leng + * have been set up. + */ +#ifndef YY_USER_ACTION +#define YY_USER_ACTION +#endif + +/* Code executed at the end of each rule. */ +#ifndef YY_BREAK +#define YY_BREAK break; +#endif + +#define YY_RULE_SETUP \ + if ( hlsl_leng > 0 ) \ + YY_CURRENT_BUFFER_LVALUE->yy_at_bol = \ + (hlsl_text[hlsl_leng - 1] == '\n'); \ + YY_USER_ACTION + +/** The main scanner function which does all the work. + */ +YY_DECL +{ + register yy_state_type yy_current_state; + register char *yy_cp, *yy_bp; + register int yy_act; + +#line 60 "hlsl.l" + +#line 1178 "hlsl.yy.c" + + if ( !(yy_init) ) + { + (yy_init) = 1; + +#ifdef YY_USER_INIT + YY_USER_INIT; +#endif + + if ( ! (yy_start) ) + (yy_start) = 1; /* first start state */ + + if ( ! hlsl_in ) + hlsl_in = stdin; + + if ( ! hlsl_out ) + hlsl_out = stdout; + + if ( ! YY_CURRENT_BUFFER ) { + hlsl_ensure_buffer_stack (); + YY_CURRENT_BUFFER_LVALUE = + hlsl__create_buffer(hlsl_in,YY_BUF_SIZE ); + } + + hlsl__load_buffer_state( ); + } + + while ( 1 ) /* loops until end-of-file is reached */ + { + yy_cp = (yy_c_buf_p); + + /* Support of hlsl_text. */ + *yy_cp = (yy_hold_char); + + /* yy_bp points to the position in yy_ch_buf of the start of + * the current run. + */ + yy_bp = yy_cp; + + yy_current_state = (yy_start); + yy_current_state += YY_AT_BOL(); +yy_match: + do + { + register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)]; + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 717 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + ++yy_cp; + } + while ( yy_current_state != 716 ); + yy_cp = (yy_last_accepting_cpos); + yy_current_state = (yy_last_accepting_state); + +yy_find_action: + yy_act = yy_accept[yy_current_state]; + + YY_DO_BEFORE_ACTION; + +do_action: /* This label is used only to access EOF actions. */ + + switch ( yy_act ) + { /* beginning of action switch */ + case 0: /* must back up */ + /* undo the effects of YY_DO_BEFORE_ACTION */ + *yy_cp = (yy_hold_char); + yy_cp = (yy_last_accepting_cpos); + yy_current_state = (yy_last_accepting_state); + goto yy_find_action; + +case 1: +YY_RULE_SETUP +#line 61 "hlsl.l" +{ + hlsl_message("Line %u: Reserved keyword \"%s\" used.\n", hlsl_ctx.line_no, hlsl_text); + set_parse_status(&hlsl_ctx.status, PARSE_ERR); + } + YY_BREAK +case 2: +YY_RULE_SETUP +#line 65 "hlsl.l" +{ + hlsl_message("Line %u: Reserved keyword \"%s\" used.\n", hlsl_ctx.line_no, hlsl_text); + set_parse_status(&hlsl_ctx.status, PARSE_ERR); + } + YY_BREAK +case 3: +YY_RULE_SETUP +#line 69 "hlsl.l" +{ + hlsl_message("Line %u: Reserved keyword \"%s\" used.\n", hlsl_ctx.line_no, hlsl_text); + set_parse_status(&hlsl_ctx.status, PARSE_ERR); + } + YY_BREAK +case 4: +YY_RULE_SETUP +#line 73 "hlsl.l" +{ + hlsl_message("Line %u: Reserved keyword \"%s\" used.\n", hlsl_ctx.line_no, hlsl_text); + set_parse_status(&hlsl_ctx.status, PARSE_ERR); + } + YY_BREAK +case 5: +YY_RULE_SETUP +#line 78 "hlsl.l" +{return KW_BLENDSTATE; } + YY_BREAK +case 6: +YY_RULE_SETUP +#line 79 "hlsl.l" +{return KW_BREAK; } + YY_BREAK +case 7: +YY_RULE_SETUP +#line 80 "hlsl.l" +{return KW_BUFFER; } + YY_BREAK +case 8: +YY_RULE_SETUP +#line 81 "hlsl.l" +{return KW_CBUFFER; } + YY_BREAK +case 9: +YY_RULE_SETUP +#line 82 "hlsl.l" +{return KW_COMPILE; } + YY_BREAK +case 10: +YY_RULE_SETUP +#line 83 "hlsl.l" +{return KW_CONST; } + YY_BREAK +case 11: +YY_RULE_SETUP +#line 84 "hlsl.l" +{return KW_CONTINUE; } + YY_BREAK +case 12: +YY_RULE_SETUP +#line 85 "hlsl.l" +{return KW_DEPTHSTENCILSTATE; } + YY_BREAK +case 13: +YY_RULE_SETUP +#line 86 "hlsl.l" +{return KW_DEPTHSTENCILVIEW; } + YY_BREAK +case 14: +YY_RULE_SETUP +#line 87 "hlsl.l" +{return KW_DISCARD; } + YY_BREAK +case 15: +YY_RULE_SETUP +#line 88 "hlsl.l" +{return KW_DO; } + YY_BREAK +case 16: +YY_RULE_SETUP +#line 89 "hlsl.l" +{return KW_DOUBLE; } + YY_BREAK +case 17: +YY_RULE_SETUP +#line 90 "hlsl.l" +{return KW_ELSE; } + YY_BREAK +case 18: +YY_RULE_SETUP +#line 91 "hlsl.l" +{return KW_EXTERN; } + YY_BREAK +case 19: +YY_RULE_SETUP +#line 92 "hlsl.l" +{return KW_FALSE; } + YY_BREAK +case 20: +YY_RULE_SETUP +#line 93 "hlsl.l" +{return KW_FOR; } + YY_BREAK +case 21: +YY_RULE_SETUP +#line 94 "hlsl.l" +{return KW_GEOMETRYSHADER; } + YY_BREAK +case 22: +YY_RULE_SETUP +#line 95 "hlsl.l" +{return KW_GROUPSHARED; } + YY_BREAK +case 23: +YY_RULE_SETUP +#line 96 "hlsl.l" +{return KW_IF; } + YY_BREAK +case 24: +YY_RULE_SETUP +#line 97 "hlsl.l" +{return KW_IN; } + YY_BREAK +case 25: +YY_RULE_SETUP +#line 98 "hlsl.l" +{return KW_INLINE; } + YY_BREAK +case 26: +YY_RULE_SETUP +#line 99 "hlsl.l" +{return KW_INOUT; } + YY_BREAK +case 27: +YY_RULE_SETUP +#line 100 "hlsl.l" +{return KW_MATRIX; } + YY_BREAK +case 28: +YY_RULE_SETUP +#line 101 "hlsl.l" +{return KW_NAMESPACE; } + YY_BREAK +case 29: +YY_RULE_SETUP +#line 102 "hlsl.l" +{return KW_NOINTERPOLATION; } + YY_BREAK +case 30: +YY_RULE_SETUP +#line 103 "hlsl.l" +{return KW_OUT; } + YY_BREAK +case 31: +YY_RULE_SETUP +#line 104 "hlsl.l" +{return KW_PASS; } + YY_BREAK +case 32: +YY_RULE_SETUP +#line 105 "hlsl.l" +{return KW_PIXELSHADER; } + YY_BREAK +case 33: +YY_RULE_SETUP +#line 106 "hlsl.l" +{return KW_PRECISE; } + YY_BREAK +case 34: +YY_RULE_SETUP +#line 107 "hlsl.l" +{return KW_RASTERIZERSTATE; } + YY_BREAK +case 35: +YY_RULE_SETUP +#line 108 "hlsl.l" +{return KW_RENDERTARGETVIEW; } + YY_BREAK +case 36: +YY_RULE_SETUP +#line 109 "hlsl.l" +{return KW_RETURN; } + YY_BREAK +case 37: +YY_RULE_SETUP +#line 110 "hlsl.l" +{return KW_REGISTER; } + YY_BREAK +case 38: +YY_RULE_SETUP +#line 111 "hlsl.l" +{return KW_SAMPLER; } + YY_BREAK +case 39: +YY_RULE_SETUP +#line 112 "hlsl.l" +{return KW_SAMPLER1D; } + YY_BREAK +case 40: +YY_RULE_SETUP +#line 113 "hlsl.l" +{return KW_SAMPLER2D; } + YY_BREAK +case 41: +YY_RULE_SETUP +#line 114 "hlsl.l" +{return KW_SAMPLER3D; } + YY_BREAK +case 42: +YY_RULE_SETUP +#line 115 "hlsl.l" +{return KW_SAMPLERCUBE; } + YY_BREAK +case 43: +YY_RULE_SETUP +#line 116 "hlsl.l" +{return KW_SAMPLER_STATE; } + YY_BREAK +case 44: +YY_RULE_SETUP +#line 117 "hlsl.l" +{return KW_SAMPLERCOMPARISONSTATE;} + YY_BREAK +case 45: +YY_RULE_SETUP +#line 118 "hlsl.l" +{return KW_SHARED; } + YY_BREAK +case 46: +YY_RULE_SETUP +#line 119 "hlsl.l" +{return KW_STATEBLOCK; } + YY_BREAK +case 47: +YY_RULE_SETUP +#line 120 "hlsl.l" +{return KW_STATEBLOCK_STATE; } + YY_BREAK +case 48: +YY_RULE_SETUP +#line 121 "hlsl.l" +{return KW_STATIC; } + YY_BREAK +case 49: +YY_RULE_SETUP +#line 122 "hlsl.l" +{return KW_STRING; } + YY_BREAK +case 50: +YY_RULE_SETUP +#line 123 "hlsl.l" +{return KW_STRUCT; } + YY_BREAK +case 51: +YY_RULE_SETUP +#line 124 "hlsl.l" +{return KW_SWITCH; } + YY_BREAK +case 52: +YY_RULE_SETUP +#line 125 "hlsl.l" +{return KW_TBUFFER; } + YY_BREAK +case 53: +YY_RULE_SETUP +#line 126 "hlsl.l" +{return KW_TECHNIQUE; } + YY_BREAK +case 54: +YY_RULE_SETUP +#line 127 "hlsl.l" +{return KW_TECHNIQUE10; } + YY_BREAK +case 55: +YY_RULE_SETUP +#line 128 "hlsl.l" +{return KW_TEXTURE; } + YY_BREAK +case 56: +YY_RULE_SETUP +#line 129 "hlsl.l" +{return KW_TEXTURE1D; } + YY_BREAK +case 57: +YY_RULE_SETUP +#line 130 "hlsl.l" +{return KW_TEXTURE1DARRAY; } + YY_BREAK +case 58: +YY_RULE_SETUP +#line 131 "hlsl.l" +{return KW_TEXTURE2D; } + YY_BREAK +case 59: +YY_RULE_SETUP +#line 132 "hlsl.l" +{return KW_TEXTURE2DARRAY; } + YY_BREAK +case 60: +YY_RULE_SETUP +#line 133 "hlsl.l" +{return KW_TEXTURE2DMS; } + YY_BREAK +case 61: +YY_RULE_SETUP +#line 134 "hlsl.l" +{return KW_TEXTURE2DMSARRAY; } + YY_BREAK +case 62: +YY_RULE_SETUP +#line 135 "hlsl.l" +{return KW_TEXTURE3D; } + YY_BREAK +case 63: +YY_RULE_SETUP +#line 136 "hlsl.l" +{return KW_TEXTURE3DARRAY; } + YY_BREAK +case 64: +YY_RULE_SETUP +#line 137 "hlsl.l" +{return KW_TEXTURECUBE; } + YY_BREAK +case 65: +YY_RULE_SETUP +#line 138 "hlsl.l" +{return KW_TRUE; } + YY_BREAK +case 66: +YY_RULE_SETUP +#line 139 "hlsl.l" +{return KW_TYPEDEF; } + YY_BREAK +case 67: +YY_RULE_SETUP +#line 140 "hlsl.l" +{return KW_UNIFORM; } + YY_BREAK +case 68: +YY_RULE_SETUP +#line 141 "hlsl.l" +{return KW_VECTOR; } + YY_BREAK +case 69: +YY_RULE_SETUP +#line 142 "hlsl.l" +{return KW_VERTEXSHADER; } + YY_BREAK +case 70: +YY_RULE_SETUP +#line 143 "hlsl.l" +{return KW_VOID; } + YY_BREAK +case 71: +YY_RULE_SETUP +#line 144 "hlsl.l" +{return KW_VOLATILE; } + YY_BREAK +case 72: +YY_RULE_SETUP +#line 145 "hlsl.l" +{return KW_WHILE; } + YY_BREAK +case 73: +YY_RULE_SETUP +#line 147 "hlsl.l" +{return OP_INC; } + YY_BREAK +case 74: +YY_RULE_SETUP +#line 148 "hlsl.l" +{return OP_DEC; } + YY_BREAK +case 75: +YY_RULE_SETUP +#line 149 "hlsl.l" +{return OP_AND; } + YY_BREAK +case 76: +YY_RULE_SETUP +#line 150 "hlsl.l" +{return OP_OR; } + YY_BREAK +case 77: +YY_RULE_SETUP +#line 151 "hlsl.l" +{return OP_EQ; } + YY_BREAK +case 78: +YY_RULE_SETUP +#line 152 "hlsl.l" +{return OP_LEFTSHIFT; } + YY_BREAK +case 79: +YY_RULE_SETUP +#line 153 "hlsl.l" +{return OP_LEFTSHIFTASSIGN; } + YY_BREAK +case 80: +YY_RULE_SETUP +#line 154 "hlsl.l" +{return OP_RIGHTSHIFT; } + YY_BREAK +case 81: +YY_RULE_SETUP +#line 155 "hlsl.l" +{return OP_RIGHTSHIFTASSIGN; } + YY_BREAK +case 82: +YY_RULE_SETUP +#line 156 "hlsl.l" +{return OP_ELLIPSIS; } + YY_BREAK +case 83: +YY_RULE_SETUP +#line 157 "hlsl.l" +{return OP_LE; } + YY_BREAK +case 84: +YY_RULE_SETUP +#line 158 "hlsl.l" +{return OP_GE; } + YY_BREAK +case 85: +YY_RULE_SETUP +#line 159 "hlsl.l" +{return OP_NE; } + YY_BREAK +case 86: +YY_RULE_SETUP +#line 160 "hlsl.l" +{return OP_ADDASSIGN; } + YY_BREAK +case 87: +YY_RULE_SETUP +#line 161 "hlsl.l" +{return OP_SUBASSIGN; } + YY_BREAK +case 88: +YY_RULE_SETUP +#line 162 "hlsl.l" +{return OP_MULASSIGN; } + YY_BREAK +case 89: +YY_RULE_SETUP +#line 163 "hlsl.l" +{return OP_DIVASSIGN; } + YY_BREAK +case 90: +YY_RULE_SETUP +#line 164 "hlsl.l" +{return OP_MODASSIGN; } + YY_BREAK +case 91: +YY_RULE_SETUP +#line 165 "hlsl.l" +{return OP_ANDASSIGN; } + YY_BREAK +case 92: +YY_RULE_SETUP +#line 166 "hlsl.l" +{return OP_ORASSIGN; } + YY_BREAK +case 93: +YY_RULE_SETUP +#line 167 "hlsl.l" +{return OP_XORASSIGN; } + YY_BREAK +case 94: +YY_RULE_SETUP +#line 168 "hlsl.l" +{return OP_UNKNOWN1; } + YY_BREAK +case 95: +YY_RULE_SETUP +#line 169 "hlsl.l" +{return OP_UNKNOWN2; } + YY_BREAK +case 96: +YY_RULE_SETUP +#line 170 "hlsl.l" +{return OP_UNKNOWN3; } + YY_BREAK +case 97: +YY_RULE_SETUP +#line 171 "hlsl.l" +{return OP_UNKNOWN4; } + YY_BREAK +case 98: +YY_RULE_SETUP +#line 173 "hlsl.l" +{return KW_COLUMN_MAJOR; } + YY_BREAK +case 99: +YY_RULE_SETUP +#line 174 "hlsl.l" +{return KW_ROW_MAJOR; } + YY_BREAK +case 100: +YY_RULE_SETUP +#line 176 "hlsl.l" +{ + hlsl_lval.name = d3dcompiler_strdup(hlsl_text); + if (get_variable(hlsl_ctx.cur_scope, hlsl_text) + || find_function(hlsl_text)) + return VAR_IDENTIFIER; + else if (get_type(hlsl_ctx.cur_scope, hlsl_text, TRUE)) + return TYPE_IDENTIFIER; + else + return NEW_IDENTIFIER; + } + YY_BREAK +case 101: +YY_RULE_SETUP +#line 187 "hlsl.l" +{ + hlsl_lval.floatval = atof(hlsl_text); + return C_FLOAT; + } + YY_BREAK +case 102: +YY_RULE_SETUP +#line 191 "hlsl.l" +{ + hlsl_lval.floatval = atof(hlsl_text); + return C_FLOAT; + } + YY_BREAK +case 103: +YY_RULE_SETUP +#line 195 "hlsl.l" +{ + hlsl_lval.floatval = atof(hlsl_text); + return C_FLOAT; + } + YY_BREAK +case 104: +YY_RULE_SETUP +#line 199 "hlsl.l" +{ + sscanf(hlsl_text, "0x%x", &hlsl_lval.intval); + return C_INTEGER; + } + YY_BREAK +case 105: +YY_RULE_SETUP +#line 203 "hlsl.l" +{ + sscanf(hlsl_text, "0%o", &hlsl_lval.intval); + return C_INTEGER; + } + YY_BREAK +case 106: +YY_RULE_SETUP +#line 207 "hlsl.l" +{ + hlsl_lval.intval = (atoi(hlsl_text)); + return C_INTEGER; + } + YY_BREAK +case 107: +YY_RULE_SETUP +#line 212 "hlsl.l" +{} + YY_BREAK +case 108: +YY_RULE_SETUP +#line 214 "hlsl.l" +{} + YY_BREAK +case 109: +/* rule 109 can match eol */ +YY_RULE_SETUP +#line 215 "hlsl.l" +{ + hlsl_ctx.line_no++; + hlsl_ctx.column = 1; + } + YY_BREAK +case 110: +YY_RULE_SETUP +#line 220 "hlsl.l" +{ + BEGIN pp; + } + YY_BREAK +case 111: +YY_RULE_SETUP +#line 224 "hlsl.l" +{ + TRACE("Got a #pragma.\n"); + BEGIN pp_pragma; + } + YY_BREAK +case 112: +YY_RULE_SETUP +#line 228 "hlsl.l" +{ + TRACE("#pragma setting row_major mode.\n"); + hlsl_ctx.matrix_majority = HLSL_ROW_MAJOR; + BEGIN pp_ignore; + } + YY_BREAK +case 113: +YY_RULE_SETUP +#line 233 "hlsl.l" +{ + TRACE("#pragma setting column_major mode.\n"); + hlsl_ctx.matrix_majority = HLSL_COLUMN_MAJOR; + BEGIN pp_ignore; + } + YY_BREAK +case 114: +/* rule 114 can match eol */ +YY_RULE_SETUP +#line 238 "hlsl.l" +{ + FIXME("Unsupported preprocessor #pragma directive at line %u.\n", hlsl_ctx.line_no); + BEGIN INITIAL; + } + YY_BREAK +case 115: +YY_RULE_SETUP +#line 242 "hlsl.l" +{} + YY_BREAK +case 116: +YY_RULE_SETUP +#line 243 "hlsl.l" +{ + TRACE("Preprocessor line info.\n"); + BEGIN pp_line; + hlsl_lval.intval = (atoi(hlsl_text)); + return PRE_LINE; + } + YY_BREAK +case 117: +/* rule 117 can match eol */ +YY_RULE_SETUP +#line 249 "hlsl.l" +{ + char *string = d3dcompiler_strdup(hlsl_text + 1); + + BEGIN pp_ignore; + string[strlen(string) - 1] = 0; + hlsl_lval.name = string; + return STRING; + } + YY_BREAK +case 118: +YY_RULE_SETUP +#line 257 "hlsl.l" +{} + YY_BREAK +case 119: +/* rule 119 can match eol */ +YY_RULE_SETUP +#line 258 "hlsl.l" +{ + FIXME("Malformed preprocessor line directive?\n"); + BEGIN INITIAL; + } + YY_BREAK +case 120: +/* rule 120 can match eol */ +YY_RULE_SETUP +#line 262 "hlsl.l" +{ + BEGIN INITIAL; + } + YY_BREAK +case 121: +YY_RULE_SETUP +#line 265 "hlsl.l" +{} + YY_BREAK +case 122: +/* rule 122 can match eol */ +YY_RULE_SETUP +#line 266 "hlsl.l" +{ + FIXME("Unexpected preprocessor directive.\n"); + BEGIN INITIAL; + } + YY_BREAK +case 123: +YY_RULE_SETUP +#line 270 "hlsl.l" +{} + YY_BREAK +case 124: +YY_RULE_SETUP +#line 272 "hlsl.l" +{ + return hlsl_text[0]; + } + YY_BREAK +case 125: +YY_RULE_SETUP +#line 276 "hlsl.l" +ECHO; + YY_BREAK +#line 1969 "hlsl.yy.c" +case YY_STATE_EOF(INITIAL): +case YY_STATE_EOF(pp): +case YY_STATE_EOF(pp_line): +case YY_STATE_EOF(pp_pragma): +case YY_STATE_EOF(pp_ignore): + yyterminate(); + + case YY_END_OF_BUFFER: + { + /* Amount of text matched not including the EOB char. */ + int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1; + + /* Undo the effects of YY_DO_BEFORE_ACTION. */ + *yy_cp = (yy_hold_char); + YY_RESTORE_YY_MORE_OFFSET + + if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW ) + { + /* We're scanning a new file or input source. It's + * possible that this happened because the user + * just pointed hlsl_in at a new source and called + * hlsl_lex(). If so, then we have to assure + * consistency between YY_CURRENT_BUFFER and our + * globals. Here is the right place to do so, because + * this is the first action (other than possibly a + * back-up) that will match for the new input source. + */ + (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + YY_CURRENT_BUFFER_LVALUE->yy_input_file = hlsl_in; + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; + } + + /* Note that here we test for yy_c_buf_p "<=" to the position + * of the first EOB in the buffer, since yy_c_buf_p will + * already have been incremented past the NUL character + * (since all states make transitions on EOB to the + * end-of-buffer state). Contrast this with the test + * in input(). + */ + if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) + { /* This was really a NUL. */ + yy_state_type yy_next_state; + + (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state( ); + + /* Okay, we're now positioned to make the NUL + * transition. We couldn't have + * yy_get_previous_state() go ahead and do it + * for us because it doesn't know how to deal + * with the possibility of jamming (and we don't + * want to build jamming into it because then it + * will run more slowly). + */ + + yy_next_state = yy_try_NUL_trans( yy_current_state ); + + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + + if ( yy_next_state ) + { + /* Consume the NUL. */ + yy_cp = ++(yy_c_buf_p); + yy_current_state = yy_next_state; + goto yy_match; + } + + else + { + yy_cp = (yy_last_accepting_cpos); + yy_current_state = (yy_last_accepting_state); + goto yy_find_action; + } + } + + else switch ( yy_get_next_buffer( ) ) + { + case EOB_ACT_END_OF_FILE: + { + (yy_did_buffer_switch_on_eof) = 0; + + if ( hlsl_wrap( ) ) + { + /* Note: because we've taken care in + * yy_get_next_buffer() to have set up + * hlsl_text, we can now set up + * yy_c_buf_p so that if some total + * hoser (like flex itself) wants to + * call the scanner after we return the + * YY_NULL, it'll still work - another + * YY_NULL will get returned. + */ + (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ; + + yy_act = YY_STATE_EOF(YY_START); + goto do_action; + } + + else + { + if ( ! (yy_did_buffer_switch_on_eof) ) + YY_NEW_FILE; + } + break; + } + + case EOB_ACT_CONTINUE_SCAN: + (yy_c_buf_p) = + (yytext_ptr) + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state( ); + + yy_cp = (yy_c_buf_p); + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + goto yy_match; + + case EOB_ACT_LAST_MATCH: + (yy_c_buf_p) = + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)]; + + yy_current_state = yy_get_previous_state( ); + + yy_cp = (yy_c_buf_p); + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + goto yy_find_action; + } + break; + } + + default: + YY_FATAL_ERROR( + "fatal flex scanner internal error--no action found" ); + } /* end of action switch */ + } /* end of scanning one token */ +} /* end of hlsl_lex */ + +/* yy_get_next_buffer - try to read in a new buffer + * + * Returns a code representing an action: + * EOB_ACT_LAST_MATCH - + * EOB_ACT_CONTINUE_SCAN - continue scanning from current position + * EOB_ACT_END_OF_FILE - end of file + */ +static int yy_get_next_buffer (void) +{ + register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; + register char *source = (yytext_ptr); + register int number_to_move, i; + int ret_val; + + if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] ) + YY_FATAL_ERROR( + "fatal flex scanner internal error--end of buffer missed" ); + + if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 ) + { /* Don't try to fill the buffer, so this is an EOF. */ + if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 ) + { + /* We matched a single character, the EOB, so + * treat this as a final EOF. + */ + return EOB_ACT_END_OF_FILE; + } + + else + { + /* We matched some text prior to the EOB, first + * process it. + */ + return EOB_ACT_LAST_MATCH; + } + } + + /* Try to read more data. */ + + /* First move last chars to start of buffer. */ + number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr)) - 1; + + for ( i = 0; i < number_to_move; ++i ) + *(dest++) = *(source++); + + if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING ) + /* don't do the read, it's not guaranteed to return an EOF, + * just force an EOF + */ + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0; + + else + { + int num_to_read = + YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; + + while ( num_to_read <= 0 ) + { /* Not enough room in the buffer - grow it. */ + + /* just a shorter name for the current buffer */ + YY_BUFFER_STATE b = YY_CURRENT_BUFFER; + + int yy_c_buf_p_offset = + (int) ((yy_c_buf_p) - b->yy_ch_buf); + + if ( b->yy_is_our_buffer ) + { + int new_size = b->yy_buf_size * 2; + + if ( new_size <= 0 ) + b->yy_buf_size += b->yy_buf_size / 8; + else + b->yy_buf_size *= 2; + + b->yy_ch_buf = (char *) + /* Include room in for 2 EOB chars. */ + hlsl_realloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 ); + } + else + /* Can't grow it, we don't own it. */ + b->yy_ch_buf = 0; + + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( + "fatal error - scanner input buffer overflow" ); + + (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset]; + + num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - + number_to_move - 1; + + } + + if ( num_to_read > YY_READ_BUF_SIZE ) + num_to_read = YY_READ_BUF_SIZE; + + /* Read in more data. */ + YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), + (yy_n_chars), (size_t) num_to_read ); + + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + if ( (yy_n_chars) == 0 ) + { + if ( number_to_move == YY_MORE_ADJ ) + { + ret_val = EOB_ACT_END_OF_FILE; + hlsl_restart(hlsl_in ); + } + + else + { + ret_val = EOB_ACT_LAST_MATCH; + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = + YY_BUFFER_EOF_PENDING; + } + } + + else + ret_val = EOB_ACT_CONTINUE_SCAN; + + if ((yy_size_t) ((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { + /* Extend the array by 50%, plus the number we really need. */ + yy_size_t new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1); + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) hlsl_realloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ); + if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); + } + + (yy_n_chars) += number_to_move; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR; + + (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; + + return ret_val; +} + +/* yy_get_previous_state - get the state just before the EOB char was reached */ + + static yy_state_type yy_get_previous_state (void) +{ + register yy_state_type yy_current_state; + register char *yy_cp; + + yy_current_state = (yy_start); + yy_current_state += YY_AT_BOL(); + + for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp ) + { + register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 717 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + } + + return yy_current_state; +} + +/* yy_try_NUL_trans - try to make a transition on the NUL character + * + * synopsis + * next_state = yy_try_NUL_trans( current_state ); + */ + static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state ) +{ + register int yy_is_jam; + register char *yy_cp = (yy_c_buf_p); + + register YY_CHAR yy_c = 1; + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 717 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + yy_is_jam = (yy_current_state == 716); + + return yy_is_jam ? 0 : yy_current_state; +} + +#ifndef YY_NO_INPUT +#ifdef __cplusplus + static int yyinput (void) +#else + static int input (void) +#endif + +{ + int c; + + *(yy_c_buf_p) = (yy_hold_char); + + if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR ) + { + /* yy_c_buf_p now points to the character we want to return. + * If this occurs *before* the EOB characters, then it's a + * valid NUL; if not, then we've hit the end of the buffer. + */ + if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) + /* This was really a NUL. */ + *(yy_c_buf_p) = '\0'; + + else + { /* need more input */ + int offset = (yy_c_buf_p) - (yytext_ptr); + ++(yy_c_buf_p); + + switch ( yy_get_next_buffer( ) ) + { + case EOB_ACT_LAST_MATCH: + /* This happens because yy_g_n_b() + * sees that we've accumulated a + * token and flags that we need to + * try matching the token before + * proceeding. But for input(), + * there's no matching to consider. + * So convert the EOB_ACT_LAST_MATCH + * to EOB_ACT_END_OF_FILE. + */ + + /* Reset buffer status. */ + hlsl_restart(hlsl_in ); + + /*FALLTHROUGH*/ + + case EOB_ACT_END_OF_FILE: + { + if ( hlsl_wrap( ) ) + return EOF; + + if ( ! (yy_did_buffer_switch_on_eof) ) + YY_NEW_FILE; +#ifdef __cplusplus + return yyinput(); +#else + return input(); +#endif + } + + case EOB_ACT_CONTINUE_SCAN: + (yy_c_buf_p) = (yytext_ptr) + offset; + break; + } + } + } + + c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */ + *(yy_c_buf_p) = '\0'; /* preserve hlsl_text */ + (yy_hold_char) = *++(yy_c_buf_p); + + YY_CURRENT_BUFFER_LVALUE->yy_at_bol = (c == '\n'); + + return c; +} +#endif /* ifndef YY_NO_INPUT */ + +/** Immediately switch to a different input stream. + * @param input_file A readable stream. + * + * @note This function does not reset the start condition to @c INITIAL . + */ + void hlsl_restart (FILE * input_file ) +{ + + if ( ! YY_CURRENT_BUFFER ){ + hlsl_ensure_buffer_stack (); + YY_CURRENT_BUFFER_LVALUE = + hlsl__create_buffer(hlsl_in,YY_BUF_SIZE ); + } + + hlsl__init_buffer(YY_CURRENT_BUFFER,input_file ); + hlsl__load_buffer_state( ); +} + +/** Switch to a different input buffer. + * @param new_buffer The new input buffer. + * + */ + void hlsl__switch_to_buffer (YY_BUFFER_STATE new_buffer ) +{ + + /* TODO. We should be able to replace this entire function body + * with + * hlsl_pop_buffer_state(); + * hlsl_push_buffer_state(new_buffer); + */ + hlsl_ensure_buffer_stack (); + if ( YY_CURRENT_BUFFER == new_buffer ) + return; + + if ( YY_CURRENT_BUFFER ) + { + /* Flush out information for old buffer. */ + *(yy_c_buf_p) = (yy_hold_char); + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + YY_CURRENT_BUFFER_LVALUE = new_buffer; + hlsl__load_buffer_state( ); + + /* We don't actually know whether we did this switch during + * EOF (hlsl_wrap()) processing, but the only time this flag + * is looked at is after hlsl_wrap() is called, so it's safe + * to go ahead and always set it. + */ + (yy_did_buffer_switch_on_eof) = 1; +} + +static void hlsl__load_buffer_state (void) +{ + (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; + hlsl_in = YY_CURRENT_BUFFER_LVALUE->yy_input_file; + (yy_hold_char) = *(yy_c_buf_p); +} + +/** Allocate and initialize an input buffer state. + * @param file A readable stream. + * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. + * + * @return the allocated buffer state. + */ + YY_BUFFER_STATE hlsl__create_buffer (FILE * file, int size ) +{ + YY_BUFFER_STATE b; + + b = (YY_BUFFER_STATE) hlsl_alloc(sizeof( struct yy_buffer_state ) ); + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in hlsl__create_buffer()" ); + + b->yy_buf_size = size; + + /* yy_ch_buf has to be 2 characters longer than the size given because + * we need to put in 2 end-of-buffer characters. + */ + b->yy_ch_buf = (char *) hlsl_alloc(b->yy_buf_size + 2 ); + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in hlsl__create_buffer()" ); + + b->yy_is_our_buffer = 1; + + hlsl__init_buffer(b,file ); + + return b; +} + +/** Destroy the buffer. + * @param b a buffer created with hlsl__create_buffer() + * + */ + void hlsl__delete_buffer (YY_BUFFER_STATE b ) +{ + + if ( ! b ) + return; + + if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */ + YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; + + if ( b->yy_is_our_buffer ) + hlsl_free((void *) b->yy_ch_buf ); + + hlsl_free((void *) b ); +} + +/* Initializes or reinitializes a buffer. + * This function is sometimes called more than once on the same buffer, + * such as during a hlsl_restart() or at EOF. + */ + static void hlsl__init_buffer (YY_BUFFER_STATE b, FILE * file ) + +{ + int oerrno = errno; + + hlsl__flush_buffer(b ); + + b->yy_input_file = file; + b->yy_fill_buffer = 1; + + /* If b is the current buffer, then hlsl__init_buffer was _probably_ + * called from hlsl_restart() or through yy_get_next_buffer. + * In that case, we don't want to reset the lineno or column. + */ + if (b != YY_CURRENT_BUFFER){ + b->yy_bs_lineno = 1; + b->yy_bs_column = 0; + } + + b->yy_is_interactive = 0; + + errno = oerrno; +} + +/** Discard all buffered characters. On the next scan, YY_INPUT will be called. + * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER. + * + */ + void hlsl__flush_buffer (YY_BUFFER_STATE b ) +{ + if ( ! b ) + return; + + b->yy_n_chars = 0; + + /* We always need two end-of-buffer characters. The first causes + * a transition to the end-of-buffer state. The second causes + * a jam in that state. + */ + b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; + b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; + + b->yy_buf_pos = &b->yy_ch_buf[0]; + + b->yy_at_bol = 1; + b->yy_buffer_status = YY_BUFFER_NEW; + + if ( b == YY_CURRENT_BUFFER ) + hlsl__load_buffer_state( ); +} + +/** Pushes the new state onto the stack. The new state becomes + * the current state. This function will allocate the stack + * if necessary. + * @param new_buffer The new state. + * + */ +void hlsl_push_buffer_state (YY_BUFFER_STATE new_buffer ) +{ + if (new_buffer == NULL) + return; + + hlsl_ensure_buffer_stack(); + + /* This block is copied from hlsl__switch_to_buffer. */ + if ( YY_CURRENT_BUFFER ) + { + /* Flush out information for old buffer. */ + *(yy_c_buf_p) = (yy_hold_char); + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + /* Only push if top exists. Otherwise, replace top. */ + if (YY_CURRENT_BUFFER) + (yy_buffer_stack_top)++; + YY_CURRENT_BUFFER_LVALUE = new_buffer; + + /* copied from hlsl__switch_to_buffer. */ + hlsl__load_buffer_state( ); + (yy_did_buffer_switch_on_eof) = 1; +} + +/** Removes and deletes the top of the stack, if present. + * The next element becomes the new top. + * + */ +void hlsl_pop_buffer_state (void) +{ + if (!YY_CURRENT_BUFFER) + return; + + hlsl__delete_buffer(YY_CURRENT_BUFFER ); + YY_CURRENT_BUFFER_LVALUE = NULL; + if ((yy_buffer_stack_top) > 0) + --(yy_buffer_stack_top); + + if (YY_CURRENT_BUFFER) { + hlsl__load_buffer_state( ); + (yy_did_buffer_switch_on_eof) = 1; + } +} + +/* Allocates the stack if it does not exist. + * Guarantees space for at least one push. + */ +static void hlsl_ensure_buffer_stack (void) +{ + int num_to_alloc; + + if (!(yy_buffer_stack)) { + + /* First allocation is just for 2 elements, since we don't know if this + * scanner will even need a stack. We use 2 instead of 1 to avoid an + * immediate realloc on the next call. + */ + num_to_alloc = 1; + (yy_buffer_stack) = (struct yy_buffer_state**)hlsl_alloc + (num_to_alloc * sizeof(struct yy_buffer_state*) + ); + if ( ! (yy_buffer_stack) ) + YY_FATAL_ERROR( "out of dynamic memory in hlsl_ensure_buffer_stack()" ); + + memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*)); + + (yy_buffer_stack_max) = num_to_alloc; + (yy_buffer_stack_top) = 0; + return; + } + + if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){ + + /* Increase the buffer to prepare for a possible push. */ + int grow_size = 8 /* arbitrary grow size */; + + num_to_alloc = (yy_buffer_stack_max) + grow_size; + (yy_buffer_stack) = (struct yy_buffer_state**)hlsl_realloc + ((yy_buffer_stack), + num_to_alloc * sizeof(struct yy_buffer_state*) + ); + if ( ! (yy_buffer_stack) ) + YY_FATAL_ERROR( "out of dynamic memory in hlsl_ensure_buffer_stack()" ); + + /* zero only the new slots.*/ + memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*)); + (yy_buffer_stack_max) = num_to_alloc; + } +} + +/** Setup the input buffer state to scan directly from a user-specified character buffer. + * @param base the character buffer + * @param size the size in bytes of the character buffer + * + * @return the newly allocated buffer state object. + */ +YY_BUFFER_STATE hlsl__scan_buffer (char * base, yy_size_t size ) +{ + YY_BUFFER_STATE b; + + if ( size < 2 || + base[size-2] != YY_END_OF_BUFFER_CHAR || + base[size-1] != YY_END_OF_BUFFER_CHAR ) + /* They forgot to leave room for the EOB's. */ + return 0; + + b = (YY_BUFFER_STATE) hlsl_alloc(sizeof( struct yy_buffer_state ) ); + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in hlsl__scan_buffer()" ); + + b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */ + b->yy_buf_pos = b->yy_ch_buf = base; + b->yy_is_our_buffer = 0; + b->yy_input_file = 0; + b->yy_n_chars = b->yy_buf_size; + b->yy_is_interactive = 0; + b->yy_at_bol = 1; + b->yy_fill_buffer = 0; + b->yy_buffer_status = YY_BUFFER_NEW; + + hlsl__switch_to_buffer(b ); + + return b; +} + +/** Setup the input buffer state to scan a string. The next call to hlsl_lex() will + * scan from a @e copy of @a str. + * @param yystr a NUL-terminated string to scan + * + * @return the newly allocated buffer state object. + * @note If you want to scan bytes that may contain NUL values, then use + * hlsl__scan_bytes() instead. + */ +YY_BUFFER_STATE hlsl__scan_string (yyconst char * yystr ) +{ + + return hlsl__scan_bytes(yystr,strlen(yystr) ); +} + +/** Setup the input buffer state to scan the given bytes. The next call to hlsl_lex() will + * scan from a @e copy of @a bytes. + * @param yybytes the byte buffer to scan + * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes. + * + * @return the newly allocated buffer state object. + */ +YY_BUFFER_STATE hlsl__scan_bytes (yyconst char * yybytes, int _yybytes_len ) +{ + YY_BUFFER_STATE b; + char *buf; + yy_size_t n; + int i; + + /* Get memory for full buffer, including space for trailing EOB's. */ + n = _yybytes_len + 2; + buf = (char *) hlsl_alloc(n ); + if ( ! buf ) + YY_FATAL_ERROR( "out of dynamic memory in hlsl__scan_bytes()" ); + + for ( i = 0; i < _yybytes_len; ++i ) + buf[i] = yybytes[i]; + + buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR; + + b = hlsl__scan_buffer(buf,n ); + if ( ! b ) + YY_FATAL_ERROR( "bad buffer in hlsl__scan_bytes()" ); + + /* It's okay to grow etc. this buffer, and we should throw it + * away when we're done. + */ + b->yy_is_our_buffer = 1; + + return b; +} + +#ifndef YY_EXIT_FAILURE +#define YY_EXIT_FAILURE 2 +#endif + +static void yy_fatal_error (yyconst char* msg ) +{ + (void) fprintf( stderr, "%s\n", msg ); + exit( YY_EXIT_FAILURE ); +} + +/* Redefine yyless() so it works in section 3 code. */ + +#undef yyless +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up hlsl_text. */ \ + int yyless_macro_arg = (n); \ + YY_LESS_LINENO(yyless_macro_arg);\ + hlsl_text[hlsl_leng] = (yy_hold_char); \ + (yy_c_buf_p) = hlsl_text + yyless_macro_arg; \ + (yy_hold_char) = *(yy_c_buf_p); \ + *(yy_c_buf_p) = '\0'; \ + hlsl_leng = yyless_macro_arg; \ + } \ + while ( 0 ) + +/* Accessor methods (get/set functions) to struct members. */ + +/** Get the current line number. + * + */ +int hlsl_get_lineno (void) +{ + + return hlsl_lineno; +} + +/** Get the input stream. + * + */ +FILE *hlsl_get_in (void) +{ + return hlsl_in; +} + +/** Get the output stream. + * + */ +FILE *hlsl_get_out (void) +{ + return hlsl_out; +} + +/** Get the length of the current token. + * + */ +int hlsl_get_leng (void) +{ + return hlsl_leng; +} + +/** Get the current token. + * + */ + +char *hlsl_get_text (void) +{ + return hlsl_text; +} + +/** Set the current line number. + * @param line_number + * + */ +void hlsl_set_lineno (int line_number ) +{ + + hlsl_lineno = line_number; +} + +/** Set the input stream. This does not discard the current + * input buffer. + * @param in_str A readable stream. + * + * @see hlsl__switch_to_buffer + */ +void hlsl_set_in (FILE * in_str ) +{ + hlsl_in = in_str ; +} + +void hlsl_set_out (FILE * out_str ) +{ + hlsl_out = out_str ; +} + +int hlsl_get_debug (void) +{ + return hlsl__flex_debug; +} + +void hlsl_set_debug (int bdebug ) +{ + hlsl__flex_debug = bdebug ; +} + +static int yy_init_globals (void) +{ + /* Initialization is the same as for the non-reentrant scanner. + * This function is called from hlsl_lex_destroy(), so don't allocate here. + */ + + (yy_buffer_stack) = 0; + (yy_buffer_stack_top) = 0; + (yy_buffer_stack_max) = 0; + (yy_c_buf_p) = (char *) 0; + (yy_init) = 0; + (yy_start) = 0; + +/* Defined in main.c */ +#ifdef YY_STDINIT + hlsl_in = stdin; + hlsl_out = stdout; +#else + hlsl_in = (FILE *) 0; + hlsl_out = (FILE *) 0; +#endif + + /* For future reference: Set errno on error, since we are called by + * hlsl_lex_init() + */ + return 0; +} + +/* hlsl_lex_destroy is for both reentrant and non-reentrant scanners. */ +int hlsl_lex_destroy (void) +{ + + /* Pop the buffer stack, destroying each element. */ + while(YY_CURRENT_BUFFER){ + hlsl__delete_buffer(YY_CURRENT_BUFFER ); + YY_CURRENT_BUFFER_LVALUE = NULL; + hlsl_pop_buffer_state(); + } + + /* Destroy the stack itself. */ + hlsl_free((yy_buffer_stack) ); + (yy_buffer_stack) = NULL; + + /* Reset the globals. This is important in a non-reentrant scanner so the next time + * hlsl_lex() is called, initialization will occur. */ + yy_init_globals( ); + + return 0; +} + +/* + * Internal utility routines. + */ + +#ifndef yytext_ptr +static void yy_flex_strncpy (char* s1, yyconst char * s2, int n ) +{ + register int i; + for ( i = 0; i < n; ++i ) + s1[i] = s2[i]; +} +#endif + +#ifdef YY_NEED_STRLEN +static int yy_flex_strlen (yyconst char * s ) +{ + register int n; + for ( n = 0; s[n]; ++n ) + ; + + return n; +} +#endif + +void *hlsl_alloc (yy_size_t size ) +{ + return (void *) malloc( size ); +} + +void *hlsl_realloc (void * ptr, yy_size_t size ) +{ + /* The cast to (char *) in the following accommodates both + * implementations that use char* generic pointers, and those + * that use void* generic pointers. It works with the latter + * because both ANSI C and C++ allow castless assignment from + * any pointer type to void*, and deal with argument conversions + * as though doing an assignment. + */ + return (void *) realloc( (char *) ptr, size ); +} + +void hlsl_free (void * ptr ) +{ + free( (char *) ptr ); /* see hlsl_realloc() for (char *) cast */ +} + +#define YYTABLES_NAME "yytables" + +#line 276 "hlsl.l" + + + +struct bwriter_shader *parse_hlsl(enum shader_type type, DWORD major, DWORD minor, + const char *entrypoint, char **messages); + +struct bwriter_shader *parse_hlsl_shader(const char *text, enum shader_type type, DWORD major, DWORD minor, + 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, major, minor, entrypoint, messages); + + hlsl__delete_buffer(buffer); + return ret; +} + diff --git a/reactos/dll/directx/wine/d3dcompiler_43/reflection.c b/reactos/dll/directx/wine/d3dcompiler_43/reflection.c new file mode 100644 index 00000000000..f516e4a0449 --- /dev/null +++ b/reactos/dll/directx/wine/d3dcompiler_43/reflection.c @@ -0,0 +1,1848 @@ +/* + * Copyright 2009 Henri Verbeet for CodeWeavers + * Copyright 2010 Rico Schüller + * + * 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 "d3dcompiler_private.h" + +WINE_DEFAULT_DEBUG_CHANNEL(d3dcompiler); + +enum D3DCOMPILER_SIGNATURE_ELEMENT_SIZE +{ + D3DCOMPILER_SIGNATURE_ELEMENT_SIZE6 = 6, + D3DCOMPILER_SIGNATURE_ELEMENT_SIZE7 = 7, +}; + +#define D3DCOMPILER_SHADER_TARGET_VERSION_MASK 0xffff +#define D3DCOMPILER_SHADER_TARGET_SHADERTYPE_MASK 0xffff0000 + +struct d3dcompiler_shader_signature +{ + D3D11_SIGNATURE_PARAMETER_DESC *elements; + UINT element_count; + char *string_data; +}; + +struct d3dcompiler_shader_reflection_type +{ + ID3D11ShaderReflectionType ID3D11ShaderReflectionType_iface; + + DWORD id; + struct wine_rb_entry entry; + + struct d3dcompiler_shader_reflection *reflection; + + D3D11_SHADER_TYPE_DESC desc; + struct d3dcompiler_shader_reflection_type_member *members; +}; + +struct d3dcompiler_shader_reflection_type_member +{ + char *name; + DWORD offset; + struct d3dcompiler_shader_reflection_type *type; +}; + +struct d3dcompiler_shader_reflection_variable +{ + ID3D11ShaderReflectionVariable ID3D11ShaderReflectionVariable_iface; + + struct d3dcompiler_shader_reflection_constant_buffer *constant_buffer; + struct d3dcompiler_shader_reflection_type *type; + + char *name; + UINT start_offset; + UINT size; + UINT flags; + LPVOID default_value; +}; + +struct d3dcompiler_shader_reflection_constant_buffer +{ + ID3D11ShaderReflectionConstantBuffer ID3D11ShaderReflectionConstantBuffer_iface; + + struct d3dcompiler_shader_reflection *reflection; + + char *name; + D3D_CBUFFER_TYPE type; + UINT variable_count; + UINT size; + UINT flags; + + struct d3dcompiler_shader_reflection_variable *variables; +}; + +/* ID3D11ShaderReflection */ +struct d3dcompiler_shader_reflection +{ + ID3D11ShaderReflection ID3D11ShaderReflection_iface; + LONG refcount; + + DWORD target; + char *creator; + UINT flags; + UINT version; + UINT bound_resource_count; + UINT constant_buffer_count; + + UINT mov_instruction_count; + UINT conversion_instruction_count; + UINT instruction_count; + UINT emit_instruction_count; + D3D_PRIMITIVE_TOPOLOGY gs_output_topology; + UINT gs_max_output_vertex_count; + D3D_PRIMITIVE input_primitive; + UINT cut_instruction_count; + UINT dcl_count; + UINT static_flow_control_count; + UINT float_instruction_count; + UINT temp_register_count; + UINT int_instruction_count; + UINT uint_instruction_count; + UINT temp_array_count; + UINT array_instruction_count; + UINT texture_normal_instructions; + UINT texture_load_instructions; + UINT texture_comp_instructions; + UINT texture_bias_instructions; + UINT texture_gradient_instructions; + UINT dynamic_flow_control_count; + UINT c_control_points; + D3D_TESSELLATOR_OUTPUT_PRIMITIVE hs_output_primitive; + D3D_TESSELLATOR_PARTITIONING hs_prtitioning; + D3D_TESSELLATOR_DOMAIN tessellator_domain; + + struct d3dcompiler_shader_signature *isgn; + struct d3dcompiler_shader_signature *osgn; + struct d3dcompiler_shader_signature *pcsg; + char *resource_string; + D3D11_SHADER_INPUT_BIND_DESC *bound_resources; + struct d3dcompiler_shader_reflection_constant_buffer *constant_buffers; + struct wine_rb_tree types; +}; + +static struct d3dcompiler_shader_reflection_type *get_reflection_type(struct d3dcompiler_shader_reflection *reflection, const char *data, DWORD offset); + +static const struct ID3D11ShaderReflectionConstantBufferVtbl d3dcompiler_shader_reflection_constant_buffer_vtbl; +static const struct ID3D11ShaderReflectionVariableVtbl d3dcompiler_shader_reflection_variable_vtbl; +static const struct ID3D11ShaderReflectionTypeVtbl d3dcompiler_shader_reflection_type_vtbl; + +/* null objects - needed for invalid calls */ +static struct d3dcompiler_shader_reflection_constant_buffer null_constant_buffer = {{&d3dcompiler_shader_reflection_constant_buffer_vtbl}}; +static struct d3dcompiler_shader_reflection_type null_type = {{&d3dcompiler_shader_reflection_type_vtbl}}; +static struct d3dcompiler_shader_reflection_variable null_variable = {{&d3dcompiler_shader_reflection_variable_vtbl}, + &null_constant_buffer, &null_type}; + +static BOOL copy_name(const char *ptr, char **name) +{ + size_t name_len; + + if (!ptr) return TRUE; + + name_len = strlen(ptr) + 1; + if (name_len == 1) + { + return TRUE; + } + + *name = HeapAlloc(GetProcessHeap(), 0, name_len); + if (!*name) + { + ERR("Failed to allocate name memory.\n"); + return FALSE; + } + + memcpy(*name, ptr, name_len); + + return TRUE; +} + +static BOOL copy_value(const char *ptr, void **value, DWORD size) +{ + if (!ptr || !size) return TRUE; + + *value = HeapAlloc(GetProcessHeap(), 0, size); + if (!*value) + { + ERR("Failed to allocate vlaue memory.\n"); + return FALSE; + } + + memcpy(*value, ptr, size); + + return TRUE; +} + +static void *d3dcompiler_rb_alloc(size_t size) +{ + return HeapAlloc(GetProcessHeap(), 0, size); +} + +static void *d3dcompiler_rb_realloc(void *ptr, size_t size) +{ + return HeapReAlloc(GetProcessHeap(), 0, ptr, size); +} + +static void d3dcompiler_rb_free(void *ptr) +{ + HeapFree(GetProcessHeap(), 0, ptr); +} + +static int d3dcompiler_shader_reflection_type_compare(const void *key, const struct wine_rb_entry *entry) +{ + const struct d3dcompiler_shader_reflection_type *t = WINE_RB_ENTRY_VALUE(entry, const struct d3dcompiler_shader_reflection_type, entry); + const DWORD *id = key; + + return *id - t->id; +} + +static void free_type_member(struct d3dcompiler_shader_reflection_type_member *member) +{ + if (member) + { + HeapFree(GetProcessHeap(), 0, member->name); + } +} + +static void d3dcompiler_shader_reflection_type_destroy(struct wine_rb_entry *entry, void *context) +{ + struct d3dcompiler_shader_reflection_type *t = WINE_RB_ENTRY_VALUE(entry, struct d3dcompiler_shader_reflection_type, entry); + unsigned int i; + + TRACE("reflection type %p.\n", t); + + if (t->members) + { + for (i = 0; i < t->desc.Members; ++i) + { + free_type_member(&t->members[i]); + } + HeapFree(GetProcessHeap(), 0, t->members); + } + + HeapFree(GetProcessHeap(), 0, t); +} + +static const struct wine_rb_functions d3dcompiler_shader_reflection_type_rb_functions = +{ + d3dcompiler_rb_alloc, + d3dcompiler_rb_realloc, + d3dcompiler_rb_free, + d3dcompiler_shader_reflection_type_compare, +}; + +static void free_signature(struct d3dcompiler_shader_signature *sig) +{ + TRACE("Free signature %p\n", sig); + + HeapFree(GetProcessHeap(), 0, sig->elements); + HeapFree(GetProcessHeap(), 0, sig->string_data); +} + +static void free_variable(struct d3dcompiler_shader_reflection_variable *var) +{ + if (var) + { + HeapFree(GetProcessHeap(), 0, var->name); + HeapFree(GetProcessHeap(), 0, var->default_value); + } +} + +static void free_constant_buffer(struct d3dcompiler_shader_reflection_constant_buffer *cb) +{ + if (cb->variables) + { + unsigned int i; + + for (i = 0; i < cb->variable_count; ++i) + { + free_variable(&cb->variables[i]); + } + HeapFree(GetProcessHeap(), 0, cb->variables); + } + + HeapFree(GetProcessHeap(), 0, cb->name); +} + +static void reflection_cleanup(struct d3dcompiler_shader_reflection *ref) +{ + TRACE("Cleanup %p\n", ref); + + if (ref->isgn) + { + free_signature(ref->isgn); + HeapFree(GetProcessHeap(), 0, ref->isgn); + } + + if (ref->osgn) + { + free_signature(ref->osgn); + HeapFree(GetProcessHeap(), 0, ref->osgn); + } + + if (ref->pcsg) + { + free_signature(ref->pcsg); + HeapFree(GetProcessHeap(), 0, ref->pcsg); + } + + if (ref->constant_buffers) + { + unsigned int i; + + for (i = 0; i < ref->constant_buffer_count; ++i) + { + free_constant_buffer(&ref->constant_buffers[i]); + } + } + + wine_rb_destroy(&ref->types, d3dcompiler_shader_reflection_type_destroy, NULL); + HeapFree(GetProcessHeap(), 0, ref->constant_buffers); + HeapFree(GetProcessHeap(), 0, ref->bound_resources); + HeapFree(GetProcessHeap(), 0, ref->resource_string); + HeapFree(GetProcessHeap(), 0, ref->creator); +} + +/* IUnknown methods */ + +static inline struct d3dcompiler_shader_reflection *impl_from_ID3D11ShaderReflection(ID3D11ShaderReflection *iface) +{ + return CONTAINING_RECORD(iface, struct d3dcompiler_shader_reflection, ID3D11ShaderReflection_iface); +} + +static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_QueryInterface(ID3D11ShaderReflection *iface, REFIID riid, void **object) +{ + TRACE("iface %p, riid %s, object %p\n", iface, debugstr_guid(riid), object); + + if (IsEqualGUID(riid, &IID_ID3D11ShaderReflection) + || IsEqualGUID(riid, &IID_IUnknown)) + { + IUnknown_AddRef(iface); + *object = iface; + return S_OK; + } + + WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid)); + + *object = NULL; + return E_NOINTERFACE; +} + +static ULONG STDMETHODCALLTYPE d3dcompiler_shader_reflection_AddRef(ID3D11ShaderReflection *iface) +{ + struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface); + ULONG refcount = InterlockedIncrement(&This->refcount); + + TRACE("%p increasing refcount to %u\n", This, refcount); + + return refcount; +} + +static ULONG STDMETHODCALLTYPE d3dcompiler_shader_reflection_Release(ID3D11ShaderReflection *iface) +{ + struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface); + ULONG refcount = InterlockedDecrement(&This->refcount); + + TRACE("%p decreasing refcount to %u\n", This, refcount); + + if (!refcount) + { + reflection_cleanup(This); + HeapFree(GetProcessHeap(), 0, This); + } + + return refcount; +} + +/* ID3D11ShaderReflection methods */ + +static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetDesc(ID3D11ShaderReflection *iface, D3D11_SHADER_DESC *desc) +{ + struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface); + + FIXME("iface %p, desc %p partial stub!\n", iface, desc); + + if (!desc) + { + WARN("Invalid argument specified\n"); + return E_FAIL; + } + + desc->Version = This->version; + desc->Creator = This->creator; + desc->Flags = This->flags; + desc->ConstantBuffers = This->constant_buffer_count; + desc->BoundResources = This->bound_resource_count; + desc->InputParameters = This->isgn ? This->isgn->element_count : 0; + desc->OutputParameters = This->osgn ? This->osgn->element_count : 0; + desc->InstructionCount = This->instruction_count; + desc->TempRegisterCount = This->temp_register_count; + desc->TempArrayCount = This->temp_array_count; + desc->DefCount = 0; + desc->DclCount = This->dcl_count; + desc->TextureNormalInstructions = This->texture_normal_instructions; + desc->TextureLoadInstructions = This->texture_load_instructions; + desc->TextureCompInstructions = This->texture_comp_instructions; + desc->TextureBiasInstructions = This->texture_bias_instructions; + desc->TextureGradientInstructions = This->texture_gradient_instructions; + desc->FloatInstructionCount = This->float_instruction_count; + desc->IntInstructionCount = This->int_instruction_count; + desc->UintInstructionCount = This->uint_instruction_count; + desc->StaticFlowControlCount = This->static_flow_control_count; + desc->DynamicFlowControlCount = This->dynamic_flow_control_count; + desc->MacroInstructionCount = 0; + desc->ArrayInstructionCount = This->array_instruction_count; + desc->CutInstructionCount = This->cut_instruction_count; + desc->EmitInstructionCount = This->emit_instruction_count; + desc->GSOutputTopology = This->gs_output_topology; + desc->GSMaxOutputVertexCount = This->gs_max_output_vertex_count; + desc->InputPrimitive = This->input_primitive; + desc->PatchConstantParameters = This->pcsg ? This->pcsg->element_count : 0; + desc->cGSInstanceCount = 0; + desc->cControlPoints = This->c_control_points; + desc->HSOutputPrimitive = This->hs_output_primitive; + desc->HSPartitioning = This->hs_prtitioning; + desc->TessellatorDomain = This->tessellator_domain; + desc->cBarrierInstructions = 0; + desc->cInterlockedInstructions = 0; + desc->cTextureStoreInstructions = 0; + + return S_OK; +} + +static struct ID3D11ShaderReflectionConstantBuffer * STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetConstantBufferByIndex( + ID3D11ShaderReflection *iface, UINT index) +{ + struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface); + + TRACE("iface %p, index %u\n", iface, index); + + if (index >= This->constant_buffer_count) + { + WARN("Invalid argument specified\n"); + return &null_constant_buffer.ID3D11ShaderReflectionConstantBuffer_iface; + } + + return &This->constant_buffers[index].ID3D11ShaderReflectionConstantBuffer_iface; +} + +static struct ID3D11ShaderReflectionConstantBuffer * STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetConstantBufferByName( + ID3D11ShaderReflection *iface, LPCSTR name) +{ + struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface); + unsigned int i; + + TRACE("iface %p, name %s\n", iface, debugstr_a(name)); + + if (!name) + { + WARN("Invalid argument specified\n"); + return &null_constant_buffer.ID3D11ShaderReflectionConstantBuffer_iface; + } + + for (i = 0; i < This->constant_buffer_count; ++i) + { + struct d3dcompiler_shader_reflection_constant_buffer *d = &This->constant_buffers[i]; + + if (!strcmp(d->name, name)) + { + TRACE("Returning ID3D11ShaderReflectionConstantBuffer %p.\n", d); + return &d->ID3D11ShaderReflectionConstantBuffer_iface; + } + } + + WARN("Invalid name specified\n"); + + return &null_constant_buffer.ID3D11ShaderReflectionConstantBuffer_iface; +} + +static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetResourceBindingDesc( + ID3D11ShaderReflection *iface, UINT index, D3D11_SHADER_INPUT_BIND_DESC *desc) +{ + struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface); + + TRACE("iface %p, index %u, desc %p\n", iface, index, desc); + + if (!desc || index >= This->bound_resource_count) + { + WARN("Invalid argument specified\n"); + return E_INVALIDARG; + } + + *desc = This->bound_resources[index]; + + return S_OK; +} + +static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetInputParameterDesc( + ID3D11ShaderReflection *iface, UINT index, D3D11_SIGNATURE_PARAMETER_DESC *desc) +{ + struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface); + + TRACE("iface %p, index %u, desc %p\n", iface, index, desc); + + if (!desc || !This->isgn || index >= This->isgn->element_count) + { + WARN("Invalid argument specified\n"); + return E_INVALIDARG; + } + + *desc = This->isgn->elements[index]; + + return S_OK; +} + +static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetOutputParameterDesc( + ID3D11ShaderReflection *iface, UINT index, D3D11_SIGNATURE_PARAMETER_DESC *desc) +{ + struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface); + + TRACE("iface %p, index %u, desc %p\n", iface, index, desc); + + if (!desc || !This->osgn || index >= This->osgn->element_count) + { + WARN("Invalid argument specified\n"); + return E_INVALIDARG; + } + + *desc = This->osgn->elements[index]; + + return S_OK; +} + +static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetPatchConstantParameterDesc( + ID3D11ShaderReflection *iface, UINT index, D3D11_SIGNATURE_PARAMETER_DESC *desc) +{ + struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface); + + TRACE("iface %p, index %u, desc %p\n", iface, index, desc); + + if (!desc || !This->pcsg || index >= This->pcsg->element_count) + { + WARN("Invalid argument specified\n"); + return E_INVALIDARG; + } + + *desc = This->pcsg->elements[index]; + + return S_OK; +} + +static struct ID3D11ShaderReflectionVariable * STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetVariableByName( + ID3D11ShaderReflection *iface, LPCSTR name) +{ + struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface); + unsigned int i, k; + + TRACE("iface %p, name %s\n", iface, debugstr_a(name)); + + if (!name) + { + WARN("Invalid name specified\n"); + return &null_variable.ID3D11ShaderReflectionVariable_iface; + } + + for (i = 0; i < This->constant_buffer_count; ++i) + { + struct d3dcompiler_shader_reflection_constant_buffer *cb = &This->constant_buffers[i]; + + for (k = 0; k < cb->variable_count; ++k) + { + struct d3dcompiler_shader_reflection_variable *v = &cb->variables[k]; + + if (!strcmp(v->name, name)) + { + TRACE("Returning ID3D11ShaderReflectionVariable %p.\n", v); + return &v->ID3D11ShaderReflectionVariable_iface; + } + } + } + + WARN("Invalid name specified\n"); + + return &null_variable.ID3D11ShaderReflectionVariable_iface; +} + +static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetResourceBindingDescByName( + ID3D11ShaderReflection *iface, LPCSTR name, D3D11_SHADER_INPUT_BIND_DESC *desc) +{ + struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface); + unsigned int i; + + TRACE("iface %p, name %s, desc %p\n", iface, debugstr_a(name), desc); + + if (!desc || !name) + { + WARN("Invalid argument specified\n"); + return E_INVALIDARG; + } + + for (i = 0; i < This->bound_resource_count; ++i) + { + D3D11_SHADER_INPUT_BIND_DESC *d = &This->bound_resources[i]; + + if (!strcmp(d->Name, name)) + { + TRACE("Returning D3D11_SHADER_INPUT_BIND_DESC %p.\n", d); + *desc = *d; + return S_OK; + } + } + + WARN("Invalid name specified\n"); + + return E_INVALIDARG; +} + +static UINT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetMovInstructionCount( + ID3D11ShaderReflection *iface) +{ + struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface); + + TRACE("iface %p\n", iface); + + return This->mov_instruction_count; +} + +static UINT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetMovcInstructionCount( + ID3D11ShaderReflection *iface) +{ + FIXME("iface %p stub!\n", iface); + + return 0; +} + +static UINT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetConversionInstructionCount( + ID3D11ShaderReflection *iface) +{ + struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface); + + TRACE("iface %p\n", iface); + + return This->conversion_instruction_count; +} + +static UINT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetBitwiseInstructionCount( + ID3D11ShaderReflection *iface) +{ + FIXME("iface %p stub!\n", iface); + + return 0; +} + +static D3D_PRIMITIVE STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetGSInputPrimitive( + ID3D11ShaderReflection *iface) +{ + FIXME("iface %p stub!\n", iface); + + return 0; +} + +static BOOL STDMETHODCALLTYPE d3dcompiler_shader_reflection_IsSampleFrequencyShader( + ID3D11ShaderReflection *iface) +{ + FIXME("iface %p stub!\n", iface); + + return 0; +} + +static UINT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetNumInterfaceSlots( + ID3D11ShaderReflection *iface) +{ + FIXME("iface %p stub!\n", iface); + + return 0; +} + +static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetMinFeatureLevel( + ID3D11ShaderReflection *iface, D3D_FEATURE_LEVEL *level) +{ + FIXME("iface %p, level %p stub!\n", iface, level); + + return E_NOTIMPL; +} + +static UINT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetThreadGroupSize( + ID3D11ShaderReflection *iface, UINT *sizex, UINT *sizey, UINT *sizez) +{ + FIXME("iface %p, sizex %p, sizey %p, sizez %p stub!\n", iface, sizex, sizey, sizez); + + return 0; +} + +static const struct ID3D11ShaderReflectionVtbl d3dcompiler_shader_reflection_vtbl = +{ + /* IUnknown methods */ + d3dcompiler_shader_reflection_QueryInterface, + d3dcompiler_shader_reflection_AddRef, + d3dcompiler_shader_reflection_Release, + /* ID3D11ShaderReflection methods */ + d3dcompiler_shader_reflection_GetDesc, + d3dcompiler_shader_reflection_GetConstantBufferByIndex, + d3dcompiler_shader_reflection_GetConstantBufferByName, + d3dcompiler_shader_reflection_GetResourceBindingDesc, + d3dcompiler_shader_reflection_GetInputParameterDesc, + d3dcompiler_shader_reflection_GetOutputParameterDesc, + d3dcompiler_shader_reflection_GetPatchConstantParameterDesc, + d3dcompiler_shader_reflection_GetVariableByName, + d3dcompiler_shader_reflection_GetResourceBindingDescByName, + d3dcompiler_shader_reflection_GetMovInstructionCount, + d3dcompiler_shader_reflection_GetMovcInstructionCount, + d3dcompiler_shader_reflection_GetConversionInstructionCount, + d3dcompiler_shader_reflection_GetBitwiseInstructionCount, + d3dcompiler_shader_reflection_GetGSInputPrimitive, + d3dcompiler_shader_reflection_IsSampleFrequencyShader, + d3dcompiler_shader_reflection_GetNumInterfaceSlots, + d3dcompiler_shader_reflection_GetMinFeatureLevel, + d3dcompiler_shader_reflection_GetThreadGroupSize, +}; + +/* ID3D11ShaderReflectionConstantBuffer methods */ + +static inline struct d3dcompiler_shader_reflection_constant_buffer *impl_from_ID3D11ShaderReflectionConstantBuffer(ID3D11ShaderReflectionConstantBuffer *iface) +{ + return CONTAINING_RECORD(iface, struct d3dcompiler_shader_reflection_constant_buffer, ID3D11ShaderReflectionConstantBuffer_iface); +} + +static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_constant_buffer_GetDesc( + ID3D11ShaderReflectionConstantBuffer *iface, D3D11_SHADER_BUFFER_DESC *desc) +{ + struct d3dcompiler_shader_reflection_constant_buffer *This = impl_from_ID3D11ShaderReflectionConstantBuffer(iface); + + TRACE("iface %p, desc %p\n", iface, desc); + + if (This == &null_constant_buffer) + { + WARN("Null constant buffer specified\n"); + return E_FAIL; + } + + if (!desc) + { + WARN("Invalid argument specified\n"); + return E_FAIL; + } + + desc->Name = This->name; + desc->Type = This->type; + desc->Variables = This->variable_count; + desc->Size = This->size; + desc->uFlags = This->flags; + + return S_OK; +} + +static ID3D11ShaderReflectionVariable * STDMETHODCALLTYPE d3dcompiler_shader_reflection_constant_buffer_GetVariableByIndex( + ID3D11ShaderReflectionConstantBuffer *iface, UINT index) +{ + struct d3dcompiler_shader_reflection_constant_buffer *This = impl_from_ID3D11ShaderReflectionConstantBuffer(iface); + + TRACE("iface %p, index %u\n", iface, index); + + if (index >= This->variable_count) + { + WARN("Invalid index specified\n"); + return &null_variable.ID3D11ShaderReflectionVariable_iface; + } + + return &This->variables[index].ID3D11ShaderReflectionVariable_iface; +} + +static ID3D11ShaderReflectionVariable * STDMETHODCALLTYPE d3dcompiler_shader_reflection_constant_buffer_GetVariableByName( + ID3D11ShaderReflectionConstantBuffer *iface, LPCSTR name) +{ + struct d3dcompiler_shader_reflection_constant_buffer *This = impl_from_ID3D11ShaderReflectionConstantBuffer(iface); + unsigned int i; + + TRACE("iface %p, name %s\n", iface, debugstr_a(name)); + + if (!name) + { + WARN("Invalid argument specified\n"); + return &null_variable.ID3D11ShaderReflectionVariable_iface; + } + + for (i = 0; i < This->variable_count; ++i) + { + struct d3dcompiler_shader_reflection_variable *v = &This->variables[i]; + + if (!strcmp(v->name, name)) + { + TRACE("Returning ID3D11ShaderReflectionVariable %p.\n", v); + return &v->ID3D11ShaderReflectionVariable_iface; + } + } + + WARN("Invalid name specified\n"); + + return &null_variable.ID3D11ShaderReflectionVariable_iface; +} + +static const struct ID3D11ShaderReflectionConstantBufferVtbl d3dcompiler_shader_reflection_constant_buffer_vtbl = +{ + /* ID3D11ShaderReflectionConstantBuffer methods */ + d3dcompiler_shader_reflection_constant_buffer_GetDesc, + d3dcompiler_shader_reflection_constant_buffer_GetVariableByIndex, + d3dcompiler_shader_reflection_constant_buffer_GetVariableByName, +}; + +/* ID3D11ShaderReflectionVariable methods */ + +static inline struct d3dcompiler_shader_reflection_variable *impl_from_ID3D11ShaderReflectionVariable(ID3D11ShaderReflectionVariable *iface) +{ + return CONTAINING_RECORD(iface, struct d3dcompiler_shader_reflection_variable, ID3D11ShaderReflectionVariable_iface); +} + +static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_variable_GetDesc( + ID3D11ShaderReflectionVariable *iface, D3D11_SHADER_VARIABLE_DESC *desc) +{ + struct d3dcompiler_shader_reflection_variable *This = impl_from_ID3D11ShaderReflectionVariable(iface); + + TRACE("iface %p, desc %p\n", iface, desc); + + if (This == &null_variable) + { + WARN("Null variable specified\n"); + return E_FAIL; + } + + if (!desc) + { + WARN("Invalid argument specified\n"); + return E_FAIL; + } + + desc->Name = This->name; + desc->StartOffset = This->start_offset; + desc->Size = This->size; + desc->uFlags = This->flags; + desc->DefaultValue = This->default_value; + + return S_OK; +} + +static ID3D11ShaderReflectionType * STDMETHODCALLTYPE d3dcompiler_shader_reflection_variable_GetType( + ID3D11ShaderReflectionVariable *iface) +{ + struct d3dcompiler_shader_reflection_variable *This = impl_from_ID3D11ShaderReflectionVariable(iface); + + TRACE("iface %p\n", iface); + + return &This->type->ID3D11ShaderReflectionType_iface; +} + +static ID3D11ShaderReflectionConstantBuffer * STDMETHODCALLTYPE d3dcompiler_shader_reflection_variable_GetBuffer( + ID3D11ShaderReflectionVariable *iface) +{ + struct d3dcompiler_shader_reflection_variable *This = impl_from_ID3D11ShaderReflectionVariable(iface); + + TRACE("iface %p\n", iface); + + return &This->constant_buffer->ID3D11ShaderReflectionConstantBuffer_iface; +} + +static UINT STDMETHODCALLTYPE d3dcompiler_shader_reflection_variable_GetInterfaceSlot( + ID3D11ShaderReflectionVariable *iface, UINT index) +{ + FIXME("iface %p, index %u stub!\n", iface, index); + + return 0; +} + +static const struct ID3D11ShaderReflectionVariableVtbl d3dcompiler_shader_reflection_variable_vtbl = +{ + /* ID3D11ShaderReflectionVariable methods */ + d3dcompiler_shader_reflection_variable_GetDesc, + d3dcompiler_shader_reflection_variable_GetType, + d3dcompiler_shader_reflection_variable_GetBuffer, + d3dcompiler_shader_reflection_variable_GetInterfaceSlot, +}; + +/* ID3D11ShaderReflectionType methods */ + +static inline struct d3dcompiler_shader_reflection_type *impl_from_ID3D11ShaderReflectionType(ID3D11ShaderReflectionType *iface) +{ + return CONTAINING_RECORD(iface, struct d3dcompiler_shader_reflection_type, ID3D11ShaderReflectionType_iface); +} + +static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_GetDesc( + ID3D11ShaderReflectionType *iface, D3D11_SHADER_TYPE_DESC *desc) +{ + struct d3dcompiler_shader_reflection_type *This = impl_from_ID3D11ShaderReflectionType(iface); + + TRACE("iface %p, desc %p\n", iface, desc); + + if (This == &null_type) + { + WARN("Null type specified\n"); + return E_FAIL; + } + + if (!desc) + { + WARN("Invalid argument specified\n"); + return E_FAIL; + } + + *desc = This->desc; + + return S_OK; +} + +static ID3D11ShaderReflectionType * STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_GetMemberTypeByIndex( + ID3D11ShaderReflectionType *iface, UINT index) +{ + struct d3dcompiler_shader_reflection_type *This = impl_from_ID3D11ShaderReflectionType(iface); + + TRACE("iface %p, index %u\n", iface, index); + + if (index >= This->desc.Members) + { + WARN("Invalid index specified\n"); + return &null_type.ID3D11ShaderReflectionType_iface; + } + + return &This->members[index].type->ID3D11ShaderReflectionType_iface; +} + +static ID3D11ShaderReflectionType * STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_GetMemberTypeByName( + ID3D11ShaderReflectionType *iface, LPCSTR name) +{ + struct d3dcompiler_shader_reflection_type *This = impl_from_ID3D11ShaderReflectionType(iface); + unsigned int i; + + TRACE("iface %p, name %s\n", iface, debugstr_a(name)); + + if (!name) + { + WARN("Invalid argument specified\n"); + return &null_type.ID3D11ShaderReflectionType_iface; + } + + for (i = 0; i < This->desc.Members; ++i) + { + struct d3dcompiler_shader_reflection_type_member *member = &This->members[i]; + + if (!strcmp(member->name, name)) + { + TRACE("Returning ID3D11ShaderReflectionType %p.\n", member->type); + return &member->type->ID3D11ShaderReflectionType_iface; + } + } + + WARN("Invalid name specified\n"); + + return &null_type.ID3D11ShaderReflectionType_iface; +} + +static LPCSTR STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_GetMemberTypeName( + ID3D11ShaderReflectionType *iface, UINT index) +{ + struct d3dcompiler_shader_reflection_type *This = impl_from_ID3D11ShaderReflectionType(iface); + + TRACE("iface %p, index %u\n", iface, index); + + if (This == &null_type) + { + WARN("Null type specified\n"); + return "$Invalid"; + } + + if (index >= This->desc.Members) + { + WARN("Invalid index specified\n"); + return NULL; + } + + return This->members[index].name; +} + +static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_IsEqual( + ID3D11ShaderReflectionType *iface, ID3D11ShaderReflectionType *type) +{ + struct d3dcompiler_shader_reflection_type *This = impl_from_ID3D11ShaderReflectionType(iface); + + TRACE("iface %p, type %p\n", iface, type); + + if (This == &null_type) + { + WARN("Null type specified\n"); + return E_FAIL; + } + + if (iface == type) + return S_OK; + + return S_FALSE; +} + +static ID3D11ShaderReflectionType * STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_GetSubType( + ID3D11ShaderReflectionType *iface) +{ + FIXME("iface %p stub!\n", iface); + + return NULL; +} + +static ID3D11ShaderReflectionType * STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_GetBaseClass( + ID3D11ShaderReflectionType *iface) +{ + FIXME("iface %p stub!\n", iface); + + return NULL; +} + +static UINT STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_GetNumInterfaces( + ID3D11ShaderReflectionType *iface) +{ + FIXME("iface %p stub!\n", iface); + + return 0; +} + +static ID3D11ShaderReflectionType * STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_GetInterfaceByIndex( + ID3D11ShaderReflectionType *iface, UINT index) +{ + FIXME("iface %p, index %u stub!\n", iface, index); + + return NULL; +} + +static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_IsOfType( + ID3D11ShaderReflectionType *iface, ID3D11ShaderReflectionType *type) +{ + FIXME("iface %p, type %p stub!\n", iface, type); + + return E_NOTIMPL; +} + +static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_ImplementsInterface( + ID3D11ShaderReflectionType *iface, ID3D11ShaderReflectionType *base) +{ + FIXME("iface %p, base %p stub!\n", iface, base); + + return E_NOTIMPL; +} + +static const struct ID3D11ShaderReflectionTypeVtbl d3dcompiler_shader_reflection_type_vtbl = +{ + /* ID3D11ShaderReflectionType methods */ + d3dcompiler_shader_reflection_type_GetDesc, + d3dcompiler_shader_reflection_type_GetMemberTypeByIndex, + d3dcompiler_shader_reflection_type_GetMemberTypeByName, + d3dcompiler_shader_reflection_type_GetMemberTypeName, + d3dcompiler_shader_reflection_type_IsEqual, + d3dcompiler_shader_reflection_type_GetSubType, + d3dcompiler_shader_reflection_type_GetBaseClass, + d3dcompiler_shader_reflection_type_GetNumInterfaces, + d3dcompiler_shader_reflection_type_GetInterfaceByIndex, + d3dcompiler_shader_reflection_type_IsOfType, + d3dcompiler_shader_reflection_type_ImplementsInterface, +}; + +static HRESULT d3dcompiler_parse_stat(struct d3dcompiler_shader_reflection *r, const char *data, DWORD data_size) +{ + const char *ptr = data; + DWORD size = data_size >> 2; + + TRACE("Size %u\n", size); + + read_dword(&ptr, &r->instruction_count); + TRACE("InstructionCount: %u\n", r->instruction_count); + + read_dword(&ptr, &r->temp_register_count); + TRACE("TempRegisterCount: %u\n", r->temp_register_count); + + skip_dword_unknown(&ptr, 1); + + read_dword(&ptr, &r->dcl_count); + TRACE("DclCount: %u\n", r->dcl_count); + + read_dword(&ptr, &r->float_instruction_count); + TRACE("FloatInstructionCount: %u\n", r->float_instruction_count); + + read_dword(&ptr, &r->int_instruction_count); + TRACE("IntInstructionCount: %u\n", r->int_instruction_count); + + read_dword(&ptr, &r->uint_instruction_count); + TRACE("UintInstructionCount: %u\n", r->uint_instruction_count); + + read_dword(&ptr, &r->static_flow_control_count); + TRACE("StaticFlowControlCount: %u\n", r->static_flow_control_count); + + read_dword(&ptr, &r->dynamic_flow_control_count); + TRACE("DynamicFlowControlCount: %u\n", r->dynamic_flow_control_count); + + skip_dword_unknown(&ptr, 1); + + read_dword(&ptr, &r->temp_array_count); + TRACE("TempArrayCount: %u\n", r->temp_array_count); + + read_dword(&ptr, &r->array_instruction_count); + TRACE("ArrayInstructionCount: %u\n", r->array_instruction_count); + + read_dword(&ptr, &r->cut_instruction_count); + TRACE("CutInstructionCount: %u\n", r->cut_instruction_count); + + read_dword(&ptr, &r->emit_instruction_count); + TRACE("EmitInstructionCount: %u\n", r->emit_instruction_count); + + read_dword(&ptr, &r->texture_normal_instructions); + TRACE("TextureNormalInstructions: %u\n", r->texture_normal_instructions); + + read_dword(&ptr, &r->texture_load_instructions); + TRACE("TextureLoadInstructions: %u\n", r->texture_load_instructions); + + read_dword(&ptr, &r->texture_comp_instructions); + TRACE("TextureCompInstructions: %u\n", r->texture_comp_instructions); + + read_dword(&ptr, &r->texture_bias_instructions); + TRACE("TextureBiasInstructions: %u\n", r->texture_bias_instructions); + + read_dword(&ptr, &r->texture_gradient_instructions); + TRACE("TextureGradientInstructions: %u\n", r->texture_gradient_instructions); + + read_dword(&ptr, &r->mov_instruction_count); + TRACE("MovInstructionCount: %u\n", r->mov_instruction_count); + + skip_dword_unknown(&ptr, 1); + + read_dword(&ptr, &r->conversion_instruction_count); + TRACE("ConversionInstructionCount: %u\n", r->conversion_instruction_count); + + skip_dword_unknown(&ptr, 1); + + read_dword(&ptr, &r->input_primitive); + TRACE("InputPrimitive: %x\n", r->input_primitive); + + read_dword(&ptr, &r->gs_output_topology); + TRACE("GSOutputTopology: %x\n", r->gs_output_topology); + + read_dword(&ptr, &r->gs_max_output_vertex_count); + TRACE("GSMaxOutputVertexCount: %u\n", r->gs_max_output_vertex_count); + + skip_dword_unknown(&ptr, 3); + + /* dx10 stat size */ + if (size == 29) return S_OK; + + skip_dword_unknown(&ptr, 1); + + read_dword(&ptr, &r->c_control_points); + TRACE("cControlPoints: %u\n", r->c_control_points); + + read_dword(&ptr, &r->hs_output_primitive); + TRACE("HSOutputPrimitive: %x\n", r->hs_output_primitive); + + read_dword(&ptr, &r->hs_prtitioning); + TRACE("HSPartitioning: %x\n", r->hs_prtitioning); + + read_dword(&ptr, &r->tessellator_domain); + TRACE("TessellatorDomain: %x\n", r->tessellator_domain); + + skip_dword_unknown(&ptr, 3); + + /* dx11 stat size */ + if (size == 37) return S_OK; + + FIXME("Unhandled size %u\n", size); + + return E_FAIL; +} + +static HRESULT d3dcompiler_parse_type_members(struct d3dcompiler_shader_reflection *ref, + struct d3dcompiler_shader_reflection_type_member *member, const char *data, const char **ptr) +{ + DWORD offset; + + read_dword(ptr, &offset); + if (!copy_name(data + offset, &member->name)) + { + ERR("Failed to copy name.\n"); + return E_OUTOFMEMORY; + } + TRACE("Member name: %s.\n", debugstr_a(member->name)); + + read_dword(ptr, &offset); + TRACE("Member type offset: %x\n", offset); + + member->type = get_reflection_type(ref, data, offset); + if (!member->type) + { + ERR("Failed to get member type\n"); + HeapFree(GetProcessHeap(), 0, member->name); + return E_FAIL; + } + + read_dword(ptr, &member->offset); + TRACE("Member offset %x\n", member->offset); + + return S_OK; +} + +static HRESULT d3dcompiler_parse_type(struct d3dcompiler_shader_reflection_type *type, const char *data, DWORD offset) +{ + const char *ptr = data + offset; + DWORD temp; + D3D11_SHADER_TYPE_DESC *desc; + unsigned int i; + struct d3dcompiler_shader_reflection_type_member *members = NULL; + HRESULT hr; + DWORD member_offset; + + desc = &type->desc; + + read_dword(&ptr, &temp); + desc->Class = temp & 0xffff; + desc->Type = temp >> 16; + TRACE("Class %s, Type %s\n", debug_d3dcompiler_shader_variable_class(desc->Class), + debug_d3dcompiler_shader_variable_type(desc->Type)); + + read_dword(&ptr, &temp); + desc->Rows = temp & 0xffff; + desc->Columns = temp >> 16; + TRACE("Rows %u, Columns %u\n", desc->Rows, desc->Columns); + + read_dword(&ptr, &temp); + desc->Elements = temp & 0xffff; + desc->Members = temp >> 16; + TRACE("Elements %u, Members %u\n", desc->Elements, desc->Members); + + read_dword(&ptr, &member_offset); + TRACE("Member Offset %u\n", member_offset); + + if ((type->reflection->target & D3DCOMPILER_SHADER_TARGET_VERSION_MASK) >= 0x500) + skip_dword_unknown(&ptr, 4); + + if (desc->Members) + { + const char *ptr2 = data + member_offset; + + members = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*members) * desc->Members); + if (!members) + { + ERR("Failed to allocate type memory.\n"); + return E_OUTOFMEMORY; + } + + for (i = 0; i < desc->Members; ++i) + { + hr = d3dcompiler_parse_type_members(type->reflection, &members[i], data, &ptr2); + if (hr != S_OK) + { + FIXME("Failed to parse type members.\n"); + goto err_out; + } + } + } + + type->members = members; + + return S_OK; + +err_out: + for (i = 0; i < desc->Members; ++i) + { + free_type_member(&members[i]); + } + HeapFree(GetProcessHeap(), 0, members); + return hr; +} + +static struct d3dcompiler_shader_reflection_type *get_reflection_type(struct d3dcompiler_shader_reflection *reflection, const char *data, DWORD offset) +{ + struct d3dcompiler_shader_reflection_type *type; + struct wine_rb_entry *entry; + HRESULT hr; + + entry = wine_rb_get(&reflection->types, &offset); + if (entry) + { + TRACE("Returning existing type.\n"); + return WINE_RB_ENTRY_VALUE(entry, struct d3dcompiler_shader_reflection_type, entry); + } + + type = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*type)); + if (!type) + return NULL; + + type->ID3D11ShaderReflectionType_iface.lpVtbl = &d3dcompiler_shader_reflection_type_vtbl; + type->id = offset; + type->reflection = reflection; + + hr = d3dcompiler_parse_type(type, data, offset); + if (FAILED(hr)) + { + ERR("Failed to parse type info, hr %#x.\n", hr); + HeapFree(GetProcessHeap(), 0, type); + return NULL; + } + + if (wine_rb_put(&reflection->types, &offset, &type->entry) == -1) + { + ERR("Failed to insert type entry.\n"); + HeapFree(GetProcessHeap(), 0, type); + return NULL; + } + + return type; +} + +static HRESULT d3dcompiler_parse_variables(struct d3dcompiler_shader_reflection_constant_buffer *cb, + const char *data, DWORD data_size, const char *ptr) +{ + struct d3dcompiler_shader_reflection_variable *variables; + unsigned int i; + HRESULT hr; + + variables = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cb->variable_count * sizeof(*variables)); + if (!variables) + { + ERR("Failed to allocate variables memory.\n"); + return E_OUTOFMEMORY; + } + + for (i = 0; i < cb->variable_count; i++) + { + struct d3dcompiler_shader_reflection_variable *v = &variables[i]; + DWORD offset; + + v->ID3D11ShaderReflectionVariable_iface.lpVtbl = &d3dcompiler_shader_reflection_variable_vtbl; + v->constant_buffer = cb; + + read_dword(&ptr, &offset); + if (!copy_name(data + offset, &v->name)) + { + ERR("Failed to copy name.\n"); + hr = E_OUTOFMEMORY; + goto err_out; + } + TRACE("Variable name: %s.\n", debugstr_a(v->name)); + + read_dword(&ptr, &v->start_offset); + TRACE("Variable offset: %u\n", v->start_offset); + + read_dword(&ptr, &v->size); + TRACE("Variable size: %u\n", v->size); + + read_dword(&ptr, &v->flags); + TRACE("Variable flags: %u\n", v->flags); + + read_dword(&ptr, &offset); + TRACE("Variable type offset: %x\n", offset); + v->type = get_reflection_type(cb->reflection, data, offset); + if (!v->type) + { + ERR("Failed to get type.\n"); + hr = E_FAIL; + goto err_out; + } + + read_dword(&ptr, &offset); + TRACE("Variable default value offset: %x\n", offset); + if (!copy_value(data + offset, &v->default_value, offset ? v->size : 0)) + { + ERR("Failed to copy name.\n"); + hr = E_OUTOFMEMORY; + goto err_out; + } + + if ((cb->reflection->target & D3DCOMPILER_SHADER_TARGET_VERSION_MASK) >= 0x500) + skip_dword_unknown(&ptr, 4); + } + + cb->variables = variables; + + return S_OK; + +err_out: + for (i = 0; i < cb->variable_count; i++) + { + free_variable(&variables[i]); + } + HeapFree(GetProcessHeap(), 0, variables); + return hr; +} + +static HRESULT d3dcompiler_parse_rdef(struct d3dcompiler_shader_reflection *r, const char *data, DWORD data_size) +{ + const char *ptr = data; + DWORD size = data_size >> 2; + DWORD offset, cbuffer_offset, resource_offset, creator_offset; + unsigned int i, string_data_offset, string_data_size; + char *string_data = NULL, *creator = NULL; + D3D11_SHADER_INPUT_BIND_DESC *bound_resources = NULL; + struct d3dcompiler_shader_reflection_constant_buffer *constant_buffers = NULL; + HRESULT hr; + + TRACE("Size %u\n", size); + + read_dword(&ptr, &r->constant_buffer_count); + TRACE("Constant buffer count: %u\n", r->constant_buffer_count); + + read_dword(&ptr, &cbuffer_offset); + TRACE("Constant buffer offset: %#x\n", cbuffer_offset); + + read_dword(&ptr, &r->bound_resource_count); + TRACE("Bound resource count: %u\n", r->bound_resource_count); + + read_dword(&ptr, &resource_offset); + TRACE("Bound resource offset: %#x\n", resource_offset); + + read_dword(&ptr, &r->target); + TRACE("Target: %#x\n", r->target); + + read_dword(&ptr, &r->flags); + TRACE("Flags: %u\n", r->flags); + + read_dword(&ptr, &creator_offset); + TRACE("Creator at offset %#x.\n", creator_offset); + + if (!copy_name(data + creator_offset, &creator)) + { + ERR("Failed to copy name.\n"); + return E_OUTOFMEMORY; + } + TRACE("Creator: %s.\n", debugstr_a(creator)); + + /* todo: Parse RD11 */ + if ((r->target & D3DCOMPILER_SHADER_TARGET_VERSION_MASK) >= 0x500) + { + skip_dword_unknown(&ptr, 8); + } + + if (r->bound_resource_count) + { + /* 8 for each bind desc */ + string_data_offset = resource_offset + r->bound_resource_count * 8 * sizeof(DWORD); + string_data_size = (cbuffer_offset ? cbuffer_offset : creator_offset) - string_data_offset; + + string_data = HeapAlloc(GetProcessHeap(), 0, string_data_size); + if (!string_data) + { + ERR("Failed to allocate string data memory.\n"); + hr = E_OUTOFMEMORY; + goto err_out; + } + memcpy(string_data, data + string_data_offset, string_data_size); + + bound_resources = HeapAlloc(GetProcessHeap(), 0, r->bound_resource_count * sizeof(*bound_resources)); + if (!bound_resources) + { + ERR("Failed to allocate resources memory.\n"); + hr = E_OUTOFMEMORY; + goto err_out; + } + + ptr = data + resource_offset; + for (i = 0; i < r->bound_resource_count; i++) + { + D3D11_SHADER_INPUT_BIND_DESC *desc = &bound_resources[i]; + + read_dword(&ptr, &offset); + desc->Name = string_data + (offset - string_data_offset); + TRACE("Input bind Name: %s\n", debugstr_a(desc->Name)); + + read_dword(&ptr, &desc->Type); + TRACE("Input bind Type: %#x\n", desc->Type); + + read_dword(&ptr, &desc->ReturnType); + TRACE("Input bind ReturnType: %#x\n", desc->ReturnType); + + read_dword(&ptr, &desc->Dimension); + TRACE("Input bind Dimension: %#x\n", desc->Dimension); + + read_dword(&ptr, &desc->NumSamples); + TRACE("Input bind NumSamples: %u\n", desc->NumSamples); + + read_dword(&ptr, &desc->BindPoint); + TRACE("Input bind BindPoint: %u\n", desc->BindPoint); + + read_dword(&ptr, &desc->BindCount); + TRACE("Input bind BindCount: %u\n", desc->BindCount); + + read_dword(&ptr, &desc->uFlags); + TRACE("Input bind uFlags: %u\n", desc->uFlags); + } + } + + if (r->constant_buffer_count) + { + constant_buffers = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, r->constant_buffer_count * sizeof(*constant_buffers)); + if (!constant_buffers) + { + ERR("Failed to allocate constant buffer memory.\n"); + hr = E_OUTOFMEMORY; + goto err_out; + } + + ptr = data + cbuffer_offset; + for (i = 0; i < r->constant_buffer_count; i++) + { + struct d3dcompiler_shader_reflection_constant_buffer *cb = &constant_buffers[i]; + + cb->ID3D11ShaderReflectionConstantBuffer_iface.lpVtbl = &d3dcompiler_shader_reflection_constant_buffer_vtbl; + cb->reflection = r; + + read_dword(&ptr, &offset); + if (!copy_name(data + offset, &cb->name)) + { + ERR("Failed to copy name.\n"); + hr = E_OUTOFMEMORY; + goto err_out; + } + TRACE("Name: %s.\n", debugstr_a(cb->name)); + + read_dword(&ptr, &cb->variable_count); + TRACE("Variable count: %u\n", cb->variable_count); + + read_dword(&ptr, &offset); + TRACE("Variable offset: %x\n", offset); + + hr = d3dcompiler_parse_variables(cb, data, data_size, data + offset); + if (hr != S_OK) + { + FIXME("Failed to parse variables.\n"); + goto err_out; + } + + read_dword(&ptr, &cb->size); + TRACE("Cbuffer size: %u\n", cb->size); + + read_dword(&ptr, &cb->flags); + TRACE("Cbuffer flags: %u\n", cb->flags); + + read_dword(&ptr, &cb->type); + TRACE("Cbuffer type: %#x\n", cb->type); + } + } + + r->creator = creator; + r->resource_string = string_data; + r->bound_resources = bound_resources; + r->constant_buffers = constant_buffers; + + return S_OK; + +err_out: + for (i = 0; i < r->constant_buffer_count; ++i) + { + free_constant_buffer(&constant_buffers[i]); + } + HeapFree(GetProcessHeap(), 0, constant_buffers); + HeapFree(GetProcessHeap(), 0, bound_resources); + HeapFree(GetProcessHeap(), 0, string_data); + HeapFree(GetProcessHeap(), 0, creator); + + return hr; +} + +static HRESULT d3dcompiler_parse_signature(struct d3dcompiler_shader_signature *s, struct dxbc_section *section, DWORD target) +{ + D3D11_SIGNATURE_PARAMETER_DESC *d; + unsigned int string_data_offset; + unsigned int string_data_size; + const char *ptr = section->data; + char *string_data; + unsigned int i; + DWORD count; + enum D3DCOMPILER_SIGNATURE_ELEMENT_SIZE element_size; + + switch (section->tag) + { + case TAG_OSG5: + element_size = D3DCOMPILER_SIGNATURE_ELEMENT_SIZE7; + break; + + case TAG_ISGN: + case TAG_OSGN: + case TAG_PCSG: + element_size = D3DCOMPILER_SIGNATURE_ELEMENT_SIZE6; + break; + + default: + FIXME("Unhandled section %s!\n", debugstr_an((const char *)§ion->tag, 4)); + element_size = D3DCOMPILER_SIGNATURE_ELEMENT_SIZE6; + break; + } + + read_dword(&ptr, &count); + TRACE("%u elements\n", count); + + skip_dword_unknown(&ptr, 1); + + d = HeapAlloc(GetProcessHeap(), 0, count * sizeof(*d)); + if (!d) + { + ERR("Failed to allocate signature memory.\n"); + return E_OUTOFMEMORY; + } + + /* 2 DWORDs for the header, element_size for each element. */ + string_data_offset = 2 * sizeof(DWORD) + count * element_size * sizeof(DWORD); + string_data_size = section->data_size - string_data_offset; + + string_data = HeapAlloc(GetProcessHeap(), 0, string_data_size); + if (!string_data) + { + ERR("Failed to allocate string data memory.\n"); + HeapFree(GetProcessHeap(), 0, d); + return E_OUTOFMEMORY; + } + memcpy(string_data, section->data + string_data_offset, string_data_size); + + for (i = 0; i < count; ++i) + { + UINT name_offset; + DWORD mask; + + if (element_size == D3DCOMPILER_SIGNATURE_ELEMENT_SIZE7) + { + read_dword(&ptr, &d[i].Stream); + } + else + { + d[i].Stream = 0; + } + + read_dword(&ptr, &name_offset); + d[i].SemanticName = string_data + (name_offset - string_data_offset); + read_dword(&ptr, &d[i].SemanticIndex); + read_dword(&ptr, &d[i].SystemValueType); + read_dword(&ptr, &d[i].ComponentType); + read_dword(&ptr, &d[i].Register); + read_dword(&ptr, &mask); + d[i].ReadWriteMask = (mask >> 8) & 0xff; + d[i].Mask = mask & 0xff; + + /* pixel shaders have a special handling for SystemValueType in the output signature */ + if (((target & D3DCOMPILER_SHADER_TARGET_SHADERTYPE_MASK) == 0xffff0000) && (section->tag == TAG_OSG5 || section->tag == TAG_OSGN)) + { + TRACE("Pixelshader output signature fixup.\n"); + + if (d[i].Register == 0xffffffff) + { + if (!strcasecmp(d[i].SemanticName, "sv_depth")) d[i].SystemValueType = D3D_NAME_DEPTH; + if (!strcasecmp(d[i].SemanticName, "sv_coverage")) d[i].SystemValueType = D3D_NAME_COVERAGE; + if (!strcasecmp(d[i].SemanticName, "sv_depthgreaterequal")) d[i].SystemValueType = D3D_NAME_DEPTH_GREATER_EQUAL; + if (!strcasecmp(d[i].SemanticName, "sv_depthlessequal")) d[i].SystemValueType = D3D_NAME_DEPTH_LESS_EQUAL; + } + else + { + d[i].SystemValueType = D3D_NAME_TARGET; + } + } + + TRACE("semantic: %s, semantic idx: %u, sysval_semantic %#x, " + "type %u, register idx: %u, use_mask %#x, input_mask %#x, stream %u\n", + debugstr_a(d[i].SemanticName), d[i].SemanticIndex, d[i].SystemValueType, + d[i].ComponentType, d[i].Register, d[i].Mask, d[i].ReadWriteMask, d[i].Stream); + } + + s->elements = d; + s->element_count = count; + s->string_data = string_data; + + return S_OK; +} + +static HRESULT d3dcompiler_parse_shdr(struct d3dcompiler_shader_reflection *r, const char *data, DWORD data_size) +{ + const char *ptr = data; + + read_dword(&ptr, &r->version); + TRACE("Shader version: %u\n", r->version); + + /* todo: Check if anything else is needed from the shdr or shex blob. */ + + return S_OK; +} + +static HRESULT d3dcompiler_shader_reflection_init(struct d3dcompiler_shader_reflection *reflection, + const void *data, SIZE_T data_size) +{ + struct dxbc src_dxbc; + HRESULT hr; + unsigned int i; + + reflection->ID3D11ShaderReflection_iface.lpVtbl = &d3dcompiler_shader_reflection_vtbl; + reflection->refcount = 1; + + if (wine_rb_init(&reflection->types, &d3dcompiler_shader_reflection_type_rb_functions) == -1) + { + ERR("Failed to initialize type rbtree.\n"); + return E_FAIL; + } + + hr = dxbc_parse(data, data_size, &src_dxbc); + if (FAILED(hr)) + { + WARN("Failed to parse reflection\n"); + return hr; + } + + for (i = 0; i < src_dxbc.count; ++i) + { + struct dxbc_section *section = &src_dxbc.sections[i]; + + switch (section->tag) + { + case TAG_RDEF: + hr = d3dcompiler_parse_rdef(reflection, section->data, section->data_size); + if (FAILED(hr)) + { + WARN("Failed to parse RDEF section.\n"); + goto err_out; + } + break; + + case TAG_ISGN: + reflection->isgn = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*reflection->isgn)); + if (!reflection->isgn) + { + ERR("Failed to allocate ISGN memory.\n"); + hr = E_OUTOFMEMORY; + goto err_out; + } + + hr = d3dcompiler_parse_signature(reflection->isgn, section, reflection->target); + if (FAILED(hr)) + { + WARN("Failed to parse section ISGN.\n"); + goto err_out; + } + break; + + case TAG_OSG5: + case TAG_OSGN: + reflection->osgn = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*reflection->osgn)); + if (!reflection->osgn) + { + ERR("Failed to allocate OSGN memory.\n"); + hr = E_OUTOFMEMORY; + goto err_out; + } + + hr = d3dcompiler_parse_signature(reflection->osgn, section, reflection->target); + if (FAILED(hr)) + { + WARN("Failed to parse section OSGN.\n"); + goto err_out; + } + break; + + case TAG_PCSG: + reflection->pcsg = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*reflection->pcsg)); + if (!reflection->pcsg) + { + ERR("Failed to allocate PCSG memory.\n"); + hr = E_OUTOFMEMORY; + goto err_out; + } + + hr = d3dcompiler_parse_signature(reflection->pcsg, section, reflection->target); + if (FAILED(hr)) + { + WARN("Failed to parse section PCSG.\n"); + goto err_out; + } + break; + + case TAG_SHEX: + case TAG_SHDR: + hr = d3dcompiler_parse_shdr(reflection, section->data, section->data_size); + if (FAILED(hr)) + { + WARN("Failed to parse SHDR section.\n"); + goto err_out; + } + break; + + case TAG_STAT: + hr = d3dcompiler_parse_stat(reflection, section->data, section->data_size); + if (FAILED(hr)) + { + WARN("Failed to parse section STAT.\n"); + goto err_out; + } + break; + + default: + FIXME("Unhandled section %s!\n", debugstr_an((const char *)§ion->tag, 4)); + break; + } + } + + dxbc_destroy(&src_dxbc); + + return hr; + +err_out: + reflection_cleanup(reflection); + dxbc_destroy(&src_dxbc); + + return hr; +} + +HRESULT WINAPI D3DReflect(const void *data, SIZE_T data_size, REFIID riid, void **reflector) +{ + struct d3dcompiler_shader_reflection *object; + HRESULT hr; + const DWORD *temp = data; + + TRACE("data %p, data_size %lu, riid %s, blob %p\n", data, data_size, debugstr_guid(riid), reflector); + + if (!data || data_size < 32) + { + WARN("Invalid argument supplied.\n"); + return D3DERR_INVALIDCALL; + } + + if (temp[6] != data_size) + { + WARN("Wrong size supplied.\n"); + return E_FAIL; + } + + if (!IsEqualGUID(riid, &IID_ID3D11ShaderReflection)) + { + WARN("Wrong riid %s, accept only %s!\n", debugstr_guid(riid), debugstr_guid(&IID_ID3D11ShaderReflection)); + return E_NOINTERFACE; + } + + object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object)); + if (!object) + return E_OUTOFMEMORY; + + hr = d3dcompiler_shader_reflection_init(object, data, data_size); + if (FAILED(hr)) + { + WARN("Failed to initialize shader reflection\n"); + HeapFree(GetProcessHeap(), 0, object); + return hr; + } + + *reflector = object; + + TRACE("Created ID3D11ShaderReflection %p\n", object); + + return S_OK; +} diff --git a/reactos/dll/directx/wine/d3dcompiler_43/utils.c b/reactos/dll/directx/wine/d3dcompiler_43/utils.c new file mode 100644 index 00000000000..0f61f61746b --- /dev/null +++ b/reactos/dll/directx/wine/d3dcompiler_43/utils.c @@ -0,0 +1,2538 @@ +/* + * Copyright 2008 Stefan Dösinger + * Copyright 2009 Matteo Bruni + * Copyright 2008-2009 Henri Verbeet for CodeWeavers + * Copyright 2010 Rico Schüller + * 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 + +#include "d3dcompiler_private.h" + +WINE_DEFAULT_DEBUG_CHANNEL(d3dcompiler); + +#define WINE_D3DCOMPILER_TO_STR(x) case x: return #x + +const char *debug_d3dcompiler_shader_variable_class(D3D_SHADER_VARIABLE_CLASS c) +{ + switch (c) + { + WINE_D3DCOMPILER_TO_STR(D3D_SVC_SCALAR); + WINE_D3DCOMPILER_TO_STR(D3D_SVC_VECTOR); + WINE_D3DCOMPILER_TO_STR(D3D_SVC_MATRIX_ROWS); + WINE_D3DCOMPILER_TO_STR(D3D_SVC_MATRIX_COLUMNS); + WINE_D3DCOMPILER_TO_STR(D3D_SVC_OBJECT); + WINE_D3DCOMPILER_TO_STR(D3D_SVC_STRUCT); + WINE_D3DCOMPILER_TO_STR(D3D_SVC_INTERFACE_CLASS); + WINE_D3DCOMPILER_TO_STR(D3D_SVC_INTERFACE_POINTER); + default: + FIXME("Unrecognized D3D_SHADER_VARIABLE_CLASS %#x.\n", c); + return "unrecognized"; + } +} + +const char *debug_d3dcompiler_shader_variable_type(D3D_SHADER_VARIABLE_TYPE t) +{ + switch (t) + { + WINE_D3DCOMPILER_TO_STR(D3D_SVT_VOID); + WINE_D3DCOMPILER_TO_STR(D3D_SVT_BOOL); + WINE_D3DCOMPILER_TO_STR(D3D_SVT_INT); + WINE_D3DCOMPILER_TO_STR(D3D_SVT_FLOAT); + WINE_D3DCOMPILER_TO_STR(D3D_SVT_STRING); + WINE_D3DCOMPILER_TO_STR(D3D_SVT_TEXTURE); + WINE_D3DCOMPILER_TO_STR(D3D_SVT_TEXTURE1D); + WINE_D3DCOMPILER_TO_STR(D3D_SVT_TEXTURE2D); + WINE_D3DCOMPILER_TO_STR(D3D_SVT_TEXTURE3D); + WINE_D3DCOMPILER_TO_STR(D3D_SVT_TEXTURECUBE); + WINE_D3DCOMPILER_TO_STR(D3D_SVT_SAMPLER); + WINE_D3DCOMPILER_TO_STR(D3D_SVT_PIXELSHADER); + WINE_D3DCOMPILER_TO_STR(D3D_SVT_VERTEXSHADER); + WINE_D3DCOMPILER_TO_STR(D3D_SVT_UINT); + WINE_D3DCOMPILER_TO_STR(D3D_SVT_UINT8); + WINE_D3DCOMPILER_TO_STR(D3D_SVT_GEOMETRYSHADER); + WINE_D3DCOMPILER_TO_STR(D3D_SVT_RASTERIZER); + WINE_D3DCOMPILER_TO_STR(D3D_SVT_DEPTHSTENCIL); + WINE_D3DCOMPILER_TO_STR(D3D_SVT_BLEND); + WINE_D3DCOMPILER_TO_STR(D3D_SVT_BUFFER); + WINE_D3DCOMPILER_TO_STR(D3D_SVT_CBUFFER); + WINE_D3DCOMPILER_TO_STR(D3D_SVT_TBUFFER); + WINE_D3DCOMPILER_TO_STR(D3D_SVT_TEXTURE1DARRAY); + WINE_D3DCOMPILER_TO_STR(D3D_SVT_TEXTURE2DARRAY); + WINE_D3DCOMPILER_TO_STR(D3D_SVT_RENDERTARGETVIEW); + WINE_D3DCOMPILER_TO_STR(D3D_SVT_DEPTHSTENCILVIEW); + WINE_D3DCOMPILER_TO_STR(D3D_SVT_TEXTURE2DMS); + WINE_D3DCOMPILER_TO_STR(D3D_SVT_TEXTURE2DMSARRAY); + WINE_D3DCOMPILER_TO_STR(D3D_SVT_TEXTURECUBEARRAY); + WINE_D3DCOMPILER_TO_STR(D3D_SVT_HULLSHADER); + WINE_D3DCOMPILER_TO_STR(D3D_SVT_DOMAINSHADER); + WINE_D3DCOMPILER_TO_STR(D3D_SVT_INTERFACE_POINTER); + WINE_D3DCOMPILER_TO_STR(D3D_SVT_COMPUTESHADER); + WINE_D3DCOMPILER_TO_STR(D3D_SVT_DOUBLE); + WINE_D3DCOMPILER_TO_STR(D3D_SVT_RWTEXTURE1D); + WINE_D3DCOMPILER_TO_STR(D3D_SVT_RWTEXTURE1DARRAY); + WINE_D3DCOMPILER_TO_STR(D3D_SVT_RWTEXTURE2D); + WINE_D3DCOMPILER_TO_STR(D3D_SVT_RWTEXTURE2DARRAY); + WINE_D3DCOMPILER_TO_STR(D3D_SVT_RWTEXTURE3D); + WINE_D3DCOMPILER_TO_STR(D3D_SVT_RWBUFFER); + WINE_D3DCOMPILER_TO_STR(D3D_SVT_BYTEADDRESS_BUFFER); + WINE_D3DCOMPILER_TO_STR(D3D_SVT_RWBYTEADDRESS_BUFFER); + WINE_D3DCOMPILER_TO_STR(D3D_SVT_STRUCTURED_BUFFER); + WINE_D3DCOMPILER_TO_STR(D3D_SVT_RWSTRUCTURED_BUFFER); + WINE_D3DCOMPILER_TO_STR(D3D_SVT_APPEND_STRUCTURED_BUFFER); + WINE_D3DCOMPILER_TO_STR(D3D_SVT_CONSUME_STRUCTURED_BUFFER); + default: + FIXME("Unrecognized D3D_SHADER_VARIABLE_TYPE %#x.\n", t); + return "unrecognized"; + } +} + +const char *debug_d3dcompiler_d3d_blob_part(D3D_BLOB_PART part) +{ + switch(part) + { + WINE_D3DCOMPILER_TO_STR(D3D_BLOB_INPUT_SIGNATURE_BLOB); + WINE_D3DCOMPILER_TO_STR(D3D_BLOB_OUTPUT_SIGNATURE_BLOB); + WINE_D3DCOMPILER_TO_STR(D3D_BLOB_INPUT_AND_OUTPUT_SIGNATURE_BLOB); + WINE_D3DCOMPILER_TO_STR(D3D_BLOB_PATCH_CONSTANT_SIGNATURE_BLOB); + WINE_D3DCOMPILER_TO_STR(D3D_BLOB_ALL_SIGNATURE_BLOB); + WINE_D3DCOMPILER_TO_STR(D3D_BLOB_DEBUG_INFO); + WINE_D3DCOMPILER_TO_STR(D3D_BLOB_LEGACY_SHADER); + WINE_D3DCOMPILER_TO_STR(D3D_BLOB_XNA_PREPASS_SHADER); + WINE_D3DCOMPILER_TO_STR(D3D_BLOB_XNA_SHADER); + WINE_D3DCOMPILER_TO_STR(D3D_BLOB_TEST_ALTERNATE_SHADER); + WINE_D3DCOMPILER_TO_STR(D3D_BLOB_TEST_COMPILE_DETAILS); + WINE_D3DCOMPILER_TO_STR(D3D_BLOB_TEST_COMPILE_PERF); + default: + FIXME("Unrecognized D3D_BLOB_PART %#x\n", part); + return "unrecognized"; + } +} + +const char *debug_print_srcmod(DWORD mod) +{ + switch (mod) + { + WINE_D3DCOMPILER_TO_STR(BWRITERSPSM_NEG); + WINE_D3DCOMPILER_TO_STR(BWRITERSPSM_BIAS); + WINE_D3DCOMPILER_TO_STR(BWRITERSPSM_BIASNEG); + WINE_D3DCOMPILER_TO_STR(BWRITERSPSM_SIGN); + WINE_D3DCOMPILER_TO_STR(BWRITERSPSM_SIGNNEG); + WINE_D3DCOMPILER_TO_STR(BWRITERSPSM_COMP); + WINE_D3DCOMPILER_TO_STR(BWRITERSPSM_X2); + WINE_D3DCOMPILER_TO_STR(BWRITERSPSM_X2NEG); + WINE_D3DCOMPILER_TO_STR(BWRITERSPSM_DZ); + WINE_D3DCOMPILER_TO_STR(BWRITERSPSM_DW); + WINE_D3DCOMPILER_TO_STR(BWRITERSPSM_ABS); + WINE_D3DCOMPILER_TO_STR(BWRITERSPSM_ABSNEG); + WINE_D3DCOMPILER_TO_STR(BWRITERSPSM_NOT); + default: + FIXME("Unrecognized source modifier %#x.\n", mod); + return "unrecognized_src_mod"; + } +} + +#undef WINE_D3DCOMPILER_TO_STR + +const char *debug_print_dstmod(DWORD mod) +{ + switch (mod) + { + case 0: + return ""; + case BWRITERSPDM_SATURATE: + return "_sat"; + case BWRITERSPDM_PARTIALPRECISION: + return "_pp"; + case BWRITERSPDM_MSAMPCENTROID: + return "_centroid"; + case BWRITERSPDM_SATURATE | BWRITERSPDM_PARTIALPRECISION: + return "_sat_pp"; + case BWRITERSPDM_SATURATE | BWRITERSPDM_MSAMPCENTROID: + return "_sat_centroid"; + case BWRITERSPDM_PARTIALPRECISION | BWRITERSPDM_MSAMPCENTROID: + return "_pp_centroid"; + case BWRITERSPDM_SATURATE | BWRITERSPDM_PARTIALPRECISION | BWRITERSPDM_MSAMPCENTROID: + return "_sat_pp_centroid"; + default: + return "Unexpected modifier\n"; + } +} + +const char *debug_print_shift(DWORD shift) +{ + static const char * const shiftstrings[] = + { + "", + "_x2", + "_x4", + "_x8", + "_x16", + "_x32", + "", + "", + "", + "", + "", + "", + "_d16", + "_d8", + "_d4", + "_d2", + }; + return shiftstrings[shift]; +} + +static const char *get_regname(const struct shader_reg *reg) +{ + switch (reg->type) + { + case BWRITERSPR_TEMP: + return wine_dbg_sprintf("r%u", reg->regnum); + case BWRITERSPR_INPUT: + return wine_dbg_sprintf("v%u", reg->regnum); + case BWRITERSPR_CONST: + return wine_dbg_sprintf("c%u", reg->regnum); + case BWRITERSPR_ADDR: + return wine_dbg_sprintf("a%u", reg->regnum); + case BWRITERSPR_TEXTURE: + return wine_dbg_sprintf("t%u", reg->regnum); + case BWRITERSPR_RASTOUT: + switch (reg->regnum) + { + case BWRITERSRO_POSITION: return "oPos"; + case BWRITERSRO_FOG: return "oFog"; + case BWRITERSRO_POINT_SIZE: return "oPts"; + default: return "Unexpected RASTOUT"; + } + case BWRITERSPR_ATTROUT: + return wine_dbg_sprintf("oD%u", reg->regnum); + case BWRITERSPR_TEXCRDOUT: + return wine_dbg_sprintf("oT%u", reg->regnum); + case BWRITERSPR_OUTPUT: + return wine_dbg_sprintf("o%u", reg->regnum); + case BWRITERSPR_CONSTINT: + return wine_dbg_sprintf("i%u", reg->regnum); + case BWRITERSPR_COLOROUT: + return wine_dbg_sprintf("oC%u", reg->regnum); + case BWRITERSPR_DEPTHOUT: + return "oDepth"; + case BWRITERSPR_SAMPLER: + return wine_dbg_sprintf("s%u", reg->regnum); + case BWRITERSPR_CONSTBOOL: + return wine_dbg_sprintf("b%u", reg->regnum); + case BWRITERSPR_LOOP: + return "aL"; + case BWRITERSPR_MISCTYPE: + switch (reg->regnum) + { + case 0: return "vPos"; + case 1: return "vFace"; + default: return "unexpected misctype"; + } + case BWRITERSPR_LABEL: + return wine_dbg_sprintf("l%u", reg->regnum); + case BWRITERSPR_PREDICATE: + return wine_dbg_sprintf("p%u", reg->regnum); + default: + return wine_dbg_sprintf("unknown regname %#x", reg->type); + } +} + +static const char *debug_print_writemask(DWORD mask) +{ + char ret[6]; + unsigned char pos = 1; + + if(mask == BWRITERSP_WRITEMASK_ALL) return ""; + ret[0] = '.'; + if(mask & BWRITERSP_WRITEMASK_0) ret[pos++] = 'x'; + if(mask & BWRITERSP_WRITEMASK_1) ret[pos++] = 'y'; + if(mask & BWRITERSP_WRITEMASK_2) ret[pos++] = 'z'; + if(mask & BWRITERSP_WRITEMASK_3) ret[pos++] = 'w'; + ret[pos] = 0; + + return wine_dbg_sprintf("%s", ret); +} + +static const char *debug_print_swizzle(DWORD arg) +{ + char ret[6]; + unsigned int i; + DWORD swizzle[4]; + + switch (arg) + { + case BWRITERVS_NOSWIZZLE: + return ""; + case BWRITERVS_SWIZZLE_X: + return ".x"; + case BWRITERVS_SWIZZLE_Y: + return ".y"; + case BWRITERVS_SWIZZLE_Z: + return ".z"; + case BWRITERVS_SWIZZLE_W: + return ".w"; + } + + swizzle[0] = (arg >> (BWRITERVS_SWIZZLE_SHIFT + 0)) & 0x03; + swizzle[1] = (arg >> (BWRITERVS_SWIZZLE_SHIFT + 2)) & 0x03; + swizzle[2] = (arg >> (BWRITERVS_SWIZZLE_SHIFT + 4)) & 0x03; + swizzle[3] = (arg >> (BWRITERVS_SWIZZLE_SHIFT + 6)) & 0x03; + + ret[0] = '.'; + for (i = 0; i < 4; ++i) + { + switch (swizzle[i]) + { + case 0: ret[1 + i] = 'x'; break; + case 1: ret[1 + i] = 'y'; break; + case 2: ret[1 + i] = 'z'; break; + case 3: ret[1 + i] = 'w'; break; + } + } + ret[5] = '\0'; + + return wine_dbg_sprintf("%s", ret); +} + +static const char *debug_print_relarg(const struct shader_reg *reg) +{ + const char *short_swizzle; + if (!reg->rel_reg) return ""; + + short_swizzle = debug_print_swizzle(reg->rel_reg->u.swizzle); + + if (reg->rel_reg->type == BWRITERSPR_ADDR) + return wine_dbg_sprintf("[a%u%s]", reg->rel_reg->regnum, short_swizzle); + else if(reg->rel_reg->type == BWRITERSPR_LOOP && reg->rel_reg->regnum == 0) + return wine_dbg_sprintf("[aL%s]", short_swizzle); + else + return "Unexpected relative addressing argument"; +} + +const char *debug_print_dstreg(const struct shader_reg *reg) +{ + return wine_dbg_sprintf("%s%s%s", get_regname(reg), + debug_print_relarg(reg), + debug_print_writemask(reg->u.writemask)); +} + +const char *debug_print_srcreg(const struct shader_reg *reg) +{ + switch (reg->srcmod) + { + case BWRITERSPSM_NONE: + return wine_dbg_sprintf("%s%s%s", get_regname(reg), + debug_print_relarg(reg), + debug_print_swizzle(reg->u.swizzle)); + case BWRITERSPSM_NEG: + return wine_dbg_sprintf("-%s%s%s", get_regname(reg), + debug_print_relarg(reg), + debug_print_swizzle(reg->u.swizzle)); + case BWRITERSPSM_BIAS: + return wine_dbg_sprintf("%s%s_bias%s", get_regname(reg), + debug_print_relarg(reg), + debug_print_swizzle(reg->u.swizzle)); + case BWRITERSPSM_BIASNEG: + return wine_dbg_sprintf("-%s%s_bias%s", get_regname(reg), + debug_print_relarg(reg), + debug_print_swizzle(reg->u.swizzle)); + case BWRITERSPSM_SIGN: + return wine_dbg_sprintf("%s%s_bx2%s", get_regname(reg), + debug_print_relarg(reg), + debug_print_swizzle(reg->u.swizzle)); + case BWRITERSPSM_SIGNNEG: + return wine_dbg_sprintf("-%s%s_bx2%s", get_regname(reg), + debug_print_relarg(reg), + debug_print_swizzle(reg->u.swizzle)); + case BWRITERSPSM_COMP: + return wine_dbg_sprintf("1 - %s%s%s", get_regname(reg), + debug_print_relarg(reg), + debug_print_swizzle(reg->u.swizzle)); + case BWRITERSPSM_X2: + return wine_dbg_sprintf("%s%s_x2%s", get_regname(reg), + debug_print_relarg(reg), + debug_print_swizzle(reg->u.swizzle)); + case BWRITERSPSM_X2NEG: + return wine_dbg_sprintf("-%s%s_x2%s", get_regname(reg), + debug_print_relarg(reg), + debug_print_swizzle(reg->u.swizzle)); + case BWRITERSPSM_DZ: + return wine_dbg_sprintf("%s%s_dz%s", get_regname(reg), + debug_print_relarg(reg), + debug_print_swizzle(reg->u.swizzle)); + case BWRITERSPSM_DW: + return wine_dbg_sprintf("%s%s_dw%s", get_regname(reg), + debug_print_relarg(reg), + debug_print_swizzle(reg->u.swizzle)); + case BWRITERSPSM_ABS: + return wine_dbg_sprintf("%s%s_abs%s", get_regname(reg), + debug_print_relarg(reg), + debug_print_swizzle(reg->u.swizzle)); + case BWRITERSPSM_ABSNEG: + return wine_dbg_sprintf("-%s%s_abs%s", get_regname(reg), + debug_print_relarg(reg), + debug_print_swizzle(reg->u.swizzle)); + case BWRITERSPSM_NOT: + return wine_dbg_sprintf("!%s%s%s", get_regname(reg), + debug_print_relarg(reg), + debug_print_swizzle(reg->u.swizzle)); + } + return "Unknown modifier"; +} + +const char *debug_print_comp(DWORD comp) +{ + switch (comp) + { + case BWRITER_COMPARISON_NONE: return ""; + case BWRITER_COMPARISON_GT: return "_gt"; + case BWRITER_COMPARISON_EQ: return "_eq"; + case BWRITER_COMPARISON_GE: return "_ge"; + case BWRITER_COMPARISON_LT: return "_lt"; + case BWRITER_COMPARISON_NE: return "_ne"; + case BWRITER_COMPARISON_LE: return "_le"; + default: return "_unknown"; + } +} + +const char *debug_print_opcode(DWORD opcode) +{ + switch (opcode) + { + case BWRITERSIO_NOP: return "nop"; + case BWRITERSIO_MOV: return "mov"; + case BWRITERSIO_ADD: return "add"; + case BWRITERSIO_SUB: return "sub"; + case BWRITERSIO_MAD: return "mad"; + case BWRITERSIO_MUL: return "mul"; + case BWRITERSIO_RCP: return "rcp"; + case BWRITERSIO_RSQ: return "rsq"; + case BWRITERSIO_DP3: return "dp3"; + case BWRITERSIO_DP4: return "dp4"; + case BWRITERSIO_MIN: return "min"; + case BWRITERSIO_MAX: return "max"; + case BWRITERSIO_SLT: return "slt"; + case BWRITERSIO_SGE: return "sge"; + case BWRITERSIO_EXP: return "exp"; + case BWRITERSIO_LOG: return "log"; + case BWRITERSIO_LIT: return "lit"; + case BWRITERSIO_DST: return "dst"; + case BWRITERSIO_LRP: return "lrp"; + case BWRITERSIO_FRC: return "frc"; + case BWRITERSIO_M4x4: return "m4x4"; + case BWRITERSIO_M4x3: return "m4x3"; + case BWRITERSIO_M3x4: return "m3x4"; + case BWRITERSIO_M3x3: return "m3x3"; + case BWRITERSIO_M3x2: return "m3x2"; + case BWRITERSIO_CALL: return "call"; + case BWRITERSIO_CALLNZ: return "callnz"; + case BWRITERSIO_LOOP: return "loop"; + case BWRITERSIO_RET: return "ret"; + case BWRITERSIO_ENDLOOP: return "endloop"; + case BWRITERSIO_LABEL: return "label"; + case BWRITERSIO_DCL: return "dcl"; + case BWRITERSIO_POW: return "pow"; + case BWRITERSIO_CRS: return "crs"; + case BWRITERSIO_SGN: return "sgn"; + case BWRITERSIO_ABS: return "abs"; + case BWRITERSIO_NRM: return "nrm"; + case BWRITERSIO_SINCOS: return "sincos"; + case BWRITERSIO_REP: return "rep"; + case BWRITERSIO_ENDREP: return "endrep"; + case BWRITERSIO_IF: return "if"; + case BWRITERSIO_IFC: return "ifc"; + case BWRITERSIO_ELSE: return "else"; + case BWRITERSIO_ENDIF: return "endif"; + case BWRITERSIO_BREAK: return "break"; + case BWRITERSIO_BREAKC: return "breakc"; + case BWRITERSIO_MOVA: return "mova"; + case BWRITERSIO_DEFB: return "defb"; + case BWRITERSIO_DEFI: return "defi"; + case BWRITERSIO_TEXCOORD: return "texcoord"; + case BWRITERSIO_TEXKILL: return "texkill"; + case BWRITERSIO_TEX: return "tex"; + case BWRITERSIO_TEXBEM: return "texbem"; + case BWRITERSIO_TEXBEML: return "texbeml"; + case BWRITERSIO_TEXREG2AR: return "texreg2ar"; + case BWRITERSIO_TEXREG2GB: return "texreg2gb"; + case BWRITERSIO_TEXM3x2PAD: return "texm3x2pad"; + case BWRITERSIO_TEXM3x2TEX: return "texm3x2tex"; + case BWRITERSIO_TEXM3x3PAD: return "texm3x3pad"; + case BWRITERSIO_TEXM3x3TEX: return "texm3x3tex"; + case BWRITERSIO_TEXM3x3SPEC: return "texm3x3vspec"; + case BWRITERSIO_TEXM3x3VSPEC: return "texm3x3vspec"; + case BWRITERSIO_EXPP: return "expp"; + case BWRITERSIO_LOGP: return "logp"; + case BWRITERSIO_CND: return "cnd"; + case BWRITERSIO_DEF: return "def"; + case BWRITERSIO_TEXREG2RGB: return "texreg2rgb"; + case BWRITERSIO_TEXDP3TEX: return "texdp3tex"; + case BWRITERSIO_TEXM3x2DEPTH: return "texm3x2depth"; + case BWRITERSIO_TEXDP3: return "texdp3"; + case BWRITERSIO_TEXM3x3: return "texm3x3"; + case BWRITERSIO_TEXDEPTH: return "texdepth"; + case BWRITERSIO_CMP: return "cmp"; + case BWRITERSIO_BEM: return "bem"; + case BWRITERSIO_DP2ADD: return "dp2add"; + case BWRITERSIO_DSX: return "dsx"; + case BWRITERSIO_DSY: return "dsy"; + case BWRITERSIO_TEXLDD: return "texldd"; + case BWRITERSIO_SETP: return "setp"; + case BWRITERSIO_TEXLDL: return "texldl"; + case BWRITERSIO_BREAKP: return "breakp"; + case BWRITERSIO_PHASE: return "phase"; + + case BWRITERSIO_TEXLDP: return "texldp"; + case BWRITERSIO_TEXLDB: return "texldb"; + + default: return "unknown"; + } +} + +void skip_dword_unknown(const char **ptr, unsigned int count) +{ + unsigned int i; + DWORD d; + + FIXME("Skipping %u unknown DWORDs:\n", count); + for (i = 0; i < count; ++i) + { + read_dword(ptr, &d); + FIXME("\t0x%08x\n", d); + } +} + +static void write_dword_unknown(char **ptr, DWORD d) +{ + FIXME("Writing unknown DWORD 0x%08x\n", d); + write_dword(ptr, d); +} + +HRESULT dxbc_add_section(struct dxbc *dxbc, DWORD tag, const char *data, DWORD data_size) +{ + TRACE("dxbc %p, tag %s, size %#x.\n", dxbc, debugstr_an((const char *)&tag, 4), data_size); + + if (dxbc->count >= dxbc->size) + { + struct dxbc_section *new_sections; + DWORD new_size = dxbc->size << 1; + + new_sections = HeapReAlloc(GetProcessHeap(), 0, dxbc->sections, new_size * sizeof(*dxbc->sections)); + if (!new_sections) + { + ERR("Failed to allocate dxbc section memory\n"); + return E_OUTOFMEMORY; + } + + dxbc->sections = new_sections; + dxbc->size = new_size; + } + + dxbc->sections[dxbc->count].tag = tag; + dxbc->sections[dxbc->count].data_size = data_size; + dxbc->sections[dxbc->count].data = data; + ++dxbc->count; + + return S_OK; +} + +HRESULT dxbc_init(struct dxbc *dxbc, UINT size) +{ + TRACE("dxbc %p, size %u.\n", dxbc, size); + + /* use a good starting value for the size if none specified */ + if (!size) size = 2; + + dxbc->sections = HeapAlloc(GetProcessHeap(), 0, size * sizeof(*dxbc->sections)); + if (!dxbc->sections) + { + ERR("Failed to allocate dxbc section memory\n"); + return E_OUTOFMEMORY; + } + + dxbc->size = size; + dxbc->count = 0; + + return S_OK; +} + +HRESULT dxbc_parse(const char *data, SIZE_T data_size, struct dxbc *dxbc) +{ + const char *ptr = data; + HRESULT hr; + unsigned int i; + DWORD tag, total_size, chunk_count; + + if (!data) + { + WARN("No data supplied.\n"); + return E_FAIL; + } + + read_dword(&ptr, &tag); + TRACE("tag: %s.\n", debugstr_an((const char *)&tag, 4)); + + if (tag != TAG_DXBC) + { + WARN("Wrong tag.\n"); + return E_FAIL; + } + + /* checksum? */ + skip_dword_unknown(&ptr, 4); + + skip_dword_unknown(&ptr, 1); + + read_dword(&ptr, &total_size); + TRACE("total size: %#x\n", total_size); + + if (data_size != total_size) + { + WARN("Wrong size supplied.\n"); + return D3DERR_INVALIDCALL; + } + + read_dword(&ptr, &chunk_count); + TRACE("chunk count: %#x\n", chunk_count); + + hr = dxbc_init(dxbc, chunk_count); + if (FAILED(hr)) + { + WARN("Failed to init dxbc\n"); + return hr; + } + + for (i = 0; i < chunk_count; ++i) + { + DWORD chunk_tag, chunk_size; + const char *chunk_ptr; + DWORD chunk_offset; + + read_dword(&ptr, &chunk_offset); + TRACE("chunk %u at offset %#x\n", i, chunk_offset); + + chunk_ptr = data + chunk_offset; + + read_dword(&chunk_ptr, &chunk_tag); + read_dword(&chunk_ptr, &chunk_size); + + hr = dxbc_add_section(dxbc, chunk_tag, chunk_ptr, chunk_size); + if (FAILED(hr)) + { + WARN("Failed to add section to dxbc\n"); + return hr; + } + } + + return hr; +} + +void dxbc_destroy(struct dxbc *dxbc) +{ + TRACE("dxbc %p.\n", dxbc); + + HeapFree(GetProcessHeap(), 0, dxbc->sections); +} + +HRESULT dxbc_write_blob(struct dxbc *dxbc, ID3DBlob **blob) +{ + DWORD size = 32, offset = size + 4 * dxbc->count; + ID3DBlob *object; + HRESULT hr; + char *ptr; + unsigned int i; + + TRACE("dxbc %p, blob %p.\n", dxbc, blob); + + for (i = 0; i < dxbc->count; ++i) + { + size += 12 + dxbc->sections[i].data_size; + } + + hr = D3DCreateBlob(size, &object); + if (FAILED(hr)) + { + WARN("Failed to create blob\n"); + return hr; + } + + ptr = ID3D10Blob_GetBufferPointer(object); + + write_dword(&ptr, TAG_DXBC); + + /* signature(?) */ + write_dword_unknown(&ptr, 0); + write_dword_unknown(&ptr, 0); + write_dword_unknown(&ptr, 0); + write_dword_unknown(&ptr, 0); + + /* seems to be always 1 */ + write_dword_unknown(&ptr, 1); + + /* DXBC size */ + write_dword(&ptr, size); + + /* chunk count */ + write_dword(&ptr, dxbc->count); + + /* write the chunk offsets */ + for (i = 0; i < dxbc->count; ++i) + { + write_dword(&ptr, offset); + offset += 8 + dxbc->sections[i].data_size; + } + + /* write the chunks */ + for (i = 0; i < dxbc->count; ++i) + { + write_dword(&ptr, dxbc->sections[i].tag); + write_dword(&ptr, dxbc->sections[i].data_size); + memcpy(ptr, dxbc->sections[i].data, dxbc->sections[i].data_size); + ptr += dxbc->sections[i].data_size; + } + + TRACE("Created ID3DBlob %p\n", object); + + *blob = object; + + return S_OK; +} + +void compilation_message(struct compilation_messages *msg, const char *fmt, va_list args) +{ + char* buffer; + int rc, size; + + if (msg->capacity == 0) + { + msg->string = d3dcompiler_alloc(MESSAGEBUFFER_INITIAL_SIZE); + if (msg->string == NULL) + { + ERR("Error allocating memory for parser messages\n"); + return; + } + msg->capacity = MESSAGEBUFFER_INITIAL_SIZE; + } + + while (1) + { + rc = vsnprintf(msg->string + msg->size, + msg->capacity - msg->size, fmt, args); + + if (rc < 0 || rc >= msg->capacity - msg->size) + { + size = msg->capacity * 2; + buffer = d3dcompiler_realloc(msg->string, size); + if (buffer == NULL) + { + ERR("Error reallocating memory for parser messages\n"); + return; + } + msg->string = buffer; + msg->capacity = size; + } + else + { + TRACE("%s", msg->string + msg->size); + msg->size += rc; + return; + } + } +} + +BOOL add_declaration(struct hlsl_scope *scope, struct hlsl_ir_var *decl, BOOL local_var) +{ + struct hlsl_ir_var *var; + + LIST_FOR_EACH_ENTRY(var, &scope->vars, struct hlsl_ir_var, scope_entry) + { + if (!strcmp(decl->name, var->name)) + return FALSE; + } + if (local_var && scope->upper->upper == hlsl_ctx.globals) + { + /* Check whether the variable redefines a function parameter. */ + LIST_FOR_EACH_ENTRY(var, &scope->upper->vars, struct hlsl_ir_var, scope_entry) + { + if (!strcmp(decl->name, var->name)) + return FALSE; + } + } + + list_add_tail(&scope->vars, &decl->scope_entry); + return TRUE; +} + +struct hlsl_ir_var *get_variable(struct hlsl_scope *scope, const char *name) +{ + struct hlsl_ir_var *var; + + LIST_FOR_EACH_ENTRY(var, &scope->vars, struct hlsl_ir_var, scope_entry) + { + if (!strcmp(name, var->name)) + return var; + } + if (!scope->upper) + return NULL; + return get_variable(scope->upper, name); +} + +void free_declaration(struct hlsl_ir_var *decl) +{ + d3dcompiler_free((void *)decl->name); + d3dcompiler_free((void *)decl->semantic); + d3dcompiler_free(decl); +} + +BOOL add_func_parameter(struct list *list, struct parse_parameter *param, const struct source_location *loc) +{ + struct hlsl_ir_var *decl = d3dcompiler_alloc(sizeof(*decl)); + + if (!decl) + { + ERR("Out of memory.\n"); + return FALSE; + } + decl->node.type = HLSL_IR_VAR; + decl->node.data_type = param->type; + decl->node.loc = *loc; + decl->name = param->name; + decl->semantic = param->semantic; + decl->modifiers = param->modifiers; + + if (!add_declaration(hlsl_ctx.cur_scope, decl, FALSE)) + { + free_declaration(decl); + return FALSE; + } + list_add_tail(list, &decl->node.entry); + return TRUE; +} + +struct hlsl_type *new_hlsl_type(const char *name, enum hlsl_type_class type_class, + enum hlsl_base_type base_type, unsigned dimx, unsigned dimy) +{ + struct hlsl_type *type; + + type = d3dcompiler_alloc(sizeof(*type)); + if (!type) + { + ERR("Out of memory\n"); + return NULL; + } + type->name = name; + type->type = type_class; + type->base_type = base_type; + type->dimx = dimx; + type->dimy = dimy; + + list_add_tail(&hlsl_ctx.types, &type->entry); + + return type; +} + +struct hlsl_type *new_array_type(struct hlsl_type *basic_type, unsigned int array_size) +{ + struct hlsl_type *type = new_hlsl_type(NULL, HLSL_CLASS_ARRAY, HLSL_TYPE_FLOAT, 1, 1); + + if (!type) + return NULL; + + type->modifiers = basic_type->modifiers; + type->e.array.elements_count = array_size; + type->e.array.type = basic_type; + return type; +} + +struct hlsl_type *get_type(struct hlsl_scope *scope, const char *name, BOOL recursive) +{ + struct wine_rb_entry *entry = wine_rb_get(&scope->types, name); + if (entry) + return WINE_RB_ENTRY_VALUE(entry, struct hlsl_type, scope_entry); + + if (recursive && scope->upper) + return get_type(scope->upper, name, recursive); + return NULL; +} + +BOOL find_function(const char *name) +{ + return wine_rb_get(&hlsl_ctx.functions, name) != NULL; +} + +unsigned int components_count_type(struct hlsl_type *type) +{ + unsigned int count = 0; + struct hlsl_struct_field *field; + + if (type->type <= HLSL_CLASS_LAST_NUMERIC) + { + return type->dimx * type->dimy; + } + if (type->type == HLSL_CLASS_ARRAY) + { + return components_count_type(type->e.array.type) * type->e.array.elements_count; + } + if (type->type != HLSL_CLASS_STRUCT) + { + ERR("Unexpected data type %s.\n", debug_hlsl_type(type)); + return 0; + } + + LIST_FOR_EACH_ENTRY(field, type->e.elements, struct hlsl_struct_field, entry) + { + count += components_count_type(field->type); + } + return count; +} + +BOOL compare_hlsl_types(const struct hlsl_type *t1, const struct hlsl_type *t2) +{ + if (t1 == t2) + return TRUE; + + if (t1->type != t2->type) + return FALSE; + if (t1->base_type != t2->base_type) + return FALSE; + if (t1->base_type == HLSL_TYPE_SAMPLER && t1->sampler_dim != t2->sampler_dim) + return FALSE; + if ((t1->modifiers & HLSL_MODIFIERS_COMPARISON_MASK) + != (t2->modifiers & HLSL_MODIFIERS_COMPARISON_MASK)) + return FALSE; + if (t1->dimx != t2->dimx) + return FALSE; + if (t1->dimy != t2->dimy) + return FALSE; + if (t1->type == HLSL_CLASS_STRUCT) + { + struct list *t1cur, *t2cur; + struct hlsl_struct_field *t1field, *t2field; + + t1cur = list_head(t1->e.elements); + t2cur = list_head(t2->e.elements); + while (t1cur && t2cur) + { + t1field = LIST_ENTRY(t1cur, struct hlsl_struct_field, entry); + t2field = LIST_ENTRY(t2cur, struct hlsl_struct_field, entry); + if (!compare_hlsl_types(t1field->type, t2field->type)) + return FALSE; + if (strcmp(t1field->name, t2field->name)) + return FALSE; + t1cur = list_next(t1->e.elements, t1cur); + t2cur = list_next(t2->e.elements, t2cur); + } + if (t1cur != t2cur) + return FALSE; + } + if (t1->type == HLSL_CLASS_ARRAY) + return t1->e.array.elements_count == t2->e.array.elements_count + && compare_hlsl_types(t1->e.array.type, t2->e.array.type); + + return TRUE; +} + +struct hlsl_type *clone_hlsl_type(struct hlsl_type *old) +{ + struct hlsl_type *type; + struct hlsl_struct_field *old_field, *field; + + type = d3dcompiler_alloc(sizeof(*type)); + if (!type) + { + ERR("Out of memory\n"); + return NULL; + } + if (old->name) + { + type->name = d3dcompiler_strdup(old->name); + if (!type->name) + { + d3dcompiler_free(type); + return NULL; + } + } + type->type = old->type; + type->base_type = old->base_type; + type->dimx = old->dimx; + type->dimy = old->dimy; + type->modifiers = old->modifiers; + type->sampler_dim = old->sampler_dim; + switch (old->type) + { + case HLSL_CLASS_ARRAY: + type->e.array.type = old->e.array.type; + type->e.array.elements_count = old->e.array.elements_count; + break; + case HLSL_CLASS_STRUCT: + type->e.elements = d3dcompiler_alloc(sizeof(*type->e.elements)); + if (!type->e.elements) + { + d3dcompiler_free((void *)type->name); + d3dcompiler_free(type); + return NULL; + } + list_init(type->e.elements); + LIST_FOR_EACH_ENTRY(old_field, old->e.elements, struct hlsl_struct_field, entry) + { + field = d3dcompiler_alloc(sizeof(*field)); + if (!field) + { + LIST_FOR_EACH_ENTRY_SAFE(field, old_field, type->e.elements, struct hlsl_struct_field, entry) + { + d3dcompiler_free((void *)field->semantic); + d3dcompiler_free((void *)field->name); + d3dcompiler_free(field); + } + d3dcompiler_free(type->e.elements); + d3dcompiler_free((void *)type->name); + d3dcompiler_free(type); + return NULL; + } + field->type = clone_hlsl_type(old_field->type); + field->name = d3dcompiler_strdup(old_field->name); + if (old_field->semantic) + field->semantic = d3dcompiler_strdup(old_field->semantic); + field->modifiers = old_field->modifiers; + list_add_tail(type->e.elements, &field->entry); + } + break; + default: + break; + } + + list_add_tail(&hlsl_ctx.types, &type->entry); + return type; +} + +static BOOL convertible_data_type(struct hlsl_type *type) +{ + return type->type != HLSL_CLASS_OBJECT; +} + +BOOL compatible_data_types(struct hlsl_type *t1, struct hlsl_type *t2) +{ + if (!convertible_data_type(t1) || !convertible_data_type(t2)) + return FALSE; + + if (t1->type <= HLSL_CLASS_LAST_NUMERIC) + { + /* Scalar vars can be cast to pretty much everything */ + if (t1->dimx == 1 && t1->dimy == 1) + return TRUE; + + if (t1->type == HLSL_CLASS_VECTOR && t2->type == HLSL_CLASS_VECTOR) + return t1->dimx >= t2->dimx; + } + + /* The other way around is true too i.e. whatever to scalar */ + if (t2->type <= HLSL_CLASS_LAST_NUMERIC && t2->dimx == 1 && t2->dimy == 1) + return TRUE; + + if (t1->type == HLSL_CLASS_ARRAY) + { + if (compare_hlsl_types(t1->e.array.type, t2)) + /* e.g. float4[3] to float4 is allowed */ + return TRUE; + + if (t2->type == HLSL_CLASS_ARRAY || t2->type == HLSL_CLASS_STRUCT) + return components_count_type(t1) >= components_count_type(t2); + else + return components_count_type(t1) == components_count_type(t2); + } + + if (t1->type == HLSL_CLASS_STRUCT) + return components_count_type(t1) >= components_count_type(t2); + + if (t2->type == HLSL_CLASS_ARRAY || t2->type == HLSL_CLASS_STRUCT) + return components_count_type(t1) == components_count_type(t2); + + if (t1->type == HLSL_CLASS_MATRIX || t2->type == HLSL_CLASS_MATRIX) + { + if (t1->type == HLSL_CLASS_MATRIX && t2->type == HLSL_CLASS_MATRIX && t1->dimx >= t2->dimx && t1->dimy >= t2->dimy) + return TRUE; + + /* Matrix-vector conversion is apparently allowed if they have the same components count */ + if ((t1->type == HLSL_CLASS_VECTOR || t2->type == HLSL_CLASS_VECTOR) + && components_count_type(t1) == components_count_type(t2)) + return TRUE; + return FALSE; + } + + if (components_count_type(t1) >= components_count_type(t2)) + return TRUE; + return FALSE; +} + +static BOOL implicit_compatible_data_types(struct hlsl_type *t1, struct hlsl_type *t2) +{ + if (!convertible_data_type(t1) || !convertible_data_type(t2)) + return FALSE; + + if (t1->type <= HLSL_CLASS_LAST_NUMERIC) + { + /* Scalar vars can be converted to any other numeric data type */ + if (t1->dimx == 1 && t1->dimy == 1 && t2->type <= HLSL_CLASS_LAST_NUMERIC) + return TRUE; + /* The other way around is true too */ + if (t2->dimx == 1 && t2->dimy == 1 && t2->type <= HLSL_CLASS_LAST_NUMERIC) + return TRUE; + } + + if (t1->type == HLSL_CLASS_ARRAY && t2->type == HLSL_CLASS_ARRAY) + { + return components_count_type(t1) == components_count_type(t2); + } + + if ((t1->type == HLSL_CLASS_ARRAY && t2->type <= HLSL_CLASS_LAST_NUMERIC) + || (t1->type <= HLSL_CLASS_LAST_NUMERIC && t2->type == HLSL_CLASS_ARRAY)) + { + /* e.g. float4[3] to float4 is allowed */ + if (t1->type == HLSL_CLASS_ARRAY && compare_hlsl_types(t1->e.array.type, t2)) + return TRUE; + if (components_count_type(t1) == components_count_type(t2)) + return TRUE; + return FALSE; + } + + if (t1->type <= HLSL_CLASS_VECTOR && t2->type <= HLSL_CLASS_VECTOR) + { + if (t1->dimx >= t2->dimx) + return TRUE; + return FALSE; + } + + if (t1->type == HLSL_CLASS_MATRIX || t2->type == HLSL_CLASS_MATRIX) + { + if (t1->type == HLSL_CLASS_MATRIX && t2->type == HLSL_CLASS_MATRIX + && t1->dimx >= t2->dimx && t1->dimy >= t2->dimy) + return TRUE; + + /* Matrix-vector conversion is apparently allowed if they have the same components count */ + if ((t1->type == HLSL_CLASS_VECTOR || t2->type == HLSL_CLASS_VECTOR) + && components_count_type(t1) == components_count_type(t2)) + return TRUE; + return FALSE; + } + + if (t1->type == HLSL_CLASS_STRUCT && t2->type == HLSL_CLASS_STRUCT) + return compare_hlsl_types(t1, t2); + + return FALSE; +} + +static BOOL expr_compatible_data_types(struct hlsl_type *t1, struct hlsl_type *t2) +{ + if (t1->base_type > HLSL_TYPE_LAST_SCALAR || t2->base_type > HLSL_TYPE_LAST_SCALAR) + return FALSE; + + /* Scalar vars can be converted to pretty much everything */ + if ((t1->dimx == 1 && t1->dimy == 1) || (t2->dimx == 1 && t2->dimy == 1)) + return TRUE; + + if (t1->type == HLSL_CLASS_VECTOR && t2->type == HLSL_CLASS_VECTOR) + return TRUE; + + if (t1->type == HLSL_CLASS_MATRIX || t2->type == HLSL_CLASS_MATRIX) + { + /* Matrix-vector conversion is apparently allowed if either they have the same components + count or the matrix is nx1 or 1xn */ + if (t1->type == HLSL_CLASS_VECTOR || t2->type == HLSL_CLASS_VECTOR) + { + if (components_count_type(t1) == components_count_type(t2)) + return TRUE; + + return (t1->type == HLSL_CLASS_MATRIX && (t1->dimx == 1 || t1->dimy == 1)) + || (t2->type == HLSL_CLASS_MATRIX && (t2->dimx == 1 || t2->dimy == 1)); + } + + /* Both matrices */ + if ((t1->dimx >= t2->dimx && t1->dimy >= t2->dimy) + || (t1->dimx <= t2->dimx && t1->dimy <= t2->dimy)) + return TRUE; + } + + return FALSE; +} + +static enum hlsl_base_type expr_common_base_type(enum hlsl_base_type t1, enum hlsl_base_type t2) +{ + enum hlsl_base_type types[] = + { + HLSL_TYPE_BOOL, + HLSL_TYPE_INT, + HLSL_TYPE_UINT, + HLSL_TYPE_HALF, + HLSL_TYPE_FLOAT, + HLSL_TYPE_DOUBLE, + }; + int t1_idx = -1, t2_idx = -1, i; + + for (i = 0; i < sizeof(types) / sizeof(types[0]); ++i) + { + /* Always convert away from HLSL_TYPE_HALF */ + if (t1 == types[i]) + t1_idx = t1 == HLSL_TYPE_HALF ? i + 1 : i; + if (t2 == types[i]) + t2_idx = t2 == HLSL_TYPE_HALF ? i + 1 : i; + + if (t1_idx != -1 && t2_idx != -1) + break; + } + if (t1_idx == -1 || t2_idx == -1) + { + FIXME("Unexpected base type.\n"); + return HLSL_TYPE_FLOAT; + } + return t1_idx >= t2_idx ? t1 : t2; +} + +static struct hlsl_type *expr_common_type(struct hlsl_type *t1, struct hlsl_type *t2, + struct source_location *loc) +{ + enum hlsl_type_class type; + enum hlsl_base_type base; + unsigned int dimx, dimy; + + if (t1->type > HLSL_CLASS_LAST_NUMERIC || t2->type > HLSL_CLASS_LAST_NUMERIC) + { + hlsl_report_message(loc->file, loc->line, loc->col, HLSL_LEVEL_ERROR, + "non scalar/vector/matrix data type in expression"); + return NULL; + } + + if (compare_hlsl_types(t1, t2)) + return t1; + + if (!expr_compatible_data_types(t1, t2)) + { + hlsl_report_message(loc->file, loc->line, loc->col, HLSL_LEVEL_ERROR, + "expression data types are incompatible"); + return NULL; + } + + if (t1->base_type == t2->base_type) + base = t1->base_type; + else + base = expr_common_base_type(t1->base_type, t2->base_type); + + if (t1->dimx == 1 && t1->dimy == 1) + { + type = t2->type; + dimx = t2->dimx; + dimy = t2->dimy; + } + else if (t2->dimx == 1 && t2->dimy == 1) + { + type = t1->type; + dimx = t1->dimx; + dimy = t1->dimy; + } + else if (t1->type == HLSL_CLASS_MATRIX && t2->type == HLSL_CLASS_MATRIX) + { + type = HLSL_CLASS_MATRIX; + dimx = min(t1->dimx, t2->dimx); + dimy = min(t1->dimy, t2->dimy); + } + else + { + /* Two vectors or a vector and a matrix (matrix must be 1xn or nx1) */ + unsigned int max_dim_1, max_dim_2; + + max_dim_1 = max(t1->dimx, t1->dimy); + max_dim_2 = max(t2->dimx, t2->dimy); + if (t1->dimx * t1->dimy == t2->dimx * t2->dimy) + { + type = HLSL_CLASS_VECTOR; + dimx = max(t1->dimx, t2->dimx); + dimy = 1; + } + else if (max_dim_1 <= max_dim_2) + { + type = t1->type; + if (type == HLSL_CLASS_VECTOR) + { + dimx = max_dim_1; + dimy = 1; + } + else + { + dimx = t1->dimx; + dimy = t1->dimy; + } + } + else + { + type = t2->type; + if (type == HLSL_CLASS_VECTOR) + { + dimx = max_dim_2; + dimy = 1; + } + else + { + dimx = t2->dimx; + dimy = t2->dimy; + } + } + } + + return new_hlsl_type(NULL, type, base, dimx, dimy); +} + +static struct hlsl_ir_node *implicit_conversion(struct hlsl_ir_node *node, struct hlsl_type *type, + struct source_location *loc) +{ + struct hlsl_ir_expr *cast; + struct hlsl_ir_node *operands[3]; + + if (compare_hlsl_types(node->data_type, type)) + return node; + TRACE("Implicit conversion of expression to %s\n", debug_hlsl_type(type)); + operands[0] = node; + operands[1] = operands[2] = NULL; + cast = new_expr(HLSL_IR_UNOP_CAST, operands, loc); + if (!cast) + return NULL; + cast->node.data_type = type; + return &cast->node; +} + +struct hlsl_ir_expr *new_expr(enum hlsl_ir_expr_op op, struct hlsl_ir_node **operands, + struct source_location *loc) +{ + struct hlsl_ir_expr *expr = d3dcompiler_alloc(sizeof(*expr)); + struct hlsl_type *type; + unsigned int i; + + if (!expr) + { + ERR("Out of memory\n"); + return NULL; + } + expr->node.type = HLSL_IR_EXPR; + expr->node.loc = *loc; + type = operands[0]->data_type; + for (i = 1; i <= 2; ++i) + { + if (!operands[i]) + break; + type = expr_common_type(type, operands[i]->data_type, loc); + if (!type) + { + d3dcompiler_free(expr); + return NULL; + } + } + for (i = 0; i <= 2; ++i) + { + if (!operands[i]) + break; + if (compare_hlsl_types(operands[i]->data_type, type)) + continue; + TRACE("Implicitly converting %s into %s in an expression\n", debug_hlsl_type(operands[i]->data_type), debug_hlsl_type(type)); + if (operands[i]->data_type->dimx * operands[i]->data_type->dimy != 1 + && operands[i]->data_type->dimx * operands[i]->data_type->dimy != type->dimx * type->dimy) + { + hlsl_report_message(operands[i]->loc.file, + operands[i]->loc.line, operands[i]->loc.col, HLSL_LEVEL_WARNING, + "implicit truncation of vector/matrix type"); + } + operands[i] = implicit_conversion(operands[i], type, &operands[i]->loc); + if (!operands[i]) + { + ERR("Impossible to convert expression operand %u to %s\n", i + 1, debug_hlsl_type(type)); + d3dcompiler_free(expr); + return NULL; + } + } + expr->node.data_type = type; + expr->op = op; + expr->operands[0] = operands[0]; + expr->operands[1] = operands[1]; + expr->operands[2] = operands[2]; + + return expr; +} + +struct hlsl_ir_expr *new_cast(struct hlsl_ir_node *node, struct hlsl_type *type, + struct source_location *loc) +{ + struct hlsl_ir_expr *cast; + struct hlsl_ir_node *operands[3]; + + operands[0] = node; + operands[1] = operands[2] = NULL; + cast = new_expr(HLSL_IR_UNOP_CAST, operands, loc); + if (cast) + cast->node.data_type = type; + return cast; +} + +struct hlsl_ir_expr *hlsl_mul(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2, + struct source_location *loc) +{ + struct hlsl_ir_expr *expr; + struct hlsl_ir_node *ops[3]; + + ops[0] = op1; + ops[1] = op2; + ops[2] = NULL; + expr = new_expr(HLSL_IR_BINOP_MUL, ops, loc); + return expr; +} + +struct hlsl_ir_expr *hlsl_div(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2, + struct source_location *loc) +{ + struct hlsl_ir_expr *expr; + struct hlsl_ir_node *ops[3]; + + ops[0] = op1; + ops[1] = op2; + ops[2] = NULL; + expr = new_expr(HLSL_IR_BINOP_DIV, ops, loc); + return expr; +} + +struct hlsl_ir_expr *hlsl_mod(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2, + struct source_location *loc) +{ + struct hlsl_ir_expr *expr; + struct hlsl_ir_node *ops[3]; + + ops[0] = op1; + ops[1] = op2; + ops[2] = NULL; + expr = new_expr(HLSL_IR_BINOP_MOD, ops, loc); + return expr; +} + +struct hlsl_ir_expr *hlsl_add(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2, + struct source_location *loc) +{ + struct hlsl_ir_expr *expr; + struct hlsl_ir_node *ops[3]; + + ops[0] = op1; + ops[1] = op2; + ops[2] = NULL; + expr = new_expr(HLSL_IR_BINOP_ADD, ops, loc); + return expr; +} + +struct hlsl_ir_expr *hlsl_sub(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2, + struct source_location *loc) +{ + struct hlsl_ir_expr *expr; + struct hlsl_ir_node *ops[3]; + + ops[0] = op1; + ops[1] = op2; + ops[2] = NULL; + expr = new_expr(HLSL_IR_BINOP_SUB, ops, loc); + return expr; +} + +struct hlsl_ir_expr *hlsl_lt(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2, + struct source_location *loc) +{ + struct hlsl_ir_expr *expr; + struct hlsl_ir_node *ops[3]; + + ops[0] = op1; + ops[1] = op2; + ops[2] = NULL; + expr = new_expr(HLSL_IR_BINOP_LESS, ops, loc); + return expr; +} + +struct hlsl_ir_expr *hlsl_gt(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2, + struct source_location *loc) +{ + struct hlsl_ir_expr *expr; + struct hlsl_ir_node *ops[3]; + + ops[0] = op1; + ops[1] = op2; + ops[2] = NULL; + expr = new_expr(HLSL_IR_BINOP_GREATER, ops, loc); + return expr; +} + +struct hlsl_ir_expr *hlsl_le(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2, + struct source_location *loc) +{ + struct hlsl_ir_expr *expr; + struct hlsl_ir_node *ops[3]; + + ops[0] = op1; + ops[1] = op2; + ops[2] = NULL; + expr = new_expr(HLSL_IR_BINOP_LEQUAL, ops, loc); + return expr; +} + +struct hlsl_ir_expr *hlsl_ge(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2, + struct source_location *loc) +{ + struct hlsl_ir_expr *expr; + struct hlsl_ir_node *ops[3]; + + ops[0] = op1; + ops[1] = op2; + ops[2] = NULL; + expr = new_expr(HLSL_IR_BINOP_GEQUAL, ops, loc); + return expr; +} + +struct hlsl_ir_expr *hlsl_eq(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2, + struct source_location *loc) +{ + struct hlsl_ir_expr *expr; + struct hlsl_ir_node *ops[3]; + + ops[0] = op1; + ops[1] = op2; + ops[2] = NULL; + expr = new_expr(HLSL_IR_BINOP_EQUAL, ops, loc); + return expr; +} + +struct hlsl_ir_expr *hlsl_ne(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2, + struct source_location *loc) +{ + struct hlsl_ir_expr *expr; + struct hlsl_ir_node *ops[3]; + + ops[0] = op1; + ops[1] = op2; + ops[2] = NULL; + expr = new_expr(HLSL_IR_BINOP_NEQUAL, ops, loc); + return expr; +} + +struct hlsl_ir_deref *new_var_deref(struct hlsl_ir_var *var) +{ + struct hlsl_ir_deref *deref = d3dcompiler_alloc(sizeof(*deref)); + + if (!deref) + { + ERR("Out of memory.\n"); + return NULL; + } + deref->node.type = HLSL_IR_DEREF; + deref->node.data_type = var->node.data_type; + deref->type = HLSL_IR_DEREF_VAR; + deref->v.var = var; + return deref; +} + +struct hlsl_ir_deref *new_record_deref(struct hlsl_ir_node *record, struct hlsl_struct_field *field) +{ + struct hlsl_ir_deref *deref = d3dcompiler_alloc(sizeof(*deref)); + + if (!deref) + { + ERR("Out of memory.\n"); + return NULL; + } + deref->node.type = HLSL_IR_DEREF; + deref->node.data_type = field->type; + deref->type = HLSL_IR_DEREF_RECORD; + if (record->type == HLSL_IR_VAR) + deref->v.record.record = &new_var_deref(var_from_node(record))->node; + else + deref->v.record.record = record; + deref->v.record.field = field; + return deref; +} + +static enum hlsl_ir_expr_op op_from_assignment(enum parse_assign_op op) +{ + static const enum hlsl_ir_expr_op ops[] = + { + 0, + HLSL_IR_BINOP_ADD, + HLSL_IR_BINOP_SUB, + HLSL_IR_BINOP_MUL, + HLSL_IR_BINOP_DIV, + HLSL_IR_BINOP_MOD, + HLSL_IR_BINOP_LSHIFT, + HLSL_IR_BINOP_RSHIFT, + HLSL_IR_BINOP_BIT_AND, + HLSL_IR_BINOP_BIT_OR, + HLSL_IR_BINOP_BIT_XOR, + }; + + return ops[op]; +} + +struct hlsl_ir_node *make_assignment(struct hlsl_ir_node *left, enum parse_assign_op assign_op, + DWORD writemask, struct hlsl_ir_node *right) +{ + struct hlsl_ir_expr *expr; + struct hlsl_ir_assignment *assign = d3dcompiler_alloc(sizeof(*assign)); + struct hlsl_type *type; + struct hlsl_ir_node *lhs, *rhs; + + if (!assign) + { + ERR("Out of memory\n"); + return NULL; + } + + TRACE("Creating proper assignment expression.\n"); + rhs = right; + if (writemask == BWRITERSP_WRITEMASK_ALL) + type = left->data_type; + else + { + FIXME("Assignments with writemasks not supported yet.\n"); + type = NULL; + } + assign->node.type = HLSL_IR_ASSIGNMENT; + assign->node.loc = left->loc; + assign->node.data_type = type; + assign->writemask = writemask; + FIXME("Check for casts in the lhs.\n"); + + lhs = left; + if (lhs->type == HLSL_IR_VAR) + { + struct hlsl_ir_deref *lhs_deref = new_var_deref(var_from_node(lhs)); + lhs = &lhs_deref->node; + } + /* FIXME: check for invalid writemasks on the lhs. */ + + if (!compare_hlsl_types(type, rhs->data_type)) + { + struct hlsl_ir_node *converted_rhs; + + if (!implicit_compatible_data_types(rhs->data_type, type)) + { + hlsl_report_message(rhs->loc.file, rhs->loc.line, rhs->loc.col, HLSL_LEVEL_ERROR, + "can't implicitly convert %s to %s", + debug_hlsl_type(rhs->data_type), debug_hlsl_type(type)); + free_instr(lhs); + free_instr(rhs); + d3dcompiler_free(assign); + return NULL; + } + if (lhs->data_type->dimx * lhs->data_type->dimy < rhs->data_type->dimx * rhs->data_type->dimy) + hlsl_report_message(rhs->loc.file, rhs->loc.line, rhs->loc.col, HLSL_LEVEL_WARNING, + "implicit truncation of vector type"); + + converted_rhs = implicit_conversion(rhs, type, &rhs->loc); + if (!converted_rhs) + { + ERR("Couldn't implicitly convert expression to %s.\n", debug_hlsl_type(type)); + free_instr(lhs); + free_instr(rhs); + d3dcompiler_free(assign); + return NULL; + } + rhs = converted_rhs; + } + + assign->lhs = lhs; + if (assign_op != ASSIGN_OP_ASSIGN) + { + struct hlsl_ir_node *operands[3]; + enum hlsl_ir_expr_op op = op_from_assignment(assign_op); + + if (lhs->type != HLSL_IR_DEREF || deref_from_node(lhs)->type != HLSL_IR_DEREF_VAR) + { + FIXME("LHS expression not supported in compound assignments yet.\n"); + assign->rhs = rhs; + } + else + { + struct hlsl_ir_deref *lhs_deref = deref_from_node(lhs), *new_deref; + + TRACE("Adding an expression for the compound assignment.\n"); + new_deref = new_var_deref(lhs_deref->v.var); + operands[0] = &new_deref->node; + operands[1] = rhs; + operands[2] = NULL; + expr = new_expr(op, operands, &left->loc); + assign->rhs = &expr->node; + } + } + else + assign->rhs = rhs; + + return &assign->node; +} + +static int compare_hlsl_types_rb(const void *key, const struct wine_rb_entry *entry) +{ + const char *name = (const char *)key; + const struct hlsl_type *type = WINE_RB_ENTRY_VALUE(entry, const struct hlsl_type, scope_entry); + + if (name == type->name) + return 0; + + if (!name || !type->name) + { + ERR("hlsl_type without a name in a scope?\n"); + return -1; + } + return strcmp(name, type->name); +} + +static inline void *d3dcompiler_alloc_rb(size_t size) +{ + return d3dcompiler_alloc(size); +} + +static inline void *d3dcompiler_realloc_rb(void *ptr, size_t size) +{ + return d3dcompiler_realloc(ptr, size); +} + +static inline void d3dcompiler_free_rb(void *ptr) +{ + d3dcompiler_free(ptr); +} +static const struct wine_rb_functions hlsl_type_rb_funcs = +{ + d3dcompiler_alloc_rb, + d3dcompiler_realloc_rb, + d3dcompiler_free_rb, + compare_hlsl_types_rb, +}; + +void push_scope(struct hlsl_parse_ctx *ctx) +{ + struct hlsl_scope *new_scope = d3dcompiler_alloc(sizeof(*new_scope)); + + if (!new_scope) + { + ERR("Out of memory!\n"); + return; + } + TRACE("Pushing a new scope\n"); + list_init(&new_scope->vars); + if (wine_rb_init(&new_scope->types, &hlsl_type_rb_funcs) == -1) + { + ERR("Failed to initialize types rbtree.\n"); + d3dcompiler_free(new_scope); + return; + } + new_scope->upper = ctx->cur_scope; + ctx->cur_scope = new_scope; + list_add_tail(&ctx->scopes, &new_scope->entry); +} + +BOOL pop_scope(struct hlsl_parse_ctx *ctx) +{ + struct hlsl_scope *prev_scope = ctx->cur_scope->upper; + if (!prev_scope) + return FALSE; + + TRACE("Popping current scope\n"); + ctx->cur_scope = prev_scope; + return TRUE; +} + +struct hlsl_ir_function_decl *new_func_decl(struct hlsl_type *return_type, struct list *parameters) +{ + struct hlsl_ir_function_decl *decl; + + decl = d3dcompiler_alloc(sizeof(*decl)); + if (!decl) + { + ERR("Out of memory.\n"); + return NULL; + } + decl->node.type = HLSL_IR_FUNCTION_DECL; + decl->node.data_type = return_type; + decl->parameters = parameters; + + return decl; +} + +static int compare_param_hlsl_types(const struct hlsl_type *t1, const struct hlsl_type *t2) +{ + if (t1->type != t2->type) + { + if (!((t1->type == HLSL_CLASS_SCALAR && t2->type == HLSL_CLASS_VECTOR) + || (t1->type == HLSL_CLASS_VECTOR && t2->type == HLSL_CLASS_SCALAR))) + return t1->type - t2->type; + } + if (t1->base_type != t2->base_type) + return t1->base_type - t2->base_type; + if (t1->base_type == HLSL_TYPE_SAMPLER && t1->sampler_dim != t2->sampler_dim) + return t1->sampler_dim - t2->sampler_dim; + if (t1->dimx != t2->dimx) + return t1->dimx - t2->dimx; + if (t1->dimy != t2->dimy) + return t1->dimx - t2->dimx; + if (t1->type == HLSL_CLASS_STRUCT) + { + struct list *t1cur, *t2cur; + struct hlsl_struct_field *t1field, *t2field; + int r; + + t1cur = list_head(t1->e.elements); + t2cur = list_head(t2->e.elements); + while (t1cur && t2cur) + { + t1field = LIST_ENTRY(t1cur, struct hlsl_struct_field, entry); + t2field = LIST_ENTRY(t2cur, struct hlsl_struct_field, entry); + if ((r = compare_param_hlsl_types(t1field->type, t2field->type))) + return r; + if ((r = strcmp(t1field->name, t2field->name))) + return r; + t1cur = list_next(t1->e.elements, t1cur); + t2cur = list_next(t2->e.elements, t2cur); + } + if (t1cur != t2cur) + return t1cur ? 1 : -1; + return 0; + } + if (t1->type == HLSL_CLASS_ARRAY) + { + if (t1->e.array.elements_count != t2->e.array.elements_count) + return t1->e.array.elements_count - t2->e.array.elements_count; + return compare_param_hlsl_types(t1->e.array.type, t2->e.array.type); + } + + return 0; +} + +static int compare_function_decl_rb(const void *key, const struct wine_rb_entry *entry) +{ + const struct list *params = (const struct list *)key; + const struct hlsl_ir_function_decl *decl = WINE_RB_ENTRY_VALUE(entry, const struct hlsl_ir_function_decl, entry); + int params_count = params ? list_count(params) : 0; + int decl_params_count = decl->parameters ? list_count(decl->parameters) : 0; + int r; + struct list *p1cur, *p2cur; + + if (params_count != decl_params_count) + return params_count - decl_params_count; + + p1cur = params ? list_head(params) : NULL; + p2cur = decl->parameters ? list_head(decl->parameters) : NULL; + while (p1cur && p2cur) + { + struct hlsl_ir_var *p1, *p2; + p1 = LIST_ENTRY(p1cur, struct hlsl_ir_var, node.entry); + p2 = LIST_ENTRY(p2cur, struct hlsl_ir_var, node.entry); + if ((r = compare_param_hlsl_types(p1->node.data_type, p2->node.data_type))) + return r; + p1cur = list_next(params, p1cur); + p2cur = list_next(decl->parameters, p2cur); + } + return 0; +} + +static const struct wine_rb_functions hlsl_ir_function_decl_rb_funcs = +{ + d3dcompiler_alloc_rb, + d3dcompiler_realloc_rb, + d3dcompiler_free_rb, + compare_function_decl_rb, +}; + +static int compare_function_rb(const void *key, const struct wine_rb_entry *entry) +{ + const char *name = (const char *)key; + const struct hlsl_ir_function *func = WINE_RB_ENTRY_VALUE(entry, const struct hlsl_ir_function,entry); + + return strcmp(name, func->name); +} + +static const struct wine_rb_functions function_rb_funcs = +{ + d3dcompiler_alloc_rb, + d3dcompiler_realloc_rb, + d3dcompiler_free_rb, + compare_function_rb, +}; + +void init_functions_tree(struct wine_rb_tree *funcs) +{ + if (wine_rb_init(&hlsl_ctx.functions, &function_rb_funcs) == -1) + ERR("Failed to initialize functions rbtree.\n"); +} + +static const char *debug_base_type(const struct hlsl_type *type) +{ + const char *name = "(unknown)"; + + switch (type->base_type) + { + case HLSL_TYPE_FLOAT: name = "float"; break; + case HLSL_TYPE_HALF: name = "half"; break; + case HLSL_TYPE_DOUBLE: name = "double"; break; + case HLSL_TYPE_INT: name = "int"; break; + case HLSL_TYPE_UINT: name = "uint"; break; + case HLSL_TYPE_BOOL: name = "bool"; break; + case HLSL_TYPE_SAMPLER: + switch (type->sampler_dim) + { + case HLSL_SAMPLER_DIM_GENERIC: name = "sampler"; break; + case HLSL_SAMPLER_DIM_1D: name = "sampler1D"; break; + case HLSL_SAMPLER_DIM_2D: name = "sampler2D"; break; + case HLSL_SAMPLER_DIM_3D: name = "sampler3D"; break; + case HLSL_SAMPLER_DIM_CUBE: name = "samplerCUBE"; break; + } + break; + default: + FIXME("Unhandled case %u\n", type->base_type); + } + return name; +} + +const char *debug_hlsl_type(const struct hlsl_type *type) +{ + const char *name; + + if (type->name) + return debugstr_a(type->name); + + if (type->type == HLSL_CLASS_STRUCT) + return ""; + + if (type->type == HLSL_CLASS_ARRAY) + { + name = debug_base_type(type->e.array.type); + return wine_dbg_sprintf("%s[%u]", name, type->e.array.elements_count); + } + + name = debug_base_type(type); + + if (type->type == HLSL_CLASS_SCALAR) + return wine_dbg_sprintf("%s", name); + if (type->type == HLSL_CLASS_VECTOR) + return wine_dbg_sprintf("%s%u", name, type->dimx); + if (type->type == HLSL_CLASS_MATRIX) + return wine_dbg_sprintf("%s%ux%u", name, type->dimx, type->dimy); + return "unexpected_type"; +} + +const char *debug_modifiers(DWORD modifiers) +{ + char string[110]; + + string[0] = 0; + if (modifiers & HLSL_STORAGE_EXTERN) + strcat(string, " extern"); /* 7 */ + if (modifiers & HLSL_STORAGE_NOINTERPOLATION) + strcat(string, " nointerpolation"); /* 16 */ + if (modifiers & HLSL_MODIFIER_PRECISE) + strcat(string, " precise"); /* 8 */ + if (modifiers & HLSL_STORAGE_SHARED) + strcat(string, " shared"); /* 7 */ + if (modifiers & HLSL_STORAGE_GROUPSHARED) + strcat(string, " groupshared"); /* 12 */ + if (modifiers & HLSL_STORAGE_STATIC) + strcat(string, " static"); /* 7 */ + if (modifiers & HLSL_STORAGE_UNIFORM) + strcat(string, " uniform"); /* 8 */ + if (modifiers & HLSL_STORAGE_VOLATILE) + strcat(string, " volatile"); /* 9 */ + if (modifiers & HLSL_MODIFIER_CONST) + strcat(string, " const"); /* 6 */ + if (modifiers & HLSL_MODIFIER_ROW_MAJOR) + strcat(string, " row_major"); /* 10 */ + if (modifiers & HLSL_MODIFIER_COLUMN_MAJOR) + strcat(string, " column_major"); /* 13 */ + if ((modifiers & (HLSL_MODIFIER_IN | HLSL_MODIFIER_OUT)) == (HLSL_MODIFIER_IN | HLSL_MODIFIER_OUT)) + strcat(string, " inout"); /* 6 */ + else if (modifiers & HLSL_MODIFIER_IN) + strcat(string, " in"); /* 3 */ + else if (modifiers & HLSL_MODIFIER_OUT) + strcat(string, " out"); /* 4 */ + + return wine_dbg_sprintf("%s", string[0] ? string + 1 : ""); +} + +static const char *debug_node_type(enum hlsl_ir_node_type type) +{ + const char *names[] = + { + "HLSL_IR_VAR", + "HLSL_IR_ASSIGNMENT", + "HLSL_IR_CONSTANT", + "HLSL_IR_CONSTRUCTOR", + "HLSL_IR_DEREF", + "HLSL_IR_EXPR", + "HLSL_IR_FUNCTION_DECL", + "HLSL_IR_IF", + "HLSL_IR_JUMP", + "HLSL_IR_SWIZZLE", + }; + + if (type >= sizeof(names) / sizeof(names[0])) + return "Unexpected node type"; + return names[type]; +} + +static void debug_dump_instr(const struct hlsl_ir_node *instr); + +static void debug_dump_instr_list(const struct list *list) +{ + struct hlsl_ir_node *instr; + + LIST_FOR_EACH_ENTRY(instr, list, struct hlsl_ir_node, entry) + { + debug_dump_instr(instr); + TRACE("\n"); + } +} + +static void debug_dump_ir_var(const struct hlsl_ir_var *var) +{ + if (var->modifiers) + TRACE("%s ", debug_modifiers(var->modifiers)); + TRACE("%s %s", debug_hlsl_type(var->node.data_type), var->name); + if (var->semantic) + TRACE(" : %s", debugstr_a(var->semantic)); +} + +static void debug_dump_ir_deref(const struct hlsl_ir_deref *deref) +{ + switch (deref->type) + { + case HLSL_IR_DEREF_VAR: + TRACE("deref("); + debug_dump_ir_var(deref->v.var); + TRACE(")"); + break; + case HLSL_IR_DEREF_ARRAY: + debug_dump_instr(deref->v.array.array); + TRACE("["); + debug_dump_instr(deref->v.array.index); + TRACE("]"); + break; + case HLSL_IR_DEREF_RECORD: + debug_dump_instr(deref->v.record.record); + TRACE(".%s", debugstr_a(deref->v.record.field->name)); + break; + } +} + +static void debug_dump_ir_constant(const struct hlsl_ir_constant *constant) +{ + struct hlsl_type *type = constant->node.data_type; + unsigned int x, y; + + if (type->dimy != 1) + TRACE("{"); + for (y = 0; y < type->dimy; ++y) + { + if (type->dimx != 1) + TRACE("{"); + for (x = 0; x < type->dimx; ++x) + { + switch (type->base_type) + { + case HLSL_TYPE_FLOAT: + TRACE("%g ", (double)constant->v.value.f[y * type->dimx + x]); + break; + case HLSL_TYPE_DOUBLE: + TRACE("%g ", constant->v.value.d[y * type->dimx + x]); + break; + case HLSL_TYPE_INT: + TRACE("%d ", constant->v.value.i[y * type->dimx + x]); + break; + case HLSL_TYPE_UINT: + TRACE("%u ", constant->v.value.u[y * type->dimx + x]); + break; + case HLSL_TYPE_BOOL: + TRACE("%s ", constant->v.value.b[y * type->dimx + x] == FALSE ? "false" : "true"); + break; + default: + TRACE("Constants of type %s not supported\n", debug_base_type(type)); + } + } + if (type->dimx != 1) + TRACE("}"); + } + if (type->dimy != 1) + TRACE("}"); +} + +static const char *debug_expr_op(const struct hlsl_ir_expr *expr) +{ + static const char *op_names[] = + { + "~", + "!", + "-", + "abs", + "sign", + "rcp", + "rsq", + "sqrt", + "nrm", + "exp2", + "log2", + + "cast", + + "fract", + + "sin", + "cos", + "sin_reduced", + "cos_reduced", + + "dsx", + "dsy", + + "sat", + + "+", + "-", + "*", + "/", + + "%", + + "<", + ">", + "<=", + ">=", + "==", + "!=", + + "&&", + "||", + + "<<", + ">>", + "&", + "|", + "^", + + "dot", + "crs", + "min", + "max", + + "pow", + + "pre++", + "pre--", + "post++", + "post--", + + "lerp", + + ",", + }; + + if (expr->op == HLSL_IR_UNOP_CAST) + return debug_hlsl_type(expr->node.data_type); + + return op_names[expr->op]; +} + +/* Dumps the expression in a prefix "operator (operands)" form */ +static void debug_dump_ir_expr(const struct hlsl_ir_expr *expr) +{ + unsigned int i; + + TRACE("%s (", debug_expr_op(expr)); + for (i = 0; i < 3 && expr->operands[i]; ++i) + { + debug_dump_instr(expr->operands[i]); + TRACE(" "); + } + TRACE(")"); +} + +static void debug_dump_ir_constructor(const struct hlsl_ir_constructor *constructor) +{ + struct hlsl_ir_node *arg; + + TRACE("%s (", debug_hlsl_type(constructor->node.data_type)); + LIST_FOR_EACH_ENTRY(arg, constructor->arguments, struct hlsl_ir_node, entry) + { + debug_dump_instr(arg); + TRACE(" "); + } + TRACE(")"); +} + +static const char *debug_writemask(DWORD writemask) +{ + char string[5], components[] = {'x', 'y', 'z', 'w'}; + unsigned int i = 0, pos = 0; + + while (writemask) + { + if (writemask & 1) + string[pos++] = components[i]; + writemask >>= 1; + i++; + } + string[pos] = '\0'; + return wine_dbg_sprintf(".%s", string); +} + +static void debug_dump_ir_assignment(const struct hlsl_ir_assignment *assign) +{ + TRACE("= ("); + debug_dump_instr(assign->lhs); + if (assign->writemask != BWRITERSP_WRITEMASK_ALL) + TRACE("%s", debug_writemask(assign->writemask)); + TRACE(" "); + debug_dump_instr(assign->rhs); + TRACE(")"); +} + +static void debug_dump_ir_swizzle(const struct hlsl_ir_swizzle *swizzle) +{ + unsigned int i; + + debug_dump_instr(swizzle->val); + TRACE("."); + if (swizzle->val->data_type->dimy > 1) + { + for (i = 0; i < swizzle->node.data_type->dimx; ++i) + TRACE("_m%u%u", (swizzle->swizzle >> i * 8) & 0xf, (swizzle->swizzle >> (i * 8 + 4)) & 0xf); + } + else + { + char c[] = {'x', 'y', 'z', 'w'}; + + for (i = 0; i < swizzle->node.data_type->dimx; ++i) + TRACE("%c", c[(swizzle->swizzle >> i * 2) & 0x3]); + } +} + +static void debug_dump_ir_jump(const struct hlsl_ir_jump *jump) +{ + switch (jump->type) + { + case HLSL_IR_JUMP_BREAK: + TRACE("break"); + break; + case HLSL_IR_JUMP_CONTINUE: + TRACE("continue"); + break; + case HLSL_IR_JUMP_DISCARD: + TRACE("discard"); + break; + case HLSL_IR_JUMP_RETURN: + TRACE("return "); + if (jump->return_value) + debug_dump_instr(jump->return_value); + TRACE(";"); + break; + } +} + +static void debug_dump_ir_if(const struct hlsl_ir_if *if_node) +{ + TRACE("if ("); + debug_dump_instr(if_node->condition); + TRACE(")\n{\n"); + debug_dump_instr_list(if_node->then_instrs); + TRACE("}\n"); + if (if_node->else_instrs) + { + TRACE("else\n{\n"); + debug_dump_instr_list(if_node->else_instrs); + TRACE("}\n"); + } +} + +static void debug_dump_instr(const struct hlsl_ir_node *instr) +{ + switch (instr->type) + { + case HLSL_IR_EXPR: + debug_dump_ir_expr(expr_from_node(instr)); + break; + case HLSL_IR_DEREF: + debug_dump_ir_deref(deref_from_node(instr)); + break; + case HLSL_IR_CONSTANT: + debug_dump_ir_constant(constant_from_node(instr)); + break; + case HLSL_IR_ASSIGNMENT: + debug_dump_ir_assignment(assignment_from_node(instr)); + break; + case HLSL_IR_SWIZZLE: + debug_dump_ir_swizzle(swizzle_from_node(instr)); + break; + case HLSL_IR_CONSTRUCTOR: + debug_dump_ir_constructor(constructor_from_node(instr)); + break; + case HLSL_IR_JUMP: + debug_dump_ir_jump(jump_from_node(instr)); + break; + case HLSL_IR_IF: + debug_dump_ir_if(if_from_node(instr)); + break; + default: + TRACE("", debug_node_type(instr->type)); + } +} + +void debug_dump_ir_function_decl(const struct hlsl_ir_function_decl *func) +{ + struct hlsl_ir_var *param; + + TRACE("Dumping function %s.\n", debugstr_a(func->func->name)); + TRACE("Function parameters:\n"); + LIST_FOR_EACH_ENTRY(param, func->parameters, struct hlsl_ir_var, node.entry) + { + debug_dump_ir_var(param); + TRACE("\n"); + } + if (func->semantic) + TRACE("Function semantic: %s\n", debugstr_a(func->semantic)); + if (func->body) + { + debug_dump_instr_list(func->body); + } +} + +void free_hlsl_type(struct hlsl_type *type) +{ + struct hlsl_struct_field *field, *next_field; + + d3dcompiler_free((void *)type->name); + if (type->type == HLSL_CLASS_STRUCT) + { + LIST_FOR_EACH_ENTRY_SAFE(field, next_field, type->e.elements, struct hlsl_struct_field, entry) + { + d3dcompiler_free((void *)field->name); + d3dcompiler_free((void *)field->semantic); + d3dcompiler_free(field); + } + } + d3dcompiler_free(type); +} + +void free_instr_list(struct list *list) +{ + struct hlsl_ir_node *node, *next_node; + + if (!list) + return; + LIST_FOR_EACH_ENTRY_SAFE(node, next_node, list, struct hlsl_ir_node, entry) + free_instr(node); + d3dcompiler_free(list); +} + +static void free_ir_constant(struct hlsl_ir_constant *constant) +{ + struct hlsl_type *type = constant->node.data_type; + unsigned int i; + struct hlsl_ir_constant *field, *next_field; + + switch (type->type) + { + case HLSL_CLASS_ARRAY: + for (i = 0; i < type->e.array.elements_count; ++i) + free_ir_constant(&constant->v.array_elements[i]); + d3dcompiler_free(constant->v.array_elements); + break; + case HLSL_CLASS_STRUCT: + LIST_FOR_EACH_ENTRY_SAFE(field, next_field, constant->v.struct_elements, struct hlsl_ir_constant, node.entry) + free_ir_constant(field); + break; + default: + break; + } + d3dcompiler_free(constant); +} + +static void free_ir_deref(struct hlsl_ir_deref *deref) +{ + switch (deref->type) + { + case HLSL_IR_DEREF_VAR: + /* Variables are shared among nodes in the tree. */ + break; + case HLSL_IR_DEREF_ARRAY: + free_instr(deref->v.array.array); + free_instr(deref->v.array.index); + break; + case HLSL_IR_DEREF_RECORD: + free_instr(deref->v.record.record); + break; + } + d3dcompiler_free(deref); +} + +static void free_ir_swizzle(struct hlsl_ir_swizzle *swizzle) +{ + free_instr(swizzle->val); + d3dcompiler_free(swizzle); +} + +static void free_ir_constructor(struct hlsl_ir_constructor *constructor) +{ + free_instr_list(constructor->arguments); + d3dcompiler_free(constructor); +} + +static void free_ir_expr(struct hlsl_ir_expr *expr) +{ + unsigned int i; + + for (i = 0; i < 3; ++i) + { + if (!expr->operands[i]) + break; + free_instr(expr->operands[i]); + } + free_instr_list(expr->subexpressions); + d3dcompiler_free(expr); +} + +static void free_ir_assignment(struct hlsl_ir_assignment *assignment) +{ + free_instr(assignment->lhs); + free_instr(assignment->rhs); + d3dcompiler_free(assignment); +} + +static void free_ir_if(struct hlsl_ir_if *if_node) +{ + free_instr(if_node->condition); + free_instr_list(if_node->then_instrs); + free_instr_list(if_node->else_instrs); + d3dcompiler_free(if_node); +} + +static void free_ir_jump(struct hlsl_ir_jump *jump) +{ + if (jump->type == HLSL_IR_JUMP_RETURN) + free_instr(jump->return_value); + d3dcompiler_free(jump); +} + +void free_instr(struct hlsl_ir_node *node) +{ + switch (node->type) + { + case HLSL_IR_VAR: + /* These are freed later on from the scopes. */ + break; + case HLSL_IR_CONSTANT: + free_ir_constant(constant_from_node(node)); + break; + case HLSL_IR_DEREF: + free_ir_deref(deref_from_node(node)); + break; + case HLSL_IR_SWIZZLE: + free_ir_swizzle(swizzle_from_node(node)); + break; + case HLSL_IR_CONSTRUCTOR: + free_ir_constructor(constructor_from_node(node)); + break; + case HLSL_IR_EXPR: + free_ir_expr(expr_from_node(node)); + break; + case HLSL_IR_ASSIGNMENT: + free_ir_assignment(assignment_from_node(node)); + break; + case HLSL_IR_IF: + free_ir_if(if_from_node(node)); + break; + case HLSL_IR_JUMP: + free_ir_jump(jump_from_node(node)); + break; + default: + FIXME("Unsupported node type %s\n", debug_node_type(node->type)); + } +} + +static void free_function_decl(struct hlsl_ir_function_decl *func) +{ + d3dcompiler_free((void *)func->semantic); + d3dcompiler_free(func->parameters); + free_instr_list(func->body); + d3dcompiler_free(func); +} + +static void free_function_decl_rb(struct wine_rb_entry *entry, void *context) +{ + free_function_decl(WINE_RB_ENTRY_VALUE(entry, struct hlsl_ir_function_decl, entry)); +} + +static void free_function(struct hlsl_ir_function *func) +{ + wine_rb_destroy(&func->overloads, free_function_decl_rb, NULL); + d3dcompiler_free((void *)func->name); +} + +void free_function_rb(struct wine_rb_entry *entry, void *context) +{ + free_function(WINE_RB_ENTRY_VALUE(entry, struct hlsl_ir_function, entry)); +} + +void add_function_decl(struct wine_rb_tree *funcs, char *name, struct hlsl_ir_function_decl *decl, BOOL intrinsic) +{ + struct hlsl_ir_function *func; + struct wine_rb_entry *func_entry, *old_entry; + + func_entry = wine_rb_get(funcs, name); + if (func_entry) + { + func = WINE_RB_ENTRY_VALUE(func_entry, struct hlsl_ir_function, entry); + decl->func = func; + if ((old_entry = wine_rb_get(&func->overloads, decl->parameters))) + { + struct hlsl_ir_function_decl *old_decl = + WINE_RB_ENTRY_VALUE(old_entry, struct hlsl_ir_function_decl, entry); + + if (!decl->body) + { + free_function_decl(decl); + d3dcompiler_free(name); + return; + } + wine_rb_remove(&func->overloads, decl->parameters); + free_function_decl(old_decl); + } + wine_rb_put(&func->overloads, decl->parameters, &decl->entry); + d3dcompiler_free(name); + return; + } + func = d3dcompiler_alloc(sizeof(*func)); + func->name = name; + if (wine_rb_init(&func->overloads, &hlsl_ir_function_decl_rb_funcs) == -1) + { + ERR("Failed to initialize function rbtree.\n"); + d3dcompiler_free(name); + d3dcompiler_free(func); + return; + } + decl->func = func; + wine_rb_put(&func->overloads, decl->parameters, &decl->entry); + func->intrinsic = intrinsic; + wine_rb_put(funcs, func->name, &func->entry); +} diff --git a/reactos/dll/directx/wine/d3dcompiler_43/version.rc b/reactos/dll/directx/wine/d3dcompiler_43/version.rc new file mode 100644 index 00000000000..5603735acf7 --- /dev/null +++ b/reactos/dll/directx/wine/d3dcompiler_43/version.rc @@ -0,0 +1,26 @@ +/* + * Copyright 2010 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 + */ + +#define WINE_FILEDESCRIPTION_STR "Wine D3DCompiler" +#define WINE_FILENAME_STR "d3dcompiler_43.dll" +#define WINE_FILEVERSION 9,29,952,3111 +#define WINE_FILEVERSION_STR "9.29.952.3111" +#define WINE_PRODUCTVERSION 9,29,952,3111 +#define WINE_PRODUCTVERSION_STR "9.29.952.3111" + +#include "wine/wine_common_ver.rc" diff --git a/reactos/include/psdk/d3d11shader.h b/reactos/include/psdk/d3d11shader.h new file mode 100644 index 00000000000..6a0ee5137df --- /dev/null +++ b/reactos/include/psdk/d3d11shader.h @@ -0,0 +1,208 @@ +/* + * Copyright 2010 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 + */ + +#ifndef __D3D11SHADER_H__ +#define __D3D11SHADER_H__ + +#include "d3dcommon.h" + +/* These are defined as version-neutral in d3dcommon.h */ +typedef D3D_CBUFFER_TYPE D3D11_CBUFFER_TYPE; + +typedef D3D_RESOURCE_RETURN_TYPE D3D11_RESOURCE_RETURN_TYPE; + +typedef D3D_TESSELLATOR_DOMAIN D3D11_TESSELLATOR_DOMAIN; + +typedef D3D_TESSELLATOR_PARTITIONING D3D11_TESSELLATOR_PARTITIONING; + +typedef D3D_TESSELLATOR_OUTPUT_PRIMITIVE D3D11_TESSELLATOR_OUTPUT_PRIMITIVE; + +typedef struct _D3D11_SHADER_DESC +{ + UINT Version; + LPCSTR Creator; + UINT Flags; + UINT ConstantBuffers; + UINT BoundResources; + UINT InputParameters; + UINT OutputParameters; + UINT InstructionCount; + UINT TempRegisterCount; + UINT TempArrayCount; + UINT DefCount; + UINT DclCount; + UINT TextureNormalInstructions; + UINT TextureLoadInstructions; + UINT TextureCompInstructions; + UINT TextureBiasInstructions; + UINT TextureGradientInstructions; + UINT FloatInstructionCount; + UINT IntInstructionCount; + UINT UintInstructionCount; + UINT StaticFlowControlCount; + UINT DynamicFlowControlCount; + UINT MacroInstructionCount; + UINT ArrayInstructionCount; + UINT CutInstructionCount; + UINT EmitInstructionCount; + D3D_PRIMITIVE_TOPOLOGY GSOutputTopology; + UINT GSMaxOutputVertexCount; + D3D_PRIMITIVE InputPrimitive; + UINT PatchConstantParameters; + UINT cGSInstanceCount; + UINT cControlPoints; + D3D_TESSELLATOR_OUTPUT_PRIMITIVE HSOutputPrimitive; + D3D_TESSELLATOR_PARTITIONING HSPartitioning; + D3D_TESSELLATOR_DOMAIN TessellatorDomain; + UINT cBarrierInstructions; + UINT cInterlockedInstructions; + UINT cTextureStoreInstructions; +} D3D11_SHADER_DESC; + +typedef struct _D3D11_SHADER_VARIABLE_DESC +{ + LPCSTR Name; + UINT StartOffset; + UINT Size; + UINT uFlags; + LPVOID DefaultValue; + UINT StartTexture; + UINT TextureSize; + UINT StartSampler; + UINT SamplerSize; +} D3D11_SHADER_VARIABLE_DESC; + +typedef struct _D3D11_SHADER_TYPE_DESC +{ + D3D_SHADER_VARIABLE_CLASS Class; + D3D_SHADER_VARIABLE_TYPE Type; + UINT Rows; + UINT Columns; + UINT Elements; + UINT Members; + UINT Offset; + LPCSTR Name; +} D3D11_SHADER_TYPE_DESC; + +typedef struct _D3D11_SHADER_BUFFER_DESC +{ + LPCSTR Name; + D3D_CBUFFER_TYPE Type; + UINT Variables; + UINT Size; + UINT uFlags; +} D3D11_SHADER_BUFFER_DESC; + +typedef struct _D3D11_SHADER_INPUT_BIND_DESC +{ + LPCSTR Name; + D3D_SHADER_INPUT_TYPE Type; + UINT BindPoint; + UINT BindCount; + UINT uFlags; + D3D_RESOURCE_RETURN_TYPE ReturnType; + D3D_SRV_DIMENSION Dimension; + UINT NumSamples; +} D3D11_SHADER_INPUT_BIND_DESC; + +typedef struct _D3D11_SIGNATURE_PARAMETER_DESC +{ + LPCSTR SemanticName; + UINT SemanticIndex; + UINT Register; + D3D_NAME SystemValueType; + D3D_REGISTER_COMPONENT_TYPE ComponentType; + BYTE Mask; + BYTE ReadWriteMask; + UINT Stream; +} D3D11_SIGNATURE_PARAMETER_DESC; + +DEFINE_GUID(IID_ID3D11ShaderReflectionType, 0x6e6ffa6a, 0x9bae, 0x4613, 0xa5, 0x1e, 0x91, 0x65, 0x2d, 0x50, 0x8c, 0x21); + +#define INTERFACE ID3D11ShaderReflectionType +DECLARE_INTERFACE(ID3D11ShaderReflectionType) +{ + STDMETHOD(GetDesc)(THIS_ D3D11_SHADER_TYPE_DESC *desc) PURE; + STDMETHOD_(struct ID3D11ShaderReflectionType *, GetMemberTypeByIndex)(THIS_ UINT index) PURE; + STDMETHOD_(struct ID3D11ShaderReflectionType *, GetMemberTypeByName)(THIS_ LPCSTR name) PURE; + STDMETHOD_(LPCSTR, GetMemberTypeName)(THIS_ UINT index) PURE; + STDMETHOD(IsEqual)(THIS_ struct ID3D11ShaderReflectionType *type) PURE; + STDMETHOD_(struct ID3D11ShaderReflectionType *, GetSubType)(THIS) PURE; + STDMETHOD_(struct ID3D11ShaderReflectionType *, GetBaseClass)(THIS) PURE; + STDMETHOD_(UINT, GetNumInterfaces)(THIS) PURE; + STDMETHOD_(struct ID3D11ShaderReflectionType *, GetInterfaceByIndex)(THIS_ UINT index) PURE; + STDMETHOD(IsOfType)(THIS_ struct ID3D11ShaderReflectionType *type) PURE; + STDMETHOD(ImplementsInterface)(THIS_ ID3D11ShaderReflectionType *base) PURE; +}; +#undef INTERFACE + +DEFINE_GUID(IID_ID3D11ShaderReflectionVariable, 0x51f23923, 0xf3e5, 0x4bd1, 0x91, 0xcb, 0x60, 0x61, 0x77, 0xd8, 0xdb, 0x4c); + +#define INTERFACE ID3D11ShaderReflectionVariable +DECLARE_INTERFACE(ID3D11ShaderReflectionVariable) +{ + STDMETHOD(GetDesc)(THIS_ D3D11_SHADER_VARIABLE_DESC *desc) PURE; + STDMETHOD_(struct ID3D11ShaderReflectionType *, GetType)(THIS) PURE; + STDMETHOD_(struct ID3D11ShaderReflectionConstantBuffer *, GetBuffer)(THIS) PURE; + STDMETHOD_(UINT, GetInterfaceSlot)(THIS_ UINT index) PURE; +}; +#undef INTERFACE + +DEFINE_GUID(IID_ID3D11ShaderReflectionConstantBuffer, 0xeb62d63d, 0x93dd, 0x4318, 0x8a, 0xe8, 0xc6, 0xf8, 0x3a, 0xd3, 0x71, 0xb8); + +#define INTERFACE ID3D11ShaderReflectionConstantBuffer +DECLARE_INTERFACE(ID3D11ShaderReflectionConstantBuffer) +{ + STDMETHOD(GetDesc)(THIS_ D3D11_SHADER_BUFFER_DESC *desc) PURE; + STDMETHOD_(struct ID3D11ShaderReflectionVariable *, GetVariableByIndex)(THIS_ UINT index) PURE; + STDMETHOD_(struct ID3D11ShaderReflectionVariable *, GetVariableByName)(THIS_ LPCSTR name) PURE; +}; +#undef INTERFACE + +DEFINE_GUID(IID_ID3D11ShaderReflection, 0x0a233719, 0x3960, 0x4578, 0x9d, 0x7c, 0x20, 0x3b, 0x8b, 0x1d, 0x9c, 0xc1); + +#define INTERFACE ID3D11ShaderReflection +DECLARE_INTERFACE_(ID3D11ShaderReflection, IUnknown) +{ + /* IUnknown methods */ + STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID *object) PURE; + STDMETHOD_(ULONG, AddRef)(THIS) PURE; + STDMETHOD_(ULONG, Release)(THIS) PURE; + /* ID3D11ShaderReflection methods */ + STDMETHOD(GetDesc)(THIS_ D3D11_SHADER_DESC *desc) PURE; + STDMETHOD_(struct ID3D11ShaderReflectionConstantBuffer *, GetConstantBufferByIndex)(THIS_ UINT index) PURE; + STDMETHOD_(struct ID3D11ShaderReflectionConstantBuffer *, GetConstantBufferByName)(THIS_ LPCSTR name) PURE; + STDMETHOD(GetResourceBindingDesc)(THIS_ UINT index, D3D11_SHADER_INPUT_BIND_DESC *desc) PURE; + STDMETHOD(GetInputParameterDesc)(THIS_ UINT index, D3D11_SIGNATURE_PARAMETER_DESC *desc) PURE; + STDMETHOD(GetOutputParameterDesc)(THIS_ UINT index, D3D11_SIGNATURE_PARAMETER_DESC *desc) PURE; + STDMETHOD(GetPatchConstantParameterDesc)(THIS_ UINT index, D3D11_SIGNATURE_PARAMETER_DESC *desc) PURE; + STDMETHOD_(struct ID3D11ShaderReflectionVariable *, GetVariableByName)(THIS_ LPCSTR name) PURE; + STDMETHOD(GetResourceBindingDescByName)(THIS_ LPCSTR name, D3D11_SHADER_INPUT_BIND_DESC *desc) PURE; + STDMETHOD_(UINT, GetMovInstructionCount)(THIS) PURE; + STDMETHOD_(UINT, GetMovcInstructionCount)(THIS) PURE; + STDMETHOD_(UINT, GetConversionInstructionCount)(THIS) PURE; + STDMETHOD_(UINT, GetBitwiseInstructionCount)(THIS) PURE; + STDMETHOD_(D3D_PRIMITIVE, GetGSInputPrimitive)(THIS) PURE; + STDMETHOD_(BOOL, IsSampleFrequencyShader)(THIS) PURE; + STDMETHOD_(UINT, GetNumInterfaceSlots)(THIS) PURE; + STDMETHOD(GetMinFeatureLevel)(THIS_ enum D3D_FEATURE_LEVEL *level) PURE; + STDMETHOD_(UINT, GetThreadGroupSize)(THIS_ UINT *sizex, UINT *sizey, UINT *sizez) PURE; +}; +#undef INTERFACE + +#endif diff --git a/reactos/include/psdk/d3d9types.h b/reactos/include/psdk/d3d9types.h index 7b338da74bb..9c7c57cc170 100644 --- a/reactos/include/psdk/d3d9types.h +++ b/reactos/include/psdk/d3d9types.h @@ -461,6 +461,9 @@ typedef enum _D3DSHADER_INSTRUCTION_OPCODE_TYPE { #define D3DSHADER_INSTRUCTION_PREDICATED (1 << 28) +#define D3DSI_TEXLD_PROJECT 0x00010000 +#define D3DSI_TEXLD_BIAS 0x00020000 + /** for parallelism */ #define D3DSI_COISSUE 0x40000000 @@ -1586,6 +1589,19 @@ typedef enum _D3DCOMPOSERECTSOP{ } D3DCOMPOSERECTSOP; #endif /* D3D_DISABLE_9EX */ +typedef enum _D3DSHADER_COMPARISON +{ + D3DSPC_RESERVED0 = 0, + D3DSPC_GT, + D3DSPC_EQ, + D3DSPC_GE, + D3DSPC_LT, + D3DSPC_NE, + D3DSPC_LE, + D3DSPC_RESERVED1, +} D3DSHADER_COMPARISON; + + #pragma pack(pop) #endif /* DIRECT3D_VERSION >= 0x0900 */ diff --git a/reactos/include/psdk/d3dcompiler.h b/reactos/include/psdk/d3dcompiler.h new file mode 100644 index 00000000000..4bbf53fd69f --- /dev/null +++ b/reactos/include/psdk/d3dcompiler.h @@ -0,0 +1,123 @@ +/* + * Copyright 2010 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 + */ + +#ifndef __D3DCOMPILER_H__ +#define __D3DCOMPILER_H__ + +#include "d3d11shader.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined(__GNUC__) +#define D3DCOMPILER_DLL_W (const WCHAR[]){'d','3','d','c','o','m','p','i','l','e','r','_','4','3','.','d','l','l',0} +#elif defined(_MSC_VER) +#define D3DCOMPILER_DLL_W L"d3dcompiler_43.dll" +#else +static const WCHAR D3DCOMPILER_DLL_W[] = {'d','3','d','c','o','m','p','i','l','e','r','_','4','3','.','d','l','l',0}; +#endif + +#define D3DCOMPILER_DLL_A "d3dcompiler_43.dll" +#define D3DCOMPILER_DLL WINELIB_NAME_AW(D3DCOMPILER_DLL_) + +#define D3DCOMPILE_DEBUG 0x00000001 +#define D3DCOMPILE_SKIP_VALIDATION 0x00000002 +#define D3DCOMPILE_SKIP_OPTIMIZATION 0x00000004 +#define D3DCOMPILE_PACK_MATRIX_ROW_MAJOR 0x00000008 +#define D3DCOMPILE_PACK_MATRIX_COLUMN_MAJOR 0x00000010 +#define D3DCOMPILE_PARTIAL_PRECISION 0x00000020 +#define D3DCOMPILE_FORCE_VS_SOFTWARE_NO_OPT 0x00000040 +#define D3DCOMPILE_FORCE_PS_SOFTWARE_NO_OPT 0x00000080 +#define D3DCOMPILE_NO_PRESHADER 0x00000100 +#define D3DCOMPILE_AVOID_FLOW_CONTROL 0x00000200 +#define D3DCOMPILE_PREFER_FLOW_CONTROL 0x00000400 +#define D3DCOMPILE_ENABLE_STRICTNESS 0x00000800 +#define D3DCOMPILE_ENABLE_BACKWARDS_COMPATIBILITY 0x00001000 +#define D3DCOMPILE_IEEE_STRICTNESS 0x00002000 +#define D3DCOMPILE_OPTIMIZATION_LEVEL0 0x00004000 +#define D3DCOMPILE_OPTIMIZATION_LEVEL1 0x00000000 +#define D3DCOMPILE_OPTIMIZATION_LEVEL2 0x0000c000 +#define D3DCOMPILE_OPTIMIZATION_LEVEL3 0x00008000 +#define D3DCOMPILE_WARNINGS_ARE_ERRORS 0x00040000 + +#define D3D_DISASM_ENABLE_COLOR_CODE 0x00000001 +#define D3D_DISASM_ENABLE_DEFAULT_VALUE_PRINTS 0x00000002 +#define D3D_DISASM_ENABLE_INSTRUCTION_NUMBERING 0x00000004 +#define D3D_DISASM_ENABLE_INSTRUCTION_CYCLE 0x00000008 +#define D3D_DISASM_DISABLE_DEBUG_INFO 0x00000010 + +HRESULT WINAPI D3DCompile(const void *data, SIZE_T data_size, const char *filename, + const D3D_SHADER_MACRO *defines, ID3DInclude *include, const char *entrypoint, + const char *target, UINT sflags, UINT eflags, ID3DBlob **shader, ID3DBlob **error_messages); +typedef HRESULT (WINAPI *pD3DCompile)(const void *data, SIZE_T data_size, const char *filename, + const D3D_SHADER_MACRO *defines, ID3DInclude *include, const char *entrypoint, + const char *target, UINT sflags, UINT eflags, ID3DBlob **shader, ID3DBlob **error_messages); + +typedef enum D3DCOMPILER_STRIP_FLAGS +{ + D3DCOMPILER_STRIP_REFLECTION_DATA = 1, + D3DCOMPILER_STRIP_DEBUG_INFO = 2, + D3DCOMPILER_STRIP_TEST_BLOBS = 4, + D3DCOMPILER_STRIP_FORCE_DWORD = 0x7fffffff +} D3DCOMPILER_STRIP_FLAGS; + +HRESULT WINAPI D3DStripShader(const void *data, SIZE_T data_size, UINT flags, ID3DBlob **blob); + +typedef enum D3D_BLOB_PART +{ + D3D_BLOB_INPUT_SIGNATURE_BLOB, + D3D_BLOB_OUTPUT_SIGNATURE_BLOB, + D3D_BLOB_INPUT_AND_OUTPUT_SIGNATURE_BLOB, + D3D_BLOB_PATCH_CONSTANT_SIGNATURE_BLOB, + D3D_BLOB_ALL_SIGNATURE_BLOB, + D3D_BLOB_DEBUG_INFO, + D3D_BLOB_LEGACY_SHADER, + D3D_BLOB_XNA_PREPASS_SHADER, + D3D_BLOB_XNA_SHADER, + D3D_BLOB_TEST_ALTERNATE_SHADER = 0x8000, + D3D_BLOB_TEST_COMPILE_DETAILS, + D3D_BLOB_TEST_COMPILE_PERF +} D3D_BLOB_PART; + +HRESULT WINAPI D3DDisassemble(const void *data, SIZE_T data_size, + UINT flags, const char *comments, ID3DBlob **disassembly); +typedef HRESULT (WINAPI *pD3DDisassemble)(const void *data, SIZE_T data_size, + UINT flags, const char *comments, ID3DBlob **disassembly); +HRESULT WINAPI D3DGetBlobPart(const void *data, SIZE_T data_size, D3D_BLOB_PART part, UINT flags, ID3DBlob **blob); +HRESULT WINAPI D3DGetInputSignatureBlob(const void *data, SIZE_T data_size, ID3DBlob **blob); +HRESULT WINAPI D3DGetOutputSignatureBlob(const void *data, SIZE_T data_size, ID3DBlob **blob); +HRESULT WINAPI D3DGetInputAndOutputSignatureBlob(const void *data, SIZE_T data_size, ID3DBlob **blob); +HRESULT WINAPI D3DGetDebugInfo(const void *data, SIZE_T data_size, ID3DBlob **blob); + +HRESULT WINAPI D3DReflect(const void *data, SIZE_T data_size, REFIID riid, void **reflector); + +HRESULT WINAPI D3DCreateBlob(SIZE_T data_size, ID3DBlob **blob); + +HRESULT WINAPI D3DPreprocess(const void *data, SIZE_T size, const char *filename, + const D3D_SHADER_MACRO *defines, ID3DInclude *include, + ID3DBlob **shader, ID3DBlob **error_messages); +typedef HRESULT (WINAPI *pD3DPreprocess)(const void *data, SIZE_T size, const char *filename, + const D3D_SHADER_MACRO *defines, ID3DInclude *include, + ID3DBlob **shader, ID3DBlob **error_messages); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/reactos/lib/sdk/dxguid/CMakeLists.txt b/reactos/lib/sdk/dxguid/CMakeLists.txt index 9cbcaecc3c7..cb67c521f42 100644 --- a/reactos/lib/sdk/dxguid/CMakeLists.txt +++ b/reactos/lib/sdk/dxguid/CMakeLists.txt @@ -1,2 +1,3 @@ add_library(dxguid dxguid-mingw.c) +add_library(dx10guid dx10guid.c) diff --git a/reactos/lib/sdk/dxguid/dx10guid.c b/reactos/lib/sdk/dxguid/dx10guid.c new file mode 100644 index 00000000000..e2938ba08c2 --- /dev/null +++ b/reactos/lib/sdk/dxguid/dx10guid.c @@ -0,0 +1,40 @@ +/* + * DirectX 10 GUID definitions + * + * Copyright 2000 Alexandre Julliard + * Copyright 2000 Francois Gouget + * Copyright 2003 Raphael Junqueira + * + * 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 + +#include "windef.h" +#include "winbase.h" +#include "wingdi.h" +#include "winuser.h" + +#include "objbase.h" +#include "olectl.h" +#include "initguid.h" + +#if 0 +#include "d3d10_1.h" +#include "d3d11.h" +#include "d3d10_1shader.h" +#endif + +#include "d3d11shader.h" diff --git a/reactos/media/doc/README.WINE b/reactos/media/doc/README.WINE index 20b423dba2c..89c00374683 100644 --- a/reactos/media/doc/README.WINE +++ b/reactos/media/doc/README.WINE @@ -27,23 +27,25 @@ reactos/tools/wpp # Synced to Wine-1.7.1 The following libraries are shared with Wine. -reactos/dll/directx/amstream # Synced to Wine-1.3.37 -reactos/dll/directx/dinput # Synced to Wine-1.5.26 -reactos/dll/directx/dinput8 # Synced to Wine-1.5.26 -reactos/dll/directx/dmusic # Synced to Wine-1.5.26 -reactos/dll/directx/dplay # Synced to Wine-1.5.26 -reactos/dll/directx/dplayx # Synced to Wine-1.5.26 -reactos/dll/directx/dsound # Synced to Wine-1.5.26 -reactos/dll/directx/dxdiagn # Synced to Wine-0_9_5 -reactos/dll/directx/dxgi # Synced to Wine-1.7.1 -reactos/dll/directx/msdmo # Autosync -reactos/dll/directx/qedit # Autosync -reactos/dll/directx/quartz # Synced to Wine-1.5.26 -reactos/dll/directx/wine/d3d8 # Synced to Wine-1.7.1 -reactos/dll/directx/wine/d3d9 # Synced to Wine-1.7.1 -reactos/dll/directx/wine/d3dxof # Synced to Wine-1.7.1 -reactos/dll/directx/wine/ddraw # Synced to Wine-1.7.1 -reactos/dll/directx/wine/wined3d # Synced to Wine-1.7.1 +reactos/dll/directx/amstream # Synced to Wine-1.3.37 +reactos/dll/directx/dinput # Synced to Wine-1.5.26 +reactos/dll/directx/dinput8 # Synced to Wine-1.5.26 +reactos/dll/directx/dmusic # Synced to Wine-1.5.26 +reactos/dll/directx/dplay # Synced to Wine-1.5.26 +reactos/dll/directx/dplayx # Synced to Wine-1.5.26 +reactos/dll/directx/dsound # Synced to Wine-1.5.26 +reactos/dll/directx/dxdiagn # Synced to Wine-0_9_5 +reactos/dll/directx/dxgi # Synced to Wine-1.7.1 +reactos/dll/directx/msdmo # Autosync +reactos/dll/directx/qedit # Autosync +reactos/dll/directx/quartz # Synced to Wine-1.5.26 +reactos/dll/directx/wine/d3d8 # Synced to Wine-1.7.1 +reactos/dll/directx/wine/d3d9 # Synced to Wine-1.7.1 +reactos/dll/directx/wine/d3dcompiler_43 # Synced to Wine-1.7.1 +reactos/dll/directx/wine/d3dxof # Synced to Wine-1.7.1 +reactos/dll/directx/wine/ddraw # Synced to Wine-1.7.1 +reactos/dll/directx/wine/wined3d # Synced to Wine-1.7.1 + reactos/dll/win32/activeds # Synced to Wine-1.1.43? reactos/dll/win32/actxprxy # Synced to Wine-1.5.26 reactos/dll/win32/advpack # Synced to Wine-1.7.1 diff --git a/reactos/tools/widl/CMakeLists.txt b/reactos/tools/widl/CMakeLists.txt index 1fb4c413970..3d9cba2b5f7 100644 --- a/reactos/tools/widl/CMakeLists.txt +++ b/reactos/tools/widl/CMakeLists.txt @@ -35,4 +35,4 @@ add_definitions(-DINT16=SHORT) add_executable(widl ${SOURCE}) -target_link_libraries(widl wpp) +target_link_libraries(widl wpphost) diff --git a/reactos/tools/wpp/CMakeLists.txt b/reactos/tools/wpp/CMakeLists.txt index 124aa202f74..424e3a72c53 100644 --- a/reactos/tools/wpp/CMakeLists.txt +++ b/reactos/tools/wpp/CMakeLists.txt @@ -12,12 +12,27 @@ if(MSVC) endif() endif() +if(CMAKE_CROSSCOMPILING) + add_definitions( + -D_DLL -D__USE_CRTIMP + -D__NO_ISOCEXT + -Dstrtoull=_strtoui64 + -Dstrtoll=_strtoi64 + -Dopen=_open + -Dclose=_close) + + include_directories(${REACTOS_SOURCE_DIR}/include/reactos/wine) +endif() + list(APPEND SOURCE preproc.c wpp.c ppl.yy.c ppy.tab.c) -add_library(wpp ${SOURCE}) - -add_dependencies(wpp build_header) +if(CMAKE_CROSSCOMPILING) + add_library(wpp ${SOURCE}) +else() + add_library(wpphost ${SOURCE}) + add_dependencies(wpphost build_header) +endif()