Exemplo n.º 1
0
        private FunctionType ReplaceVarargs(
            FunctionType sig,
            IEnumerable <DataType> argumentTypes)
        {
            var varargs        = sig.Parameters.Last();
            var varargsStorage = varargs.Storage as StackStorage;

            if (varargsStorage == null)
            {
                throw new NotSupportedException(
                          string.Format(
                              "The {0} parameter of {1} wasn't a stack access.",
                              varargs.Name,
                              sig.Name));
            }
            var stackOffset = varargsStorage.StackOffset;
            var args        = argumentTypes.Select(dt =>
            {
                var stg      = new StackArgumentStorage(stackOffset, dt);
                stackOffset += dt.Size;
                return(new Identifier(null, dt, stg));
            });

            return(sig.ReplaceVarargs(args.ToArray()));
        }
Exemplo n.º 2
0
        public void Stg_StackStorageCover()
        {
            // Mimic a big endian copy of the low 8 bits of a stack word.
            var argLarge = new StackArgumentStorage(4, PrimitiveType.Word32);
            var argSmall = new StackArgumentStorage(7, PrimitiveType.Byte);

            Assert.IsTrue(argLarge.Covers(argSmall), $"{argLarge} should cover {argSmall}.");
            Assert.False(argSmall.Covers(argLarge), $"{argSmall} shouldn't cover {argLarge}.");
        }
Exemplo n.º 3
0
 public Storage VisitStackArgumentStorage(StackArgumentStorage stack)
 {
     if (defining)
     {
         regDefs[stack] = value;
     }
     else
     {
         value = null;
         regDefs.TryGetValue(stack, out value);
     }
     return(stack);
 }
Exemplo n.º 4
0
        public Expression VisitStackArgumentStorage(StackArgumentStorage stack)
        {
            int localOff = stack.StackOffset - stackDepthOnEntry;

            foreach (var de in this.map
                     .Where(d => d.Value.Storage is StackStorage))
            {
                if (((StackStorage)de.Value.Storage).StackOffset == localOff)
                {
                    return(de.Value.Expression);
                }
            }
            return(FallbackArgument($"stackArg{localOff}", stack.DataType));
        }
Exemplo n.º 5
0
 private static CallBinding?IntersectStackRegisterBinding(StackArgumentStorage stArg, IEnumerable <CallBinding> callBindings)
 {
     foreach (var binding in callBindings)
     {
         if (binding.Storage is StackArgumentStorage)
         {
             if (binding.Storage.Equals(stArg))
             {
                 return(binding);
             }
         }
     }
     return(null);
 }
Exemplo n.º 6
0
        public bool MergeIntoProcedureFlow(IdentifierLiveness varLive, ProcedureFlow flow)
        {
            if (varLive.BitSet[0x1F])
            {
                varLive.ToString();
            }
            bool fChange = false;

            if (!(varLive.BitSet & ~flow.Summary).IsEmpty)
            {
                flow.Summary |= varLive.BitSet;
                fChange       = true;
            }
            if ((varLive.Grf & ~flow.grfSummary) != 0)
            {
                flow.grfSummary |= varLive.Grf;
                fChange          = true;
            }
            foreach (KeyValuePair <Storage, int> de in varLive.LiveStorages)
            {
                StackArgumentStorage sa = de.Key as StackArgumentStorage;
                if (sa == null)
                {
                    continue;
                }
                int bits = de.Value;

                object o = flow.StackArguments[sa];
                if (o != null)
                {
                    int bitsOld = (int)o;
                    if (bitsOld < bits)
                    {
                        flow.StackArguments[sa] = bits;
                        fChange = true;
                    }
                }
                else
                {
                    flow.StackArguments[sa] = bits;
                    fChange = true;
                }
            }
            return(fChange);
        }
Exemplo n.º 7
0
        public void Pflow_IntersectBinding_StackArgument_ExactMatch()
        {
            var stCallee = new StackArgumentStorage(4, PrimitiveType.Word32);
            var stCaller = new StackArgumentStorage(4, PrimitiveType.Word32);
            var idCaller = new Identifier("local", stCaller.DataType, stCaller);
            var cbs      = new[]
            {
                new CallBinding(stCaller, idCaller)
            };
            var uses = new Dictionary <Storage, BitRange>
            {
                { stCallee, new BitRange(0, 32) }
            };
            var bindings = ProcedureFlow.IntersectCallBindingsWithUses(cbs, uses)
                           .ToArray();

            Assert.AreEqual(1, bindings.Length);
            Assert.AreEqual("Stack +0004:local", bindings[0].ToString());
        }
Exemplo n.º 8
0
        public bool MergeIntoProcedureFlow(IdentifierLiveness varLive, ProcedureFlow flow)
        {
            bool fChange  = false;
            int  oldcount = flow.Summary.Count;

            flow.Summary.UnionWith(varLive.Identifiers);
            if (flow.Summary.Count != oldcount)
            {
                fChange = true;
            }
            if ((varLive.Grf & ~flow.grfSummary) != 0)
            {
                flow.grfSummary |= varLive.Grf;
                fChange          = true;
            }
            foreach (KeyValuePair <Storage, int> de in varLive.LiveStorages)
            {
                StackArgumentStorage sa = de.Key as StackArgumentStorage;
                if (sa == null)
                {
                    continue;
                }
                int bits = de.Value;

                object o = flow.StackArguments[sa];
                if (o != null)
                {
                    int bitsOld = (int)o;
                    if (bitsOld < bits)
                    {
                        flow.StackArguments[sa] = bits;
                        fChange = true;
                    }
                }
                else
                {
                    flow.StackArguments[sa] = bits;
                    fChange = true;
                }
            }
            return(fChange);
        }
Exemplo n.º 9
0
        public void Pflow_IntersectBinding_NotFoundUses()
        {
            var reg      = new RegisterStorage("r1", 1, 0, PrimitiveType.Word32);
            var stCallee = new StackArgumentStorage(4, PrimitiveType.Word32);
            var id       = new Identifier("r1", reg.DataType, reg);
            var cbs      = new CallBinding[] { };
            var uses     = new Dictionary <Storage, BitRange>
            {
                {
                    reg,
                    new BitRange(0, 31)
                },
                {
                    stCallee,
                    new BitRange(0, 31)
                },
            };

            var bindings = ProcedureFlow.IntersectCallBindingsWithUses(cbs, uses)
                           .ToArray();

            Assert.AreEqual(0, bindings.Length);
        }
Exemplo n.º 10
0
 public Storage VisitStackArgumentStorage(StackArgumentStorage arg)
 {
     if (define)
     {
         if (liveStackVars.ContainsKey(arg))
         {
             defBitSize = liveStackVars[arg];
             liveStackVars.Remove(arg);
         }
         defOffset = 0;
     }
     else
     {
         if (liveStackVars.ContainsKey(arg))
         {
             liveStackVars[arg] = Math.Max(useBitSize, liveStackVars[arg]);
         }
         else
         {
             liveStackVars.Add(arg, useBitSize != 0 ? useBitSize : arg.DataType.BitSize);
         }
     }
     return(null);
 }
Exemplo n.º 11
0
 public bool VisitStackArgumentStorage(StackArgumentStorage stack, bool defining)
 {
     return(true);
 }
Exemplo n.º 12
0
 public Storage VisitStackArgumentStorage(StackArgumentStorage stack)
 {
     return(null);
 }
Exemplo n.º 13
0
        private FunctionType ReplaceVarargs(
            FunctionType sig,
            IEnumerable<DataType> argumentTypes)
        {
            var varargs = sig.Parameters.Last();
            var varargsStorage = varargs.Storage as StackStorage;
            if (varargsStorage == null)
                throw new NotSupportedException(
                    string.Format(
                        "The {0} parameter of {1} wasn't a stack access.",
                        varargs.Name,
                        sig.Name));
            var stackOffset = varargsStorage.StackOffset;
            var args = argumentTypes.Select(dt =>
            {
                var stg = new StackArgumentStorage(stackOffset, dt);
                stackOffset += dt.Size;
                return new Identifier(null, dt, stg);
            });

            return sig.ReplaceVarargs(args.ToArray());
        }
Exemplo n.º 14
0
 public bool VisitStackArgumentStorage(StackArgumentStorage stack, bool defining)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 15
0
 public Identifier VisitStackArgumentStorage(StackArgumentStorage arg)
 {
     return(frame.EnsureStackArgument(arg.StackOffset, arg.DataType));
 }
Exemplo n.º 16
0
 public bool VisitStackArgumentStorage(StackArgumentStorage stack)
 {
     return(liveState.LiveStorages.ContainsKey(stack));
 }
Exemplo n.º 17
0
 public Storage VisitStackArgumentStorage(StackArgumentStorage stack)
 {
     ctx.StackState[stack.StackOffset] = value;
     return(stack);
 }
Exemplo n.º 18
0
 public Identifier VisitStackArgumentStorage(StackArgumentStorage stack)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 19
0
 public string VisitStackArgumentStorage(StackArgumentStorage stack)
 {
     return("stack");
 }