ast_binary* ast_binary_new(lex_ctx_t ctx, int op,
ast_expression* left, ast_expression* right)
{
+ ast_binary *fold;
ast_instantiate(ast_binary, ctx, ast_binary_delete);
ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_binary_codegen);
ast_propagate_effects(self, left);
ast_propagate_effects(self, right);
+ if (OPTS_OPTIMIZATION(OPTIM_PEEPHOLE) && (fold = (ast_binary*)fold_superfluous(left, right, op))) {
+ ast_binary_delete(self);
+ return fold;
+ }
+
if (op >= INSTR_EQ_F && op <= INSTR_GT)
self->expression.vtype = TYPE_FLOAT;
else if (op == INSTR_AND || op == INSTR_OR) {
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);
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,
ir_value *dummy;
ast_expression *ec;
ast_expression_codegen *cgen;
+
size_t i;
(void)ir;