当前位置: 首页>>代码示例>>C#>>正文


C# Context.AddBranchTarget方法代码示例

本文整理汇总了C#中Context.AddBranchTarget方法的典型用法代码示例。如果您正苦于以下问题:C# Context.AddBranchTarget方法的具体用法?C# Context.AddBranchTarget怎么用?C# Context.AddBranchTarget使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Context的用法示例。


在下文中一共展示了Context.AddBranchTarget方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: UpdateBlockProtectInstructions

        private void UpdateBlockProtectInstructions()
        {
            foreach (var block in BasicBlocks)
            {
                var context = new Context(block.Last);

                while (context.IsEmpty || context.IsBlockEndInstruction || context.Instruction == IRInstruction.Flow)
                {
                    context.GotoPrevious();
                }

                if (context.Instruction is EndFinallyInstruction)
                {
                    context.SetInstruction(IRInstruction.FinallyEnd);

                    var entry = FindFinallyHandler(context.Node);
                    var list = returns.Get(entry);

                    if (list == null)
                        return;

                    context.AppendInstruction(IRInstruction.FinallyReturn);

                    foreach (var returnBlock in list)
                    {
                        context.AddBranchTarget(returnBlock);
                    }
                }
                else if (context.Instruction is LeaveInstruction)
                {
                    // Find enclosing finally clause
                    bool createLink = false;

                    var entry = FindImmediateExceptionHandler(context.Node);

                    if (entry != null)
                    {
                        if (entry.IsLabelWithinTry(context.Label))
                            createLink = true;
                    }

                    if (createLink)
                    {
                        var tryFinallyBlock = context.BranchTargets[0];

                        returns.Add(entry, tryFinallyBlock);

                        context.SetInstruction(IRInstruction.TryEnd);

                        if (entry.HandlerType == ExceptionHandlerType.Finally)
                        {
                            var finallyBlock = BasicBlocks.GetByLabel(entry.HandlerStart);

                            context.AppendInstruction(IRInstruction.CallFinally, finallyBlock, tryFinallyBlock);
                        }
                        else
                        {
                            context.AppendInstruction(IRInstruction.Jmp, tryFinallyBlock);
                        }

                        //Debug.Assert(context.BasicBlock.NextBlocks.Count <= 1);
                    }
                    else
                    {
                        context.ReplaceInstructionOnly(IRInstruction.ExceptionEnd);
                    }
                }
            }
        }
开发者ID:pacificIT,项目名称:MOSA-Project,代码行数:69,代码来源:ProtectedRegionStage.cs

示例2: UnaryBranch

        /// <summary>
        /// Visitation function for UnaryBranch instruction.
        /// </summary>
        /// <param name="context">The context.</param>
        private void UnaryBranch(Context context)
        {
            var target = context.BranchTargets[0];

            Operand first = context.Operand1;
            Operand second = ConstantZero;

            CIL.OpCode opcode = ((CIL.BaseCILInstruction)context.Instruction).OpCode;

            if (opcode == CIL.OpCode.Brtrue || opcode == CIL.OpCode.Brtrue_s)
            {
                context.SetInstruction(IRInstruction.CompareIntegerBranch, ConditionCode.NotEqual, null, first, second);
                context.AddBranchTarget(target);
                return;
            }
            else if (opcode == CIL.OpCode.Brfalse || opcode == CIL.OpCode.Brfalse_s)
            {
                context.SetInstruction(IRInstruction.CompareIntegerBranch, ConditionCode.Equal, null, first, second);
                context.AddBranchTarget(target);
                return;
            }

            throw new NotImplementCompilerException(@"CILTransformationStage.UnaryBranch doesn't support CIL opcode " + opcode);
        }
开发者ID:tgiphil,项目名称:MOSA-Project,代码行数:28,代码来源:CILTransformationStage.cs

示例3: BinaryBranch

        /// <summary>
        /// Visitation function for BinaryBranch instruction.
        /// </summary>
        /// <param name="context">The context.</param>
        private void BinaryBranch(Context context)
        {
            var target = context.BranchTargets[0];

            ConditionCode cc = ConvertCondition(((CIL.BaseCILInstruction)context.Instruction).OpCode);
            Operand first = context.Operand1;
            Operand second = context.Operand2;

            if (first.IsR)
            {
                Operand result = AllocateVirtualRegister(TypeSystem.BuiltIn.I4);

                if (first.IsR4)
                    context.SetInstruction(IRInstruction.CompareFloatR4, cc, result, first, second);
                else
                    context.SetInstruction(IRInstruction.CompareFloatR8, cc, result, first, second);

                context.AppendInstruction(IRInstruction.CompareIntegerBranch, ConditionCode.Equal, null, result, Operand.CreateConstant(TypeSystem, 1));
            }
            else
            {
                context.SetInstruction(IRInstruction.CompareIntegerBranch, cc, null, first, second);
            }

            context.AddBranchTarget(target);
        }
开发者ID:tgiphil,项目名称:MOSA-Project,代码行数:30,代码来源:CILTransformationStage.cs

示例4: BinaryBranch

        /// <summary>
        /// Visitation function for BinaryBranch instruction.
        /// </summary>
        /// <param name="context">The context.</param>
        private void BinaryBranch(Context context)
        {
            var target = context.BranchTargets[0];

            ConditionCode cc = ConvertCondition(((CIL.BaseCILInstruction)context.Instruction).OpCode);
            Operand first = context.Operand1;
            Operand second = context.Operand2;

            if (first.IsR)
            {
                Operand comparisonResult = MethodCompiler.CreateVirtualRegister(TypeSystem.BuiltIn.I4);
                context.SetInstruction(IRInstruction.FloatCompare, cc, comparisonResult, first, second);
                context.AppendInstruction(IRInstruction.IntegerCompareBranch, ConditionCode.Equal, null, comparisonResult, Operand.CreateConstant(TypeSystem, 1));
                context.AddBranchTarget(target);
            }
            else
            {
                context.SetInstruction(IRInstruction.IntegerCompareBranch, cc, null, first, second);
                context.AddBranchTarget(target);
            }
        }
开发者ID:Zahovay,项目名称:MOSA-Project,代码行数:25,代码来源:CILTransformationStage.cs


注:本文中的Context.AddBranchTarget方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。