本文整理汇总了C#中Context.SetBranch方法的典型用法代码示例。如果您正苦于以下问题:C# Context.SetBranch方法的具体用法?C# Context.SetBranch怎么用?C# Context.SetBranch使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Context
的用法示例。
在下文中一共展示了Context.SetBranch方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Decode
/// <summary>
/// Decodes the specified instruction.
/// </summary>
/// <param name="ctx">The context.</param>
/// <param name="decoder">The instruction decoder, which holds the code stream.</param>
public override void Decode(Context ctx, IInstructionDecoder decoder)
{
// Decode base classes first
base.Decode(ctx, decoder);
// Read the branch target
// Is this a short branch target?
if (opcode == OpCode.Brfalse_s || opcode == OpCode.Brtrue_s)
{
sbyte target = decoder.DecodeSByte();
ctx.SetBranch(target);
}
else if (opcode == OpCode.Brfalse || opcode == OpCode.Brtrue)
{
int target = decoder.DecodeInt();
ctx.SetBranch(target);
}
else if (opcode == OpCode.Switch)
{
// Don't do anything, the derived class will do everything
}
else
{
throw new NotSupportedException(@"Invalid opcode " + opcode.ToString() + " specified for UnaryBranchInstruction.");
}
}
示例2: Decode
/// <summary>
/// Decodes the specified instruction.
/// </summary>
/// <param name="ctx">The context.</param>
/// <param name="decoder">The instruction decoder, which holds the code stream.</param>
public override void Decode(Context ctx, IInstructionDecoder decoder)
{
// Decode base classes first
base.Decode(ctx, decoder);
// Read the branch target
// Is this a short branch target?
// FIXME: Remove unary branch instructions from this list.
if (_opcode == OpCode.Beq_s || _opcode == OpCode.Bge_s || _opcode == OpCode.Bge_un_s || _opcode == OpCode.Bgt_s ||
_opcode == OpCode.Bgt_un_s || _opcode == OpCode.Ble_s || _opcode == OpCode.Ble_un_s || _opcode == OpCode.Blt_s ||
_opcode == OpCode.Blt_un_s || _opcode == OpCode.Bne_un_s) {
sbyte target;
decoder.Decode(out target);
ctx.SetBranch(target);
}
else if (_opcode == OpCode.Beq || _opcode == OpCode.Bge || _opcode == OpCode.Bge_un || _opcode == OpCode.Bgt ||
_opcode == OpCode.Bgt_un || _opcode == OpCode.Ble || _opcode == OpCode.Ble_un || _opcode == OpCode.Blt ||
_opcode == OpCode.Blt_un || _opcode == OpCode.Bne_un) {
int target;
decoder.Decode(out target);
ctx.SetBranch(target);
}
else {
throw new NotSupportedException(@"Invalid branch opcode specified for BinaryBranchInstruction");
}
}
示例3: Decode
/// <summary>
/// Decodes the specified instruction.
/// </summary>
/// <param name="ctx">The context.</param>
/// <param name="decoder">The instruction decoder, which holds the code stream.</param>
public override void Decode(Context ctx, IInstructionDecoder decoder)
{
// Decode base classes first
base.Decode(ctx, decoder);
// Read the branch target
// Is this a short branch target?
// FIXME: Remove unary branch instructions from this list.
ctx.SetBranch((int)decoder.Instruction.Operand);
}
示例4: Decode
/// <summary>
/// Decodes the specified instruction.
/// </summary>
/// <param name="ctx">The context.</param>
/// <param name="decoder">The instruction decoder, which holds the code stream.</param>
public override void Decode(Context ctx, IInstructionDecoder decoder)
{
// Decode base classes first
base.Decode(ctx, decoder);
switch (opcode)
{
case OpCode.Leave_s:
{
sbyte sb = decoder.DecodeSByte();
ctx.SetBranch(sb);
break;
}
case OpCode.Leave:
{
int sb = decoder.DecodeInt();
ctx.SetBranch(sb);
break;
}
}
}
示例5: Decode
/// <summary>
/// Decodes the specified instruction.
/// </summary>
/// <param name="ctx">The context.</param>
/// <param name="decoder">The instruction decoder, which holds the code stream.</param>
public override void Decode(Context ctx, IInstructionDecoder decoder)
{
// Decode bases first
base.Decode(ctx, decoder);
switch (opcode)
{
case OpCode.Br_s:
{
sbyte target = decoder.DecodeSByte();
ctx.SetBranch(target);
}
break;
case OpCode.Br:
{
int target = decoder.DecodeInt();
ctx.SetBranch(target);
break;
}
}
}
示例6: Decode
/// <summary>
/// Decodes the specified instruction.
/// </summary>
/// <param name="ctx">The context.</param>
/// <param name="decoder">The instruction decoder, which holds the code stream.</param>
public override void Decode(Context ctx, IInstructionDecoder decoder)
{
// Decode base classes first
base.Decode(ctx, decoder);
if (OpCode.Ret != opcode)
throw new ArgumentException(@"Invalid opcode.", @"code");
if (decoder.Method.Signature.ReturnType.Type == CilElementType.Void)
ctx.OperandCount = 0;
else
ctx.OperandCount = 1;
ctx.SetBranch(Int32.MaxValue);
}
示例7: Context
/// <summary>
/// Performs stage specific processing on the compiler context.
/// </summary>
void IMethodCompilerStage.Run()
{
if (methodCompiler.Compiler.PlugSystem.GetPlugMethod(methodCompiler.Method) != null)
return;
if (!methodCompiler.Method.HasCode)
return;
// Create the prologue block
Context context = new Context(instructionSet);
// Add a jump instruction to the first block from the prologue
context.AppendInstruction(IRInstruction.Jmp);
context.SetBranch(0);
context.Label = BasicBlock.PrologueLabel;
prologue = basicBlocks.CreateBlock(BasicBlock.PrologueLabel, context.Index);
basicBlocks.AddHeaderBlock(prologue);
SplitIntoBlocks(0);
// Create the epilogue block
context = new Context(instructionSet);
// Add null instruction, necessary to generate a block index
context.AppendInstruction(null);
context.Label = BasicBlock.EpilogueLabel;
epilogue = basicBlocks.CreateBlock(BasicBlock.EpilogueLabel, context.Index);
// Link all the blocks together
BuildBlockLinks(prologue);
foreach (ExceptionHandlingClause exceptionClause in methodCompiler.ExceptionClauseHeader.Clauses)
{
if (exceptionClause.HandlerOffset != 0)
{
BasicBlock basicBlock = basicBlocks.GetByLabel(exceptionClause.HandlerOffset);
BuildBlockLinks(basicBlock);
basicBlocks.AddHeaderBlock(basicBlock);
}
if (exceptionClause.FilterOffset != 0)
{
BasicBlock basicBlock = basicBlocks.GetByLabel(exceptionClause.FilterOffset);
BuildBlockLinks(basicBlock);
basicBlocks.AddHeaderBlock(basicBlock);
}
}
}
示例8: ConvertCondition
/// <summary>
/// Visitation function for BinaryBranch instruction.
/// </summary>
/// <param name="context">The context.</param>
void CIL.ICILVisitor.BinaryBranch(Context context)
{
int 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.CreateConstantSignedInt(TypeSystem, 1));
context.SetBranch(target);
}
else
{
context.SetInstruction(IRInstruction.IntegerCompareBranch, cc, null, first, second);
context.SetBranch(target);
}
}
示例9: if
/// <summary>
/// Visitation function for UnaryBranch instruction.
/// </summary>
/// <param name="context">The context.</param>
void CIL.ICILVisitor.UnaryBranch(Context context)
{
int target = context.BranchTargets[0];
Operand first = context.Operand1;
Operand second = Operand.CreateConstantSignedInt(TypeSystem, (int)0);
CIL.OpCode opcode = ((CIL.BaseCILInstruction)context.Instruction).OpCode;
if (opcode == CIL.OpCode.Brtrue || opcode == CIL.OpCode.Brtrue_s)
{
context.SetInstruction(IRInstruction.IntegerCompareBranch, ConditionCode.NotEqual, null, first, second);
context.SetBranch(target);
return;
}
else if (opcode == CIL.OpCode.Brfalse || opcode == CIL.OpCode.Brfalse_s)
{
context.SetInstruction(IRInstruction.IntegerCompareBranch, ConditionCode.Equal, null, first, second);
context.SetBranch(target);
return;
}
throw new NotSupportedException(@"CILTransformationStage.UnaryBranch doesn't support CIL opcode " + opcode);
}
示例10: Run
protected override void Run()
{
if (!HasProtectedRegions)
return;
var exceptionRegister = Operand.CreateCPURegister(TypeLayout.TypeSystem.BuiltIn.Pointer, Architecture.ExceptionRegister);
var nullOperand = Operand.GetNull(TypeSystem);
CreateExceptionReturnOperands();
for (int i = 0; i < BasicBlocks.Count; i++)
{
var block = BasicBlocks[i];
for (var ctx = new Context(InstructionSet, block); !ctx.IsBlockEndInstruction; ctx.GotoNext())
{
if (ctx.IsEmpty)
continue;
if (ctx.Instruction == IRInstruction.Throw)
{
var method = PlatformInternalRuntimeType.FindMethodByName("ExceptionHandler");
ctx.SetInstruction(IRInstruction.Move, exceptionRegister, ctx.Operand1);
ctx.AppendInstruction(IRInstruction.Call, null, Operand.CreateSymbolFromMethod(TypeSystem, method));
ctx.MosaMethod = method;
}
else if (ctx.Instruction == IRInstruction.CallFinally)
{
var target = ctx.BranchTargets[0];
ctx.SetInstruction(IRInstruction.KillAll);
ctx.AppendInstruction(IRInstruction.Move, exceptionRegister, nullOperand);
ctx.AppendInstruction(IRInstruction.InternalCall);
ctx.SetBranch(target);
}
else if (ctx.Instruction == IRInstruction.FinallyStart)
{
var header = FindImmediateExceptionHandler(ctx);
var headerBlock = BasicBlocks.GetByLabel(header.HandlerStart);
var v1 = AllocateVirtualRegister(TypeSystem.BuiltIn.Pointer);
ctx.SetInstruction(IRInstruction.KillAll);
ctx.AppendInstruction(IRInstruction.Gen, exceptionRegister);
ctx.AppendInstruction(IRInstruction.Move, exceptionRegisters[headerBlock], exceptionRegister);
}
else if (ctx.Instruction == IRInstruction.FinallyEnd)
{
var header = FindImmediateExceptionHandler(ctx);
var headerBlock = BasicBlocks.GetByLabel(header.HandlerStart);
var newBlocks = CreateNewBlocksWithContexts(2);
ctx.SetInstruction(IRInstruction.Move, exceptionRegister, exceptionRegisters[headerBlock]);
ctx.AppendInstruction(IRInstruction.IntegerCompareBranch, ConditionCode.Equal, null, exceptionRegister, nullOperand);
ctx.SetBranch(newBlocks[0].BasicBlock);
ctx.AppendInstruction(IRInstruction.Jmp, newBlocks[1].BasicBlock);
LinkBlocks(ctx, newBlocks[0]);
LinkBlocks(ctx, newBlocks[1]);
newBlocks[0].AppendInstruction(IRInstruction.InternalReturn);
var method = PlatformInternalRuntimeType.FindMethodByName("ExceptionHandler");
newBlocks[1].AppendInstruction(IRInstruction.Call, null, Operand.CreateSymbolFromMethod(TypeSystem, method));
newBlocks[1].MosaMethod = method;
}
else if (ctx.Instruction == IRInstruction.ExceptionStart)
{
ctx.SetInstruction(IRInstruction.KillAll);
ctx.AppendInstruction(IRInstruction.Gen, exceptionRegister);
ctx.AppendInstruction(IRInstruction.Move, ctx.Result, exceptionRegister);
}
else if (ctx.Instruction == IRInstruction.ExceptionEnd)
{
int target = ctx.BranchTargets[0];
ctx.SetInstruction(IRInstruction.Jmp);
ctx.SetBranch(target);
}
}
}
}
示例11: BinaryBranch
/// <summary>
/// Visitation function for BinaryBranch instruction.
/// </summary>
/// <param name="context">The context.</param>
public void BinaryBranch(Context context)
{
int target = context.BranchTargets[0];
ConditionCode cc = ConvertCondition(((CIL.ICILInstruction)context.Instruction).OpCode);
Operand first = context.Operand1;
Operand second = context.Operand2;
if (first.StackType == StackTypeCode.F)
{
Operand comparisonResult = methodCompiler.CreateVirtualRegister(BuiltInSigType.Int32);
context.SetInstruction(IRInstruction.FloatingPointCompare, comparisonResult, first, second);
context.ConditionCode = cc;
context.AppendInstruction(IRInstruction.IntegerCompareBranch, null, comparisonResult, new ConstantOperand(BuiltInSigType.IntPtr, 1));
context.ConditionCode = ConditionCode.Equal;
context.SetBranch(target);
}
else
{
context.SetInstruction(IRInstruction.IntegerCompareBranch, null, first, second);
context.ConditionCode = cc;
context.SetBranch(target);
}
}
示例12: UnaryBranch
/// <summary>
/// Visitation function for UnaryBranch instruction.
/// </summary>
/// <param name="context">The context.</param>
public void UnaryBranch(Context context)
{
int target = context.BranchTargets[0];
ConditionCode cc;
Operand first = context.Operand1;
Operand second = ConstantOperand.I4_0;
CIL.OpCode opcode = ((CIL.ICILInstruction)context.Instruction).OpCode;
if (opcode == CIL.OpCode.Brtrue || opcode == CIL.OpCode.Brtrue_s)
{
cc = ConditionCode.NotEqual;
}
else if (opcode == CIL.OpCode.Brfalse || opcode == CIL.OpCode.Brfalse_s)
{
cc = ConditionCode.Equal;
}
else
{
throw new NotSupportedException(@"CILTransformationStage.UnaryBranch doesn't support CIL opcode " + opcode);
}
context.SetInstruction(IRInstruction.IntegerCompareBranch, null, first, second);
context.ConditionCode = cc;
context.SetBranch(target);
}
示例13: BinaryBranch
/// <summary>
/// Visitation function for BinaryBranch instruction.
/// </summary>
/// <param name="context">The context.</param>
public void BinaryBranch(Context context)
{
IBranch branch = context.Branch;
ConditionCode cc = ConvertCondition(((CIL.ICILInstruction)context.Instruction).OpCode);
Operand first = context.Operand1;
Operand second = context.Operand2;
if (first.StackType == StackTypeCode.F)
{
Operand comparisonResult = this.methodCompiler.CreateTemporary(BuiltInSigType.Int32);
context.SetInstruction(Instruction.FloatingPointCompareInstruction, comparisonResult, first, second);
context.ConditionCode = cc;
context.SetInstruction(Instruction.IntegerCompareBranchInstruction, null, comparisonResult, new ConstantOperand(BuiltInSigType.IntPtr, 1));
context.ConditionCode = ConditionCode.Equal;
context.SetBranch(branch.Targets[0]);
}
else
{
context.SetInstruction(Instruction.IntegerCompareBranchInstruction, null, first, second);
context.ConditionCode = cc;
context.SetBranch(branch.Targets[0]);
}
}
示例14: UnaryBranch
/// <summary>
/// Visitation function for UnaryBranch instruction.
/// </summary>
/// <param name="context">The context.</param>
public void UnaryBranch(Context context)
{
IBranch branch = context.Branch;
ConditionCode cc;
Operand first = context.Operand1;
Operand second = new ConstantOperand(BuiltInSigType.Int32, 0UL);
CIL.OpCode opcode = ((CIL.ICILInstruction)context.Instruction).OpCode;
if (opcode == CIL.OpCode.Brtrue || opcode == CIL.OpCode.Brtrue_s)
{
cc = ConditionCode.NotEqual;
}
else if (opcode == CIL.OpCode.Brfalse || opcode == CIL.OpCode.Brfalse_s)
{
cc = ConditionCode.Equal;
}
else
{
throw new NotSupportedException(@"CILTransformationStage.UnaryBranch doesn't support CIL opcode " + opcode);
}
context.SetInstruction(Instruction.IntegerCompareBranchInstruction, null, first, second);
context.ConditionCode = cc;
context.SetBranch(branch.Targets[0]);
}