public static Expr binary(BinaryOperation op, OperationType type, Expr first, Expr second, TextLocation loc) { Expr expr = binary(op, type, first, second); expr.setLocation(loc); return expr; }
private Expr compare(BinaryOperation op, OperationType type, Variable value) { Expr expr = Expr.binary(op, type, Expr.var(value.getIndex()), Expr.constant(0)); expr.setLocation(currentLocation); return expr; }
private void binary(NumericOperandType type, int first, int second, Variable result, BinaryOperation op) { assign(Expr.binary(op, mapOperandType(type), Expr.var(first), Expr.var(second)), result); }
public static Expr invert(Expr expr) { if (expr instanceof UnaryExpr) { UnaryExpr unary = (UnaryExpr) expr; if (unary.getOperation() == UnaryOperation.NOT) { return unary.getOperand(); } } else if (expr instanceof BinaryExpr) { BinaryExpr binary = (BinaryExpr) expr; Expr a = binary.getFirstOperand(); Expr b = binary.getSecondOperand(); switch (binary.getOperation()) { case EQUALS: return Expr.binary(BinaryOperation.NOT_EQUALS, binary.getType(), a, b, expr.getLocation()); case NOT_EQUALS: return Expr.binary(BinaryOperation.EQUALS, binary.getType(), a, b, expr.getLocation()); case LESS: return Expr.binary(BinaryOperation.GREATER_OR_EQUALS, binary.getType(), a, b, expr.getLocation()); case LESS_OR_EQUALS: return Expr.binary(BinaryOperation.GREATER, binary.getType(), a, b, expr.getLocation()); case GREATER: return Expr.binary(BinaryOperation.LESS_OR_EQUALS, binary.getType(), a, b, expr.getLocation()); case GREATER_OR_EQUALS: return Expr.binary(BinaryOperation.LESS, binary.getType(), a, b, expr.getLocation()); default: break; } } return Expr.invert(expr); } }
cond.getConsequent().clear(); cond.getConsequent().addAll(innerCond.getConsequent()); cond.setCondition(Expr.binary(BinaryOperation.AND, null, cond.getCondition(), innerCond.getCondition(), cond.getCondition().getLocation())); --i;
statement.getBody().remove(0); if (statement.getCondition() != null) { Expr newCondition = Expr.binary(BinaryOperation.AND, null, statement.getCondition(), ExprOptimizer.invert(cond.getCondition())); newCondition.setLocation(statement.getCondition().getLocation());
@Override public void visit(BinaryBranchingInstruction insn) { int a = insn.getFirstOperand().getIndex(); int b = insn.getSecondOperand().getIndex(); BasicBlock consequent = insn.getConsequent(); BasicBlock alternative = insn.getAlternative(); switch (insn.getCondition()) { case EQUAL: branch(withLocation(Expr.binary(BinaryOperation.EQUALS, OperationType.INT, Expr.var(a), Expr.var(b))), consequent, alternative); break; case REFERENCE_EQUAL: branch(withLocation(Expr.binary(BinaryOperation.EQUALS, null, Expr.var(a), Expr.var(b))), consequent, alternative); break; case NOT_EQUAL: branch(withLocation(Expr.binary(BinaryOperation.NOT_EQUALS, OperationType.INT, Expr.var(a), Expr.var(b))), consequent, alternative); break; case REFERENCE_NOT_EQUAL: branch(withLocation(Expr.binary(BinaryOperation.NOT_EQUALS, null, Expr.var(a), Expr.var(b))), consequent, alternative); break; } }
break; case NOT_NULL: branch(Expr.binary(BinaryOperation.NOT_EQUALS, null, Expr.var(insn.getOperand().getIndex()), Expr.constant(null)), insn.getConsequent(), insn.getAlternative()); break; case NULL: branch(Expr.binary(BinaryOperation.EQUALS, null, Expr.var(insn.getOperand().getIndex()), Expr.constant(null)), insn.getConsequent(), insn.getAlternative()); break;
public static Expr binary(BinaryOperation op, OperationType type, Expr first, Expr second, TextLocation loc) { Expr expr = binary(op, type, first, second); expr.setLocation(loc); return expr; }
private Expr compare(BinaryOperation op, OperationType type, Variable value) { Expr expr = Expr.binary(op, type, Expr.var(value.getIndex()), Expr.constant(0)); expr.setLocation(currentLocation); return expr; }
public static Expr invert(Expr expr) { if (expr instanceof UnaryExpr) { UnaryExpr unary = (UnaryExpr) expr; if (unary.getOperation() == UnaryOperation.NOT) { return unary.getOperand(); } } else if (expr instanceof BinaryExpr) { BinaryExpr binary = (BinaryExpr) expr; Expr a = binary.getFirstOperand(); Expr b = binary.getSecondOperand(); switch (binary.getOperation()) { case EQUALS: return Expr.binary(BinaryOperation.NOT_EQUALS, binary.getType(), a, b, expr.getLocation()); case NOT_EQUALS: return Expr.binary(BinaryOperation.EQUALS, binary.getType(), a, b, expr.getLocation()); case LESS: return Expr.binary(BinaryOperation.GREATER_OR_EQUALS, binary.getType(), a, b, expr.getLocation()); case LESS_OR_EQUALS: return Expr.binary(BinaryOperation.GREATER, binary.getType(), a, b); case GREATER: return Expr.binary(BinaryOperation.LESS_OR_EQUALS, binary.getType(), a, b, expr.getLocation()); case GREATER_OR_EQUALS: return Expr.binary(BinaryOperation.LESS, binary.getType(), a, b, expr.getLocation()); default: break; } } return Expr.invert(expr); } }
private void binary(NumericOperandType type, int first, int second, Variable result, BinaryOperation op) { assign(Expr.binary(op, mapOperandType(type), Expr.var(first), Expr.var(second)), result); }
cond.getConsequent().clear(); cond.getConsequent().addAll(innerCond.getConsequent()); cond.setCondition(Expr.binary(BinaryOperation.AND, null, cond.getCondition(), innerCond.getCondition(), cond.getCondition().getLocation())); --i;
statement.getBody().remove(0); if (statement.getCondition() != null) { Expr newCondition = Expr.binary(BinaryOperation.AND, null, statement.getCondition(), ExprOptimizer.invert(cond.getCondition())); newCondition.setLocation(statement.getCondition().getLocation());
@Override public void visit(BinaryBranchingInstruction insn) { int a = insn.getFirstOperand().getIndex(); int b = insn.getSecondOperand().getIndex(); BasicBlock consequent = insn.getConsequent(); BasicBlock alternative = insn.getAlternative(); switch (insn.getCondition()) { case EQUAL: branch(withLocation(Expr.binary(BinaryOperation.EQUALS, OperationType.INT, Expr.var(a), Expr.var(b))), consequent, alternative); break; case REFERENCE_EQUAL: branch(withLocation(Expr.binary(BinaryOperation.EQUALS, null, Expr.var(a), Expr.var(b))), consequent, alternative); break; case NOT_EQUAL: branch(withLocation(Expr.binary(BinaryOperation.NOT_EQUALS, OperationType.INT, Expr.var(a), Expr.var(b))), consequent, alternative); break; case REFERENCE_NOT_EQUAL: branch(withLocation(Expr.binary(BinaryOperation.NOT_EQUALS, null, Expr.var(a), Expr.var(b))), consequent, alternative); break; } }
break; case NOT_NULL: branch(Expr.binary(BinaryOperation.NOT_EQUALS, null, Expr.var(insn.getOperand().getIndex()), Expr.constant(null)), insn.getConsequent(), insn.getAlternative()); break; case NULL: branch(Expr.binary(BinaryOperation.EQUALS, null, Expr.var(insn.getOperand().getIndex()), Expr.constant(null)), insn.getConsequent(), insn.getAlternative()); break;