Esempio n. 1
0
        /// <summary>
        /// Gets all registers of category!=Argument that are used in an instruction.
        /// </summary>
        private static void GetUsedArgumentRegisters(MethodBody body, out Dictionary <Register, RegisterFlags> used, out int maxOutgoingRegisters, out bool largeInvokeInsFound)
        {
            //maxOutgoingRegisters = body.Instructions.Max(x => x.Code.IsInvoke() ? x.Registers.Count : 0);
            //largeInvokeInsFound = body.Instructions.Any(x => x.Code.IsInvoke() && x.Registers.Count > 5);
            maxOutgoingRegisters = 0;
            largeInvokeInsFound  = false;

            used = new Dictionary <Register, RegisterFlags>();
            foreach (var ins in body.Instructions)
            {
                if (ins.Code.IsInvoke())
                {
                    maxOutgoingRegisters = Math.Max(maxOutgoingRegisters, ins.Registers.Count);
                    if (ins.Registers.Count > 5)
                    {
                        largeInvokeInsFound = true;
                    }
                }
                foreach (var reg in ins.Registers)
                {
                    if (reg.Category != RCategory.Argument)
                    {
                        var           lowestSize = GetLowestSize(ins, reg);
                        RegisterFlags currentLowestSize;
                        if (used.TryGetValue(reg, out currentLowestSize))
                        {
                            if (lowestSize < currentLowestSize)
                            {
                                used[reg] = lowestSize;
                            }
                        }
                        else
                        {
                            used.Add(reg, lowestSize);
                        }
                    }
                }
            }

            // Add second register of wide registers.
            Register prevReg = null;

            foreach (var reg in body.Registers)
            {
                if (prevReg != null)
                {
                    if (reg.Type == RType.Wide2)
                    {
                        RegisterFlags flags;
                        if (used.TryGetValue(prevReg, out flags))
                        {
                            used[reg] = flags;
                        }
                    }
                }
                prevReg = reg;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the lowest size (in bitsX) that is available for the given register in the given instruction.
        /// </summary>
        private static RegisterFlags GetLowestSize(Instruction instruction, Register r)
        {
            var result    = RegisterFlags.Bits16;
            var info      = OpCodeInfo.Get(instruction.Code.ToDex());
            var registers = instruction.Registers;

            for (var i = 0; i < registers.Count; i++)
            {
                if (registers[i] == r)
                {
                    var size = info.GetUsage(i) & RegisterFlags.SizeMask;
                    if (size < result)
                    {
                        result = size;
                    }
                }
            }
            return(result);
        }
Esempio n. 3
0
 /// <summary>
 /// Gets the Dex register for the given RL register.
 /// </summary>
 public bool ContainsKey(Register source)
 {
     return(map.ContainsKey(source));
 }
Esempio n. 4
0
 /// <summary>
 /// Gets the Dex register for the given RL register.
 /// </summary>
 public Dot42.DexLib.Instructions.Register this[Register source]
 {
     get { return(map[source]); }
 }
Esempio n. 5
0
 /// <summary>
 /// Gets the lowest size (in bitsX) that is available for the given register in the given instruction.
 /// </summary>
 private static RegisterFlags GetLowestSize(Instruction instruction, Register r)
 {
     var result = RegisterFlags.Bits16;
     var info = OpCodeInfo.Get(instruction.Code.ToDex());
     var registers = instruction.Registers;
     for (var i = 0; i < registers.Count; i++)
     {
         if (registers[i] == r)
         {
             var size = info.GetUsage(i) & RegisterFlags.SizeMask;
             if (size < result) result = size;
         }
     }
     return result;
 }
Esempio n. 6
0
 /// <summary>
 /// Gets the Dex register for the given RL register.
 /// </summary>
 public bool ContainsKey(Register source)
 {
     return map.ContainsKey(source); 
 }
Esempio n. 7
0
 /// <summary>
 /// Gets the Dex register for the given RL register.
 /// </summary>
 public Dot42.DexLib.Instructions.Register this[Register source]
 {
     get { return map[source]; }
 }
Esempio n. 8
0
 /// <summary>
 /// Gets the register immediately following the given register.
 /// </summary>
 public Register GetNext(Register r)
 {
     return(registers.First(x => x.Index == r.Index + 1));
 }