Esempio n. 1
0
 public void EmitLinearBlockStatements(StructureNode node, AbsynStatementEmitter emitter)
 {
     foreach (Statement stm in node.Instructions)
     {
         if (stm.Instruction.IsControlFlow)
             return;
         emitter.EmitStatement(stm);
     }
 }
Esempio n. 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);
                }
            }
        }
Esempio n. 3
0
        private AbsynIf EmitIfCondition(Expression exp, Conditional cond, AbsynStatementEmitter emitter)
        {
            if (cond is IfElse || cond is IfThenElse)
            {
                exp = exp.Invert();
            }
            AbsynIf ifStm = new AbsynIf();
            ifStm.Condition = exp;
            emitter.EmitStatement(ifStm);

            return ifStm;
        }