aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-09-28 01:08:33 +0200
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-10-20 22:35:08 +0200
commit97e6515a7944b2ed9ec5be4614066632682559d7 (patch)
tree88d319e5e69d6a94cc0bfb81793da7c7b820c690
parent2bd6dd27dd4dfc5f022de38ef52fdca6b6e92269 (diff)
downloadsparse-97e6515a7944b2ed9ec5be4614066632682559d7.tar.gz
unop: add helper eval_unop()
Currently, eval_op() only do the evaluation of binops but unops need sometimes to be evaluated too. So, teach eval_op() about OP_NEG & OP_NOT and add a new helper, eval_unop() for making it easier to use with unops. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r--simplify.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/simplify.c b/simplify.c
index ac27debf..4c6569eb 100644
--- a/simplify.c
+++ b/simplify.c
@@ -535,6 +535,13 @@ static pseudo_t eval_op(int op, unsigned size, pseudo_t src1, pseudo_t src2)
ur = right & bits;
switch (op) {
+ case OP_NEG:
+ res = -left;
+ break;
+ case OP_NOT:
+ res = ~ul;
+ break;
+
case OP_ADD:
res = left + right;
break;
@@ -636,6 +643,11 @@ undef:
return NULL;
}
+static inline pseudo_t eval_unop(int op, unsigned size, pseudo_t src)
+{
+ return eval_op(op, size, src, VOID);
+}
+
///
// Simplifications
// ^^^^^^^^^^^^^^^