本文整理汇总了C#中Mosa.Runtime.CompilerFramework.Context.SliceBefore方法的典型用法代码示例。如果您正苦于以下问题:C# Context.SliceBefore方法的具体用法?C# Context.SliceBefore怎么用?C# Context.SliceBefore使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mosa.Runtime.CompilerFramework.Context
的用法示例。
在下文中一共展示了Context.SliceBefore方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SplitIntoBlocks
/// <summary>
/// Finds all targets.
/// </summary>
/// <param name="index">The index.</param>
private void SplitIntoBlocks(int index)
{
Dictionary<int, int> targets = new Dictionary<int, int>();
targets.Add(index, -1);
// Find out all targets labels
for (Context ctx = new Context(InstructionSet, index); !ctx.EndOfInstruction; ctx.GotoNext())
{
switch (ctx.Instruction.FlowControl)
{
case FlowControl.Next: continue;
case FlowControl.Call: continue;
case FlowControl.Break: goto case FlowControl.Branch;
case FlowControl.Return: continue;
case FlowControl.Throw: goto case FlowControl.Branch;
case FlowControl.Branch:
// Unconditional branch
Debug.Assert(ctx.Branch.Targets.Length == 1);
if (!targets.ContainsKey(ctx.Branch.Targets[0]))
targets.Add(ctx.Branch.Targets[0], -1);
continue;
case FlowControl.Switch: goto case FlowControl.ConditionalBranch;
case FlowControl.ConditionalBranch:
// Conditional branch with multiple targets
foreach (int target in ctx.Branch.Targets)
if (!targets.ContainsKey(target))
targets.Add(target, -1);
int next = ctx.Next.Label;
if (!targets.ContainsKey(next))
targets.Add(next, -1);
continue;
default:
Debug.Assert(false);
break;
}
}
bool slice = false;
for (Context ctx = new Context(InstructionSet, index); !ctx.EndOfInstruction; ctx.GotoNext())
{
FlowControl flow;
if (targets.ContainsKey(ctx.Label))
{
CreateBlock(ctx.Label, ctx.Index);
if (!ctx.IsFirstInstruction)
{
Context prev = ctx.Previous;
flow = prev.Instruction.FlowControl;
if (flow == FlowControl.Next || flow == FlowControl.Call || flow == FlowControl.ConditionalBranch || flow == FlowControl.Switch)
{
// This jump joins fall-through blocks, by giving them a proper end.
prev.AppendInstruction(CIL.Instruction.Get(CIL.OpCode.Br));
prev.SetBranch(ctx.Label);
prev.SliceAfter();
}
}
targets.Remove(ctx.Label);
}
if (slice)
ctx.SliceBefore();
flow = ctx.Instruction.FlowControl;
slice = (flow == FlowControl.Return || flow == FlowControl.Branch || flow == FlowControl.ConditionalBranch || flow == FlowControl.Break || flow == FlowControl.Throw);
}
Debug.Assert(targets.Count <= 1);
if (FindBlock(0) == null)
CreateBlock(0, index);
}