X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=ast.c;h=dbd23f14db04889f3e17a0b977db503aac5904dc;hb=0695ad1659bc1f86487b4fe609823620bf798dce;hp=5ea6d93b2f51a34f06bfe42fc25627f39f4111e4;hpb=2cf5046d3807551365180a73c923762182f7bc83;p=xonotic%2Fgmqcc.git diff --git a/ast.c b/ast.c index 5ea6d93..dbd23f1 100644 --- a/ast.c +++ b/ast.c @@ -450,11 +450,7 @@ ast_binary* ast_binary_new(lex_ctx_t ctx, int op, ast_propagate_effects(self, left); ast_propagate_effects(self, right); - /* - * Try to fold away superfluous binary operations, such as: - * A * 1, a + 0, etc. - */ - if ((fold = (ast_binary*)fold_superfluous(left, right, op))) { + if (OPTS_OPTIMIZATION(OPTIM_PEEPHOLE) && (fold = (ast_binary*)fold_superfluous(left, right, op))) { ast_binary_delete(self); return fold; } @@ -467,10 +463,12 @@ ast_binary* ast_binary_new(lex_ctx_t ctx, int op, else self->expression.vtype = TYPE_FLOAT; } - else if (op == INSTR_BITAND || op == INSTR_BITOR || op == INSTR_MUL_F) + else if (op == INSTR_BITAND || op == INSTR_BITOR) self->expression.vtype = TYPE_FLOAT; - else if (op >= INSTR_MUL_V && op <= INSTR_MUL_VF) + else if (op == INSTR_MUL_VF || op == INSTR_MUL_FV) self->expression.vtype = TYPE_VECTOR; + else if (op == INSTR_MUL_V) + self->expression.vtype = TYPE_FLOAT; else self->expression.vtype = left->vtype; @@ -531,10 +529,8 @@ ast_unary* ast_unary_new(lex_ctx_t ctx, int op, ast_unary *prev = (ast_unary*)((ast_unary*)expr)->operand; /* Handle for double negation */ - if ((((ast_unary*)expr)->op == VINSTR_NEG_V && op == VINSTR_NEG_V) || - (((ast_unary*)expr)->op == VINSTR_NEG_F && op == VINSTR_NEG_F)) { + if (((ast_unary*)expr)->op == op) prev = (ast_unary*)((ast_unary*)expr)->operand; - } if (ast_istype(prev, ast_unary)) { ast_expression_delete((ast_expression*)self); @@ -1187,6 +1183,7 @@ ast_function* ast_function_new(lex_ctx_t ctx, const char *name, ast_value *vtype if (!vtype) { compile_error(ast_ctx(self), "internal error: ast_function_new condition 0"); goto cleanup; + } else if (vtype->hasvalue || vtype->expression.vtype != TYPE_FUNCTION) { } else if (vtype->hasvalue || vtype->expression.vtype != TYPE_FUNCTION) { compile_error(ast_ctx(self), "internal error: ast_function_new condition %i %i type=%i (probably 2 bodies?)", (int)!vtype, @@ -1796,6 +1793,7 @@ bool ast_function_codegen(ast_function *self, ir_builder *ir) ir_value *dummy; ast_expression *ec; ast_expression_codegen *cgen; + size_t i; (void)ir;