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


C# Context.AppendInstruction方法代码示例

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


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

示例1: Run

        protected override void Run()
        {
            triggered = false;

            // The method declaring type must be a valuetype
            if (!MethodCompiler.Type.IsValueType)
                return;

            // If the method is static, non-virtual or is a constructor then don't process
            if (MethodCompiler.Method.IsStatic || !MethodCompiler.Method.IsVirtual || MethodCompiler.Method.Name.Equals(".ctor"))
                return;

            // If the method does not belong to an interface then don't process
            if (!(IsInterfaceMethod() || OverridesMethod()))
                return;

            // If the method is empty then don't process
            if (BasicBlocks.PrologueBlock.NextBlocks.Count == 0 || BasicBlocks.PrologueBlock.NextBlocks[0] == BasicBlocks.EpilogueBlock)
                return;

            triggered = true;

            // Get the this pointer
            var thisPtr = MethodCompiler.Parameters[0];

            //todo: move this to the end of prologue
            var context = new Context(BasicBlocks.PrologueBlock.NextBlocks[0].First);

            // Now push the this pointer by two native pointer sizes
            var v1 = AllocateVirtualRegister(TypeSystem.BuiltIn.TypedRef);

            context.AppendInstruction(IRInstruction.LoadInteger, NativeInstructionSize, v1, StackFrame, thisPtr);
            context.AppendInstruction(IRInstruction.AddSigned, NativeInstructionSize, v1, v1, Operand.CreateConstant(TypeSystem.BuiltIn.I4, NativePointerSize * 2));
            context.AppendInstruction(IRInstruction.StoreInteger, NativeInstructionSize, null, StackFrame, thisPtr, v1);
        }
开发者ID:tgiphil,项目名称:MOSA-Project,代码行数:35,代码来源:UnboxValueTypeStage.cs

示例2: TypeInitializerSchedulerStage

        /// <summary>
        /// Initializes a new instance of the <see cref="TypeInitializerSchedulerStage"/> class.
        /// </summary>
        public TypeInitializerSchedulerStage()
        {
            basicBlocks = new BasicBlocks();

            // Create the blocks
            var prologueBlock = basicBlocks.CreateBlock(BasicBlock.PrologueLabel);
            var startBlock = basicBlocks.CreateBlock(BasicBlock.StartLabel);
            var epilogueBlock = basicBlocks.CreateBlock(BasicBlock.EpilogueLabel);

            // Create the prologue instructions
            basicBlocks.AddHeadBlock(prologueBlock);
            var prologue = new Context(prologueBlock);
            prologue.AppendInstruction(IRInstruction.Prologue);
            prologue.Label = -1;
            prologue.AppendInstruction(IRInstruction.Jmp, startBlock);

            // Create the epilogue instruction
            var epilogue = new Context(epilogueBlock);
            epilogue.AppendInstruction(IRInstruction.Epilogue);

            // create start instructions
            start = new Context(startBlock);
            start.AppendInstruction(IRInstruction.Jmp, epilogueBlock);
            start.GotoPrevious();
        }
开发者ID:Profi-Concept,项目名称:MOSA-Project,代码行数:28,代码来源:TypeInitializerSchedulerStage.cs

示例3: InsertBlockProtectInstructions

        private void InsertBlockProtectInstructions()
        {
            foreach (var handler in MethodCompiler.Method.ExceptionHandlers)
            {
                var tryBlock = BasicBlocks.GetByLabel(handler.TryStart);

                var tryHandler = BasicBlocks.GetByLabel(handler.HandlerStart);

                var context = new Context(InstructionSet, tryBlock);

                while (context.IsEmpty || context.Instruction == IRInstruction.TryStart)
                {
                    context.GotoNext();
                }

                context.AppendInstruction(IRInstruction.TryStart, tryHandler);

                context = new Context(InstructionSet, tryHandler);

                if (handler.HandlerType == ExceptionHandlerType.Exception)
                {
                    var exceptionObject = MethodCompiler.CreateVirtualRegister(handler.Type);

                    context.AppendInstruction(IRInstruction.ExceptionStart, exceptionObject);
                }
                else if (handler.HandlerType == ExceptionHandlerType.Finally)
                {
                    context.AppendInstruction(IRInstruction.FinallyStart);
                }
            }
        }
开发者ID:Boddlnagg,项目名称:MOSA-Project,代码行数:31,代码来源:ProtectedRegionStage.cs

示例4: Run

        protected override void Run()
        {
            // The method declaring type must be a valuetype
            if (!MethodCompiler.Type.IsValueType)
                return;

            // The method and method declaring type must not have generic parameters
            //if (MethodCompiler.Method.HasOpenGenericParams || MethodCompiler.Method.DeclaringType.HasOpenGenericParams)
            //	return;

            // If the method is static, non-virtual or is a constructor then don't process
            if (MethodCompiler.Method.IsStatic || !MethodCompiler.Method.IsVirtual || MethodCompiler.Method.Name.Equals(".ctor"))
                return;

            // If the method does not belong to an interface then don't process
            if (!(IsInterfaceMethod() || OverridesMethod()))
                return;

            // If the method is empty then don't process
            if (BasicBlocks.PrologueBlock.NextBlocks.Count == 0 || BasicBlocks.PrologueBlock.NextBlocks[0] == BasicBlocks.EpilogueBlock)
                return;

            // Get the this pointer
            var thisPtr = MethodCompiler.StackLayout.GetStackParameter(0);

            var context = new Context(BasicBlocks.PrologueBlock.NextBlocks[0].First);

            // Now push the this pointer by two native pointer sizes
            context.AppendInstruction(IRInstruction.AddSigned, thisPtr, thisPtr, Operand.CreateConstant(TypeSystem, NativePointerSize * 2));
        }
开发者ID:pacificIT,项目名称:MOSA-Project,代码行数:30,代码来源:UnboxValueTypeStage.cs

示例5: Run

        protected override void Run()
        {
            triggered = false;

            // The method declaring type must be a valuetype
            if (!MethodCompiler.Type.IsValueType)
                return;

            // If the method is static, non-virtual or is a constructor then don't process
            if (MethodCompiler.Method.IsStatic || !MethodCompiler.Method.IsVirtual || MethodCompiler.Method.Name.Equals(".ctor"))
                return;

            // If the method does not belong to an interface then don't process
            if (!(IsInterfaceMethod() || OverridesMethod()))
                return;

            // If the method is empty then don't process
            if (BasicBlocks.PrologueBlock.NextBlocks.Count == 0 || BasicBlocks.PrologueBlock.NextBlocks[0] == BasicBlocks.EpilogueBlock)
                return;

            triggered = true;

            //System.Diagnostics.Debug.WriteLine(this.MethodCompiler.Method.FullName); //temp - remove me

            // Get the this pointer
            var thisPtr = MethodCompiler.StackLayout.Parameters[0];

            var context = new Context(BasicBlocks.PrologueBlock.NextBlocks[0].First);

            // Now push the this pointer by two native pointer sizes
            context.AppendInstruction(IRInstruction.AddSigned, thisPtr, thisPtr, Operand.CreateConstant(TypeSystem, NativePointerSize * 2));
        }
开发者ID:Zahovay,项目名称:MOSA-Project,代码行数:32,代码来源:UnboxValueTypeStage.cs

示例6: InsertBlockProtectInstructions

        private void InsertBlockProtectInstructions()
        {
            foreach (var handler in MethodCompiler.Method.ExceptionHandlers)
            {
                var tryBlock = BasicBlocks.GetByLabel(handler.TryStart);

                var tryHandler = BasicBlocks.GetByLabel(handler.HandlerStart);

                var context = new Context(tryBlock);

                while (context.IsEmpty || context.Instruction == IRInstruction.TryStart)
                {
                    context.GotoNext();
                }

                context.AppendInstruction(IRInstruction.TryStart, tryHandler);

                context = new Context(tryHandler);

                if (handler.ExceptionHandlerType == ExceptionHandlerType.Finally)
                {
                    var exceptionObject = AllocateVirtualRegister(exceptionType);
                    var finallyOperand = AllocateVirtualRegister(TypeSystem.BuiltIn.I4);

                    context.AppendInstruction2(IRInstruction.FinallyStart, exceptionObject, finallyOperand);
                }
            }
        }
开发者ID:tgiphil,项目名称:MOSA-Project,代码行数:28,代码来源:CILProtectedRegionStage.cs

示例7: CollectLocalVariablesFromIL

        /// <summary>
        /// Runs the specified method compiler.
        /// </summary>
        void IMethodCompilerStage.Run()
        {
            if (methodCompiler.PlugSystem != null)
                if (methodCompiler.PlugSystem.GetPlugMethod(methodCompiler.Method) != null)
                    return;

            List<StackOperand> locals = CollectLocalVariablesFromIL();

            // Iterate and collect locals from all blocks
            foreach (BasicBlock block in basicBlocks)
            {
                CollectLocalVariables(locals, block);
            }

            // Sort all found locals
            OrderVariables(locals, callingConvention);

            // Now we assign increasing stack offsets to each variable
            localsSize = LayoutVariables(locals, callingConvention, callingConvention.OffsetOfFirstLocal, 1);

            // Layout parameters
            LayoutParameters(methodCompiler);

            // Create a prologue instruction
            Context prologueCtx = new Context(instructionSet, basicBlocks.PrologueBlock).InsertBefore();
            prologueCtx.SetInstruction(IRInstruction.Prologue);
            prologueCtx.Label = -1;

            // Create an epilogue instruction
            Context epilogueCtx = new Context(instructionSet, basicBlocks.EpilogueBlock);
            epilogueCtx.AppendInstruction(IRInstruction.Epilogue);
            epilogueCtx.Label = Int32.MaxValue;
        }
开发者ID:grover,项目名称:MOSA-Project,代码行数:36,代码来源:StackLayoutStage.cs

示例8: TypeInitializerSchedulerStage

        /// <summary>
        /// Initializes a new instance of the <see cref="TypeInitializerSchedulerStage"/> class.
        /// </summary>
        public TypeInitializerSchedulerStage()
        {
            basicBlocks = new BasicBlocks();
            instructionSet = new InstructionSet(25);
            context = instructionSet.CreateNewBlock(basicBlocks);
            basicBlocks.AddHeaderBlock(context.BasicBlock);

            context.AppendInstruction(IRInstruction.Prologue);
        }
开发者ID:tea,项目名称:MOSA-Project,代码行数:12,代码来源:TypeInitializerSchedulerStage.cs

示例9: CreateEmptyBlockContext

        /// <summary>
        /// Create an empty block.
        /// </summary>
        /// <param name="label">The label.</param>
        /// <returns></returns>
        protected Context CreateEmptyBlockContext(int label)
        {
            Context ctx = new Context(instructionSet);
            BasicBlock block = basicBlocks.CreateBlock();
            ctx.BasicBlock = block;

            // Need a dummy instruction at the start of each block to establish a starting point of the block
            ctx.AppendInstruction(null);
            ctx.Label = label;
            block.Index = ctx.Index;

            return ctx;
        }
开发者ID:jeffreye,项目名称:MOSA-Project,代码行数:18,代码来源:BaseCodeTransformationStage.cs

示例10: InsertExceptionStartInstructions

        private void InsertExceptionStartInstructions()
        {
            foreach (var clause in MethodCompiler.Method.ExceptionHandlers)
            {
                if (clause.HandlerType == ExceptionHandlerType.Exception)
                {
                    var tryHandler = BasicBlocks.GetByLabel(clause.HandlerStart);

                    var context = new Context(tryHandler);

                    var exceptionObject = MethodCompiler.CreateVirtualRegister(clause.Type);

                    context.AppendInstruction(IRInstruction.ExceptionStart, exceptionObject);
                }
            }
        }
开发者ID:yonglehou,项目名称:MOSA-Project,代码行数:16,代码来源:ExceptionPrologueStage.cs

示例11: 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

示例12: InsertExceptionStartInstructions

        private void InsertExceptionStartInstructions()
        {
            var objectType = TypeSystem.GetTypeByName("System", "Object");

            foreach (var clause in MethodCompiler.Method.ExceptionHandlers)
            {
                if (clause.ExceptionHandlerType == ExceptionHandlerType.Exception)
                {
                    var handler = BasicBlocks.GetByLabel(clause.HandlerStart);

                    var exceptionObject = MethodCompiler.CreateVirtualRegister(clause.Type);

                    var context = new Context(handler);

                    context.AppendInstruction(IRInstruction.ExceptionStart, exceptionObject);
                }

                if (clause.ExceptionHandlerType == ExceptionHandlerType.Filter)
                {
                    {
                        var handler = BasicBlocks.GetByLabel(clause.HandlerStart);

                        var exceptionObject = MethodCompiler.CreateVirtualRegister(objectType);

                        var context = new Context(handler);

                        context.AppendInstruction(IRInstruction.ExceptionStart, exceptionObject);
                    }

                    {
                        var handler = BasicBlocks.GetByLabel(clause.FilterStart.Value);

                        var exceptionObject = MethodCompiler.CreateVirtualRegister(objectType);

                        var context = new Context(handler);

                        context.AppendInstruction(IRInstruction.FilterStart, exceptionObject);
                    }
                }
            }
        }
开发者ID:Profi-Concept,项目名称:MOSA-Project,代码行数:41,代码来源:ExceptionPrologueStage.cs

示例13: LayoutStackVariables

        /// <summary>
        /// Runs the specified method compiler.
        /// </summary>
        void IMethodCompilerStage.Run()
        {
            if (methodCompiler.Compiler.PlugSystem.GetPlugMethod(methodCompiler.Method) != null)
                return;

            // Layout stack variables
            LayoutStackVariables();

            // Layout parameters
            LayoutParameters(methodCompiler);

            // Create a prologue instruction
            Context prologueCtx = new Context(instructionSet, basicBlocks.PrologueBlock).InsertBefore();
            prologueCtx.SetInstruction(IRInstruction.Prologue);
            prologueCtx.Label = -1;

            // Create an epilogue instruction
            Context epilogueCtx = new Context(instructionSet, basicBlocks.EpilogueBlock);
            epilogueCtx.AppendInstruction(IRInstruction.Epilogue);
            epilogueCtx.Label = Int32.MaxValue;
        }
开发者ID:pdelprat,项目名称:MOSA-Project,代码行数:24,代码来源:StackLayoutStage.cs

示例14: SplitEdge

        private void SplitEdge(BasicBlock a, BasicBlock b)
        {
            // Create new block z
            var z = basicBlocks.CreateBlock();
            Context ctx = new Context(instructionSet);
            ctx.AppendInstruction(IR.IRInstruction.Jmp, a);
            ctx.Label = -1;
            z.Index = ctx.Index;

            // Unlink blocks
            a.NextBlocks.Remove(b);
            b.PreviousBlocks.Remove(a);

            // Link a to z
            a.NextBlocks.Add(z);
            z.PreviousBlocks.Add(a);

            // Link z to b
            b.PreviousBlocks.Add(z);
            z.NextBlocks.Add(b);

            // Insert jump in z to b
            ctx.SetInstruction(IRInstruction.Jmp, b);

            // Replace any jump/branch target in block a with z
            ctx = new Context(instructionSet, a);
            ctx.GotoLast();

            // Find branch or jump to b and replace it with z
            while (ctx.BranchTargets != null)
            {
                int[] targets = ctx.BranchTargets;
                for (int index = 0; index < targets.Length; index++)
                {
                    if (targets[index] == b.Label)
                        targets[index] = z.Label;
                }
                ctx.GotoPrevious();
            }
        }
开发者ID:jeffreye,项目名称:MOSA-Project,代码行数:40,代码来源:EdgeSplitStage.cs

示例15: Run

        protected override void Run()
        {
            // No stack setup if this is a linker generated method
            if (MethodCompiler.Method.DeclaringType.IsLinkerGenerated)
                return;

            if (IsPlugged)
                return;

            // Create a prologue instruction
            var prologue = new Context(BasicBlocks.PrologueBlock);
            prologue.AppendInstruction(IRInstruction.Prologue);
            prologue.Label = -1;

            if (BasicBlocks.EpilogueBlock != null)
            {
                // Create an epilogue instruction
                var epilogueCtx = new Context(BasicBlocks.EpilogueBlock);
                epilogueCtx.AppendInstruction(IRInstruction.Epilogue);
                epilogueCtx.Label = BasicBlock.EpilogueLabel;
            }
        }
开发者ID:Zahovay,项目名称:MOSA-Project,代码行数:22,代码来源:StackSetupStage.cs


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