private bool ModifyInitialAssigment(IncrementedUse use) { if (ctx.InitialStatement == null) { return(false); } if (!(ctx.InitialStatement.Instruction is Assignment ass)) { return(false); } if (ass.Src is Constant c) { ass.Src = Operator.IAdd.ApplyConstants(c, use.Increment); } else { // Change expression d = x to d = x + c. ass.Src = new BinaryExpression( Operator.IAdd, ass.Src.DataType, ass.Src, use.Increment); } return(true); }
private void ModifyTest(LinearInductionVariableContext ctx, IncrementedUse use) { if (ctx.TestStatement == null) { return; } if (ctx.TestStatement.Instruction is Branch branch && branch.Condition is BinaryExpression exp && exp.Right is Constant c) { exp.Right = Operator.ISub.ApplyConstants(c, use.Increment); } }
private void ModifyTest(LinearInductionVariableContext ctx, IncrementedUse use) { if (ctx.TestStatement == null) return; Branch branch; BinaryExpression exp ; Constant c ; if (ctx.TestStatement.Instruction.As(out branch) && branch.Condition.As(out exp) && exp.Right.As(out c)) { exp.Right = Operator.ISub.ApplyConstants(c, use.Increment); } }
public void ModifyUses() { if (incrUses.Count != 1) { return; } IncrementedUse use = incrUses[0]; if (ModifyInitialAssigment(use)) { use.Expression.Right = Constant.Create(use.Increment.DataType, 0); ModifyTest(ctx, use); liv.AddIncrement(use.Increment); } }
private bool ModifyInitialAssigment(IncrementedUse use) { if (ctx.InitialStatement == null) return false; Assignment ass = ctx.InitialStatement.Instruction as Assignment; if (ass == null) return false; Constant c = ass.Src as Constant; if (c != null) { ass.Src = Operator.IAdd.ApplyConstants(c, use.Increment); } else { // Change expression d = x to d = x + c. ass.Src = new BinaryExpression( Operator.IAdd, ass.Src.DataType, ass.Src, use.Increment); } return true; }