From 2c975fe48feaa8a78792510e5ef09c6f4cd9f655 Mon Sep 17 00:00:00 2001 From: Dale Weiler Date: Tue, 30 Jul 2013 17:27:54 +0000 Subject: [PATCH] I'm in a state of confusion as to why constant folding was never done on comparisions, now it is ;) --- parser.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/parser.c b/parser.c index 00e7299..9f53b42 100644 --- a/parser.c +++ b/parser.c @@ -1326,7 +1326,9 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy) type_name[exprs[1]->vtype]); return false; } - out = (ast_expression*)ast_binary_new(ctx, type_ne_instr[exprs[0]->vtype], exprs[0], exprs[1]); + out = CanConstFold(exprs[0], exprs[1]) + ? (ast_expression*)parser_const_float(parser, ConstF(0) != ConstF(1)) + : (ast_expression*)ast_binary_new(ctx, type_ne_instr[exprs[0]->vtype], exprs[0], exprs[1]); break; case opid2('=', '='): if (exprs[0]->vtype != exprs[1]->vtype) { @@ -1335,7 +1337,9 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy) type_name[exprs[1]->vtype]); return false; } - out = (ast_expression*)ast_binary_new(ctx, type_eq_instr[exprs[0]->vtype], exprs[0], exprs[1]); + out = CanConstFold(exprs[0], exprs[1]) + ? (ast_expression*)parser_const_float(parser, ConstF(0) == ConstF(1)) + : (ast_expression*)ast_binary_new(ctx, type_eq_instr[exprs[0]->vtype], exprs[0], exprs[1]); break; case opid1('='):