Пример #1
0
        /// <summary>
        /// Emits the instructions within a branch.
        /// </summary>
        /// <param name="codeGen">The code generator.</param>
        /// <param name="branch">The branch.</param>
        private void emitInstructionsInBranch(CodeGenerator codeGen, Branch branch)
        {
            // Check dependencies.
            foreach (Branch source in branch.Sources)
            {
                if (source.Generation == 0)
                {
                    source.Generation++;
                    emitInstructionsInBranch(codeGen, source);
                }
            }

            branch.Generation++;
            if (branch.Generation > 2)
            {
                return;
            }

            mContext.CurrentStack = branch.Stack;
            branch.UpdateStack(mBuilder);
            LLVM.PositionBuilderAtEnd(mBuilder, branch.Block);

            foreach (Instruction instruction in branch.Instructions)
            {
                FlowControl flow = instruction.OpCode.FlowControl;

                codeGen.Emit(instruction, mContext, mBuilder);

                // If the next instruction is a new block, and we didn't have an explicit branch instruction to the next block,
                // then we need to create the branch instruction explicitely.
                if (mContext.IsNewBranch(instruction.Next))
                {
                    // If this instruction did not branch already...
                    if (flow != FlowControl.Branch && flow != FlowControl.Cond_Branch && flow != FlowControl.Return)
                    {
                        LLVM.BuildBr(mBuilder, mContext.GetBlockOf(instruction.Next));
                    }
                }
            }
        }