private void RunValuePropagator(ProcedureBuilder m) { var ssa = new SsaState(m.Procedure, null); foreach (var ssaId in ssaIds) { ssa.Identifiers.Add(ssaId.Identifier, ssaId); } ssaIds = ssa.Identifiers; var stms = m.Procedure.EntryBlock.Succ[0].Statements; stms.ForEach(stm => { var ass = stm.Instruction as Assignment; if (ass != null) { ssaIds[ass.Dst].DefStatement = stm; ssaIds[ass.Dst].DefExpression = ass.Src; } var phiAss = stm.Instruction as PhiAssignment; if (phiAss != null) { ssaIds[phiAss.Dst].DefStatement = stm; ssaIds[phiAss.Dst].DefExpression = phiAss.Src; } ssa.AddUses(stm); }); var vp = new ValuePropagator(arch, ssa, listener); vp.Transform(); ssa.CheckUses(s => Assert.Fail(s)); }
private Statement ProcessInstruction(Instruction instr, Statement stm) { switch (instr) { case Assignment ass: Ssa.Identifiers[ass.Dst].DefStatement = stm; Ssa.Identifiers[ass.Dst].DefExpression = ass.Src; break; case PhiAssignment phiAss: Ssa.Identifiers[phiAss.Dst].DefStatement = stm; Ssa.Identifiers[phiAss.Dst].DefExpression = phiAss.Src; break; case Store store: if (store.Dst is MemoryAccess access) { var memId = AddMemIdToSsa(access.MemoryId); Ssa.Identifiers[memId].DefStatement = stm; Ssa.Identifiers[memId].DefExpression = null; var ea = access.EffectiveAddress; var dt = access.DataType; if (store.Dst is SegmentedAccess sa) { var basePtr = sa.BasePointer; store.Dst = new SegmentedAccess(memId, basePtr, ea, dt); } else { store.Dst = new MemoryAccess(memId, ea, dt); } } break; case CallInstruction call: foreach (var def in call.Definitions) { var id = def.Identifier; Ssa.Identifiers[id].DefStatement = stm; Ssa.Identifiers[id].DefExpression = call.Callee; } break; case DefInstruction def: Ssa.Identifiers[def.Identifier].DefStatement = stm; Ssa.Identifiers[def.Identifier].DefExpression = null; break; } Ssa.AddUses(stm); return(stm); }