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


C# Context.SetBranch方法代码示例

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


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

示例1: Decode

        /// <summary>
        /// Decodes the specified instruction.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="decoder">The instruction decoder, which holds the code stream.</param>
        public override void Decode(Context ctx, IInstructionDecoder decoder)
        {
            // Decode base classes first
            base.Decode(ctx, decoder);

            // Read the branch target
            // Is this a short branch target?
            if (opcode == OpCode.Brfalse_s || opcode == OpCode.Brtrue_s)
            {
                sbyte target = decoder.DecodeSByte();
                ctx.SetBranch(target);
            }
            else if (opcode == OpCode.Brfalse || opcode == OpCode.Brtrue)
            {
                int target = decoder.DecodeInt();
                ctx.SetBranch(target);
            }
            else if (opcode == OpCode.Switch)
            {
                // Don't do anything, the derived class will do everything
            }
            else
            {
                throw new NotSupportedException(@"Invalid opcode " + opcode.ToString() + " specified for UnaryBranchInstruction.");
            }
        }
开发者ID:GeroL,项目名称:MOSA-Project,代码行数:31,代码来源:UnaryBranchInstruction.cs

示例2: Decode

        /// <summary>
        /// Decodes the specified instruction.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="decoder">The instruction decoder, which holds the code stream.</param>
        public override void Decode(Context ctx, IInstructionDecoder decoder)
        {
            // Decode base classes first
            base.Decode(ctx, decoder);

            // Read the branch target
            // Is this a short branch target?
            // FIXME: Remove unary branch instructions from this list.
            if (_opcode == OpCode.Beq_s || _opcode == OpCode.Bge_s || _opcode == OpCode.Bge_un_s || _opcode == OpCode.Bgt_s ||
                _opcode == OpCode.Bgt_un_s || _opcode == OpCode.Ble_s || _opcode == OpCode.Ble_un_s || _opcode == OpCode.Blt_s ||
                _opcode == OpCode.Blt_un_s || _opcode == OpCode.Bne_un_s) {
                sbyte target;
                decoder.Decode(out target);
                ctx.SetBranch(target);
            }
            else if (_opcode == OpCode.Beq || _opcode == OpCode.Bge || _opcode == OpCode.Bge_un || _opcode == OpCode.Bgt ||
                _opcode == OpCode.Bgt_un || _opcode == OpCode.Ble || _opcode == OpCode.Ble_un || _opcode == OpCode.Blt ||
                _opcode == OpCode.Blt_un || _opcode == OpCode.Bne_un) {
                int target;
                decoder.Decode(out target);
                ctx.SetBranch(target);
            }
            else {
                throw new NotSupportedException(@"Invalid branch opcode specified for BinaryBranchInstruction");
            }
        }
开发者ID:hj1980,项目名称:Mosa,代码行数:31,代码来源:BinaryBranchInstruction.cs

示例3: Decode

        /// <summary>
        /// Decodes the specified instruction.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="decoder">The instruction decoder, which holds the code stream.</param>
        public override void Decode(Context ctx, IInstructionDecoder decoder)
        {
            // Decode base classes first
            base.Decode(ctx, decoder);

            // Read the branch target
            // Is this a short branch target?
            // FIXME: Remove unary branch instructions from this list.
            ctx.SetBranch((int)decoder.Instruction.Operand);
        }
开发者ID:Boddlnagg,项目名称:MOSA-Project,代码行数:15,代码来源:BinaryBranchInstruction.cs

示例4: Decode

        /// <summary>
        /// Decodes the specified instruction.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="decoder">The instruction decoder, which holds the code stream.</param>
        public override void Decode(Context ctx, IInstructionDecoder decoder)
        {
            // Decode base classes first
            base.Decode(ctx, decoder);

            switch (opcode)
            {
                case OpCode.Leave_s:
                    {
                        sbyte sb = decoder.DecodeSByte();
                        ctx.SetBranch(sb);
                        break;
                    }
                case OpCode.Leave:
                    {
                        int sb = decoder.DecodeInt();
                        ctx.SetBranch(sb);
                        break;
                    }
            }
        }
开发者ID:jeffreye,项目名称:MOSA-Project,代码行数:26,代码来源:LeaveInstruction.cs

示例5: Decode

        /// <summary>
        /// Decodes the specified instruction.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="decoder">The instruction decoder, which holds the code stream.</param>
        public override void Decode(Context ctx, IInstructionDecoder decoder)
        {
            // Decode bases first
            base.Decode(ctx, decoder);

            switch (opcode)
            {
                case OpCode.Br_s:
                    {
                        sbyte target = decoder.DecodeSByte();
                        ctx.SetBranch(target);
                    }
                    break;

                case OpCode.Br:
                    {
                        int target = decoder.DecodeInt();
                        ctx.SetBranch(target);
                        break;
                    }
            }
        }
开发者ID:GeroL,项目名称:MOSA-Project,代码行数:27,代码来源:BranchInstruction.cs

示例6: Decode

        /// <summary>
        /// Decodes the specified instruction.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="decoder">The instruction decoder, which holds the code stream.</param>
        public override void Decode(Context ctx, IInstructionDecoder decoder)
        {
            // Decode base classes first
            base.Decode(ctx, decoder);

            if (OpCode.Ret != opcode)
                throw new ArgumentException(@"Invalid opcode.", @"code");

            if (decoder.Method.Signature.ReturnType.Type == CilElementType.Void)
                ctx.OperandCount = 0;
            else
                ctx.OperandCount = 1;

            ctx.SetBranch(Int32.MaxValue);
        }
开发者ID:GeroL,项目名称:MOSA-Project,代码行数:20,代码来源:ReturnInstruction.cs

示例7: Context

        /// <summary>
        /// Performs stage specific processing on the compiler context.
        /// </summary>
        void IMethodCompilerStage.Run()
        {
            if (methodCompiler.Compiler.PlugSystem.GetPlugMethod(methodCompiler.Method) != null)
                return;

            if (!methodCompiler.Method.HasCode)
                return;

            // Create the prologue block
            Context context = new Context(instructionSet);

            // Add a jump instruction to the first block from the prologue
            context.AppendInstruction(IRInstruction.Jmp);
            context.SetBranch(0);
            context.Label = BasicBlock.PrologueLabel;
            prologue = basicBlocks.CreateBlock(BasicBlock.PrologueLabel, context.Index);
            basicBlocks.AddHeaderBlock(prologue);

            SplitIntoBlocks(0);

            // Create the epilogue block
            context = new Context(instructionSet);

            // Add null instruction, necessary to generate a block index
            context.AppendInstruction(null);
            context.Label = BasicBlock.EpilogueLabel;
            epilogue = basicBlocks.CreateBlock(BasicBlock.EpilogueLabel, context.Index);

            // Link all the blocks together
            BuildBlockLinks(prologue);

            foreach (ExceptionHandlingClause exceptionClause in methodCompiler.ExceptionClauseHeader.Clauses)
            {
                if (exceptionClause.HandlerOffset != 0)
                {
                    BasicBlock basicBlock = basicBlocks.GetByLabel(exceptionClause.HandlerOffset);
                    BuildBlockLinks(basicBlock);
                    basicBlocks.AddHeaderBlock(basicBlock);
                }
                if (exceptionClause.FilterOffset != 0)
                {
                    BasicBlock basicBlock = basicBlocks.GetByLabel(exceptionClause.FilterOffset);
                    BuildBlockLinks(basicBlock);
                    basicBlocks.AddHeaderBlock(basicBlock);
                }
            }
        }
开发者ID:jeffreye,项目名称:MOSA-Project,代码行数:50,代码来源:BasicBlockBuilderStage.cs

示例8: ConvertCondition

        /// <summary>
        /// Visitation function for BinaryBranch instruction.
        /// </summary>
        /// <param name="context">The context.</param>
        void CIL.ICILVisitor.BinaryBranch(Context context)
        {
            int 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.CreateConstantSignedInt(TypeSystem, 1));
                context.SetBranch(target);
            }
            else
            {
                context.SetInstruction(IRInstruction.IntegerCompareBranch, cc, null, first, second);
                context.SetBranch(target);
            }
        }
开发者ID:tea,项目名称:MOSA-Project,代码行数:25,代码来源:CILTransformationStage.cs

示例9: if

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

            Operand first = context.Operand1;
            Operand second = Operand.CreateConstantSignedInt(TypeSystem, (int)0);

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

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

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

示例10: Run

        protected override void Run()
        {
            if (!HasProtectedRegions)
                return;

            var exceptionRegister = Operand.CreateCPURegister(TypeLayout.TypeSystem.BuiltIn.Pointer, Architecture.ExceptionRegister);

            var nullOperand = Operand.GetNull(TypeSystem);

            CreateExceptionReturnOperands();

            for (int i = 0; i < BasicBlocks.Count; i++)
            {
                var block = BasicBlocks[i];

                for (var ctx = new Context(InstructionSet, block); !ctx.IsBlockEndInstruction; ctx.GotoNext())
                {
                    if (ctx.IsEmpty)
                        continue;

                    if (ctx.Instruction == IRInstruction.Throw)
                    {
                        var method = PlatformInternalRuntimeType.FindMethodByName("ExceptionHandler");

                        ctx.SetInstruction(IRInstruction.Move, exceptionRegister, ctx.Operand1);
                        ctx.AppendInstruction(IRInstruction.Call, null, Operand.CreateSymbolFromMethod(TypeSystem, method));
                        ctx.MosaMethod = method;
                    }
                    else if (ctx.Instruction == IRInstruction.CallFinally)
                    {
                        var target = ctx.BranchTargets[0];

                        ctx.SetInstruction(IRInstruction.KillAll);
                        ctx.AppendInstruction(IRInstruction.Move, exceptionRegister, nullOperand);
                        ctx.AppendInstruction(IRInstruction.InternalCall);
                        ctx.SetBranch(target);
                    }
                    else if (ctx.Instruction == IRInstruction.FinallyStart)
                    {
                        var header = FindImmediateExceptionHandler(ctx);
                        var headerBlock = BasicBlocks.GetByLabel(header.HandlerStart);

                        var v1 = AllocateVirtualRegister(TypeSystem.BuiltIn.Pointer);

                        ctx.SetInstruction(IRInstruction.KillAll);
                        ctx.AppendInstruction(IRInstruction.Gen, exceptionRegister);
                        ctx.AppendInstruction(IRInstruction.Move, exceptionRegisters[headerBlock], exceptionRegister);
                    }
                    else if (ctx.Instruction == IRInstruction.FinallyEnd)
                    {
                        var header = FindImmediateExceptionHandler(ctx);
                        var headerBlock = BasicBlocks.GetByLabel(header.HandlerStart);

                        var newBlocks = CreateNewBlocksWithContexts(2);

                        ctx.SetInstruction(IRInstruction.Move, exceptionRegister, exceptionRegisters[headerBlock]);
                        ctx.AppendInstruction(IRInstruction.IntegerCompareBranch, ConditionCode.Equal, null, exceptionRegister, nullOperand);
                        ctx.SetBranch(newBlocks[0].BasicBlock);
                        ctx.AppendInstruction(IRInstruction.Jmp, newBlocks[1].BasicBlock);
                        LinkBlocks(ctx, newBlocks[0]);
                        LinkBlocks(ctx, newBlocks[1]);

                        newBlocks[0].AppendInstruction(IRInstruction.InternalReturn);

                        var method = PlatformInternalRuntimeType.FindMethodByName("ExceptionHandler");

                        newBlocks[1].AppendInstruction(IRInstruction.Call, null, Operand.CreateSymbolFromMethod(TypeSystem, method));
                        newBlocks[1].MosaMethod = method;
                    }
                    else if (ctx.Instruction == IRInstruction.ExceptionStart)
                    {
                        ctx.SetInstruction(IRInstruction.KillAll);
                        ctx.AppendInstruction(IRInstruction.Gen, exceptionRegister);
                        ctx.AppendInstruction(IRInstruction.Move, ctx.Result, exceptionRegister);
                    }
                    else if (ctx.Instruction == IRInstruction.ExceptionEnd)
                    {
                        int target = ctx.BranchTargets[0];
                        ctx.SetInstruction(IRInstruction.Jmp);
                        ctx.SetBranch(target);
                    }
                }
            }
        }
开发者ID:Boddlnagg,项目名称:MOSA-Project,代码行数:84,代码来源:ExceptionStage.cs

示例11: BinaryBranch

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

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

            if (first.StackType == StackTypeCode.F)
            {
                Operand comparisonResult = methodCompiler.CreateVirtualRegister(BuiltInSigType.Int32);
                context.SetInstruction(IRInstruction.FloatingPointCompare, comparisonResult, first, second);
                context.ConditionCode = cc;
                context.AppendInstruction(IRInstruction.IntegerCompareBranch, null, comparisonResult, new ConstantOperand(BuiltInSigType.IntPtr, 1));
                context.ConditionCode = ConditionCode.Equal;
                context.SetBranch(target);
            }
            else
            {
                context.SetInstruction(IRInstruction.IntegerCompareBranch, null, first, second);
                context.ConditionCode = cc;
                context.SetBranch(target);
            }
        }
开发者ID:grover,项目名称:MOSA-Project,代码行数:28,代码来源:CILTransformationStage.cs

示例12: UnaryBranch

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

            ConditionCode cc;
            Operand first = context.Operand1;
            Operand second = ConstantOperand.I4_0;

            CIL.OpCode opcode = ((CIL.ICILInstruction)context.Instruction).OpCode;
            if (opcode == CIL.OpCode.Brtrue || opcode == CIL.OpCode.Brtrue_s)
            {
                cc = ConditionCode.NotEqual;
            }
            else if (opcode == CIL.OpCode.Brfalse || opcode == CIL.OpCode.Brfalse_s)
            {
                cc = ConditionCode.Equal;
            }
            else
            {
                throw new NotSupportedException(@"CILTransformationStage.UnaryBranch doesn't support CIL opcode " + opcode);
            }

            context.SetInstruction(IRInstruction.IntegerCompareBranch, null, first, second);
            context.ConditionCode = cc;
            context.SetBranch(target);
        }
开发者ID:grover,项目名称:MOSA-Project,代码行数:30,代码来源:CILTransformationStage.cs

示例13: BinaryBranch

        /// <summary>
        /// Visitation function for BinaryBranch instruction.
        /// </summary>
        /// <param name="context">The context.</param>
        public void BinaryBranch(Context context)
        {
            IBranch branch = context.Branch;

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

            if (first.StackType == StackTypeCode.F)
            {
                Operand comparisonResult = this.methodCompiler.CreateTemporary(BuiltInSigType.Int32);
                context.SetInstruction(Instruction.FloatingPointCompareInstruction, comparisonResult, first, second);
                context.ConditionCode = cc;
                context.SetInstruction(Instruction.IntegerCompareBranchInstruction, null, comparisonResult, new ConstantOperand(BuiltInSigType.IntPtr, 1));
                context.ConditionCode = ConditionCode.Equal;
                context.SetBranch(branch.Targets[0]);
            }
            else
            {
                context.SetInstruction(Instruction.IntegerCompareBranchInstruction, null, first, second);
                context.ConditionCode = cc;
                context.SetBranch(branch.Targets[0]);
            }
        }
开发者ID:GeroL,项目名称:MOSA-Project,代码行数:28,代码来源:CILTransformationStage.cs

示例14: UnaryBranch

        /// <summary>
        /// Visitation function for UnaryBranch instruction.
        /// </summary>
        /// <param name="context">The context.</param>
        public void UnaryBranch(Context context)
        {
            IBranch branch = context.Branch;

            ConditionCode cc;
            Operand first = context.Operand1;
            Operand second = new ConstantOperand(BuiltInSigType.Int32, 0UL);

            CIL.OpCode opcode = ((CIL.ICILInstruction)context.Instruction).OpCode;
            if (opcode == CIL.OpCode.Brtrue || opcode == CIL.OpCode.Brtrue_s)
            {
                cc = ConditionCode.NotEqual;
            }
            else if (opcode == CIL.OpCode.Brfalse || opcode == CIL.OpCode.Brfalse_s)
            {
                cc = ConditionCode.Equal;
            }
            else
            {
                throw new NotSupportedException(@"CILTransformationStage.UnaryBranch doesn't support CIL opcode " + opcode);
            }

            context.SetInstruction(Instruction.IntegerCompareBranchInstruction, null, first, second);
            context.ConditionCode = cc;
            context.SetBranch(branch.Targets[0]);
        }
开发者ID:GeroL,项目名称:MOSA-Project,代码行数:30,代码来源:CILTransformationStage.cs


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