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


C# Mocks.ProgramBuilder类代码示例

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


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

示例1: 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

示例2: 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

示例3: Dfa2_StackArgs

        public void Dfa2_StackArgs()
        {
            var pb = new ProgramBuilder(new FakeArchitecture());
            pb.Add("test", m =>
            {
                var sp = m.Register(m.Architecture.StackRegister);
                var r1 = m.Reg32("r1");
                var r2 = m.Reg32("r2");
                m.Assign(sp, m.Frame.FramePointer);
                m.Assign(r1, m.LoadDw(m.IAdd(sp, 4)));
                m.Assign(r2, m.LoadDw(m.IAdd(sp, 8)));
                m.Assign(r1, m.IAdd(r1, r2));
                m.Store(m.Word32(0x010008), r1);
                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:melbcat,项目名称:reko,代码行数:30,代码来源:DataFlowAnalysisTests2.cs

示例4: 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

示例5: 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

示例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: 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

示例8: 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

示例9: AssertProgram

 private void AssertProgram(string sExp, ProgramBuilder pb)
 {
     var sw = new StringWriter();
     pb.Program.Procedures.Values.First().Write(false, sw);
     var sActual = sw.ToString();
     if (sExp != sActual) 
         Debug.WriteLine(sActual);
     Assert.AreEqual(sExp, sw.ToString());
 }
开发者ID:melbcat,项目名称:reko,代码行数:9,代码来源:DataFlowAnalysisTests2.cs

示例10: 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

示例11: 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

示例12: 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

示例13: Setup

        public void Setup()
        {
            exit = new ExternalProcedure("exit", 
                new ProcedureSignature(null, new Identifier("retCode", PrimitiveType.Int32, new StackArgumentStorage(0, PrimitiveType.Int32))));
            exit.Characteristics = new ProcedureCharacteristics();
            exit.Characteristics.Terminates = true;

            progMock = new ProgramBuilder();
            flow = new ProgramDataFlow();
        }
开发者ID:gitter-badger,项目名称:reko,代码行数:10,代码来源:TerminationAnalysisTests.cs

示例14: 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

示例15: Setup

 public void Setup()
 {
     arch = new IntelArchitecture(ProcessorMode.Protected32);
     m = new ProcedureBuilder(arch);
     prog = new Program();
     prog.Architecture = arch;
     exit = new Procedure("exit", new Frame(PrimitiveType.Word32));
     flow = new ProgramDataFlow();
     p = new ProgramBuilder();
 }
开发者ID:gh0std4ncer,项目名称:reko,代码行数:10,代码来源:TrashedRegisterFinderTests.cs


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