/// <summary>
        /// Runs the specified method compiler.
        /// </summary>
        void IMethodCompilerStage.Run()
        {
            if (methodCompiler.PlugSystem != null)
                if (methodCompiler.PlugSystem.GetPlugMethod(methodCompiler.Method) != null)
                    return;

            traversed = new BitArray(basicBlocks.Count);
            analyzed = new BitArray(basicBlocks.Count);

            RegisterBitmap start = new RegisterBitmap();

            // Main Code
            start.Set(architecture.StackFrameRegister);
            start.Set(architecture.StackPointerRegister);
            start.Set(architecture.CallingConvention.CalleeSavedRegisters);

            ProcesBlockChain(basicBlocks.PrologueBlock, start);

            // Handler Code
            foreach (ExceptionHandlingClause clause in methodCompiler.ExceptionClauseHeader.Clauses)
            {
                RegisterBitmap exceptionStart = new RegisterBitmap();
                start.Set(architecture.StackFrameRegister);
                start.Set(architecture.StackPointerRegister);

                // TODO: Set the exception register

                ProcesBlockChain(basicBlocks.GetByLabel(clause.HandlerOffset), exceptionStart);
            }
        }
        protected void AnalyzeBlock(BasicBlock block)
        {
            if (analyzed.Get(block.Sequence))
                return;

            //Debug.WriteLine(String.Format("Analyzing Block #{0} - Label L_{1:X4}", block.Index, block.Label));

            traversed.Set(block.Sequence, true);

            // Analysis all child blocks first
            foreach (BasicBlock nextBlock in block.NextBlocks)
            {
                if (!traversed.Get(nextBlock.Sequence))
                    AnalyzeBlock(nextBlock);
            }

            //Debug.WriteLine(String.Format("Working Block #{0} - Label L_{1:X4}", block.Index, block.Label));

            RegisterBitmap used = new RegisterBitmap();

            if (block.NextBlocks.Count == 0)
            {
                if (block.Label == Int32.MaxValue)
                {
                    used.Set(architecture.StackFrameRegister);
                    used.Set(architecture.StackPointerRegister);

                    used.Set(architecture.CallingConvention.GetReturnRegisters(methodCompiler.Method.Signature.ReturnType.Type));
                    used.Set(architecture.CallingConvention.CalleeSavedRegisters);
                }
            }
            else
            {
                foreach (BasicBlock nextBlock in block.NextBlocks)
                    used.Or(top[nextBlock.Sequence]);
            }

            bottom[block.Sequence] = used;

            var ctx = new Context(instructionSet, block);
            ctx.GotoLast();

            for (; ; ctx.GotoPrevious())
            {
                if (ctx.Ignore || ctx.Instruction == null)
                    if (ctx.IsFirstInstruction)
                        break;
                    else
                        continue;

                RegisterBitmap inputRegisters = new RegisterBitmap();
                RegisterBitmap outputRegisters = new RegisterBitmap();

                GetRegisterUsage(ctx, ref inputRegisters, ref outputRegisters);

                RegisterBitmap assignment = inputRegisters;
                assignment.Xor(outputRegisters);
                assignment.Not();

                used.And(assignment);

                used.Or(inputRegisters);

                usage[ctx.Index] = used;

                if (ctx.IsFirstInstruction)
                    break;
            }

            top[block.Sequence] = used;
            analyzed.Set(block.Sequence, true);
        }
        /// <summary>
        /// Gets the output registers.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        public virtual RegisterBitmap GetOutputRegisters(Context context)
        {
            RegisterBitmap registers = new RegisterBitmap();

            if (context.Result.IsRegister)
                registers.Set(context.Result.Register);

            registers.Or(AdditionalOutputRegisters);

            return registers;
        }
        /// <summary>
        /// Gets the input registers.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        public virtual RegisterBitmap GetInputRegisters(Context context)
        {
            RegisterBitmap registers = new RegisterBitmap();

            registers.Set(GetRegister(context.Operand1, true));
            registers.Set(GetRegister(context.Operand2, true));
            registers.Set(GetRegister(context.Operand3, true));
            registers.Set(GetRegister(context.Result, ResultIsInput));

            registers.Or(AdditionalInputRegisters);

            return registers;
        }
        /// <summary>
        /// Gets the output registers.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        public virtual RegisterBitmap GetOutputRegisters(Context context)
        {
            RegisterBitmap registers = new RegisterBitmap();

            RegisterOperand regOperand = context.Result as RegisterOperand;

            if (regOperand != null)
                registers.Set(regOperand.Register);

            registers.Or(AdditionalOutputRegisters);

            return registers;
        }