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


C# MethodBody类代码示例

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


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

示例1: ReplaceRegisterWith

        /// <summary>
        /// Replace all references to oldRegister with newRegister in the given instruction set.
        /// </summary>
        public void ReplaceRegisterWith(Register oldRegister, Register newRegister, MethodBody body)
        {
            var oldRegister2 = (oldRegister.Type == RType.Wide) ? body.GetNext(oldRegister) : null;
            var newRegister2 = (newRegister.Type == RType.Wide) ? body.GetNext(newRegister) : null;

            if (oldRegister.IsKeepWithNext != newRegister.IsKeepWithNext)
                throw new ArgumentException("New register has different keep-with-next value");

            HashSet<Instruction> list;
            if (map.TryGetValue(oldRegister, out list))
            {
                list.ForEach(x => x.ReplaceRegisterWith(oldRegister, newRegister));
                // Update newRegister
                AddRange(newRegister, list);
            }
            if (oldRegister2 != null)
            {
                if (map.TryGetValue(oldRegister2, out list))
                {
                    list.ForEach(x => x.ReplaceRegisterWith(oldRegister2, newRegister2));
                    // Update newRegister2
                    AddRange(newRegister2, list);
                }                
            }
        }
开发者ID:rfcclub,项目名称:dot42,代码行数:28,代码来源:RegisterUsageMap.cs

示例2: TransformTempToVariable

        /// <summary>
        /// Transform the given body.
        /// </summary>
        private static void TransformTempToVariable(MethodBody body, List<BasicBlock> basicBlocks)
        {
            body.Instructions.UpdateIndexCache();
            var allTempRegisterRanges = CollectTempRegisterUsageRanges(basicBlocks).Values.ToList();

            foreach (var iterator in basicBlocks)
            {
                var block = iterator;
                // Collect all register ranges that fit completly within this block and are used exactly 2 times
                var registerRanges = allTempRegisterRanges.Where(x => (x.InstructionCount == 2) && x.ContainsExactlyOne(block)).ToList();

                foreach (var range in registerRanges)
                {
                    var firstIns = range.Range.First;
                    var lastIns = range.Range.Last;
                    if (!lastIns.Code.IsMove())
                        continue;
                    var reg = range.Register;
                    if (lastIns.Registers[1] != reg)
                        continue;
                    var varReg = lastIns.Registers[0];
                    if (varReg.Category != RCategory.Variable)
                        continue;

                    // Replace
                    firstIns.ReplaceRegisterWith(reg, varReg);
                    lastIns.ConvertToNop();
                }
            }
        }
开发者ID:Xtremrules,项目名称:dot42,代码行数:33,代码来源:ShareRegistersTransformation.TempToVariable.cs

示例3: BranchReRouter

 /// <summary>
 /// Default ctor
 /// </summary>
 public BranchReRouter(MethodBody body)
 {
     List<Instruction> list = null;
     // Record instructions with branch targets
     foreach (var inst in body.Instructions)
     {
         switch (inst.Code)
         {
             case RCode.Goto:
             case RCode.Leave:
             case RCode.If_eq:
             case RCode.If_ne:
             case RCode.If_lt:
             case RCode.If_ge:
             case RCode.If_gt:
             case RCode.If_le:
             case RCode.If_eqz:
             case RCode.If_nez:
             case RCode.If_ltz:
             case RCode.If_gez:
             case RCode.If_gtz:
             case RCode.If_lez:
             case RCode.Packed_switch:
             case RCode.Sparse_switch:
                 list = list ?? new List<Instruction>();
                 list.Add(inst);
                 break;
         }
     }
     branches = list;
     exceptionHandlers = body.Exceptions.Any() ? body.Exceptions.ToArray() : null;
 }
开发者ID:Xtremrules,项目名称:dot42,代码行数:35,代码来源:BranchRerouter.cs

示例4: Transform

 /// <summary>
 /// Transform the given body.
 /// </summary>
 public void Transform(Dex target, MethodBody body)
 {
     foreach (var ins in body.Instructions)
     {
         switch (ins.Code)
         {
             case RCode.Invoke_direct:
             case RCode.Invoke_virtual:
             case RCode.Invoke_interface:
                 MethodDefinition method;
                 if (((MethodReference)ins.Operand).TryResolve(target, out method))
                 {
                     if (method.Owner.IsInterface)
                     {
                         ins.Code = RCode.Invoke_interface;
                     }
                     else if (method.IsDirect)
                     {
                         ins.Code = RCode.Invoke_direct;
                     }
                     else
                     {
                         ins.Code = RCode.Invoke_virtual;
                     }
                 }
                 break;
         }
     }
 }
开发者ID:Xtremrules,项目名称:dot42,代码行数:32,代码来源:InvokeTypeTransformation.cs

示例5: GetTransformations

        private static IEnumerable<IRLTransformation> GetTransformations(Dex target, MethodBody body)
        {
            foreach (var transformation in optimizations1)
            {
                transformation.Transform(target, body);
                yield return transformation;
            }

            var noopRemove = new NopRemoveTransformation();
            noopRemove.Transform(target, body);
            yield return noopRemove;

            bool hasChanges = true;

            while (hasChanges)
            {
                hasChanges = false;
                foreach (var transformation in incrementalOptimizations)
                {
                    bool changed = transformation.Transform(target, body);
                    if (changed) noopRemove.Transform(target, body);

                    hasChanges = changed || hasChanges;

                    yield return transformation;
                }
            }

            foreach (var transformation in optimizations2)
            {
                transformation.Transform(target, body);
                yield return transformation;
            }    
        }
开发者ID:Xtremrules,项目名称:dot42,代码行数:34,代码来源:RLTransformations.cs

示例6: Transform

        public bool Transform(Dex target, MethodBody body)
        {
#if DEBUG
            //return;
#endif
            return DoOptimization(body);
        }
开发者ID:Xtremrules,项目名称:dot42,代码行数:7,代码来源:EliminateDeadAssignmentsOptimization.cs

示例7: AssertOpCodeSequence

		static void AssertOpCodeSequence (OpCode [] expected, MethodBody body)
		{
			var opcodes = body.Instructions.Select (i => i.OpCode).ToArray ();
			Assert.AreEqual (expected.Length, opcodes.Length);

			for (int i = 0; i < opcodes.Length; i++)
				Assert.AreEqual (expected [i], opcodes [i]);
		}
开发者ID:BGCX261,项目名称:zoom-decompiler-hg-to-git,代码行数:8,代码来源:ILProcessorTests.cs

示例8: Transform

        /// <summary>
        /// Transform the given body.
        /// </summary>
        public void Transform(Dex target, MethodBody body)
        {
            var basicBlocks = BasicBlock.Find(body);
            var registerCount = body.Registers.Count();
            if (registerCount > MaxRegisters)
                return;

            Dictionary<Instruction, ConstantKey> allConstInstructions;
            CollectReadOnlyConstInstructions(body, out allConstInstructions);
            RegisterUsageMap registerUsageMap = null;

            foreach (var block in basicBlocks)
            {
                // Select all const instructions that have a next instruction in the block.
                var list = block.Instructions.ToList();
                var isLargeBlock = list.Count > LargeBlockSize;
                if (isLargeBlock)
                    continue;
                var constInstructionKeys = list.Where(x => allConstInstructions.ContainsKey(x)).Select(x => allConstInstructions[x]).ToList();

                // Select all const instructions where the next instruction is a move.
                while (constInstructionKeys.Count > 0)
                {
                    // Take the first instruction
                    var insKey = constInstructionKeys[0];
                    constInstructionKeys.RemoveAt(0);

                    // Get the register
                    var reg = insKey.Instruction.Registers[0];

                    // Are there other const instructions of the same type and the same operand?
                    var sameConstInstructions = constInstructionKeys.Where(x => x.Equals(insKey)).ToList();
                    if (sameConstInstructions.Count == 0)
                        continue;
                    if (sameConstInstructions.Count < 4)
                        continue;

                    // It is now save to use the register for all const operations
                    foreach (var other in sameConstInstructions)
                    {
                        // Replace all register uses
                        var otherReg = other.Instruction.Registers[0];

                        // Find usages
                        registerUsageMap = registerUsageMap ?? new RegisterUsageMap(body.Instructions);
                        registerUsageMap.ReplaceRegisterWith(otherReg, reg, body);

                        // Remove const
                        constInstructionKeys.Remove(other);
                        allConstInstructions.Remove(other.Instruction);

                        // Change const to nop which will be removed later
                        other.Instruction.ConvertToNop();
                    }
                }
            }
        }
开发者ID:rfcclub,项目名称:dot42,代码行数:60,代码来源:ShareConstTransformation.cs

示例9: ControlFlowGraph2

        public ControlFlowGraph2(MethodBody body)
        {
            _body = body;
            _basicBlocks = new ControlFlowGraph(body).ToList();
            _entries = _basicBlocks.ToDictionary(b => b.Entry, b => b);
            _exits = _basicBlocks.ToDictionary(b => b.Exit, b => b);
            _entryInstructions = _basicBlocks.Select(b => b.Entry).ToList();

            IncludeExceptionHandlers(body);
        }
开发者ID:Xtremrules,项目名称:dot42,代码行数:10,代码来源:ControlFlowGraph2.cs

示例10: Transform

        public bool Transform(Dex target, MethodBody body)
        {
            bool hasChanges = false;

            var registerUsage = new RegisterUsageMap2(body);

            hasChanges = InlineIntConstsIntoBinOp(registerUsage);

            return hasChanges;
        }
开发者ID:Xtremrules,项目名称:dot42,代码行数:10,代码来源:InlineIntLiteralsTransformation.cs

示例11: Transform

        /// <summary>
        /// Transform the given body.
        /// </summary>
        public bool Transform(Dex target, MethodBody body)
        {
            bool hasChanges = false;

            // Find all "const" instructions and record register usage
            var allConstInstructions = new List<Instruction>();
            var registerUsage = new Dictionary<Register, List<Instruction>>();
            CollectInstructionInformation(body, allConstInstructions, registerUsage);

            // Find all basic blocks
            var basicBlocks = BasicBlock.Find(body);

            // Go over each block
            foreach (var iterator in basicBlocks)
            {
                var block = iterator;
                // Select all const instructions where the next instruction is a move.
                foreach (var ins in allConstInstructions)
                {
                    var r = ins.Registers[0];
                    // Only optimize const instructions to temp registers
                    if (r.Category != RCategory.Temp)
                        continue;

                    // Get all instructions using this register
                    var all = registerUsage[r];
                    if ((all.Count != 2) || (all[0] != ins))
                        continue;
                    var next = all[1];
                    // Opcode must match
                    if (next.Code != ConstToMove(ins.Code))
                        continue;
                    // Register must match
                    if (next.Registers[1] != r)
                        continue;
                    
                    // The following are the most expensive, so only test them if we have to.
                    // Only optimize is instruction is in current block
                    if (!block.Contains(ins))
                        continue;

                    // Next must be in same basic block
                    if (!block.Contains(next))
                        continue;

                    // We found a replacement
                    r = next.Registers[0];
                    ins.Registers[0] = r;
                    next.ConvertToNop();

                    hasChanges = true;
                }
            }
            return hasChanges;
        }
开发者ID:Xtremrules,项目名称:dot42,代码行数:58,代码来源:ConstPropagationTransformation.cs

示例12: Transform

        public bool Transform(Dex target, MethodBody body)
        {
            bool hasChanges = false;

            var graph = new ControlFlowGraph2(body);
            var registerUsage = new RegisterUsageMap2(graph);

            hasChanges = EliminateRegisterAssigments(registerUsage);
            
            return hasChanges;
        }
开发者ID:jakesays,项目名称:dot42,代码行数:11,代码来源:EliminateRegistersOptimization.cs

示例13: Read

        public void Read(MethodBody body, InstructionMapper mapper)
        {
            var method_token = body.Method.MetadataToken;

            PdbFunction function;
            if (!functions.TryGetValue (method_token.ToUInt32 (), out function))
                return;

            ReadSequencePoints (function, mapper);
            ReadScopeAndLocals (function.scopes, null, body, mapper);
        }
开发者ID:ttRevan,项目名称:cecil,代码行数:11,代码来源:PdbReader.cs

示例14: Read

        public void Read(MethodBody body, InstructionMapper mapper)
        {
            var method_token = body.Method.MetadataToken;
            var entry = symbol_file.GetMethodByToken (method_token.ToInt32	());
            if (entry == null)
                return;

            var scopes = ReadScopes (entry, body, mapper);
            ReadLineNumbers (entry, mapper);
            ReadLocalVariables (entry, body, scopes);
        }
开发者ID:ttRevan,项目名称:cecil,代码行数:11,代码来源:MdbReader.cs

示例15: ReadMethodBody

		public MethodBody ReadMethodBody (MethodDefinition method)
		{
			this.method = method;
			this.body = new MethodBody (method);

			reader.context = method;

			ReadMethodBody ();

			return this.body;
		}
开发者ID:mayuki,项目名称:Inazuma,代码行数:11,代码来源:CodeReader.cs


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