public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { ILRange.WriteTo(output, options); if (options.UseLogicOperationSugar) { if (MatchLogicAnd(out var lhs, out var rhs)) { output.Write("logic.and("); lhs.WriteTo(output, options); output.Write(", "); rhs.WriteTo(output, options); output.Write(')'); return; } if (MatchLogicOr(out lhs, out rhs)) { output.Write("logic.or("); lhs.WriteTo(output, options); output.Write(", "); rhs.WriteTo(output, options); output.Write(')'); return; } } output.Write(OpCode); output.Write(" ("); condition.WriteTo(output, options); output.Write(") "); trueInst.WriteTo(output, options); if (falseInst.OpCode != OpCode.Nop) { output.Write(" else "); falseInst.WriteTo(output, options); } }
public BreakpointBookmark(MemberReference member, AstLocation location, ILRange range, BreakpointAction action, DecompiledLanguages language) : base(member, location) { this.action = action; this.ILRange = range; this.Tooltip = string.Format("Language:{0}, Line:{1}, IL range:{2}-{3}", language.ToString(), location.Line, range.From, range.To); this.Language = language; }
public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { ILRange.WriteTo(output, options); output.Write(OpCode); output.Write(' '); output.WriteLocalReference(TargetLabel, (object)targetBlock ?? TargetILOffset); }
/// <summary> /// Retrieves the array that contains the IL range and the missing gaps between ranges. /// </summary> /// <returns>The array representation of the step aranges.</returns> public int[] ToArray(bool isMatch) { var currentList = new List <ILRange>(); // add list for the current source code line currentList.AddRange(ILRange.OrderAndJoint(MemberMapping.MemberCodeMappings .FindAll(m => m.SourceCodeLine == this.SourceCodeLine) .ConvertAll <ILRange>(m => m.ILInstructionOffset))); if (!isMatch) { // add inverted currentList.AddRange(MemberMapping.InvertedList); } else { // if the current list contains the last mapping, add also the last gap var lastInverted = MemberMapping.InvertedList.LastOrDefault(); if (lastInverted != null && lastInverted.From == currentList[currentList.Count - 1].To) { currentList.Add(lastInverted); } } // set the output var resultList = new List <int>(); foreach (var element in ILRange.OrderAndJoint(currentList)) { resultList.Add(element.From); resultList.Add(element.To); } return(resultList.ToArray()); }
public void DebugEnd(AstNode node) { var state = debugStack.Pop(); if (currentMemberMapping != null) { foreach (var range in ILRange.OrderAndJoin(GetILRanges(state))) { currentMemberMapping.MemberCodeMappings.Add( new SourceCodeMapping { ILInstructionOffset = range, StartLocation = state.StartLocation, EndLocation = output.Location, MemberMapping = currentMemberMapping }); } } else if (multiMappings != null) { foreach (var mm in multiMappings) { foreach (var range in ILRange.OrderAndJoin(mm.Item2)) { mm.Item1.MemberCodeMappings.Add( new SourceCodeMapping { ILInstructionOffset = range, StartLocation = state.StartLocation, EndLocation = output.Location, MemberMapping = mm.Item1 }); } } } }
public BreakpointBookmark(IMemberRef member, TextLocation location, int functionToken, ILRange range, BreakpointAction action) : base(member, location) { this.action = action; this.FunctionToken = functionToken; this.ILRange = range; this.Tooltip = string.Format("Line:{0}, IL range:{1}-{2}", location.Line, range.From, range.To); }
public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { ILRange.WriteTo(output, options); output.Write(".try "); TryBlock.WriteTo(output, options); output.Write(" fault "); faultBlock.WriteTo(output, options); }
public static ILExpression WithILRangesAndJoin(this ILExpression expr, IEnumerable <ILRange> ilranges1, IEnumerable <ILRange> ilranges2) { expr.WithILRanges(ilranges1, ilranges2); if (ilranges1 != null || ilranges2 != null) { ILRange.OrderAndJoin(expr.ILRanges); } return(expr); }
LocalVariable(IMethod method, int index, IType type, string name, ILRange[] ilranges, Getter getter) { this.Method = method; this.Index = index; this.Type = type; this.Name = name; this.ILRanges = ilranges; this.getter = getter; }
public BreakpointBookmark(IMemberRef member, TextLocation location, TextLocation endLocation, ILRange range, bool isEnabled = true) : base(member, range.From, location, endLocation) { var key = MethodKey.Create(member); Debug.Assert(key != null, "Caller must verify that MethodKey.Create() won't fail"); this.MethodKey = key.Value; this.ILRange = range; this.isEnabled = isEnabled; }
public static ILExpression WithILRangesAndJoin(this ILExpression expr, IEnumerable <ILRange> ilranges) { if (ilranges != null) { expr.ILRanges.AddRange(ilranges); ILRange.OrderAndJoin(expr.ILRanges); } return(expr); }
public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { ILRange.WriteTo(output, options); output.Write(OpCode); output.Write('.'); output.Write(resultType); output.Write('('); this.array.WriteTo(output, options); output.Write(')'); }
public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { ILRange.WriteTo(output, options); output.Write(OpCode); output.Write("("); valueInst.WriteTo(output, options); output.Write(", "); fallbackInst.WriteTo(output, options); output.Write(")"); }
public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { ILRange.WriteTo(output, options); output.Write(OpCode); if (!string.IsNullOrEmpty(Message)) { output.Write("(\""); output.Write(Message); output.Write("\")"); } }
public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { ILRange.WriteTo(output, options); output.Write(".try "); TryBlock.WriteTo(output, options); foreach (var handler in Handlers) { output.Write(' '); handler.WriteTo(output, options); } }
public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { ILRange.WriteTo(output, options); output.Write("lock ("); OnExpression.WriteTo(output, options); output.WriteLine(") {"); output.Indent(); Body.WriteTo(output, options); output.Unindent(); output.WriteLine(); output.Write("}"); }
public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { ILRange.WriteTo(output, options); output.Write(OpCode); if (IsLifted) { output.Write(".lifted"); } output.Write('('); this.Argument.WriteTo(output, options); output.Write(')'); }
public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { ILRange.WriteTo(output, options); output.Write(OpCode); if (Kind != NopKind.Normal) { output.Write("." + Kind.ToString().ToLowerInvariant()); } if (!string.IsNullOrEmpty(Comment)) { output.Write(" // " + Comment); } }
public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { ILRange.WriteTo(output, options); output.Write(OpCode); if (targetContainer != null) { output.Write(' '); output.WriteReference(TargetLabel, targetContainer, isLocal: true); output.Write(" ("); value.WriteTo(output, options); output.Write(')'); } }
public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { ILRange.WriteTo(output, options); output.Write(OpCode); if (IsChecked) { output.Write(".checked"); } output.Write(' '); type.WriteTo(output); output.Write('('); Argument.WriteTo(output, options); output.Write(')'); }
/// <summary> /// Subarray from this array /// </summary> /// <param name="range"> strings specifying the ranges to create subarray from</param> /// <returns>subarray as specified</returns> public override ILBaseArray <BaseT> Subarray(params string [] range) { if (range == null) { return(ShiftDimensions(0)); } ILRange rng = new ILRange(m_dimensions, RangeSide.Right, range); if (rng.NumberOfElements == 0) { return(ILArray <BaseT> .empty(0, 0)); } return(CreatePhysicalSubarrayFromPhysical(rng)); }
public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { ILRange.WriteTo(output, options); output.Write("using ("); Variable.WriteTo(output); output.Write(" = "); ResourceExpression.WriteTo(output, options); output.WriteLine(") {"); output.Indent(); Body.WriteTo(output, options); output.Unindent(); output.WriteLine(); output.Write("}"); }
public static AstNode CreateHidden(IEnumerable <ILRange> ilRanges, AstNode stmt) { var list = ILRange.OrderAndJoin(ilRanges); if (list.Count == 0) { return(stmt); } if (stmt == null) { stmt = new EmptyStatement(); } stmt.AddAnnotation(list); return(stmt); }
public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { ILRange.WriteTo(output, options); output.Write("string.to.int ("); Argument.WriteTo(output, options); output.Write(", { "); for (int i = 0; i < Map.Length; i++) { if (i > 0) { output.Write(", "); } output.Write($"[{i}] = \"{Map[i]}\""); } output.Write(" })"); }
public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { ILRange.WriteTo(output, options); output.Write("catch "); if (variable != null) { output.WriteLocalReference(variable.Name, variable, isDefinition: true); output.Write(" : "); Disassembler.DisassemblerHelpers.WriteOperand(output, variable.Type); } output.Write(" when ("); filter.WriteTo(output, options); output.Write(')'); output.Write(' '); body.WriteTo(output, options); }
public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { ILRange.WriteTo(output, options); output.Write(OpCode); output.Write("." + Operation.ToString().ToLower()); DynamicInstruction.WriteBinderFlags(BinderFlags, output, options); if (CompoundAssignmentType == CompoundAssignmentType.EvaluatesToNewValue) { output.Write(".new"); } else { output.Write(".old"); } output.Write(' '); DynamicInstruction.WriteArgumentList(output, options, (Target, TargetArgumentInfo), (Value, ValueArgumentInfo)); }
/// <summary> /// Subarray from this ILArray + dimension shift /// </summary> /// <param name="range"> arrays specifying the ranges to create subarray from</param> /// <param name="shift"> Number of dimensions to shift the result.</param> /// <returns>shifted subarray as specified</returns> public override ILBaseArray <BaseT> Subarray(int shift, ILBaseArray[] range) { if (shift == 0) { return(Subarray(range)); } if (range.Length == 0) { return(ILArray <BaseT> .empty(0, 0)); } else if (range.Length == 1) { #region sequential indices access if (range[0] is ILArray <double> ) { return(CreatePhysicalSubarrayFromPhysicalSequentialShifted((ILArray <double>)range[0], shift)); } else if (range[0] is ILLogicalArray) { return(CreatePhysicalSubarrayFromPhysicalSequentialShifted(ILNumerics.BuiltInFunctions.ILMath.find((ILLogicalArray)range[0]), shift)); } else if (range[0] is ILArray <complex> ) { return(CreatePhysicalSubarrayFromPhysicalSequentialShifted((ILArray <complex>)range[0], shift)); } else if (range[0] is ILArray <byte> ) { return(CreatePhysicalSubarrayFromPhysicalSequentialShifted((ILArray <byte>)range[0], shift)); } else { throw new ILArgumentException("specified type of indices array is not supported for sequential addressing!"); } #endregion sequential index access } else { ILRange rng = new ILRange(m_dimensions, RangeSide.Right, range); if (rng.NumberOfElements == 0) { return(ILArray <BaseT> .empty(0, 0)); } return(CreatePhysicalSubarrayFromPhysicalShifted((short)shift, rng)); } }
public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { ILRange.WriteTo(output, options); output.Write(OpCode); if (CompoundAssignmentType == CompoundAssignmentType.EvaluatesToNewValue) { output.Write(".new"); } else { output.Write(".old"); } output.Write(' '); Method.WriteTo(output); output.Write('('); this.Target.WriteTo(output, options); output.Write(", "); this.Value.WriteTo(output, options); output.Write(')'); }
public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { ILRange.WriteTo(output, options); if (options.UseLogicOperationSugar && MatchLogicNot(out var arg)) { output.Write("logic.not("); arg.WriteTo(output, options); output.Write(')'); return; } output.Write(OpCode); output.Write('.'); output.Write(InputType.ToString().ToLower()); switch (Sign) { case Sign.Signed: output.Write(".signed"); break; case Sign.Unsigned: output.Write(".unsigned"); break; } switch (LiftingKind) { case ComparisonLiftingKind.CSharp: output.Write(".lifted[C#]"); break; case ComparisonLiftingKind.ThreeValuedLogic: output.Write(".lifted[3VL]"); break; } output.Write('('); Left.WriteTo(output, options); output.Write(' '); output.Write(Kind.GetToken()); output.Write(' '); Right.WriteTo(output, options); output.Write(')'); }
/// <summary> /// Subarray from this array /// </summary> /// <param name="range">Strings specifying the ranges to create subarray from</param> /// <returns>subarray as specified</returns> public ILBaseArray <BaseT> SubarrayPython(params object[] range) { if (range is ILBaseArray[]) { return(Subarray(range as ILBaseArray[])); } if (range == null) { return(ShiftDimensions(0)); } ILRange rng = new ILRange(m_dimensions, RangeSide.Right, range); if (rng.NumberOfElements == 0) { return(ILArray <BaseT> .empty(0, 0)); } if (rng.nonSingletonDimensions >= MinimumRefDimensions) { // create reference if (IsReference) { return(CreateReferenceSubarrayFromReference(rng)); } else { return(CreateReferenceSubarrayFromPhysical(rng)); } } else { // create physical if (IsReference) { return(CreatePhysicalSubarrayFromReference(rng)); } else { return(CreatePhysicalSubarrayFromPhysical(rng)); } } }
public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { ILRange.WriteTo(output, options); output.Write("Block "); output.WriteLocalReference(Label, this, isDefinition: true); if (Kind != BlockKind.ControlFlow) { output.Write($" ({Kind})"); } if (Parent is BlockContainer) { output.Write(" (incoming: {0})", IncomingEdgeCount); } output.Write(' '); output.MarkFoldStart("{...}"); output.WriteLine("{"); output.Indent(); int index = 0; foreach (var inst in Instructions) { if (options.ShowChildIndexInBlock) { output.Write("[" + index + "] "); index++; } inst.WriteTo(output, options); output.WriteLine(); } if (finalInstruction.OpCode != OpCode.Nop) { output.Write("final: "); finalInstruction.WriteTo(output, options); output.WriteLine(); } output.Unindent(); output.Write("}"); output.MarkFoldEnd(); }
public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { ILRange.WriteTo(output, options); output.WriteDefinition("case", this, isLocal: true); output.Write(' '); if (HasNullLabel) { output.Write("null"); if (!Labels.IsEmpty) { output.Write(", "); output.Write(Labels.ToString()); } } else { output.Write(Labels.ToString()); } output.Write(": "); body.WriteTo(output, options); }
public override void DebugEnd(AstNode node, TextPosition?end) { var state = debugStack.Pop(); if (currentMemberMapping != null) { foreach (var range in ILRange.OrderAndJoin(GetILRanges(state))) { currentMemberMapping.MemberCodeMappings.Add(new SourceCodeMapping(range, state.StartLocation, end ?? output.Location, currentMemberMapping)); } } else if (multiMappings != null) { foreach (var mm in multiMappings) { foreach (var range in ILRange.OrderAndJoin(mm.Item2)) { mm.Item1.MemberCodeMappings.Add(new SourceCodeMapping(range, state.StartLocation, end ?? output.Location, mm.Item1)); } } } }
public override void WriteTo(ITextOutput output, ILAstWritingOptions options) { ILRange.WriteTo(output, options); output.Write("switch"); if (IsLifted) { output.Write(".lifted"); } output.Write(" ("); value.WriteTo(output, options); output.Write(") "); output.MarkFoldStart("{...}"); output.WriteLine("{"); output.Indent(); foreach (var section in this.Sections) { section.WriteTo(output, options); output.WriteLine(); } output.Unindent(); output.Write('}'); output.MarkFoldEnd(); }
public static void ToggleBreakpointAt(IMemberRef member, int lineNumber, int functionToken, ILRange range) { BookmarkManager.ToggleBookmark( member.FullName, lineNumber, b => b.CanToggle && b is BreakpointBookmark, location => new BreakpointBookmark(member, location, functionToken, range, BreakpointAction.Break)); }
public SourceCodeMapping(ILRange ilRange, TextPosition start, TextPosition end, MemberMapping mapping) { this.ilRange = ilRange; this.startPos = start; this.endPos = end; this.memberMapping = mapping; }
public static void ToggleBreakpointAt(MemberReference member, int lineNumber, int functionToken, ILRange range, DecompiledLanguages language) { BookmarkManager.ToggleBookmark( member.FullName, lineNumber, b => b.CanToggle && b is BreakpointBookmark, location => new BreakpointBookmark(member, location, functionToken, range, BreakpointAction.Break, language)); }
// Parses the ILRange and return all delegate pointers that could end up on the stack as a result of executing that code. private List<MethodDefinition> GetDelegatePointers (List<List<MethodDefinition>> locals, ILRange range) { List<MethodDefinition> result = null; MethodReference ldftn; MethodDefinition ldftn_definition; // Check if the code does any ldftn. if (range.First != range.Last && range.Last.OpCode.Code == Code.Newobj && range.Last.Previous.OpCode.Code == Code.Ldftn) { ldftn = range.Last.Previous.Operand as MethodReference; if (ldftn != null) { ldftn_definition = ldftn.Resolve (); if (ldftn_definition != null) { if (result == null) result = new List<MethodDefinition> (); result.Add (ldftn_definition); } } } // Check if the code loads any local variables which can be delegates. if (locals != null && range.Last.IsLoadLocal ()) { int index = range.Last.GetLoadIndex (); if (locals.Count > index) { List<MethodDefinition> pointers = locals [index]; if (pointers != null && pointers.Count != 0) { if (result == null) result = new List<MethodDefinition> (); result.AddRange (pointers); } } } // If the last opcode is a field load, check if any pointers have been stored in that field. if (stored_fields.Count > 0 && range.Last.OpCode.Code == Code.Ldfld || range.Last.OpCode.Code == Code.Ldsfld) { FieldReference field = range.Last.Operand as FieldReference; FieldDefinition field_definition; List<MethodDefinition> pointers; if (field != null) { field_definition = (range.Last.Operand as FieldReference).Resolve (); if (field_definition != null && stored_fields.TryGetValue (field_definition, out pointers)) { if (result == null) result = new List<MethodDefinition> (); result.AddRange (pointers); } } } return result; }
static void AddCapturedLocalVariables(List<LocalVariable> vars, IMethod method, ILRange[] ilranges, ValueGetter getCaptureClass, IType captureClassType) { if (captureClassType.IsDisplayClass()) { foreach(IField fieldInfo in captureClassType.GetFields()) { IField fieldInfoCopy = fieldInfo; if (fieldInfo.Name.StartsWith("CS$")) continue; // Ignore LocalVariable locVar = new LocalVariable( method, -1, fieldInfo.Type, fieldInfo.Name, ilranges, // TODO: Use eval thread context => getCaptureClass(context).GetFieldValue(context.Thread, fieldInfoCopy) ); locVar.IsCaptured = true; if (locVar.Name.StartsWith("<>")) { if (locVar.Name.EndsWith("__this")) { locVar.Name = "this"; locVar.IsThis = true; } else { continue; // Ignore } } if (locVar.Name.StartsWith("<")) { int endIndex = locVar.Name.IndexOf('>'); if (endIndex == -1) continue; // Ignore locVar.Name = fieldInfo.Name.Substring(1, endIndex - 1); } vars.Add(locVar); } } }