/ICSharpCode.Decompiler/FlowAnalysis/SsaBlock.cs

http://github.com/icsharpcode/ILSpy · C# · 60 lines · 29 code · 5 blank · 26 comment · 0 complexity · db43457b3215519b619b20b58d7107f4 MD5 · raw file

  1. // Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team
  2. //
  3. // Permission is hereby granted, free of charge, to any person obtaining a copy of this
  4. // software and associated documentation files (the "Software"), to deal in the Software
  5. // without restriction, including without limitation the rights to use, copy, modify, merge,
  6. // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
  7. // to whom the Software is furnished to do so, subject to the following conditions:
  8. //
  9. // The above copyright notice and this permission notice shall be included in all copies or
  10. // substantial portions of the Software.
  11. //
  12. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  13. // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  14. // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
  15. // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  16. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  17. // DEALINGS IN THE SOFTWARE.
  18. using System;
  19. using System.Collections.Generic;
  20. using System.IO;
  21. namespace ICSharpCode.Decompiler.FlowAnalysis
  22. {
  23. /// <summary>
  24. /// A block in a control flow graph; with instructions represented by "SsaInstructions" (instructions use variables, no evaluation stack).
  25. /// Usually these variables are in SSA form to make analysis easier.
  26. /// </summary>
  27. public sealed class SsaBlock
  28. {
  29. public readonly List<SsaBlock> Successors = new List<SsaBlock>();
  30. public readonly List<SsaBlock> Predecessors = new List<SsaBlock>();
  31. public readonly ControlFlowNodeType NodeType;
  32. public readonly List<SsaInstruction> Instructions = new List<SsaInstruction>();
  33. /// <summary>
  34. /// The block index in the control flow graph.
  35. /// This correspons to the node index in ControlFlowGraph.Nodes, so it can be used to retrieve the original CFG node and look
  36. /// up additional information (e.g. dominance).
  37. /// </summary>
  38. public readonly int BlockIndex;
  39. internal SsaBlock(ControlFlowNode node)
  40. {
  41. this.NodeType = node.NodeType;
  42. this.BlockIndex = node.BlockIndex;
  43. }
  44. public override string ToString()
  45. {
  46. StringWriter writer = new StringWriter();
  47. writer.Write("Block #{0} ({1})", BlockIndex, NodeType);
  48. foreach (SsaInstruction inst in Instructions) {
  49. writer.WriteLine();
  50. inst.WriteTo(writer);
  51. }
  52. return writer.ToString();
  53. }
  54. }
  55. }