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


C# Context.GetOperand方法代码示例

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


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

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

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

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

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

        private void Phi(Context context)
        {
            //if (Trace.Active) Trace.Log(context.ToString());

            var result = GetVariableState(context.Result);

            if (result.IsOverDefined)
                return;

            var sourceBlocks = context.Other as List<BasicBlock>;

            VariableState first = null;

            var currentBlock = GetBlock(context, true);

            //if (Trace.Active) Trace.Log("Loop: " + currentBlock.PreviousBlocks.Count.ToString());

            for (var index = 0; index < currentBlock.PreviousBlocks.Count; index++)
            {
                var op = context.GetOperand(index);

                var predecessor = sourceBlocks[index];
                bool executable = blockStates[predecessor.Sequence];

                //if (Trace.Active) Trace.Log("# " + index.ToString() + ": " + predecessor.ToString() + " " + (executable ? "Yes" : "No"));

                phiStatements.AddIfNew(predecessor, context.Index);

                if (!executable)
                    continue;

                var operand = GetVariableState(op);

                //if (Trace.Active) Trace.Log("# " + index.ToString() + ": " + operand.ToString());

                if (operand.IsOverDefined)
                {
                    UpdateToOverDefined(result);
                    return;
                }

                if (operand.IsConstant)
                {
                    if (first == null)
                    {
                        first = operand;
                        continue;
                    }

                    if (!first.AreConstantsEqual(operand))
                    {
                        UpdateToOverDefined(result);
                        return;
                    }
                }
            }

            if (first != null)
            {
                UpdateToConstant(result, first.ConstantUnsignedInteger);
            }
        }
开发者ID:Boddlnagg,项目名称:MOSA-Project,代码行数:62,代码来源:SparseConditionalConstantPropagation.cs

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

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

示例10: SimpleConstantPropagation

        /// <summary>
        /// Simple constant propagation.
        /// </summary>
        /// <param name="context">The context.</param>
        private void SimpleConstantPropagation(Context context)
        {
            if (context.IsEmpty)
                return;

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

            if (!context.Operand1.IsConstant)
                return;

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

            // 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)
                    continue;

                bool propogated = false;

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

                    if (operand == context.Result)
                    {
                        propogated = true;

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

                if (propogated)
                    AddToWorkList(index);
            }
        }
开发者ID:pdelprat,项目名称:MOSA-Project,代码行数:47,代码来源:SSAOptimizations.cs

示例11: SimpleCopyPropagation

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

            if (context.Instruction != IRInstruction.Move)
                return;

            if (context.Operand1.IsConstant)
                return;

            if (!context.Result.IsVirtualRegister)
                return;

            if (!context.Operand1.IsVirtualRegister)
                return;

            Debug.Assert(context.Result.Definitions.Count == 1);

            // If the pointer or reference types are different, we can not copy propagation because type information would be lost.
            // Also if the operand sign is different, we cannot do it as it required a signed/unsigned extended move, not a normal move
            if (!CanCopyPropagation(context.Result, context.Operand1))
                return;

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

            //if (trace.IsLogging) trace.Log("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 == IRInstruction.AddressOf)
                    return;
            }

            AddOperandUsageToWorkList(context);

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

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

                    if (destinationOperand == operand)
                    {
                        if (trace.Active) trace.Log("*** SimpleCopyPropagation");
                        if (trace.Active) trace.Log("BEFORE:\t" + ctx.ToString());
                        ctx.SetOperand(i, sourceOperand);
                        simpleCopyPropagationCount++;
                        if (trace.Active) trace.Log("AFTER: \t" + ctx.ToString());
                    }
                }
            }

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

            if (trace.Active) trace.Log("REMOVED:\t" + context.ToString());
            AddOperandUsageToWorkList(context);
            context.SetInstruction(IRInstruction.Nop);
            instructionsRemovedCount++;

            //context.Remove();
        }
开发者ID:tea,项目名称:MOSA-Project,代码行数:72,代码来源:SSAOptimizations.cs

示例12: ProcessPhiInstruction

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

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

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

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

示例13: AssignOperandsFromCILStack

        /// <summary>
        /// Assigns the operands from CIL stack.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="currentStack">The current stack.</param>
        private void AssignOperandsFromCILStack(Context ctx, Stack<Operand> currentStack)
        {
            for (int index = ctx.OperandCount - 1; index >= 0; --index)
            {
                if (ctx.GetOperand(index) != null)
                    continue;

                ctx.SetOperand(index, currentStack.Pop());
            }
        }
开发者ID:yonglehou,项目名称:MOSA-Project,代码行数:15,代码来源:OperandAssignmentStage.cs

示例14: Calli

        /// <summary>
        /// Visitation function for Calli instruction.
        /// </summary>
        /// <param name="context">The context.</param>
        private void Calli(Context context)
        {
            Operand destinationOperand = context.GetOperand(context.OperandCount - 1);
            context.OperandCount -= 1;

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

示例15: ProcessPhiInstruction

        /// <summary>
        /// Processes the phi instruction.
        /// </summary>
        /// <param name="block">The block.</param>
        /// <param name="context">The context.</param>
        private void ProcessPhiInstruction(BasicBlock block, Context context)
        {
            for (var index = 0; index < block.PreviousBlocks.Count; index++)
            {
                var predecessor = block.PreviousBlocks[index];
                var operand = context.GetOperand(index);

                InsertCopyStatement(predecessor, context.Result, operand);
            }
            context.Remove();
        }
开发者ID:jeffreye,项目名称:MOSA-Project,代码行数:16,代码来源:LeaveSSAStage.cs


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