• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# CompilerFramework.BasicBlock类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Mosa.Runtime.CompilerFramework.BasicBlock的典型用法代码示例。如果您正苦于以下问题:C# BasicBlock类的具体用法?C# BasicBlock怎么用?C# BasicBlock使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



BasicBlock类属于Mosa.Runtime.CompilerFramework命名空间,在下文中一共展示了BasicBlock类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: ArgumentNullException

        BasicBlock[] IDominanceProvider.GetDominators(BasicBlock block)
        {
            if (block == null)
                throw new ArgumentNullException(@"block");

            Debug.Assert(block.Sequence < _doms.Length, @"Invalid block index.");

            if (block.Sequence >= _doms.Length)
                throw new ArgumentException(@"Invalid block index.", @"block");

            // Return value
            BasicBlock[] result;
            // Counter
            int count, idx = block.Sequence;

            // Count the dominators first
            for (count = 1; 0 != idx; count++)
                idx = _doms[idx].Sequence;

            // Allocate a dominator array
            result = new BasicBlock[count + 1];
            result[0] = block;
            for (idx = block.Sequence, count = 1; 0 != idx; idx = _doms[idx].Sequence)
                result[count++] = _doms[idx];
            result[count] = _doms[0];

            return result;
        }
开发者ID:rtownsend,项目名称:MOSA-Project,代码行数:28,代码来源:DominanceCalculationStage.cs


示例2: CreateBlock

 /// <summary>
 /// Creates the block.
 /// </summary>
 /// <param name="label">The label.</param>
 /// <param name="index">The index.</param>
 /// <returns></returns>
 protected BasicBlock CreateBlock(int label, int index)
 {
     // HACK: BasicBlock.Count for the sequence works for now since blocks are not removed
     BasicBlock basicBlock = new BasicBlock (BasicBlocks.Count, label, index);
     BasicBlocks.Add (basicBlock);
     return basicBlock;
 }
开发者ID:54616E6E6572,项目名称:Mosa,代码行数:13,代码来源:BaseStage.cs


示例3: NextBlockHasInitialStack

        /// <summary>
        /// Nexts the block has initial stack.
        /// </summary>
        /// <param name="block">The block.</param>
        /// <param name="nextBlock">The next block.</param>
        /// <returns></returns>
        private static bool NextBlockHasInitialStack(BasicBlock block, out BasicBlock nextBlock)
        {
            nextBlock = null;
            foreach (BasicBlock b in block.NextBlocks)
            {
                if (b.InitialStack == null)
                    continue;

                nextBlock = b;
                return true;
            }
            return false;
        }
开发者ID:shanebrown99,项目名称:MOSA-Project,代码行数:19,代码来源:OperandDeterminationStage.cs


示例4: FindAndLinkBlock

 private void FindAndLinkBlock(BasicBlock block, int target)
 {
     BasicBlock next = this.FindBlock(target);
     if (!block.NextBlocks.Contains(next)) {
         this.LinkBlocks(block, next);
         this.BuildBlockLinks(next);
     }
 }
开发者ID:davidbjornn,项目名称:MOSA-Project,代码行数:8,代码来源:BasicBlockBuilderStage.cs


示例5: LinkBlocks

 /// <summary>
 /// Links the Blocks.
 /// </summary>
 /// <param name="caller">The caller.</param>
 /// <param name="callee">The callee.</param>
 private void LinkBlocks(BasicBlock caller, BasicBlock callee)
 {
     // Chain the blocks together
     caller.NextBlocks.Add(callee);
     callee.PreviousBlocks.Add(caller);
 }
开发者ID:davidbjornn,项目名称:MOSA-Project,代码行数:11,代码来源:BasicBlockBuilderStage.cs


示例6: Intersect

        /// <summary>
        /// Retrieves the highest common immediate dominator of the two given Blocks.
        /// </summary>
        /// <param name="b1">The first basic block.</param>
        /// <param name="b2">The second basic block.</param>
        /// <returns>The highest common dominator.</returns>
        private BasicBlock Intersect(BasicBlock b1, BasicBlock b2)
        {
            BasicBlock f1 = b1, f2 = b2;

            while (f2 != null && f1 != null && f1.Sequence != f2.Sequence)
            {
                while (f1 != null && f1.Sequence > f2.Sequence)
                    f1 = _doms[f1.Sequence];

                while (f2 != null && f1 != null && f2.Sequence > f1.Sequence)
                    f2 = _doms[f2.Sequence];
            }

            return f1;
        }
开发者ID:rtownsend,项目名称:MOSA-Project,代码行数:21,代码来源:DominanceCalculationStage.cs


示例7: SpillActiveOperands

        /// <summary>
        /// Spills all active operands at the end of a basic block.
        /// </summary>
        /// <param name="block">The basic block to spill in.</param>
        private void SpillActiveOperands(BasicBlock block)
        {
            int regIdx = 0;
            foreach (Operand op in _activeOperands) {
                if (op != null && op is MemoryOperand) {

                    Context ctx = new Context(InstructionSet, block);
                    ctx.GotoLast();

                    InsertMove(ctx, op, new RegisterOperand(op.Type, _registerSet[regIdx]));
                }

                regIdx++;
            }
            Array.Clear(_activeOperands, 0, _activeOperands.Length);
        }
开发者ID:rtownsend,项目名称:MOSA-Project,代码行数:20,代码来源:SimpleRegisterAllocator.cs


示例8: LinkTemporaryMoves

        /// <summary>
        /// Links the temporary moves.
        /// </summary>
        /// <param name="ctx">The CTX.</param>
        /// <param name="block">The block.</param>
        /// <param name="nextBlock">The next block.</param>
        /// <param name="stack">The stack.</param>
        private void LinkTemporaryMoves(Context ctx, BasicBlock block, BasicBlock nextBlock, Stack<Operand> stack)
        {
            Stack<Operand> initialStack = GetCurrentStack(stack);
            Stack<Operand> nextInitialStack = GetCurrentStack(nextBlock.InitialStack);

            for (int i = 0; i < nextBlock.InitialStack.Count; ++i)
                ctx.AppendInstruction(IR.Instruction.MoveInstruction, nextInitialStack.Pop(), initialStack.Pop());

            if (nextBlock.InitialStack.Count > 0)
                foreach (BasicBlock nBlock in block.NextBlocks)
                    nBlock.InitialStack = GetCurrentStack(nextBlock.InitialStack);
        }
开发者ID:shanebrown99,项目名称:MOSA-Project,代码行数:19,代码来源:OperandDeterminationStage.cs


示例9: AppendInstruction

 /// <summary>
 /// Inserts the instruction after.
 /// </summary>
 /// <param name="instruction">The instruction.</param>
 /// <param name="code">The code.</param>
 /// <param name="block">The block.</param>
 public void AppendInstruction(IInstruction instruction, IR.ConditionCode code, BasicBlock block)
 {
     AppendInstruction();
     SetInstruction(instruction, code, block);
 }
开发者ID:illuminus86,项目名称:MOSA-Project,代码行数:11,代码来源:Context.cs


示例10: CreateTemporaryMoves

        /// <summary>
        /// Creates the temporary moves.
        /// </summary>
        /// <param name="ctx">The CTX.</param>
        /// <param name="block">The block.</param>
        /// <param name="stack">The stack.</param>
        private void CreateTemporaryMoves(Context ctx, BasicBlock block, Stack<Operand> stack)
        {
            Context context = ctx.InsertBefore();

            context.SetInstruction(IR.Instruction.NopInstruction);

            BasicBlock nextBlock;

            if (NextBlockHasInitialStack(block, out nextBlock))
                LinkTemporaryMoves(context, block, nextBlock, stack);
            else
                CreateNewTemporaryMoves(context, block, stack);
        }
开发者ID:shanebrown99,项目名称:MOSA-Project,代码行数:19,代码来源:OperandDeterminationStage.cs


示例11: IsNotProcessed

 /// <summary>
 /// Determines whether [is not processed] [the specified block].
 /// </summary>
 /// <param name="block">The block.</param>
 /// <returns>
 /// 	<c>true</c> if [is not processed] [the specified block]; otherwise, <c>false</c>.
 /// </returns>
 private bool IsNotProcessed(BasicBlock block)
 {
     return !_processed.Contains(block);
 }
开发者ID:shanebrown99,项目名称:MOSA-Project,代码行数:11,代码来源:OperandDeterminationStage.cs


示例12: CreateNewTemporaryMoves

        /// <summary>
        /// Creates the new temporary moves.
        /// </summary>
        /// <param name="ctx">The CTX.</param>
        /// <param name="block">The block.</param>
        /// <param name="stack">The stack.</param>
        private void CreateNewTemporaryMoves(Context ctx, BasicBlock block, Stack<Operand> stack)
        {
            Stack<Operand> nextStack = new Stack<Operand>();
            foreach (Operand operand in stack)
            {
                Operand temp = MethodCompiler.CreateTemporary(operand.Type);
                nextStack.Push(temp);
                _operandStack.Pop();
                ctx.AppendInstruction(IR.Instruction.MoveInstruction, temp, operand);
            }

            if (nextStack.Count > 0)
                foreach (BasicBlock nextBlock in block.NextBlocks)
                    nextBlock.InitialStack = GetCurrentStack(nextStack);
        }
开发者ID:shanebrown99,项目名称:MOSA-Project,代码行数:21,代码来源:OperandDeterminationStage.cs


示例13: AssignOperands

        /// <summary>
        /// Assigns the operands.
        /// </summary>
        /// <param name="block">The block.</param>
        private void AssignOperands(BasicBlock block)
        {
            if (block.InitialStack != null)
                foreach (Operand operand in block.InitialStack)
                    _operandStack.Push(operand);

            for (Context ctx = new Context(InstructionSet, block); !ctx.EndOfInstruction; ctx.GotoNext())
            {
                if (!(ctx.Instruction is IBranchInstruction) && !(ctx.Instruction is ICILInstruction))
                    continue;

                if (!(ctx.Instruction is IR.JmpInstruction))
                {
                    AssignOperandsFromCILStack(ctx, _operandStack);
                    (ctx.Instruction as ICILInstruction).Validate(ctx, MethodCompiler);
                    PushResultOperands(ctx, _operandStack);
                }

                if (ctx.Instruction is IBranchInstruction)
                {
                    Stack<Operand> initialStack = GetCurrentStack(_operandStack);
                    CreateTemporaryMoves(ctx, block, initialStack);
                    break;
                }
            }

            MarkAsProcessed(block);

            foreach (BasicBlock b in block.NextBlocks)
            {
                if (IsNotProcessed(b))
                    AssignOperands(b);
            }
        }
开发者ID:shanebrown99,项目名称:MOSA-Project,代码行数:38,代码来源:OperandDeterminationStage.cs


示例14: Run

        /// <summary>
        /// Runs the specified compiler.
        /// </summary>
        public void Run()
        {
            if (!methodCount.ContainsKey(MethodCompiler.Method.Name))
                methodCount[MethodCompiler.Method.Name] = 0;

            ++methodCount[MethodCompiler.Method.Name];

            // Retreive the first block
            firstBlock = FindBlock(-1);

            workList = new Stack<BasicBlock>();
            workList.Push(firstBlock);
            workArray = new BitArray(BasicBlocks.Count);

            string methodName = MethodCompiler.Method.Name;
            methodName = methodName.Replace("<", "");
            methodName = methodName.Replace(">", "");
            methodName = methodName.Replace("$", "");
            methodName = methodName.Replace(".", "");
            IPipelineStage previousStage = MethodCompiler.GetPreviousStage(typeof(IMethodCompilerStage));
            dotFile.WriteLine("subgraph cluster" + methodName + "_FlowGraph {");
            dotFile.WriteLine("label = \"Method: " + methodName + "(" + MethodCompiler.Method.Signature + ") after " + previousStage.Name + "\"");
            //dotFile.WriteLine("graph [rankdir = \"TB\"];");

            string nodes = string.Empty;
            string edges = string.Empty;

            foreach (BasicBlock block in BasicBlocks)
            {
                string nodeName = string.Empty;
                string nodeContent = string.Empty;
                string nextNode = string.Empty;

                nodeName = methodName + "_" + block.ToString();
                //nodeName = nodeName.Replace("-", "_");

                nodeContent += "<tr><td bgcolor=\"black\" align=\"center\" colspan=\"4\"><font face=\"Courier\" color=\"white\">L_" + block.Label.ToString("x4") + "</font></td></tr>";

                int field = 0;
                int i = 0;

                for (Context ctx = new Context(InstructionSet, block); !ctx.EndOfInstruction; ctx.GotoNext())
                {
                    if (ctx.Instruction == null)
                        continue;

                    string color;
                    string inst = ctx.Instruction.ToString(ctx).Replace("&", "&amp;");
                    inst = inst.Replace("<", "&lt;");
                    inst = inst.Replace(">", "&gt;");

                    if (inst.StartsWith("IL") || inst.StartsWith("T_"))
                        color = "#0000ff5f";
                    else if (inst.StartsWith("IR"))
                        color = "#ff00005f";
                    else
                        color = "#CFD6CEff";

                    nodeContent += "<tr height=\"20\"><td bgcolor=\"white\" align=\"right\" width=\"20\"><img src=\"icon.png\"/></td><td bgcolor=\"white\" align=\"right\">" + (i++) + "</td><td bgcolor=\"" + color + "\" align=\"center\" colspan=\"2\"><font face=\"Courier\">" + inst + "</font></td></tr>";

                    ++field;
                }

                if (nodeContent != string.Empty && nodeContent[nodeContent.Length - 1] == '|')
                    nodeContent = nodeContent.Substring(0, nodeContent.Length - 2);

                if (nodeContent != string.Empty)
                    nodes += "\"" + nodeName + "\" [label = <<table border=\"1\" cellborder=\"0\" cellpadding=\"3\" bgcolor=\"white\">" + nodeContent + "</table>> shape = \"Mrecord\"];\r\n";

                foreach (BasicBlock nextBlock in block.NextBlocks)
                {
                    nextNode = methodName + "_" + nextBlock.ToString();

                    edges += "\"" + nodeName + "\"" + " -> " + "\"" + nextNode + "\";\r\n";
                }
            }

            dotFile.WriteLine(nodes);
            dotFile.WriteLine(edges);
            dotFile.WriteLine("};");
        }
开发者ID:shanebrown99,项目名称:MOSA-Project,代码行数:84,代码来源:FlowGraphVisualizationStage.cs


示例15: BuildBlockLinks

        /// <summary>
        /// Builds the block links.
        /// </summary>
        /// <param name="block">The current block.</param>
        private void BuildBlockLinks(BasicBlock block)
        {
            for (Context ctx = CreateContext(block); !ctx.EndOfInstruction; ctx.GotoNext())
            {
                switch (ctx.Instruction.FlowControl)
                {
                    case FlowControl.Next: continue;
                    case FlowControl.Call: continue;
                    case FlowControl.Return:
                        if (!block.NextBlocks.Contains(_epilogue))
                            LinkBlocks(block, _epilogue);
                        return;
                    case FlowControl.Break: goto case FlowControl.Branch;
                    case FlowControl.Throw: goto case FlowControl.Branch;
                    case FlowControl.Switch: goto case FlowControl.ConditionalBranch;
                    case FlowControl.Branch:
                        {
                            FindAndLinkBlock(block, ctx.Branch.Targets[0]);
                            return;
                        }
                    case FlowControl.ConditionalBranch:
                        foreach (int target in ctx.Branch.Targets) {
                            FindAndLinkBlock(block, target);
                        }

                        // Conditional blocks are at least two way branches. The old way of adding jumps didn't properly
                        // resolve operands under certain circumstances. This does.
                        int nextIndex = ctx.Index + 1;
                        if (nextIndex < this.InstructionSet.Used)
                        {
                            FindAndLinkBlock(block, this.InstructionSet.Data[nextIndex].Label);
                        }
                        continue;
                    default:
                        Debug.Assert(false);
                        break;
                }
            }
        }
开发者ID:davidbjornn,项目名称:MOSA-Project,代码行数:43,代码来源:BasicBlockBuilderStage.cs


示例16: MarkAsProcessed

 /// <summary>
 /// Marks as processed.
 /// </summary>
 /// <param name="block">The block.</param>
 private void MarkAsProcessed(BasicBlock block)
 {
     if (_processed.Contains(block))
         return;
     _processed.Add(block);
 }
开发者ID:shanebrown99,项目名称:MOSA-Project,代码行数:10,代码来源:OperandDeterminationStage.cs


示例17: SetInstruction

 /// <summary>
 /// Sets the instruction.
 /// </summary>
 /// <param name="instruction">The instruction.</param>
 /// <param name="code">The code.</param>
 /// <param name="block">The block.</param>
 public void SetInstruction(IInstruction instruction, IR.ConditionCode code, BasicBlock block)
 {
     SetInstruction(instruction);
     ConditionCode = code;
     SetBranch(block);
 }
开发者ID:illuminus86,项目名称:MOSA-Project,代码行数:12,代码来源:Context.cs


示例18: SetBranch

 /// <summary>
 /// Sets the branch.
 /// </summary>
 /// <param name="block">The block.</param>
 public void SetBranch(BasicBlock block)
 {
     SetBranch(block.Label);
 }
开发者ID:illuminus86,项目名称:MOSA-Project,代码行数:8,代码来源:Context.cs


示例19: BlockEnd

 /// <summary>
 /// Completion of code generation for a block.
 /// </summary>
 /// <param name="block">The completed block.</param>
 protected virtual void BlockEnd(BasicBlock block)
 {
 }
开发者ID:shanebrown99,项目名称:MOSA-Project,代码行数:7,代码来源:CodeGenerationStage.cs


示例20: ReversePostorder

        private BasicBlock[] ReversePostorder(List<BasicBlock> blocks)
        {
            BasicBlock[] result = new BasicBlock[blocks.Count - 1];
            int idx = 0;
            Queue<BasicBlock> workList = new Queue<BasicBlock>(blocks.Count);

            // Add next blocks
            foreach (BasicBlock next in blocks[0].NextBlocks)
                workList.Enqueue(next);

            while (workList.Count != 0)
            {
                BasicBlock current = workList.Dequeue();
                if (Array.IndexOf(result, current) == -1)
                {
                    result[idx++] = current;
                    foreach (BasicBlock next in current.NextBlocks)
                        workList.Enqueue(next);
                }
            }

            return result;
        }
开发者ID:rtownsend,项目名称:MOSA-Project,代码行数:23,代码来源:DominanceCalculationStage.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# CompilerFramework.Context类代码示例发布时间:2022-05-26
下一篇:
C# TypeSystem.RuntimeMethod类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap