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


C# Context.GotoPrevious方法代码示例

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


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

示例1: Run

        // TODO:
        // 1. If first branch is to the next basic block,
        //       then swap branch condition, replace branch target with jump target, and remove jump instruction.
        //           part of code: ConditionCode = GetOppositeConditionCode(ConditionCode);
        // 2. If the basic block contains only a single jump instruction, rewrite all jumps to avoid it.
        protected override void Run()
        {
            var trace = CreateTrace();

            for (int f = 0; f < BasicBlocks.Count - 1; f++)
            {
                var from = BasicBlocks[f];
                var next = BasicBlocks[f + 1];

                Context context = new Context(InstructionSet, from, from.EndIndex);
                context.GotoPrevious();

                while (context.IsEmpty)
                {
                    context.GotoPrevious();
                }

                if (context.Instruction.FlowControl != FlowControl.UnconditionalBranch)
                    continue;

                Debug.Assert(context.Instruction.FlowControl == FlowControl.UnconditionalBranch);
                Debug.Assert(context.BranchTargets.Length == 1);

                var target = context.BranchTargets[0];

                if (next.Label != target)
                    continue;

                context.Remove();
            }
        }
开发者ID:tea,项目名称:MOSA-Project,代码行数:36,代码来源:JumpPeepholeOptimizationStage.cs

示例2: CreateNewBlock

        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;
        }
开发者ID:tea,项目名称:MOSA-Project,代码行数:16,代码来源:ContextExtension.cs

示例3: ReplaceBranchTargets

        /// <summary>
        /// Replaces the branch targets.
        /// </summary>
        /// <param name="block">The current from block.</param>
        /// <param name="oldTarget">The current destination block.</param>
        /// <param name="newTarget">The new target block.</param>
        protected void ReplaceBranchTargets(BasicBlock block, BasicBlock oldTarget, BasicBlock newTarget)
        {
            // Replace any jump/branch target in block (from) with js
            var ctx = new Context(InstructionSet, block, block.EndIndex);
            Debug.Assert(ctx.IsBlockEndInstruction);

            do
            {
                ctx.GotoPrevious();
            }
            while (ctx.IsEmpty);

            // Find branch or jump to (to) and replace it with js
            while (!ctx.IsBlockStartInstruction)
            {
                if (ctx.BranchTargets != null)
                {
                    var targets = ctx.BranchTargets;
                    for (int index = 0; index < targets.Length; index++)
                    {
                        if (targets[index] == oldTarget.Label)
                            targets[index] = newTarget.Label;
                    }
                }

                do
                {
                    ctx.GotoPrevious();
                }
                while (ctx.IsEmpty);
            }
        }
开发者ID:Boddlnagg,项目名称:MOSA-Project,代码行数:38,代码来源:BaseMethodCompilerStage.cs


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