/// <summary> /// Finds the subsequent statement in this block that defines a condition code based on the /// result in expression <paramref name="exp"/>. /// </summary> /// <param name="p"></param> /// <param name="ax"></param> /// <returns></returns> public CondMatch?FindConditionOf(List <Statement> stms, int iStm, Expression exp) { if (exp is Identifier idLo) { foreach (var use in ssa.Identifiers[idLo].Uses.Where(u => condm.Match(u.Instruction))) { var grf = (Identifier)condm.CapturedExpressions("grf") !; var condExp = condm.CapturedExpressions("exp"); if (grf.Storage is FlagGroupStorage && exp == condExp) { return(new CondMatch(grf, exp, use, 0)); } } } for (int i = iStm + 1; i < stms.Count; ++i) { if (!condm.Match(stms[i].Instruction)) { continue; } var grf = (Identifier)condm.CapturedExpressions("grf") !; var condExp = condm.CapturedExpressions("exp"); if (grf.Storage is FlagGroupStorage && exp == condExp) { return(new CondMatch(grf, exp, null !, i)); } } return(null); }
/// <summary> /// Matches an "ADC" or "SBB/SBC" pattern. /// </summary> /// <param name="instr"></param> /// <returns>If the match succeeded, returns a partial BinaryExpression /// with the left and right side of the ADC/SBC instruction.</returns> public AddSubCandidate MatchAdcSbc(Statement stm) { if (!adcPattern.Match(stm.Instruction)) { return(null); } if (!IsCarryFlag(adcPattern.CapturedExpressions("cf"))) { return(null); } var op = adcPattern.CapturedOperators("op2"); if (!IsIAddOrISub(op)) { return(null); } return(new AddSubCandidate { Dst = adcPattern.CapturedExpressions("dst"), Op = op, Left = adcPattern.CapturedExpressions("left"), Right = adcPattern.CapturedExpressions("right"), Statement = stm }); }
public void MatchAssignment() { var ax = RegW("ax"); var pattern = m.Assign(ax, m.IAdd(ax, ExpressionMatcher.AnyConstant("c"))); var instrmatcher = new InstructionMatcher(pattern); Assert.IsTrue(instrmatcher.Match( m.Assign(ax, m.IAdd(ax, m.Word16(42))))); Assert.AreEqual("0x002A", instrmatcher.CapturedExpressions("c").ToString()); }
public AddSubCandidate? MatchAddSub(Statement stm) { if (!addPattern.Match(stm.Instruction)) return null; var op = addPattern.CapturedOperators("op")!; if (!IsIAddOrISub(op)) return null; return new AddSubCandidate( op, addPattern.CapturedExpressions("left")!, addPattern.CapturedExpressions("right")!) { Dst = addPattern.CapturedExpressions("dst")!, }; }
/// <summary> /// Matches an "ADC" or "SBB/SBC" pattern. /// </summary> /// <param name="instr"></param> /// <returns>If the match succeeded, returns a partial BinaryExpression /// with the left and right side of the ADC/SBC instruction.</returns> public AddSubCandidate? MatchAdcSbc(Statement stm) { if (!adcPattern.Match(stm.Instruction)) return null; if (!IsCarryFlag(adcPattern.CapturedExpressions("cf")!)) return null; var op = adcPattern.CapturedOperators("op2")!; if (!IsIAddOrISub(op)) return null; return new AddSubCandidate( op, adcPattern.CapturedExpressions("left")!, adcPattern.CapturedExpressions("right")!) { Dst = adcPattern.CapturedExpressions("dst")!, Statement = stm }; }
/// <summary> /// Finds the subsequent statement in this block that defines a condition code based on the /// result in expression <paramref name="exp"/>. /// </summary> /// <param name="p"></param> /// <param name="ax"></param> /// <returns></returns> public CondMatch FindConditionOf(StatementList stms, int iStm, Expression exp) { for (int i = iStm + 1; i < stms.Count; ++i) { if (!condm.Match(stms[i].Instruction)) { continue; } var grf = (Identifier)condm.CapturedExpressions("grf"); var condExp = condm.CapturedExpressions("exp"); if (grf.Storage is FlagGroupStorage && exp == condExp) { return(new CondMatch { FlagGroup = grf, src = exp, StatementIndex = i }); } } return(null); }
public AddSubCandidate MatchAddSub(Instruction instr) { if (!addPattern.Match(instr)) { return(null); } var op = addPattern.CapturedOperators("op"); if (!IsIAddOrISub(op)) { return(null); } return(new AddSubCandidate { Dst = addPattern.CapturedExpressions("dst"), Op = op, Left = addPattern.CapturedExpressions("left"), Right = addPattern.CapturedExpressions("right") }); }