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


C# Context.Empty方法代码示例

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


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

示例1: MakeCall

        /// <summary>
        /// Expands method call instruction represented by the context to perform the method call.
        /// </summary>
        /// <param name="typeLayout">The type layouts.</param>
        /// <param name="context">The context.</param>
        public override void MakeCall(BaseMethodCompiler compiler, MosaTypeLayout typeLayout, Context context)
        {
            /*
             * Calling convention is right-to-left, pushed on the stack. Return value in EAX for integral
             * types 4 bytes or less, XMM0 for floating point and EAX:EDX for 64-bit. If this is a method
             * of a type, the this argument is moved to ECX right before the call.
             * If return value is value type, a stack local is allocated as a hidden parameter in caller
             * stack, the callee will then store the return value in the allocated space
             * The return value is the first parameter (even before this)
             * The callee will place the address of the return value into EAX and the caller will then
             * either retrieve the return value using compound move or will let one of the callers higher
             * in the caller chain handle the retrieval of the return value using compound move.
             */

            Operand target = context.Operand1;
            Operand result = context.Result;
            MosaMethod method = context.InvokeMethod;

            Debug.Assert(method != null, context.ToString());

            Operand scratch = Operand.CreateCPURegister(typeLayout.TypeSystem.BuiltIn.Pointer, scratchRegister);

            List<Operand> operands = BuildOperands(context);

            int stackSize = CalculateStackSizeForParameters(typeLayout, architecture, operands, method);

            context.Empty();

            int returnSize = 0;
            if (typeLayout.IsCompoundType(method.Signature.ReturnType))
            {
                returnSize = typeLayout.GetTypeSize(method.Signature.ReturnType);
            }

            if (stackSize != 0 || returnSize != 0)
            {
                ReserveStackSizeForCall(typeLayout.TypeSystem, context, returnSize + stackSize, scratch);
                PushOperands(compiler, typeLayout, context, method, operands, returnSize + stackSize, scratch);
            }

            // the mov/call two-instructions combo is to help facilitate the register allocator
            architecture.InsertMoveInstruction(context, scratch, target);
            architecture.InsertCallInstruction(context, scratch);

            CleanupReturnValue(compiler, typeLayout, context, result);
            FreeStackAfterCall(typeLayout.TypeSystem, context, returnSize + stackSize);
        }
开发者ID:yonglehou,项目名称:MOSA-Project,代码行数:52,代码来源:BaseCallingConvention32Bit.cs

示例2: GotoLeaveTargetInstruction

        private void GotoLeaveTargetInstruction(InstructionNode node)
        {
            var ctx = new Context(node);

            // clear exception register
            // FIXME: This will need to be preserved for filtered exceptions; will need a flag to know this - maybe an upper bit of leaveTargetRegister
            ctx.SetInstruction(IRInstruction.MoveInteger, exceptionRegister, nullOperand);

            var label = node.Label;
            var exceptionContext = FindImmediateExceptionContext(label);

            // 1) currently within a try block with a finally handler --- call it.
            if (exceptionContext.ExceptionHandlerType == ExceptionHandlerType.Finally && exceptionContext.IsLabelWithinTry(node.Label))
            {
                var handlerBlock = BasicBlocks.GetByLabel(exceptionContext.HandlerStart);

                ctx.AppendInstruction(IRInstruction.Jmp, handlerBlock);

                return;
            }

            // 2) else, find the next finally handler (if any), check if it should be called, if so, call it
            var nextFinallyContext = FindNextEnclosingFinallyContext(exceptionContext);

            if (nextFinallyContext != null)
            {
                var handlerBlock = BasicBlocks.GetByLabel(nextFinallyContext.HandlerStart);

                var nextBlock = Split(ctx);

                // compare leaveTargetRegister > handlerBlock.End, then goto finally handler
                ctx.AppendInstruction(IRInstruction.CompareIntegerBranch, ConditionCode.GreaterThan, null, Operand.CreateConstant(TypeSystem, handlerBlock.Label), leaveTargetRegister, nextBlock.Block);
                ctx.AppendInstruction(IRInstruction.Jmp, handlerBlock);

                ctx = nextBlock;
            }

            // find all the available targets within the method from this node's location
            var targets = new List<BasicBlock>();

            // using the end of the protected as the location
            var location = exceptionContext.TryEnd;

            foreach (var targetBlock in leaveTargets)
            {
                var source = targetBlock.Item2;
                var target = targetBlock.Item1;

                // target must be after end of exception context
                if (target.Label <= location)
                    continue;

                // target must be found within try or handler
                if (exceptionContext.IsLabelWithinTry(source.Label) || exceptionContext.IsLabelWithinHandler(source.Label))
                {
                    targets.AddIfNew(target);
                }
            }

            if (targets.Count == 0)
            {
                // this is an unreachable location

                // clear this block --- should only have on instruction
                ctx.Empty();

                var currentBlock = ctx.Block;
                var previousBlock = currentBlock.PreviousBlocks[0];

                var otherBranch = (previousBlock.NextBlocks[0] == currentBlock) ? previousBlock.NextBlocks[1] : previousBlock.NextBlocks[0];

                ReplaceBranchTargets(previousBlock, currentBlock, otherBranch);

                // the optimizer will remove the branch comparison

                return;
            }

            if (targets.Count == 1)
            {
                ctx.AppendInstruction(IRInstruction.Jmp, targets[0]);
                return;
            }
            else
            {
                var newBlocks = CreateNewBlockContexts(targets.Count - 1);

                ctx.AppendInstruction(IRInstruction.CompareIntegerBranch, ConditionCode.Equal, null, leaveTargetRegister, Operand.CreateConstant(TypeSystem, targets[0].Label), targets[0]);
                ctx.AppendInstruction(IRInstruction.Jmp, newBlocks[0].Block);

                for (int b = 1; b < targets.Count - 2; b++)
                {
                    newBlocks[b - 1].AppendInstruction(IRInstruction.CompareIntegerBranch, ConditionCode.Equal, null, leaveTargetRegister, Operand.CreateConstant(TypeSystem, targets[b].Label), targets[b]);
                    newBlocks[b - 1].AppendInstruction(IRInstruction.Jmp, newBlocks[b + 1].Block);
                }

                newBlocks[targets.Count - 2].AppendInstruction(IRInstruction.Jmp, targets[targets.Count - 1]);
            }
        }
开发者ID:tgiphil,项目名称:MOSA-Project,代码行数:99,代码来源:ExceptionStage.cs

示例3: ProcessPhiInstruction

        /// <summary>
        /// Processes the phi instruction.
        /// </summary>
        /// <param name="context">The context.</param>
        private void ProcessPhiInstruction(Context context)
        {
            var sourceBlocks = context.PhiBlocks;

            for (var index = 0; index < context.Block.PreviousBlocks.Count; index++)
            {
                var operand = context.GetOperand(index);
                var predecessor = sourceBlocks[index];

                InsertCopyStatement(predecessor, context.Result, operand);
            }

            context.Empty();
        }
开发者ID:Zahovay,项目名称:MOSA-Project,代码行数:18,代码来源:LeaveSSAStage.cs

示例4: Call

        /// <summary>
        /// Visitation function for Call instruction.
        /// </summary>
        /// <param name="context">The context.</param>
        private void Call(Context context)
        {
            if (CanSkipDueToRecursiveSystemObjectCtorCall(context))
            {
                context.Empty();
                return;
            }

            if (ProcessExternalCall(context))
                return;

            // If the method being called is a virtual method then we need to box the value type
            if (context.InvokeMethod.IsVirtual &&
                context.Operand1.Type.ElementType != null &&
                context.Operand1.Type.ElementType.IsValueType &&
                context.InvokeMethod.DeclaringType == context.Operand1.Type.ElementType)
            {
                if (OverridesMethod(context.InvokeMethod))
                {
                    var before = context.InsertBefore();
                    before.SetInstruction(IRInstruction.SubSigned, context.Operand1, context.Operand1, Operand.CreateConstant(TypeSystem, NativePointerSize * 2));
                }
                else
                {
                    // Get the value type, size and native alignment
                    MosaType type = context.Operand1.Type.ElementType;
                    int typeSize = TypeLayout.GetTypeSize(type);
                    int alignment = TypeLayout.NativePointerAlignment;
                    typeSize += (alignment - (typeSize % alignment)) % alignment;

                    // Create a virtual register to hold our boxed value
                    var boxedValue = AllocateVirtualRegister(TypeSystem.BuiltIn.Object);

                    // Create a new context before the call and set it as a VmCall
                    var before = context.InsertBefore();
                    before.SetInstruction(IRInstruction.Nop);
                    ReplaceWithVmCall(before, VmCall.Box);

                    // Populate the operands for the VmCall and result
                    before.SetOperand(1, GetRuntimeTypeHandle(type, before));
                    before.SetOperand(2, context.Operand1);
                    before.SetOperand(3, Operand.CreateConstant(TypeSystem, typeSize));
                    before.OperandCount = 4;
                    before.Result = boxedValue;
                    before.ResultCount = 1;

                    // Now replace the value type pointer with the boxed value virtual register
                    context.Operand1 = boxedValue;
                }
            }

            ProcessInvokeInstruction(context, context.InvokeMethod, context.Result, new List<Operand>(context.Operands));
        }
开发者ID:tgiphil,项目名称:MOSA-Project,代码行数:57,代码来源:CILTransformationStage.cs

示例5: Pop

 /// <summary>
 /// Visitation function for Pop instruction.
 /// </summary>
 /// <param name="context">The context.</param>
 private void Pop(Context context)
 {
     context.Empty();
 }
开发者ID:tgiphil,项目名称:MOSA-Project,代码行数:8,代码来源:CILTransformationStage.cs

示例6: Dup

        /// <summary>
        /// Visitation function for Dup instruction.
        /// </summary>
        /// <param name="context">The context.</param>
        private void Dup(Context context)
        {
            Debug.Assert(false); // should never get here

            // We don't need the dup anymore.
            context.Empty();
        }
开发者ID:tgiphil,项目名称:MOSA-Project,代码行数:11,代码来源:CILTransformationStage.cs


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