public void CreatesMultipleBasicBlocksWhenBranchingInstructionsArePresent()
		{
			// Arrange.
			var instructions = new InstructionBase[]
			{
				new NormalInstruction(),
				new NormalInstruction(),
				new BranchingInstruction { BranchType = BranchType.Conditional },
				new NormalInstruction()
			};

			// Act.
			var controlFlowGraph = ControlFlowGraph.FromInstructions(instructions);

			// Assert.
			Assert.That(controlFlowGraph.BasicBlocks, Is.Not.Null);
			Assert.That(controlFlowGraph.BasicBlocks, Has.Count.EqualTo(2));
			Assert.That(controlFlowGraph.BasicBlocks[0].Position, Is.EqualTo(0));
			Assert.That(controlFlowGraph.BasicBlocks[0].Instructions, Has.Count.EqualTo(3));
			Assert.That(controlFlowGraph.BasicBlocks[0].Successors, Has.Count.EqualTo(1));
			Assert.That(controlFlowGraph.BasicBlocks[0].Successors[0], Is.EqualTo(controlFlowGraph.BasicBlocks[1]));
			Assert.That(controlFlowGraph.BasicBlocks[1].Position, Is.EqualTo(1));
			Assert.That(controlFlowGraph.BasicBlocks[1].Instructions, Has.Count.EqualTo(1));
			Assert.That(controlFlowGraph.BasicBlocks[1].Successors, Is.Empty);
		}
		private static void AssertBranchingInstruction(
			InstructionBase instruction, 
			InstructionBase branchTarget,
			BranchType branchType)
		{
			Assert.That(instruction, Is.InstanceOf<BranchingInstruction>());
			Assert.That(((BranchingInstruction) instruction).BranchTarget, Is.EqualTo(branchTarget));
			Assert.That(((BranchingInstruction) instruction).BranchType, Is.EqualTo(branchType));
		}
		private static int GetInstructionIndex(IList<InstructionBase> instructions, InstructionBase instruction)
		{
			return instructions.IndexOf(instruction);
		}
Пример #4
0
		public virtual bool BranchesTo(InstructionBase otherInstruction)
		{
			return false;
		}
Пример #5
0
 public virtual bool BranchesTo(InstructionBase otherInstruction)
 {
     return(false);
 }