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


C# Context.SetInstruction方法代码示例

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


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

示例1: foreach

        /// <summary>
        /// Replaces the intrinsic call site
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="methodCompiler">The method compiler.</param>
        void IIntrinsicInternalMethod.ReplaceIntrinsicCall(Context context, BaseMethodCompiler methodCompiler)
        {
            var result = context.Result;
            var operand1 = context.Operand1;
            if (operand1.IsValueType)
            {
                InstructionNode def = operand1.Definitions[0];
                var replacements = new List<Tuple<InstructionNode, int>>();
                foreach (var use in operand1.Uses)
                    for (int i = 0; i < use.OperandCount; i++)
                        if (use.GetOperand(i) == operand1)
                            replacements.Add(new Tuple<InstructionNode, int>(use, i));

                foreach (var replace in replacements)
                    replace.Item1.SetOperand(replace.Item2, def.Operand1);

                operand1 = def.Operand1;
                def.Empty();

                if (operand1.IsMemoryAddress)
                {
                    context.SetInstruction(IRInstruction.AddressOf, result, operand1);
                    return;
                }
            }
            context.SetInstruction(IRInstruction.Move, result, operand1);
        }
开发者ID:Profi-Concept,项目名称:MOSA-Project,代码行数:32,代码来源:GetObjectAddress.cs

示例2:

 /// <summary>
 /// Replaces the intrinsic call site
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="methodCompiler">The method compiler.</param>
 void IIntrinsicInternalMethod.ReplaceIntrinsicCall(Context context, BaseMethodCompiler methodCompiler)
 {
     var result = context.Result;
     var operand1 = context.Operand1;
     if (operand1.IsValueType)
     {
         operand1 = context.Previous.Operand1;
         context.Previous.Empty();
         context.SetInstruction(IRInstruction.AddressOf, result, operand1);
         return;
     }
     context.SetInstruction(IRInstruction.Move, result, operand1);
 }
开发者ID:pacificIT,项目名称:MOSA-Project,代码行数:18,代码来源:GetObjectAddress.cs

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

示例4: Internal

        /// <summary>
        /// Allows quick internal call replacements
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="methodCompiler">The method compiler.</param>
        /// <param name="internalMethod">The internal method to replace with.</param>
        /// <param name="internalClass">The internal class that has the internal method.</param>
        protected void Internal(Context context, BaseMethodCompiler methodCompiler, string internalMethod, string internalClass = "Internal")
        {
            if (context == null || methodCompiler == null || internalMethod == null || internalClass == null)
                throw new ArgumentNullException();

            var type = methodCompiler.TypeSystem.GetTypeByName("Mosa.Runtime", internalClass);
            Debug.Assert(type != null, "Cannot find Mosa.Runtime." + internalClass);

            var method = type.FindMethodByName(internalMethod);
            Debug.Assert(method != null, "Cannot find " + internalMethod + " in " + type.Name);

            Operand callTargetOperand = Operand.CreateSymbolFromMethod(methodCompiler.TypeSystem, method);

            var operands = new Operand[context.OperandCount];

            for (int i = 0; i < context.OperandCount; i++)
                operands[i] = context.GetOperand(i);

            Operand result = context.Result;

            context.SetInstruction(IRInstruction.Call, result, callTargetOperand);

            for (int i = 0; i < operands.Length; i++)
            {
                context.SetOperand(1 + i, operands[i]);
            }

            context.OperandCount = (byte)(1 + operands.Length);
            context.InvokeMethod = method;
        }
开发者ID:Zahovay,项目名称:MOSA-Project,代码行数:37,代码来源:InternalsBase.cs

示例5: FoldMulSInstruction

        /// <summary>
        /// Folds the multiply instruction.
        /// </summary>
        /// <param name="context">The context.</param>
        private void FoldMulSInstruction(Context context)
        {
            var cA = LoadSignedInteger(context.Operand1);
            var cB = LoadSignedInteger(context.Operand2);

            context.SetInstruction(IRInstruction.Move, context.Result, new ConstantOperand(context.Result.Type, cA * cB));
        }
开发者ID:grover,项目名称:MOSA-Project,代码行数:11,代码来源:ConstantFoldingStage.cs

示例6: if

        /// <summary>
        /// Replaces the intrinsic call site
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="methodCompiler">The method compiler.</param>
        void IIntrinsicInternalMethod.ReplaceIntrinsicCall(Context context, BaseMethodCompiler methodCompiler)
        {
            var size = InstructionSize.Size32;

            if (context.OperandCount == 1)
            {
                context.SetInstruction(IRInstruction.LoadInteger, size, context.Result, context.Operand1, Operand.CreateConstant(methodCompiler.TypeSystem, 0));
            }
            else if (context.OperandCount == 2)
            {
                context.SetInstruction(IRInstruction.LoadInteger, size, context.Result, context.Operand1, context.Operand2);
            }
            else
            {
                throw new InvalidCompilerException();
            }
        }
开发者ID:tgiphil,项目名称:MOSA-Project,代码行数:22,代码来源:Load32.cs

示例7: if

        /// <summary>
        /// Replaces the intrinsic call site
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="methodCompiler">The method compiler.</param>
        void IIntrinsicInternalMethod.ReplaceIntrinsicCall(Context context, BaseMethodCompiler methodCompiler)
        {
            var size = methodCompiler.Architecture.NativePointerSize == 4 ? InstructionSize.Size32 : InstructionSize.Size64;

            if (context.OperandCount == 1)
            {
                context.SetInstruction(IRInstruction.Load, size, context.Result, context.Operand1, Operand.CreateConstantSignedInt(methodCompiler.TypeSystem, 0));
            }
            else if (context.OperandCount == 2)
            {
                context.SetInstruction(IRInstruction.Load, size, context.Result, context.Operand1, context.Operand2);
            }
            else
            {
                throw new InvalidCompilerException();
            }
        }
开发者ID:Boddlnagg,项目名称:MOSA-Project,代码行数:22,代码来源:Load.cs

示例8:

        /// <summary>
        /// Replaces the intrinsic call site
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="typeSystem">The type system.</param>
        void IIntrinsicInternalMethod.ReplaceIntrinsicCall(Context context, ITypeSystem typeSystem, IList<RuntimeParameter> parameters)
        {
            Operand callTargetOperand = this.GetInternalAllocateStringCallTarget(typeSystem);
            Operand methodTableOperand = Operand.CreateSymbol(BuiltInSigType.IntPtr, StringClassMethodTableSymbolName);
            Operand lengthOperand = context.Operand1;
            Operand result = context.Result;

            context.SetInstruction(IRInstruction.Call, result, callTargetOperand, methodTableOperand, lengthOperand);
        }
开发者ID:jeffreye,项目名称:MOSA-Project,代码行数:14,代码来源:InternalAllocateString.cs

示例9: ReplaceIntrinsicCall

        /// <summary>
        /// Replaces the intrinsic call site
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="typeSystem">The type system.</param>
        public void ReplaceIntrinsicCall(Context context, ITypeSystem typeSystem)
        {
            SymbolOperand callTargetOperand = this.GetInternalAllocateStringCallTarget(typeSystem);
            SymbolOperand methodTableOperand = new SymbolOperand(BuiltInSigType.IntPtr, StringClassMethodTableSymbolName);
            Operand lengthOperand = context.Operand1;
            Operand result = context.Result;

            context.SetInstruction(IR.Instruction.CallInstruction, result, callTargetOperand, methodTableOperand, lengthOperand);
        }
开发者ID:davidleon,项目名称:MOSA-Project,代码行数:14,代码来源:InternalAllocateString.cs

示例10: GetRuntimeTypeHandle

        /// <summary>
        /// Replaces the intrinsic call site
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="methodCompiler">The method compiler.</param>
        void IIntrinsicInternalMethod.ReplaceIntrinsicCall(Context context, BaseMethodCompiler methodCompiler)
        {
            var method = methodCompiler.Compiler.PlatformInternalRuntimeType.FindMethodByName("AllocateString");

            Operand callTargetOperand = Operand.CreateSymbolFromMethod(methodCompiler.TypeSystem, method);

            Operand typeDefinitionOperand = GetRuntimeTypeHandle(context, methodCompiler);
            Operand lengthOperand = context.Operand1;
            Operand result = context.Result;

            context.SetInstruction(IRInstruction.Call, result, callTargetOperand, typeDefinitionOperand, lengthOperand);
            context.InvokeMethod = method;
        }
开发者ID:yonglehou,项目名称:MOSA-Project,代码行数:18,代码来源:InternalAllocateString.cs

示例11: Run

        protected override void Run()
        {
            // Handler Code
            foreach (var clause in MethodCompiler.Method.ExceptionBlocks)
            {
                if (clause.HandlerType == ExceptionHandlerType.Exception)
                {
                    var block = BasicBlocks.GetByLabel(clause.HandlerOffset);

                    var context = new Context(InstructionSet, block).InsertBefore();

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

                    context.SetInstruction(IRInstruction.ExceptionPrologue, exceptionObject);
                }
            }
        }
开发者ID:tea,项目名称:MOSA-Project,代码行数:17,代码来源:ExceptionPrologueStage.cs

示例12:

        /// <summary>
        /// Replaces the intrinsic call site
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="methodCompiler">The method compiler.</param>
        void IIntrinsicInternalMethod.ReplaceIntrinsicCall(Context context, BaseMethodCompiler methodCompiler)
        {
            string arch = "Mosa.Platform.Internal." + methodCompiler.Architecture.PlatformName;

            var type = methodCompiler.TypeSystem.GetTypeByName(arch, "Runtime");
            Debug.Assert(type != null, "Cannot find " + arch + ".Runtime");

            var method = type.FindMethodByName("InitializeArray");

            Operand callTargetOperand = Operand.CreateSymbolFromMethod(methodCompiler.TypeSystem, method);

            Operand arrayOperand = context.Operand1;
            Operand fieldOperand = context.Operand2;

            context.SetInstruction(IRInstruction.Call, null, callTargetOperand, arrayOperand, fieldOperand);
            context.MosaMethod = method;
        }
开发者ID:tea,项目名称:MOSA-Project,代码行数:22,代码来源:InternalInitializeArray.cs

示例13: InsertCopyStatement

        /// <summary>
        /// Inserts the copy statement.
        /// </summary>
        /// <param name="predecessor">The predecessor.</param>
        /// <param name="result">The result.</param>
        /// <param name="operand">The operand.</param>
        private void InsertCopyStatement(BasicBlock predecessor, Operand result, Operand operand)
        {
            var context = new Context(instructionSet, predecessor);
            while (!context.EndOfInstruction && IsBranchInstruction(context))
                context.GotoNext();

            if (context.Index != -1)
                context = context.InsertBefore();

            var source = operand.IsSSA ? operand.SsaOperand : operand;
            var destination = result.IsSSA ? result.SsaOperand : result;

            Debug.Assert(!source.IsSSA);
            Debug.Assert(!destination.IsSSA);

            if (destination != source)
                context.SetInstruction(IR.IRInstruction.Move, destination, source);
        }
开发者ID:jeffreye,项目名称:MOSA-Project,代码行数:24,代码来源:LeaveSSAStage.cs

示例14:

        /// <summary>
        /// Replaces the intrinsic call site
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="methodCompiler">The method compiler.</param>
        void IIntrinsicInternalMethod.ReplaceIntrinsicCall(Context context, BaseMethodCompiler methodCompiler)
        {
            string arch = "Mosa.Platform.Internal." + methodCompiler.Architecture.PlatformName;

            var type = methodCompiler.TypeSystem.GetTypeByName(arch, "Runtime");
            Debug.Assert(type != null, "Cannot find " + arch + ".Runtime");

            var method = type.FindMethodByName("AllocateString");

            Operand callTargetOperand = Operand.CreateSymbolFromMethod(methodCompiler.TypeSystem, method);

            Operand methodTableOperand = Operand.CreateUnmanagedSymbolPointer(methodCompiler.TypeSystem, StringClassMethodTableSymbolName);
            Operand lengthOperand = context.Operand1;
            Operand result = context.Result;

            context.SetInstruction(IRInstruction.Call, result, callTargetOperand, methodTableOperand, lengthOperand);
            context.MosaMethod = method;
        }
开发者ID:tea,项目名称:MOSA-Project,代码行数:23,代码来源:InternalAllocateString.cs

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


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