示例#1
0
        protected override void GenerateCodeInner(AbsynCodeGenerator codeGen, StructureNode node, AbsynStatementEmitter emitter)
        {
            List <AbsynStatement> loopBody    = new List <AbsynStatement>();
            AbsynStatementEmitter bodyEmitter = new AbsynStatementEmitter(loopBody);

            if (node.IsLatchNode())
            {
                codeGen.EmitLinearBlockStatements(node, bodyEmitter);
            }
            else
            {
                if (node.Conditional != null)
                {
                    node.Conditional.GenerateCode(codeGen, node, Latch, bodyEmitter);
                }
                else
                {
                    codeGen.EmitLinearBlockStatements(node, bodyEmitter);
                    if (node.OutEdges.Count != 1)
                    {
                        throw new NotSupportedException(string.Format("Expected top of PostTestedLoop {0} to have only 1 out edge, but found {1} out edges.", node.Name, node.OutEdges.Count));
                    }
                    codeGen.GenerateCode(node.OutEdges[0], Latch, bodyEmitter);
                }
            }
            emitter.EmitDoWhile(loopBody, codeGen.BranchCondition(Latch));
        }
示例#2
0
        public void GenerateCode(
            StructureNode node,
            StructureNode latchNode,
            AbsynStatementEmitter emitter)
        {
            if (followStack.Contains(node) && followStack.Peek() == node)
            {
                return;
            }
            if (IsVisited(node))
            {
                return;
            }
            visited.Add(node);

            if (NeedsLabel(node))
            {
                GenerateLabel(node, emitter);
            }

            if (node.IsLoopHeader())
            {
                node.Loop.GenerateCode(this, node, latchNode, emitter);
            }
            else if (node.Conditional != null)
            {
                node.Conditional.GenerateCode(this, node, latchNode, emitter);
            }
            else
            {
                EmitLinearBlockStatements(node, emitter);
                if (EndsWithReturnInstruction(node))
                {
                    emitter.EmitStatement(node.Instructions.Last);
                    return;
                }
                if (node.IsLatchNode())
                {
                    return;
                }

                if (node.OutEdges.Count == 1)
                {
                    StructureNode succ = node.OutEdges[0];
                    if (ShouldJumpFromSequentialNode(node, succ))
                    {
                        EmitGotoAndForceLabel(node, succ, emitter);
                    }
                    else
                    {
                        GenerateCode(succ, latchNode, emitter);
                    }
                }
            }
        }