/// <summary>
 /// Creates and pushes empty node to the end of the tac container
 /// </summary>
 public static void AddEmptyNode(ThreeAddressCode tacContainer, string label = null)
 {
     tacContainer.PushNode(new TacEmptyNode()
     {
         Label = label
     });
 }
 /// <summary>
 /// Creates and pushes goto node to the end of the tac container
 /// </summary>
 public static void AddGotoNode(ThreeAddressCode tacContainer,
                                string label, string targetLabel)
 {
     tacContainer.PushNode(new TacGotoNode
     {
         Label       = label,
         TargetLabel = targetLabel
     });
 }
 /// <summary>
 /// Creates and pushes if-goto node to the end of the tac container
 /// </summary>
 public static void AddIfGotoNode(ThreeAddressCode tacContainer,
                                  string label, string targetLabel, string condition)
 {
     tacContainer.PushNode(new TacIfGotoNode
     {
         Label       = label,
         Condition   = condition,
         TargetLabel = targetLabel
     });
 }
 /// <summary>
 /// Creates and pushes assignment node to the end of the tac container
 /// </summary>
 public static void AddAssignmentNode(ThreeAddressCode tacContainer, string label,
                                      string id, string firstOp, string op = null, string secondOp = null)
 {
     tacContainer.PushNode(new TacAssignmentNode
     {
         Label = label,
         LeftPartIdentifier = id,
         FirstOperand       = firstOp,
         Operation          = op,
         SecondOperand      = secondOp
     });
 }
        public void Calculate_NotEmpyInAndOut()
        {
            var bblock_1 = new ThreeAddressCode();

            bblock_1.PushNode(new TacAssignmentNode
            {
                LeftPartIdentifier = "i",
                FirstOperand       = "m",
                Operation          = "-",
                SecondOperand      = "1"
            });
            bblock_1.PushNode(new TacAssignmentNode
            {
                LeftPartIdentifier = "j",
                FirstOperand       = "n",
            });
            bblock_1.PushNode(new TacAssignmentNode
            {
                LeftPartIdentifier = "a",
                FirstOperand       = "u1"
            });

            var bblock_2 = new ThreeAddressCode();

            bblock_2.PushNode(new TacAssignmentNode
            {
                LeftPartIdentifier = "i",
                FirstOperand       = "i",
                Operation          = "+",
                SecondOperand      = "1"
            });
            bblock_2.PushNode(new TacAssignmentNode
            {
                LeftPartIdentifier = "j",
                FirstOperand       = "j",
                Operation          = "-",
                SecondOperand      = "1"
            });

            var bblock_3 = new ThreeAddressCode();

            bblock_3.PushNode(new TacAssignmentNode
            {
                LeftPartIdentifier = "a",
                FirstOperand       = "u2",
            });

            var bblock_4 = new ThreeAddressCode();

            bblock_4.PushNode(new TacAssignmentNode
            {
                LeftPartIdentifier = "i",
                FirstOperand       = "u3",
            });

            var basicBlocks = new BasicBlocks
            {
                BasicBlockItems = new List <ThreeAddressCode> {
                    bblock_1, bblock_2, bblock_3, bblock_4
                }
            };

            var genKillVisitor = new GenKillVisitor();
            var genKill        = genKillVisitor.GenerateReachingDefinitionForBlocks(basicBlocks);

            var expected = new HashSet <TacNode>
            {
                bblock_1.TACodeLines.First.Next.Next.Value,
                bblock_2.TACodeLines.First.Value,
                bblock_2.TACodeLines.First.Next.Value
            };

            var _in = new HashSet <TacNode>();

            foreach (var line in bblock_1)
            {
                _in.Add(line);
            }

            var tfFunction = new TFByComposition(genKill);
            var output     = tfFunction.Calculate(_in, bblock_2);

            Assert.IsTrue(expected.SetEquals(output));
        }
        public void Calculate_EmptyIn()
        {
            var bblock_1 = new ThreeAddressCode();

            bblock_1.PushNode(new TacAssignmentNode
            {
                LeftPartIdentifier = "i",
                FirstOperand       = "m",
                Operation          = "-",
                SecondOperand      = "1"
            });
            bblock_1.PushNode(new TacAssignmentNode
            {
                LeftPartIdentifier = "j",
                FirstOperand       = "n",
            });
            bblock_1.PushNode(new TacAssignmentNode
            {
                LeftPartIdentifier = "a",
                FirstOperand       = "u1"
            });

            var bblock_2 = new ThreeAddressCode();

            bblock_2.PushNode(new TacAssignmentNode
            {
                LeftPartIdentifier = "i",
                FirstOperand       = "i",
                Operation          = "+",
                SecondOperand      = "1"
            });
            bblock_2.PushNode(new TacAssignmentNode
            {
                LeftPartIdentifier = "j",
                FirstOperand       = "j",
                Operation          = "-",
                SecondOperand      = "1"
            });

            var bblock_3 = new ThreeAddressCode();

            bblock_3.PushNode(new TacAssignmentNode
            {
                LeftPartIdentifier = "a",
                FirstOperand       = "u2",
            });

            var bblock_4 = new ThreeAddressCode();

            bblock_4.PushNode(new TacAssignmentNode
            {
                LeftPartIdentifier = "i",
                FirstOperand       = "u3",
            });

            var basicBlocks = new BasicBlocks
            {
                BasicBlockItems = new List <ThreeAddressCode> {
                    bblock_1, bblock_2, bblock_3, bblock_4
                }
            };

            var genKillVisitor = new GenKillVisitor();
            var genKill        = genKillVisitor.GenerateReachingDefinitionForBlocks(basicBlocks);

            var tfFunction = new TFByComposition(genKill);
            var output     = tfFunction.Calculate(new HashSet <TacNode>(), basicBlocks.BasicBlockItems[0]);
            var expected   = new HashSet <TacNode>();

            foreach (var item in bblock_1)
            {
                expected.Add(item);
            }

            Assert.IsTrue(expected.SetEquals(output));
        }
Пример #7
0
 /// <summary>
 /// Creates and pushes empty node to the end of the tac container
 /// </summary>
 public static void AddEmptyNode(ThreeAddressCode tacContainer)
 {
     tacContainer.PushNode(new TacEmptyNode());
 }