[PATCH 2/5] d3dcompiler: Synthesize a variable when indexing a non-deref node.
Matteo Bruni
matteo.mystral at gmail.com
Tue May 19 14:31:56 CDT 2020
On Mon, May 4, 2020 at 10:04 PM Zebediah Figura <z.figura12 at gmail.com> wrote:
>
> Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
> ---
> dlls/d3dcompiler_43/hlsl.y | 122 +++++++++++++++++++++----------------
> 1 file changed, 70 insertions(+), 52 deletions(-)
>
> diff --git a/dlls/d3dcompiler_43/hlsl.y b/dlls/d3dcompiler_43/hlsl.y
> index 01b210419c8..5875705cf18 100644
> --- a/dlls/d3dcompiler_43/hlsl.y
> +++ b/dlls/d3dcompiler_43/hlsl.y
> @@ -562,32 +562,39 @@ static struct hlsl_ir_deref *new_var_deref(struct hlsl_ir_var *var, const struct
> return deref;
> }
>
> -static struct hlsl_ir_deref *new_record_deref(struct hlsl_ir_node *record,
> - struct hlsl_struct_field *field, const struct source_location loc)
> +static struct hlsl_ir_node *get_var_deref(struct hlsl_ir_node *node)
> {
> + struct hlsl_ir_assignment *assign;
> struct hlsl_ir_deref *deref;
> + struct hlsl_ir_var *var;
> + char name[27];
>
> - if (record->type != HLSL_IR_DEREF)
> - {
> - struct hlsl_ir_assignment *assign;
> - struct hlsl_ir_var *var;
> - char name[27];
> + if (node->type == HLSL_IR_DEREF)
> + return node;
>
> - sprintf(name, "<deref-%p>", record);
> - if (!(var = new_synthetic_var(name, record->data_type, record->loc)))
> - return NULL;
> + sprintf(name, "<deref-%p>", node);
> + if (!(var = new_synthetic_var(name, node->data_type, node->loc)))
> + return NULL;
>
> - TRACE("Synthesized variable %p for %s node.\n", var, debug_node_type(record->type));
> + TRACE("Synthesized variable %p for %s node.\n", var, debug_node_type(node->type));
>
> - if (!(assign = make_simple_assignment(var, record)))
> - return NULL;
> - list_add_after(&record->entry, &assign->node.entry);
> + if (!(assign = make_simple_assignment(var, node)))
> + return NULL;
> + list_add_after(&node->entry, &assign->node.entry);
>
> - if (!(deref = new_var_deref(var, var->loc)))
> - return NULL;
> - list_add_after(&assign->node.entry, &deref->node.entry);
> - record = &deref->node;
> - }
> + if (!(deref = new_var_deref(var, var->loc)))
> + return NULL;
> + list_add_after(&assign->node.entry, &deref->node.entry);
> + return &deref->node;
> +}
> +
> +static struct hlsl_ir_deref *new_record_deref(struct hlsl_ir_node *record,
> + struct hlsl_struct_field *field, const struct source_location loc)
> +{
> + struct hlsl_ir_deref *deref;
> +
> + if (!(record = get_var_deref(record)))
> + return NULL;
>
> if (!(deref = d3dcompiler_alloc(sizeof(*deref))))
> return NULL;
> @@ -599,6 +606,49 @@ static struct hlsl_ir_deref *new_record_deref(struct hlsl_ir_node *record,
> return deref;
> }
>
> +static struct hlsl_ir_deref *new_array_deref(struct hlsl_ir_node *array,
> + struct hlsl_ir_node *index, const struct source_location loc)
> +{
> + const struct hlsl_type *expr_type = array->data_type;
> + struct hlsl_ir_deref *deref;
> + struct hlsl_type *data_type;
> +
> + TRACE("Array dereference from type %s.\n", debug_hlsl_type(expr_type));
> +
> + if (expr_type->type == HLSL_CLASS_ARRAY)
> + {
> + data_type = expr_type->e.array.type;
> + }
> + else if (expr_type->type == HLSL_CLASS_MATRIX)
> + {
> + data_type = new_hlsl_type(NULL, HLSL_CLASS_VECTOR, expr_type->base_type, expr_type->dimx, 1);
> + }
> + else if (expr_type->type == HLSL_CLASS_VECTOR)
> + {
> + data_type = new_hlsl_type(NULL, HLSL_CLASS_SCALAR, expr_type->base_type, 1, 1);
> + }
> + else
> + {
> + if (expr_type->type == HLSL_CLASS_SCALAR)
> + hlsl_report_message(loc, HLSL_LEVEL_ERROR, "array-indexed expression is scalar");
> + else
> + hlsl_report_message(loc, HLSL_LEVEL_ERROR, "expression is not array-indexable");
> + return NULL;
> + }
> +
> + if (!(array = get_var_deref(array)))
> + return NULL;
> +
> + if (!(deref = d3dcompiler_alloc(sizeof(*deref))))
> + return NULL;
> +
> + init_node(&deref->node, HLSL_IR_DEREF, data_type, loc);
> + deref->src.type = HLSL_IR_DEREF_ARRAY;
> + deref->src.v.array.array = array;
> + deref->src.v.array.index = index;
> + return deref;
> +}
It should be possible to have a sensible test for this one instead.
Care to write one?
More information about the wine-devel
mailing list