Beispiel #1
0
        /// <summary>
        /// Creates a signature for this procedure, and ensures that all registers accessed by the procedure are in the procedure
        /// Frame.
        /// </summary>
        public void EnsureSignature(Procedure proc, ProcedureFlow flow)
        {
            if (proc.Signature != null && proc.Signature.ParametersValid)
            {
                return;
            }

            SignatureBuilder sb    = new SignatureBuilder(proc, Program.Architecture);
            Frame            frame = proc.Frame;

            if (flow.grfLiveOut != 0)
            {
                sb.AddFlagGroupReturnValue(flow.grfLiveOut, frame);
            }

            var    implicitRegs = Program.Platform.CreateImplicitArgumentRegisters();
            BitSet mayUse       = flow.MayUse - implicitRegs;

            foreach (int r in mayUse)
            {
                if (!IsSubRegisterOfRegisters(r, mayUse))
                {
                    sb.AddRegisterArgument(r);
                }
            }

            foreach (KeyValuePair <int, Identifier> de in GetSortedStackArguments(proc.Frame))
            {
                AddStackArgument(de.Key, de.Value, flow, sb);
            }

            foreach (KeyValuePair <int, Identifier> de in GetSortedFpuStackArguments(proc.Frame, 0))
            {
                sb.AddFpuStackArgument(de.Key, de.Value);
            }

            BitSet liveOut = flow.LiveOut - implicitRegs;

            foreach (int r in liveOut)
            {
                if (!IsSubRegisterOfRegisters(r, liveOut))
                {
                    sb.AddArgument(frame.EnsureRegister(Program.Architecture.GetRegister(r)), true);
                }
            }

            foreach (KeyValuePair <int, Identifier> de in GetSortedFpuStackArguments(proc.Frame, -proc.Signature.FpuStackDelta))
            {
                int i = de.Key;
                if (i <= proc.Signature.FpuStackOutArgumentMax)
                {
                    sb.AddArgument(frame.EnsureFpuStackVariable(i, de.Value.DataType), true);
                }
            }

            var sig = sb.BuildSignature();

            flow.Signature = sig;
            proc.Signature = sig;
        }
Beispiel #2
0
        public SortedList <int, Identifier> GetSortedArguments(Frame f, Type type, int startOffset)
        {
            SortedList <int, Identifier> arguments = new SortedList <int, Identifier>();

            foreach (Identifier id in f.Identifiers)
            {
                if (id.Storage.GetType() == type)
                {
                    int externalOffset = f.ExternalOffset(id);                                  //$REFACTOR: do this with BindToExternalFrame.
                    if (externalOffset >= startOffset)
                    {
                        Identifier vOld;
                        if (!arguments.TryGetValue(externalOffset, out vOld) ||
                            vOld.DataType.Size < id.DataType.Size)
                        {
                            arguments[externalOffset] = id;
                        }
                    }
                }
            }
            return(arguments);
        }
Beispiel #3
0
        public SortedList<int, Identifier> GetSortedFpuStackArguments(Frame frame, int d)
		{
			return GetSortedArguments(frame, typeof (FpuStackStorage), d);
		}
Beispiel #4
0
		/// <summary>
		/// Returns a list of all stack arguments accessed, indexed by their offsets
		/// as seen by a caller. I.e. the first argument is at offset 0, &c.
		/// </summary>
        public SortedList<int, Identifier> GetSortedStackArguments(Frame frame)
		{
			return GetSortedArguments(frame, typeof (StackArgumentStorage), 0);
		}
Beispiel #5
0
		public SortedList<int, Identifier> GetSortedArguments(Frame f, Type type, int startOffset)
		{
			SortedList<int, Identifier> arguments = new SortedList<int,Identifier>();
			foreach (Identifier id in f.Identifiers)
			{
				if (id.Storage.GetType() == type)
				{
					int externalOffset = f.ExternalOffset(id);		//$REFACTOR: do this with BindToExternalFrame.
					if (externalOffset >= startOffset)
					{
						Identifier vOld;
                        if (!arguments.TryGetValue(externalOffset, out vOld) ||
                            vOld.DataType.Size < id.DataType.Size)
                        {
                            arguments[externalOffset] = id;
                        }
					}
				}
			}
			return arguments;
		}
Beispiel #6
0
 public SortedList <int, Identifier> GetSortedFpuStackArguments(Frame frame, int d)
 {
     return(GetSortedArguments(frame, typeof(FpuStackStorage), d));
 }
Beispiel #7
0
 /// <summary>
 /// Returns a list of all stack arguments accessed, indexed by their offsets
 /// as seen by a caller. I.e. the first argument is at offset 0, &c.
 /// </summary>
 public SortedList <int, Identifier> GetSortedStackArguments(Frame frame)
 {
     return(GetSortedArguments(frame, typeof(StackArgumentStorage), 0));
 }