diff mbox

[1/2] add_uniop() should take a type, not an expression

Message ID 20180622210651.23555-2-luc.vanoostenryck@gmail.com (mailing list archive)
State Mainlined, archived
Headers show

Commit Message

Luc Van Oostenryck June 22, 2018, 9:06 p.m. UTC
The function add_uniop() needs the instruction's type but this
type was given indirectly via an expression. As consequence this
function cannot be used standalone.

Change the function to take the type as argument so that it can
also be used when no expression is available.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 linearize.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
diff mbox

Patch

diff --git a/linearize.c b/linearize.c
index 6284d079b..ce6b91b74 100644
--- a/linearize.c
+++ b/linearize.c
@@ -1086,9 +1086,9 @@  static pseudo_t linearize_inc_dec(struct entrypoint *ep, struct expression *expr
 	return postop ? old : new;
 }
 
-static pseudo_t add_uniop(struct entrypoint *ep, struct expression *expr, int op, pseudo_t src)
+static pseudo_t add_uniop(struct entrypoint *ep, struct symbol *ctype, int op, pseudo_t src)
 {
-	struct instruction *insn = alloc_typed_instruction(op, expr->ctype);
+	struct instruction *insn = alloc_typed_instruction(op, ctype);
 	pseudo_t new = alloc_pseudo(insn);
 
 	insn->target = new;
@@ -1114,17 +1114,18 @@  static pseudo_t linearize_slice(struct entrypoint *ep, struct expression *expr)
 static pseudo_t linearize_regular_preop(struct entrypoint *ep, struct expression *expr)
 {
 	pseudo_t pre = linearize_expression(ep, expr->unop);
+	struct symbol *ctype = expr->ctype;
 	switch (expr->op) {
 	case '+':
 		return pre;
 	case '!': {
 		pseudo_t zero = value_pseudo(0);
-		return add_binary_op(ep, expr->ctype, OP_SET_EQ, pre, zero);
+		return add_binary_op(ep, ctype, OP_SET_EQ, pre, zero);
 	}
 	case '~':
-		return add_uniop(ep, expr, OP_NOT, pre);
+		return add_uniop(ep, ctype, OP_NOT, pre);
 	case '-':
-		return add_uniop(ep, expr, opcode_float(OP_NEG, expr->ctype), pre);
+		return add_uniop(ep, ctype, opcode_float(OP_NEG, ctype), pre);
 	}
 	return VOID;
 }