当前位置: 首页>>代码示例>>C#>>正文


C# MachineCodeEmitter类代码示例

本文整理汇总了C#中MachineCodeEmitter的典型用法代码示例。如果您正苦于以下问题:C# MachineCodeEmitter类的具体用法?C# MachineCodeEmitter怎么用?C# MachineCodeEmitter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


MachineCodeEmitter类属于命名空间,在下文中一共展示了MachineCodeEmitter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: 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);
        }
开发者ID:hj1980,项目名称:Mosa,代码行数:30,代码来源:LeaInstruction.cs

示例2: Emit

        protected override void Emit(InstructionNode node, MachineCodeEmitter emitter)
        {
            Debug.Assert(node.Result.IsRegister);
            Debug.Assert(node.Operand1.IsRegister);
            Debug.Assert(node.Operand2.IsConstant);

            // reg from xmmreg, imm8
            // 0110 0110:0000 1111:0011 1010: 0001 0110:11 xmmreg reg: imm8
            var opcode = new OpcodeEncoder()
                .AppendNibble(Bits.b0110)                                       // 4:opcode
                .AppendNibble(Bits.b0110)                                       // 4:opcode

                .AppendNibble(Bits.b0000)                                       // 4:opcode
                .AppendNibble(Bits.b1111)                                       // 4:opcode

                .AppendNibble(Bits.b0011)                                       // 4:opcode
                .AppendNibble(Bits.b1010)                                       // 4:opcode

                .AppendNibble(Bits.b0001)                                       // 4:opcode
                .AppendNibble(Bits.b0110)                                       // 4:opcode

                .Append2Bits(Bits.b11)                                          // 2:opcode
                .AppendRM(node.Operand1)                                        // 3:r/m (source)
                .AppendRegister(node.Result.Register)                           // 3:register (destination)

                .AppendByteValue((byte)node.Operand2.ConstantUnsignedInteger);  // 8:memory

            emitter.Emit(opcode);
        }
开发者ID:Zahovay,项目名称:MOSA-Project,代码行数:29,代码来源:Pextrd.cs

示例3: MovImmediateToFixedMemory

        private static void MovImmediateToFixedMemory(InstructionNode node, MachineCodeEmitter emitter)
        {
            Debug.Assert(node.Operand1.IsConstant);
            Debug.Assert(node.Operand2.IsResolvedConstant);
            Debug.Assert(node.Operand3.IsConstant);

            // immediate to memory	1100 011w: mod 000 r/m : immediate data
            var opcode = new OpcodeEncoder()
                .AppendConditionalPrefix(node.Size == InstructionSize.Size16, 0x66)  // 8:prefix: 16bit
                .AppendNibble(Bits.b1100)                                       // 4:opcode
                .Append3Bits(Bits.b011)                                         // 3:opcode
                .AppendWidthBit(node.Size != InstructionSize.Size8)             // 1:width

                .AppendMod(Bits.b00)                                            // 2:mod (00)
                .Append3Bits(Bits.b000)                                         // 3:source (000)
                .AppendRM(node.Operand1)                                        // 3:r/m (destination)

                .AppendConditionalDisplacement(!node.Operand1.IsLinkerResolved, node.Operand1)   // 32:displacement value

                .AppendConditionalIntegerValue(node.Operand1.IsLinkerResolved, 0)  // 32:memory
                .AppendInteger(node.Operand3, node.Size);                       // 8/16/32:immediate

            if (node.Operand1.IsLinkerResolved && !node.Operand3.IsLinkerResolved)
                emitter.Emit(opcode, node.Operand1, 2, node.Operand2.ConstantSignedInteger);
            else if (node.Operand1.IsLinkerResolved && node.Operand3.IsLinkerResolved)
            {
                // fixme: trouble!
                throw new NotImplementCompilerException("not here");
            }
            else
                emitter.Emit(opcode);
        }
开发者ID:tgiphil,项目名称:MOSA-Project,代码行数:32,代码来源:MovStore.cs

示例4: 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);
 }
开发者ID:davidleon,项目名称:MOSA-Project,代码行数:33,代码来源:PushInstruction.cs

示例5: Emit

        /// <summary>
        /// Emits the specified platform instruction.
        /// </summary>
        /// <param name="node">The node.</param>
        /// <param name="emitter">The emitter.</param>
        /// <exception cref="System.NotSupportedException"></exception>
        protected override void Emit(InstructionNode node, MachineCodeEmitter emitter)
        {
            OpCode opcode;

            switch (node.ConditionCode)
            {
                case ConditionCode.Equal: opcode = E; break;
                case ConditionCode.LessThan: opcode = LT; break;
                case ConditionCode.LessOrEqual: opcode = LE; break;
                case ConditionCode.GreaterOrEqual: opcode = GE; break;
                case ConditionCode.GreaterThan: opcode = GT; break;
                case ConditionCode.NotEqual: opcode = NE; break;
                case ConditionCode.UnsignedGreaterOrEqual: opcode = UGE; break;
                case ConditionCode.UnsignedGreaterThan: opcode = UGT; break;
                case ConditionCode.UnsignedLessOrEqual: opcode = ULE; break;
                case ConditionCode.UnsignedLessThan: opcode = ULT; break;
                case ConditionCode.Parity: opcode = P; break;
                case ConditionCode.NoParity: opcode = NP; break;
                case ConditionCode.NoCarry: opcode = NC; break;
                case ConditionCode.Carry: opcode = C; break;
                case ConditionCode.Zero: opcode = Z; break;
                case ConditionCode.NotZero: opcode = NZ; break;
                default: throw new NotSupportedException();
            }

            emitter.Emit(opcode, node.Result, null);
        }
开发者ID:Profi-Concept,项目名称:MOSA-Project,代码行数:33,代码来源:Setcc.cs

示例6: 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);
        }
开发者ID:Profi-Concept,项目名称:MOSA-Project,代码行数:12,代码来源:Ucomiss.cs

示例7: 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);
        }
开发者ID:tgiphil,项目名称:MOSA-Project,代码行数:25,代码来源:MovsdStore.cs

示例8: 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.IsRegister && context.Operand1.IsRegister && context.Operand2.IsRegister)
     {
         emitter.EmitThreeRegistersUnshifted(0x24, (byte)context.Operand1.Register.RegisterCode, (byte)context.Operand2.Register.RegisterCode, (byte)context.Result.Register.RegisterCode);
     }
     else if (context.Result.IsRegister && context.Operand1.IsRegister && context.Operand2.IsConstant)
     {
         int value = 0;
         if (IsConstantBetween(context.Operand2, -128, 127, out value))
         {
             emitter.EmitTwoRegisterOperandsWithK8Immediate(0x00, (byte)context.Operand1.Register.RegisterCode, (byte)context.Result.Register.RegisterCode, (sbyte)value);
         }
         else
             throw new OverflowException();
     }
     else if (context.Result.IsRegister && context.Operand1.IsRegister)
     {
         emitter.EmitTwoRegisterInstructions(0x13, (byte)context.Operand1.Register.RegisterCode, (byte)context.Result.Register.RegisterCode);
     }
     else
     {
         throw new Exception("Not supported combination of operands");
     }
 }
开发者ID:jeffreye,项目名称:MOSA-Project,代码行数:30,代码来源:Mul.cs

示例9: Emit

        /// <summary>
        /// Emits the specified platform instruction.
        /// </summary>
        /// <param name="node">The node.</param>
        /// <param name="emitter">The emitter.</param>
        /// <exception cref="System.NotSupportedException"></exception>
        protected override void Emit(InstructionNode node, MachineCodeEmitter emitter)
        {
            byte[] opcode = null;

            switch (node.ConditionCode)
            {
                case ConditionCode.Equal: opcode = JE; break;
                case ConditionCode.NotEqual: opcode = JNE; break;
                case ConditionCode.Zero: opcode = JZ; break;
                case ConditionCode.NotZero: opcode = JNZ; break;
                case ConditionCode.GreaterOrEqual: opcode = JGE; break;
                case ConditionCode.GreaterThan: opcode = JG; break;
                case ConditionCode.LessOrEqual: opcode = JLE; break;
                case ConditionCode.LessThan: opcode = JL; break;
                case ConditionCode.UnsignedGreaterOrEqual: opcode = JAE; break;
                case ConditionCode.UnsignedGreaterThan: opcode = JA; break;
                case ConditionCode.UnsignedLessOrEqual: opcode = JBE; break;
                case ConditionCode.UnsignedLessThan: opcode = JB; break;
                case ConditionCode.Signed: opcode = JS; break;
                case ConditionCode.NotSigned: opcode = JNS; break;
                case ConditionCode.Carry: opcode = JC; break;
                case ConditionCode.NoCarry: opcode = JNC; break;
                case ConditionCode.Overflow: opcode = JO; break;
                case ConditionCode.NoOverflow: opcode = JNO; break;
                case ConditionCode.Parity: opcode = JP; break;
                case ConditionCode.NoParity: opcode = JNP; break;
                default: throw new NotSupportedException();
            }

            emitter.EmitRelativeBranch(opcode, node.BranchTargets[0].Label);
        }
开发者ID:Zahovay,项目名称:MOSA-Project,代码行数:37,代码来源:Branch.cs

示例10: 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

示例11: 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

示例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)
        {
            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

示例13: 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);
 }
开发者ID:tgiphil,项目名称:MOSA-Project,代码行数:34,代码来源:Push.cs

示例14: 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);
        }
开发者ID:Zahovay,项目名称:MOSA-Project,代码行数:31,代码来源:CmpXchgLoad.cs

示例15: 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);
 }
开发者ID:hj1980,项目名称:Mosa,代码行数:12,代码来源:CpuIdEcxInstruction.cs


注:本文中的MachineCodeEmitter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。