示例#1
0
        public static Context CreateNewBlock(this InstructionSet instructionSet, BasicBlocks basicBlocks)
        {
            Context ctx = new Context(instructionSet);

            ctx.AppendInstruction(IRInstruction.BlockStart);
            int start = ctx.Index;
            ctx.AppendInstruction(IRInstruction.BlockEnd);
            int last = ctx.Index;

            BasicBlock block = basicBlocks.CreateBlockWithAutoLabel(start, last);
            ctx.BasicBlock = block;

            ctx.GotoPrevious();

            return ctx;
        }
示例#2
0
        /// <summary>
        /// Splits the block.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <returns></returns>
        private Context Split(Context ctx, BasicBlocks basicBlocks, InstructionSet instructionSet)
        {
            Context current = ctx.Clone();

            Context next = ctx.Clone();
            next.AppendInstruction(IRInstruction.BlockStart);
            BasicBlock nextBlock = basicBlocks.CreateBlockWithAutoLabel(next.Index, current.BasicBlock.EndIndex);
            Context nextContext = new Context(instructionSet, nextBlock);

            foreach (BasicBlock block in current.BasicBlock.NextBlocks)
            {
                nextBlock.NextBlocks.Add(block);
                block.PreviousBlocks.Remove(current.BasicBlock);
                block.PreviousBlocks.Add(nextBlock);
            }

            current.BasicBlock.NextBlocks.Clear();

            current.AppendInstruction(IRInstruction.BlockEnd);
            current.BasicBlock.EndIndex = current.Index;

            return nextContext;
        }