本文整理汇总了C#中Context.ReplaceInstructionOnly方法的典型用法代码示例。如果您正苦于以下问题:C# Context.ReplaceInstructionOnly方法的具体用法?C# Context.ReplaceInstructionOnly怎么用?C# Context.ReplaceInstructionOnly使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Context
的用法示例。
在下文中一共展示了Context.ReplaceInstructionOnly方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessInstruction
private void ProcessInstruction(Context ctx)
{
if (ctx.Instruction is Load)
{
if (ctx.MosaType != null &&
TypeLayout.IsCompoundType(ctx.MosaType) && !ctx.MosaType.IsUI8 && !ctx.MosaType.IsR8)
{
if (ctx.Result.IsVirtualRegister && !repl.ContainsKey(ctx.Result))
{
repl[ctx.Result] = MethodCompiler.StackLayout.AddStackLocal(ctx.MosaType);
}
ctx.ReplaceInstructionOnly(IRInstruction.CompoundLoad);
}
}
else if (ctx.Instruction is Store)
{
if (ctx.MosaType != null &&
TypeLayout.IsCompoundType(ctx.MosaType) && !ctx.MosaType.IsUI8 && !ctx.MosaType.IsR8)
{
if (ctx.Operand3.IsVirtualRegister && !repl.ContainsKey(ctx.Operand3))
{
repl[ctx.Operand3] = MethodCompiler.StackLayout.AddStackLocal(ctx.Result.Type);
}
ctx.ReplaceInstructionOnly(IRInstruction.CompoundStore);
}
}
else if (ctx.Instruction is Move)
{
if (ctx.Result.Type.Equals(ctx.Operand1.Type) &&
TypeLayout.IsCompoundType(ctx.Result.Type) && !ctx.Result.Type.IsUI8 && !ctx.Result.Type.IsR8)
{
if (ctx.Result.IsVirtualRegister && !repl.ContainsKey(ctx.Result))
{
repl[ctx.Result] = MethodCompiler.StackLayout.AddStackLocal(ctx.Result.Type);
}
if (ctx.Operand1.IsVirtualRegister && !repl.ContainsKey(ctx.Operand1))
{
repl[ctx.Operand1] = MethodCompiler.StackLayout.AddStackLocal(ctx.Operand1.Type);
}
ctx.ReplaceInstructionOnly(IRInstruction.CompoundMove);
}
}
else if (ctx.Instruction is Call)
{
if (ctx.Result != null &&
TypeLayout.IsCompoundType(ctx.Result.Type) && !ctx.Result.Type.IsUI8 && !ctx.Result.Type.IsR8)
{
if (ctx.Result.IsVirtualRegister && !repl.ContainsKey(ctx.Result))
{
repl[ctx.Result] = MethodCompiler.StackLayout.AddStackLocal(ctx.Result.Type);
}
}
}
}
示例2: UpdateBlockProtectInstructions
private void UpdateBlockProtectInstructions()
{
foreach (var block in BasicBlocks)
{
var context = new Context(InstructionSet, block, block.EndIndex);
while (context.IsEmpty || context.IsBlockEndInstruction)
{
context.GotoPrevious();
}
if (context.Instruction is EndFinallyInstruction)
{
context.ReplaceInstructionOnly(IRInstruction.FinallyEnd);
}
else if (context.Instruction is LeaveInstruction)
{
// Find enclosing finally clause
bool createLink = false;
var entry = FindImmediateExceptionHandler(context);
if (entry != null)
{
if (entry.IsLabelWithinTry(context.Label))
createLink = true;
}
if (createLink)
{
var tryEndNext = context.BranchTargets[0];
var tryEndNextBlock = BasicBlocks.GetByLabel(tryEndNext);
if (entry.HandlerType == ExceptionHandlerType.Finally)
{
var finallyBlock = BasicBlocks.GetByLabel(entry.HandlerStart);
context.SetInstruction(IRInstruction.CallFinally, finallyBlock);
context.AppendInstruction(IRInstruction.TryEnd);
}
else
{
context.SetInstruction(IRInstruction.TryEnd);
}
context.AppendInstruction(IRInstruction.Jmp, tryEndNextBlock);
}
else
{
context.ReplaceInstructionOnly(IRInstruction.ExceptionEnd);
}
}
}
}
示例3: Decode
public override void Decode(Context ctx, IInstructionDecoder decoder)
{
if (ctx.HasPrefix && ctx.Previous.Instruction is ConstrainedPrefixInstruction)
{
MosaMethod toBeReplaced = HandleConstrained(ctx, decoder, ctx.Previous);
base.Decode(ctx, decoder);
if (toBeReplaced != null)
{
ctx.MosaMethod = toBeReplaced;
ctx.ReplaceInstructionOnly(CILInstruction.Instructions[(int)OpCode.Call]);
}
}
else
base.Decode(ctx, decoder);
}
示例4: ReplaceWithVmCall
/// <summary>
/// Replaces the instruction with an internal call.
/// </summary>
/// <param name="context">The transformation context.</param>
/// <param name="internalCallTarget">The internal call target.</param>
private void ReplaceWithVmCall(Context context, VmCall internalCallTarget)
{
var method = InternalRuntimeType.FindMethodByName(internalCallTarget.ToString());
if (method == null)
{
method = PlatformInternalRuntimeType.FindMethodByName(internalCallTarget.ToString());
}
Debug.Assert(method != null, "Cannot find method: " + internalCallTarget.ToString());
context.ReplaceInstructionOnly(IRInstruction.Call);
context.SetOperand(0, Operand.CreateSymbolFromMethod(TypeSystem, method));
context.OperandCount = 1;
context.InvokeMethod = method;
}
示例5: Ldloca
/// <summary>
/// Visitation function for Ldloca instruction.
/// </summary>
/// <param name="context">The context.</param>
private void Ldloca(Context context)
{
context.ReplaceInstructionOnly(IRInstruction.AddressOf);
}
示例6:
/// <summary>
/// Visitation function for Castclass instruction.
/// </summary>
/// <param name="context">The context.</param>
void CIL.ICILVisitor.Castclass(Context context)
{
// TODO!
//ReplaceWithVmCall(context, VmCall.Castclass);
context.ReplaceInstructionOnly(IRInstruction.Move); // HACK!
}
示例7: FindImmediateClause
/// <summary>
/// Visitation function for Leave instruction.
/// </summary>
/// <param name="context">The context.</param>
void CIL.ICILVisitor.Leave(Context context)
{
// Find enclosing finally clause
MosaExceptionHandler clause = FindImmediateClause(context);
if (clause.IsLabelWithinTry(context.Label))
{
if (clause != null)
{
// Find finally block
BasicBlock finallyBlock = BasicBlocks.GetByLabel(clause.HandlerOffset);
Context before = context.InsertBefore();
before.SetInstruction(IRInstruction.Call, finallyBlock);
}
}
else if (clause.IsLabelWithinHandler(context.Label))
{
// nothing!
}
else
{
throw new Exception("can not find leave clause");
}
context.ReplaceInstructionOnly(IRInstruction.Jmp);
}
示例8: ProcessLoadInstruction
/// <summary>
/// Replaces the IL load instruction by an appropriate IR move instruction or removes it entirely, if
/// it is a native size.
/// </summary>
/// <param name="context">Provides the transformation context.</param>
private void ProcessLoadInstruction(Context context)
{
Operand source = context.Operand1;
Operand destination = context.Result;
BaseInstruction extension = null;
if (MustSignExtendOnLoad(source.Type))
{
extension = IRInstruction.SignExtendedMove;
}
else if (MustZeroExtendOnLoad(source.Type))
{
extension = IRInstruction.ZeroExtendedMove;
}
if (extension != null)
{
context.SetInstruction(extension, destination, source);
return;
}
context.ReplaceInstructionOnly(IRInstruction.Move);
}
示例9: ToVmBoxCall
/// <summary>
/// Visitation function for Box instruction.
/// </summary>
/// <param name="context">The context.</param>
void CIL.ICILVisitor.Box(Context context)
{
var value = context.Operand1;
var result = context.Result;
var type = context.MosaType;
if (!type.IsValueType)
{
context.ReplaceInstructionOnly(IRInstruction.Move);
return;
}
int typeSize = TypeLayout.GetTypeSize(type);
int alignment = TypeLayout.NativePointerAlignment;
typeSize += (alignment - (typeSize % alignment)) % alignment;
var vmCall = ToVmBoxCall(typeSize);
context.SetInstruction(IRInstruction.Nop);
ReplaceWithVmCall(context, vmCall);
var methodTableSymbol = GetMethodTableSymbol(type);
context.SetOperand(1, methodTableSymbol);
if (vmCall == VmCall.Box)
{
Operand adr = MethodCompiler.CreateVirtualRegister(type.ToManagedPointer());
context.InsertBefore().SetInstruction(IRInstruction.AddressOf, adr, value);
context.SetOperand(2, adr);
context.SetOperand(3, Operand.CreateConstantUnsignedInt(TypeSystem, (uint)typeSize));
context.OperandCount = 4;
}
else
{
context.SetOperand(2, value);
context.OperandCount = 3;
}
context.Result = result;
return;
}
示例10: PerformStaticAllocationOf
private void PerformStaticAllocationOf(Context allocation, Context assignment)
{
MosaType allocatedType = (allocation.InvokeMethod != null) ? allocation.InvokeMethod.DeclaringType : allocation.Result.Type;
MosaField assignmentField = (assignment.Instruction is DupInstruction) ? FindStsfldForDup(assignment).MosaField : assignment.MosaField;
// Get size of type
int typeSize = TypeLayout.GetTypeSize(allocatedType);
// If instruction is newarr then get the size of the element, multiply it by array size, and add array header size
// Also need to align to a 4-byte boundry
if (allocation.Instruction is NewarrInstruction)
typeSize = (TypeLayout.GetTypeSize(allocatedType.ElementType) * (int)allocation.Previous.Operand1.ConstantSignedLongInteger) + (TypeLayout.NativePointerSize * 3);
// Allocate a linker symbol to refer to this allocation. Use the destination field name as the linker symbol name.
var symbolName = MethodCompiler.Linker.CreateSymbol(assignmentField.FullName + @"<<$cctor", SectionKind.ROData, Architecture.NativeAlignment, typeSize);
// Try to get typeDefinitionSymbol if allocatedType isn't a value type
string typeDefinitionSymbol = GetTypeDefinition(allocatedType);
if (typeDefinitionSymbol != null)
MethodCompiler.Linker.Link(LinkType.AbsoluteAddress, BuiltInPatch.I4, symbolName, 0, 0, typeDefinitionSymbol, SectionKind.ROData, 0);
// Issue a load request before the newobj and before the assignment.
Operand symbol1 = InsertLoadBeforeInstruction(assignment, symbolName.Name, assignmentField.FieldType);
assignment.Operand1 = symbol1;
// If the instruction is a newarr and the assignment instruction is a dup then we want to remove it
if (allocation.Instruction is NewarrInstruction && assignment.Instruction is DupInstruction)
assignment.SetInstruction(CILInstruction.Get(OpCode.Ldc_i4), assignment.Result, assignment.Operand1);
// Change the newobj to a call and increase the operand count to include the this ptr.
// If the instruction is a newarr, then just replace with a nop instead
allocation.ResultCount = 0;
if (allocation.Instruction is NewarrInstruction)
{
allocation.OperandCount = 0;
allocation.SetInstruction(CILInstruction.Get(OpCode.Nop));
}
else
{
Operand symbol2 = InsertLoadBeforeInstruction(allocation, symbolName.Name, assignmentField.FieldType);
IEnumerable<Operand> ops = allocation.Operands;
allocation.OperandCount++;
allocation.Operand1 = symbol2;
int i = 0;
foreach (Operand op in ops)
{
i++;
allocation.SetOperand(i, op);
}
allocation.ReplaceInstructionOnly(CILInstruction.Get(OpCode.Call));
}
}
示例11: Replace
private static void Replace(Context context, BaseInstruction floatingPointInstruction, BaseInstruction signedInstruction, BaseInstruction unsignedInstruction)
{
if (context.Result.IsR)
{
context.ReplaceInstructionOnly(floatingPointInstruction);
}
else if (context.Result.IsUnsigned)
{
context.ReplaceInstructionOnly(unsignedInstruction);
}
else
{
context.ReplaceInstructionOnly(signedInstruction);
}
}
示例12: Box
/// <summary>
/// Visitation function for Box instruction.
/// </summary>
/// <param name="context">The context.</param>
private void Box(Context context)
{
var value = context.Operand1;
var result = context.Result;
var type = context.MosaType;
if (!type.IsValueType)
{
Debug.Assert(result.IsVirtualRegister);
Debug.Assert(value.IsVirtualRegister);
var moveInstruction = GetMoveInstruction(type);
context.ReplaceInstructionOnly(moveInstruction);
return;
}
int typeSize = TypeLayout.GetTypeSize(type);
int alignment = TypeLayout.NativePointerAlignment;
typeSize += (alignment - (typeSize % alignment)) % alignment;
VmCall vmCall = VmCall.Box32;
if (type.IsR4)
vmCall = VmCall.BoxR4;
else if (type.IsR8)
vmCall = VmCall.BoxR8;
else if (typeSize <= 4)
vmCall = VmCall.Box32;
else if (typeSize == 8)
vmCall = VmCall.Box64;
else
vmCall = VmCall.Box;
context.SetInstruction(IRInstruction.Nop);
ReplaceWithVmCall(context, vmCall);
context.SetOperand(1, GetRuntimeTypeHandle(type, context));
if (vmCall == VmCall.Box)
{
Operand adr = AllocateVirtualRegister(type.ToManagedPointer());
context.InsertBefore().SetInstruction(IRInstruction.AddressOf, adr, value);
context.SetOperand(2, adr);
context.SetOperand(3, Operand.CreateConstant(TypeSystem, typeSize));
context.OperandCount = 4;
}
else
{
context.SetOperand(2, value);
context.OperandCount = 3;
}
context.Result = result;
context.ResultCount = 1;
}
示例13: Branch
/// <summary>
/// Visitation function for Branch instruction.
/// </summary>
/// <param name="context">The context.</param>
private void Branch(Context context)
{
context.ReplaceInstructionOnly(IRInstruction.Jmp);
}
示例14: UnboxAny
/// <summary>
/// Visitation function for Unbox.Any instruction.
/// </summary>
/// <param name="context">The context.</param>
private void UnboxAny(Context context)
{
var value = context.Operand1;
var result = context.Result;
var type = context.MosaType;
if (!type.IsValueType)
{
var moveInstruction = GetMoveInstruction(type);
context.ReplaceInstructionOnly(moveInstruction);
return;
}
int typeSize = TypeLayout.GetTypeSize(type);
int alignment = TypeLayout.NativePointerAlignment;
typeSize += (alignment - (typeSize % alignment)) % alignment;
var vmCall = ToVmUnboxCall(typeSize);
context.SetInstruction(IRInstruction.Nop);
ReplaceWithVmCall(context, vmCall);
context.SetOperand(1, value);
if (vmCall == VmCall.Unbox)
{
Operand adr = AllocateVirtualRegister(type.ToManagedPointer());
context.InsertBefore().SetInstruction(IRInstruction.AddressOf, adr, MethodCompiler.AddStackLocal(type));
context.SetOperand(2, adr);
context.SetOperand(3, Operand.CreateConstant(TypeSystem, typeSize));
context.OperandCount = 4;
}
else
{
context.OperandCount = 2;
}
Operand tmp = AllocateVirtualRegister(type.ToManagedPointer());
context.Result = tmp;
context.ResultCount = 1;
var size = GetInstructionSize(type);
if (StoreOnStack(type))
{
context.AppendInstruction(IRInstruction.CompoundLoad, result, tmp, ConstantZero);
context.MosaType = type;
}
else
{
var loadInstruction = GetLoadInstruction(type);
context.AppendInstruction(loadInstruction, size, result, tmp, ConstantZero);
context.MosaType = type;
}
}
示例15: Switch
/// <summary>
/// Visitation function for Switch instruction.
/// </summary>
/// <param name="context">The context.</param>
private void Switch(Context context)
{
context.ReplaceInstructionOnly(IRInstruction.Switch);
}