private static void MarkPreserved(Identifier id, ProcedureFlow2 procFlow) { if (procFlow.Trashed.Contains(id.Storage)) { return; } procFlow.Preserved.Add(id.Storage); }
private ProcedureFlow2 EnsureProcedureFlow(Procedure proc) { ProcedureFlow2 procFlow; if (!dataFlow.ProcedureFlows.TryGetValue(proc, out procFlow)) { procFlow = new ProcedureFlow2(); dataFlow.ProcedureFlows.Add(proc, procFlow); } return(procFlow); }
public TrashedRegisterFinder2( IProcessorArchitecture arch, ProgramDataFlow flow, Procedure proc, SsaIdentifierCollection ssa, DecompilerEventListener listener) { this.arch = arch; this.progFlow = flow; this.proc = proc; this.ssa = ssa; this.decompilerEventListener = listener; this.flow = new ProcedureFlow2(); }
private void ProcessAssignment(Assignment ass, ProcedureFlow2 procFlow, Queue <Identifier> worklist) { if (ass.Src is Constant) { SetConstant(ass.Dst, (Constant)ass.Src, procFlow); } else if (ass.Src is Identifier) { worklist.Enqueue((Identifier)ass.Src); } else { MarkTrashed(idFinal, procFlow); } }
private void AddDefInstructions(CallInstruction ci, ProcedureFlow2 flow) { var existing = ci.Definitions.Select(d => ssa.Identifiers[(Identifier)d.Identifier].OriginalIdentifier).ToHashSet(); var ab = new ApplicationBuilder(null, proc.Frame, null, null, null, true); foreach (var idDef in flow.Trashed) { var idLocal = proc.Frame.EnsureIdentifier(idDef); if (!existing.Contains(idLocal)) { ci.Definitions.Add(new DefInstruction(idLocal)); } } foreach (var def in ci.Definitions) { var idNew = NewDef((Identifier)def.Identifier, null, false); def.Identifier = idNew; } }
private void SetConstant(Identifier id, Constant c, ProcedureFlow2 procFlow) { if (procFlow.Trashed.Contains(id.Storage)) { Constant c2; if (!procFlow.Constants.TryGetValue(id.Storage, out c2)) { return; } if (!cmp.Equals(c, c2)) { procFlow.Constants.Remove(id.Storage); } } else { procFlow.Preserved.Remove(id.Storage); procFlow.Trashed.Add(id.Storage); procFlow.Constants.Add(id.Storage, c); } }
private ProcedureFlow2 EnsureProcedureFlow(Procedure proc) { ProcedureFlow2 procFlow; if (!dataFlow.ProcedureFlows.TryGetValue(proc, out procFlow)) { procFlow = new ProcedureFlow2(); dataFlow.ProcedureFlows.Add(proc, procFlow); } return procFlow; }
private static void MarkPreserved(Identifier id, ProcedureFlow2 procFlow) { if (procFlow.Trashed.Contains(id.Storage)) return; procFlow.Preserved.Add(id.Storage); }
private void SetConstant(Identifier id, Constant c, ProcedureFlow2 procFlow) { if (procFlow.Trashed.Contains(id.Storage)) { Constant c2; if (!procFlow.Constants.TryGetValue(id.Storage, out c2)) return; if (!cmp.Equals(c, c2)) procFlow.Constants.Remove(id.Storage); } else { procFlow.Preserved.Remove(id.Storage); procFlow.Trashed.Add(id.Storage); procFlow.Constants.Add(id.Storage, c); } }
private void MarkTrashed(Identifier id, ProcedureFlow2 procFlow) { procFlow.Preserved.Remove(id.Storage); procFlow.Trashed.Add(id.Storage); procFlow.Constants.Remove(id.Storage); }
private void ProcessAssignment(Assignment ass, ProcedureFlow2 procFlow, Queue<Identifier> worklist) { if (ass.Src is Constant) { SetConstant(ass.Dst, (Constant)ass.Src, procFlow); } else if (ass.Src is Identifier) { worklist.Enqueue((Identifier)ass.Src); } else { MarkTrashed(idFinal, procFlow); } }
private void AddDefInstructions(CallInstruction ci, ProcedureFlow2 flow) { var existing = ci.Definitions.Select(d => ssa.Identifiers[(Identifier)d.Expression].OriginalIdentifier).ToHashSet(); var ab = new ApplicationBuilder(null, proc.Frame, null, null, null, true); foreach (var idDef in flow.Trashed) { var idLocal = proc.Frame.EnsureIdentifier(idDef); if (!existing.Contains(idLocal)) { ci.Definitions.Add(new DefInstruction(idLocal)); } } foreach (var def in ci.Definitions) { var idNew = NewDef((Identifier) def.Expression, null, false); def.Expression = idNew; } }
public void SsaSubroutine() { Storage r1_ = null; // Simulate the creation of a subroutine. var procSub = this.pb.Add("Adder", m => { r1_ = m.Register(1).Storage; }); var procSubFlow = new ProcedureFlow2 { Trashed = { r1_ } }; programFlow.ProcedureFlows2.Add(procSub, procSubFlow); var sExp = @"// ProcedureBuilder // Return size: 0 void ProcedureBuilder() ProcedureBuilder_entry: // succ: l1 l1: r1_0 = 0x00000003 r2_1 = 0x00000004 call Adder (retsize: 4;) uses: r1_0,r2_1 defs: r1_2 Mem3[0x00012300:word32] = r1_2 return // succ: ProcedureBuilder_exit ProcedureBuilder_exit: use Mem3 use r1_2 use r2_1 "; RunTest(sExp, m => { var r1 = m.Register(1); var r2 = m.Register(2); m.Assign(r1, 3); m.Assign(r2, 4); m.Call(procSub, 4); m.Store(m.Word32(0x012300), r1); m.Return(); }); }