本文整理汇总了C#中Mosa.Compiler.Framework.Context.GotoPrevious方法的典型用法代码示例。如果您正苦于以下问题:C# Context.GotoPrevious方法的具体用法?C# Context.GotoPrevious怎么用?C# Context.GotoPrevious使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mosa.Compiler.Framework.Context
的用法示例。
在下文中一共展示了Context.GotoPrevious方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
// TODO:
// 1. If first branch is to the next basic block,
// then swap branch condition, replace branch target with jump target, and remove jump instruction.
// part of code: ConditionCode = GetOppositeConditionCode(ConditionCode);
// 2. If the basic block contains only a single jump instruction, rewrite all jumps to avoid it.
protected override void Run()
{
var trace = CreateTrace();
for (int f = 0; f < BasicBlocks.Count - 1; f++)
{
var from = BasicBlocks[f];
var next = BasicBlocks[f + 1];
Context context = new Context(InstructionSet, from, from.EndIndex);
context.GotoPrevious();
while (context.IsEmpty)
{
context.GotoPrevious();
}
if (context.Instruction.FlowControl != FlowControl.UnconditionalBranch)
continue;
Debug.Assert(context.Instruction.FlowControl == FlowControl.UnconditionalBranch);
Debug.Assert(context.BranchTargets.Length == 1);
var target = context.BranchTargets[0];
if (next.Label != target)
continue;
context.Remove();
}
}
示例2: CreateNewBlock
public static Context CreateNewBlock(this InstructionSet instructionSet, BasicBlocks basicBlocks)
{
Context ctx = new Context(instructionSet);
ctx.AppendInstruction(IRInstruction.BlockStart);
int start = ctx.Index;
ctx.AppendInstruction(IRInstruction.BlockEnd);
int last = ctx.Index;
BasicBlock block = basicBlocks.CreateBlockWithAutoLabel(start, last);
ctx.BasicBlock = block;
ctx.GotoPrevious();
return ctx;
}
示例3: ReplaceBranchTargets
/// <summary>
/// Replaces the branch targets.
/// </summary>
/// <param name="block">The current from block.</param>
/// <param name="oldTarget">The current destination block.</param>
/// <param name="newTarget">The new target block.</param>
protected void ReplaceBranchTargets(BasicBlock block, BasicBlock oldTarget, BasicBlock newTarget)
{
// Replace any jump/branch target in block (from) with js
var ctx = new Context(InstructionSet, block, block.EndIndex);
Debug.Assert(ctx.IsBlockEndInstruction);
do
{
ctx.GotoPrevious();
}
while (ctx.IsEmpty);
// Find branch or jump to (to) and replace it with js
while (!ctx.IsBlockStartInstruction)
{
if (ctx.BranchTargets != null)
{
var targets = ctx.BranchTargets;
for (int index = 0; index < targets.Length; index++)
{
if (targets[index] == oldTarget.Label)
targets[index] = newTarget.Label;
}
}
do
{
ctx.GotoPrevious();
}
while (ctx.IsEmpty);
}
}