diff options
author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2018-06-24 12:29:53 +0200 |
---|---|---|
committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-10-20 22:35:05 +0200 |
commit | 2bd6dd27dd4dfc5f022de38ef52fdca6b6e92269 (patch) | |
tree | 9a95effea63944e12273de22773fbc0677bdc6f1 | |
parent | e54859fe6da330ed34b8be3f93f36b741d0127d2 (diff) | |
download | sparse-2bd6dd27dd4dfc5f022de38ef52fdca6b6e92269.tar.gz |
extract eval_op() from eval_insn()
eval_insn() can be handy when there is an existing instruction
to evaluate but it can happen that there isn't one, only pseudos.
Allow to reuse the evaluation code by using a new API: eval_op()
extracted from eval_insn() and taking all its input as arguments
(opcode, size, src1 & src2).
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r-- | simplify.c | 14 |
1 files changed, 9 insertions, 5 deletions
@@ -516,12 +516,11 @@ static unsigned int operand_size(struct instruction *insn, pseudo_t pseudo) return size; } -static pseudo_t eval_insn(struct instruction *insn) +static pseudo_t eval_op(int op, unsigned size, pseudo_t src1, pseudo_t src2) { /* FIXME! Verify signs and sizes!! */ - unsigned int size = insn->size; - long long left = insn->src1->value; - long long right = insn->src2->value; + long long left = src1->value; + long long right = src2->value; unsigned long long ul, ur; long long res, mask, bits; @@ -535,7 +534,7 @@ static pseudo_t eval_insn(struct instruction *insn) ul = left & bits; ur = right & bits; - switch (insn->opcode) { + switch (op) { case OP_ADD: res = left + right; break; @@ -754,6 +753,11 @@ static int simplify_mask_shift(struct instruction *sh, unsigned long long mask) return 0; } +static pseudo_t eval_insn(struct instruction *insn) +{ + return eval_op(insn->opcode, insn->size, insn->src1, insn->src2); +} + static long long check_shift_count(struct instruction *insn, unsigned long long uval) { unsigned int size = insn->size; |