Ejemplo n.º 1
0
		public void TestGrfWithOneBit()
		{
			IProcessorArchitecture arch = new X86ArchitectureReal();
			SignatureBuilder sb = new SignatureBuilder(null, arch);
            sb.AddFlagGroupReturnValue((uint) FlagM.CF, arch.CreateFrame());
			FunctionType sig = sb.BuildSignature();
			Assert.AreEqual("bool", sig.ReturnValue.DataType.ToString());
		}
Ejemplo n.º 2
0
        public void AddStackArgument(Identifier id, ProcedureFlow flow, SignatureBuilder sb)
        {
            object o = flow.StackArguments[id];

            if (o != null)
            {
                int bitWidth = (int)o;
                if (bitWidth < id.DataType.BitSize)
                {
                    PrimtiveType pt = id.DataType as PrimtiveType;
                    if (pt != null)
                    {
                        id.DataType = PrimtiveType.Create(pt.Domain, bitWidth);
                    }
                }
            }
            sb.AddInParam(id);
        }
Ejemplo n.º 3
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.ParametersValid)
            {
                return;
            }

            var sb    = new SignatureBuilder(proc.Frame, proc.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 (var id in GetSortedStackArguments(proc.Frame).Values)
            {
                AddStackArgument(id, 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);

            // Sort the names in a stable way to avoid regression tests failing.
            foreach (var r in liveOut.OrderBy(r => r.Number).ThenBy(r => r.BitAddress))
            {
                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;
        }
Ejemplo n.º 4
0
 public void Msp_cdecl_long_return_value()
 {
     Given_MsdosPlatform();
     Given_Procedure();
     var dx_ax = proc.Frame.EnsureSequence(Registers.dx, Registers.ax, PrimitiveType.Word32);
     var arg06 = proc.Frame.EnsureStackArgument(6, PrimitiveType.Word16);
     var sb = new SignatureBuilder(proc, arch);
     sb.AddOutParam(dx_ax);
     sb.AddInParam(arg06);
     var sig = sb.BuildSignature();
     sig.ReturnAddressOnStack = 4;
     sig.StackDelta = 0;
     var cc = platform.DetermineCallingConvention(sig);
     Assert.AreEqual("__cdecl", cc);
 }