本文整理汇总了C#中Context.AddBranchTarget方法的典型用法代码示例。如果您正苦于以下问题:C# Context.AddBranchTarget方法的具体用法?C# Context.AddBranchTarget怎么用?C# Context.AddBranchTarget使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Context
的用法示例。
在下文中一共展示了Context.AddBranchTarget方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdateBlockProtectInstructions
private void UpdateBlockProtectInstructions()
{
foreach (var block in BasicBlocks)
{
var context = new Context(block.Last);
while (context.IsEmpty || context.IsBlockEndInstruction || context.Instruction == IRInstruction.Flow)
{
context.GotoPrevious();
}
if (context.Instruction is EndFinallyInstruction)
{
context.SetInstruction(IRInstruction.FinallyEnd);
var entry = FindFinallyHandler(context.Node);
var list = returns.Get(entry);
if (list == null)
return;
context.AppendInstruction(IRInstruction.FinallyReturn);
foreach (var returnBlock in list)
{
context.AddBranchTarget(returnBlock);
}
}
else if (context.Instruction is LeaveInstruction)
{
// Find enclosing finally clause
bool createLink = false;
var entry = FindImmediateExceptionHandler(context.Node);
if (entry != null)
{
if (entry.IsLabelWithinTry(context.Label))
createLink = true;
}
if (createLink)
{
var tryFinallyBlock = context.BranchTargets[0];
returns.Add(entry, tryFinallyBlock);
context.SetInstruction(IRInstruction.TryEnd);
if (entry.HandlerType == ExceptionHandlerType.Finally)
{
var finallyBlock = BasicBlocks.GetByLabel(entry.HandlerStart);
context.AppendInstruction(IRInstruction.CallFinally, finallyBlock, tryFinallyBlock);
}
else
{
context.AppendInstruction(IRInstruction.Jmp, tryFinallyBlock);
}
//Debug.Assert(context.BasicBlock.NextBlocks.Count <= 1);
}
else
{
context.ReplaceInstructionOnly(IRInstruction.ExceptionEnd);
}
}
}
}
示例2: UnaryBranch
/// <summary>
/// Visitation function for UnaryBranch instruction.
/// </summary>
/// <param name="context">The context.</param>
private void UnaryBranch(Context context)
{
var target = context.BranchTargets[0];
Operand first = context.Operand1;
Operand second = ConstantZero;
CIL.OpCode opcode = ((CIL.BaseCILInstruction)context.Instruction).OpCode;
if (opcode == CIL.OpCode.Brtrue || opcode == CIL.OpCode.Brtrue_s)
{
context.SetInstruction(IRInstruction.CompareIntegerBranch, ConditionCode.NotEqual, null, first, second);
context.AddBranchTarget(target);
return;
}
else if (opcode == CIL.OpCode.Brfalse || opcode == CIL.OpCode.Brfalse_s)
{
context.SetInstruction(IRInstruction.CompareIntegerBranch, ConditionCode.Equal, null, first, second);
context.AddBranchTarget(target);
return;
}
throw new NotImplementCompilerException(@"CILTransformationStage.UnaryBranch doesn't support CIL opcode " + opcode);
}
示例3: BinaryBranch
/// <summary>
/// Visitation function for BinaryBranch instruction.
/// </summary>
/// <param name="context">The context.</param>
private void BinaryBranch(Context context)
{
var target = context.BranchTargets[0];
ConditionCode cc = ConvertCondition(((CIL.BaseCILInstruction)context.Instruction).OpCode);
Operand first = context.Operand1;
Operand second = context.Operand2;
if (first.IsR)
{
Operand result = AllocateVirtualRegister(TypeSystem.BuiltIn.I4);
if (first.IsR4)
context.SetInstruction(IRInstruction.CompareFloatR4, cc, result, first, second);
else
context.SetInstruction(IRInstruction.CompareFloatR8, cc, result, first, second);
context.AppendInstruction(IRInstruction.CompareIntegerBranch, ConditionCode.Equal, null, result, Operand.CreateConstant(TypeSystem, 1));
}
else
{
context.SetInstruction(IRInstruction.CompareIntegerBranch, cc, null, first, second);
}
context.AddBranchTarget(target);
}
示例4: BinaryBranch
/// <summary>
/// Visitation function for BinaryBranch instruction.
/// </summary>
/// <param name="context">The context.</param>
private void BinaryBranch(Context context)
{
var target = context.BranchTargets[0];
ConditionCode cc = ConvertCondition(((CIL.BaseCILInstruction)context.Instruction).OpCode);
Operand first = context.Operand1;
Operand second = context.Operand2;
if (first.IsR)
{
Operand comparisonResult = MethodCompiler.CreateVirtualRegister(TypeSystem.BuiltIn.I4);
context.SetInstruction(IRInstruction.FloatCompare, cc, comparisonResult, first, second);
context.AppendInstruction(IRInstruction.IntegerCompareBranch, ConditionCode.Equal, null, comparisonResult, Operand.CreateConstant(TypeSystem, 1));
context.AddBranchTarget(target);
}
else
{
context.SetInstruction(IRInstruction.IntegerCompareBranch, cc, null, first, second);
context.AddBranchTarget(target);
}
}