2012-05-15 16:12:56 +02:00
|
|
|
/*
|
|
|
|
* 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 "wine/debug.h"
|
|
|
|
|
2020-03-30 04:53:17 +02:00
|
|
|
#include <limits.h>
|
2012-05-15 16:12:56 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "d3dcompiler_private.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(hlsl_parser);
|
|
|
|
|
2012-05-15 16:12:57 +02:00
|
|
|
int hlsl_lex(void);
|
2012-05-15 16:12:56 +02:00
|
|
|
|
|
|
|
struct hlsl_parse_ctx hlsl_ctx;
|
|
|
|
|
2012-07-12 16:01:35 +02:00
|
|
|
struct YYLTYPE;
|
2020-03-04 03:29:46 +01:00
|
|
|
static struct source_location get_location(const struct YYLTYPE *l);
|
2012-07-12 16:01:35 +02:00
|
|
|
|
2019-07-07 08:02:55 +02:00
|
|
|
void WINAPIV hlsl_message(const char *fmt, ...)
|
2012-05-15 16:12:56 +02:00
|
|
|
{
|
2019-07-02 13:37:18 +02:00
|
|
|
__ms_va_list args;
|
2012-05-15 16:12:56 +02:00
|
|
|
|
2019-07-02 13:37:18 +02:00
|
|
|
__ms_va_start(args, fmt);
|
2012-05-15 16:12:56 +02:00
|
|
|
compilation_message(&hlsl_ctx.messages, fmt, args);
|
2019-07-02 13:37:18 +02:00
|
|
|
__ms_va_end(args);
|
2012-05-15 16:12:56 +02:00
|
|
|
}
|
|
|
|
|
2012-07-12 16:01:32 +02:00
|
|
|
static const char *hlsl_get_error_level_name(enum hlsl_error_level level)
|
|
|
|
{
|
2014-05-02 12:50:18 +02:00
|
|
|
static const char * const names[] =
|
2012-07-12 16:01:32 +02:00
|
|
|
{
|
|
|
|
"error",
|
|
|
|
"warning",
|
|
|
|
"note",
|
|
|
|
};
|
|
|
|
return names[level];
|
|
|
|
}
|
|
|
|
|
2020-03-04 03:29:47 +01:00
|
|
|
void WINAPIV hlsl_report_message(const struct source_location loc,
|
2012-07-12 16:01:32 +02:00
|
|
|
enum hlsl_error_level level, const char *fmt, ...)
|
|
|
|
{
|
2019-07-02 13:37:18 +02:00
|
|
|
__ms_va_list args;
|
2012-07-12 16:01:32 +02:00
|
|
|
char *string = NULL;
|
|
|
|
int rc, size = 0;
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
2019-07-02 13:37:18 +02:00
|
|
|
__ms_va_start(args, fmt);
|
2012-07-12 16:01:32 +02:00
|
|
|
rc = vsnprintf(string, size, fmt, args);
|
2019-07-02 13:37:18 +02:00
|
|
|
__ms_va_end(args);
|
2012-07-12 16:01:32 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-04 03:29:47 +01:00
|
|
|
hlsl_message("%s:%u:%u: %s: %s\n", loc.file, loc.line, loc.col,
|
|
|
|
hlsl_get_error_level_name(level), string);
|
2012-07-12 16:01:32 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2012-05-15 16:12:56 +02:00
|
|
|
static void hlsl_error(const char *s)
|
|
|
|
{
|
2020-03-04 03:29:47 +01:00
|
|
|
const struct source_location loc =
|
|
|
|
{
|
|
|
|
.file = hlsl_ctx.source_file,
|
|
|
|
.line = hlsl_ctx.line_no,
|
|
|
|
.col = hlsl_ctx.column,
|
|
|
|
};
|
|
|
|
hlsl_report_message(loc, HLSL_LEVEL_ERROR, "%s", s);
|
2012-05-15 16:12:56 +02:00
|
|
|
}
|
|
|
|
|
2012-06-04 17:58:24 +02:00
|
|
|
static void debug_dump_decl(struct hlsl_type *type, DWORD modifiers, const char *declname, unsigned int line_no)
|
|
|
|
{
|
|
|
|
TRACE("Line %u: ", line_no);
|
2012-06-07 00:19:03 +02:00
|
|
|
if (modifiers)
|
|
|
|
TRACE("%s ", debug_modifiers(modifiers));
|
2012-06-04 17:58:24 +02:00
|
|
|
TRACE("%s %s;\n", debug_hlsl_type(type), declname);
|
|
|
|
}
|
|
|
|
|
2020-03-04 03:29:50 +01:00
|
|
|
static void check_invalid_matrix_modifiers(DWORD modifiers, struct source_location loc)
|
2012-07-18 16:25:11 +02:00
|
|
|
{
|
2020-03-15 22:25:11 +01:00
|
|
|
if (modifiers & HLSL_MODIFIERS_MAJORITY_MASK)
|
2012-07-18 16:25:11 +02:00
|
|
|
{
|
2020-03-04 03:29:50 +01:00
|
|
|
hlsl_report_message(loc, HLSL_LEVEL_ERROR,
|
2012-07-18 16:25:11 +02:00
|
|
|
"'row_major' or 'column_major' modifiers are only allowed for matrices");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-04 22:03:42 +02:00
|
|
|
static BOOL type_is_single_reg(const struct hlsl_type *type)
|
|
|
|
{
|
|
|
|
return type->type == HLSL_CLASS_SCALAR || type->type == HLSL_CLASS_VECTOR;
|
|
|
|
}
|
|
|
|
|
2012-06-04 17:58:24 +02:00
|
|
|
static BOOL declare_variable(struct hlsl_ir_var *decl, BOOL local)
|
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
TRACE("Declaring variable %s.\n", decl->name);
|
2020-03-13 17:34:54 +01:00
|
|
|
if (decl->data_type->type != HLSL_CLASS_MATRIX)
|
2020-03-04 03:29:50 +01:00
|
|
|
check_invalid_matrix_modifiers(decl->modifiers, decl->loc);
|
2012-07-18 16:25:11 +02:00
|
|
|
|
2012-06-07 00:19:03 +02:00
|
|
|
if (local)
|
|
|
|
{
|
|
|
|
DWORD invalid = decl->modifiers & (HLSL_STORAGE_EXTERN | HLSL_STORAGE_SHARED
|
|
|
|
| HLSL_STORAGE_GROUPSHARED | HLSL_STORAGE_UNIFORM);
|
|
|
|
if (invalid)
|
|
|
|
{
|
2020-03-04 03:29:47 +01:00
|
|
|
hlsl_report_message(decl->loc, HLSL_LEVEL_ERROR,
|
2012-07-12 16:01:35 +02:00
|
|
|
"modifier '%s' invalid for local variables", debug_modifiers(invalid));
|
2012-06-07 00:19:03 +02:00
|
|
|
}
|
2012-07-18 16:25:13 +02:00
|
|
|
if (decl->semantic)
|
|
|
|
{
|
2020-03-04 03:29:47 +01:00
|
|
|
hlsl_report_message(decl->loc, HLSL_LEVEL_ERROR,
|
2012-07-18 16:25:13 +02:00
|
|
|
"semantics are not allowed on local variables");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2012-06-07 00:19:03 +02:00
|
|
|
}
|
2012-07-16 20:39:21 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (find_function(decl->name))
|
|
|
|
{
|
2020-03-04 03:29:47 +01:00
|
|
|
hlsl_report_message(decl->loc, HLSL_LEVEL_ERROR, "redefinition of '%s'", decl->name);
|
2012-07-16 20:39:21 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2012-06-04 17:58:24 +02:00
|
|
|
ret = add_declaration(hlsl_ctx.cur_scope, decl, local);
|
2012-07-16 20:39:21 +02:00
|
|
|
if (!ret)
|
2012-06-04 17:58:24 +02:00
|
|
|
{
|
|
|
|
struct hlsl_ir_var *old = get_variable(hlsl_ctx.cur_scope, decl->name);
|
|
|
|
|
2020-03-04 03:29:47 +01:00
|
|
|
hlsl_report_message(decl->loc, HLSL_LEVEL_ERROR, "\"%s\" already declared", decl->name);
|
|
|
|
hlsl_report_message(old->loc, HLSL_LEVEL_NOTE, "\"%s\" was previously declared here", old->name);
|
2012-06-04 17:58:24 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2020-03-13 17:34:56 +01:00
|
|
|
static DWORD add_modifiers(DWORD modifiers, DWORD mod, const struct source_location loc)
|
|
|
|
{
|
|
|
|
if (modifiers & mod)
|
|
|
|
{
|
|
|
|
hlsl_report_message(loc, HLSL_LEVEL_ERROR, "modifier '%s' already specified", debug_modifiers(mod));
|
|
|
|
return modifiers;
|
|
|
|
}
|
2020-03-15 22:25:11 +01:00
|
|
|
if ((mod & HLSL_MODIFIERS_MAJORITY_MASK) && (modifiers & HLSL_MODIFIERS_MAJORITY_MASK))
|
2020-03-13 17:34:56 +01:00
|
|
|
{
|
|
|
|
hlsl_report_message(loc, HLSL_LEVEL_ERROR, "more than one matrix majority keyword");
|
|
|
|
return modifiers;
|
|
|
|
}
|
|
|
|
return modifiers | mod;
|
|
|
|
}
|
2012-06-07 00:19:03 +02:00
|
|
|
|
2012-09-19 20:12:17 +02:00
|
|
|
static BOOL add_type_to_scope(struct hlsl_scope *scope, struct hlsl_type *def)
|
2012-09-18 18:18:05 +02:00
|
|
|
{
|
|
|
|
if (get_type(scope, def->name, FALSE))
|
|
|
|
return FALSE;
|
|
|
|
|
2012-09-19 19:46:12 +02:00
|
|
|
wine_rb_put(&scope->types, def->name, &def->scope_entry);
|
2012-09-18 18:18:05 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void declare_predefined_types(struct hlsl_scope *scope)
|
|
|
|
{
|
|
|
|
struct hlsl_type *type;
|
|
|
|
unsigned int x, y, bt;
|
2014-05-02 12:50:18 +02:00
|
|
|
static const char * const names[] =
|
2012-09-18 18:18:05 +02:00
|
|
|
{
|
|
|
|
"float",
|
|
|
|
"half",
|
|
|
|
"double",
|
|
|
|
"int",
|
|
|
|
"uint",
|
|
|
|
"bool",
|
|
|
|
};
|
|
|
|
char name[10];
|
|
|
|
|
2020-06-02 00:58:41 +02:00
|
|
|
static const char *const sampler_names[] =
|
|
|
|
{
|
|
|
|
"sampler",
|
|
|
|
"sampler1D",
|
|
|
|
"sampler2D",
|
|
|
|
"sampler3D",
|
|
|
|
"samplerCUBE"
|
|
|
|
};
|
|
|
|
|
2012-09-18 18:18:05 +02:00
|
|
|
for (bt = 0; bt <= HLSL_TYPE_LAST_SCALAR; ++bt)
|
|
|
|
{
|
|
|
|
for (y = 1; y <= 4; ++y)
|
|
|
|
{
|
|
|
|
for (x = 1; x <= 4; ++x)
|
|
|
|
{
|
2020-04-30 04:54:39 +02:00
|
|
|
sprintf(name, "%s%ux%u", names[bt], y, x);
|
2012-09-18 18:18:05 +02:00
|
|
|
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);
|
2020-06-11 21:44:10 +02:00
|
|
|
hlsl_ctx.builtin_types.vector[bt][x - 1] = type;
|
2012-09-18 18:18:05 +02:00
|
|
|
|
|
|
|
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);
|
2020-06-02 00:58:41 +02:00
|
|
|
hlsl_ctx.builtin_types.scalar[bt] = type;
|
2012-09-18 18:18:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-02 00:58:41 +02:00
|
|
|
for (bt = 0; bt <= HLSL_SAMPLER_DIM_MAX; ++bt)
|
|
|
|
{
|
|
|
|
type = new_hlsl_type(d3dcompiler_strdup(sampler_names[bt]), HLSL_CLASS_OBJECT, HLSL_TYPE_SAMPLER, 1, 1);
|
|
|
|
type->sampler_dim = bt;
|
|
|
|
hlsl_ctx.builtin_types.sampler[bt] = type;
|
|
|
|
}
|
|
|
|
|
|
|
|
hlsl_ctx.builtin_types.Void = new_hlsl_type(d3dcompiler_strdup("void"), HLSL_CLASS_OBJECT, HLSL_TYPE_VOID, 1, 1);
|
|
|
|
|
2012-09-18 18:18:05 +02:00
|
|
|
/* 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);
|
|
|
|
}
|
|
|
|
|
2020-06-02 00:58:45 +02:00
|
|
|
static BOOL type_is_void(const struct hlsl_type *type)
|
|
|
|
{
|
|
|
|
return type->type == HLSL_CLASS_OBJECT && type->base_type == HLSL_TYPE_VOID;
|
|
|
|
}
|
|
|
|
|
2020-07-07 23:09:24 +02:00
|
|
|
static struct hlsl_ir_if *new_if(struct hlsl_ir_node *condition, struct source_location loc)
|
|
|
|
{
|
|
|
|
struct hlsl_ir_if *iff;
|
|
|
|
|
|
|
|
if (!(iff = d3dcompiler_alloc(sizeof(*iff))))
|
|
|
|
return NULL;
|
|
|
|
init_node(&iff->node, HLSL_IR_IF, NULL, loc);
|
|
|
|
hlsl_src_from_node(&iff->condition, condition);
|
|
|
|
list_init(&iff->then_instrs);
|
|
|
|
list_init(&iff->else_instrs);
|
|
|
|
return iff;
|
|
|
|
}
|
|
|
|
|
2020-02-13 04:57:18 +01:00
|
|
|
static BOOL append_conditional_break(struct list *cond_list)
|
2012-09-21 16:25:56 +02:00
|
|
|
{
|
2020-02-13 04:57:18 +01:00
|
|
|
struct hlsl_ir_node *condition, *not;
|
2012-09-21 16:25:56 +02:00
|
|
|
struct hlsl_ir_jump *jump;
|
2020-02-13 04:57:18 +01:00
|
|
|
struct hlsl_ir_if *iff;
|
2012-09-21 16:25:56 +02:00
|
|
|
|
2020-02-13 04:57:18 +01:00
|
|
|
/* E.g. "for (i = 0; ; ++i)". */
|
|
|
|
if (!list_count(cond_list))
|
|
|
|
return TRUE;
|
2012-09-21 16:25:56 +02:00
|
|
|
|
2020-02-13 04:57:18 +01:00
|
|
|
condition = node_from_list(cond_list);
|
|
|
|
if (!(not = new_unary_expr(HLSL_IR_UNOP_LOGIC_NOT, condition, condition->loc)))
|
2012-09-21 16:25:56 +02:00
|
|
|
{
|
|
|
|
ERR("Out of memory.\n");
|
2020-02-13 04:57:18 +01:00
|
|
|
return FALSE;
|
2012-09-21 16:25:56 +02:00
|
|
|
}
|
2020-02-13 04:57:18 +01:00
|
|
|
list_add_tail(cond_list, ¬->entry);
|
|
|
|
|
2020-07-07 23:09:24 +02:00
|
|
|
if (!(iff = new_if(not, condition->loc)))
|
2012-09-21 16:25:56 +02:00
|
|
|
{
|
|
|
|
ERR("Out of memory.\n");
|
2020-02-13 04:57:18 +01:00
|
|
|
return FALSE;
|
2012-09-21 16:25:56 +02:00
|
|
|
}
|
2020-02-13 04:57:18 +01:00
|
|
|
list_add_tail(cond_list, &iff->node.entry);
|
|
|
|
|
|
|
|
if (!(jump = d3dcompiler_alloc(sizeof(*jump))))
|
2012-09-21 16:25:56 +02:00
|
|
|
{
|
|
|
|
ERR("Out of memory.\n");
|
2020-02-13 04:57:18 +01:00
|
|
|
return FALSE;
|
2012-09-21 16:25:56 +02:00
|
|
|
}
|
2020-05-01 06:54:23 +02:00
|
|
|
init_node(&jump->node, HLSL_IR_JUMP, NULL, condition->loc);
|
2020-02-13 04:57:18 +01:00
|
|
|
jump->type = HLSL_IR_JUMP_BREAK;
|
2020-07-07 23:09:24 +02:00
|
|
|
list_add_head(&iff->then_instrs, &jump->node.entry);
|
2020-02-13 04:57:18 +01:00
|
|
|
return TRUE;
|
2012-09-21 16:25:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
2020-03-04 03:29:51 +01:00
|
|
|
struct list *iter, struct list *body, struct source_location loc)
|
2012-09-21 16:25:56 +02:00
|
|
|
{
|
|
|
|
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;
|
2020-05-01 06:54:23 +02:00
|
|
|
init_node(&loop->node, HLSL_IR_LOOP, NULL, loc);
|
2012-09-21 16:25:56 +02:00
|
|
|
list_add_tail(list, &loop->node.entry);
|
2020-07-06 00:45:36 +02:00
|
|
|
list_init(&loop->body);
|
2012-09-21 16:25:56 +02:00
|
|
|
|
2020-02-13 04:57:18 +01:00
|
|
|
if (!append_conditional_break(cond))
|
2012-09-21 16:25:56 +02:00
|
|
|
goto oom;
|
|
|
|
|
|
|
|
if (type != LOOP_DO_WHILE)
|
2020-07-06 00:45:36 +02:00
|
|
|
list_move_tail(&loop->body, cond);
|
2012-09-21 16:25:56 +02:00
|
|
|
|
2020-07-06 00:45:36 +02:00
|
|
|
list_move_tail(&loop->body, body);
|
2012-09-21 16:25:56 +02:00
|
|
|
|
|
|
|
if (iter)
|
2020-07-06 00:45:36 +02:00
|
|
|
list_move_tail(&loop->body, iter);
|
2012-09-21 16:25:56 +02:00
|
|
|
|
|
|
|
if (type == LOOP_DO_WHILE)
|
2020-07-06 00:45:36 +02:00
|
|
|
list_move_tail(&loop->body, cond);
|
2012-09-21 16:25:56 +02:00
|
|
|
|
|
|
|
d3dcompiler_free(init);
|
|
|
|
d3dcompiler_free(cond);
|
|
|
|
d3dcompiler_free(body);
|
|
|
|
return list;
|
|
|
|
|
|
|
|
oom:
|
|
|
|
ERR("Out of memory.\n");
|
|
|
|
d3dcompiler_free(loop);
|
|
|
|
d3dcompiler_free(cond_jump);
|
|
|
|
d3dcompiler_free(list);
|
|
|
|
free_instr_list(init);
|
|
|
|
free_instr_list(cond);
|
2020-02-13 04:57:18 +01:00
|
|
|
free_instr_list(iter);
|
2012-09-21 16:25:56 +02:00
|
|
|
free_instr_list(body);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-08-12 17:27:28 +02:00
|
|
|
static unsigned int initializer_size(const struct parse_initializer *initializer)
|
2012-09-19 19:46:14 +02:00
|
|
|
{
|
2019-08-12 17:27:28 +02:00
|
|
|
unsigned int count = 0, i;
|
2012-09-19 19:46:14 +02:00
|
|
|
|
2019-08-12 17:27:28 +02:00
|
|
|
for (i = 0; i < initializer->args_count; ++i)
|
2012-09-19 19:46:14 +02:00
|
|
|
{
|
2019-08-12 17:27:28 +02:00
|
|
|
count += components_count_type(initializer->args[i]->data_type);
|
2012-09-19 19:46:14 +02:00
|
|
|
}
|
2019-08-09 16:52:46 +02:00
|
|
|
TRACE("Initializer size = %u.\n", count);
|
2012-06-11 19:18:35 +02:00
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2019-08-12 17:27:28 +02:00
|
|
|
static void free_parse_initializer(struct parse_initializer *initializer)
|
|
|
|
{
|
2020-02-13 04:57:18 +01:00
|
|
|
free_instr_list(initializer->instrs);
|
2019-08-12 17:27:28 +02:00
|
|
|
d3dcompiler_free(initializer->args);
|
|
|
|
}
|
|
|
|
|
2012-09-17 15:32:04 +02:00
|
|
|
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;
|
2020-05-01 06:54:23 +02:00
|
|
|
init_node(&swizzle->node, HLSL_IR_SWIZZLE,
|
|
|
|
new_hlsl_type(NULL, HLSL_CLASS_VECTOR, val->data_type->base_type, components, 1), *loc);
|
2020-06-30 01:55:35 +02:00
|
|
|
hlsl_src_from_node(&swizzle->val, val);
|
2012-09-17 15:32:04 +02:00
|
|
|
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;
|
2020-04-30 04:54:39 +02:00
|
|
|
y = swizzle[i + 2] - '0';
|
|
|
|
x = swizzle[i + 3] - '0';
|
2012-09-17 15:32:04 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-04-30 04:54:39 +02:00
|
|
|
y = swizzle[i + 1] - '1';
|
|
|
|
x = swizzle[i + 2] - '1';
|
2012-09-17 15:32:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-06-11 23:44:20 +02:00
|
|
|
static struct hlsl_ir_var *new_var(const char *name, struct hlsl_type *type, const struct source_location loc,
|
|
|
|
const char *semantic, unsigned int modifiers, const struct reg_reservation *reg_reservation)
|
2020-05-04 22:03:42 +02:00
|
|
|
{
|
|
|
|
struct hlsl_ir_var *var;
|
|
|
|
|
|
|
|
if (!(var = d3dcompiler_alloc(sizeof(*var))))
|
|
|
|
{
|
|
|
|
hlsl_ctx.status = PARSE_ERR;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2020-06-11 23:44:20 +02:00
|
|
|
var->name = name;
|
2020-05-04 22:03:42 +02:00
|
|
|
var->data_type = type;
|
|
|
|
var->loc = loc;
|
2020-06-11 23:44:20 +02:00
|
|
|
var->semantic = semantic;
|
|
|
|
var->modifiers = modifiers;
|
|
|
|
var->reg_reservation = reg_reservation;
|
|
|
|
return var;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct hlsl_ir_var *new_synthetic_var(const char *name, struct hlsl_type *type,
|
|
|
|
const struct source_location loc)
|
|
|
|
{
|
|
|
|
struct hlsl_ir_var *var = new_var(strdup(name), type, loc, NULL, 0, NULL);
|
|
|
|
|
|
|
|
if (var)
|
|
|
|
list_add_tail(&hlsl_ctx.globals->vars, &var->scope_entry);
|
2020-05-04 22:03:42 +02:00
|
|
|
return var;
|
|
|
|
}
|
|
|
|
|
2020-06-02 00:58:43 +02:00
|
|
|
static struct hlsl_ir_assignment *new_assignment(struct hlsl_ir_var *var, struct hlsl_ir_node *offset,
|
|
|
|
struct hlsl_ir_node *rhs, unsigned int writemask, struct source_location loc)
|
2020-05-04 22:03:42 +02:00
|
|
|
{
|
|
|
|
struct hlsl_ir_assignment *assign;
|
|
|
|
|
2020-06-02 00:58:43 +02:00
|
|
|
if (!writemask && type_is_single_reg(rhs->data_type))
|
|
|
|
writemask = (1 << rhs->data_type->dimx) - 1;
|
|
|
|
|
2020-05-04 22:03:42 +02:00
|
|
|
if (!(assign = d3dcompiler_alloc(sizeof(*assign))))
|
|
|
|
return NULL;
|
|
|
|
|
2020-06-02 00:58:43 +02:00
|
|
|
init_node(&assign->node, HLSL_IR_ASSIGNMENT, NULL, loc);
|
|
|
|
assign->lhs.var = var;
|
2020-06-30 01:55:35 +02:00
|
|
|
hlsl_src_from_node(&assign->lhs.offset, offset);
|
|
|
|
hlsl_src_from_node(&assign->rhs, rhs);
|
2020-06-02 00:58:43 +02:00
|
|
|
assign->writemask = writemask;
|
2020-05-04 22:03:42 +02:00
|
|
|
return assign;
|
|
|
|
}
|
|
|
|
|
2020-06-23 00:47:20 +02:00
|
|
|
static struct hlsl_ir_assignment *new_simple_assignment(struct hlsl_ir_var *lhs, struct hlsl_ir_node *rhs)
|
2020-06-02 00:58:43 +02:00
|
|
|
{
|
|
|
|
return new_assignment(lhs, NULL, rhs, 0, rhs->loc);
|
|
|
|
}
|
|
|
|
|
2020-06-22 22:53:00 +02:00
|
|
|
static struct hlsl_ir_jump *add_return(struct list *instrs,
|
|
|
|
struct hlsl_ir_node *return_value, struct source_location loc)
|
2020-06-02 00:58:46 +02:00
|
|
|
{
|
|
|
|
struct hlsl_type *return_type = hlsl_ctx.cur_function->return_type;
|
|
|
|
struct hlsl_ir_jump *jump;
|
|
|
|
|
|
|
|
if (return_value)
|
|
|
|
{
|
|
|
|
struct hlsl_ir_assignment *assignment;
|
|
|
|
|
2020-06-22 22:53:01 +02:00
|
|
|
if (!(return_value = add_implicit_conversion(instrs, return_value, return_type, &loc)))
|
2020-06-02 00:58:46 +02:00
|
|
|
return NULL;
|
|
|
|
|
2020-06-23 00:47:20 +02:00
|
|
|
if (!(assignment = new_simple_assignment(hlsl_ctx.cur_function->return_var, return_value)))
|
2020-06-02 00:58:46 +02:00
|
|
|
return NULL;
|
|
|
|
list_add_after(&return_value->entry, &assignment->node.entry);
|
|
|
|
}
|
|
|
|
else if (!type_is_void(return_type))
|
|
|
|
{
|
|
|
|
hlsl_report_message(loc, HLSL_LEVEL_ERROR, "non-void function must return a value");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(jump = d3dcompiler_alloc(sizeof(*jump))))
|
|
|
|
{
|
|
|
|
ERR("Out of memory\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
init_node(&jump->node, HLSL_IR_JUMP, NULL, loc);
|
|
|
|
jump->type = HLSL_IR_JUMP_RETURN;
|
2020-06-22 22:53:00 +02:00
|
|
|
list_add_tail(instrs, &jump->node.entry);
|
2020-06-02 00:58:46 +02:00
|
|
|
|
|
|
|
return jump;
|
|
|
|
}
|
|
|
|
|
2020-05-22 22:45:29 +02:00
|
|
|
static struct hlsl_ir_constant *new_uint_constant(unsigned int n, const struct source_location loc)
|
|
|
|
{
|
|
|
|
struct hlsl_ir_constant *c;
|
|
|
|
|
|
|
|
if (!(c = d3dcompiler_alloc(sizeof(*c))))
|
|
|
|
return NULL;
|
2020-06-02 00:58:41 +02:00
|
|
|
init_node(&c->node, HLSL_IR_CONSTANT, hlsl_ctx.builtin_types.scalar[HLSL_TYPE_UINT], loc);
|
2020-06-08 23:49:37 +02:00
|
|
|
c->value.u[0] = n;
|
2020-05-22 22:45:29 +02:00
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2020-06-23 00:47:19 +02:00
|
|
|
struct hlsl_ir_node *new_unary_expr(enum hlsl_ir_expr_op op, struct hlsl_ir_node *arg, struct source_location loc)
|
|
|
|
{
|
|
|
|
struct hlsl_ir_expr *expr;
|
|
|
|
|
|
|
|
if (!(expr = d3dcompiler_alloc(sizeof(*expr))))
|
|
|
|
return NULL;
|
|
|
|
init_node(&expr->node, HLSL_IR_EXPR, arg->data_type, loc);
|
|
|
|
expr->op = op;
|
2020-06-30 01:55:35 +02:00
|
|
|
hlsl_src_from_node(&expr->operands[0], arg);
|
2020-06-23 00:47:19 +02:00
|
|
|
return &expr->node;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct hlsl_ir_node *new_binary_expr(enum hlsl_ir_expr_op op,
|
|
|
|
struct hlsl_ir_node *arg1, struct hlsl_ir_node *arg2)
|
|
|
|
{
|
|
|
|
struct hlsl_ir_expr *expr;
|
|
|
|
|
|
|
|
assert(compare_hlsl_types(arg1->data_type, arg2->data_type));
|
|
|
|
|
|
|
|
if (!(expr = d3dcompiler_alloc(sizeof(*expr))))
|
|
|
|
return NULL;
|
|
|
|
init_node(&expr->node, HLSL_IR_EXPR, arg1->data_type, arg1->loc);
|
|
|
|
expr->op = op;
|
2020-06-30 01:55:35 +02:00
|
|
|
hlsl_src_from_node(&expr->operands[0], arg1);
|
|
|
|
hlsl_src_from_node(&expr->operands[1], arg2);
|
2020-06-23 00:47:19 +02:00
|
|
|
return &expr->node;
|
|
|
|
}
|
|
|
|
|
2020-05-22 22:45:30 +02:00
|
|
|
static struct hlsl_ir_load *new_var_load(struct hlsl_ir_var *var, const struct source_location loc)
|
2020-05-01 06:54:23 +02:00
|
|
|
{
|
2020-05-22 22:45:30 +02:00
|
|
|
struct hlsl_ir_load *load = d3dcompiler_alloc(sizeof(*load));
|
2020-05-01 06:54:23 +02:00
|
|
|
|
2020-05-22 22:45:30 +02:00
|
|
|
if (!load)
|
2020-05-01 06:54:23 +02:00
|
|
|
{
|
|
|
|
ERR("Out of memory.\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
2020-05-22 22:45:30 +02:00
|
|
|
init_node(&load->node, HLSL_IR_LOAD, var->data_type, loc);
|
|
|
|
load->src.var = var;
|
|
|
|
return load;
|
2020-05-01 06:54:23 +02:00
|
|
|
}
|
|
|
|
|
2020-06-18 17:46:24 +02:00
|
|
|
static struct hlsl_ir_load *add_load(struct list *instrs, struct hlsl_ir_node *var_node, struct hlsl_ir_node *offset,
|
2020-05-22 22:45:29 +02:00
|
|
|
struct hlsl_type *data_type, const struct source_location loc)
|
2020-05-01 06:54:23 +02:00
|
|
|
{
|
2020-05-22 22:45:29 +02:00
|
|
|
struct hlsl_ir_node *add = NULL;
|
2020-05-22 22:45:30 +02:00
|
|
|
struct hlsl_ir_load *load;
|
2020-05-04 22:03:43 +02:00
|
|
|
struct hlsl_ir_var *var;
|
2020-05-01 06:54:23 +02:00
|
|
|
|
2020-05-22 22:45:30 +02:00
|
|
|
if (var_node->type == HLSL_IR_LOAD)
|
2020-05-22 22:45:29 +02:00
|
|
|
{
|
2020-05-22 22:45:30 +02:00
|
|
|
const struct hlsl_deref *src = &load_from_node(var_node)->src;
|
2020-05-04 22:03:42 +02:00
|
|
|
|
2020-05-22 22:45:29 +02:00
|
|
|
var = src->var;
|
2020-06-30 01:55:35 +02:00
|
|
|
if (src->offset.node)
|
2020-05-22 22:45:29 +02:00
|
|
|
{
|
2020-06-30 01:55:35 +02:00
|
|
|
if (!(add = new_binary_expr(HLSL_IR_BINOP_ADD, src->offset.node, offset)))
|
2020-05-22 22:45:29 +02:00
|
|
|
return NULL;
|
2020-06-18 17:46:24 +02:00
|
|
|
list_add_tail(instrs, &add->entry);
|
2020-05-22 22:45:29 +02:00
|
|
|
offset = add;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
struct hlsl_ir_assignment *assign;
|
|
|
|
char name[27];
|
2020-05-04 22:03:42 +02:00
|
|
|
|
2020-05-22 22:45:29 +02:00
|
|
|
sprintf(name, "<deref-%p>", var_node);
|
|
|
|
if (!(var = new_synthetic_var(name, var_node->data_type, var_node->loc)))
|
|
|
|
return NULL;
|
2020-05-04 22:03:42 +02:00
|
|
|
|
2020-05-22 22:45:29 +02:00
|
|
|
TRACE("Synthesized variable %p for %s node.\n", var, debug_node_type(var_node->type));
|
|
|
|
|
2020-06-23 00:47:20 +02:00
|
|
|
if (!(assign = new_simple_assignment(var, var_node)))
|
2020-05-22 22:45:29 +02:00
|
|
|
return NULL;
|
2020-05-04 22:03:42 +02:00
|
|
|
|
2020-06-18 17:46:24 +02:00
|
|
|
list_add_tail(instrs, &assign->node.entry);
|
2020-05-22 22:45:29 +02:00
|
|
|
}
|
|
|
|
|
2020-05-22 22:45:30 +02:00
|
|
|
if (!(load = d3dcompiler_alloc(sizeof(*load))))
|
2020-05-04 22:03:43 +02:00
|
|
|
return NULL;
|
2020-05-22 22:45:30 +02:00
|
|
|
init_node(&load->node, HLSL_IR_LOAD, data_type, loc);
|
|
|
|
load->src.var = var;
|
2020-06-30 01:55:35 +02:00
|
|
|
hlsl_src_from_node(&load->src.offset, offset);
|
2020-06-18 17:46:24 +02:00
|
|
|
list_add_tail(instrs, &load->node.entry);
|
2020-05-22 22:45:30 +02:00
|
|
|
return load;
|
2020-05-04 22:03:43 +02:00
|
|
|
}
|
|
|
|
|
2020-06-18 17:46:24 +02:00
|
|
|
static struct hlsl_ir_load *add_record_load(struct list *instrs, struct hlsl_ir_node *record,
|
2020-05-22 22:45:29 +02:00
|
|
|
const struct hlsl_struct_field *field, const struct source_location loc)
|
2020-05-04 22:03:43 +02:00
|
|
|
{
|
2020-05-22 22:45:29 +02:00
|
|
|
struct hlsl_ir_constant *c;
|
2020-05-04 22:03:43 +02:00
|
|
|
|
2020-05-22 22:45:29 +02:00
|
|
|
if (!(c = new_uint_constant(field->reg_offset * 4, loc)))
|
2020-05-04 22:03:43 +02:00
|
|
|
return NULL;
|
2020-06-18 17:46:24 +02:00
|
|
|
list_add_tail(instrs, &c->node.entry);
|
2020-05-04 22:03:42 +02:00
|
|
|
|
2020-06-18 17:46:24 +02:00
|
|
|
return add_load(instrs, record, &c->node, field->type, loc);
|
2020-05-01 06:54:23 +02:00
|
|
|
}
|
|
|
|
|
2020-06-18 17:46:24 +02:00
|
|
|
static struct hlsl_ir_load *add_array_load(struct list *instrs, struct hlsl_ir_node *array,
|
2020-05-04 22:03:43 +02:00
|
|
|
struct hlsl_ir_node *index, const struct source_location loc)
|
|
|
|
{
|
|
|
|
const struct hlsl_type *expr_type = array->data_type;
|
|
|
|
struct hlsl_type *data_type;
|
2020-05-22 22:45:29 +02:00
|
|
|
struct hlsl_ir_constant *c;
|
|
|
|
struct hlsl_ir_node *mul;
|
2020-05-04 22:03:43 +02:00
|
|
|
|
2020-05-22 22:45:30 +02:00
|
|
|
TRACE("Array load from type %s.\n", debug_hlsl_type(expr_type));
|
2020-05-04 22:03:43 +02:00
|
|
|
|
|
|
|
if (expr_type->type == HLSL_CLASS_ARRAY)
|
|
|
|
{
|
|
|
|
data_type = expr_type->e.array.type;
|
|
|
|
}
|
2020-05-04 22:03:44 +02:00
|
|
|
else if (expr_type->type == HLSL_CLASS_MATRIX || expr_type->type == HLSL_CLASS_VECTOR)
|
2020-05-04 22:03:43 +02:00
|
|
|
{
|
2020-05-22 22:45:29 +02:00
|
|
|
/* This needs to be lowered now, while we still have type information. */
|
2020-05-04 22:03:44 +02:00
|
|
|
FIXME("Index of matrix or vector type.\n");
|
|
|
|
return NULL;
|
2020-05-04 22:03:43 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (expr_type->type == HLSL_CLASS_SCALAR)
|
|
|
|
hlsl_report_message(loc, HLSL_LEVEL_ERROR, "array-indexed expression is scalar");
|
|
|
|
else
|
|
|
|
hlsl_report_message(loc, HLSL_LEVEL_ERROR, "expression is not array-indexable");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2020-05-22 22:45:29 +02:00
|
|
|
if (!(c = new_uint_constant(data_type->reg_size * 4, loc)))
|
2020-05-04 22:03:43 +02:00
|
|
|
return NULL;
|
2020-06-18 17:46:24 +02:00
|
|
|
list_add_tail(instrs, &c->node.entry);
|
2020-06-23 00:47:19 +02:00
|
|
|
if (!(mul = new_binary_expr(HLSL_IR_BINOP_MUL, index, &c->node)))
|
2020-05-04 22:03:43 +02:00
|
|
|
return NULL;
|
2020-06-18 17:46:24 +02:00
|
|
|
list_add_tail(instrs, &mul->entry);
|
2020-05-22 22:45:29 +02:00
|
|
|
index = mul;
|
2020-05-04 22:03:43 +02:00
|
|
|
|
2020-06-18 17:46:24 +02:00
|
|
|
return add_load(instrs, array, index, data_type, loc);
|
2020-05-04 22:03:43 +02:00
|
|
|
}
|
|
|
|
|
2019-08-12 17:27:28 +02:00
|
|
|
static void struct_var_initializer(struct list *list, struct hlsl_ir_var *var,
|
|
|
|
struct parse_initializer *initializer)
|
2012-09-26 19:22:35 +02:00
|
|
|
{
|
2019-08-13 17:23:32 +02:00
|
|
|
struct hlsl_type *type = var->data_type;
|
2012-09-26 19:22:35 +02:00
|
|
|
struct hlsl_struct_field *field;
|
2019-08-12 17:27:28 +02:00
|
|
|
unsigned int i = 0;
|
2012-09-26 19:22:35 +02:00
|
|
|
|
|
|
|
if (initializer_size(initializer) != components_count_type(type))
|
|
|
|
{
|
2020-03-04 03:29:47 +01:00
|
|
|
hlsl_report_message(var->loc, HLSL_LEVEL_ERROR, "structure initializer mismatch");
|
2019-08-12 17:27:28 +02:00
|
|
|
free_parse_initializer(initializer);
|
2012-09-26 19:22:35 +02:00
|
|
|
return;
|
|
|
|
}
|
2019-08-12 17:27:28 +02:00
|
|
|
|
2020-02-13 04:57:18 +01:00
|
|
|
list_move_tail(list, initializer->instrs);
|
|
|
|
d3dcompiler_free(initializer->instrs);
|
|
|
|
|
2012-09-26 19:22:35 +02:00
|
|
|
LIST_FOR_EACH_ENTRY(field, type->e.elements, struct hlsl_struct_field, entry)
|
|
|
|
{
|
2019-08-12 17:27:28 +02:00
|
|
|
struct hlsl_ir_node *node = initializer->args[i];
|
2020-06-02 00:58:43 +02:00
|
|
|
struct hlsl_ir_assignment *assign;
|
|
|
|
struct hlsl_ir_constant *c;
|
2019-08-12 17:27:28 +02:00
|
|
|
|
|
|
|
if (i++ >= initializer->args_count)
|
2020-06-02 00:58:43 +02:00
|
|
|
break;
|
|
|
|
|
2012-09-26 19:22:35 +02:00
|
|
|
if (components_count_type(field->type) == components_count_type(node->data_type))
|
|
|
|
{
|
2020-06-02 00:58:43 +02:00
|
|
|
if (!(c = new_uint_constant(field->reg_offset * 4, node->loc)))
|
2012-09-26 19:22:35 +02:00
|
|
|
break;
|
2020-06-02 00:58:43 +02:00
|
|
|
list_add_tail(list, &c->node.entry);
|
|
|
|
|
|
|
|
if (!(assign = new_assignment(var, &c->node, node, 0, node->loc)))
|
|
|
|
break;
|
|
|
|
list_add_tail(list, &assign->node.entry);
|
2012-09-26 19:22:35 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
FIXME("Initializing with \"mismatched\" fields is not supported yet.\n");
|
|
|
|
}
|
|
|
|
|
2019-08-12 17:27:28 +02:00
|
|
|
d3dcompiler_free(initializer->args);
|
2012-09-26 19:22:35 +02:00
|
|
|
}
|
|
|
|
|
2020-02-14 19:31:03 +01:00
|
|
|
static void free_parse_variable_def(struct parse_variable_def *v)
|
|
|
|
{
|
|
|
|
free_parse_initializer(&v->initializer);
|
|
|
|
d3dcompiler_free(v->name);
|
|
|
|
d3dcompiler_free((void *)v->semantic);
|
|
|
|
d3dcompiler_free(v->reg_reservation);
|
|
|
|
d3dcompiler_free(v);
|
|
|
|
}
|
|
|
|
|
2012-09-26 19:22:31 +02:00
|
|
|
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;
|
|
|
|
BOOL ret, local = TRUE;
|
|
|
|
struct list *statements_list = d3dcompiler_alloc(sizeof(*statements_list));
|
|
|
|
|
2020-04-02 23:14:12 +02:00
|
|
|
if (basic_type->type == HLSL_CLASS_MATRIX)
|
|
|
|
assert(basic_type->modifiers & HLSL_MODIFIERS_MAJORITY_MASK);
|
|
|
|
|
2012-09-26 19:22:31 +02:00
|
|
|
if (!statements_list)
|
|
|
|
{
|
|
|
|
ERR("Out of memory.\n");
|
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(v, v_next, var_list, struct parse_variable_def, entry)
|
2020-02-14 19:31:03 +01:00
|
|
|
free_parse_variable_def(v);
|
2012-09-26 19:22:31 +02:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
if (v->array_size)
|
|
|
|
type = new_array_type(basic_type, v->array_size);
|
|
|
|
else
|
|
|
|
type = basic_type;
|
2020-06-11 23:44:20 +02:00
|
|
|
|
|
|
|
if (!(var = new_var(v->name, type, v->loc, v->semantic, modifiers, v->reg_reservation)))
|
|
|
|
{
|
|
|
|
free_parse_variable_def(v);
|
|
|
|
continue;
|
|
|
|
}
|
2012-09-26 19:22:31 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-03-13 17:34:56 +01:00
|
|
|
if (type->modifiers & HLSL_MODIFIER_CONST && !(var->modifiers & HLSL_STORAGE_UNIFORM) && !v->initializer.args_count)
|
2012-09-26 19:22:31 +02:00
|
|
|
{
|
2020-03-04 03:29:47 +01:00
|
|
|
hlsl_report_message(v->loc, HLSL_LEVEL_ERROR, "const variable without initializer");
|
2012-09-26 19:22:31 +02:00
|
|
|
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);
|
|
|
|
|
2019-08-12 17:27:28 +02:00
|
|
|
if (v->initializer.args_count)
|
2012-09-26 19:22:31 +02:00
|
|
|
{
|
2019-08-12 17:27:28 +02:00
|
|
|
unsigned int size = initializer_size(&v->initializer);
|
2020-05-22 22:45:30 +02:00
|
|
|
struct hlsl_ir_load *load;
|
2012-09-26 19:22:31 +02:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2020-03-04 03:29:47 +01:00
|
|
|
hlsl_report_message(v->loc, HLSL_LEVEL_ERROR,
|
2012-09-26 19:22:31 +02:00
|
|
|
"'%s' initializer does not match", v->name);
|
2019-08-12 17:27:28 +02:00
|
|
|
free_parse_initializer(&v->initializer);
|
2012-09-26 19:22:31 +02:00
|
|
|
d3dcompiler_free(v);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((type->type == HLSL_CLASS_STRUCT || type->type == HLSL_CLASS_ARRAY)
|
|
|
|
&& components_count_type(type) != size)
|
|
|
|
{
|
2020-03-04 03:29:47 +01:00
|
|
|
hlsl_report_message(v->loc, HLSL_LEVEL_ERROR,
|
2012-09-26 19:22:31 +02:00
|
|
|
"'%s' initializer does not match", v->name);
|
2019-08-12 17:27:28 +02:00
|
|
|
free_parse_initializer(&v->initializer);
|
2012-09-26 19:22:31 +02:00
|
|
|
d3dcompiler_free(v);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-09-26 19:22:32 +02:00
|
|
|
if (type->type == HLSL_CLASS_STRUCT)
|
|
|
|
{
|
2019-08-12 17:27:28 +02:00
|
|
|
struct_var_initializer(statements_list, var, &v->initializer);
|
2012-09-26 19:22:32 +02:00
|
|
|
d3dcompiler_free(v);
|
|
|
|
continue;
|
|
|
|
}
|
2012-09-26 19:22:31 +02:00
|
|
|
if (type->type > HLSL_CLASS_LAST_NUMERIC)
|
|
|
|
{
|
|
|
|
FIXME("Initializers for non scalar/struct variables not supported yet.\n");
|
2019-08-12 17:27:28 +02:00
|
|
|
free_parse_initializer(&v->initializer);
|
2012-09-26 19:22:31 +02:00
|
|
|
d3dcompiler_free(v);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (v->array_size > 0)
|
|
|
|
{
|
|
|
|
FIXME("Initializing arrays is not supported yet.\n");
|
2019-08-12 17:27:28 +02:00
|
|
|
free_parse_initializer(&v->initializer);
|
2012-09-26 19:22:31 +02:00
|
|
|
d3dcompiler_free(v);
|
|
|
|
continue;
|
|
|
|
}
|
2019-08-12 17:27:28 +02:00
|
|
|
if (v->initializer.args_count > 1)
|
2012-09-26 19:22:31 +02:00
|
|
|
{
|
|
|
|
FIXME("Complex initializers are not supported yet.\n");
|
2019-08-12 17:27:28 +02:00
|
|
|
free_parse_initializer(&v->initializer);
|
2012-09-26 19:22:31 +02:00
|
|
|
d3dcompiler_free(v);
|
|
|
|
continue;
|
|
|
|
}
|
2019-08-12 17:27:28 +02:00
|
|
|
|
2020-05-22 22:45:30 +02:00
|
|
|
load = new_var_load(var, var->loc);
|
2020-06-18 17:46:20 +02:00
|
|
|
list_add_tail(v->initializer.instrs, &load->node.entry);
|
2020-06-22 22:52:59 +02:00
|
|
|
add_assignment(v->initializer.instrs, &load->node, ASSIGN_OP_ASSIGN, v->initializer.args[0]);
|
2019-08-12 17:27:28 +02:00
|
|
|
d3dcompiler_free(v->initializer.args);
|
2020-06-18 17:46:20 +02:00
|
|
|
|
|
|
|
if (modifiers & HLSL_STORAGE_STATIC)
|
|
|
|
list_move_tail(&hlsl_ctx.static_initializers, v->initializer.instrs);
|
|
|
|
else
|
|
|
|
list_move_tail(statements_list, v->initializer.instrs);
|
|
|
|
d3dcompiler_free(v->initializer.instrs);
|
2012-09-26 19:22:31 +02:00
|
|
|
}
|
|
|
|
d3dcompiler_free(v);
|
|
|
|
}
|
|
|
|
d3dcompiler_free(var_list);
|
|
|
|
return statements_list;
|
|
|
|
}
|
|
|
|
|
2012-09-26 19:22:32 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-04-02 23:14:13 +02:00
|
|
|
BOOL is_row_major(const struct hlsl_type *type)
|
|
|
|
{
|
|
|
|
/* Default to column-major if the majority isn't explicitly set, which can
|
|
|
|
* happen for anonymous nodes. */
|
|
|
|
return !!(type->modifiers & HLSL_MODIFIER_ROW_MAJOR);
|
|
|
|
}
|
|
|
|
|
2020-04-02 23:14:12 +02:00
|
|
|
static struct hlsl_type *apply_type_modifiers(struct hlsl_type *type,
|
|
|
|
unsigned int *modifiers, struct source_location loc)
|
2020-03-13 17:34:56 +01:00
|
|
|
{
|
2020-04-02 23:14:12 +02:00
|
|
|
unsigned int default_majority = 0;
|
2020-03-13 17:34:56 +01:00
|
|
|
struct hlsl_type *new_type;
|
|
|
|
|
2020-04-02 23:14:12 +02:00
|
|
|
/* This function is only used for declarations (i.e. variables and struct
|
|
|
|
* fields), which should inherit the matrix majority. We only explicitly set
|
|
|
|
* the default majority for declarations—typedefs depend on this—but we
|
|
|
|
* want to always set it, so that an hlsl_type object is never used to
|
|
|
|
* represent two different majorities (and thus can be used to store its
|
|
|
|
* register size, etc.) */
|
|
|
|
if (!(*modifiers & HLSL_MODIFIERS_MAJORITY_MASK)
|
|
|
|
&& !(type->modifiers & HLSL_MODIFIERS_MAJORITY_MASK)
|
|
|
|
&& type->type == HLSL_CLASS_MATRIX)
|
|
|
|
{
|
|
|
|
if (hlsl_ctx.matrix_majority == HLSL_COLUMN_MAJOR)
|
|
|
|
default_majority = HLSL_MODIFIER_COLUMN_MAJOR;
|
|
|
|
else
|
|
|
|
default_majority = HLSL_MODIFIER_ROW_MAJOR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!default_majority && !(*modifiers & HLSL_TYPE_MODIFIERS_MASK))
|
2020-03-13 17:34:56 +01:00
|
|
|
return type;
|
|
|
|
|
2020-04-02 23:14:12 +02:00
|
|
|
if (!(new_type = clone_hlsl_type(type, default_majority)))
|
2020-03-13 17:34:56 +01:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
new_type->modifiers = add_modifiers(new_type->modifiers, *modifiers, loc);
|
|
|
|
*modifiers &= ~HLSL_TYPE_MODIFIERS_MASK;
|
2020-04-02 23:14:13 +02:00
|
|
|
|
|
|
|
if (new_type->type == HLSL_CLASS_MATRIX)
|
|
|
|
new_type->reg_size = is_row_major(new_type) ? new_type->dimy : new_type->dimx;
|
2020-03-13 17:34:56 +01:00
|
|
|
return new_type;
|
|
|
|
}
|
|
|
|
|
2012-09-26 19:22:32 +02:00
|
|
|
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;
|
|
|
|
|
2020-04-02 23:14:12 +02:00
|
|
|
if (type->type == HLSL_CLASS_MATRIX)
|
|
|
|
assert(type->modifiers & HLSL_MODIFIERS_MAJORITY_MASK);
|
|
|
|
|
2012-09-26 19:22:32 +02:00
|
|
|
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;
|
|
|
|
}
|
2020-04-30 04:54:41 +02:00
|
|
|
if (v->array_size)
|
|
|
|
field->type = new_array_type(type, v->array_size);
|
|
|
|
else
|
|
|
|
field->type = type;
|
2012-09-26 19:22:32 +02:00
|
|
|
field->name = v->name;
|
|
|
|
field->modifiers = modifiers;
|
|
|
|
field->semantic = v->semantic;
|
2019-08-12 17:27:28 +02:00
|
|
|
if (v->initializer.args_count)
|
2012-09-26 19:22:32 +02:00
|
|
|
{
|
2020-03-04 03:29:47 +01:00
|
|
|
hlsl_report_message(v->loc, HLSL_LEVEL_ERROR, "struct field with an initializer.\n");
|
2019-08-12 17:27:28 +02:00
|
|
|
free_parse_initializer(&v->initializer);
|
2012-09-26 19:22:32 +02:00
|
|
|
}
|
|
|
|
list_add_tail(list, &field->entry);
|
|
|
|
d3dcompiler_free(v);
|
|
|
|
}
|
|
|
|
d3dcompiler_free(fields);
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2020-04-30 04:54:43 +02:00
|
|
|
static DWORD get_array_size(const struct hlsl_type *type)
|
|
|
|
{
|
|
|
|
if (type->type == HLSL_CLASS_ARRAY)
|
|
|
|
return get_array_size(type->e.array.type) * type->e.array.elements_count;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2020-03-15 22:25:10 +01:00
|
|
|
static struct hlsl_type *new_struct_type(const char *name, struct list *fields)
|
2012-09-26 19:22:32 +02:00
|
|
|
{
|
|
|
|
struct hlsl_type *type = d3dcompiler_alloc(sizeof(*type));
|
2020-04-02 23:14:13 +02:00
|
|
|
struct hlsl_struct_field *field;
|
|
|
|
unsigned int reg_size = 0;
|
2012-09-26 19:22:32 +02:00
|
|
|
|
|
|
|
if (!type)
|
|
|
|
{
|
|
|
|
ERR("Out of memory.\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
type->type = HLSL_CLASS_STRUCT;
|
2020-04-30 04:54:40 +02:00
|
|
|
type->base_type = HLSL_TYPE_VOID;
|
2012-09-26 19:22:32 +02:00
|
|
|
type->name = name;
|
2020-04-30 04:54:43 +02:00
|
|
|
type->dimx = 0;
|
|
|
|
type->dimy = 1;
|
2012-09-26 19:22:32 +02:00
|
|
|
type->e.elements = fields;
|
|
|
|
|
2020-04-02 23:14:13 +02:00
|
|
|
LIST_FOR_EACH_ENTRY(field, fields, struct hlsl_struct_field, entry)
|
|
|
|
{
|
|
|
|
field->reg_offset = reg_size;
|
|
|
|
reg_size += field->type->reg_size;
|
2020-04-30 04:54:43 +02:00
|
|
|
type->dimx += field->type->dimx * field->type->dimy * get_array_size(field->type);
|
2020-04-02 23:14:13 +02:00
|
|
|
}
|
|
|
|
type->reg_size = reg_size;
|
|
|
|
|
2012-09-26 19:22:32 +02:00
|
|
|
list_add_tail(&hlsl_ctx.types, &type->entry);
|
|
|
|
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
2020-03-04 03:29:49 +01:00
|
|
|
static BOOL add_typedef(DWORD modifiers, struct hlsl_type *orig_type, struct list *list)
|
2012-09-19 19:46:13 +02:00
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
struct hlsl_type *type;
|
|
|
|
struct parse_variable_def *v, *v_next;
|
|
|
|
|
|
|
|
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
|
2020-04-02 23:14:12 +02:00
|
|
|
type = clone_hlsl_type(orig_type, 0);
|
2012-09-19 19:46:13 +02:00
|
|
|
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)
|
2020-03-04 03:29:50 +01:00
|
|
|
check_invalid_matrix_modifiers(type->modifiers, v->loc);
|
2020-04-02 23:14:13 +02:00
|
|
|
else
|
|
|
|
type->reg_size = is_row_major(type) ? type->dimy : type->dimx;
|
2012-09-19 19:46:13 +02:00
|
|
|
|
2020-04-02 23:14:10 +02:00
|
|
|
if ((type->modifiers & HLSL_MODIFIER_COLUMN_MAJOR)
|
|
|
|
&& (type->modifiers & HLSL_MODIFIER_ROW_MAJOR))
|
|
|
|
hlsl_report_message(v->loc, HLSL_LEVEL_ERROR, "more than one matrix majority keyword");
|
|
|
|
|
2012-09-19 19:46:13 +02:00
|
|
|
ret = add_type_to_scope(hlsl_ctx.cur_scope, type);
|
|
|
|
if (!ret)
|
|
|
|
{
|
2020-03-04 03:29:47 +01:00
|
|
|
hlsl_report_message(v->loc, HLSL_LEVEL_ERROR,
|
2012-09-19 19:46:13 +02:00
|
|
|
"redefinition of custom type '%s'", v->name);
|
|
|
|
}
|
|
|
|
d3dcompiler_free(v);
|
|
|
|
}
|
|
|
|
d3dcompiler_free(list);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2020-03-04 03:29:48 +01:00
|
|
|
static BOOL add_func_parameter(struct list *list, struct parse_parameter *param, const struct source_location loc)
|
2014-05-02 16:30:14 +02:00
|
|
|
{
|
2020-06-11 23:44:20 +02:00
|
|
|
struct hlsl_ir_var *var;
|
2014-05-02 16:30:14 +02:00
|
|
|
|
2020-04-02 23:14:12 +02:00
|
|
|
if (param->type->type == HLSL_CLASS_MATRIX)
|
|
|
|
assert(param->type->modifiers & HLSL_MODIFIERS_MAJORITY_MASK);
|
|
|
|
|
2020-06-11 23:44:20 +02:00
|
|
|
if (!(var = new_var(param->name, param->type, loc, param->semantic, param->modifiers, param->reg_reservation)))
|
2014-05-02 16:30:14 +02:00
|
|
|
return FALSE;
|
2020-06-11 23:44:20 +02:00
|
|
|
|
|
|
|
if (!add_declaration(hlsl_ctx.cur_scope, var, FALSE))
|
2014-05-02 16:30:14 +02:00
|
|
|
{
|
2020-06-11 23:44:20 +02:00
|
|
|
free_declaration(var);
|
2014-05-02 16:30:14 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
2020-06-11 23:44:20 +02:00
|
|
|
list_add_tail(list, &var->param_entry);
|
2014-05-02 16:30:14 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-06-16 22:45:44 +02:00
|
|
|
static struct reg_reservation *parse_reg_reservation(const char *reg_string)
|
|
|
|
{
|
|
|
|
struct reg_reservation *reg_res;
|
|
|
|
enum bwritershader_param_register_type type;
|
|
|
|
DWORD regnum = 0;
|
|
|
|
|
|
|
|
switch (reg_string[0])
|
|
|
|
{
|
|
|
|
case 'c':
|
|
|
|
type = BWRITERSPR_CONST;
|
|
|
|
break;
|
|
|
|
case 'i':
|
|
|
|
type = BWRITERSPR_CONSTINT;
|
|
|
|
break;
|
|
|
|
case 'b':
|
|
|
|
type = BWRITERSPR_CONSTBOOL;
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
type = BWRITERSPR_SAMPLER;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FIXME("Unsupported register type.\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!sscanf(reg_string + 1, "%u", ®num))
|
|
|
|
{
|
|
|
|
FIXME("Unsupported register reservation syntax.\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
reg_res = d3dcompiler_alloc(sizeof(*reg_res));
|
|
|
|
if (!reg_res)
|
|
|
|
{
|
|
|
|
ERR("Out of memory.\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
reg_res->type = type;
|
|
|
|
reg_res->regnum = regnum;
|
|
|
|
return reg_res;
|
|
|
|
}
|
|
|
|
|
2012-10-11 19:48:49 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-04-01 20:31:18 +02:00
|
|
|
static struct hlsl_ir_function_decl *get_func_entry(const char *name)
|
|
|
|
{
|
|
|
|
struct hlsl_ir_function_decl *decl;
|
|
|
|
struct hlsl_ir_function *func;
|
|
|
|
struct wine_rb_entry *entry;
|
|
|
|
|
|
|
|
if ((entry = wine_rb_get(&hlsl_ctx.functions, name)))
|
|
|
|
{
|
|
|
|
func = WINE_RB_ENTRY_VALUE(entry, struct hlsl_ir_function, entry);
|
|
|
|
WINE_RB_FOR_EACH_ENTRY(decl, &func->overloads, struct hlsl_ir_function_decl, entry)
|
|
|
|
return decl;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2020-02-13 04:57:18 +01:00
|
|
|
static struct list *append_unop(struct list *list, struct hlsl_ir_node *node)
|
|
|
|
{
|
|
|
|
list_add_tail(list, &node->entry);
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2020-06-23 00:47:18 +02:00
|
|
|
static struct list *add_binary_expr(struct list *list1, struct list *list2,
|
|
|
|
enum hlsl_ir_expr_op op, struct source_location loc)
|
2020-02-13 04:57:18 +01:00
|
|
|
{
|
2020-06-23 00:47:19 +02:00
|
|
|
struct hlsl_ir_node *args[3] = {node_from_list(list1), node_from_list(list2)};
|
2020-06-23 00:47:18 +02:00
|
|
|
list_move_tail(list1, list2);
|
|
|
|
d3dcompiler_free(list2);
|
2020-06-23 00:47:19 +02:00
|
|
|
add_expr(list1, op, args, &loc);
|
2020-06-23 00:47:18 +02:00
|
|
|
return list1;
|
2020-02-13 04:57:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct list *make_list(struct hlsl_ir_node *node)
|
|
|
|
{
|
|
|
|
struct list *list;
|
|
|
|
|
|
|
|
if (!(list = d3dcompiler_alloc(sizeof(*list))))
|
|
|
|
{
|
|
|
|
ERR("Out of memory.\n");
|
|
|
|
free_instr(node);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
list_init(list);
|
|
|
|
list_add_tail(list, &node->entry);
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2020-03-07 00:17:30 +01:00
|
|
|
static unsigned int evaluate_array_dimension(struct hlsl_ir_node *node)
|
|
|
|
{
|
|
|
|
if (node->data_type->type != HLSL_CLASS_SCALAR)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
switch (node->type)
|
|
|
|
{
|
|
|
|
case HLSL_IR_CONSTANT:
|
|
|
|
{
|
|
|
|
struct hlsl_ir_constant *constant = constant_from_node(node);
|
|
|
|
|
|
|
|
switch (constant->node.data_type->base_type)
|
|
|
|
{
|
|
|
|
case HLSL_TYPE_UINT:
|
2020-06-08 23:49:37 +02:00
|
|
|
return constant->value.u[0];
|
2020-03-07 00:17:30 +01:00
|
|
|
case HLSL_TYPE_INT:
|
2020-06-08 23:49:37 +02:00
|
|
|
return constant->value.i[0];
|
2020-03-07 00:17:30 +01:00
|
|
|
case HLSL_TYPE_FLOAT:
|
2020-06-08 23:49:37 +02:00
|
|
|
return constant->value.f[0];
|
2020-03-07 00:17:30 +01:00
|
|
|
case HLSL_TYPE_DOUBLE:
|
2020-06-08 23:49:37 +02:00
|
|
|
return constant->value.d[0];
|
2020-03-07 00:17:30 +01:00
|
|
|
case HLSL_TYPE_BOOL:
|
2020-06-08 23:49:37 +02:00
|
|
|
return constant->value.b[0];
|
2020-03-07 00:17:30 +01:00
|
|
|
default:
|
|
|
|
WARN("Invalid type %s.\n", debug_base_type(constant->node.data_type));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case HLSL_IR_EXPR:
|
2020-05-22 22:45:30 +02:00
|
|
|
case HLSL_IR_LOAD:
|
2020-03-07 00:17:30 +01:00
|
|
|
case HLSL_IR_SWIZZLE:
|
|
|
|
FIXME("Unhandled type %s.\n", debug_node_type(node->type));
|
|
|
|
return 0;
|
|
|
|
case HLSL_IR_ASSIGNMENT:
|
|
|
|
default:
|
|
|
|
WARN("Invalid node type %s.\n", debug_node_type(node->type));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-02 00:58:44 +02:00
|
|
|
static struct hlsl_ir_function_decl *new_func_decl(struct hlsl_type *return_type,
|
|
|
|
struct list *parameters, const char *semantic, struct source_location loc)
|
|
|
|
{
|
|
|
|
struct hlsl_ir_function_decl *decl;
|
|
|
|
|
|
|
|
if (!(decl = d3dcompiler_alloc(sizeof(*decl))))
|
|
|
|
return NULL;
|
|
|
|
decl->return_type = return_type;
|
|
|
|
decl->parameters = parameters;
|
|
|
|
decl->semantic = semantic;
|
|
|
|
decl->loc = loc;
|
2020-06-02 00:58:46 +02:00
|
|
|
|
|
|
|
if (!type_is_void(return_type))
|
|
|
|
{
|
|
|
|
struct hlsl_ir_var *return_var;
|
|
|
|
char name[28];
|
|
|
|
|
|
|
|
sprintf(name, "<retval-%p>", decl);
|
|
|
|
if (!(return_var = new_synthetic_var(name, return_type, loc)))
|
|
|
|
{
|
|
|
|
d3dcompiler_free(decl);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
decl->return_var = return_var;
|
|
|
|
}
|
|
|
|
|
2020-06-02 00:58:44 +02:00
|
|
|
return decl;
|
|
|
|
}
|
|
|
|
|
2012-05-15 16:12:56 +02:00
|
|
|
%}
|
|
|
|
|
2012-07-12 16:01:33 +02:00
|
|
|
%locations
|
2019-04-23 11:47:53 +02:00
|
|
|
%define parse.error verbose
|
2012-09-19 19:46:11 +02:00
|
|
|
%expect 1
|
2012-05-15 16:12:56 +02:00
|
|
|
|
|
|
|
%union
|
|
|
|
{
|
2012-06-04 17:58:24 +02:00
|
|
|
struct hlsl_type *type;
|
2012-05-15 16:12:56 +02:00
|
|
|
INT intval;
|
2012-06-04 17:58:22 +02:00
|
|
|
FLOAT floatval;
|
2012-06-07 00:19:04 +02:00
|
|
|
BOOL boolval;
|
2012-06-04 17:58:24 +02:00
|
|
|
char *name;
|
|
|
|
DWORD modifiers;
|
2012-06-07 00:19:04 +02:00
|
|
|
struct hlsl_ir_node *instr;
|
2012-06-04 17:58:24 +02:00
|
|
|
struct list *list;
|
2012-10-11 19:48:48 +02:00
|
|
|
struct parse_function function;
|
2012-06-11 19:18:33 +02:00
|
|
|
struct parse_parameter parameter;
|
2019-08-12 17:27:28 +02:00
|
|
|
struct parse_initializer initializer;
|
2012-06-04 17:58:24 +02:00
|
|
|
struct parse_variable_def *variable_def;
|
2012-09-19 19:46:11 +02:00
|
|
|
struct parse_if_body if_body;
|
2012-07-20 16:37:38 +02:00
|
|
|
enum parse_unary_op unary_op;
|
2012-07-20 16:37:40 +02:00
|
|
|
enum parse_assign_op assign_op;
|
2015-06-16 22:45:44 +02:00
|
|
|
struct reg_reservation *reg_reservation;
|
|
|
|
struct parse_colon_attribute colon_attribute;
|
2012-05-15 16:12:56 +02:00
|
|
|
}
|
|
|
|
|
2012-06-04 17:58:22 +02:00
|
|
|
%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
|
|
|
|
|
2012-05-15 16:12:56 +02:00
|
|
|
%token <intval> PRE_LINE
|
|
|
|
|
2012-06-04 17:58:23 +02:00
|
|
|
%token <name> VAR_IDENTIFIER TYPE_IDENTIFIER NEW_IDENTIFIER
|
2012-06-11 19:18:33 +02:00
|
|
|
%type <name> any_identifier var_identifier
|
2012-05-15 16:12:56 +02:00
|
|
|
%token <name> STRING
|
2012-06-04 17:58:22 +02:00
|
|
|
%token <floatval> C_FLOAT
|
|
|
|
%token <intval> C_INTEGER
|
2012-06-07 00:19:04 +02:00
|
|
|
%type <boolval> boolean
|
2012-06-04 17:58:24 +02:00
|
|
|
%type <type> base_type
|
|
|
|
%type <type> type
|
2012-07-11 17:27:50 +02:00
|
|
|
%type <list> declaration_statement
|
2012-09-19 19:46:14 +02:00
|
|
|
%type <list> declaration
|
2012-09-26 19:22:32 +02:00
|
|
|
%type <list> struct_declaration
|
|
|
|
%type <type> struct_spec
|
|
|
|
%type <type> named_struct_spec
|
|
|
|
%type <type> unnamed_struct_spec
|
2020-03-15 22:25:10 +01:00
|
|
|
%type <type> field_type
|
|
|
|
%type <type> typedef_type
|
2012-09-19 19:46:13 +02:00
|
|
|
%type <list> type_specs
|
|
|
|
%type <variable_def> type_spec
|
2019-08-12 17:27:28 +02:00
|
|
|
%type <initializer> complex_initializer
|
|
|
|
%type <initializer> initializer_expr_list
|
2020-02-13 04:57:18 +01:00
|
|
|
%type <list> initializer_expr
|
2012-06-04 17:58:24 +02:00
|
|
|
%type <modifiers> var_modifiers
|
2012-09-26 19:22:32 +02:00
|
|
|
%type <list> field
|
2012-06-11 19:18:33 +02:00
|
|
|
%type <list> parameters
|
|
|
|
%type <list> param_list
|
2020-02-13 04:57:18 +01:00
|
|
|
%type <list> expr
|
2012-06-04 17:58:24 +02:00
|
|
|
%type <intval> array
|
2012-06-11 19:18:34 +02:00
|
|
|
%type <list> statement
|
|
|
|
%type <list> statement_list
|
|
|
|
%type <list> compound_statement
|
2012-09-18 18:18:08 +02:00
|
|
|
%type <list> jump_statement
|
2012-09-19 19:46:11 +02:00
|
|
|
%type <list> selection_statement
|
2012-09-21 16:25:56 +02:00
|
|
|
%type <list> loop_statement
|
2012-06-11 19:18:33 +02:00
|
|
|
%type <function> func_declaration
|
|
|
|
%type <function> func_prototype
|
2012-09-26 19:22:32 +02:00
|
|
|
%type <list> fields_list
|
2012-06-11 19:18:33 +02:00
|
|
|
%type <parameter> parameter
|
2015-06-16 22:45:44 +02:00
|
|
|
%type <colon_attribute> colon_attribute
|
2012-06-04 17:58:24 +02:00
|
|
|
%type <name> semantic
|
2015-06-16 22:45:44 +02:00
|
|
|
%type <reg_reservation> register_opt
|
2012-06-04 17:58:24 +02:00
|
|
|
%type <variable_def> variable_def
|
|
|
|
%type <list> variables_def
|
2012-09-26 19:22:32 +02:00
|
|
|
%type <list> variables_def_optional
|
2012-09-19 19:46:11 +02:00
|
|
|
%type <if_body> if_body
|
2020-02-13 04:57:18 +01:00
|
|
|
%type <list> primary_expr
|
|
|
|
%type <list> postfix_expr
|
|
|
|
%type <list> unary_expr
|
|
|
|
%type <list> mul_expr
|
|
|
|
%type <list> add_expr
|
|
|
|
%type <list> shift_expr
|
|
|
|
%type <list> relational_expr
|
|
|
|
%type <list> equality_expr
|
|
|
|
%type <list> bitand_expr
|
|
|
|
%type <list> bitxor_expr
|
|
|
|
%type <list> bitor_expr
|
|
|
|
%type <list> logicand_expr
|
|
|
|
%type <list> logicor_expr
|
|
|
|
%type <list> conditional_expr
|
|
|
|
%type <list> assignment_expr
|
2012-06-11 19:18:34 +02:00
|
|
|
%type <list> expr_statement
|
2012-07-20 16:37:38 +02:00
|
|
|
%type <unary_op> unary_op
|
2012-07-20 16:37:40 +02:00
|
|
|
%type <assign_op> assign_op
|
2012-10-11 19:48:47 +02:00
|
|
|
%type <modifiers> input_mods
|
2012-06-11 19:18:33 +02:00
|
|
|
%type <modifiers> input_mod
|
2012-05-15 16:12:56 +02:00
|
|
|
%%
|
|
|
|
|
|
|
|
hlsl_prog: /* empty */
|
|
|
|
{
|
|
|
|
}
|
2012-06-11 19:18:33 +02:00
|
|
|
| hlsl_prog func_declaration
|
|
|
|
{
|
2012-10-11 19:48:49 +02:00
|
|
|
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)
|
|
|
|
{
|
2020-03-04 03:29:47 +01:00
|
|
|
hlsl_report_message($2.decl->loc, HLSL_LEVEL_ERROR,
|
2012-10-11 19:48:49 +02:00
|
|
|
"redefinition of function %s", debugstr_a($2.name));
|
2019-08-12 17:27:27 +02:00
|
|
|
YYABORT;
|
2012-10-11 19:48:49 +02:00
|
|
|
}
|
2019-08-13 17:23:31 +02:00
|
|
|
else if (!compare_hlsl_types(decl->return_type, $2.decl->return_type))
|
2012-10-11 19:48:49 +02:00
|
|
|
{
|
2020-03-04 03:29:47 +01:00
|
|
|
hlsl_report_message($2.decl->loc, HLSL_LEVEL_ERROR,
|
2012-10-11 19:48:49 +02:00
|
|
|
"redefining function %s with a different return type",
|
|
|
|
debugstr_a($2.name));
|
2020-03-04 03:29:47 +01:00
|
|
|
hlsl_report_message(decl->loc, HLSL_LEVEL_NOTE,
|
2012-10-11 19:48:49 +02:00
|
|
|
"%s previously declared here",
|
|
|
|
debugstr_a($2.name));
|
2019-08-12 17:27:27 +02:00
|
|
|
YYABORT;
|
2012-10-11 19:48:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-02 00:58:45 +02:00
|
|
|
if (type_is_void($2.decl->return_type) && $2.decl->semantic)
|
2012-10-11 19:48:49 +02:00
|
|
|
{
|
2020-03-04 03:29:47 +01:00
|
|
|
hlsl_report_message($2.decl->loc, HLSL_LEVEL_ERROR,
|
2012-10-11 19:48:49 +02:00
|
|
|
"void function with a semantic");
|
|
|
|
}
|
|
|
|
|
2012-10-11 19:48:48 +02:00
|
|
|
TRACE("Adding function '%s' to the function list.\n", $2.name);
|
|
|
|
add_function_decl(&hlsl_ctx.functions, $2.name, $2.decl, FALSE);
|
2012-06-11 19:18:33 +02:00
|
|
|
}
|
2012-06-04 17:58:24 +02:00
|
|
|
| hlsl_prog declaration_statement
|
|
|
|
{
|
|
|
|
TRACE("Declaration statement parsed.\n");
|
2020-06-18 17:46:20 +02:00
|
|
|
|
|
|
|
if (!list_empty($2))
|
|
|
|
FIXME("Uniform initializer.\n");
|
|
|
|
free_instr_list($2);
|
2012-06-04 17:58:24 +02:00
|
|
|
}
|
2012-05-15 16:12:56 +02:00
|
|
|
| hlsl_prog preproc_directive
|
|
|
|
{
|
|
|
|
}
|
2012-11-09 15:20:38 +01:00
|
|
|
| hlsl_prog ';'
|
|
|
|
{
|
|
|
|
TRACE("Skipping stray semicolon.\n");
|
|
|
|
}
|
2012-05-15 16:12:56 +02:00
|
|
|
|
|
|
|
preproc_directive: PRE_LINE STRING
|
|
|
|
{
|
2015-04-30 16:46:37 +02:00
|
|
|
const char **new_array = NULL;
|
|
|
|
|
2012-06-02 10:35:21 +02:00
|
|
|
TRACE("Updating line information to file %s, line %u\n", debugstr_a($2), $1);
|
2012-07-10 15:39:41 +02:00
|
|
|
hlsl_ctx.line_no = $1;
|
2012-07-12 16:01:33 +02:00
|
|
|
if (strcmp($2, hlsl_ctx.source_file))
|
|
|
|
new_array = d3dcompiler_realloc(hlsl_ctx.source_files,
|
2017-10-07 18:38:58 +02:00
|
|
|
sizeof(*hlsl_ctx.source_files) * (hlsl_ctx.source_files_count + 1));
|
2015-04-30 16:46:37 +02:00
|
|
|
|
|
|
|
if (new_array)
|
|
|
|
{
|
|
|
|
hlsl_ctx.source_files = new_array;
|
|
|
|
hlsl_ctx.source_files[hlsl_ctx.source_files_count++] = $2;
|
|
|
|
hlsl_ctx.source_file = $2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
d3dcompiler_free($2);
|
2012-07-12 16:01:33 +02:00
|
|
|
}
|
2012-05-15 16:12:56 +02:00
|
|
|
}
|
|
|
|
|
2020-03-15 22:25:10 +01:00
|
|
|
struct_declaration: var_modifiers struct_spec variables_def_optional ';'
|
2012-09-26 19:22:32 +02:00
|
|
|
{
|
2020-03-15 22:25:10 +01:00
|
|
|
struct hlsl_type *type;
|
|
|
|
DWORD modifiers = $1;
|
|
|
|
|
|
|
|
if (!$3)
|
2012-09-26 19:22:32 +02:00
|
|
|
{
|
2020-03-15 22:25:10 +01:00
|
|
|
if (!$2->name)
|
2012-09-26 19:22:32 +02:00
|
|
|
{
|
2020-03-20 00:07:11 +01:00
|
|
|
hlsl_report_message(get_location(&@2), HLSL_LEVEL_ERROR,
|
2020-03-04 03:29:47 +01:00
|
|
|
"anonymous struct declaration with no variables");
|
2012-09-26 19:22:32 +02:00
|
|
|
}
|
2020-03-15 22:25:10 +01:00
|
|
|
if (modifiers)
|
2020-03-04 03:29:49 +01:00
|
|
|
{
|
|
|
|
hlsl_report_message(get_location(&@1), HLSL_LEVEL_ERROR,
|
|
|
|
"modifier not allowed on struct type declaration");
|
|
|
|
}
|
2012-09-26 19:22:32 +02:00
|
|
|
}
|
2020-03-15 22:25:10 +01:00
|
|
|
|
|
|
|
if (!(type = apply_type_modifiers($2, &modifiers, get_location(&@1))))
|
|
|
|
YYABORT;
|
|
|
|
$$ = declare_vars(type, modifiers, $3);
|
2012-09-26 19:22:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
struct_spec: named_struct_spec
|
|
|
|
| unnamed_struct_spec
|
|
|
|
|
2020-03-15 22:25:10 +01:00
|
|
|
named_struct_spec: KW_STRUCT any_identifier '{' fields_list '}'
|
2012-09-26 19:22:32 +02:00
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
|
2020-03-15 22:25:10 +01:00
|
|
|
TRACE("Structure %s declaration.\n", debugstr_a($2));
|
|
|
|
$$ = new_struct_type($2, $4);
|
2012-09-26 19:22:32 +02:00
|
|
|
|
2020-03-15 22:25:10 +01:00
|
|
|
if (get_variable(hlsl_ctx.cur_scope, $2))
|
2012-09-26 19:22:32 +02:00
|
|
|
{
|
2020-03-15 22:25:10 +01:00
|
|
|
hlsl_report_message(get_location(&@2),
|
|
|
|
HLSL_LEVEL_ERROR, "redefinition of '%s'", $2);
|
2019-08-12 17:27:27 +02:00
|
|
|
YYABORT;
|
2012-09-26 19:22:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = add_type_to_scope(hlsl_ctx.cur_scope, $$);
|
|
|
|
if (!ret)
|
|
|
|
{
|
2020-03-15 22:25:10 +01:00
|
|
|
hlsl_report_message(get_location(&@2),
|
|
|
|
HLSL_LEVEL_ERROR, "redefinition of struct '%s'", $2);
|
2019-08-12 17:27:27 +02:00
|
|
|
YYABORT;
|
2012-09-26 19:22:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-15 22:25:10 +01:00
|
|
|
unnamed_struct_spec: KW_STRUCT '{' fields_list '}'
|
2012-09-26 19:22:32 +02:00
|
|
|
{
|
|
|
|
TRACE("Anonymous structure declaration.\n");
|
2020-03-15 22:25:10 +01:00
|
|
|
$$ = new_struct_type(NULL, $3);
|
2012-09-26 19:22:32 +02:00
|
|
|
}
|
|
|
|
|
2012-06-04 17:58:24 +02:00
|
|
|
any_identifier: VAR_IDENTIFIER
|
|
|
|
| TYPE_IDENTIFIER
|
|
|
|
| NEW_IDENTIFIER
|
|
|
|
|
2012-09-26 19:22:32 +02:00
|
|
|
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)
|
|
|
|
{
|
2020-03-04 03:29:47 +01:00
|
|
|
hlsl_report_message(get_location(&@2),
|
2012-09-26 19:22:32 +02:00
|
|
|
HLSL_LEVEL_ERROR, "redefinition of '%s'", field->name);
|
|
|
|
d3dcompiler_free(field);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
d3dcompiler_free($2);
|
|
|
|
}
|
|
|
|
|
2020-03-15 22:25:10 +01:00
|
|
|
field_type: type
|
|
|
|
| unnamed_struct_spec
|
|
|
|
|
|
|
|
field: var_modifiers field_type variables_def ';'
|
2012-09-26 19:22:32 +02:00
|
|
|
{
|
2020-03-13 17:34:56 +01:00
|
|
|
struct hlsl_type *type;
|
|
|
|
DWORD modifiers = $1;
|
|
|
|
|
|
|
|
if (!(type = apply_type_modifiers($2, &modifiers, get_location(&@1))))
|
|
|
|
YYABORT;
|
|
|
|
$$ = gen_struct_fields(type, modifiers, $3);
|
2012-09-26 19:22:32 +02:00
|
|
|
}
|
|
|
|
|
2012-06-11 19:18:34 +02:00
|
|
|
func_declaration: func_prototype compound_statement
|
|
|
|
{
|
2012-10-11 19:48:48 +02:00
|
|
|
TRACE("Function %s parsed.\n", $1.name);
|
2012-06-11 19:18:34 +02:00
|
|
|
$$ = $1;
|
2012-10-11 19:48:48 +02:00
|
|
|
$$.decl->body = $2;
|
2012-06-11 19:18:34 +02:00
|
|
|
pop_scope(&hlsl_ctx);
|
|
|
|
}
|
|
|
|
| func_prototype ';'
|
2012-06-11 19:18:33 +02:00
|
|
|
{
|
2012-10-11 19:48:48 +02:00
|
|
|
TRACE("Function prototype for %s.\n", $1.name);
|
2012-06-11 19:18:33 +02:00
|
|
|
$$ = $1;
|
|
|
|
pop_scope(&hlsl_ctx);
|
|
|
|
}
|
|
|
|
|
2020-03-13 17:34:55 +01:00
|
|
|
/* var_modifiers is necessary to avoid shift/reduce conflicts. */
|
2015-06-16 22:45:44 +02:00
|
|
|
func_prototype: var_modifiers type var_identifier '(' parameters ')' colon_attribute
|
2012-06-11 19:18:33 +02:00
|
|
|
{
|
2020-03-13 17:34:55 +01:00
|
|
|
if ($1)
|
|
|
|
{
|
|
|
|
hlsl_report_message(get_location(&@1), HLSL_LEVEL_ERROR,
|
|
|
|
"unexpected modifiers on a function");
|
|
|
|
YYABORT;
|
|
|
|
}
|
2012-07-16 20:39:21 +02:00
|
|
|
if (get_variable(hlsl_ctx.globals, $3))
|
|
|
|
{
|
2020-03-04 03:29:47 +01:00
|
|
|
hlsl_report_message(get_location(&@3),
|
2012-07-16 20:39:21 +02:00
|
|
|
HLSL_LEVEL_ERROR, "redefinition of '%s'\n", $3);
|
2019-08-12 17:27:27 +02:00
|
|
|
YYABORT;
|
2012-07-16 20:39:21 +02:00
|
|
|
}
|
2020-06-02 00:58:45 +02:00
|
|
|
if (type_is_void($2) && $7.semantic)
|
2012-07-16 20:39:22 +02:00
|
|
|
{
|
2020-03-04 03:29:47 +01:00
|
|
|
hlsl_report_message(get_location(&@7),
|
2012-07-16 20:39:22 +02:00
|
|
|
HLSL_LEVEL_ERROR, "void function with a semantic");
|
|
|
|
}
|
2012-07-16 20:39:21 +02:00
|
|
|
|
2015-06-16 22:45:44 +02:00
|
|
|
if ($7.reg_reservation)
|
|
|
|
{
|
|
|
|
FIXME("Unexpected register reservation for a function.\n");
|
|
|
|
d3dcompiler_free($7.reg_reservation);
|
|
|
|
}
|
2020-06-02 00:58:44 +02:00
|
|
|
if (!($$.decl = new_func_decl($2, $5, $7.semantic, get_location(&@3))))
|
2012-06-11 19:18:33 +02:00
|
|
|
{
|
|
|
|
ERR("Out of memory.\n");
|
2019-08-12 17:27:27 +02:00
|
|
|
YYABORT;
|
2012-06-11 19:18:33 +02:00
|
|
|
}
|
2012-10-11 19:48:48 +02:00
|
|
|
$$.name = $3;
|
2020-03-02 05:55:26 +01:00
|
|
|
hlsl_ctx.cur_function = $$.decl;
|
2012-06-11 19:18:33 +02:00
|
|
|
}
|
|
|
|
|
2012-06-11 19:18:34 +02:00
|
|
|
compound_statement: '{' '}'
|
|
|
|
{
|
|
|
|
$$ = d3dcompiler_alloc(sizeof(*$$));
|
|
|
|
list_init($$);
|
|
|
|
}
|
|
|
|
| '{' scope_start statement_list '}'
|
|
|
|
{
|
|
|
|
pop_scope(&hlsl_ctx);
|
|
|
|
$$ = $3;
|
|
|
|
}
|
|
|
|
|
2012-06-11 19:18:33 +02:00
|
|
|
scope_start: /* Empty */
|
|
|
|
{
|
|
|
|
push_scope(&hlsl_ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
var_identifier: VAR_IDENTIFIER
|
|
|
|
| NEW_IDENTIFIER
|
|
|
|
|
2015-06-16 22:45:44 +02:00
|
|
|
colon_attribute: /* Empty */
|
2012-06-04 17:58:24 +02:00
|
|
|
{
|
2015-06-16 22:45:44 +02:00
|
|
|
$$.semantic = NULL;
|
|
|
|
$$.reg_reservation = NULL;
|
|
|
|
}
|
|
|
|
| semantic
|
|
|
|
{
|
|
|
|
$$.semantic = $1;
|
|
|
|
$$.reg_reservation = NULL;
|
|
|
|
}
|
|
|
|
| register_opt
|
|
|
|
{
|
|
|
|
$$.semantic = NULL;
|
|
|
|
$$.reg_reservation = $1;
|
2012-06-04 17:58:24 +02:00
|
|
|
}
|
2015-06-16 22:45:44 +02:00
|
|
|
|
|
|
|
semantic: ':' any_identifier
|
2012-06-04 17:58:24 +02:00
|
|
|
{
|
|
|
|
$$ = $2;
|
|
|
|
}
|
|
|
|
|
2015-06-16 22:45:44 +02:00
|
|
|
/* FIXME: Writemasks */
|
|
|
|
register_opt: ':' KW_REGISTER '(' any_identifier ')'
|
|
|
|
{
|
|
|
|
$$ = parse_reg_reservation($4);
|
|
|
|
d3dcompiler_free($4);
|
|
|
|
}
|
|
|
|
| ':' KW_REGISTER '(' any_identifier ',' any_identifier ')'
|
|
|
|
{
|
|
|
|
FIXME("Ignoring shader target %s in a register reservation.\n", debugstr_a($4));
|
|
|
|
d3dcompiler_free($4);
|
|
|
|
|
|
|
|
$$ = parse_reg_reservation($6);
|
|
|
|
d3dcompiler_free($6);
|
|
|
|
}
|
|
|
|
|
2012-06-11 19:18:33 +02:00
|
|
|
parameters: scope_start
|
|
|
|
{
|
|
|
|
$$ = d3dcompiler_alloc(sizeof(*$$));
|
|
|
|
list_init($$);
|
|
|
|
}
|
|
|
|
| scope_start param_list
|
|
|
|
{
|
|
|
|
$$ = $2;
|
|
|
|
}
|
|
|
|
|
|
|
|
param_list: parameter
|
|
|
|
{
|
|
|
|
$$ = d3dcompiler_alloc(sizeof(*$$));
|
|
|
|
list_init($$);
|
2020-03-04 03:29:48 +01:00
|
|
|
if (!add_func_parameter($$, &$1, get_location(&@1)))
|
2012-06-11 19:18:33 +02:00
|
|
|
{
|
|
|
|
ERR("Error adding function parameter %s.\n", $1.name);
|
|
|
|
set_parse_status(&hlsl_ctx.status, PARSE_ERR);
|
2019-08-12 17:27:27 +02:00
|
|
|
YYABORT;
|
2012-06-11 19:18:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
| param_list ',' parameter
|
|
|
|
{
|
|
|
|
$$ = $1;
|
2020-03-04 03:29:48 +01:00
|
|
|
if (!add_func_parameter($$, &$3, get_location(&@3)))
|
2012-06-11 19:18:33 +02:00
|
|
|
{
|
2020-03-04 03:29:48 +01:00
|
|
|
hlsl_report_message(get_location(&@3), HLSL_LEVEL_ERROR,
|
2012-07-16 20:39:20 +02:00
|
|
|
"duplicate parameter %s", $3.name);
|
2019-08-12 17:27:27 +02:00
|
|
|
YYABORT;
|
2012-06-11 19:18:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-16 22:45:44 +02:00
|
|
|
parameter: input_mods var_modifiers type any_identifier colon_attribute
|
2012-06-11 19:18:33 +02:00
|
|
|
{
|
2020-03-13 17:34:56 +01:00
|
|
|
struct hlsl_type *type;
|
|
|
|
DWORD modifiers = $2;
|
|
|
|
|
|
|
|
if (!(type = apply_type_modifiers($3, &modifiers, get_location(&@2))))
|
|
|
|
YYABORT;
|
|
|
|
|
2020-03-15 22:25:09 +01:00
|
|
|
$$.modifiers = $1 ? $1 : HLSL_STORAGE_IN;
|
2020-03-13 17:34:56 +01:00
|
|
|
$$.modifiers |= modifiers;
|
|
|
|
$$.type = type;
|
2012-06-11 19:18:33 +02:00
|
|
|
$$.name = $4;
|
2015-06-16 22:45:44 +02:00
|
|
|
$$.semantic = $5.semantic;
|
|
|
|
$$.reg_reservation = $5.reg_reservation;
|
2012-06-11 19:18:33 +02:00
|
|
|
}
|
|
|
|
|
2012-10-11 19:48:47 +02:00
|
|
|
input_mods: /* Empty */
|
2012-06-11 19:18:33 +02:00
|
|
|
{
|
2012-10-11 19:48:47 +02:00
|
|
|
$$ = 0;
|
2012-06-11 19:18:33 +02:00
|
|
|
}
|
2012-10-11 19:48:47 +02:00
|
|
|
| input_mods input_mod
|
|
|
|
{
|
|
|
|
if ($1 & $2)
|
|
|
|
{
|
2020-03-04 03:29:47 +01:00
|
|
|
hlsl_report_message(get_location(&@2), HLSL_LEVEL_ERROR,
|
|
|
|
"duplicate input-output modifiers");
|
2019-08-12 17:27:27 +02:00
|
|
|
YYABORT;
|
2012-10-11 19:48:47 +02:00
|
|
|
}
|
|
|
|
$$ = $1 | $2;
|
|
|
|
}
|
|
|
|
|
|
|
|
input_mod: KW_IN
|
2012-06-11 19:18:33 +02:00
|
|
|
{
|
2020-03-15 22:25:09 +01:00
|
|
|
$$ = HLSL_STORAGE_IN;
|
2012-06-11 19:18:33 +02:00
|
|
|
}
|
|
|
|
| KW_OUT
|
|
|
|
{
|
2020-03-15 22:25:09 +01:00
|
|
|
$$ = HLSL_STORAGE_OUT;
|
2012-06-11 19:18:33 +02:00
|
|
|
}
|
|
|
|
| KW_INOUT
|
|
|
|
{
|
2020-03-15 22:25:09 +01:00
|
|
|
$$ = HLSL_STORAGE_IN | HLSL_STORAGE_OUT;
|
2012-06-11 19:18:33 +02:00
|
|
|
}
|
|
|
|
|
2020-06-04 04:06:54 +02:00
|
|
|
type:
|
2012-06-11 19:18:31 +02:00
|
|
|
|
2020-06-04 04:06:54 +02:00
|
|
|
base_type
|
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
}
|
|
|
|
| KW_VECTOR '<' base_type ',' C_INTEGER '>'
|
|
|
|
{
|
|
|
|
if ($3->type != HLSL_CLASS_SCALAR)
|
|
|
|
{
|
|
|
|
hlsl_report_message(get_location(&@3), HLSL_LEVEL_ERROR,
|
|
|
|
"vectors of non-scalar types are not allowed\n");
|
|
|
|
YYABORT;
|
|
|
|
}
|
|
|
|
if ($5 < 1 || $5 > 4)
|
|
|
|
{
|
|
|
|
hlsl_report_message(get_location(&@5), HLSL_LEVEL_ERROR,
|
|
|
|
"vector size must be between 1 and 4\n");
|
|
|
|
YYABORT;
|
|
|
|
}
|
2012-06-11 19:18:31 +02:00
|
|
|
|
2020-06-04 04:06:54 +02:00
|
|
|
$$ = 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_report_message(get_location(&@3), HLSL_LEVEL_ERROR,
|
|
|
|
"matrices of non-scalar types are not allowed\n");
|
|
|
|
YYABORT;
|
|
|
|
}
|
|
|
|
if ($5 < 1 || $5 > 4)
|
|
|
|
{
|
|
|
|
hlsl_report_message(get_location(&@5), HLSL_LEVEL_ERROR,
|
|
|
|
"matrix row count must be between 1 and 4\n");
|
|
|
|
YYABORT;
|
|
|
|
}
|
|
|
|
if ($7 < 1 || $7 > 4)
|
|
|
|
{
|
|
|
|
hlsl_report_message(get_location(&@7), HLSL_LEVEL_ERROR,
|
|
|
|
"matrix column count must be between 1 and 4\n");
|
|
|
|
YYABORT;
|
|
|
|
}
|
|
|
|
|
|
|
|
$$ = new_hlsl_type(NULL, HLSL_CLASS_MATRIX, $3->base_type, $7, $5);
|
|
|
|
}
|
2012-06-04 17:58:24 +02:00
|
|
|
|
2020-06-02 00:58:41 +02:00
|
|
|
base_type:
|
2012-06-04 17:58:24 +02:00
|
|
|
|
2020-06-02 00:58:41 +02:00
|
|
|
KW_VOID
|
|
|
|
{
|
|
|
|
$$ = hlsl_ctx.builtin_types.Void;
|
|
|
|
}
|
|
|
|
| KW_SAMPLER
|
|
|
|
{
|
|
|
|
$$ = hlsl_ctx.builtin_types.sampler[HLSL_SAMPLER_DIM_GENERIC];
|
|
|
|
}
|
|
|
|
| KW_SAMPLER1D
|
|
|
|
{
|
|
|
|
$$ = hlsl_ctx.builtin_types.sampler[HLSL_SAMPLER_DIM_1D];
|
|
|
|
}
|
|
|
|
| KW_SAMPLER2D
|
|
|
|
{
|
|
|
|
$$ = hlsl_ctx.builtin_types.sampler[HLSL_SAMPLER_DIM_2D];
|
|
|
|
}
|
|
|
|
| KW_SAMPLER3D
|
|
|
|
{
|
|
|
|
$$ = hlsl_ctx.builtin_types.sampler[HLSL_SAMPLER_DIM_3D];
|
|
|
|
}
|
|
|
|
| KW_SAMPLERCUBE
|
|
|
|
{
|
|
|
|
$$ = hlsl_ctx.builtin_types.sampler[HLSL_SAMPLER_DIM_3D];
|
|
|
|
}
|
|
|
|
| TYPE_IDENTIFIER
|
|
|
|
{
|
|
|
|
$$ = get_type(hlsl_ctx.cur_scope, $1, TRUE);
|
|
|
|
d3dcompiler_free($1);
|
|
|
|
}
|
|
|
|
| KW_STRUCT TYPE_IDENTIFIER
|
|
|
|
{
|
|
|
|
$$ = get_type(hlsl_ctx.cur_scope, $2, TRUE);
|
|
|
|
if ($$->type != HLSL_CLASS_STRUCT)
|
2020-06-04 04:06:54 +02:00
|
|
|
hlsl_report_message(get_location(&@1), HLSL_LEVEL_ERROR, "'%s' redefined as a structure\n", $2);
|
2020-06-02 00:58:41 +02:00
|
|
|
d3dcompiler_free($2);
|
|
|
|
}
|
2012-06-04 17:58:24 +02:00
|
|
|
|
|
|
|
declaration_statement: declaration
|
2012-09-26 19:22:32 +02:00
|
|
|
| struct_declaration
|
2012-09-19 19:46:13 +02:00
|
|
|
| typedef
|
|
|
|
{
|
|
|
|
$$ = d3dcompiler_alloc(sizeof(*$$));
|
|
|
|
if (!$$)
|
|
|
|
{
|
|
|
|
ERR("Out of memory\n");
|
2019-08-12 17:27:27 +02:00
|
|
|
YYABORT;
|
2012-09-19 19:46:13 +02:00
|
|
|
}
|
|
|
|
list_init($$);
|
|
|
|
}
|
|
|
|
|
2020-03-15 22:25:10 +01:00
|
|
|
typedef_type: type
|
|
|
|
| struct_spec
|
|
|
|
|
|
|
|
typedef: KW_TYPEDEF var_modifiers typedef_type type_specs ';'
|
2012-09-19 19:46:13 +02:00
|
|
|
{
|
2020-03-04 03:29:49 +01:00
|
|
|
if ($2 & ~HLSL_TYPE_MODIFIERS_MASK)
|
|
|
|
{
|
|
|
|
struct parse_variable_def *v, *v_next;
|
|
|
|
hlsl_report_message(get_location(&@1),
|
|
|
|
HLSL_LEVEL_ERROR, "modifier not allowed on typedefs");
|
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(v, v_next, $4, struct parse_variable_def, entry)
|
|
|
|
d3dcompiler_free(v);
|
|
|
|
d3dcompiler_free($4);
|
|
|
|
YYABORT;
|
|
|
|
}
|
|
|
|
if (!add_typedef($2, $3, $4))
|
2019-08-12 17:27:27 +02:00
|
|
|
YYABORT;
|
2012-09-28 17:22:40 +02:00
|
|
|
}
|
2012-09-19 19:46:13 +02:00
|
|
|
|
|
|
|
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(*$$));
|
2020-03-04 03:29:46 +01:00
|
|
|
$$->loc = get_location(&@1);
|
2012-09-19 19:46:13 +02:00
|
|
|
$$->name = $1;
|
|
|
|
$$->array_size = $2;
|
|
|
|
}
|
2012-06-04 17:58:24 +02:00
|
|
|
|
|
|
|
declaration: var_modifiers type variables_def ';'
|
|
|
|
{
|
2020-03-13 17:34:56 +01:00
|
|
|
struct hlsl_type *type;
|
|
|
|
DWORD modifiers = $1;
|
|
|
|
|
|
|
|
if (!(type = apply_type_modifiers($2, &modifiers, get_location(&@1))))
|
|
|
|
YYABORT;
|
|
|
|
$$ = declare_vars(type, modifiers, $3);
|
2012-06-04 17:58:24 +02:00
|
|
|
}
|
|
|
|
|
2012-09-26 19:22:32 +02:00
|
|
|
variables_def_optional: /* Empty */
|
|
|
|
{
|
|
|
|
$$ = NULL;
|
|
|
|
}
|
|
|
|
| variables_def
|
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
}
|
|
|
|
|
2012-06-04 17:58:24 +02:00
|
|
|
variables_def: variable_def
|
|
|
|
{
|
|
|
|
$$ = d3dcompiler_alloc(sizeof(*$$));
|
|
|
|
list_init($$);
|
|
|
|
list_add_head($$, &$1->entry);
|
|
|
|
}
|
|
|
|
| variables_def ',' variable_def
|
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
list_add_tail($$, &$3->entry);
|
|
|
|
}
|
|
|
|
|
2015-06-16 22:45:44 +02:00
|
|
|
variable_def: any_identifier array colon_attribute
|
2012-06-04 17:58:24 +02:00
|
|
|
{
|
|
|
|
$$ = d3dcompiler_alloc(sizeof(*$$));
|
2020-03-04 03:29:46 +01:00
|
|
|
$$->loc = get_location(&@1);
|
2012-06-04 17:58:24 +02:00
|
|
|
$$->name = $1;
|
|
|
|
$$->array_size = $2;
|
2015-06-16 22:45:44 +02:00
|
|
|
$$->semantic = $3.semantic;
|
|
|
|
$$->reg_reservation = $3.reg_reservation;
|
2012-06-04 17:58:24 +02:00
|
|
|
}
|
2015-06-16 22:45:44 +02:00
|
|
|
| any_identifier array colon_attribute '=' complex_initializer
|
2012-06-07 00:19:04 +02:00
|
|
|
{
|
|
|
|
TRACE("Declaration with initializer.\n");
|
|
|
|
$$ = d3dcompiler_alloc(sizeof(*$$));
|
2020-03-04 03:29:46 +01:00
|
|
|
$$->loc = get_location(&@1);
|
2012-06-07 00:19:04 +02:00
|
|
|
$$->name = $1;
|
|
|
|
$$->array_size = $2;
|
2015-06-16 22:45:44 +02:00
|
|
|
$$->semantic = $3.semantic;
|
|
|
|
$$->reg_reservation = $3.reg_reservation;
|
2012-06-07 00:19:04 +02:00
|
|
|
$$->initializer = $5;
|
|
|
|
}
|
2012-06-04 17:58:24 +02:00
|
|
|
|
|
|
|
array: /* Empty */
|
|
|
|
{
|
|
|
|
$$ = 0;
|
|
|
|
}
|
2012-06-07 00:19:04 +02:00
|
|
|
| '[' expr ']'
|
|
|
|
{
|
2020-03-07 00:17:30 +01:00
|
|
|
unsigned int size = evaluate_array_dimension(node_from_list($2));
|
|
|
|
|
2020-02-13 04:57:18 +01:00
|
|
|
free_instr_list($2);
|
2020-03-07 00:17:30 +01:00
|
|
|
|
|
|
|
if (!size)
|
|
|
|
{
|
|
|
|
hlsl_report_message(get_location(&@2), HLSL_LEVEL_ERROR,
|
|
|
|
"array size is not a positive integer constant\n");
|
|
|
|
YYABORT;
|
|
|
|
}
|
|
|
|
TRACE("Array size %u.\n", size);
|
|
|
|
|
|
|
|
if (size > 65536)
|
|
|
|
{
|
|
|
|
hlsl_report_message(get_location(&@2), HLSL_LEVEL_ERROR,
|
|
|
|
"array size must be between 1 and 65536");
|
|
|
|
YYABORT;
|
|
|
|
}
|
|
|
|
$$ = size;
|
2012-06-07 00:19:04 +02:00
|
|
|
}
|
2012-06-04 17:58:24 +02:00
|
|
|
|
|
|
|
var_modifiers: /* Empty */
|
|
|
|
{
|
|
|
|
$$ = 0;
|
|
|
|
}
|
2012-06-07 00:19:03 +02:00
|
|
|
| KW_EXTERN var_modifiers
|
|
|
|
{
|
2020-03-13 17:34:56 +01:00
|
|
|
$$ = add_modifiers($2, HLSL_STORAGE_EXTERN, get_location(&@1));
|
2012-06-07 00:19:03 +02:00
|
|
|
}
|
|
|
|
| KW_NOINTERPOLATION var_modifiers
|
|
|
|
{
|
2020-03-13 17:34:56 +01:00
|
|
|
$$ = add_modifiers($2, HLSL_STORAGE_NOINTERPOLATION, get_location(&@1));
|
2012-06-07 00:19:03 +02:00
|
|
|
}
|
|
|
|
| KW_PRECISE var_modifiers
|
|
|
|
{
|
2020-03-13 17:34:56 +01:00
|
|
|
$$ = add_modifiers($2, HLSL_MODIFIER_PRECISE, get_location(&@1));
|
2012-06-07 00:19:03 +02:00
|
|
|
}
|
|
|
|
| KW_SHARED var_modifiers
|
|
|
|
{
|
2020-03-13 17:34:56 +01:00
|
|
|
$$ = add_modifiers($2, HLSL_STORAGE_SHARED, get_location(&@1));
|
2012-06-07 00:19:03 +02:00
|
|
|
}
|
|
|
|
| KW_GROUPSHARED var_modifiers
|
|
|
|
{
|
2020-03-13 17:34:56 +01:00
|
|
|
$$ = add_modifiers($2, HLSL_STORAGE_GROUPSHARED, get_location(&@1));
|
2012-06-07 00:19:03 +02:00
|
|
|
}
|
|
|
|
| KW_STATIC var_modifiers
|
|
|
|
{
|
2020-03-13 17:34:56 +01:00
|
|
|
$$ = add_modifiers($2, HLSL_STORAGE_STATIC, get_location(&@1));
|
2012-06-07 00:19:03 +02:00
|
|
|
}
|
|
|
|
| KW_UNIFORM var_modifiers
|
|
|
|
{
|
2020-03-13 17:34:56 +01:00
|
|
|
$$ = add_modifiers($2, HLSL_STORAGE_UNIFORM, get_location(&@1));
|
2012-06-07 00:19:03 +02:00
|
|
|
}
|
|
|
|
| KW_VOLATILE var_modifiers
|
|
|
|
{
|
2020-03-13 17:34:56 +01:00
|
|
|
$$ = add_modifiers($2, HLSL_STORAGE_VOLATILE, get_location(&@1));
|
2012-06-07 00:19:03 +02:00
|
|
|
}
|
|
|
|
| KW_CONST var_modifiers
|
|
|
|
{
|
2020-03-13 17:34:56 +01:00
|
|
|
$$ = add_modifiers($2, HLSL_MODIFIER_CONST, get_location(&@1));
|
2012-06-07 00:19:03 +02:00
|
|
|
}
|
|
|
|
| KW_ROW_MAJOR var_modifiers
|
|
|
|
{
|
2020-03-13 17:34:56 +01:00
|
|
|
$$ = add_modifiers($2, HLSL_MODIFIER_ROW_MAJOR, get_location(&@1));
|
2012-06-07 00:19:03 +02:00
|
|
|
}
|
|
|
|
| KW_COLUMN_MAJOR var_modifiers
|
|
|
|
{
|
2020-03-13 17:34:56 +01:00
|
|
|
$$ = add_modifiers($2, HLSL_MODIFIER_COLUMN_MAJOR, get_location(&@1));
|
2012-06-07 00:19:03 +02:00
|
|
|
}
|
2012-06-04 17:58:24 +02:00
|
|
|
|
2012-06-07 00:19:04 +02:00
|
|
|
complex_initializer: initializer_expr
|
|
|
|
{
|
2019-08-12 17:27:28 +02:00
|
|
|
$$.args_count = 1;
|
|
|
|
if (!($$.args = d3dcompiler_alloc(sizeof(*$$.args))))
|
|
|
|
YYABORT;
|
2020-02-13 04:57:18 +01:00
|
|
|
$$.args[0] = node_from_list($1);
|
|
|
|
$$.instrs = $1;
|
2012-06-07 00:19:04 +02:00
|
|
|
}
|
|
|
|
| '{' initializer_expr_list '}'
|
|
|
|
{
|
|
|
|
$$ = $2;
|
|
|
|
}
|
2012-11-09 15:20:37 +01:00
|
|
|
| '{' initializer_expr_list ',' '}'
|
|
|
|
{
|
|
|
|
$$ = $2;
|
|
|
|
}
|
2012-06-07 00:19:04 +02:00
|
|
|
|
|
|
|
initializer_expr: assignment_expr
|
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
}
|
|
|
|
|
|
|
|
initializer_expr_list: initializer_expr
|
|
|
|
{
|
2019-08-12 17:27:28 +02:00
|
|
|
$$.args_count = 1;
|
|
|
|
if (!($$.args = d3dcompiler_alloc(sizeof(*$$.args))))
|
|
|
|
YYABORT;
|
2020-02-13 04:57:18 +01:00
|
|
|
$$.args[0] = node_from_list($1);
|
|
|
|
$$.instrs = $1;
|
2012-06-07 00:19:04 +02:00
|
|
|
}
|
|
|
|
| initializer_expr_list ',' initializer_expr
|
|
|
|
{
|
|
|
|
$$ = $1;
|
2019-08-12 17:27:28 +02:00
|
|
|
if (!($$.args = d3dcompiler_realloc($$.args, ($$.args_count + 1) * sizeof(*$$.args))))
|
|
|
|
YYABORT;
|
2020-02-13 04:57:18 +01:00
|
|
|
$$.args[$$.args_count++] = node_from_list($3);
|
|
|
|
list_move_tail($$.instrs, $3);
|
|
|
|
d3dcompiler_free($3);
|
2012-06-07 00:19:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
boolean: KW_TRUE
|
|
|
|
{
|
|
|
|
$$ = TRUE;
|
|
|
|
}
|
|
|
|
| KW_FALSE
|
|
|
|
{
|
|
|
|
$$ = FALSE;
|
|
|
|
}
|
|
|
|
|
2012-06-11 19:18:34 +02:00
|
|
|
statement_list: statement
|
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
}
|
|
|
|
| statement_list statement
|
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
list_move_tail($$, $2);
|
|
|
|
d3dcompiler_free($2);
|
|
|
|
}
|
|
|
|
|
|
|
|
statement: declaration_statement
|
|
|
|
| expr_statement
|
|
|
|
| compound_statement
|
2012-09-18 18:18:08 +02:00
|
|
|
| jump_statement
|
2012-09-19 19:46:11 +02:00
|
|
|
| selection_statement
|
2012-09-21 16:25:56 +02:00
|
|
|
| loop_statement
|
2012-09-18 18:18:08 +02:00
|
|
|
|
2020-06-22 22:53:00 +02:00
|
|
|
jump_statement:
|
2012-09-18 18:18:08 +02:00
|
|
|
|
2020-06-22 22:53:00 +02:00
|
|
|
KW_RETURN expr ';'
|
|
|
|
{
|
|
|
|
if (!add_return($2, node_from_list($2), get_location(&@1)))
|
|
|
|
YYABORT;
|
|
|
|
$$ = $2;
|
|
|
|
}
|
|
|
|
| KW_RETURN ';'
|
|
|
|
{
|
|
|
|
if (!($$ = d3dcompiler_alloc(sizeof(*$$))))
|
|
|
|
YYABORT;
|
|
|
|
list_init($$);
|
|
|
|
if (!add_return($$, NULL, get_location(&@1)))
|
|
|
|
YYABORT;
|
|
|
|
}
|
2012-06-11 19:18:34 +02:00
|
|
|
|
2012-09-19 19:46:11 +02:00
|
|
|
selection_statement: KW_IF '(' expr ')' if_body
|
|
|
|
{
|
2020-06-30 01:55:35 +02:00
|
|
|
struct hlsl_ir_node *condition = node_from_list($3);
|
2020-07-07 23:09:24 +02:00
|
|
|
struct hlsl_ir_if *instr;
|
2020-06-30 01:55:35 +02:00
|
|
|
|
2020-07-07 23:09:24 +02:00
|
|
|
if (!(instr = new_if(condition, get_location(&@1))))
|
2019-08-12 17:27:27 +02:00
|
|
|
YYABORT;
|
2020-07-07 23:09:24 +02:00
|
|
|
list_move_tail(&instr->then_instrs, $5.then_instrs);
|
|
|
|
list_move_tail(&instr->else_instrs, $5.else_instrs);
|
|
|
|
d3dcompiler_free($5.then_instrs);
|
|
|
|
d3dcompiler_free($5.else_instrs);
|
2020-06-30 01:55:35 +02:00
|
|
|
if (condition->data_type->dimx > 1 || condition->data_type->dimy > 1)
|
2012-09-19 19:46:11 +02:00
|
|
|
{
|
2020-03-04 03:29:47 +01:00
|
|
|
hlsl_report_message(instr->node.loc, HLSL_LEVEL_ERROR,
|
2012-09-19 19:46:11 +02:00
|
|
|
"if condition requires a scalar");
|
|
|
|
}
|
2020-02-13 04:57:18 +01:00
|
|
|
$$ = $3;
|
|
|
|
list_add_tail($$, &instr->node.entry);
|
2012-09-19 19:46:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if_body: statement
|
|
|
|
{
|
|
|
|
$$.then_instrs = $1;
|
|
|
|
$$.else_instrs = NULL;
|
|
|
|
}
|
|
|
|
| statement KW_ELSE statement
|
|
|
|
{
|
|
|
|
$$.then_instrs = $1;
|
|
|
|
$$.else_instrs = $3;
|
|
|
|
}
|
|
|
|
|
2012-09-21 16:25:56 +02:00
|
|
|
loop_statement: KW_WHILE '(' expr ')' statement
|
|
|
|
{
|
2020-03-04 03:29:51 +01:00
|
|
|
$$ = create_loop(LOOP_WHILE, NULL, $3, NULL, $5, get_location(&@1));
|
2012-09-21 16:25:56 +02:00
|
|
|
}
|
2012-09-21 16:25:57 +02:00
|
|
|
| KW_DO statement KW_WHILE '(' expr ')' ';'
|
|
|
|
{
|
2020-03-04 03:29:51 +01:00
|
|
|
$$ = create_loop(LOOP_DO_WHILE, NULL, $5, NULL, $2, get_location(&@1));
|
2012-09-21 16:25:57 +02:00
|
|
|
}
|
2012-10-10 18:25:58 +02:00
|
|
|
| KW_FOR '(' scope_start expr_statement expr_statement expr ')' statement
|
2012-09-21 16:25:58 +02:00
|
|
|
{
|
2020-03-04 03:29:51 +01:00
|
|
|
$$ = create_loop(LOOP_FOR, $4, $5, $6, $8, get_location(&@1));
|
2012-09-21 16:25:58 +02:00
|
|
|
pop_scope(&hlsl_ctx);
|
|
|
|
}
|
2012-10-10 18:25:58 +02:00
|
|
|
| KW_FOR '(' scope_start declaration expr_statement expr ')' statement
|
2012-09-21 16:25:59 +02:00
|
|
|
{
|
|
|
|
if (!$4)
|
2020-03-04 03:29:51 +01:00
|
|
|
hlsl_report_message(get_location(&@4), HLSL_LEVEL_WARNING,
|
2012-09-21 16:25:59 +02:00
|
|
|
"no expressions in for loop initializer");
|
2020-03-04 03:29:51 +01:00
|
|
|
$$ = create_loop(LOOP_FOR, $4, $5, $6, $8, get_location(&@1));
|
2012-09-21 16:25:59 +02:00
|
|
|
pop_scope(&hlsl_ctx);
|
|
|
|
}
|
2012-09-21 16:25:56 +02:00
|
|
|
|
2012-06-11 19:18:34 +02:00
|
|
|
expr_statement: ';'
|
|
|
|
{
|
|
|
|
$$ = d3dcompiler_alloc(sizeof(*$$));
|
|
|
|
list_init($$);
|
|
|
|
}
|
|
|
|
| expr ';'
|
|
|
|
{
|
2020-02-13 04:57:18 +01:00
|
|
|
$$ = $1;
|
2012-06-11 19:18:34 +02:00
|
|
|
}
|
|
|
|
|
2012-06-07 00:19:04 +02:00
|
|
|
primary_expr: C_FLOAT
|
|
|
|
{
|
|
|
|
struct hlsl_ir_constant *c = d3dcompiler_alloc(sizeof(*c));
|
|
|
|
if (!c)
|
|
|
|
{
|
|
|
|
ERR("Out of memory.\n");
|
2019-08-12 17:27:27 +02:00
|
|
|
YYABORT;
|
2012-06-07 00:19:04 +02:00
|
|
|
}
|
2020-06-02 00:58:41 +02:00
|
|
|
init_node(&c->node, HLSL_IR_CONSTANT,
|
|
|
|
hlsl_ctx.builtin_types.scalar[HLSL_TYPE_FLOAT], get_location(&@1));
|
2020-06-08 23:49:37 +02:00
|
|
|
c->value.f[0] = $1;
|
2020-02-13 04:57:18 +01:00
|
|
|
if (!($$ = make_list(&c->node)))
|
|
|
|
YYABORT;
|
2012-06-07 00:19:04 +02:00
|
|
|
}
|
|
|
|
| C_INTEGER
|
|
|
|
{
|
|
|
|
struct hlsl_ir_constant *c = d3dcompiler_alloc(sizeof(*c));
|
|
|
|
if (!c)
|
|
|
|
{
|
|
|
|
ERR("Out of memory.\n");
|
2019-08-12 17:27:27 +02:00
|
|
|
YYABORT;
|
2012-06-07 00:19:04 +02:00
|
|
|
}
|
2020-06-02 00:58:41 +02:00
|
|
|
init_node(&c->node, HLSL_IR_CONSTANT,
|
|
|
|
hlsl_ctx.builtin_types.scalar[HLSL_TYPE_INT], get_location(&@1));
|
2020-06-08 23:49:37 +02:00
|
|
|
c->value.i[0] = $1;
|
2020-02-13 04:57:18 +01:00
|
|
|
if (!($$ = make_list(&c->node)))
|
|
|
|
YYABORT;
|
2012-06-07 00:19:04 +02:00
|
|
|
}
|
|
|
|
| boolean
|
|
|
|
{
|
|
|
|
struct hlsl_ir_constant *c = d3dcompiler_alloc(sizeof(*c));
|
|
|
|
if (!c)
|
|
|
|
{
|
|
|
|
ERR("Out of memory.\n");
|
2019-08-12 17:27:27 +02:00
|
|
|
YYABORT;
|
2012-06-07 00:19:04 +02:00
|
|
|
}
|
2020-06-02 00:58:41 +02:00
|
|
|
init_node(&c->node, HLSL_IR_CONSTANT,
|
|
|
|
hlsl_ctx.builtin_types.scalar[HLSL_TYPE_BOOL], get_location(&@1));
|
2020-06-08 23:49:37 +02:00
|
|
|
c->value.b[0] = $1;
|
2020-02-13 04:57:18 +01:00
|
|
|
if (!($$ = make_list(&c->node)))
|
|
|
|
YYABORT;
|
2012-06-07 00:19:04 +02:00
|
|
|
}
|
2019-08-09 16:52:44 +02:00
|
|
|
| VAR_IDENTIFIER
|
2012-06-07 00:19:05 +02:00
|
|
|
{
|
2020-05-22 22:45:30 +02:00
|
|
|
struct hlsl_ir_load *load;
|
2019-08-09 16:52:44 +02:00
|
|
|
struct hlsl_ir_var *var;
|
|
|
|
|
|
|
|
if (!(var = get_variable(hlsl_ctx.cur_scope, $1)))
|
|
|
|
{
|
2020-06-04 04:06:54 +02:00
|
|
|
hlsl_report_message(get_location(&@1), HLSL_LEVEL_ERROR,
|
|
|
|
"variable '%s' is not declared\n", $1);
|
2019-08-12 17:27:27 +02:00
|
|
|
YYABORT;
|
2019-08-09 16:52:44 +02:00
|
|
|
}
|
2020-05-22 22:45:30 +02:00
|
|
|
if ((load = new_var_load(var, get_location(&@1))))
|
2012-07-16 20:39:19 +02:00
|
|
|
{
|
2020-05-22 22:45:30 +02:00
|
|
|
if (!($$ = make_list(&load->node)))
|
2020-02-13 04:57:18 +01:00
|
|
|
YYABORT;
|
2012-07-16 20:39:19 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
$$ = NULL;
|
2012-06-07 00:19:05 +02:00
|
|
|
}
|
2012-06-07 00:19:04 +02:00
|
|
|
| '(' expr ')'
|
|
|
|
{
|
|
|
|
$$ = $2;
|
|
|
|
}
|
|
|
|
|
|
|
|
postfix_expr: primary_expr
|
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
}
|
2012-07-20 16:37:37 +02:00
|
|
|
| postfix_expr OP_INC
|
|
|
|
{
|
|
|
|
struct source_location loc;
|
2020-02-13 04:57:18 +01:00
|
|
|
struct hlsl_ir_node *inc;
|
2012-07-20 16:37:37 +02:00
|
|
|
|
2020-03-04 03:29:46 +01:00
|
|
|
loc = get_location(&@2);
|
2020-02-13 04:57:18 +01:00
|
|
|
if (node_from_list($1)->data_type->modifiers & HLSL_MODIFIER_CONST)
|
2012-09-17 15:32:05 +02:00
|
|
|
{
|
2020-03-04 03:29:47 +01:00
|
|
|
hlsl_report_message(loc, HLSL_LEVEL_ERROR, "modifying a const expression");
|
2019-08-12 17:27:27 +02:00
|
|
|
YYABORT;
|
2012-09-17 15:32:05 +02:00
|
|
|
}
|
2020-02-13 04:57:18 +01:00
|
|
|
inc = new_unary_expr(HLSL_IR_UNOP_POSTINC, node_from_list($1), loc);
|
2012-09-17 15:32:05 +02:00
|
|
|
/* Post increment/decrement expressions are considered const */
|
2020-04-02 23:14:12 +02:00
|
|
|
inc->data_type = clone_hlsl_type(inc->data_type, 0);
|
2020-02-13 04:57:18 +01:00
|
|
|
inc->data_type->modifiers |= HLSL_MODIFIER_CONST;
|
|
|
|
$$ = append_unop($1, inc);
|
2012-07-20 16:37:37 +02:00
|
|
|
}
|
|
|
|
| postfix_expr OP_DEC
|
|
|
|
{
|
|
|
|
struct source_location loc;
|
2020-02-13 04:57:18 +01:00
|
|
|
struct hlsl_ir_node *inc;
|
2012-07-20 16:37:37 +02:00
|
|
|
|
2020-03-04 03:29:46 +01:00
|
|
|
loc = get_location(&@2);
|
2020-02-13 04:57:18 +01:00
|
|
|
if (node_from_list($1)->data_type->modifiers & HLSL_MODIFIER_CONST)
|
2012-09-17 15:32:05 +02:00
|
|
|
{
|
2020-03-04 03:29:47 +01:00
|
|
|
hlsl_report_message(loc, HLSL_LEVEL_ERROR, "modifying a const expression");
|
2019-08-12 17:27:27 +02:00
|
|
|
YYABORT;
|
2012-09-17 15:32:05 +02:00
|
|
|
}
|
2020-02-13 04:57:18 +01:00
|
|
|
inc = new_unary_expr(HLSL_IR_UNOP_POSTDEC, node_from_list($1), loc);
|
2012-09-17 15:32:05 +02:00
|
|
|
/* Post increment/decrement expressions are considered const */
|
2020-04-02 23:14:12 +02:00
|
|
|
inc->data_type = clone_hlsl_type(inc->data_type, 0);
|
2020-02-13 04:57:18 +01:00
|
|
|
inc->data_type->modifiers |= HLSL_MODIFIER_CONST;
|
|
|
|
$$ = append_unop($1, inc);
|
2012-07-20 16:37:37 +02:00
|
|
|
}
|
2012-09-17 15:32:04 +02:00
|
|
|
| postfix_expr '.' any_identifier
|
|
|
|
{
|
2020-02-13 04:57:18 +01:00
|
|
|
struct hlsl_ir_node *node = node_from_list($1);
|
2012-09-17 15:32:04 +02:00
|
|
|
struct source_location loc;
|
|
|
|
|
2020-03-04 03:29:46 +01:00
|
|
|
loc = get_location(&@2);
|
2020-02-13 04:57:18 +01:00
|
|
|
if (node->data_type->type == HLSL_CLASS_STRUCT)
|
2012-09-28 17:22:39 +02:00
|
|
|
{
|
2020-02-13 04:57:18 +01:00
|
|
|
struct hlsl_type *type = node->data_type;
|
2012-09-28 17:22:39 +02:00
|
|
|
struct hlsl_struct_field *field;
|
|
|
|
|
|
|
|
$$ = NULL;
|
|
|
|
LIST_FOR_EACH_ENTRY(field, type->e.elements, struct hlsl_struct_field, entry)
|
|
|
|
{
|
|
|
|
if (!strcmp($3, field->name))
|
|
|
|
{
|
2020-06-18 17:46:24 +02:00
|
|
|
if (!add_record_load($1, node, field, loc))
|
2019-08-12 17:27:27 +02:00
|
|
|
YYABORT;
|
2020-06-02 00:58:42 +02:00
|
|
|
$$ = $1;
|
2012-09-28 17:22:39 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!$$)
|
|
|
|
{
|
2020-03-04 03:29:47 +01:00
|
|
|
hlsl_report_message(loc, HLSL_LEVEL_ERROR,
|
2012-09-28 17:22:39 +02:00
|
|
|
"invalid subscript %s", debugstr_a($3));
|
2019-08-12 17:27:27 +02:00
|
|
|
YYABORT;
|
2012-09-28 17:22:39 +02:00
|
|
|
}
|
|
|
|
}
|
2020-02-13 04:57:18 +01:00
|
|
|
else if (node->data_type->type <= HLSL_CLASS_LAST_NUMERIC)
|
2012-09-17 15:32:04 +02:00
|
|
|
{
|
|
|
|
struct hlsl_ir_swizzle *swizzle;
|
|
|
|
|
2020-02-13 04:57:18 +01:00
|
|
|
swizzle = get_swizzle(node, $3, &loc);
|
2012-09-17 15:32:04 +02:00
|
|
|
if (!swizzle)
|
|
|
|
{
|
2020-03-04 03:29:47 +01:00
|
|
|
hlsl_report_message(loc, HLSL_LEVEL_ERROR,
|
2012-09-17 15:32:04 +02:00
|
|
|
"invalid swizzle %s", debugstr_a($3));
|
2019-08-12 17:27:27 +02:00
|
|
|
YYABORT;
|
2012-09-17 15:32:04 +02:00
|
|
|
}
|
2020-02-13 04:57:18 +01:00
|
|
|
$$ = append_unop($1, &swizzle->node);
|
2012-09-17 15:32:04 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-03-04 03:29:47 +01:00
|
|
|
hlsl_report_message(loc, HLSL_LEVEL_ERROR,
|
2012-09-17 15:32:04 +02:00
|
|
|
"invalid subscript %s", debugstr_a($3));
|
2019-08-12 17:27:27 +02:00
|
|
|
YYABORT;
|
2012-09-17 15:32:04 +02:00
|
|
|
}
|
|
|
|
}
|
2020-06-18 17:46:24 +02:00
|
|
|
| postfix_expr '[' expr ']'
|
|
|
|
{
|
|
|
|
struct hlsl_ir_node *array = node_from_list($1), *index = node_from_list($3);
|
2020-05-01 06:54:23 +02:00
|
|
|
|
2020-06-18 17:46:24 +02:00
|
|
|
list_move_tail($1, $3);
|
|
|
|
d3dcompiler_free($3);
|
2020-05-01 06:54:23 +02:00
|
|
|
|
2020-06-18 17:46:24 +02:00
|
|
|
if (index->data_type->type != HLSL_CLASS_SCALAR)
|
|
|
|
{
|
|
|
|
hlsl_report_message(get_location(&@3), HLSL_LEVEL_ERROR, "array index is not scalar");
|
|
|
|
free_instr_list($1);
|
|
|
|
YYABORT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!add_array_load($1, array, index, get_location(&@2)))
|
|
|
|
{
|
|
|
|
free_instr_list($1);
|
|
|
|
YYABORT;
|
|
|
|
}
|
|
|
|
$$ = $1;
|
|
|
|
}
|
2012-06-11 19:18:35 +02:00
|
|
|
|
2020-06-08 23:49:36 +02:00
|
|
|
/* "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_assignment *assignment;
|
|
|
|
unsigned int i, writemask_offset = 0;
|
|
|
|
static unsigned int counter;
|
|
|
|
struct hlsl_ir_load *load;
|
|
|
|
struct hlsl_ir_var *var;
|
|
|
|
char name[23];
|
2012-06-11 19:18:35 +02:00
|
|
|
|
2020-06-08 23:49:36 +02:00
|
|
|
if ($1)
|
|
|
|
{
|
|
|
|
hlsl_report_message(get_location(&@1), HLSL_LEVEL_ERROR,
|
|
|
|
"unexpected modifier on a constructor\n");
|
|
|
|
YYABORT;
|
|
|
|
}
|
|
|
|
if ($2->type > HLSL_CLASS_LAST_NUMERIC)
|
|
|
|
{
|
|
|
|
hlsl_report_message(get_location(&@2), HLSL_LEVEL_ERROR,
|
|
|
|
"constructors may only be used with numeric data types\n");
|
|
|
|
YYABORT;
|
|
|
|
}
|
|
|
|
if ($2->dimx * $2->dimy != initializer_size(&$4))
|
|
|
|
{
|
|
|
|
hlsl_report_message(get_location(&@4), HLSL_LEVEL_ERROR,
|
|
|
|
"expected %u components in constructor, but got %u\n",
|
|
|
|
$2->dimx * $2->dimy, initializer_size(&$4));
|
|
|
|
YYABORT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($2->type == HLSL_CLASS_MATRIX)
|
|
|
|
FIXME("Matrix constructors are not supported yet.\n");
|
|
|
|
|
|
|
|
sprintf(name, "<constructor-%x>", counter++);
|
|
|
|
if (!(var = new_synthetic_var(name, $2, get_location(&@2))))
|
|
|
|
YYABORT;
|
|
|
|
for (i = 0; i < $4.args_count; ++i)
|
|
|
|
{
|
|
|
|
struct hlsl_ir_node *arg = $4.args[i];
|
|
|
|
unsigned int width;
|
|
|
|
|
|
|
|
if (arg->data_type->type == HLSL_CLASS_OBJECT)
|
|
|
|
{
|
|
|
|
hlsl_report_message(arg->loc, HLSL_LEVEL_ERROR,
|
|
|
|
"invalid constructor argument");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
width = components_count_type(arg->data_type);
|
|
|
|
|
|
|
|
if (width > 4)
|
|
|
|
{
|
|
|
|
FIXME("Constructor argument with %u components.\n", width);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-06-22 22:53:01 +02:00
|
|
|
if (!(arg = add_implicit_conversion($4.instrs, arg,
|
2020-06-08 23:49:36 +02:00
|
|
|
hlsl_ctx.builtin_types.vector[$2->base_type][width - 1], &arg->loc)))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!(assignment = new_assignment(var, NULL, arg,
|
|
|
|
((1 << width) - 1) << writemask_offset, arg->loc)))
|
|
|
|
YYABORT;
|
|
|
|
writemask_offset += width;
|
|
|
|
list_add_tail($4.instrs, &assignment->node.entry);
|
|
|
|
}
|
|
|
|
d3dcompiler_free($4.args);
|
|
|
|
if (!(load = new_var_load(var, get_location(&@2))))
|
|
|
|
YYABORT;
|
|
|
|
$$ = append_unop($4.instrs, &load->node);
|
|
|
|
}
|
2012-06-07 00:19:04 +02:00
|
|
|
|
|
|
|
unary_expr: postfix_expr
|
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
}
|
2012-07-20 16:37:38 +02:00
|
|
|
| OP_INC unary_expr
|
|
|
|
{
|
|
|
|
struct source_location loc;
|
|
|
|
|
2020-03-04 03:29:46 +01:00
|
|
|
loc = get_location(&@1);
|
2020-02-13 04:57:18 +01:00
|
|
|
if (node_from_list($2)->data_type->modifiers & HLSL_MODIFIER_CONST)
|
2012-09-17 15:32:05 +02:00
|
|
|
{
|
2020-03-04 03:29:47 +01:00
|
|
|
hlsl_report_message(loc, HLSL_LEVEL_ERROR, "modifying a const expression");
|
2019-08-12 17:27:27 +02:00
|
|
|
YYABORT;
|
2012-09-17 15:32:05 +02:00
|
|
|
}
|
2020-02-13 04:57:18 +01:00
|
|
|
$$ = append_unop($2, new_unary_expr(HLSL_IR_UNOP_PREINC, node_from_list($2), loc));
|
2012-07-20 16:37:38 +02:00
|
|
|
}
|
|
|
|
| OP_DEC unary_expr
|
|
|
|
{
|
|
|
|
struct source_location loc;
|
|
|
|
|
2020-03-04 03:29:46 +01:00
|
|
|
loc = get_location(&@1);
|
2020-02-13 04:57:18 +01:00
|
|
|
if (node_from_list($2)->data_type->modifiers & HLSL_MODIFIER_CONST)
|
2012-09-17 15:32:05 +02:00
|
|
|
{
|
2020-03-04 03:29:47 +01:00
|
|
|
hlsl_report_message(loc, HLSL_LEVEL_ERROR, "modifying a const expression");
|
2019-08-12 17:27:27 +02:00
|
|
|
YYABORT;
|
2012-09-17 15:32:05 +02:00
|
|
|
}
|
2020-02-13 04:57:18 +01:00
|
|
|
$$ = append_unop($2, new_unary_expr(HLSL_IR_UNOP_PREDEC, node_from_list($2), loc));
|
2012-07-20 16:37:38 +02:00
|
|
|
}
|
|
|
|
| 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};
|
|
|
|
|
|
|
|
if ($1 == UNARY_OP_PLUS)
|
|
|
|
{
|
|
|
|
$$ = $2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-03-04 03:29:46 +01:00
|
|
|
$$ = append_unop($2, new_unary_expr(ops[$1], node_from_list($2), get_location(&@1)));
|
2012-07-20 16:37:38 +02:00
|
|
|
}
|
|
|
|
}
|
2012-09-19 19:46:15 +02:00
|
|
|
/* var_modifiers just to avoid shift/reduce conflicts */
|
|
|
|
| '(' var_modifiers type array ')' unary_expr
|
|
|
|
{
|
2020-02-13 04:57:18 +01:00
|
|
|
struct hlsl_type *src_type = node_from_list($6)->data_type;
|
2012-09-19 19:46:15 +02:00
|
|
|
struct hlsl_type *dst_type;
|
|
|
|
struct source_location loc;
|
|
|
|
|
2020-03-04 03:29:46 +01:00
|
|
|
loc = get_location(&@3);
|
2012-09-19 19:46:15 +02:00
|
|
|
if ($2)
|
|
|
|
{
|
2020-03-04 03:29:47 +01:00
|
|
|
hlsl_report_message(loc, HLSL_LEVEL_ERROR, "unexpected modifier in a cast");
|
2019-08-12 17:27:27 +02:00
|
|
|
YYABORT;
|
2012-09-19 19:46:15 +02:00
|
|
|
}
|
|
|
|
|
2012-09-21 16:25:55 +02:00
|
|
|
if ($4)
|
|
|
|
dst_type = new_array_type($3, $4);
|
|
|
|
else
|
|
|
|
dst_type = $3;
|
2012-09-19 19:46:15 +02:00
|
|
|
|
|
|
|
if (!compatible_data_types(src_type, dst_type))
|
|
|
|
{
|
2020-03-04 03:29:47 +01:00
|
|
|
hlsl_report_message(loc, HLSL_LEVEL_ERROR, "can't cast from %s to %s",
|
2012-09-19 19:46:15 +02:00
|
|
|
debug_hlsl_type(src_type), debug_hlsl_type(dst_type));
|
2019-08-12 17:27:27 +02:00
|
|
|
YYABORT;
|
2012-09-19 19:46:15 +02:00
|
|
|
}
|
|
|
|
|
2020-02-13 04:57:18 +01:00
|
|
|
$$ = append_unop($6, &new_cast(node_from_list($6), dst_type, &loc)->node);
|
2012-09-19 19:46:15 +02:00
|
|
|
}
|
2012-07-20 16:37:38 +02:00
|
|
|
|
|
|
|
unary_op: '+'
|
|
|
|
{
|
|
|
|
$$ = UNARY_OP_PLUS;
|
|
|
|
}
|
|
|
|
| '-'
|
|
|
|
{
|
|
|
|
$$ = UNARY_OP_MINUS;
|
|
|
|
}
|
|
|
|
| '!'
|
|
|
|
{
|
|
|
|
$$ = UNARY_OP_LOGICNOT;
|
|
|
|
}
|
|
|
|
| '~'
|
|
|
|
{
|
|
|
|
$$ = UNARY_OP_BITNOT;
|
|
|
|
}
|
2012-06-07 00:19:04 +02:00
|
|
|
|
2020-06-23 00:47:18 +02:00
|
|
|
mul_expr:
|
2012-06-07 00:19:04 +02:00
|
|
|
|
2020-06-23 00:47:18 +02:00
|
|
|
unary_expr
|
|
|
|
| mul_expr '*' unary_expr
|
|
|
|
{
|
|
|
|
$$ = add_binary_expr($1, $3, HLSL_IR_BINOP_MUL, get_location(&@2));
|
|
|
|
}
|
|
|
|
| mul_expr '/' unary_expr
|
|
|
|
{
|
|
|
|
$$ = add_binary_expr($1, $3, HLSL_IR_BINOP_DIV, get_location(&@2));
|
|
|
|
}
|
|
|
|
| mul_expr '%' unary_expr
|
|
|
|
{
|
|
|
|
$$ = add_binary_expr($1, $3, HLSL_IR_BINOP_MOD, get_location(&@2));
|
|
|
|
}
|
|
|
|
|
|
|
|
add_expr:
|
|
|
|
|
|
|
|
mul_expr
|
|
|
|
| add_expr '+' mul_expr
|
|
|
|
{
|
|
|
|
$$ = add_binary_expr($1, $3, HLSL_IR_BINOP_ADD, get_location(&@2));
|
|
|
|
}
|
|
|
|
| add_expr '-' mul_expr
|
|
|
|
{
|
|
|
|
$$ = add_binary_expr($1, $3, HLSL_IR_BINOP_SUB, get_location(&@2));
|
|
|
|
}
|
2012-06-07 00:19:04 +02:00
|
|
|
|
|
|
|
shift_expr: add_expr
|
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
}
|
2012-07-18 16:25:15 +02:00
|
|
|
| shift_expr OP_LEFTSHIFT add_expr
|
|
|
|
{
|
|
|
|
FIXME("Left shift\n");
|
|
|
|
}
|
|
|
|
| shift_expr OP_RIGHTSHIFT add_expr
|
|
|
|
{
|
|
|
|
FIXME("Right shift\n");
|
|
|
|
}
|
2012-06-07 00:19:04 +02:00
|
|
|
|
2020-06-23 00:47:18 +02:00
|
|
|
relational_expr:
|
2012-06-07 00:19:04 +02:00
|
|
|
|
2020-06-23 00:47:18 +02:00
|
|
|
shift_expr
|
|
|
|
| relational_expr '<' shift_expr
|
|
|
|
{
|
|
|
|
$$ = add_binary_expr($1, $3, HLSL_IR_BINOP_LESS, get_location(&@2));
|
|
|
|
}
|
|
|
|
| relational_expr '>' shift_expr
|
|
|
|
{
|
|
|
|
$$ = add_binary_expr($1, $3, HLSL_IR_BINOP_GREATER, get_location(&@2));
|
|
|
|
}
|
|
|
|
| relational_expr OP_LE shift_expr
|
|
|
|
{
|
|
|
|
$$ = add_binary_expr($1, $3, HLSL_IR_BINOP_LEQUAL, get_location(&@2));
|
|
|
|
}
|
|
|
|
| relational_expr OP_GE shift_expr
|
|
|
|
{
|
|
|
|
$$ = add_binary_expr($1, $3, HLSL_IR_BINOP_GEQUAL, get_location(&@2));
|
|
|
|
}
|
|
|
|
|
|
|
|
equality_expr:
|
|
|
|
|
|
|
|
relational_expr
|
|
|
|
| equality_expr OP_EQ relational_expr
|
|
|
|
{
|
|
|
|
$$ = add_binary_expr($1, $3, HLSL_IR_BINOP_EQUAL, get_location(&@2));
|
|
|
|
}
|
|
|
|
| equality_expr OP_NE relational_expr
|
|
|
|
{
|
|
|
|
$$ = add_binary_expr($1, $3, HLSL_IR_BINOP_NEQUAL, get_location(&@2));
|
|
|
|
}
|
2012-06-07 00:19:04 +02:00
|
|
|
|
|
|
|
bitand_expr: equality_expr
|
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
}
|
2012-07-18 16:25:15 +02:00
|
|
|
| bitand_expr '&' equality_expr
|
|
|
|
{
|
|
|
|
FIXME("bitwise AND\n");
|
|
|
|
}
|
2012-06-07 00:19:04 +02:00
|
|
|
|
|
|
|
bitxor_expr: bitand_expr
|
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
}
|
2012-07-18 16:25:15 +02:00
|
|
|
| bitxor_expr '^' bitand_expr
|
|
|
|
{
|
|
|
|
FIXME("bitwise XOR\n");
|
|
|
|
}
|
2012-06-07 00:19:04 +02:00
|
|
|
|
|
|
|
bitor_expr: bitxor_expr
|
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
}
|
2012-07-18 16:25:15 +02:00
|
|
|
| bitor_expr '|' bitxor_expr
|
|
|
|
{
|
|
|
|
FIXME("bitwise OR\n");
|
|
|
|
}
|
2012-06-07 00:19:04 +02:00
|
|
|
|
|
|
|
logicand_expr: bitor_expr
|
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
}
|
2012-07-18 16:25:15 +02:00
|
|
|
| logicand_expr OP_AND bitor_expr
|
|
|
|
{
|
|
|
|
FIXME("logic AND\n");
|
|
|
|
}
|
2012-06-07 00:19:04 +02:00
|
|
|
|
|
|
|
logicor_expr: logicand_expr
|
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
}
|
2012-07-18 16:25:15 +02:00
|
|
|
| logicor_expr OP_OR logicand_expr
|
|
|
|
{
|
|
|
|
FIXME("logic OR\n");
|
|
|
|
}
|
2012-06-07 00:19:04 +02:00
|
|
|
|
|
|
|
conditional_expr: logicor_expr
|
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
}
|
2012-07-18 16:25:15 +02:00
|
|
|
| logicor_expr '?' expr ':' assignment_expr
|
|
|
|
{
|
|
|
|
FIXME("ternary operator\n");
|
|
|
|
}
|
2012-06-07 00:19:04 +02:00
|
|
|
|
2020-06-22 22:52:59 +02:00
|
|
|
assignment_expr:
|
2012-09-17 15:32:05 +02:00
|
|
|
|
2020-06-22 22:52:59 +02:00
|
|
|
conditional_expr
|
|
|
|
| unary_expr assign_op assignment_expr
|
|
|
|
{
|
|
|
|
struct hlsl_ir_node *lhs = node_from_list($1), *rhs = node_from_list($3);
|
|
|
|
|
|
|
|
if (lhs->data_type->modifiers & HLSL_MODIFIER_CONST)
|
|
|
|
{
|
|
|
|
hlsl_report_message(get_location(&@2), HLSL_LEVEL_ERROR, "l-value is const");
|
|
|
|
YYABORT;
|
|
|
|
}
|
|
|
|
list_move_tail($3, $1);
|
|
|
|
d3dcompiler_free($1);
|
|
|
|
if (!add_assignment($3, lhs, $2, rhs))
|
|
|
|
YYABORT;
|
|
|
|
$$ = $3;
|
|
|
|
}
|
2012-07-20 16:37:40 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2012-06-07 00:19:04 +02:00
|
|
|
|
|
|
|
expr: assignment_expr
|
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
}
|
|
|
|
| expr ',' assignment_expr
|
|
|
|
{
|
2020-02-12 05:54:20 +01:00
|
|
|
$$ = $1;
|
|
|
|
list_move_tail($$, $3);
|
|
|
|
d3dcompiler_free($3);
|
2012-06-07 00:19:04 +02:00
|
|
|
}
|
|
|
|
|
2012-05-15 16:12:56 +02:00
|
|
|
%%
|
|
|
|
|
2020-03-04 03:29:46 +01:00
|
|
|
static struct source_location get_location(const struct YYLTYPE *l)
|
2012-07-12 16:01:35 +02:00
|
|
|
{
|
2020-03-04 03:29:46 +01:00
|
|
|
const struct source_location loc =
|
|
|
|
{
|
|
|
|
.file = hlsl_ctx.source_file,
|
|
|
|
.line = l->first_line,
|
|
|
|
.col = l->first_column,
|
|
|
|
};
|
|
|
|
return loc;
|
2012-07-12 16:01:35 +02:00
|
|
|
}
|
|
|
|
|
2012-10-11 19:48:48 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2020-04-01 20:31:18 +02:00
|
|
|
/* Allocate a unique, ordered index to each instruction, which will be used for
|
|
|
|
* computing liveness ranges. */
|
|
|
|
static unsigned int index_instructions(struct list *instrs, unsigned int index)
|
|
|
|
{
|
|
|
|
struct hlsl_ir_node *instr;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY(instr, instrs, struct hlsl_ir_node, entry)
|
|
|
|
{
|
|
|
|
instr->index = index++;
|
|
|
|
|
|
|
|
if (instr->type == HLSL_IR_IF)
|
|
|
|
{
|
|
|
|
struct hlsl_ir_if *iff = if_from_node(instr);
|
2020-07-07 23:09:24 +02:00
|
|
|
index = index_instructions(&iff->then_instrs, index);
|
|
|
|
index = index_instructions(&iff->else_instrs, index);
|
2020-04-01 20:31:18 +02:00
|
|
|
}
|
|
|
|
else if (instr->type == HLSL_IR_LOOP)
|
|
|
|
{
|
2020-07-06 00:45:36 +02:00
|
|
|
index = index_instructions(&loop_from_node(instr)->body, index);
|
2020-04-01 20:31:18 +02:00
|
|
|
loop_from_node(instr)->next_index = index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
2020-03-30 04:53:17 +02:00
|
|
|
/* Compute the earliest and latest liveness for each variable. In the case that
|
|
|
|
* a variable is accessed inside of a loop, we promote its liveness to extend
|
2020-03-30 04:53:18 +02:00
|
|
|
* to at least the range of the entire loop. Note that we don't need to do this
|
|
|
|
* for anonymous nodes, since there's currently no way to use a node which was
|
|
|
|
* calculated in an earlier iteration of the loop. */
|
2020-03-30 04:53:17 +02:00
|
|
|
static void compute_liveness_recurse(struct list *instrs, unsigned int loop_first, unsigned int loop_last)
|
|
|
|
{
|
|
|
|
struct hlsl_ir_node *instr;
|
|
|
|
struct hlsl_ir_var *var;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY(instr, instrs, struct hlsl_ir_node, entry)
|
|
|
|
{
|
|
|
|
switch (instr->type)
|
|
|
|
{
|
|
|
|
case HLSL_IR_ASSIGNMENT:
|
|
|
|
{
|
|
|
|
struct hlsl_ir_assignment *assignment = assignment_from_node(instr);
|
2020-05-22 22:45:29 +02:00
|
|
|
var = assignment->lhs.var;
|
2020-03-30 04:53:17 +02:00
|
|
|
if (!var->first_write)
|
|
|
|
var->first_write = loop_first ? min(instr->index, loop_first) : instr->index;
|
2020-06-30 01:55:35 +02:00
|
|
|
assignment->rhs.node->last_read = instr->index;
|
|
|
|
if (assignment->lhs.offset.node)
|
|
|
|
assignment->lhs.offset.node->last_read = instr->index;
|
2020-03-30 04:53:17 +02:00
|
|
|
break;
|
|
|
|
}
|
2020-03-30 04:53:18 +02:00
|
|
|
case HLSL_IR_EXPR:
|
|
|
|
{
|
|
|
|
struct hlsl_ir_expr *expr = expr_from_node(instr);
|
2020-06-30 01:55:35 +02:00
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(expr->operands) && expr->operands[i].node; ++i)
|
|
|
|
expr->operands[i].node->last_read = instr->index;
|
2020-03-30 04:53:17 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case HLSL_IR_IF:
|
|
|
|
{
|
|
|
|
struct hlsl_ir_if *iff = if_from_node(instr);
|
2020-07-07 23:09:24 +02:00
|
|
|
compute_liveness_recurse(&iff->then_instrs, loop_first, loop_last);
|
|
|
|
compute_liveness_recurse(&iff->else_instrs, loop_first, loop_last);
|
2020-06-30 01:55:35 +02:00
|
|
|
iff->condition.node->last_read = instr->index;
|
2020-03-30 04:53:18 +02:00
|
|
|
break;
|
|
|
|
}
|
2020-05-22 22:45:30 +02:00
|
|
|
case HLSL_IR_LOAD:
|
|
|
|
{
|
|
|
|
struct hlsl_ir_load *load = load_from_node(instr);
|
|
|
|
var = load->src.var;
|
|
|
|
var->last_read = loop_last ? max(instr->index, loop_last) : instr->index;
|
2020-06-30 01:55:35 +02:00
|
|
|
if (load->src.offset.node)
|
|
|
|
load->src.offset.node->last_read = instr->index;
|
2020-05-22 22:45:30 +02:00
|
|
|
break;
|
|
|
|
}
|
2020-03-30 04:53:17 +02:00
|
|
|
case HLSL_IR_LOOP:
|
|
|
|
{
|
|
|
|
struct hlsl_ir_loop *loop = loop_from_node(instr);
|
2020-07-06 00:45:36 +02:00
|
|
|
compute_liveness_recurse(&loop->body, loop_first ? loop_first : instr->index,
|
2020-03-30 04:53:17 +02:00
|
|
|
loop_last ? loop_last : loop->next_index);
|
|
|
|
break;
|
|
|
|
}
|
2020-03-30 04:53:18 +02:00
|
|
|
case HLSL_IR_SWIZZLE:
|
|
|
|
{
|
|
|
|
struct hlsl_ir_swizzle *swizzle = swizzle_from_node(instr);
|
2020-06-30 01:55:35 +02:00
|
|
|
swizzle->val.node->last_read = instr->index;
|
2020-03-30 04:53:18 +02:00
|
|
|
break;
|
|
|
|
}
|
2020-06-02 00:58:46 +02:00
|
|
|
case HLSL_IR_CONSTANT:
|
|
|
|
case HLSL_IR_JUMP:
|
2020-03-30 04:53:17 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void compute_liveness(struct hlsl_ir_function_decl *entry_func)
|
|
|
|
{
|
|
|
|
struct hlsl_ir_var *var;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY(var, &hlsl_ctx.globals->vars, struct hlsl_ir_var, scope_entry)
|
|
|
|
{
|
|
|
|
var->first_write = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY(var, entry_func->parameters, struct hlsl_ir_var, param_entry)
|
|
|
|
{
|
|
|
|
if (var->modifiers & HLSL_STORAGE_IN)
|
|
|
|
var->first_write = 1;
|
|
|
|
if (var->modifiers & HLSL_STORAGE_OUT)
|
|
|
|
var->last_read = UINT_MAX;
|
|
|
|
}
|
|
|
|
|
2020-06-02 00:58:46 +02:00
|
|
|
if (entry_func->return_var)
|
|
|
|
entry_func->return_var->last_read = UINT_MAX;
|
|
|
|
|
2020-03-30 04:53:17 +02:00
|
|
|
compute_liveness_recurse(entry_func->body, 0, 0);
|
|
|
|
}
|
|
|
|
|
2020-06-08 23:49:39 +02:00
|
|
|
HRESULT parse_hlsl(enum shader_type type, DWORD major, DWORD minor,
|
|
|
|
const char *entrypoint, ID3D10Blob **shader_blob, char **messages)
|
2012-05-15 16:12:56 +02:00
|
|
|
{
|
2020-04-01 20:31:18 +02:00
|
|
|
struct hlsl_ir_function_decl *entry_func;
|
2012-06-04 17:58:24 +02:00
|
|
|
struct hlsl_scope *scope, *next_scope;
|
|
|
|
struct hlsl_type *hlsl_type, *next_type;
|
|
|
|
struct hlsl_ir_var *var, *next_var;
|
2020-06-08 23:49:39 +02:00
|
|
|
HRESULT hr = E_FAIL;
|
2012-07-12 16:01:33 +02:00
|
|
|
unsigned int i;
|
2012-06-04 17:58:24 +02:00
|
|
|
|
2012-07-10 15:39:45 +02:00
|
|
|
hlsl_ctx.status = PARSE_SUCCESS;
|
|
|
|
hlsl_ctx.messages.size = hlsl_ctx.messages.capacity = 0;
|
2012-07-12 16:01:33 +02:00
|
|
|
hlsl_ctx.line_no = hlsl_ctx.column = 1;
|
2012-05-15 16:12:57 +02:00
|
|
|
hlsl_ctx.source_file = d3dcompiler_strdup("");
|
2012-07-12 16:01:33 +02:00
|
|
|
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;
|
2012-06-04 17:58:24 +02:00
|
|
|
hlsl_ctx.cur_scope = NULL;
|
2012-05-15 16:12:56 +02:00
|
|
|
hlsl_ctx.matrix_majority = HLSL_COLUMN_MAJOR;
|
2012-06-04 17:58:24 +02:00
|
|
|
list_init(&hlsl_ctx.scopes);
|
|
|
|
list_init(&hlsl_ctx.types);
|
2012-10-11 19:48:48 +02:00
|
|
|
init_functions_tree(&hlsl_ctx.functions);
|
2020-06-18 17:46:20 +02:00
|
|
|
list_init(&hlsl_ctx.static_initializers);
|
2012-06-04 17:58:24 +02:00
|
|
|
|
|
|
|
push_scope(&hlsl_ctx);
|
|
|
|
hlsl_ctx.globals = hlsl_ctx.cur_scope;
|
2012-09-18 18:18:05 +02:00
|
|
|
declare_predefined_types(hlsl_ctx.globals);
|
2012-05-15 16:12:56 +02:00
|
|
|
|
|
|
|
hlsl_parse();
|
|
|
|
|
2020-04-01 20:31:18 +02:00
|
|
|
if (hlsl_ctx.status == PARSE_ERR)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (!(entry_func = get_func_entry(entrypoint)))
|
|
|
|
{
|
|
|
|
hlsl_message("error: entry point %s is not defined\n", debugstr_a(entrypoint));
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2020-06-08 23:49:38 +02:00
|
|
|
if (!type_is_void(entry_func->return_type)
|
|
|
|
&& entry_func->return_type->type != HLSL_CLASS_STRUCT && !entry_func->semantic)
|
|
|
|
{
|
|
|
|
hlsl_report_message(entry_func->loc, HLSL_LEVEL_ERROR,
|
|
|
|
"entry point \"%s\" is missing a return value semantic", entry_func->func->name);
|
|
|
|
}
|
|
|
|
|
2020-06-18 17:46:20 +02:00
|
|
|
list_move_head(entry_func->body, &hlsl_ctx.static_initializers);
|
|
|
|
|
2020-03-30 04:53:17 +02:00
|
|
|
/* Index 0 means unused; index 1 means function entry, so start at 2. */
|
|
|
|
index_instructions(entry_func->body, 2);
|
2020-04-01 20:31:18 +02:00
|
|
|
|
|
|
|
if (TRACE_ON(hlsl_parser))
|
|
|
|
{
|
|
|
|
TRACE("IR dump.\n");
|
|
|
|
wine_rb_for_each_entry(&hlsl_ctx.functions, dump_function, NULL);
|
|
|
|
}
|
|
|
|
|
2020-03-30 04:53:17 +02:00
|
|
|
compute_liveness(entry_func);
|
|
|
|
|
2020-06-08 23:49:39 +02:00
|
|
|
if (hlsl_ctx.status != PARSE_ERR)
|
|
|
|
hr = E_NOTIMPL;
|
|
|
|
|
2020-04-01 20:31:18 +02:00
|
|
|
out:
|
2020-06-08 23:49:38 +02:00
|
|
|
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);
|
|
|
|
|
2012-06-11 19:18:33 +02:00
|
|
|
TRACE("Freeing functions IR.\n");
|
2012-10-11 19:48:48 +02:00
|
|
|
wine_rb_destroy(&hlsl_ctx.functions, free_function_rb, NULL);
|
2012-05-15 16:12:57 +02:00
|
|
|
|
2012-06-04 17:58:24 +02:00
|
|
|
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);
|
|
|
|
}
|
2012-09-19 19:46:12 +02:00
|
|
|
wine_rb_destroy(&scope->types, NULL, NULL);
|
2012-06-04 17:58:24 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2020-06-08 23:49:39 +02:00
|
|
|
return hr;
|
2012-05-15 16:12:56 +02:00
|
|
|
}
|