public StackState Clone() { StackState state = new StackState(); foreach (Entry entry in Enumerable.Reverse<Entry>(this._entries)) { state.Entries.Push(entry.Clone()); } return state; }
private StackStateBuilder(MethodDefinition methodDefinition, StackState initialState, Unity.IL2CPP.ILPreProcessor.TypeResolver typeResolver) { this._methodDefinition = methodDefinition; this._typeResolver = typeResolver; this._simulationStack = new Stack <Entry>(); foreach (Entry entry in initialState.Entries.Reverse <Entry>()) { this._simulationStack.Push(entry.Clone()); } }
public StackState Clone() { StackState state = new StackState(); foreach (Entry entry in this._entries.Reverse <Entry>()) { state.Entries.Push(entry.Clone()); } return(state); }
private void Analyze() { foreach (InstructionBlock block in this._cfg.Blocks) { StackState state; if (!this._ins.TryGetValue(block, out state)) { state = new StackState(); } StackState other = StackStateBuilder.StackStateFor(block, state, this._methodDefinition, this._typeResolver); this._outs.Add(block, other.Clone()); foreach (InstructionBlock block2 in block.Successors) { if (!this._ins.ContainsKey(block2)) { this._ins[block2] = new StackState(); } this._ins[block2].Merge(other); } } }
public void Merge(StackState other) { List<Entry> collection = new List<Entry>(this._entries); List<Entry> list2 = new List<Entry>(other.Entries); while (collection.Count < list2.Count) { collection.Add(new Entry()); } for (int i = 0; i < list2.Count; i++) { Entry entry = list2[i]; Entry entry2 = collection[i]; entry2.NullValue |= entry.NullValue; foreach (TypeReference reference in entry.Types) { entry2.Types.Add(reference); } } collection.Reverse(); this._entries = new Stack<Entry>(collection); }
public void Merge(StackState other) { List <Entry> collection = new List <Entry>(this._entries); List <Entry> list2 = new List <Entry>(other.Entries); while (collection.Count < list2.Count) { collection.Add(new Entry()); } for (int i = 0; i < list2.Count; i++) { Entry entry = list2[i]; Entry entry2 = collection[i]; entry2.NullValue |= entry.NullValue; foreach (TypeReference reference in entry.Types) { entry2.Types.Add(reference); } } collection.Reverse(); this._entries = new Stack <Entry>(collection); }
private StackState Build(IEnumerable <Instruction> instructions) { StackState state = new StackState(); foreach (Instruction instruction in instructions) { this.SetupCatchBlockIfNeeded(instruction); switch (instruction.OpCode.Code) { case Code.Ldarg_0: this.LoadArg(0); break; case Code.Ldarg_1: this.LoadArg(1); break; case Code.Ldarg_2: this.LoadArg(2); break; case Code.Ldarg_3: this.LoadArg(3); break; case Code.Ldloc_0: this.LoadLocal(0); break; case Code.Ldloc_1: this.LoadLocal(1); break; case Code.Ldloc_2: this.LoadLocal(2); break; case Code.Ldloc_3: this.LoadLocal(3); break; case Code.Stloc_0: this.PopEntry(); break; case Code.Stloc_1: this.PopEntry(); break; case Code.Stloc_2: this.PopEntry(); break; case Code.Stloc_3: this.PopEntry(); break; case Code.Ldarg_S: { ParameterReference operand = (ParameterReference)instruction.Operand; int index = operand.Index; if (this._methodDefinition.HasThis) { index++; } this.LoadArg(index); break; } case Code.Ldarga_S: this.LoadArgumentAddress((ParameterReference)instruction.Operand); break; case Code.Starg_S: this.PopEntry(); break; case Code.Ldloc_S: this.LoadLocal(((VariableReference)instruction.Operand).Index); break; case Code.Ldloca_S: this.LoadLocalAddress((VariableReference)instruction.Operand); break; case Code.Stloc_S: this.PopEntry(); break; case Code.Ldnull: this.PushNullStackEntry(); break; case Code.Ldc_I4_M1: this.PushStackEntry(this.Int32TypeReference); break; case Code.Ldc_I4_0: this.PushStackEntry(this.Int32TypeReference); break; case Code.Ldc_I4_1: this.PushStackEntry(this.Int32TypeReference); break; case Code.Ldc_I4_2: this.PushStackEntry(this.Int32TypeReference); break; case Code.Ldc_I4_3: this.PushStackEntry(this.Int32TypeReference); break; case Code.Ldc_I4_4: this.PushStackEntry(this.Int32TypeReference); break; case Code.Ldc_I4_5: this.PushStackEntry(this.Int32TypeReference); break; case Code.Ldc_I4_6: this.PushStackEntry(this.Int32TypeReference); break; case Code.Ldc_I4_7: this.PushStackEntry(this.Int32TypeReference); break; case Code.Ldc_I4_8: this.PushStackEntry(this.Int32TypeReference); break; case Code.Ldc_I4_S: this.PushStackEntry(this.Int32TypeReference); break; case Code.Ldc_I4: this.PushStackEntry(this.Int32TypeReference); break; case Code.Ldc_I8: this.PushStackEntry(this.Int64TypeReference); break; case Code.Ldc_R4: this.PushStackEntry(this.SingleTypeReference); break; case Code.Ldc_R8: this.PushStackEntry(this.DoubleTypeReference); break; case Code.Dup: this._simulationStack.Push(this._simulationStack.Peek().Clone()); break; case Code.Pop: this.PopEntry(); break; case Code.Call: this.CallMethod((MethodReference)instruction.Operand); break; case Code.Calli: this.CallInternalMethod((MethodReference)instruction.Operand); break; case Code.Ret: if (this.ReturnsValue()) { this.PopEntry(); } break; case Code.Brfalse_S: this.PopEntry(); break; case Code.Brtrue_S: this.PopEntry(); break; case Code.Beq_S: this.PopEntry(); this.PopEntry(); break; case Code.Bge_S: this.PopEntry(); this.PopEntry(); break; case Code.Bgt_S: this.PopEntry(); this.PopEntry(); break; case Code.Ble_S: this.PopEntry(); this.PopEntry(); break; case Code.Blt_S: this.PopEntry(); this.PopEntry(); break; case Code.Bne_Un_S: this.PopEntry(); this.PopEntry(); break; case Code.Bge_Un_S: this.PopEntry(); this.PopEntry(); break; case Code.Bgt_Un_S: this.PopEntry(); this.PopEntry(); break; case Code.Ble_Un_S: this.PopEntry(); this.PopEntry(); break; case Code.Blt_Un_S: this.PopEntry(); this.PopEntry(); break; case Code.Brfalse: this.PopEntry(); break; case Code.Brtrue: this.PopEntry(); break; case Code.Beq: this.PopEntry(); this.PopEntry(); break; case Code.Bge: this.PopEntry(); this.PopEntry(); break; case Code.Bgt: this.PopEntry(); this.PopEntry(); break; case Code.Ble: this.PopEntry(); this.PopEntry(); break; case Code.Blt: this.PopEntry(); this.PopEntry(); break; case Code.Bne_Un: this.PopEntry(); this.PopEntry(); break; case Code.Bge_Un: this.PopEntry(); this.PopEntry(); break; case Code.Bgt_Un: this.PopEntry(); this.PopEntry(); break; case Code.Ble_Un: this.PopEntry(); this.PopEntry(); break; case Code.Blt_Un: this.PopEntry(); this.PopEntry(); break; case Code.Switch: this.PopEntry(); break; case Code.Ldind_I1: this.PopEntry(); this.PushStackEntry(this.Int32TypeReference); break; case Code.Ldind_U1: this.PopEntry(); this.PushStackEntry(this.Int32TypeReference); break; case Code.Ldind_I2: this.PopEntry(); this.PushStackEntry(this.Int32TypeReference); break; case Code.Ldind_U2: this.PopEntry(); this.PushStackEntry(this.Int32TypeReference); break; case Code.Ldind_I4: this.PopEntry(); this.PushStackEntry(this.Int32TypeReference); break; case Code.Ldind_U4: this.PopEntry(); this.PushStackEntry(this.Int32TypeReference); break; case Code.Ldind_I8: this.PopEntry(); this.PushStackEntry(this.Int64TypeReference); break; case Code.Ldind_I: { TypeReference elementType = this.PopEntry().Types.First <TypeReference>().GetElementType(); if (elementType.IsIntegralPointerType()) { this.PushStackEntry(elementType); } else { this.PushStackEntry(this.NativeIntTypeReference); } break; } case Code.Ldind_R4: this.PopEntry(); this.PushStackEntry(this.SingleTypeReference); break; case Code.Ldind_R8: this.PopEntry(); this.PushStackEntry(this.DoubleTypeReference); break; case Code.Ldind_Ref: { ByReferenceType type = (ByReferenceType)this.PopEntry().Types.First <TypeReference>(); this.PushStackEntry(type.ElementType); break; } case Code.Stind_Ref: this.PopEntry(); this.PopEntry(); break; case Code.Stind_I1: this.PopEntry(); this.PopEntry(); break; case Code.Stind_I2: this.PopEntry(); this.PopEntry(); break; case Code.Stind_I4: this.PopEntry(); this.PopEntry(); break; case Code.Stind_I8: this.PopEntry(); this.PopEntry(); break; case Code.Stind_R4: this.PopEntry(); this.PopEntry(); break; case Code.Stind_R8: this.PopEntry(); this.PopEntry(); break; case Code.Add: if (< > f__mg$cache0 == null) { < > f__mg$cache0 = new StackAnalysisUtils.ResultTypeAnalysisMethod(StackAnalysisUtils.ResultTypeForAdd); } this._simulationStack.Push(this.GetResultEntryUsing(< > f__mg$cache0)); break;