本文整理汇总了C#中Mosa.Compiler.Framework.Context类的典型用法代码示例。如果您正苦于以下问题:C# Context类的具体用法?C# Context怎么用?C# Context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Context类属于Mosa.Compiler.Framework命名空间,在下文中一共展示了Context类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
}
开发者ID:Zahovay,项目名称:MOSA-Project,代码行数:32,代码来源:InvokeInstanceDelegateWithReturn.cs
示例2: FoldInstruction
/// <summary>
/// Folds the instruction.
/// </summary>
/// <param name="context">The context.</param>
private void FoldInstruction(Context context)
{
if (context.Instruction is AddSInstruction)
this.FoldAddSInstruction(context);
else if (context.Instruction is MulSInstruction)
this.FoldMulSInstruction(context);
}
开发者ID:GeroL,项目名称:MOSA-Project,代码行数:11,代码来源:ConstantFoldingStage.cs
示例3: Emit
/// <summary>
/// Emits the specified platform instruction.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="emitter">The emitter.</param>
protected override void Emit(Context context, MachineCodeEmitter emitter)
{
// TODO: Remove
if (context.Operand1 is MemberOperand)
return;
if (context.Result is RegisterOperand && context.Operand1 is MemoryOperand)
{
RegisterOperand result = context.Result as RegisterOperand;
MemoryOperand operand = context.Operand1 as MemoryOperand;
int displacement = operand.Offset.ToInt32();
if (IsBetween(displacement, 0, 7))
{
emitter.EmitTwoRegisterInstructions((byte)(0x0C & displacement), (byte)operand.Base.RegisterCode, (byte)result.Register.RegisterCode);
}
else
if (IsBetween(displacement, -32768, 32767))
{
emitter.EmitTwoRegistersAndK16(0x13, (byte)operand.Base.RegisterCode, (byte)result.Register.RegisterCode, (short)displacement);
}
else
throw new OverflowException();
}
else
throw new Exception("Not supported combination of operands");
}
开发者ID:pdelprat,项目名称:MOSA-Project,代码行数:32,代码来源:LdubInstruction.cs
示例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);
}
}
开发者ID:tgiphil,项目名称:MOSA-Project,代码行数:38,代码来源:FloatingPointStage.cs
示例5: Emit
/// <summary>
/// Emits the specified platform instruction.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="emitter">The emitter.</param>
protected override void Emit(Context context, MachineCodeEmitter emitter)
{
Debug.Assert(context.Result == null);
OpCode opCode = ComputeOpCode(null, context.Operand1, context.Operand2);
emitter.Emit(opCode, context.Operand1, context.Operand2);
}
开发者ID:toddhainsworth,项目名称:MOSA-Project,代码行数:12,代码来源:TwoOperandNoResultInstruction.cs
示例6: CollectLocalVariablesFromIL
/// <summary>
/// Runs the specified method compiler.
/// </summary>
void IMethodCompilerStage.Run()
{
if (methodCompiler.PlugSystem != null)
if (methodCompiler.PlugSystem.GetPlugMethod(this.methodCompiler.Method) != null)
return;
List<StackOperand> locals = CollectLocalVariablesFromIL();
// Iterate and collect locals from all blocks
foreach (BasicBlock block in basicBlocks)
{
CollectLocalVariables(locals, block);
}
// Sort all found locals
OrderVariables(locals, callingConvention);
// Now we assign increasing stack offsets to each variable
localsSize = LayoutVariables(locals, callingConvention, callingConvention.OffsetOfFirstLocal, 1);
// Layout parameters
LayoutParameters(methodCompiler);
// Create a prologue instruction
Context prologueCtx = new Context(instructionSet, FindBlock(-1)).InsertBefore();
prologueCtx.SetInstruction(IR.Instruction.PrologueInstruction);
prologueCtx.Label = -1;
// Create an epilogue instruction
Context epilogueCtx = new Context(instructionSet, FindBlock(Int32.MaxValue));
epilogueCtx.AppendInstruction(IR.Instruction.EpilogueInstruction);
epilogueCtx.Label = Int32.MaxValue;
}
开发者ID:GeroL,项目名称:MOSA-Project,代码行数:36,代码来源:StackLayoutStage.cs
示例7: CreateExceptionVector
/// <summary>
/// Creates the ISR methods.
/// </summary>
private void CreateExceptionVector()
{
RuntimeType runtimeType = typeSystem.GetType(@"Mosa.Kernel.x86.IDT");
if (runtimeType == null)
return;
RuntimeMethod runtimeMethod = runtimeType.FindMethod(@"ExceptionHandler");
if (runtimeMethod == null)
return;
SymbolOperand exceptionMethod = SymbolOperand.FromMethod(runtimeMethod);
RegisterOperand esp = new RegisterOperand(BuiltInSigType.Int32, GeneralPurposeRegister.ESP);
InstructionSet instructionSet = new InstructionSet(100);
Context ctx = new Context(instructionSet);
// TODO - setup stack for call to the managed exception handler
//1.
//2.
//3. Call the managed exception handler
ctx.AppendInstruction(Instruction.CallInstruction, null, exceptionMethod);
LinkTimeCodeGenerator.Compile(this.compiler, @"ExceptionVector", instructionSet, typeSystem);
}
开发者ID:GeroL,项目名称:MOSA-Project,代码行数:32,代码来源:ExceptionVectorStage.cs
示例8:
/// <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);
}
开发者ID:Zahovay,项目名称:MOSA-Project,代码行数:12,代码来源:GetMultibootEAX.cs
示例9: Call
/// <summary>
/// Visitation function for <see cref="IX86Visitor.Call"/> instructions.
/// </summary>
/// <param name="context">The context.</param>
public override void Call(Context context)
{
if (context.Operand1 == null)
return;
if (!context.Operand1.IsCPURegister)
return;
var before = context.Previous;
while (before.IsEmpty && !before.IsBlockStartInstruction)
{
before = before.Previous;
}
if (before == null || before.IsBlockStartInstruction)
return;
if (!before.Result.IsCPURegister)
return;
if (context.Operand1.Register != before.Result.Register)
return;
before.SetInstruction(X86.Call, null, before.Operand1);
context.Empty();
}
开发者ID:yonglehou,项目名称:MOSA-Project,代码行数:31,代码来源:FinalTweakTransformationStage.cs
示例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)
{
Debug.Assert(context.Result.IsI4 | context.Result.IsU4);
Operand zero = Operand.CreateConstant(methodCompiler.TypeSystem, 0);
context.SetInstruction(X86.MovzxLoad, InstructionSize.Size16, context.Result, context.Operand1, zero);
}
开发者ID:Zahovay,项目名称:MOSA-Project,代码行数:12,代码来源:Get16.cs
示例11:
/// <summary>
/// Visitation function for AddFloat.
/// </summary>
/// <param name="context">The context.</param>
void IIRVisitor.AddFloat(Context context)
{
if (context.Result.IsR4)
ReplaceInstructionAndAnyFloatingPointConstant(context, X86.Addss);
else
ReplaceInstructionAndAnyFloatingPointConstant(context, X86.Addsd);
}
开发者ID:tea,项目名称:MOSA-Project,代码行数:11,代码来源:IRTransformationStage.cs
示例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)
{
Operand methodAddress = context.Operand1;
Operand newESP = context.Operand2;
context.SetInstruction(X86.Call, null, methodAddress);
}
开发者ID:tgiphil,项目名称:MOSA-Project,代码行数:12,代码来源:FrameCall.cs
示例13: while
/// <summary>
/// Visitation function for <see cref="IX86Visitor.Call"/> instructions.
/// </summary>
/// <param name="context">The context.</param>
void IX86Visitor.Call(Context context)
{
if (context.Operand1 == null)
return;
if (!context.Operand1.IsCPURegister)
return;
var before = context.Previous;
while (before.IsEmpty && !before.IsBlockStartInstruction)
{
before = before.Previous;
}
if (before == null || before.IsBlockStartInstruction)
return;
if (!before.Result.IsCPURegister)
return;
if (context.Operand1.Register != before.Result.Register)
return;
before.SetInstruction(X86.Call, null, before.Operand1);
context.Delete(false);
}
开发者ID:Boddlnagg,项目名称:MOSA-Project,代码行数:31,代码来源:FinalTweakTransformationStage.cs
示例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, 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);
}
}
开发者ID:yonglehou,项目名称:MOSA-Project,代码行数:36,代码来源:Remainder.cs
示例15: 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));
}
开发者ID:GeroL,项目名称:MOSA-Project,代码行数:11,代码来源:ConstantFoldingStage.cs
示例16: Emit
/// <summary>
/// Emits the specified platform instruction.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="emitter">The emitter.</param>
protected override void Emit(Context context, MachineCodeEmitter emitter)
{
if (context.OperandCount == 0)
{
// TODO:
//emitter.EmitBranch(LabelCall, context.BranchTargets[0]);
return;
}
Operand destinationOperand = context.Operand1;
SymbolOperand destinationSymbol = destinationOperand as SymbolOperand;
if (destinationSymbol != null)
{
emitter.Call(destinationSymbol);
}
else
{
if (destinationOperand is MemoryOperand)
{
//RegisterOperand register = destinationOperand as RegisterOperand;
//emitter.EmitSingleRegisterInstructions(0x11, (byte)register.Register.RegisterCode);
MemoryOperand memory = destinationOperand as MemoryOperand;
emitter.EmitRegisterOperandWithK16(0x101, (byte)memory.Base.RegisterCode, (ushort)memory.Offset);
}
}
}
开发者ID:grover,项目名称:MOSA-Project,代码行数:32,代码来源:Call.cs
示例17: Emit
/// <summary>
/// Emits the specified platform instruction.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="emitter">The emitter.</param>
protected override void Emit(Context context, MachineCodeEmitter emitter)
{
if (context.Result is RegisterOperand && context.Operand1 is ConstantOperand)
{
RegisterOperand reg = context.Result as RegisterOperand;
ConstantOperand op = context.Operand1 as ConstantOperand;
int value = 0;
if (IsConstantBetween(op, -128, 127, out value))
{
emitter.EmitK8immediateAndSingleRegister(0x01, (sbyte)value, (byte)reg.Register.RegisterCode); // mov Rd, Imm (k8)
}
else
if (IsConstantBetween(op, -1048576, 1048575, out value))
{
emitter.EmitRegisterOrConditionCodeAndK21(0x03, (byte)reg.Register.RegisterCode, value); // mov Rd, Imm (k21)
}
else
throw new OverflowException();
}
else
if ((context.Result is RegisterOperand) && (context.Operand1 is RegisterOperand))
{
RegisterOperand destination = context.Result as RegisterOperand;
RegisterOperand source = context.Operand1 as RegisterOperand;
emitter.EmitTwoRegisterInstructions(0x09, (byte)source.Register.RegisterCode, (byte)destination.Register.RegisterCode); // mov Rd, Rs
}
//else
//throw new Exception("Not supported combination of operands");
}
开发者ID:pdelprat,项目名称:MOSA-Project,代码行数:37,代码来源:MovInstruction.cs
示例18: 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));
}
开发者ID:yonglehou,项目名称:MOSA-Project,代码行数:34,代码来源:GetIDTJumpLocation.cs
示例19: Cmp
/// <summary>
/// Visitation function for <see cref="IX86Visitor.Cmp"/> instructions.
/// </summary>
/// <param name="context">The context.</param>
public override void Cmp(Context context)
{
Operand left = context.Operand1;
Operand right = context.Operand2;
if (left.IsConstant)
{
Operand ecx = AllocateVirtualRegister(left.Type);
Context before = context.InsertBefore();
before.AppendInstruction(X86.Mov, ecx, left);
context.Operand1 = ecx;
}
if (right.IsConstant && (left.IsChar || left.IsShort || left.IsByte))
{
Operand edx = AllocateVirtualRegister(TypeSystem.BuiltIn.I4);
Context before = context.InsertBefore();
if (left.IsSigned)
{
before.AppendInstruction(X86.Movsx, edx, left);
}
else
{
before.AppendInstruction(X86.Movzx, edx, left);
}
context.Operand1 = edx;
}
}
开发者ID:pacificIT,项目名称:MOSA-Project,代码行数:34,代码来源:TweakTransformationStage.cs
示例20:
/// <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);
}
开发者ID:jeffreye,项目名称:MOSA-Project,代码行数:32,代码来源:RestoreContext.cs
注:本文中的Mosa.Compiler.Framework.Context类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论