Commit 27880abb authored by Matteo Bruni's avatar Matteo Bruni Committed by Alexandre Julliard

d3dcompiler: Implement basic expressions parsing.

parent 604a91eb
......@@ -703,6 +703,7 @@ enum hlsl_ir_node_type
HLSL_IR_CONSTANT,
HLSL_IR_CONSTRUCTOR,
HLSL_IR_DEREF,
HLSL_IR_EXPR,
HLSL_IR_FUNCTION_DECL,
};
......@@ -749,6 +750,81 @@ struct hlsl_ir_function_decl
struct list *body;
};
enum hlsl_ir_expr_op {
HLSL_IR_UNOP_BIT_NOT = 0,
HLSL_IR_UNOP_LOGIC_NOT,
HLSL_IR_UNOP_NEG,
HLSL_IR_UNOP_ABS,
HLSL_IR_UNOP_SIGN,
HLSL_IR_UNOP_RCP,
HLSL_IR_UNOP_RSQ,
HLSL_IR_UNOP_SQRT,
HLSL_IR_UNOP_NRM,
HLSL_IR_UNOP_EXP2,
HLSL_IR_UNOP_LOG2,
HLSL_IR_UNOP_CAST,
HLSL_IR_UNOP_FRACT,
HLSL_IR_UNOP_SIN,
HLSL_IR_UNOP_COS,
HLSL_IR_UNOP_SIN_REDUCED, /* Reduced range [-pi, pi] */
HLSL_IR_UNOP_COS_REDUCED, /* Reduced range [-pi, pi] */
HLSL_IR_UNOP_DSX,
HLSL_IR_UNOP_DSY,
HLSL_IR_UNOP_SAT,
HLSL_IR_BINOP_ADD,
HLSL_IR_BINOP_SUB,
HLSL_IR_BINOP_MUL,
HLSL_IR_BINOP_DIV,
HLSL_IR_BINOP_MOD,
HLSL_IR_BINOP_LESS,
HLSL_IR_BINOP_GREATER,
HLSL_IR_BINOP_LEQUAL,
HLSL_IR_BINOP_GEQUAL,
HLSL_IR_BINOP_EQUAL,
HLSL_IR_BINOP_NEQUAL,
HLSL_IR_BINOP_LOGIC_AND,
HLSL_IR_BINOP_LOGIC_OR,
HLSL_IR_BINOP_LSHIFT,
HLSL_IR_BINOP_RSHIFT,
HLSL_IR_BINOP_BIT_AND,
HLSL_IR_BINOP_BIT_OR,
HLSL_IR_BINOP_BIT_XOR,
HLSL_IR_BINOP_DOT,
HLSL_IR_BINOP_CRS,
HLSL_IR_BINOP_MIN,
HLSL_IR_BINOP_MAX,
HLSL_IR_BINOP_POW,
HLSL_IR_BINOP_PREINC,
HLSL_IR_BINOP_PREDEC,
HLSL_IR_BINOP_POSTINC,
HLSL_IR_BINOP_POSTDEC,
HLSL_IR_TEROP_LERP,
HLSL_IR_SEQUENCE,
};
struct hlsl_ir_expr
{
struct hlsl_ir_node node;
enum hlsl_ir_expr_op op;
struct hlsl_ir_node *operands[3];
struct list *subexpressions;
};
enum hlsl_ir_deref_type
{
HLSL_IR_DEREF_VAR,
......@@ -861,6 +937,12 @@ void hlsl_message(const char *fmt, ...) PRINTF_ATTR(1,2) DECLSPEC_HIDDEN;
void hlsl_report_message(const char *filename, DWORD line, DWORD column,
enum hlsl_error_level level, const char *fmt, ...) PRINTF_ATTR(5,6) DECLSPEC_HIDDEN;
static inline struct hlsl_ir_expr *expr_from_node(const struct hlsl_ir_node *node)
{
assert(node->type == HLSL_IR_EXPR);
return CONTAINING_RECORD(node, struct hlsl_ir_expr, node);
}
static inline struct hlsl_ir_deref *deref_from_node(const struct hlsl_ir_node *node)
{
assert(node->type == HLSL_IR_DEREF);
......@@ -890,6 +972,12 @@ struct hlsl_type *new_array_type(struct hlsl_type *basic_type, unsigned int arra
struct hlsl_type *get_type(struct hlsl_scope *scope, const char *name, BOOL recursive) DECLSPEC_HIDDEN;
BOOL find_function(const char *name) DECLSPEC_HIDDEN;
unsigned int components_count_type(struct hlsl_type *type) DECLSPEC_HIDDEN;
struct hlsl_ir_expr *new_expr(enum hlsl_ir_expr_op op, struct hlsl_ir_node **operands,
struct source_location *loc) DECLSPEC_HIDDEN;
struct hlsl_ir_expr *hlsl_add(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2,
struct source_location *loc) DECLSPEC_HIDDEN;
struct hlsl_ir_expr *hlsl_sub(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2,
struct source_location *loc) DECLSPEC_HIDDEN;
struct hlsl_ir_deref *new_var_deref(struct hlsl_ir_var *var) DECLSPEC_HIDDEN;
void push_scope(struct hlsl_parse_ctx *ctx) DECLSPEC_HIDDEN;
BOOL pop_scope(struct hlsl_parse_ctx *ctx) DECLSPEC_HIDDEN;
......
......@@ -944,6 +944,20 @@ add_expr: mul_expr
{
$$ = $1;
}
| add_expr '+' mul_expr
{
struct source_location loc;
set_location(&loc, &@2);
$$ = &hlsl_add($1, $3, &loc)->node;
}
| add_expr '-' mul_expr
{
struct source_location loc;
set_location(&loc, &@2);
$$ = &hlsl_sub($1, $3, &loc)->node;
}
shift_expr: add_expr
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment