public void Bwi_Branch_DelaySlot() { var l00100008 = new Block(proc, "l00100008"); var l00100100 = new Block(proc, "l00101000"); scanner.Stub(f => f.FindContainingBlock(Address.Ptr32(0x100000))).Return(block); scanner.Stub(f => f.FindContainingBlock(Address.Ptr32(0x100004))).Return(block); scanner.Stub(f => f.FindContainingBlock(Address.Ptr32(0x100008))).Return(l00100008); scanner.Stub(f => f.FindContainingBlock(Address.Ptr32(0x10000C))).Return(null); scanner.Stub(s => s.GetTrace(null, null, null)).IgnoreArguments().Return(trace); scanner.Stub(s => s.EnqueueJumpTarget( Arg <Address> .Is.Equal(Address.Ptr32(0x00100004)), Arg <Address> .Is.Equal(Address.Ptr32(0x00101000)), Arg <Procedure> .Is.Equal(proc), Arg <ProcessorState> .Is.NotNull)).Return(l00100100); scanner.Stub(s => s.EnqueueJumpTarget( Arg <Address> .Is.Equal(Address.Ptr32(0x00100004)), Arg <Address> .Is.Equal(Address.Ptr32(0x00100008)), Arg <Procedure> .Is.Equal(proc), Arg <ProcessorState> .Is.NotNull)).Return(l00100008); mr.ReplayAll(); trace.Add(m => m.Branch(r1, Address.Ptr32(0x101000), RtlClass.ConditionalTransfer | RtlClass.Delay)); trace.Add(m => m.Assign(r0, r1)); // 100004 trace.Add(m => m.Assign(r2, r1)); // 100008 var wi = CreateWorkItem(Address.Ptr32(0x100000), new FakeProcessorState(arch)); wi.Process(); Assert.AreEqual("branch r1 l00100000_ds_t", block.Statements[0].ToString()); var blFalse = block.ElseBlock; var blTrue = block.ThenBlock; proc.Dump(true); Assert.AreEqual("l00100000_ds_f", blFalse.Name); // delay-slot-false Assert.AreEqual(1, blFalse.Statements.Count); Assert.AreEqual("r0 = r1", blFalse.Statements[0].ToString()); Assert.AreEqual(1, blFalse.Succ.Count); Assert.AreEqual("l00100008", blFalse.Succ[0].Name); Assert.AreEqual("l00100000_ds_t", blTrue.Name); // delay-slot-true Assert.AreEqual(1, blTrue.Statements.Count); Assert.AreEqual("r0 = r1", blTrue.Statements[0].ToString()); Assert.AreEqual(1, blTrue.Succ.Count); Assert.AreEqual("l00101000", blTrue.Succ[0].Name); }
public void Transform() { foreach (var block in proc.ControlGraph.Blocks) { ReplaceLongAdditions(block); } proc.Dump(true); }
public static void DumpWatchedProcedure(string caption, Procedure proc) { if (proc.Name == "fn00100000") { Debug.Print("// {0}: {1} ==================", proc.Name, caption); MockGenerator.DumpMethod(proc); proc.Dump(true); } }
public void Transform() { do { dirty = false; foreach (var block in new DfsIterator <Block>(proc.ControlGraph).PostOrder().ToList()) { if (block == null) { continue; } if (EndsInBranch(block)) { if (BranchTargetsEqual(block)) { ReplaceBranchWithJump(block); } } if (EndsInJump(block)) { Block next = block.Succ[0]; if (block != proc.EntryBlock && block.Statements.Count == 0 && next.Pred.Count == 1) { if (Block.ReplaceJumpsTo(block, next)) { dirty = true; } } if (next.Pred.Count == 1 && next != proc.ExitBlock) { Coalesce(block, next); } #if IGNORE // This bollixes up the graphs for ForkedLoop.asm, so we can't use it. // It's not as important as the other three clean stages. else if (EndsInBranch(next) && next.Statements.Count == 1) { ReplaceJumpWithBranch(block, next); } #endif } } } while (dirty); proc.Dump(true); }
private void RunTest(string sExp) { try { GenCode(proc, sb); Assert.AreEqual(sExp, sb.ToString()); } catch { proc.Dump(true); Console.WriteLine(sb.ToString()); throw; } }
public void DumpWatchedProcedure(string phase, string caption, Procedure proc) { if (program.User.DebugTraceProcedures.Contains(proc.Name)) { Debug.Print("// {0}: {1} ==================", proc.Name, caption); //MockGenerator.DumpMethod(proc); proc.Dump(true); var testSvc = this.services.GetService <ITestGenerationService>(); if (testSvc != null) { if (!this.phaseNumbering.TryGetValue(phase, out int n)) { n = phaseNumbering.Count + 1; phaseNumbering.Add(phase, n); } testSvc.ReportProcedure($"analysis_{n:00}_{phase}.txt", $"// {proc.Name} ===========", proc); } } }
public void Liv_CreateDecTest() { Prepare(delegate(ProcedureBuilder m) { Identifier id = m.Local32("id"); m.Assign(id, Constant.Word32(10)); m.Label("loop"); m.Assign(id, m.ISub(id, 1)); m.BranchIf(m.Ge(id, 0), "loop"); m.Store(m.Word32(0x4232), id); m.Return(id); }); proc.Dump(true); var liv = new LinearInductionVariableFinder(proc, ssaIds, doms); liv.Find(); var iv = liv.InductionVariables[0]; Assert.AreEqual("(9 -1 -1 signed)", iv.ToString()); }
private void Prepare(Procedure proc) { this.proc = proc; doms = proc.CreateBlockDominatorGraph(); SsaTransform sst = new SsaTransform(new ProgramDataFlow(), proc, doms); SsaState ssa = sst.SsaState; ssaIds = ssa.Identifiers; var cce = new ConditionCodeEliminator(ssaIds, new DefaultPlatform(null, new FakeArchitecture())); cce.Transform(); DeadCode.Eliminate(proc, ssa); var vp = new ValuePropagator(ssa.Identifiers, proc); vp.Transform(); DeadCode.Eliminate(proc, ssa); proc.Dump(true); //$DEBUG }
private void Build(Procedure proc, IProcessorArchitecture arch) { var platform = new DefaultPlatform(null, arch); this.proc = proc; Aliases alias = new Aliases(proc, arch); alias.Transform(); var gr = proc.CreateBlockDominatorGraph(); SsaTransform sst = new SsaTransform(new ProgramDataFlow(), proc, gr); SsaState ssa = sst.SsaState; this.ssaIds = ssa.Identifiers; ConditionCodeEliminator cce = new ConditionCodeEliminator(ssa.Identifiers, platform); cce.Transform(); DeadCode.Eliminate(proc, ssa); ValuePropagator vp = new ValuePropagator(ssa.Identifiers, proc); vp.Transform(); Coalescer coa = new Coalescer(proc, ssa); coa.Transform(); DeadCode.Eliminate(proc, ssa); proc.Dump(true, false); //$DEBUG }
private void Prepare(Procedure proc) { this.proc = proc; doms = proc.CreateBlockDominatorGraph(); SsaTransform sst = new SsaTransform(new ProgramDataFlow(), proc, doms); SsaState ssa = sst.SsaState; ssaIds = ssa.Identifiers; var cce = new ConditionCodeEliminator(ssaIds, new DefaultPlatform(null,new FakeArchitecture())); cce.Transform(); DeadCode.Eliminate(proc, ssa); var vp = new ValuePropagator(ssa.Identifiers, proc); vp.Transform(); DeadCode.Eliminate(proc, ssa); proc.Dump(true, false); //$DEBUG }