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


C# Mocks.ProcedureBuilder类代码示例

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


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

示例1: WriteProcedure_Max

        public void WriteProcedure_Max()
        {
            var m = new ProcedureBuilder("proc");
            var r1 = m.Register("r1");
            var r2 = m.Register("r2");
            var r3 = m.Register("r3");
            m.BranchIf(m.Gt(r1, r2), "greaterthan");
            m.Assign(r3,r2);
            m.Assign(r2, r1);
            m.Assign(r1, r3);
            m.Label("greaterthan");
            m.Return(r1);

            hcf.Write(m.Procedure);

            var sExp = @"void&nbsp;proc()<br />
            {<br />
            proc_entry:<br />
            &nbsp;&nbsp;&nbsp;&nbsp;<span class=""kw"">goto</span>&nbsp;l1<br />
            greaterthan:<br />
            &nbsp;&nbsp;&nbsp;&nbsp;<span class=""kw"">return</span>&nbsp;r1<br />
            l1:<br />
            &nbsp;&nbsp;&nbsp;&nbsp;<span class=""kw"">branch</span>&nbsp;r1&nbsp;&gt;&nbsp;r2&nbsp;greaterthan<br />
            l2:<br />
            &nbsp;&nbsp;&nbsp;&nbsp;r3&nbsp;=&nbsp;r2<br />
            &nbsp;&nbsp;&nbsp;&nbsp;r2&nbsp;=&nbsp;r1<br />
            &nbsp;&nbsp;&nbsp;&nbsp;r1&nbsp;=&nbsp;r3<br />
            &nbsp;&nbsp;&nbsp;&nbsp;<span class=""kw"">goto</span>&nbsp;greaterthan<br />
            proc_exit:<br />
            }<br />
            ";
            Debug.Write(sb.ToString());
            Assert.AreEqual(sExp, sb.ToString());
        }
开发者ID:nemerle,项目名称:reko,代码行数:34,代码来源:HtmlCodeFormatterTests.cs

示例2: AssertSmallConst

        private void AssertSmallConst(string sExp, int shift, uint mult)
        {
            var m = new ProcedureBuilder();
            var c = Constant.Int32((int)mult);
            var r1 = m.Reg32("r1", 1);
            var r2 = m.Reg32("r2", 2);
            var r2_r1 = m.Frame.EnsureSequence(r2.Storage, r1.Storage, PrimitiveType.Word64);

            var ass = m.Assign(r2_r1, m.SMul(r1, c));
            m.Emit(new AliasAssignment(r2, m.Slice(PrimitiveType.Word32, r2_r1, 32)));
            if (shift != 0)
                m.Assign(r2, m.Sar(r2, shift));

            var proc = m.Procedure;
            var ssa = new SsaTransform(
                null, 
                proc,
                null,
                proc.CreateBlockDominatorGraph(),
                new HashSet<RegisterStorage>()).Transform();
            var ctx = new SsaEvaluationContext(null, ssa.Identifiers);
            var rule = new ConstDivisionImplementedByMultiplication(ssa);
            ctx.Statement = proc.EntryBlock.Succ[0].Statements[0];
            Assert.IsTrue(rule.Match(ass));
            ass = rule.TransformInstruction();
            Assert.AreEqual(sExp, ass.Src.ToString());
        }
开发者ID:relaxar,项目名称:reko,代码行数:27,代码来源:ConstDivisionImplementedByMultiplicationTests.cs

示例3: RunTest

        private void RunTest(string sExp, Action<ProcedureBuilder> builder)
        {
            var pb = new ProcedureBuilder(this.pb.Program.Architecture);
            builder(pb);
            var proc = pb.Procedure;
            var dg = new DominatorGraph<Block>(proc.ControlGraph, proc.EntryBlock);

            // Perform the initial transformation
            var ssa = new SsaTransform(programFlow, proc, dg);

            // Propagate values and simplify the results.
            // We hope the the sequence
            //   esp = fp - 4
            //   mov [esp-4],eax
            // will become
            //   esp_2 = fp - 4
            //   mov [fp - 8],eax

            var vp = new ValuePropagator(ssa.SsaState.Identifiers, proc);
            vp.Transform();

            ssa.RenameFrameAccesses = true;
            ssa.AddUseInstructions = true;
            ssa.Transform();

            var writer = new StringWriter();
            proc.Write(false, writer);
            var sActual = writer.ToString();
            if (sActual != sExp)
                Debug.Print(sActual);
            Assert.AreEqual(sExp, sActual);
        }
开发者ID:melbcat,项目名称:reko,代码行数:32,代码来源:SsaTransformTests.cs

示例4: Given_Procedure

 private void Given_Procedure(uint address)
 {
     var m = new ProcedureBuilder("fnTest");
     m.Return();
     this.proc = m.Procedure;
     this.program.Procedures[Address.Ptr32(address)] = this.proc;
 }
开发者ID:gitter-badger,项目名称:reko,代码行数:7,代码来源:UserSignatureBuilderTests.cs

示例5: OutpReplaceManyUses

        public void OutpReplaceManyUses()
        {
            ProcedureBuilder m = new ProcedureBuilder();
            Identifier foo = new Identifier("foo", PrimitiveType.Word32, null);
            Identifier bar = new Identifier("bar", PrimitiveType.Word32, null);
            Identifier pfoo = new Identifier("pfoo", PrimitiveType.Pointer32, null);

            Block block = m.Label("block");
            m.Assign(foo, 1);
            Statement stmFoo = m.Block.Statements.Last;
            m.Assign(bar, foo);
            Statement stmBar = m.Block.Statements.Last;

            SsaIdentifier ssaFoo = new SsaIdentifier(foo, foo, stmFoo, ((Assignment) stmFoo.Instruction).Src, false);
            ssaFoo.Uses.Add(stmBar);
            SsaIdentifier ssaBar = new SsaIdentifier(bar, bar, stmBar, ((Assignment) stmBar.Instruction).Src, false);

            SsaIdentifierCollection ssaIds = new SsaIdentifierCollection();
            ssaIds.Add(foo, ssaFoo);
            ssaIds.Add(bar, ssaBar);

            OutParameterTransformer opt = new OutParameterTransformer(m.Procedure, ssaIds);
            opt.ReplaceDefinitionsWithOutParameter(foo, pfoo);
            Assert.AreEqual(3, block.Statements.Count);
            Assert.AreEqual("foo = 0x00000001", block.Statements[0].Instruction.ToString());
            Assert.AreEqual("*pfoo = foo", block.Statements[1].Instruction.ToString());
            Assert.AreEqual("bar = foo", block.Statements[2].Instruction.ToString());
        }
开发者ID:nemerle,项目名称:reko,代码行数:28,代码来源:OutParameterTransformerTests.cs

示例6: Setup

		public void Setup()
		{
            m = new ProcedureBuilder();
            ssaState = new SsaState(m.Procedure, null);
            ssaIds = ssaState.Identifiers;
            freg = new FlagRegister("flags", 32, PrimitiveType.Word32);
		}
开发者ID:uxmal,项目名称:reko,代码行数:7,代码来源:ConditionCodeEliminatorTests.cs

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

示例8: FindPostDominators

 private void FindPostDominators(ProcedureBuilder m)
 {
     ProcedureStructureBuilder graphs = new ProcedureStructureBuilder(m.Procedure);
     h = graphs.Build();
     sw = new StringWriter();
     graphs.AnalyzeGraph().Write(sw);
 }
开发者ID:gh0std4ncer,项目名称:reko,代码行数:7,代码来源:PostDominatorGraphTests.cs

示例9: Setup

 public void Setup()
 {
     this.sc = new ServiceContainer();
     this.x86 = new X86ArchitectureFlat32();
     this.ppc = new PowerPcArchitecture32();
     this.m = new ProcedureBuilder();
     this.printfChr = new ProcedureCharacteristics()
     {
         VarargsParserClass =
             "Reko.Libraries.Libc.PrintfFormatParser,Reko.Libraries.Libc"
     };
     this.x86PrintfSig = new FunctionType(
         null,
         StackId(null,   4, CStringType()),
         StackId("...",  8, new UnknownType()));
     this.x86SprintfSig = new FunctionType(
         null,
         StackId(null,   4, CStringType()),
         StackId(null,   8, CStringType()),
         StackId("...", 12, new UnknownType()));
     this.ppcPrintfSig = new FunctionType(
         null,
         RegId(null,  ppc, "r3", CStringType()),
         RegId("...", ppc, "r4", new UnknownType()));
     this.addrInstr = Address.Ptr32(0x123400);
 }
开发者ID:relaxar,项目名称:reko,代码行数:26,代码来源:VarargsFormatScannerTests.cs

示例10: RunTest

        private void RunTest(string sExp, Action<ProcedureBuilder> builder)
        {
            var pb = new ProcedureBuilder(this.pb.Program.Architecture);
            builder(pb);
            var proc = pb.Procedure;
            var dg = new DominatorGraph<Block>(proc.ControlGraph, proc.EntryBlock);
            var project = new Project
            {
                Programs = { this.pb.Program }
            };
            var importResolver = new ImportResolver(
                project,
                this.pb.Program,
                new FakeDecompilerEventListener());
            var arch = new FakeArchitecture();
            
            var platform = new FakePlatform(null, arch);

            // Register r1 is assumed to always be implicit when calling
            // another procedure.
            var implicitRegs = new HashSet<RegisterStorage>
            {
                arch.GetRegister(1)
            };
            Debug.Print("GetRegister(1) {0}", arch.GetRegister(1));
            this.pb.Program.Platform = platform;
            this.pb.Program.Platform = new FakePlatform(null, new FakeArchitecture());
            this.pb.Program.SegmentMap = new SegmentMap(
                Address.Ptr32(0x0000),
                new ImageSegment(
                    ".text",
                    Address.Ptr32(0), 
                    0x40000,
                    AccessMode.ReadWriteExecute));

            // Perform the initial transformation
            var ssa = new SsaTransform(programFlow, proc, importResolver, dg, implicitRegs);

            // Propagate values and simplify the results.
            // We hope the the sequence
            //   esp = fp - 4
            //   mov [esp-4],eax
            // will become
            //   esp_2 = fp - 4
            //   mov [fp - 8],eax

            var vp = new ValuePropagator(this.pb.Program.Architecture, ssa.SsaState);
            vp.Transform();

            ssa.RenameFrameAccesses = true;
            ssa.AddUseInstructions = true;
            ssa.Transform();

            var writer = new StringWriter();
            proc.Write(false, writer);
            var sActual = writer.ToString();
            if (sActual != sExp)
                Debug.Print(sActual);
            Assert.AreEqual(sExp, sActual);
        }
开发者ID:relaxar,项目名称:reko,代码行数:60,代码来源:SsaTransformTests.cs

示例11: Test1

		public void Test1()
		{
			var m = new ProcedureBuilder();
			var id = m.Local32("id");
			var x = m.Local32("x");
			var stm = m.Assign(x, m.IAdd(m.SMul(id, 4), id));
		}
开发者ID:gitter-badger,项目名称:reko,代码行数:7,代码来源:Add_id_c_id_RuleTest.cs

示例12: Fstsw_Setup

 public void Fstsw_Setup()
 {
     arch = new IntelArchitecture(ProcessorMode.Protected32);
     asm = new X86Assembler(arch, Address.Ptr32(0x10000), new List<EntryPoint>());
     Procedure proc = new Procedure("test", arch.CreateFrame());
     orw = new OperandRewriter32(arch, proc.Frame, null);
     emitter = new ProcedureBuilder();
 }
开发者ID:gh0std4ncer,项目名称:reko,代码行数:8,代码来源:FstswChainMatcherTests.cs

示例13: DeadFnReturn

		public void DeadFnReturn()
		{
			ProcedureBuilder m = new ProcedureBuilder("foo");
			Identifier unused = m.Local32("unused");
			m.Assign(unused, m.Fn("foo", Constant.Word32(1)));
			m.Return();
			RunTest(m, "Analysis/DeadFnReturn.txt");
		}
开发者ID:melbcat,项目名称:reko,代码行数:8,代码来源:DeadCodeTests.cs

示例14: RunTest

 protected virtual void RunTest(ProcedureBuilder pm)
 {
     ProcedureStructureBuilder g = new ProcedureStructureBuilder(pm.Procedure);
     g.BuildNodes();
     g.DefineEdges();
     proc = g.CreateProcedureStructure();
     g.SetTimeStamps();
 }
开发者ID:gh0std4ncer,项目名称:reko,代码行数:8,代码来源:ProcHeaderTests.cs

示例15: CompileTest

 private void CompileTest(ProcedureBuilder mock)
 {
     proc = mock.Procedure;
     StructureAnalysis sa = new StructureAnalysis(mock.Procedure);
     sa.BuildProcedureStructure();
     sa.FindStructures();
     curProc = sa.ProcedureStructure;
 }
开发者ID:gh0std4ncer,项目名称:reko,代码行数:8,代码来源:AbsynCodeGeneratorTests.cs


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