PageRenderTime 25ms CodeModel.GetById 15ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/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
19using System;
20using System.Collections.Generic;
21using System.IO;
22
23namespace ICSharpCode.Decompiler.FlowAnalysis
24{
25	/// <summary>
26	/// A block in a control flow graph; with instructions represented by "SsaInstructions" (instructions use variables, no evaluation stack).
27	/// Usually these variables are in SSA form to make analysis easier.
28	/// </summary>
29	public sealed class SsaBlock
30	{
31		public readonly List<SsaBlock> Successors = new List<SsaBlock>();
32		public readonly List<SsaBlock> Predecessors = new List<SsaBlock>();
33		public readonly ControlFlowNodeType NodeType;
34		public readonly List<SsaInstruction> Instructions = new List<SsaInstruction>();
35		
36		/// <summary>
37		/// The block index in the control flow graph.
38		/// This correspons to the node index in ControlFlowGraph.Nodes, so it can be used to retrieve the original CFG node and look
39		/// up additional information (e.g. dominance).
40		/// </summary>
41		public readonly int BlockIndex;
42		
43		internal SsaBlock(ControlFlowNode node)
44		{
45			this.NodeType = node.NodeType;
46			this.BlockIndex = node.BlockIndex;
47		}
48		
49		public override string ToString()
50		{
51			StringWriter writer = new StringWriter();
52			writer.Write("Block #{0} ({1})", BlockIndex, NodeType);
53			foreach (SsaInstruction inst in Instructions) {
54				writer.WriteLine();
55				inst.WriteTo(writer);
56			}
57			return writer.ToString();
58		}
59	}
60}