Esempio n. 1
0
        private bool WriteCode(BasicBlock previous, BasicBlock block, List<CodeStatement> stmts, Context context)
        {
            if (block == context.LoopFollow) {
                AddStatement(stmts, new CodeBreakStatement());
                return true;
            }

            if (block == context.LoopHeader && (previous == null || !previous.IsLoopLatch)) {
                AddStatement(stmts, new CodeContinueStatement());
                return true;
            }

            if (context.IsUntil(block) ||
                block.DfsTraversed == DfsTraversal.Alpha) {
                return false;
            }

            if (block.IsTryHeader && context.Try != block.Try) {
                return WriteTry(block, stmts, context);
            }

            block.DfsTraversed = DfsTraversal.Alpha;

            if (block.IsLoopHeader) {
                return WriteLoop(block, stmts, context);
            }
            else if (block.IsMultiWay) {
                return WriteSwitch(block, stmts, context);
            }
            else if (block.Conditional != null) {
                return WriteIf(block, block.Conditional, stmts, context);
            }
            else {
                var isReturn = WriteBasicBlock(block, stmts);
                if (isReturn)
                    return true;

                var succ = (BasicBlock)block.Successors.FirstOrDefault();
                return WriteCode(block, succ, stmts, context);
            }
        }