當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。