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())); }
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}."); }
public Storage VisitStackArgumentStorage(StackArgumentStorage stack) { if (defining) { regDefs[stack] = value; } else { value = null; regDefs.TryGetValue(stack, out value); } return(stack); }
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)); }
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); }
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); }
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()); }
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); }
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); }
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); }
public bool VisitStackArgumentStorage(StackArgumentStorage stack, bool defining) { return(true); }
public Storage VisitStackArgumentStorage(StackArgumentStorage stack) { return(null); }
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()); }
public bool VisitStackArgumentStorage(StackArgumentStorage stack, bool defining) { throw new NotImplementedException(); }
public Identifier VisitStackArgumentStorage(StackArgumentStorage arg) { return(frame.EnsureStackArgument(arg.StackOffset, arg.DataType)); }
public bool VisitStackArgumentStorage(StackArgumentStorage stack) { return(liveState.LiveStorages.ContainsKey(stack)); }
public Storage VisitStackArgumentStorage(StackArgumentStorage stack) { ctx.StackState[stack.StackOffset] = value; return(stack); }
public Identifier VisitStackArgumentStorage(StackArgumentStorage stack) { throw new NotImplementedException(); }
public string VisitStackArgumentStorage(StackArgumentStorage stack) { return("stack"); }