本文整理汇总了C#中MachineCodeEmitter.Emit方法的典型用法代码示例。如果您正苦于以下问题:C# MachineCodeEmitter.Emit方法的具体用法?C# MachineCodeEmitter.Emit怎么用?C# MachineCodeEmitter.Emit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MachineCodeEmitter
的用法示例。
在下文中一共展示了MachineCodeEmitter.Emit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Emit
/// <summary>
/// Emits the specified platform instruction.
/// </summary>
/// <param name="node">The node.</param>
/// <param name="emitter">The emitter.</param>
/// <exception cref="System.InvalidOperationException">@unable to emit opcode for segment register</exception>
protected override void Emit(InstructionNode node, MachineCodeEmitter emitter)
{
if (node.Operand1.IsConstant)
{
if (node.Operand1.IsByte)
emitter.Emit(CONST8, node.Operand1);
else if (node.Operand1.IsShort || node.Operand1.IsChar)
emitter.Emit(CONST16, node.Operand1);
else if (node.Operand1.IsInt)
emitter.Emit(CONST32, node.Operand1);
return;
}
if (node.Operand1.IsCPURegister)
{
if (node.Operand1.Register is SegmentRegister)
switch ((node.Operand1.Register as SegmentRegister).Segment)
{
case SegmentRegister.SegmentType.CS: emitter.Emit(PUSH_CS); return;
case SegmentRegister.SegmentType.SS: emitter.Emit(PUSH_SS); return;
case SegmentRegister.SegmentType.DS: emitter.Emit(PUSH_DS); return;
case SegmentRegister.SegmentType.ES: emitter.Emit(PUSH_ES); return;
case SegmentRegister.SegmentType.FS: emitter.Emit(PUSH_FS); return;
case SegmentRegister.SegmentType.GS: emitter.Emit(PUSH_GS); return;
default: throw new InvalidOperationException(@"unable to emit opcode for segment register");
}
}
emitter.Emit(PUSH, node.Operand1);
}
示例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.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);
}
示例3: MovsdRegToMemory
private static void MovsdRegToMemory(InstructionNode node, MachineCodeEmitter emitter)
{
Debug.Assert(node.Operand3.IsCPURegister);
Debug.Assert(node.ResultCount == 0);
Debug.Assert(!node.Operand3.IsConstant);
// xmmreg1 to mem 1111 0010:0000 1111:0001 0001: mod xmmreg r/m
var opcode = new OpcodeEncoder()
.AppendNibble(Bits.b1111) // 4:opcode
.AppendNibble(Bits.b0010) // 4:opcode
.AppendNibble(Bits.b0000) // 4:opcode
.AppendNibble(Bits.b1111) // 4:opcode
.AppendNibble(Bits.b0001) // 4:opcode
.AppendNibble(Bits.b0001) // 4:opcode
// This opcode has a directionality bit, and it is set to 0
// This means we must swap around operand1 and operand3, and set offsetDestination to false
.ModRegRMSIBDisplacement(false, node.Operand3, node.Operand1, node.Operand2) // Mod-Reg-RM-?SIB-?Displacement
.AppendConditionalIntegerValue(node.Operand1.IsLinkerResolved, 0); // 32:memory
if (node.Operand1.IsLinkerResolved)
emitter.Emit(opcode, node.Operand1, (opcode.Size - 32) / 8);
else
emitter.Emit(opcode);
}
示例4: CmpXchg
private static void CmpXchg(InstructionNode node, MachineCodeEmitter emitter)
{
Debug.Assert(node.Result.IsRegister);
Debug.Assert(node.Operand1.IsRegister);
Debug.Assert(node.Operand2.IsRegister);
Debug.Assert(node.GetOperand(3).IsRegister);
Debug.Assert(node.Result.Register == GeneralPurposeRegister.EAX);
Debug.Assert(node.Operand1.Register == GeneralPurposeRegister.EAX);
Debug.Assert(node.ResultCount == 1);
var linkreference = node.Operand2.IsLabel || node.Operand2.IsField || node.Operand2.IsSymbol;
// Compare EAX with r/m32. If equal, ZF is set and r32 is loaded into r/m32.
// Else, clear ZF and load r/m32 into EAX.
// memory, register 0000 1111 : 1011 000w : mod reg r/m
var opcode = new OpcodeEncoder()
.AppendConditionalPrefix(0x66, node.Size == InstructionSize.Size16) // 8:prefix: 16bit
.AppendNibble(Bits.b0000) // 4:opcode
.AppendNibble(Bits.b1111) // 4:opcode
.AppendNibble(Bits.b1011) // 4:opcode
.Append3Bits(Bits.b000) // 3:opcode
.AppendWidthBit(node.Size != InstructionSize.Size8) // 1:width
.ModRegRMSIBDisplacement(node.GetOperand(3), node.Operand2, node.Operand3) // Mod-Reg-RM-?SIB-?Displacement
.AppendConditionalIntegerValue(0, linkreference); // 32:memory
if (linkreference)
emitter.Emit(opcode, node.Operand1, (opcode.Size - 32) / 8);
else
emitter.Emit(opcode);
}
示例5: Emit
/// <summary>
/// Emits the specified platform instruction.
/// </summary>
/// <param name="node">The node.</param>
/// <param name="emitter">The emitter.</param>
protected override void Emit(InstructionNode node, MachineCodeEmitter emitter)
{
if (node.Operand3.IsConstant)
{
emitter.Emit(C, node.Operand2, node.Result, node.Operand3);
}
else
{
emitter.Emit(RM, node.Operand2, node.Result);
}
}
示例6: 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.Operand3.IsConstant)
{
emitter.Emit(C, context.Operand2, context.Result, context.Operand3);
}
else
{
emitter.Emit(RM, context.Operand2, context.Result);
}
}
示例7: 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)
{
OpCode opCode = ComputeOpCode(context.Result, context.Operand1, context.Operand2);
if (context.Operand1.IsConstant)
{
// FIXME: Conversion not necessary if constant already byte.
Operand op = Operand.CreateConstant(BuiltInSigType.Byte, context.Operand1.Value);
emitter.Emit(opCode, context.Result, op);
}
else
emitter.Emit(opCode, context.Operand1, null);
}
示例8: Emit
/// <summary>
///
/// </summary>
/// <param name="context"></param>
/// <param name="emitter"></param>
protected override void Emit(Context context, MachineCodeEmitter emitter)
{
OpCode opCode = ComputeOpCode(context.Result, context.Operand1, context.Operand2);
if (context.Operand1 is ConstantOperand)
{
ConstantOperand op = context.Operand1 as ConstantOperand;
op = new ConstantOperand(BuiltInSigType.Byte, op.Value);
emitter.Emit(opCode, context.Result, op);
}
else
emitter.Emit(opCode, context.Operand1, null);
}
示例9: Emit
/// <summary>
///
/// </summary>
/// <param name="ctx"></param>
/// <param name="emitter"></param>
protected override void Emit(Context ctx, MachineCodeEmitter emitter)
{
OpCode opCode = ComputeOpCode(ctx.Result, ctx.Operand1, ctx.Operand2);
if (ctx.Operand1 is ConstantOperand)
{
ConstantOperand op = ctx.Operand1 as ConstantOperand;
op = new ConstantOperand(new Mosa.Runtime.Metadata.Signatures.SigType(CilElementType.U1), op.Value);
emitter.Emit(opCode, ctx.Result, op);
}
else
emitter.Emit(opCode, ctx.Operand1, null);
}
示例10: Emit
/// <summary>
/// Emits the specified platform instruction.
/// </summary>
/// <param name="node">The context.</param>
/// <param name="emitter">The emitter.</param>
protected override void Emit(InstructionNode node, MachineCodeEmitter emitter)
{
var opCode = ComputeOpCode(node.Size, node.Operand1, node.Operand2);
if (node.Operand1.IsConstant)
{
emitter.Emit(opCode, node.Operand1, null);
}
else
{
emitter.Emit(opCode, null, null);
}
}
示例11: Emit
/// <summary>
/// Emits the specified platform instruction.
/// </summary>
/// <param name="node">The node.</param>
/// <param name="emitter">The emitter.</param>
protected override void Emit(InstructionNode node, MachineCodeEmitter emitter)
{
OpCode opCode = ComputeOpCode(node.Result, node.Operand1, null);
if (node.Result.Register is ControlRegister)
{
emitter.Emit(opCode, node.Result, node.Operand1);
}
else
{
emitter.Emit(opCode, node.Operand1, node.Result);
}
}
示例12: 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)
{
OpCode opCode = ComputeOpCode(context.Result, context.Operand1, context.Operand2);
if (context.Operand2 is ConstantOperand)
{
// TODO/FIXME: Move these two lines into a stage
ConstantOperand op = context.Operand2 as ConstantOperand;
op = new ConstantOperand(BuiltInSigType.Byte, op.Value);
emitter.Emit(opCode, context.Result, context.Operand1, op);
}
else
emitter.Emit(opCode, context.Result, context.Operand1, context.Operand2);
}
示例13: 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]);
}
示例14: 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);
}
示例15: Emit
/// <summary>
/// Emits the specified platform instruction.
/// </summary>
/// <param name="node">The node.</param>
/// <param name="emitter">The emitter.</param>
protected override void Emit(InstructionNode node, MachineCodeEmitter emitter)
{
Debug.Assert(node.Result == null);
OpCode opCode = ComputeOpCode(null, node.Operand1, node.Operand2);
emitter.Emit(opCode, node.Operand1, node.Operand2);
}