public Identifier DeserializeArgument(Argument_v1 sArg, int idx, string convention)
        {
            if (sArg.Kind != null)
            {
                return(argser.Deserialize(sArg, sArg.Kind));
            }
            Identifier arg;
            var        dtArg = sArg.Type.Accept(TypeLoader);
            var        prim  = dtArg as PrimitiveType;

            if (dtArg.Size <= 8)
            {
                if (this.ir >= iregs.Length)
                {
                    arg = argser.Deserialize(sArg, new StackVariable_v1());
                }
                else
                {
                    arg = argser.Deserialize(sArg, new Register_v1 {
                        Name = iregs[ir]
                    });
                }
                ++this.ir;
                return(arg);
            }
            //int regsNeeded = (dtArg.Size + 7) / 8;
            //if (regsNeeded > 4 || ir + regsNeeded >= iregs.Length)
            //{
            //    return argser.Deserialize(sArg, new StackVariable_v1());
            //}
            throw new NotImplementedException();
        }
 public Identifier DeserializeArgument(Argument_v1 sArg, int idx, string convention)
 {
     if (sArg.Kind != null)
     {
         return(argser.Deserialize(sArg, sArg.Kind));
     }
     return(argser.Deserialize(sArg, new StackVariable_v1()));
 }
        private Identifier DeserializeImplicitThisArgument(SerializedSignature ss)
        {
            var sArg = new Argument_v1
            {
                Type = new PointerType_v1(ss.EnclosingType),
                Name = "this",
                Kind = new Register_v1("rcx")
            };
            var arg = argDeser.Deserialize(sArg);

            return(arg);
        }
Exemple #4
0
        public void ArgSer_DeserializeRegister()
        {
            Register_v1 reg = new Register_v1("eax");
            Argument_v1 arg = new Argument_v1
            {
                Name = "eax",
                Kind = reg,
            };
            Identifier id = argser.Deserialize(arg);

            Assert.AreEqual("eax", id.Name);
            Assert.AreEqual(32, id.DataType.BitSize);
        }
        public override FunctionType Deserialize(SerializedSignature ss, Frame frame)
        {
            if (ss == null)
            {
                return(null);
            }
            var        argser = new ArgumentDeserializer(this, Architecture, frame, 4, 2);
            Identifier ret    = null;

            if (ss.ReturnValue != null)
            {
                ret = argser.DeserializeReturnValue(ss.ReturnValue);
            }

            var args = new List <Identifier>();

            if (ss.Arguments != null)
            {
                for (int iArg = 0; iArg < ss.Arguments.Length; ++iArg)
                {
                    var        sArg = ss.Arguments[iArg];
                    Identifier arg  = argser.Deserialize(sArg);
                    args.Add(arg);
                }
            }

            var sig = new FunctionType(ret, args.ToArray());

            return(sig);
        }
Exemple #6
0
        private Identifier DeserializeArgument(ArgumentDeserializer argser, Argument_v1 sArg)
        {
            Identifier arg;

            if (sArg.Kind != null)
            {
                return(argser.Deserialize(sArg));
            }

            var dtArg = sArg.Type.Accept(TypeLoader);
            var prim  = dtArg as PrimitiveType;

            arg = argser.Deserialize(sArg, new Register_v1("r" + gr));
            ++this.gr;
            return(arg);
        }
        private Identifier DeserializeImplicitThisArgument(SerializedSignature ss)
        {
            var sArg = new Argument_v1
            {
                Type = new PointerType_v1(ss.EnclosingType),
                Name = "this",
            };

            if (ss.Convention == "__thiscall")
            {
                sArg.Kind = new Register_v1("ecx");
            }
            else
            {
                sArg.Kind = new StackVariable_v1();
            }
            var arg = argDeser.Deserialize(sArg);

            return(arg);
        }
        private Identifier DeserializeArgument(ArgumentDeserializer argser, Argument_v1 sArg)
        {
            Identifier arg;

            if (sArg.Kind != null)
            {
                return(argser.Deserialize(sArg));
            }
            var dtArg = sArg.Type.Accept(TypeLoader);
            var prim  = dtArg as PrimitiveType;

            if (prim != null && prim.Domain == Domain.Real && !firstArgIntegral)
            {
                if ((ir % 2) != 0)
                {
                    ++ir;
                }
                if (this.ir >= 4)
                {
                    arg = argser.Deserialize(sArg, new StackVariable_v1());
                }
                else
                {
                    if (prim.Size == 4)
                    {
                        arg      = argser.Deserialize(sArg, new Register_v1("f" + (this.ir + 12)));
                        this.ir += 1;
                    }
                    else if (prim.Size == 8)
                    {
                        arg = argser.Deserialize(sArg, new SerializedSequence
                        {
                            Registers = new[] {
                                new Register_v1("f" + (this.ir + 12)),
                                new Register_v1("f" + (this.ir + 13))
                            }
                        });
                        this.ir += 2;
                    }
                    else
                    {
                        throw new NotSupportedException(string.Format("Real type of size {0} not supported.", prim.Size));
                    }
                }
                return(arg);
            }
            if (ir == 0)
            {
                firstArgIntegral = true;
            }
            if (dtArg.Size <= 4)
            {
                if (this.ir >= 4)
                {
                    arg = argser.Deserialize(sArg, new StackVariable_v1());
                }
                else
                {
                    arg = argser.Deserialize(sArg, new Register_v1("r" + (ir + 4)));
                    ++this.ir;
                }
                return(arg);
            }
            if (dtArg.Size <= 8)
            {
                if ((ir & 1) != 0)
                {
                    ++ir;
                }
                if (this.ir >= 4)
                {
                    arg = argser.Deserialize(sArg, new StackVariable_v1());
                }
                else
                {
                    arg = argser.Deserialize(sArg, new SerializedSequence
                    {
                        Registers = new Register_v1[] {
                            new Register_v1("r" + (ir + 4)),
                            new Register_v1("r" + (ir + 5))
                        }
                    });
                    ir += 2;
                }
                return(arg);
            }
            throw new NotImplementedException();
        }
Exemple #9
0
        public Identifier DeserializeArgument(Argument_v1 sArg, int idx, string convention)
        {
            if (sArg.Kind != null)
            {
                return(argDeser.Deserialize(sArg, sArg.Kind));
            }
            Identifier arg;
            var        dtArg = sArg.Type.Accept(TypeLoader);
            var        prim  = dtArg as PrimitiveType;

            if (prim != null && prim.Domain == Domain.Real)
            {
                if (this.fr >= fregs.Length)
                {
                    arg = argDeser.Deserialize(sArg, new StackVariable_v1());
                }
                else
                {
                    arg = argDeser.Deserialize(sArg, new Register_v1 {
                        Name = fregs[fr]
                    });
                }
                ++this.fr;
                return(arg);
            }
            if (dtArg.Size <= 4)
            {
                if (this.ir >= iregs.Length)
                {
                    arg = argDeser.Deserialize(sArg, new StackVariable_v1());
                }
                else
                {
                    arg = argDeser.Deserialize(sArg, new Register_v1 {
                        Name = iregs[ir]
                    });
                }
                ++this.ir;
                arg.DataType = dtArg;
                return(arg);
            }
            int regsNeeded = (dtArg.Size + 3) / 4;

            if (regsNeeded > 4 || ir + regsNeeded >= iregs.Length)
            {
                return(argDeser.Deserialize(sArg, new StackVariable_v1()));
            }
            if (regsNeeded == 2)
            {
                arg = argDeser.Deserialize(sArg, new SerializedSequence
                {
                    Registers = new[]
                    {
                        new Register_v1 {
                            Name = iregs[ir]
                        },
                        new Register_v1 {
                            Name = iregs[ir + 1]
                        },
                    }
                });
                ir          += 2;
                arg.DataType = dtArg;
                return(arg);
            }
            throw new NotImplementedException();
        }
        private Identifier DeserializeArgument(ArgumentDeserializer argser, Argument_v1 sArg)
        {
            Identifier arg;

            if (sArg.Kind != null)
            {
                return(argser.Deserialize(sArg));
            }

            var dtArg = sArg.Type.Accept(TypeLoader);
            var prim  = dtArg as PrimitiveType;

            if (prim != null && prim.Domain == Domain.Real)
            {
                if (this.fr > 8)
                {
                    arg = argser.Deserialize(sArg, new StackVariable_v1());
                }
                else
                {
                    arg = argser.Deserialize(sArg, new Register_v1("f" + this.fr));
                    ++this.fr;
                }
                return(arg);
            }
            if (dtArg.Size <= 4)
            {
                if (this.gr > 10)
                {
                    arg = argser.Deserialize(sArg, new StackVariable_v1());
                }
                else
                {
                    arg = argser.Deserialize(sArg, new Register_v1("r" + gr));
                    ++this.gr;
                }
                return(arg);
            }
            if (dtArg.Size <= 8)
            {
                if (this.gr > 9)
                {
                    arg = argser.Deserialize(sArg, new StackVariable_v1());
                }
                else
                {
                    if ((gr & 1) == 0)
                    {
                        ++gr;
                    }
                    arg = argser.Deserialize(sArg, new SerializedSequence
                    {
                        Registers = new Register_v1[] {
                            new Register_v1("r" + gr),
                            new Register_v1("r" + (gr + 1))
                        }
                    });
                    gr += 2;
                }
                return(arg);
            }
            throw new NotImplementedException();
        }
Exemple #11
0
        public override FunctionType Deserialize(SerializedSignature ss, Frame frame)
        {
            int ncrn = 0;
            int nsaa = 0;
            // mem arg forb ret val

            var argser = new ArgumentDeserializer(
                this,
                Architecture,
                frame,
                Architecture.PointerType.Size,
                Architecture.WordWidth.Size);

            Identifier ret = null;

            if (ss.ReturnValue != null)
            {
                ret = argser.DeserializeReturnValue(ss.ReturnValue);
            }

            var args = new List <Identifier>();

            if (ss.Arguments != null)
            {
                foreach (var sArg in ss.Arguments)
                {
                    if (sArg.Name == "...")
                    {
                        argser.Deserialize(sArg);
                        continue;
                    }
                    var dt          = sArg.Type.Accept(TypeLoader);
                    var sizeInWords = (dt.Size + 3) / 4;

                    if (sizeInWords == 2 && (ncrn & 1) == 1)
                    {
                        ++ncrn;
                    }
                    Identifier arg;
                    if (sizeInWords <= 4 - ncrn)
                    {
                        if (sizeInWords == 2)
                        {
                            arg = frame.EnsureSequence(
                                Architecture.GetRegister(argRegs[ncrn]),
                                Architecture.GetRegister(argRegs[ncrn + 1]),
                                dt);
                            ncrn += 2;
                        }
                        else
                        {
                            arg = frame.EnsureRegister(
                                Architecture.GetRegister(argRegs[ncrn]));
                            ncrn += 1;
                        }
                    }
                    else
                    {
                        arg   = frame.EnsureStackArgument(nsaa, dt);
                        nsaa += AlignedStackArgumentSize(dt);
                    }
                    args.Add(arg);
                }
            }
            return(new FunctionType(ret, args.ToArray()));
        }