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


C# Context.SetOperand方法代码示例

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


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

示例1: Run

        protected override void Run()
        {
            finalVirtualRegisters = new Dictionary<Operand, Operand>();

            foreach (var block in BasicBlocks)
            {
                for (var context = new Context(InstructionSet, block); !context.IsBlockEndInstruction; context.GotoNext())
                {
                    if (context.Instruction == IRInstruction.Phi)
                    {
                        Debug.Assert(context.OperandCount == context.BasicBlock.PreviousBlocks.Count);

                        ProcessPhiInstruction(context);
                    }

                    for (var i = 0; i < context.OperandCount; ++i)
                    {
                        var op = context.GetOperand(i);

                        if (op != null && op.IsSSA)
                        {
                            context.SetOperand(i, GetFinalVirtualRegister(op));
                        }
                    }

                    if (context.Result != null && context.Result.IsSSA)
                    {
                        context.Result = GetFinalVirtualRegister(context.Result);
                    }
                }
            }

            finalVirtualRegisters = null;
        }
开发者ID:tea,项目名称:MOSA-Project,代码行数:34,代码来源:LeaveSSAStage.cs

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

示例3: foreach

        /// <summary>
        /// Performs stage specific processing on the compiler context.
        /// </summary>
        void IMethodCompilerStage.Run()
        {
            foreach (var block in basicBlocks)
            {
                if (block.Label == BasicBlock.EpilogueLabel)
                    continue;

                for (var context = new Context(instructionSet, block); !context.EndOfInstruction; context.GotoNext())
                {
                    if (context.Instruction is IR.Phi)
                        ProcessPhiInstruction(block, context);

                    for (var i = 0; i < context.OperandCount; ++i)
                    {
                        var op = context.GetOperand(i);
                        if (op is SsaOperand)
                            context.SetOperand(i, (op as SsaOperand).Operand);
                    }

                    if (context.Result != null)
                    {
                        if (context.Result is SsaOperand)
                            context.Result = (context.Result as SsaOperand).Operand;
                    }
                }
            }
        }
开发者ID:toddhainsworth,项目名称:MOSA-Project,代码行数:30,代码来源:LeaveSSAStage.cs

示例4: Run

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

            if (HasProtectedRegions)
                return;

            finalVirtualRegisters = new Dictionary<Operand, Operand>();

            foreach (var block in BasicBlocks)
            {
                for (var context = new Context(InstructionSet, block); !context.IsBlockEndInstruction; context.GotoNext())
                {
                    if (context.IsEmpty)
                        continue;

                    instructionCount++;

                    if (context.Instruction == IRInstruction.Phi)
                    {
                        //Debug.Assert(context.OperandCount == context.BasicBlock.PreviousBlocks.Count);
                        if (context.OperandCount != context.BasicBlock.PreviousBlocks.Count)
                        {
                            throw new Mosa.Compiler.Common.InvalidCompilerException(context.ToString());
                        }

                        ProcessPhiInstruction(context);
                    }

                    for (var i = 0; i < context.OperandCount; ++i)
                    {
                        var op = context.GetOperand(i);

                        if (op != null && op.IsSSA)
                        {
                            context.SetOperand(i, GetFinalVirtualRegister(op));
                        }
                    }

                    if (context.Result != null && context.Result.IsSSA)
                    {
                        context.Result = GetFinalVirtualRegister(context.Result);
                    }
                }
            }

            finalVirtualRegisters = null;
        }
开发者ID:Boddlnagg,项目名称:MOSA-Project,代码行数:49,代码来源:LeaveSSAStage.cs

示例5: Promote

        protected void Promote(Operand local)
        {
            var stacktype = local.Type.GetStackType();

            var v = MethodCompiler.CreateVirtualRegister(stacktype);

            if (trace.Active) trace.Log("*** Replacing: " + local.ToString() + " with " + v.ToString());

            foreach (int index in local.Uses.ToArray())
            {
                Context ctx = new Context(InstructionSet, index);

                for (int i = 0; i < ctx.OperandCount; i++)
                {
                    Operand operand = ctx.GetOperand(i);

                    if (local == operand)
                    {
                        if (trace.Active) trace.Log("BEFORE:\t" + ctx.ToString());
                        ctx.SetOperand(i, v);
                        if (trace.Active) trace.Log("AFTER: \t" + ctx.ToString());
                    }
                }
            }

            foreach (int index in local.Definitions.ToArray())
            {
                Context ctx = new Context(InstructionSet, index);

                for (int i = 0; i < ctx.OperandCount; i++)
                {
                    Operand operand = ctx.GetResult(i);

                    if (local == operand)
                    {
                        if (trace.Active) trace.Log("BEFORE:\t" + ctx.ToString());
                        ctx.SetResult(i, v);
                        if (trace.Active) trace.Log("AFTER: \t" + ctx.ToString());
                    }
                }
            }
        }
开发者ID:Boddlnagg,项目名称:MOSA-Project,代码行数:42,代码来源:PromoteLocalVariablesStage.cs

示例6: foreach

        /// <summary>
        /// Performs stage specific processing on the compiler context.
        /// </summary>
        void IMethodCompilerStage.Run()
        {
            foreach (var block in basicBlocks)
            {
                for (var context = new Context(instructionSet, block); !context.EndOfInstruction; context.GotoNext())
                {
                    if (context.Instruction is IR.Phi)
                        ProcessPhiInstruction(block, context);

                    for (var i = 0; i < context.OperandCount; ++i)
                    {
                        var op = context.GetOperand(i);
                        if (op != null && op.IsSSA)
                            context.SetOperand(i, op.SsaOperand);
                    }

                    if (context.Result != null)
                    {
                        if (context.Result.IsSSA)
                            context.Result = context.Result.SsaOperand;
                    }
                }
            }
        }
开发者ID:jeffreye,项目名称:MOSA-Project,代码行数:27,代码来源:LeaveSSAStage.cs

示例7: RenameVariables

        /// <summary>
        /// Renames the variables.
        /// </summary>
        /// <param name="block">The block.</param>
        /// <param name="dominanceCalculation">The dominance calculation.</param>
        /// <param name="variables">The variables.</param>
        private void RenameVariables(BasicBlock block, IDominanceProvider dominanceCalculation, Dictionary<Operand, Stack<int>> variables)
        {
            for (var context = new Context(instructionSet, block); !context.EndOfInstruction; context.GotoNext())
            {
                if (!(context.Instruction is Phi))
                {
                    for (var i = 0; i < context.OperandCount; ++i)
                    {
                        var op = context.GetOperand(i);

                        if (!(op is StackOperand))
                            continue;

                        if (!variables.ContainsKey(op))
                            throw new Exception(op.ToString() + " is not in dictionary [block = " + block + "]");

                        var index = variables[op].Peek();
                        context.SetOperand(i, CreateSsaOperand(context.GetOperand(i), index));
                    }
                }

                if (PhiPlacementStage.IsAssignmentToStackVariable(context))
                {
                    var op = context.Result;
                    var index = variables[op].Count;
                    context.SetResult(CreateSsaOperand(op, index));
                    variables[op].Push(index);
                }
            }

            foreach (var s in block.NextBlocks)
            {
                var j = WhichPredecessor(s, block);

                for (var context = new Context(instructionSet, s); !context.EndOfInstruction; context.GotoNext())
                {
                    if (!(context.Instruction is Phi))
                        continue;

                    var op = context.GetOperand(j);

                    if (variables[op].Count > 0)
                    {
                        var index = variables[op].Peek();
                        context.SetOperand(j, CreateSsaOperand(context.GetOperand(j), index));
                    }
                }
            }

            foreach (var s in dominanceCalculation.GetChildren(block))
            {
                RenameVariables(s, dominanceCalculation, variables);
            }
        }
开发者ID:grover,项目名称:MOSA-Project,代码行数:60,代码来源:EnterSSAStage.cs

示例8: SimpleCopyPropagation

        /// <summary>
        /// Simples the copy propagation.
        /// </summary>
        /// <param name="context">The context.</param>
        private void SimpleCopyPropagation(Context context)
        {
            if (context.IsEmpty)
                return;

            if (!(context.Instruction is IR.Move))
                return;

            if (context.Operand1.IsConstant)
                return;

            if (!context.Result.IsStackLocal)
                return;

            // FIXME: does not work on ptr or I4 types - probably because of signed extension, or I8/U8 - probably because 64-bit
            if (!(CanCopyPropagation(context.Result) && CanCopyPropagation(context.Operand1)))
                return;

            Operand destinationOperand = context.Result;
            Operand sourceOperand = context.Operand1;

            //if (IsLogging) Trace("REVIEWING:\t" + context.ToString());

            // for each statement T that uses operand, substituted c in statement T
            foreach (int index in destinationOperand.Uses.ToArray())
            {
                Context ctx = new Context(instructionSet, index);

                if (ctx.Instruction is IR.AddressOf || ctx.Instruction is IR.Phi)
                    return;
            }

            AddOperandUsageToWorkList(context);

            foreach (int index in destinationOperand.Uses.ToArray())
            {
                Context ctx = new Context(instructionSet, index);

                if (ctx.Instruction is IR.AddressOf || ctx.Instruction is IR.Phi)
                    continue;

                for (int i = 0; i < ctx.OperandCount; i++)
                {
                    Operand operand = ctx.GetOperand(i);

                    if (destinationOperand == operand)
                    {
                        if (IsLogging) Trace("BEFORE:\t" + ctx.ToString());
                        ctx.SetOperand(i, sourceOperand);
                        if (IsLogging) Trace("AFTER: \t" + ctx.ToString());
                    }
                }

            }

            Debug.Assert(destinationOperand.Uses.Count == 0);

            if (IsLogging) Trace("REMOVED:\t" + context.ToString());
            AddOperandUsageToWorkList(context);
            context.SetInstruction(IRInstruction.Nop);
            instructionsRemoved++;
            //context.Remove();
        }
开发者ID:pdelprat,项目名称:MOSA-Project,代码行数:67,代码来源:SSAOptimizations.cs

示例9: ReplaceWithVmCall

        /// <summary>
        /// Visitation function for UnboxAny instruction.
        /// </summary>
        /// <param name="context">The context.</param>
        void CIL.ICILVisitor.UnboxAny(Context context)
        {
            var value = context.Operand1;
            var type = context.RuntimeType;
            var result = context.Result;

            if (type.FullName == "System.Boolean")
            {
                ReplaceWithVmCall(context, VmCall.UnboxBool);
            }
            else if (type.FullName == "System.Char")
            {
                ReplaceWithVmCall(context, VmCall.UnboxChar);
            }
            else if (type.FullName == "System.SByte")
            {
                ReplaceWithVmCall(context, VmCall.UnboxInt8);
            }
            else if (type.FullName == "System.Byte")
            {
                ReplaceWithVmCall(context, VmCall.UnboxUInt8);
            }
            else if (type.FullName == "System.Int16")
            {
                //ReplaceWithVmCall(context, VmCall.UnboxInt32);
                ReplaceWithVmCall(context, VmCall.UnboxInt16);
            }
            else if (type.FullName == "System.UInt16")
            {
                ReplaceWithVmCall(context, VmCall.UnboxUInt32);
            }
            else if (type.FullName == "System.Int32")
            {
                ReplaceWithVmCall(context, VmCall.UnboxInt32);
            }
            else if (type.FullName == "System.UInt32")
            {
                ReplaceWithVmCall(context, VmCall.UnboxUInt32);
            }
            else if (type.FullName == "System.Int64")
            {
                ReplaceWithVmCall(context, VmCall.UnboxInt64);
            }
            else if (type.FullName == "System.UInt64")
            {
                ReplaceWithVmCall(context, VmCall.UnboxUInt64);
            }
            else if (type.FullName == "System.Single")
            {
                ReplaceWithVmCall(context, VmCall.UnboxSingle);
            }
            else if (type.FullName == "System.Double")
            {
                ReplaceWithVmCall(context, VmCall.UnboxDouble);
            }
            else
            {
                context.ReplaceInstructionOnly(IRInstruction.Move);
                return;
            }

            context.SetOperand(1, value);
            context.OperandCount = 2;
            context.Result = result;
        }
开发者ID:jeffreye,项目名称:MOSA-Project,代码行数:69,代码来源:CILTransformationStage.cs

示例10: RenameVariables

        /// <summary>
        /// Renames the variables.
        /// </summary>
        /// <param name="block">The block.</param>
        /// <param name="dominance">The dominance provider.</param>
        private void RenameVariables(BasicBlock block, IDominanceAnalysis dominance)
        {
            for (var node = block.First; !node.IsBlockEndInstruction; node = node.Next)
            {
                if (node.Instruction != IRInstruction.Phi)
                {
                    for (var i = 0; i < node.OperandCount; ++i)
                    {
                        var op = node.GetOperand(i);

                        if (op == null || !op.IsVirtualRegister)
                            continue;

                        Debug.Assert(variables.ContainsKey(op), op.ToString() + " is not in dictionary [block = " + block + "]");

                        var version = variables[op].Peek();
                        node.SetOperand(i, GetSSAOperand(op, version));
                    }
                }

                if (!node.IsEmpty && node.Result != null && node.Result.IsVirtualRegister)
                {
                    var op = node.Result;
                    var index = counts[op];
                    node.Result = GetSSAOperand(op, index);
                    variables[op].Push(index);
                    counts[op] = index + 1;
                }
            }

            foreach (var s in block.NextBlocks)
            {
                // index does not change between this stage and PhiPlacementStage since the block list order does not change
                var index = WhichPredecessor(s, block);

                for (var context = new Context(s); !context.IsBlockEndInstruction; context.GotoNext())
                {
                    if (context.Instruction != IRInstruction.Phi)
                        continue;

                    Debug.Assert(context.OperandCount == context.Block.PreviousBlocks.Count);

                    var op = context.GetOperand(index);

                    if (variables[op].Count > 0)
                    {
                        var version = variables[op].Peek();
                        context.SetOperand(index, GetSSAOperand(context.GetOperand(index), version));
                    }
                }
            }

            foreach (var s in dominance.GetChildren(block))
            {
                RenameVariables(s, dominance);
            }

            for (var context = new Context(block); !context.IsBlockEndInstruction; context.GotoNext())
            {
                if (!context.IsEmpty && context.Result != null && context.Result.IsVirtualRegister)
                {
                    var op = context.Result.SSAParent;
                    var index = variables[op].Pop();
                }
            }
        }
开发者ID:Zahovay,项目名称:MOSA-Project,代码行数:71,代码来源:EnterSSAStage.cs

示例11: GetMethodTableSymbol

        /// <summary>
        /// Visitation function for Isinst instruction.
        /// </summary>
        /// <param name="context">The context.</param>
        void CIL.ICILVisitor.IsInst(Context context)
        {
            Operand reference = context.Operand1;
            Operand result = context.Result;

            MosaType classType = result.Type;
            Operand methodTableSymbol = GetMethodTableSymbol(classType);

            if (!classType.IsInterface)
            {
                ReplaceWithVmCall(context, VmCall.IsInstanceOfType);

                context.SetOperand(1, methodTableSymbol);
                context.SetOperand(2, reference);
                context.OperandCount = 3;
                context.ResultCount = 1;
            }
            else
            {
                int slot = CalculateInterfaceSlot(classType);

                ReplaceWithVmCall(context, VmCall.IsInstanceOfInterfaceType);

                context.SetOperand(1, Operand.CreateConstantUnsignedInt(TypeSystem, (uint)slot));
                context.SetOperand(2, reference);
                context.OperandCount = 3;
                context.ResultCount = 1;
            }
        }
开发者ID:tea,项目名称:MOSA-Project,代码行数:33,代码来源:CILTransformationStage.cs

示例12: switch

        /// <summary>
        /// Visitation function for BinaryLogic instruction.
        /// </summary>
        /// <param name="context">The context.</param>
        void CIL.ICILVisitor.BinaryLogic(Context context)
        {
            if (context.Operand1.Type.IsEnum)
            {
                var type = context.Operand1.Type;
                var operand = Operand.CreateField(type.Fields[0]);
                context.SetOperand(0, operand);
            }

            if (context.Operand2.Type.IsEnum)
            {
                var type = context.Operand2.Type;
                var operand = Operand.CreateField(type.Fields[0]);
                context.SetOperand(1, operand);
            }

            switch ((context.Instruction as CIL.BaseCILInstruction).OpCode)
            {
                case CIL.OpCode.And: context.SetInstruction(IRInstruction.LogicalAnd, context.Result, context.Operand1, context.Operand2); break;
                case CIL.OpCode.Or: context.SetInstruction(IRInstruction.LogicalOr, context.Result, context.Operand1, context.Operand2); break;
                case CIL.OpCode.Xor: context.SetInstruction(IRInstruction.LogicalXor, context.Result, context.Operand1, context.Operand2); break;
                case CIL.OpCode.Div_un: context.SetInstruction(IRInstruction.DivUnsigned, context.Result, context.Operand1, context.Operand2); break;
                case CIL.OpCode.Rem_un: context.SetInstruction(IRInstruction.RemUnsigned, context.Result, context.Operand1, context.Operand2); break;
                default: throw new InvalidCompilerException();
            }
        }
开发者ID:tea,项目名称:MOSA-Project,代码行数:30,代码来源:CILTransformationStage.cs

示例13: ProcessInvokeInstruction

        /// <summary>
        /// Processes a method call instruction.
        /// </summary>
        /// <param name="context">The transformation context.</param>
        /// <param name="method">The method.</param>
        /// <param name="resultOperand">The result operand.</param>
        /// <param name="operands">The operands.</param>
        private void ProcessInvokeInstruction(Context context, MosaMethod method, Operand symbolOperand, Operand resultOperand, List<Operand> operands)
        {
            Debug.Assert(method != null);

            context.SetInstruction(IRInstruction.Call, (byte)(operands.Count + 1), (byte)(resultOperand == null ? 0 : 1));
            context.MosaMethod = method;

            if (resultOperand != null)
            {
                context.SetResult(resultOperand);
            }

            int index = 0;
            context.SetOperand(index++, symbolOperand);
            foreach (Operand op in operands)
            {
                context.SetOperand(index++, op);
            }
        }
开发者ID:tea,项目名称:MOSA-Project,代码行数:26,代码来源:CILTransformationStage.cs

示例14: InsertPhiInstruction

        /// <summary>
        /// Inserts the phi instruction.
        /// </summary>
        /// <param name="block">The block.</param>
        /// <param name="variable">The variable.</param>
        private void InsertPhiInstruction(BasicBlock block, Operand variable)
        {
            var context = new Context(instructionSet, block).InsertBefore();
            context.SetInstruction(IRInstruction.Phi, variable);

            for (var i = 0; i < block.PreviousBlocks.Count; ++i)
                context.SetOperand(i, variable);

            context.OperandCount = (byte)block.PreviousBlocks.Count;
        }
开发者ID:pdelprat,项目名称:MOSA-Project,代码行数:15,代码来源:PhiPlacementStage.cs

示例15: PerformStaticAllocationOf

        private void PerformStaticAllocationOf(Context allocation, Context assignment)
        {
            MosaType allocatedType = (allocation.InvokeMethod != null) ? allocation.InvokeMethod.DeclaringType : allocation.Result.Type;
            MosaField assignmentField = (assignment.Instruction is DupInstruction) ? FindStsfldForDup(assignment).MosaField : assignment.MosaField;

            // Get size of type
            int typeSize = TypeLayout.GetTypeSize(allocatedType);

            // If instruction is newarr then get the size of the element, multiply it by array size, and add array header size
            // Also need to align to a 4-byte boundry
            if (allocation.Instruction is NewarrInstruction)
                typeSize = (TypeLayout.GetTypeSize(allocatedType.ElementType) * (int)allocation.Previous.Operand1.ConstantSignedLongInteger) + (TypeLayout.NativePointerSize * 3);

            // Allocate a linker symbol to refer to this allocation. Use the destination field name as the linker symbol name.
            var symbolName = MethodCompiler.Linker.CreateSymbol(assignmentField.FullName + @"<<$cctor", SectionKind.ROData, Architecture.NativeAlignment, typeSize);

            // Try to get typeDefinitionSymbol if allocatedType isn't a value type
            string typeDefinitionSymbol = GetTypeDefinition(allocatedType);

            if (typeDefinitionSymbol != null)
                MethodCompiler.Linker.Link(LinkType.AbsoluteAddress, BuiltInPatch.I4, symbolName, 0, 0, typeDefinitionSymbol, SectionKind.ROData, 0);

            // Issue a load request before the newobj and before the assignment.
            Operand symbol1 = InsertLoadBeforeInstruction(assignment, symbolName.Name, assignmentField.FieldType);
            assignment.Operand1 = symbol1;

            // If the instruction is a newarr and the assignment instruction is a dup then we want to remove it
            if (allocation.Instruction is NewarrInstruction && assignment.Instruction is DupInstruction)
                assignment.SetInstruction(CILInstruction.Get(OpCode.Ldc_i4), assignment.Result, assignment.Operand1);

            // Change the newobj to a call and increase the operand count to include the this ptr.
            // If the instruction is a newarr, then just replace with a nop instead
            allocation.ResultCount = 0;
            if (allocation.Instruction is NewarrInstruction)
            {
                allocation.OperandCount = 0;
                allocation.SetInstruction(CILInstruction.Get(OpCode.Nop));
            }
            else
            {
                Operand symbol2 = InsertLoadBeforeInstruction(allocation, symbolName.Name, assignmentField.FieldType);
                IEnumerable<Operand> ops = allocation.Operands;
                allocation.OperandCount++;
                allocation.Operand1 = symbol2;
                int i = 0;
                foreach (Operand op in ops)
                {
                    i++;
                    allocation.SetOperand(i, op);
                }
                allocation.ReplaceInstructionOnly(CILInstruction.Get(OpCode.Call));
            }
        }
开发者ID:yonglehou,项目名称:MOSA-Project,代码行数:53,代码来源:StaticAllocationResolutionStage.cs


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