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


C# Framework.Context类代码示例

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


Context类属于Mosa.Compiler.Framework命名空间,在下文中一共展示了Context类的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
        }
开发者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


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