From: Dale Weiler Date: Sun, 1 Dec 2013 14:57:05 +0000 (-0500) Subject: Merge branch 'cooking' into ast_iterator X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=ea13c171ddda7ae01defb70a269850ffa2a1799d;p=xonotic%2Fgmqcc.git Merge branch 'cooking' into ast_iterator --- ea13c171ddda7ae01defb70a269850ffa2a1799d diff --cc ast.c index 7b7737b,238d00a..f7a4fb3 --- a/ast.c +++ b/ast.c @@@ -467,9 -438,24 +467,24 @@@ bool ast_value_set_name(ast_value *self ast_binary* ast_binary_new(lex_ctx_t ctx, int op, ast_expression* left, ast_expression* right) { - ast_instantiate(ast_binary, ctx, ast_binary_delete); + ast_instantiate(ast_binary, ctx, ast_binary_delete, ast_binary_next_child); ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_binary_codegen); + if (ast_istype(right, ast_unary) && OPTS_OPTIMIZATION(OPTIM_PEEPHOLE)) { + ast_expression *normal = ((ast_unary*)right)->operand; + + /* make a-(-b) => a + b */ + if (op == INSTR_SUB_F) { + op = INSTR_ADD_F; + right = normal; + ++opts_optimizationcount[OPTIM_PEEPHOLE]; + } else if (op == INSTR_SUB_V) { + op = INSTR_ADD_V; + right = normal; + ++opts_optimizationcount[OPTIM_PEEPHOLE]; + } + } + self->op = op; self->left = left; self->right = right;