Ejemplo n.º 1
0
 /// <summary>
 /// Sorts all local variables by their size requirements.
 /// </summary>
 /// <param name="locals">Holds all local variables to sort..</param>
 /// <param name="cc">The calling convention used to determine size and alignment requirements.</param>
 private static void OrderVariables(List <StackOperand> locals, ICallingConvention cc)
 {
     /* Sort the list by stack size requirements - this moves equally sized operands closer together,
      * in the hope that this reduces padding on the stack to enforce HW alignment requirements.
      */
     locals.Sort(delegate(StackOperand op1, StackOperand op2) {
         int size1, size2, alignment;
         cc.GetStackRequirements(op1, out size1, out alignment);
         cc.GetStackRequirements(op2, out size2, out alignment);
         return(size2 - size1);
     });
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Performs a stack layout of all local variables in the list.
        /// </summary>
        /// <param name="locals">The enumerable holding all locals.</param>
        /// <param name="cc">The cc.</param>
        /// <param name="offsetOfFirst">Specifies the offset of the first stack operand in the list.</param>
        /// <param name="direction">The direction.</param>
        /// <returns></returns>
        private static int LayoutVariables(IEnumerable <StackOperand> locals, ICallingConvention cc, int offsetOfFirst, int direction)
        {
            int offset = offsetOfFirst;

            foreach (StackOperand lvo in locals)
            {
                // Does the offset fit the alignment requirement?
                int alignment;
                int size;
                int padding;
                int thisOffset;

                cc.GetStackRequirements(lvo, out size, out alignment);
                if (1 == direction)
                {
                    padding    = (offset % alignment);
                    offset    -= (padding + size);
                    thisOffset = offset;
                }
                else
                {
                    padding = (offset % alignment);
                    if (0 != padding)
                    {
                        padding = alignment - padding;
                    }

                    thisOffset = offset;
                    offset    += (padding + size);
                }

                lvo.Offset = new IntPtr(thisOffset);
            }

            return(offset);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Performs a stack layout of all local variables in the list.
        /// </summary>
        /// <param name="locals">The enumerable holding all locals.</param>
        /// <param name="callingConvention">The cc.</param>
        /// <param name="offsetOfFirst">Specifies the offset of the first stack operand in the list.</param>
        /// <param name="direction">The direction.</param>
        /// <returns></returns>
        private static int LayoutVariables(List<Operand> locals, ICallingConvention callingConvention, int offsetOfFirst, int direction)
        {
            int offset = offsetOfFirst;

            foreach (Operand operand in locals)
            {
                // Does the offset fit the alignment requirement?
                int alignment;
                int size;
                int padding;
                int thisOffset;

                callingConvention.GetStackRequirements(operand, out size, out alignment);
                if (direction == 1)
                {
                    padding = (offset % alignment);
                    offset -= (padding + size);
                    thisOffset = offset;
                }
                else
                {
                    padding = (offset % alignment);
                    if (padding != 0)
                        padding = alignment - padding;

                    thisOffset = offset;
                    offset += (padding + size);
                }

                operand.Offset = new IntPtr(thisOffset);
            }

            return offset;
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Sorts all local variables by their size requirements.
 /// </summary>
 /// <param name="locals">Holds all local variables to sort..</param>
 /// <param name="callingConvention">The calling convention used to determine size and alignment requirements.</param>
 private static void OrderVariables(List<Operand> locals, ICallingConvention callingConvention)
 {
     // Sort the list by stack size requirements - this moves equally sized operands closer together,
     // in the hope that this reduces padding on the stack to enforce HW alignment requirements.
     locals.Sort(delegate(Operand op1, Operand op2)
     {
         int size1, size2, alignment;
         callingConvention.GetStackRequirements(op1, out size1, out alignment);
         callingConvention.GetStackRequirements(op2, out size2, out alignment);
         return size2 - size1;
     });
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Performs a stack layout of all local variables in the list.
        /// </summary>
        /// <param name="locals">The enumerable holding all locals.</param>
        /// <param name="cc">The cc.</param>
        /// <param name="offsetOfFirst">Specifies the offset of the first stack operand in the list.</param>
        /// <param name="direction">The direction.</param>
        /// <returns></returns>
        private static int LayoutVariables(IEnumerable<StackOperand> locals, ICallingConvention cc, int offsetOfFirst, int direction)
        {
            int offset = offsetOfFirst;

            foreach (StackOperand lvo in locals)
            {
                // Does the offset fit the alignment requirement?
                int alignment;
                int size;
                int padding;
                int thisOffset;

                cc.GetStackRequirements(lvo, out size, out alignment);
                if (1 == direction)
                {
                    padding = (offset % alignment);
                    offset -= (padding + size);
                    thisOffset = offset;
                }
                else
                {
                    padding = (offset % alignment);
                    if (0 != padding)
                        padding = alignment - padding;

                    thisOffset = offset;
                    offset += (padding + size);
                }

                lvo.Offset = new IntPtr(thisOffset);
            }

            return offset;
        }