本文整理汇总了C#中Mosa.Compiler.Framework.Context.SetInstruction方法的典型用法代码示例。如果您正苦于以下问题:C# Context.SetInstruction方法的具体用法?C# Context.SetInstruction怎么用?C# Context.SetInstruction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mosa.Compiler.Framework.Context
的用法示例。
在下文中一共展示了Context.SetInstruction方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: foreach
/// <summary>
/// Replaces the intrinsic call site
/// </summary>
/// <param name="context">The context.</param>
/// <param name="typeSystem">The type system.</param>
void IIntrinsicPlatformMethod.ReplaceIntrinsicCall(Context context, ITypeSystem typeSystem, IList<RuntimeParameter> parameters)
{
var result = context.Result;
var op1 = context.Operand1;
var op2 = context.Operand2;
var constant = Operand.CreateConstant(BuiltInSigType.IntPtr, parameters.Count * 4);
var eax = Operand.CreateCPURegister(BuiltInSigType.IntPtr, GeneralPurposeRegister.EAX); // FIXME - need access to virtual register allocator
var edx = Operand.CreateCPURegister(BuiltInSigType.IntPtr, GeneralPurposeRegister.EDX); // FIXME - need access to virtual register allocator
var esp = Operand.CreateCPURegister(BuiltInSigType.IntPtr, GeneralPurposeRegister.ESP); // FIXME - need access to virtual register allocator
var ebp = Operand.CreateCPURegister(BuiltInSigType.IntPtr, GeneralPurposeRegister.EBP); // FIXME - need access to virtual register allocator
context.SetInstruction(X86.Sub, esp, constant);
context.AppendInstruction(X86.Mov, edx, esp);
var size = parameters.Count * 4 + 4;
foreach (var parameter in parameters)
{
context.AppendInstruction(X86.Mov, Operand.CreateMemoryAddress(BuiltInSigType.IntPtr, edx, new IntPtr(size - 4)), Operand.CreateMemoryAddress(BuiltInSigType.IntPtr, ebp, new IntPtr(size + 4)));
size -= 4;
}
context.AppendInstruction(X86.Mov, Operand.CreateMemoryAddress(BuiltInSigType.IntPtr, edx, new IntPtr(size - 4)), op1);
context.AppendInstruction(X86.Mov, eax, op2);
context.AppendInstruction(X86.Call, null, eax);
context.AppendInstruction(X86.Add, esp, constant);
context.AppendInstruction(X86.Mov, result, Operand.CreateCPURegister(result.Type, GeneralPurposeRegister.EAX)); // FIXME - need access to virtual register allocator
}
示例2: Mov
/// <summary>
/// Visitation function for <see cref="IX86Visitor.Mov"/> instructions.
/// </summary>
/// <param name="context">The context.</param>
public void Mov(Context context)
{
if (context.Result.IsCPURegister && context.Operand1.IsMemoryAddress)
{
context.SetInstruction(X86.MovLoad,
//context.Size,
context.Result,
(context.Operand1.IsLabel || context.Operand1.IsSymbol || context.Operand1.IsField)
? context.Operand1
: Operand.CreateCPURegister(context.Operand1.Type, context.Operand1.EffectiveOffsetBase),
Operand.CreateConstant(MethodCompiler.TypeSystem, (int)context.Operand1.Displacement)
);
}
if (context.Result.IsMemoryAddress && (context.Operand1.IsCPURegister /*|| context.Operand1.IsConstant*/))
{
context.SetInstruction(X86.MovStore,
//InstructionSize.Size32,
null,
(context.Result.IsLabel || context.Result.IsSymbol || context.Result.IsField)
? context.Result
: Operand.CreateCPURegister(context.Result.Type, context.Result.EffectiveOffsetBase),
Operand.CreateConstant(MethodCompiler.TypeSystem, (int)context.Result.Displacement),
context.Operand1
);
}
}
示例3:
/// <summary>
/// Replaces the intrinsic call site
/// </summary>
/// <param name="context">The context.</param>
/// <param name="typeSystem">The type system.</param>
void IIntrinsicPlatformMethod.ReplaceIntrinsicCall(Context context, BaseMethodCompiler methodCompiler)
{
var result = context.Result;
var dividend = context.Operand1;
var divisor = context.Operand2;
if (result.IsR8)
{
var xmm1 = methodCompiler.CreateVirtualRegister(methodCompiler.TypeSystem.BuiltIn.R8);
var xmm2 = methodCompiler.CreateVirtualRegister(methodCompiler.TypeSystem.BuiltIn.R8);
var xmm3 = methodCompiler.CreateVirtualRegister(methodCompiler.TypeSystem.BuiltIn.R8);
var size = InstructionSize.Size64;
context.SetInstruction(X86.Divsd, size, xmm1, dividend, divisor);
context.AppendInstruction(X86.Roundsd, size, xmm2, xmm1, Operand.CreateConstant(methodCompiler.TypeSystem.BuiltIn.U1, 0x3));
context.AppendInstruction(X86.Mulsd, size, xmm3, divisor, xmm2);
context.AppendInstruction(X86.Subsd, size, result, dividend, xmm3);
}
else
{
var xmm1 = methodCompiler.CreateVirtualRegister(methodCompiler.TypeSystem.BuiltIn.R4);
var xmm2 = methodCompiler.CreateVirtualRegister(methodCompiler.TypeSystem.BuiltIn.R4);
var xmm3 = methodCompiler.CreateVirtualRegister(methodCompiler.TypeSystem.BuiltIn.R4);
var size = InstructionSize.Size32;
context.SetInstruction(X86.Divss, size, xmm1, dividend, divisor);
context.AppendInstruction(X86.Roundss, size, xmm2, xmm1, Operand.CreateConstant(methodCompiler.TypeSystem.BuiltIn.U1, 0x3));
context.AppendInstruction(X86.Mulss, size, xmm3, divisor, xmm2);
context.AppendInstruction(X86.Subss, size, result, dividend, xmm3);
}
}
示例4: EmitFloatingPointConstants
/// <summary>
/// Emits the constant operands.
/// </summary>
/// <param name="node">The node.</param>
protected void EmitFloatingPointConstants(InstructionNode node)
{
for (int i = 0; i < node.OperandCount; i++)
{
var operand = node.GetOperand(i);
if (operand == null || !operand.IsConstant || !operand.IsR)
continue;
if (operand.IsUnresolvedConstant)
continue;
var v1 = AllocateVirtualRegister(operand.Type);
var symbol = (operand.IsR4) ?
MethodCompiler.Linker.GetConstantSymbol(operand.ConstantSingleFloatingPoint)
: MethodCompiler.Linker.GetConstantSymbol(operand.ConstantDoubleFloatingPoint);
var s1 = Operand.CreateLabel(operand.Type, symbol.Name);
var before = new Context(node).InsertBefore();
if (operand.IsR4)
{
before.SetInstruction(X86.MovssLoad, InstructionSize.Size32, v1, s1, ConstantZero);
}
else
{
before.SetInstruction(X86.MovsdLoad, InstructionSize.Size64, v1, s1, ConstantZero);
}
node.SetOperand(i, v1);
}
}
示例5: while
/// <summary>
/// Replaces the intrinsic call site
/// </summary>
/// <param name="context">The context.</param>
/// <param name="typeSystem">The type system.</param>
void IIntrinsicPlatformMethod.ReplaceIntrinsicCall(Context context, BaseMethodCompiler methodCompiler)
{
Operand v0 = context.Operand1;
Operand v1 = context.Operand2;
Operand v2 = context.Operand3;
Operand v3 = context.GetOperand(3);
Operand esp = Operand.CreateCPURegister(methodCompiler.TypeSystem.BuiltIn.I4, GeneralPurposeRegister.ESP);
Operand ebp = Operand.CreateCPURegister(methodCompiler.TypeSystem.BuiltIn.I4, GeneralPurposeRegister.EBP);
Operand eax = Operand.CreateCPURegister(methodCompiler.TypeSystem.BuiltIn.I4, GeneralPurposeRegister.EAX);
Operand ebx = Operand.CreateCPURegister(methodCompiler.TypeSystem.BuiltIn.I4, GeneralPurposeRegister.EBX);
Operand ecx = Operand.CreateCPURegister(methodCompiler.TypeSystem.BuiltIn.I4, GeneralPurposeRegister.ECX);
Operand exceptionRegister = Operand.CreateCPURegister(methodCompiler.TypeSystem.BuiltIn.Object, methodCompiler.Architecture.ExceptionRegister);
// Move all virtual registers into physical registers - necessary since stack frame pointer will change
context.SetInstruction(X86.Mov, eax, v0);
context.AppendInstruction(X86.Mov, ebx, v1);
context.AppendInstruction(X86.Mov, ecx, v2);
context.AppendInstruction(X86.Mov, exceptionRegister, v3);
// Update the frame and stack registers
context.AppendInstruction(X86.Mov, ebp, ecx);
context.AppendInstruction(X86.Mov, esp, ebx);
context.AppendInstruction(X86.Jmp, null, eax);
// future - common code (refactor opportunity)
context.GotoNext();
// Remove all remaining instructions in block and clear next block list
while (!context.IsBlockEndInstruction)
{
if (!context.IsEmpty)
{
context.SetInstruction(X86.Nop);
}
context.GotoNext();
}
var nextBlocks = context.Block.NextBlocks;
foreach (var next in nextBlocks)
{
next.PreviousBlocks.Remove(context.Block);
}
nextBlocks.Clear();
}
示例6: AddEpilogueInstructions
/// <summary>
/// Adds the epilogue instructions.
/// </summary>
/// <param name="context">The context.</param>
private void AddEpilogueInstructions(Context context)
{
Operand ebp = Operand.CreateCPURegister(TypeSystem.BuiltIn.I4, GeneralPurposeRegister.EBP);
Operand esp = Operand.CreateCPURegister(TypeSystem.BuiltIn.I4, GeneralPurposeRegister.ESP);
Operand edx = Operand.CreateCPURegister(TypeSystem.BuiltIn.I4, GeneralPurposeRegister.EDX);
Operand edi = Operand.CreateCPURegister(TypeSystem.BuiltIn.I4, GeneralPurposeRegister.EDI);
Operand ecx = Operand.CreateCPURegister(TypeSystem.BuiltIn.I4, GeneralPurposeRegister.ECX);
Operand ebx = Operand.CreateCPURegister(TypeSystem.BuiltIn.I4, GeneralPurposeRegister.EBX);
context.SetInstruction(X86.Nop);
if (SaveRegisters)
{
context.AppendInstruction(X86.Pop, ebx);
context.AppendInstruction(X86.Pop, ecx);
context.AppendInstruction(X86.Pop, edi);
// Save EDX for int32 return values (or do not save EDX for non-int64 return values)
if (!MethodCompiler.Method.Signature.ReturnType.IsUI8)
{
context.AppendInstruction(X86.Pop, edx);
}
}
if (MethodCompiler.StackLayout.StackSize != 0)
{
context.AppendInstruction(X86.Add, esp, esp, Operand.CreateConstantSignedInt(TypeSystem, -MethodCompiler.StackLayout.StackSize));
}
context.AppendInstruction(X86.Pop, ebp);
context.AppendInstruction(X86.Ret);
}
示例7: FoldMulSInstruction
/// <summary>
/// Folds the mul S instruction.
/// </summary>
/// <param name="context">The context.</param>
private void FoldMulSInstruction(Context context)
{
var cA = this.LoadSignedInteger(context.Operand1);
var cB = this.LoadSignedInteger(context.Operand2);
context.SetInstruction(Instruction.MoveInstruction, context.Result, new ConstantOperand(context.Result.Type, cA * cB));
}
示例8: Div
/// <summary>
/// Visitation function for <see cref="IX86Visitor.Div"/> instructions.
/// </summary>
/// <param name="context">The context.</param>
public void Div(Context context)
{
if (context.Result.IsCPURegister && context.Result2.IsCPURegister && context.Operand1.IsCPURegister)
if (context.Result.Register == GeneralPurposeRegister.EDX &&
context.Result2.Register == GeneralPurposeRegister.EAX &&
context.Operand1.Register == GeneralPurposeRegister.EDX &&
context.Operand2.Register == GeneralPurposeRegister.EAX)
return;
Operand operand1 = context.Operand1;
Operand operand2 = context.Operand2;
Operand operand3 = context.Operand3;
Operand result = context.Result;
Operand result2 = context.Result2;
Operand EAX = Operand.CreateCPURegister(TypeSystem.BuiltIn.I4, GeneralPurposeRegister.EAX);
Operand EDX = Operand.CreateCPURegister(TypeSystem.BuiltIn.I4, GeneralPurposeRegister.EDX);
context.SetInstruction(X86.Mov, EDX, operand1);
context.AppendInstruction(X86.Mov, EAX, operand2);
if (operand3.IsCPURegister)
{
context.AppendInstruction2(X86.Div, EDX, EAX, EDX, EAX, operand3);
}
else
{
Operand v3 = AllocateVirtualRegister(TypeSystem.BuiltIn.I4);
context.AppendInstruction(X86.Mov, v3, operand3);
context.AppendInstruction2(X86.Div, EDX, EAX, EDX, EAX, v3);
}
context.AppendInstruction(X86.Mov, result2, EAX);
context.AppendInstruction(X86.Mov, result, EDX);
}
示例9: HandleSplitAnd
private void HandleSplitAnd(Context context)
{
Operand r8 = Operand.CreateCPURegister(context.Operand1.Type, GeneralPurposeRegister.R8);
context.SetInstruction(AVR32.Mov, r8, context.Operand1);
context.AppendInstruction(AVR32.And, context.Result, r8);
}
示例10:
/// <summary>
/// Replaces the intrinsic call site
/// </summary>
/// <param name="context">The context.</param>
/// <param name="typeSystem">The type system.</param>
void IIntrinsicPlatformMethod.ReplaceIntrinsicCall(Context context, BaseMethodCompiler methodCompiler)
{
var zero = Operand.CreateConstant(methodCompiler.TypeSystem.BuiltIn.I4, 0);
var MultibootEAX = Operand.CreateUnmanagedSymbolPointer(methodCompiler.TypeSystem, Multiboot0695Stage.MultibootEAX);
context.SetInstruction(IRInstruction.Load2, context.Result, MultibootEAX, zero);
}
示例11: RegisterOperand
/// <summary>
/// Replaces the intrinsic call site
/// </summary>
/// <param name="context">The context.</param>
/// <param name="typeSystem">The type system.</param>
void IIntrinsicMethod.ReplaceIntrinsicCall(Context context, ITypeSystem typeSystem, IList<RuntimeParameter> parameters)
{
var result = context.Result;
//var op1 = context.Operand1;
var op2 = context.Operand2;
var eax = new RegisterOperand(BuiltInSigType.IntPtr, GeneralPurposeRegister.EAX);
var edx = new RegisterOperand(BuiltInSigType.IntPtr, GeneralPurposeRegister.EDX);
var esp = new RegisterOperand(BuiltInSigType.IntPtr, GeneralPurposeRegister.ESP);
var ebp = new RegisterOperand(BuiltInSigType.IntPtr, GeneralPurposeRegister.EBP);
context.SetInstruction(X86.Sub, esp, new ConstantOperand(BuiltInSigType.IntPtr, parameters.Count * 4));
context.AppendInstruction(X86.Mov, edx, esp);
var size = parameters.Count * 4;
foreach (var parameter in parameters)
{
context.AppendInstruction(X86.Mov, new MemoryOperand(BuiltInSigType.IntPtr, edx.Register, new IntPtr(size - 4)), new MemoryOperand(BuiltInSigType.IntPtr, ebp.Register, new IntPtr(size + 8)));
size -= 4;
}
context.AppendInstruction(X86.Mov, eax, op2);
context.AppendInstruction(X86.Call, null, new RegisterOperand(BuiltInSigType.IntPtr, GeneralPurposeRegister.EAX));
context.AppendInstruction(X86.Add, esp, new ConstantOperand(BuiltInSigType.IntPtr, parameters.Count * 4));
context.AppendInstruction(X86.Mov,result, new RegisterOperand(result.Type, GeneralPurposeRegister.EAX));
}
示例12:
/// <summary>
/// Replaces the intrinsic call site
/// </summary>
/// <param name="context">The context.</param>
/// <param name="typeSystem">The type system.</param>
void IIntrinsicPlatformMethod.ReplaceIntrinsicCall(Context context, BaseMethodCompiler methodCompiler)
{
var result = context.Result;
var address = methodCompiler.CreateVirtualRegister(methodCompiler.TypeSystem.BuiltIn.I4);
context.SetInstruction(IRInstruction.Move, address, Operand.CreateUnmanagedSymbolPointer(methodCompiler.TypeSystem, Multiboot0695Stage.MultibootEBX));
context.AppendInstruction(IRInstruction.Move, result, Operand.CreateMemoryAddress(methodCompiler.TypeSystem.BuiltIn.I4, address, 0));
}
示例13:
/// <summary>
/// Replaces the intrinsic call site
/// </summary>
/// <param name="context">The context.</param>
/// <param name="typeSystem">The type system.</param>
void IIntrinsicPlatformMethod.ReplaceIntrinsicCall(Context context, BaseMethodCompiler methodCompiler)
{
Operand methodAddress = context.Operand1;
Operand newESP = context.Operand2;
context.SetInstruction(X86.Call, null, methodAddress);
}
示例14:
/// <summary>
/// Replaces the intrinsic call site
/// </summary>
/// <param name="context">The context.</param>
/// <param name="typeSystem">The type system.</param>
void IIntrinsicPlatformMethod.ReplaceIntrinsicCall(Context context, ITypeSystem typeSystem, IList<RuntimeParameter> parameters)
{
// Retrieve register context
//context.SetInstruction(CPUx86.Instruction.MovInstruction, new RegisterOperand(BuiltInSigType.UInt32, GeneralPurposeRegister.EAX), Operand.CreateMemoryAddress(BuiltInSigType.UInt32, GeneralPurposeRegister.ESP, new IntPtr(28)));
// Restore registers (Note: EAX and EDX are NOT restored!)
//context.AppendInstruction(CPUx86.Instruction.MovInstruction, new RegisterOperand(BuiltInSigType.UInt32, GeneralPurposeRegister.EDX), Operand.CreateMemoryAddress(BuiltInSigType.UInt32, GeneralPurposeRegister.EAX, new IntPtr(28)));
//context.AppendInstruction(CPUx86.Instruction.MovInstruction, new RegisterOperand(BuiltInSigType.UInt32, GeneralPurposeRegister.EBX), Operand.CreateMemoryAddress(BuiltInSigType.UInt32, GeneralPurposeRegister.EAX, new IntPtr(4)));
//context.AppendInstruction(CPUx86.Instruction.MovInstruction, new RegisterOperand(BuiltInSigType.UInt32, GeneralPurposeRegister.EDI), Operand.CreateMemoryAddress(BuiltInSigType.UInt32, GeneralPurposeRegister.EAX, new IntPtr(20)));
//context.AppendInstruction(CPUx86.Instruction.MovInstruction, new RegisterOperand(BuiltInSigType.UInt32, GeneralPurposeRegister.ESI), Operand.CreateMemoryAddress(BuiltInSigType.UInt32, GeneralPurposeRegister.EAX, new IntPtr(16)));
//context.AppendInstruction(CPUx86.Instruction.MovInstruction, new RegisterOperand(BuiltInSigType.UInt32, GeneralPurposeRegister.ESP), Operand.CreateMemoryAddress(BuiltInSigType.UInt32, GeneralPurposeRegister.EAX, new IntPtr(32)));
//context.AppendInstruction(CPUx86.Instruction.MovInstruction, new RegisterOperand(BuiltInSigType.UInt32, GeneralPurposeRegister.EBP), Operand.CreateMemoryAddress(BuiltInSigType.UInt32, GeneralPurposeRegister.EAX, new IntPtr(24)));
//uint ebp, uint esp, int eip
Operand edx = Operand.CreateCPURegister(BuiltInSigType.UInt32, GeneralPurposeRegister.EDX);
Operand ebp = Operand.CreateCPURegister(BuiltInSigType.UInt32, GeneralPurposeRegister.EBP);
Operand esp = Operand.CreateCPURegister(BuiltInSigType.UInt32, GeneralPurposeRegister.ESP);
// Restore registers
context.SetInstruction(X86.Mov, Operand.CreateCPURegister(BuiltInSigType.UInt32, GeneralPurposeRegister.ESP), context.Operand1);
// Jmp to EIP (stored in EDX)
context.AppendInstruction(X86.Jmp, null, edx);
//context.SetOperand(0, edx);
}
示例15: Context
/// <summary>
/// Replaces the intrinsic call site
/// </summary>
/// <param name="context">The context.</param>
/// <param name="typeSystem">The type system.</param>
void IIntrinsicPlatformMethod.ReplaceIntrinsicCall(Context context, BaseMethodCompiler methodCompiler)
{
var operand = context.Operand1;
if (!operand.IsConstant)
{
// try to find the constant - a bit of a hack
Context ctx = new Context(operand.Definitions[0]);
if (ctx.Instruction == IRInstruction.Move && ctx.Operand1.IsConstant)
{
operand = ctx.Operand1;
}
}
Debug.Assert(operand.IsConstant);
int irq = (int)operand.ConstantSignedLongInteger;
// Find the method
var method = methodCompiler.TypeSystem.DefaultLinkerType.FindMethodByName("InterruptISR" + irq.ToString());
if (method == null)
{
throw new InvalidCompilerException();
}
context.SetInstruction(IRInstruction.Move, context.Result, Operand.CreateSymbolFromMethod(methodCompiler.TypeSystem, method));
}