当前位置: 首页>>代码示例>>C#>>正文


C# ProgramBuilder.Add方法代码示例

本文整理汇总了C#中Reko.UnitTests.Mocks.ProgramBuilder.Add方法的典型用法代码示例。如果您正苦于以下问题:C# ProgramBuilder.Add方法的具体用法?C# ProgramBuilder.Add怎么用?C# ProgramBuilder.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Reko.UnitTests.Mocks.ProgramBuilder的用法示例。


在下文中一共展示了ProgramBuilder.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CrossJump

        /// <summary>
        /// This program has a cross procedural jump
        /// that should result in a new procedure, at Real_entry,since the jumped-to code 
        /// is not a simple linear block but a branch.
        /// </summary>
        /// <returns></returns>
        public static Program CrossJump()
        {
            var b = new ProgramBuilder();
            b.Add("bob", m =>
            {
                var r1 = m.Reg32("r1", 1);
                var r2 = m.Reg32("r2", 2);
                m.Label("bob_1");
                m.Assign(r1, 0);
                // Fall through should be promoted to call/return pair.

                m.Label("Real_entry"); // Cross jump target: should become a new function entry point.
                m.Store(r2, r1);
                m.BranchIf(r2, "Real_entry");
                m.Return();
            });

            b.Add("ext", m =>
            {
                var r1 = m.Reg32("r1", 1);
                m.Label("ext_1");
                m.Assign(r1, 4);
                m.Goto("Real_entry");
            });
            return b.BuildProgram();
        }
开发者ID:gitter-badger,项目名称:reko,代码行数:32,代码来源:ScannerTestPrograms.cs

示例2: BuildProgram

        /// <summary>
        /// Mutually recursive functions that jump into each other's bodies.
        /// </summary>
        /// <returns></returns>
        public static Program BuildProgram()
        {
            var prog = new ProgramBuilder();

            var m = new ProcedureBuilder("even");
            var r1 = m.Register(1);
            m.BranchIf(m.Eq0(r1), "done");
            m.Assign(r1, m.ISub(r1, 1));
            m.Call("odd", 4);
            m.Assign(r1, m.Not(r1));
            m.Return();

            m.Label("done");
            m.Assign(r1, true);
            m.Return();
            prog.Add(m);

            m = new ProcedureBuilder("odd");
            r1 = m.Register(1);
            m.BranchIf(m.Eq(r1, 1), "done");
            m.Assign(r1, m.ISub(r1, 1));
            m.Call("event", 4);
            m.Assign(r1, m.Not(r1));
            m.Return();

            m.Label("done");
            m.Assign(r1, true);
            m.Return();
            prog.Add(m);

            return prog.BuildProgram();
        }
开发者ID:gitter-badger,项目名称:reko,代码行数:36,代码来源:EvenOdd.cs

示例3: EP_AddrOf

        public void EP_AddrOf()
        {
            var arch = new FakeArchitecture();
            var p = new ProgramBuilder(arch);
            Identifier r2 = null, r3 = null;
            var proc = p.Add("main", (m) =>
            {
                r2 = m.Register("r2");
                r3 = m.Register("r3");
                m.Assign(r2, 0x1234);                       // after which R2 has a definite value
                m.SideEffect(m.Fn("Foo", m.Out(PrimitiveType.Pointer32, r2)));    // Can't promise R2 is preserved after call, so should be invalid.
                m.Assign(r3, r2);
            });

            var ctx = new SymbolicEvaluationContext(arch, proc.Frame);
            var simplifier = new ExpressionSimplifier(ctx);
            var ep = new ExpressionPropagator(arch, simplifier, ctx, new ProgramDataFlow());

            ctx.RegisterState[arch.StackRegister] = proc.Frame.FramePointer;

            var stms = proc.EntryBlock.Succ[0].Statements;
            var instr1 = stms[0].Instruction.Accept(ep);
            Assert.AreEqual("0x00001234", ctx.GetValue(r2).ToString());
            var instr2 = stms[1].Instruction.Accept(ep);
            Assert.AreEqual("Foo(out r2)", instr2.ToString());
            Assert.AreEqual("<invalid>", ctx.GetValue(r2).ToString());
            var instr3 = stms[2].Instruction.Accept(ep);
            Assert.AreEqual("r3 = r2", instr3.ToString());
            Assert.AreEqual("<invalid>", ctx.GetValue(r2).ToString());
            Assert.AreEqual("<invalid>", ctx.GetValue(r3).ToString());
        }
开发者ID:nemerle,项目名称:reko,代码行数:31,代码来源:ExpressionPropagatorTests.cs

示例4: RunTest

 protected override void RunTest(Action<ProcedureBuilder> doBuild, string outputFile)
 {
     var pb = new ProgramBuilder();
     pb.Add("proc1", doBuild);
     var program = pb.BuildProgram();
     RunTest(program, outputFile);
 }
开发者ID:relaxar,项目名称:reko,代码行数:7,代码来源:TypeCollectorTests.cs

示例5: Dfa2_Simple

        public void Dfa2_Simple()
        {
            var pb = new ProgramBuilder(new FakeArchitecture());
            pb.Add("test", m=>
                {
                    var r1 = m.Reg32("r1", 1);
                    var r2 = m.Reg32("r2", 2);
                    m.Assign(r1, m.LoadDw(m.Word32(0x010000)));
                    m.Assign(r2, m.LoadDw(m.Word32(0x010004)));
                    m.Store(m.Word32(0x010008), m.IAdd(r1, r2));
                    m.Return();
                });
            var dfa = new DataFlowAnalysis(pb.BuildProgram(), new FakeDecompilerEventListener());
            dfa.AnalyzeProgram2();
            var sExp = @"// test
// Return size: 0
void test()
test_entry:
	// succ:  l1
l1:
	Mem3[0x00010008:word32] = Mem0[0x00010000:word32] + Mem0[0x00010004:word32]
	return
	// succ:  test_exit
test_exit:
";
            AssertProgram(sExp, pb.Program);
        }
开发者ID:gitter-badger,项目名称:reko,代码行数:27,代码来源:DataFlowAnalysisTests2.cs

示例6: Dfa2_CallProc

        public void Dfa2_CallProc()
        {
            pb = new ProgramBuilder();
            pb.Add("test", m =>
            {
                var sp = m.Register(m.Architecture.StackRegister);

                var fooProc = GivenFunction("foo", m.Architecture.GetRegister(1), 4, 8);
                m.Assign(sp, m.ISub(sp, 4));
                m.Store(sp, 2);
                m.Assign(sp, m.ISub(sp, 4));
                m.Store(sp, 1);
                m.Call(fooProc, 4);
                m.Assign(sp, m.IAdd(sp, 8));
                m.Return();
            });

            var dfa = new DataFlowAnalysis(pb.BuildProgram(), new FakeDecompilerEventListener());
            dfa.UntangleProcedures2();
            var sExp = @"// test
            // Return size: 0
            void test()
            test_entry:
            // succ:  l1
            l1:
            Mem9[0x00010008:word32] = Mem0[fp + 0x00000004:word32] + Mem0[fp + 0x00000008:word32]
            return
            // succ:  test_exit
            test_exit:
            ";
            AssertProgram(sExp, pb);
        }
开发者ID:nemerle,项目名称:reko,代码行数:32,代码来源:DataFlowAnalysisTests2.cs

示例7: CompileTest

 protected Program CompileTest(Action<ProcedureBuilder> m)
 {
     var mock = new ProcedureBuilder();
     m(mock);
     var pmock = new ProgramBuilder();
     pmock.Add(mock);
     return pmock.BuildProgram();
 }
开发者ID:uxmal,项目名称:reko,代码行数:8,代码来源:ConditionCodeEliminatorTests.cs

示例8: PprMemberVars

 public void PprMemberVars()
 {
     ProgramBuilder mock = new ProgramBuilder();
     ProcedureBuilder p = new ProcedureBuilder();
     Identifier cs = p.Frame.EnsureRegister(Registers.cs);
     p.Store(p.SegMemW(cs, p.Word32(0x0001)), Constant.Create(PrimitiveType.SegmentSelector, 0x0800));
     mock.Add(p);
     RunTest(mock.BuildProgram(), "Typing/PprMemberVars.txt");
 }
开发者ID:nemerle,项目名称:reko,代码行数:9,代码来源:PtrPrimitiveReplacerTests.cs

示例9: PprMemberPointers

 public void PprMemberPointers()
 {
     ProgramBuilder mock = new ProgramBuilder();
     ProcedureBuilder m = new ProcedureBuilder();
     Identifier ds = m.Local(PrimitiveType.SegmentSelector, "ds");
     m.SegStore(ds, m.Word32(7000), m.SegMemW(ds, m.SegMemW(ds, m.Word32(0x5321))));
     mock.Add(m);
     RunTest(mock.BuildProgram(), "Typing/PprMemberPointers.txt");
 }
开发者ID:nemerle,项目名称:reko,代码行数:9,代码来源:PtrPrimitiveReplacerTests.cs

示例10: Simple

 //$TODO: translate to RtlTraces
 /// <summary>
 /// Simple program consisting of a single procedure.
 /// </summary>
 /// <returns></returns>
 public Program Simple()
 {
     var b = new ProgramBuilder();
     b.Add("bob", m =>
     {
         m.Label("Zlon");
         m.Return();
     });
     return b.BuildProgram();
 }
开发者ID:gitter-badger,项目名称:reko,代码行数:15,代码来源:ScannerTestPrograms.cs

示例11: CpaSimple

		public void CpaSimple()
		{
			var program = new ProgramBuilder();
            program.Add("test", m=>
               {
                   var r1 = m.Register(1);
                   m.Assign(r1, m.Load(PrimitiveType.Real32, m.Word32(0x10000000)));
               });
			RunTest(program.BuildProgram(), "Typing/CpaSimple.txt");
		}
开发者ID:relaxar,项目名称:reko,代码行数:10,代码来源:ConstantPointerAnalysisTests.cs

示例12: DpaConstantPointer

        public void DpaConstantPointer()
        {
            ProgramBuilder prog = new ProgramBuilder();
            ProcedureBuilder m = new ProcedureBuilder();
            Identifier r1 = m.Register(1);
            m.Assign(r1, 0x123130);
            m.Store(r1, m.Int32(0x42));
            prog.Add(m);

            RunTest(prog.BuildProgram(), "Typing/DpaConstantPointer.txt");
        }
开发者ID:nemerle,项目名称:reko,代码行数:11,代码来源:DerivedPointerAnalysisTests.cs

示例13: CreateIntraProceduralJumps

 private void CreateIntraProceduralJumps()
 {
     var regS = new RegisterStorage("reg", 1, 0, PrimitiveType.Word32);
     prog = new ProgramBuilder();
     prog.Add("main", (m) =>
     {
         var reg = m.Frame.EnsureRegister(regS);
         m.Assign(reg, 0);
         m.Store(m.Word32(0x1234), reg);
         m.Return();
     });
 }
开发者ID:uxmal,项目名称:reko,代码行数:12,代码来源:InterProceduralJumpTests.cs

示例14: DpaConstantMemberPointer

        public void DpaConstantMemberPointer()
        {
            ProgramBuilder prog = new ProgramBuilder();
            ProcedureBuilder m = new ProcedureBuilder();
            Identifier ds = m.Local16("ds");
            ds.DataType = PrimitiveType.SegmentSelector;
            Identifier bx = m.Local16("bx");

            m.Assign(bx, 0x1234);
            m.Store(m.SegMemW(ds, bx), m.Int16(0x0042));
            prog.Add(m);

            RunTest(prog.BuildProgram(), "Typing/DpaConstantMemberPointer.txt");
        }
开发者ID:nemerle,项目名称:reko,代码行数:14,代码来源:DerivedPointerAnalysisTests.cs

示例15: BuildSample

        public static Program BuildSample()
        {
            var pb = new ProgramBuilder();
            pb.Add("fact", m =>
            {
                var sp = m.Register(m.Architecture.StackRegister);
                var r1 = m.Register(1);
                var r2 = m.Register(2);
                var r3 = m.Register(3);
                var cc = m.Flags("cc");
                m.Assign(sp, m.Frame.FramePointer);
                m.Assign(r2, r1);
                m.Assign(r1, 1);
                m.Assign(cc, m.Cond(m.ISub(r2, r1)));
                m.BranchIf(m.Test(ConditionCode.LE, cc), "m_done");

                m.Assign(sp, m.ISub(sp, 4));
                m.Store(sp, r2);
                m.Assign(r1, m.ISub(r2, r1));
                m.Call("fact", 0);
                m.Assign(r2, m.LoadDw(sp));
                m.Assign(sp, m.IAdd(sp, 4));
                m.Assign(r1, m.IMul(r1, r2));

                m.Label("m_done");
                m.Return();
            });
            pb.Add("main", m =>
            {
                var r1 = m.Register(1);
                m.Assign(r1, 10);
                m.Call("fact", 0);
                m.Store(m.Word32(0x400000), r1);
            });
            return pb.BuildProgram();
        }
开发者ID:gitter-badger,项目名称:reko,代码行数:36,代码来源:Factorial.cs


注:本文中的Reko.UnitTests.Mocks.ProgramBuilder.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。