Exemple #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;
        }
Exemple #2
0
		public void AddUseInstructionsForOutArguments(Procedure proc)
		{
			foreach (Identifier id in proc.Signature.Parameters)
			{
				var os = id.Storage as OutArgumentStorage;
				if (os == null)
					continue;
				var r = os.OriginalIdentifier.Storage as RegisterStorage;
				if (r == null)
					continue;

				proc.ExitBlock.Statements.Add(0, new UseInstruction(os.OriginalIdentifier, id));
			}
		}
Exemple #3
0
        /// <summary>
        /// Having identified the return variable -- if any, rewrite all
        /// return statements to return that variable.
        /// </summary>
        /// <param name="proc"></param>
        private void RewriteReturns(Procedure proc)
        {
            Identifier idRet = proc.Signature.ReturnValue;

            if (idRet == null)
            {
                return;
            }
            foreach (Statement stm in proc.Statements)
            {
                var ret = stm.Instruction as ReturnInstruction;
                if (ret != null)
                {
                    ret.Expression = idRet;
                }
            }
        }
Exemple #4
0
        public void AddUseInstructionsForOutArguments(Procedure proc)
        {
            foreach (Identifier id in proc.Signature.Parameters)
            {
                var os = id.Storage as OutArgumentStorage;
                if (os == null)
                {
                    continue;
                }
                var r = os.OriginalIdentifier.Storage as RegisterStorage;
                if (r == null)
                {
                    continue;
                }

                proc.ExitBlock.Statements.Add(0, new UseInstruction(os.OriginalIdentifier, id));
            }
        }
Exemple #5
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;

			var sb = new SignatureBuilder(proc, Program.Architecture);
			var frame = proc.Frame;
			if (flow.grfLiveOut != 0)
			{
				sb.AddFlagGroupReturnValue(flow.grfLiveOut, frame);
			}

            var implicitRegs = Program.Platform.CreateImplicitArgumentRegisters();
            var mayUse = new HashSet<RegisterStorage>(flow.MayUse);
            mayUse.ExceptWith(implicitRegs);
			foreach (var reg in mayUse.OrderBy(r => r.Number))
			{
				if (!IsSubRegisterOfRegisters(reg, mayUse))
				{
					sb.AddRegisterArgument(reg);
				}
			}

			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);
			}

            var liveOut = new HashSet<RegisterStorage>(flow.LiveOut);
            liveOut.ExceptWith(implicitRegs);
			foreach (var r in liveOut.OrderBy(r => r.Number))
			{
				if (!IsSubRegisterOfRegisters(r, liveOut))
				{
					sb.AddOutParam(frame.EnsureRegister(r));
				}
			}

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

            var sig = sb.BuildSignature();
            flow.Signature = sig;
			proc.Signature = sig;
		}
		/// <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;
		}
		/// <summary>
		/// Having identified the return variable -- if any, rewrite all 
		/// return statements to return that variable.
		/// </summary>
		/// <param name="proc"></param>
        private void RewriteReturns(Procedure proc)
        {
            Identifier idRet = proc.Signature.ReturnValue;
            if (idRet == null)
                return;
            foreach (Statement stm in proc.Statements)
            {
                var ret = stm.Instruction as ReturnInstruction;
                if (ret != null)
                {
                    ret.Expression = idRet;
                }
            }
        }
Exemple #8
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;
            }

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

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

            var implicitRegs = Program.Platform.CreateImplicitArgumentRegisters();
            var mayUse       = new HashSet <RegisterStorage>(flow.MayUse);

            mayUse.ExceptWith(implicitRegs);
            foreach (var reg in mayUse.OrderBy(r => r.Number))
            {
                if (!IsSubRegisterOfRegisters(reg, mayUse))
                {
                    sb.AddRegisterArgument(reg);
                }
            }

            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);
            }

            var liveOut = new HashSet <RegisterStorage>(flow.LiveOut);

            liveOut.ExceptWith(implicitRegs);
            foreach (var r in liveOut.OrderBy(r => r.Number))
            {
                if (!IsSubRegisterOfRegisters(r, liveOut))
                {
                    sb.AddOutParam(frame.EnsureRegister(r));
                }
            }

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

            var sig = sb.BuildSignature();

            flow.Signature = sig;
            proc.Signature = sig;
        }