本文整理汇总了C#中Mosa.Runtime.CompilerFramework.Context类的典型用法代码示例。如果您正苦于以下问题:C# Context类的具体用法?C# Context怎么用?C# Context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Context类属于Mosa.Runtime.CompilerFramework命名空间,在下文中一共展示了Context类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Emit
/// <summary>
/// Emits the specified platform instruction.
/// </summary>
/// <param name="ctx">The context.</param>
/// <param name="emitter">The emitter.</param>
protected override void Emit(Context ctx, MachineCodeEmitter emitter)
{
if (ctx.Operand1 is ConstantOperand)
{
if (IsByte(ctx.Operand1))
emitter.Emit(CONST8, ctx.Operand1, null);
else if (IsShort(ctx.Operand1) || IsChar(ctx.Operand1))
emitter.Emit(CONST16, ctx.Operand1, null);
else if (IsInt(ctx.Operand1))
emitter.Emit(CONST32, ctx.Operand1, null);
return;
}
if (ctx.Operand1 is RegisterOperand)
{
if ((ctx.Operand1 as RegisterOperand).Register is SegmentRegister)
switch (((ctx.Operand1 as RegisterOperand).Register as SegmentRegister).Segment)
{
case SegmentRegister.SegmentType.CS: emitter.Emit(PUSH_CS, null, null); return;
case SegmentRegister.SegmentType.SS: emitter.Emit(PUSH_SS, null, null); return;
case SegmentRegister.SegmentType.DS: emitter.Emit(PUSH_DS, null, null); return;
case SegmentRegister.SegmentType.ES: emitter.Emit(PUSH_ES, null, null); return;
case SegmentRegister.SegmentType.FS: emitter.Emit(PUSH_FS, null, null); return;
case SegmentRegister.SegmentType.GS: emitter.Emit(PUSH_GS, null, null); return;
default: throw new InvalidOperationException(@"unable to emit opcode for segment register");
}
}
emitter.Emit(PUSH, ctx.Operand1, null, null);
}
示例2: Emit
/// <summary>
/// Emits the specified platform instruction.
/// </summary>
/// <param name="ctx">The context.</param>
/// <param name="emitter">The emitter.</param>
protected override void Emit(Context ctx, MachineCodeEmitter emitter)
{
if (ctx.Result is RegisterOperand)
emitter.WriteByte ((byte)(0x58 + (ctx.Result as RegisterOperand).Register.RegisterCode));
else
emitter.Emit (POP.Code, 0, ctx.Result, null);
}
示例3: HandleMemoryToMemoryOperation
private void HandleMemoryToMemoryOperation(Context ctx, Operand register, bool useStack)
{
Operand destination = ctx.Result;
Operand source = ctx.Operand1;
Debug.Assert (destination is MemoryOperand && source is MemoryOperand);
if (register == null)
register = new RegisterOperand (destination.Type, GeneralPurposeRegister.EDX);
ctx.Operand1 = register;
Context before = ctx.InsertBefore ();
if (useStack)
{
before.SetInstruction (CPUx86.Instruction.PushInstruction, null, register);
before.AppendInstruction (CPUx86.Instruction.MovInstruction, register, source);
}
else
before.SetInstruction (CPUx86.Instruction.MovInstruction, register, source);
if (useStack)
ctx.AppendInstruction (CPUx86.Instruction.PopInstruction, register);
}
示例4: Emit
/// <summary>
///
/// </summary>
/// <param name="ctx"></param>
/// <param name="emitter"></param>
protected override void Emit(Context ctx, MachineCodeEmitter emitter)
{
RegisterOperand rop = (RegisterOperand)ctx.Result;
MemoryOperand mop = (MemoryOperand)ctx.Operand1;
byte[] code;
if (null != mop.Base)
{
code = new byte[] {
0x8d,
0x84,
(4 << 3)
};
code[1] |= (byte)((rop.Register.RegisterCode & 0x7));
code[2] |= (byte)((mop.Base.RegisterCode & 0x7));
}
else
{
code = new byte[] { 0xb8 };
}
emitter.Write (code, 0, code.Length);
emitter.EmitImmediate (mop);
}
示例5: Emit
/// <summary>
/// Emits the specified platform instruction.
/// </summary>
/// <param name="ctx">The context.</param>
/// <param name="emitter">The emitter.</param>
protected override void Emit(Context ctx, MachineCodeEmitter emitter)
{
if (ctx.Operand1 is RegisterOperand)
emitter.Emit(JmpReg, ctx.Operand1);
else
emitter.EmitBranch(JMP, ctx.Branch.Targets[0]);
}
示例6: Emit
/// <summary>
/// Emits the specified platform instruction.
/// </summary>
/// <param name="ctx">The context.</param>
/// <param name="emitter">The emitter.</param>
protected override void Emit(Context ctx, MachineCodeEmitter emitter)
{
OpCode opcode;
switch (ctx.ConditionCode)
{
case IR.ConditionCode.Equal: opcode = E; break;
case IR.ConditionCode.LessThan: opcode = LT; break;
case IR.ConditionCode.LessOrEqual: opcode = LE; break;
case IR.ConditionCode.GreaterOrEqual: opcode = GE; break;
case IR.ConditionCode.GreaterThan: opcode = GT; break;
case IR.ConditionCode.NotEqual: opcode = NE; break;
case IR.ConditionCode.UnsignedGreaterOrEqual: opcode = UGE; break;
case IR.ConditionCode.UnsignedGreaterThan: opcode = UGT; break;
case IR.ConditionCode.UnsignedLessOrEqual: opcode = ULE; break;
case IR.ConditionCode.UnsignedLessThan: opcode = ULT; break;
case IR.ConditionCode.Parity: opcode = P; break;
case IR.ConditionCode.NoParity: opcode = NP; break;
case IR.ConditionCode.NoCarry: opcode = NC; break;
case IR.ConditionCode.Carry: opcode = C; break;
case IR.ConditionCode.Zero: opcode = Z; break;
case IR.ConditionCode.NoZero: opcode = NZ; break;
default: throw new NotSupportedException();
}
emitter.Emit(opcode, ctx.Result, null);
}
示例7: CreateISRMethods
/// <summary>
/// Creates the ISR methods.
/// </summary>
/// <param name="compiler">The compiler.</param>
private void CreateISRMethods(AssemblyCompiler compiler)
{
// Create Interrupt Service Routines (ISR)
RuntimeMethod InterruptMethod = compiler.Assembly.EntryPoint; // TODO: replace with another entry point
SigType I1 = new SigType(CilElementType.I1);
SigType I4 = new SigType(CilElementType.I4);
RegisterOperand eax = new RegisterOperand(I4, GeneralPurposeRegister.EAX);
for (int i = 0; i <= 256; i++) {
InstructionSet set = new InstructionSet(100);
Context ctx = new Context(set, -1);
ctx.SetInstruction(CPUx86.Instruction.CliInstruction);
if ((i != 8) && (i < 10 || i > 14)) // For IRQ 8, 10, 11, 12, 13, 14 the cpu automatically pushed the error code
ctx.AppendInstruction(CPUx86.Instruction.PushInstruction, null, new ConstantOperand(I4, 0x0));
ctx.AppendInstruction(CPUx86.Instruction.PushadInstruction);
ctx.AppendInstruction(CPUx86.Instruction.PushInstruction, null, new ConstantOperand(I4, i));
// TODO: Set method parameters
ctx.AppendInstruction(CPUx86.Instruction.CallInstruction, InterruptMethod);
ctx.AppendInstruction(CPUx86.Instruction.PopInstruction, eax);
ctx.AppendInstruction(CPUx86.Instruction.PopadInstruction);
ctx.AppendInstruction(CPUx86.Instruction.PopInstruction, eax);
ctx.AppendInstruction(CPUx86.Instruction.StiInstruction);
//ctx.AppendInstruction(CPUx86.Instruction.IRetdInstruction);
CompilerGeneratedMethod method = LinkTimeCodeGenerator.Compile(compiler, @"InterruptISR" + i.ToString(), set);
}
}
示例8: Run
/// <summary>
/// Performs stage specific processing on the compiler context.
/// </summary>
public virtual void Run()
{
for (int index = 0; index < BasicBlocks.Count; index++)
for (Context ctx = new Context (InstructionSet, BasicBlocks[index]); !ctx.EndOfInstruction; ctx.GotoNext ())
if (ctx.Instruction != null)
ctx.Clone ().Visit (this);
}
示例9: Run
/// <summary>
/// Performs stage specific processing on the compiler context.
/// </summary>
public void Run()
{
// Create the prologue block
Context ctx = new Context(InstructionSet, -1);
// Add a jump instruction to the first block from the prologue
ctx.AppendInstruction(IR.Instruction.JmpInstruction);
//ctx.AppendInstruction(CIL.Instruction.Get(CIL.OpCode.Br));
ctx.SetBranch(0);
ctx.Label = -1;
_prologue = CreateBlock(-1, ctx.Index);
SplitIntoBlocks(0);
// Create the epilogue block
ctx = new Context(InstructionSet, -1);
// Add null instruction, necessary to generate a block index
ctx.AppendInstruction(null);
ctx.Ignore = true;
ctx.Label = Int32.MaxValue;
_epilogue = CreateBlock(Int32.MaxValue, ctx.Index);
// Link all the blocks together
BuildBlockLinks(_prologue);
// Link Exception Header Clauses
LinkExceptionHeaderClauses();
}
示例10: Emit
/// <summary>
///
/// </summary>
/// <param name="ctx"></param>
/// <param name="emitter"></param>
protected override void Emit(Context ctx, MachineCodeEmitter emitter)
{
emitter.Emit (new OpCode (new byte[] {
0xf,
0xa2
}), null, null);
}
示例11: TypeInitializerSchedulerStage
/// <summary>
/// Initializes a new instance of the <see cref="TypeInitializerSchedulerStage"/> class.
/// </summary>
public TypeInitializerSchedulerStage()
{
InstructionSet = new InstructionSet(1024);
_ctx = CreateContext(-1);
_ctx.AppendInstruction(IR.Instruction.PrologueInstruction);
_ctx.Other = 0; // stacksize
}
示例12: ReplaceIntrinsicCall
/// <summary>
/// Replaces the instrinsic call site
/// </summary>
/// <param name="context">The context.</param>
public void ReplaceIntrinsicCall(Context context)
{
Operand operand1 = context.Operand1;
RegisterOperand imm = new RegisterOperand(new SigType(CilElementType.U4), GeneralPurposeRegister.EAX);
context.SetInstruction(IR.Instruction.MoveInstruction, imm, operand1);
context.AppendInstruction(IR.Instruction.MoveInstruction, new RegisterOperand(new SigType(CilElementType.U4), _control), imm);
}
示例13: RegisterOperand
/// <summary>
/// Visitation function for <see cref="IR.IIRVisitor.AddressOfInstruction"/> instruction.
/// </summary>
/// <param name="ctx">The context.</param>
void IR.IIRVisitor.AddressOfInstruction(Context ctx)
{
Operand opRes = ctx.Result;
RegisterOperand eax = new RegisterOperand (opRes.Type, GeneralPurposeRegister.EAX);
ctx.Result = eax;
ctx.ReplaceInstructionOnly (CPUx86.Instruction.LeaInstruction);
// ctx.Ignore = true;
ctx.AppendInstruction (CPUx86.Instruction.MovInstruction, opRes, eax);
}
示例14: ReplaceIntrinsicCall
/// <summary>
/// Replaces the instrinsic call site
/// </summary>
/// <param name="context">The context.</param>
/// <param name="typeSystem">The type system.</param>
public void ReplaceIntrinsicCall(Context context, ITypeSystem typeSystem)
{
Operand result = context.Result;
RegisterOperand imm = new RegisterOperand(new SigType(CilElementType.U4), GeneralPurposeRegister.EAX);
context.SetInstruction(IR.Instruction.MoveInstruction, imm, new RegisterOperand(new SigType(CilElementType.U4), _control));
context.AppendInstruction(IR.Instruction.MoveInstruction, result, imm);
}
示例15: Emit
/// <summary>
/// Emits the specified platform instruction.
/// </summary>
/// <param name="ctx">The context.</param>
/// <param name="emitter">The emitter.</param>
protected override void Emit(Context ctx, MachineCodeEmitter emitter)
{
emitter.WriteByte(0xE8);
emitter.WriteByte(0x00);
emitter.WriteByte(0x00);
emitter.WriteByte(0x00);
emitter.WriteByte(0x00);
emitter.Call(ctx.InvokeTarget);
}