コード例 #1
1
        /// <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
        }
コード例 #2
0
 protected ReflectionBasedMember(ITypeSystem typeSystem, Type targetType)
 {
     TypeSystem        = typeSystem;
     SurrogateProvider = typeSystem.SurrogateProvider;
     PathManager       = typeSystem.PathManager;
     TargetType        = targetType;
 }
コード例 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TestRuntime"/>.
 /// </summary>
 public TestRuntime()
 {
     _memoryPageManager = new Win32MemoryPageManager();
     _typeLoader        = new DefaultTypeSystem();
     _assemblyLoader    = new AssemblyLoader(_typeLoader);
     _jitService        = new SimpleJitService();
 }
コード例 #4
0
        private IType AsAnnotationType(ITypeSystem system, IEnvironment env, IList <IType> types)
        {
            IType ctor;

            if
            (
                (Spec is Node) &&
                (((ctor = ((Node)Spec).Type as IType)) != null) &&
                (!IsFunction(ctor) || IsAnnotation)
            )
            {
                Args.Select
                (
                    (arg, i) =>
                    arg is Var ?
                    system.Infer(env, Define((Var)arg, Const(ctor[i])), types)
                            :
                    null
                ).
                ToArray();
                var type = system.NewType(ctor, Args.Select(arg => system.Infer(env, ToFormal(system, env, types, arg), types)).ToArray());
                return(type);
            }
            else
            {
                return(null);
            }
        }
コード例 #5
0
 public ReflectionBasedProperty(ITypeSystem typeSystem, IMember parent, PropertyInfo property, object[] propertyParameters)
     : base(typeSystem, property.PropertyType)
 {
     PropertyParameters = propertyParameters ?? new object[0];
     Property           = property;
     Owner = parent;
 }
コード例 #6
0
ファイル: CompilationRuntime.cs プロジェクト: hj1980/Mosa
 /// <summary>
 /// Initializes a new instance of <see cref="CompilationRuntime"/>.
 /// </summary>
 public CompilationRuntime()
 {
     _typeLoader = new DefaultTypeSystem();
     _assemblyLoader = new AssemblyLoader(_typeLoader);
     _memoryManager = new MockMemoryPageManager();
     _jitService = new MockJitService();
 }
コード例 #7
0
 public void Setup(AssemblyCompiler compiler)
 {
     this.compiler = compiler;
     architecture  = compiler.Architecture;
     typeSystem    = compiler.TypeSystem;
     typeLayout    = compiler.TypeLayout;
 }
コード例 #8
0
 public WebFormsDefaultHandler(ICommunicationContext context, ITypeSystem typeSystem, IDependencyResolver resolver)
 {
     _context = context;
     _typeSystem = typeSystem;
     _resolver = resolver;
     _pageType = typeSystem.FromClr<Page>();
 }
コード例 #9
0
ファイル: Lidt.cs プロジェクト: davidleon/MOSA-Project
        /// <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)
        {
            MemoryOperand operand = new MemoryOperand(new Mosa.Runtime.Metadata.Signatures.SigType(Mosa.Runtime.Metadata.CilElementType.Ptr), GeneralPurposeRegister.EAX, new System.IntPtr(0));

            context.SetInstruction(CPUx86.Instruction.MovInstruction, new RegisterOperand(new Mosa.Runtime.Metadata.Signatures.SigType(Mosa.Runtime.Metadata.CilElementType.Ptr), GeneralPurposeRegister.EAX), context.Operand1);
            context.AppendInstruction(CPUx86.Instruction.LidtInstruction, null, operand);
        }
コード例 #10
0
        /// <summary>
        /// Initializes static data members of the type loader.
        /// </summary>
        /// <param name="typeSystem">The type system.</param>
        public InternalTypeModule(ITypeSystem typeSystem)
        {
            Debug.Assert(typeSystem != null);

            this.typeSystem = typeSystem;
            this.types      = new List <RuntimeType>();
        }
コード例 #11
0
        /// <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
        }
コード例 #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TestRuntime"/>.
 /// </summary>
 public TestRuntime()
 {
     _memoryPageManager = new Win32MemoryPageManager();
     _typeLoader = new DefaultTypeSystem();
     _assemblyLoader = new AssemblyLoader(_typeLoader);
     _jitService = new SimpleJitService();
 }
コード例 #13
0
        void IAssemblyCompilerStage.Run(AssemblyCompiler compiler)
        {
            // Save the Compiler
            _compiler = compiler;
            // The compilation target Architecture
            _architecture = compiler.Architecture;
            // The type system
            _typeSystem = RuntimeBase.Instance.TypeLoader;

            // Enumerate all types and do an appropriate type layout
            ReadOnlyRuntimeTypeListView types = _typeSystem.GetTypesFromModule(compiler.Assembly);

            foreach (RuntimeType type in types)
            {
                switch (type.Attributes & TypeAttributes.LayoutMask)
                {
                case TypeAttributes.AutoLayout:
                    goto case TypeAttributes.SequentialLayout;

                case TypeAttributes.SequentialLayout:
                    CreateSequentialLayout(type);
                    break;

                case TypeAttributes.ExplicitLayout:
                    CreateExplicitLayout(type);
                    break;
                }
            }
        }
コード例 #14
0
        /// <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)
        {
            Context         loadContext = new Context(context.InstructionSet, context.Operand1.Definitions[0]);
            ConstantOperand op1         = loadContext.Operand1 as ConstantOperand;

            if (op1 == null)
            {
                throw new InvalidOperationException();
            }

            int irq = -1;

            object obj = op1.Value;

            if ((obj is int) || (obj is uint))
            {
                irq = (int)obj;
            }
            else if (obj is sbyte)
            {
                irq = (sbyte)obj;
            }

            if ((irq > 256) || (irq < 0))
            {
                throw new InvalidOperationException();
            }

            SigType PTR = new SigType(CilElementType.Ptr);

            context.SetInstruction(IR.Instruction.MoveInstruction, context.Result, new SymbolOperand(PTR, @"Mosa.Tools.Compiler.LinkerGenerated.<$>InterruptISR" + irq.ToString() + "()"));
        }
コード例 #15
0
        private SymbolOperand GetInternalAllocateStringCallTarget(ITypeSystem typeSystem)
        {
            RuntimeType   runtimeType = typeSystem.GetType(@"Mosa.Internal.Runtime");
            RuntimeMethod callTarget  = runtimeType.FindMethod(@"AllocateString");

            return(SymbolOperand.FromMethod(callTarget));
        }
コード例 #16
0
 /// <summary>
 /// Initializes a new instance of <see cref="CompilationRuntime"/>.
 /// </summary>
 public CompilationRuntime()
 {
     _typeLoader     = new DefaultTypeSystem();
     _assemblyLoader = new AssemblyLoader(_typeLoader);
     _memoryManager  = new MockMemoryPageManager();
     _jitService     = new MockJitService();
 }
コード例 #17
0
        public override IType Infer(ITypeSystem system, IEnvironment env, IList <IType> types)
        {
            if (Type == null)
            {
                var annotation = AsAnnotationType(system, env, types);
                if (annotation != null)
                {
                    return(annotation);
                }
            }
            var   args = Args.Select(arg => system.Infer(env, ToFormal(system, env, types, arg), types)).ToList();
            var   expr = (Node)Spec;
            var   self = system.Infer(env, expr, types);
            IType @out;

            if (Type != null)
            {
                var ctor = !(Type is IType) ? system.Const(env, (string)Type) : (IType)Type;
                @out = system.Infer(env, Apply(Var(ctor.Id, ctor), args.Select(arg => Const(arg)).ToArray(), IsAnnotation), types);
            }
            else
            {
                @out = system.NewGeneric();
                args.Add(@out);
                system.Unify(system.NewType(TypeSystem.Function, args.ToArray()), self);
            }
            return(@out);
        }
コード例 #18
0
        private WeakEventHandlerWeaver(ModuleDefinition moduleDefinition, ITypeSystem typeSystem, ILogger logger, TypeReference makeWeakAttributeReference)
        {
            _moduleDefinition = moduleDefinition;
            _typeSystem       = typeSystem;
            _logger           = logger;

            var makeWeakAttribute = makeWeakAttributeReference.Resolve();

            var helperTypes = makeWeakAttribute.Module.Types;

            _codeImporter = new CodeImporter(moduleDefinition)
            {
                NamespaceDecorator = value => "<>" + value
            };

            _weakAdapterType      = _codeImporter.Import(helperTypes.Single(t => t.Name == "WeakEventHandlerFodyWeakEventAdapter`4"));
            _eventTargetInterface = _codeImporter.Import(helperTypes.Single(t => t.Name == "IWeakEventHandlerFodyWeakEventTarget"));

            _weakAdapterConstructor = _weakAdapterType.GetConstructors().Single(ctor => ctor.Parameters.Count == 4);
            _generatedCodeAttribute = _weakAdapterType.CustomAttributes.Single(attr => attr.AttributeType.Name == nameof(GeneratedCodeAttribute));

            var weakAdapterMethods = _weakAdapterType.GetMethods().ToList();

            _weakAdapterSubscribeMethod   = weakAdapterMethods.Single(method => method.Name == "Subscribe");
            _weakAdapterUnsubscribeMethod = weakAdapterMethods.Single(method => method.Name == "Unsubscribe");
            _weakAdapterReleaseMethod     = weakAdapterMethods.Single(method => method.Name == "Release");

            _action2Type        = typeSystem.ImportType <Action <object, EventArgs> >();
            _action2Constructor = typeSystem.ImportMethod <Action <object, EventArgs>, object, IntPtr>(".ctor");
            _action3Type        = typeSystem.ImportType <Action <Type, object, EventArgs> >();
            _action3Constructor = typeSystem.ImportMethod <Action <Type, object, EventArgs>, object, IntPtr>(".ctor");
        }
コード例 #19
0
        /// <summary>
        /// Link time code generator used to compile dynamically created methods during link time.
        /// </summary>
        /// <param name="compiler">The assembly compiler used to compile this method.</param>
        /// <param name="methodName">The name of the created method.</param>
        /// <param name="instructionSet">The instruction set.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException"><paramref name="compiler"/>, <paramref name="methodName"/> or <paramref name="instructionSet"/> is null.</exception>
        /// <exception cref="System.ArgumentException"><paramref name="methodName"/> is invalid.</exception>
        public static LinkerGeneratedMethod Compile(AssemblyCompiler compiler, string methodName, InstructionSet instructionSet, ITypeSystem typeSystem)
        {
            if (compiler == null)
                throw new ArgumentNullException(@"compiler");
            if (methodName == null)
                throw new ArgumentNullException(@"methodName");
            if (methodName.Length == 0)
                throw new ArgumentException(@"Invalid method name.");

            LinkerGeneratedType compilerGeneratedType = typeSystem.InternalTypeModule.GetType(@"Mosa.Tools.Compiler", @"LinkerGenerated") as LinkerGeneratedType;

            // Create the type if we need to.
            if (compilerGeneratedType == null)
            {
                compilerGeneratedType = new LinkerGeneratedType(typeSystem.InternalTypeModule, @"Mosa.Tools.Compiler", @"LinkerGenerated", null);
                typeSystem.AddInternalType(compilerGeneratedType);
            }

            MethodSignature signature = new MethodSignature(BuiltInSigType.Void, new SigType[0]);

            // Create the method
            // HACK: <$> prevents the method from being called from CIL
            LinkerGeneratedMethod method = new LinkerGeneratedMethod(typeSystem.InternalTypeModule, "<$>" + methodName, compilerGeneratedType, signature);
            compilerGeneratedType.AddMethod(method);

            LinkerMethodCompiler methodCompiler = new LinkerMethodCompiler(compiler, compiler.Pipeline.FindFirst<ICompilationSchedulerStage>(), method, instructionSet);
            methodCompiler.Compile();
            return method;
        }
コード例 #20
0
        /// <summary>
        /// Initializes static data members of the type loader.
        /// </summary>
        /// <param name="typeSystem">The type system.</param>
        /// <param name="metadataModule">The metadata module.</param>
        public DefaultModuleTypeSystem(ITypeSystem typeSystem, IMetadataModule metadataModule)
        {
            Debug.Assert(typeSystem != null);
            Debug.Assert(metadataModule != null);
            Debug.Assert(metadataModule.Metadata != null);

            this.typeSystem = typeSystem;
            this.metadataModule = metadataModule;
            this.metadata = metadataModule.Metadata;

            methods = new RuntimeMethod[GetTableRows(TokenTypes.MethodDef)];
            fields = new RuntimeField[GetTableRows(TokenTypes.Field)];
            types = new RuntimeType[GetTableRows(TokenTypes.TypeDef)];
            parameters = new RuntimeParameter[GetTableRows(TokenTypes.Param)];

            typeSpecs = new RuntimeType[GetTableRows(TokenTypes.TypeSpec)];
            methodSpecs = new RuntimeMethod[GetTableRows(TokenTypes.MethodSpec)];

            // Load all types from the assembly into the type array
            LoadTypes();
            LoadGenerics();
            LoadTypeSpecs();
            LoadParameters();
            LoadCustomAttributes();
        }
コード例 #21
0
ファイル: TestAssemblyLinker.cs プロジェクト: djlw78/Mosa
        /// <summary>
        /// Special resolution for internal calls.
        /// </summary>
        /// <param name="method">The internal call method to resolve.</param>
        /// <returns>The virtualAddress</returns>
        protected unsafe override long ResolveInternalCall(RuntimeMethod method)
        {
            Delegate methodDelegate = null;

            if (false == this.resolvedInternals.TryGetValue(method, out methodDelegate))
            {
                ITypeSystem   ts           = RuntimeBase.Instance.TypeLoader;
                RuntimeMethod internalImpl = ts.GetImplementationForInternalCall(method);
                if (null != internalImpl)
                {
                    // Find the .NET counterpart for this method (we're not really compiling or using trampolines just yet.)
                    string typeName = String.Format(@"{0}.{1}, {2}",
                                                    internalImpl.DeclaringType.Namespace,
                                                    internalImpl.DeclaringType.Name,
                                                    internalImpl.Module.Name);
                    Type       type = Type.GetType(typeName);
                    MethodInfo mi   = type.GetMethod(internalImpl.Name);

                    methodDelegate = BuildDelegateForMethodInfo(mi);
                    this.resolvedInternals.Add(method, methodDelegate);
                }
            }

            if (null == methodDelegate)
            {
                throw new NotImplementedException(@"InternalCall implementation not loaded.");
            }

            return(Marshal.GetFunctionPointerForDelegate(methodDelegate).ToInt64());
        }
コード例 #22
0
        /// <summary>
        /// Initializes static data members of the type loader.
        /// </summary>
        /// <param name="typeSystem">The type system.</param>
        public InternalTypeModule(ITypeSystem typeSystem)
        {
            Debug.Assert(typeSystem != null);

            this.typeSystem = typeSystem;
            this.types = new List<RuntimeType>();
        }
コード例 #23
0
        public static CodecRegistration FromResourceType(
            Type resourceType,
            Type codecType,
            ITypeSystem typeSystem,
            MediaType mediaType,
            IEnumerable <string> extensions,
            object codecConfiguration,
            bool isSystem)
        {
            bool isStrict = false;

            if (IsStrictRegistration(resourceType))
            {
                resourceType = GetStrictType(resourceType);
                isStrict     = true;
            }

            return(new CodecRegistration(codecType,
                                         typeSystem.FromClr(resourceType),
                                         isStrict,
                                         mediaType,
                                         extensions,
                                         codecConfiguration,
                                         isSystem));
        }
コード例 #24
0
        /// <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);
        }
コード例 #25
0
 /// <summary>
 /// Initializes a new instance of <see cref="CompilationRuntime"/>.
 /// </summary>
 public CompilationRuntime()
 {
     this.typeLoader = new DefaultTypeSystem();
     this.assemblyLoader = new AssemblyLoader(this.typeLoader);
     this.memoryManager = new MockMemoryPageManager();
     this.jitService = new MockJitService();
 }
コード例 #26
0
ファイル: TypeLayoutStage.cs プロジェクト: hj1980/Mosa
        void IAssemblyCompilerStage.Run(AssemblyCompiler compiler)
        {
            // Save the Compiler
            _compiler = compiler;
            // The compilation target Architecture
            _architecture = compiler.Architecture;
            // The type system
            _typeSystem = RuntimeBase.Instance.TypeLoader;

            // Enumerate all types and do an appropriate type layout
            ReadOnlyRuntimeTypeListView types = _typeSystem.GetTypesFromModule (compiler.Assembly);
            foreach (RuntimeType type in types)
            {
                switch (type.Attributes & TypeAttributes.LayoutMask) {
                case TypeAttributes.AutoLayout:
                    goto case TypeAttributes.SequentialLayout;

                case TypeAttributes.SequentialLayout:
                    CreateSequentialLayout (type);
                    break;

                case TypeAttributes.ExplicitLayout:
                    CreateExplicitLayout (type);
                    break;
                }
            }
        }
コード例 #27
0
        private SymbolOperand GetInternalAllocateStringCallTarget(ITypeSystem typeSystem)
        {
            RuntimeType runtimeType = typeSystem.GetType(@"Mosa.Internal.Runtime");
            RuntimeMethod callTarget = runtimeType.FindMethod(@"AllocateString");

            return SymbolOperand.FromMethod(callTarget);
        }
コード例 #28
0
 public void Setup(AssemblyCompiler compiler)
 {
     this.compiler = compiler;
     architecture = compiler.Architecture;
     typeSystem = compiler.TypeSystem;
     typeLayout = compiler.TypeLayout;
 }
コード例 #29
0
        /// <summary>
        /// Replaces the intrinsic call site
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="typeSystem">The type system.</param>
        void IIntrinsicMethod.ReplaceIntrinsicCall(Context context, ITypeSystem typeSystem, IList<RuntimeParameter> parameters)
        {
            var result = context.Result;
            //var op1 = context.Operand1;
            var op2 = context.Operand2;

            var eax = new RegisterOperand(BuiltInSigType.IntPtr, GeneralPurposeRegister.EAX);
            var edx = new RegisterOperand(BuiltInSigType.IntPtr, GeneralPurposeRegister.EDX);
            var esp = new RegisterOperand(BuiltInSigType.IntPtr, GeneralPurposeRegister.ESP);
            var ebp = new RegisterOperand(BuiltInSigType.IntPtr, GeneralPurposeRegister.EBP);
            context.SetInstruction(X86.Sub, esp, new ConstantOperand(BuiltInSigType.IntPtr, parameters.Count * 4));
            context.AppendInstruction(X86.Mov, edx, esp);

            var size = parameters.Count * 4;
            foreach (var parameter in parameters)
            {
                context.AppendInstruction(X86.Mov, new MemoryOperand(BuiltInSigType.IntPtr, edx.Register, new IntPtr(size - 4)), new MemoryOperand(BuiltInSigType.IntPtr, ebp.Register, new IntPtr(size + 8)));
                size -= 4;
            }

            context.AppendInstruction(X86.Mov, eax, op2);
            context.AppendInstruction(X86.Call, null, new RegisterOperand(BuiltInSigType.IntPtr, GeneralPurposeRegister.EAX));
            context.AppendInstruction(X86.Add, esp, new ConstantOperand(BuiltInSigType.IntPtr, parameters.Count * 4));
            context.AppendInstruction(X86.Mov,result, new RegisterOperand(result.Type, GeneralPurposeRegister.EAX));
        }
コード例 #30
0
ファイル: Container.cs プロジェクト: einari/Yggdrasil
 public Container(IBindingManager bindingManager, IBindingDiscoverer bindingDiscoverer, IActivationManager activationManager, ITypeSystem typeSystem)
 {
     _bindingManager    = bindingManager;
     _bindingDiscoverer = bindingDiscoverer;
     _activationManager = activationManager;
     TypeSystem         = typeSystem;
 }
コード例 #31
0
 public WebFormsDefaultHandler(ICommunicationContext context, ITypeSystem typeSystem, IDependencyResolver resolver)
 {
     _context    = context;
     _typeSystem = typeSystem;
     _resolver   = resolver;
     _pageType   = typeSystem.FromClr <Page>();
 }
コード例 #32
0
        RuntimeMethod ITypeSystem.GetImplementationForInternalCall(RuntimeMethod internalCall)
        {
            Debug.Assert(internalCall != null, @"internalCall is null.");
            if (null == internalCall)
            {
                throw new ArgumentNullException(@"internalCall");
            }

            // Return value
            RuntimeMethod result = null;

            // Shortcut: If the call was resolved previously, scan it there
            if (this.internalCallTargets.TryGetValue(internalCall, out result))
            {
                return(result);
            }

            /*
             * FIXME:
             * - The following sequence requires that mscorlib is available in the test runtime.
             * - Maybe we should be smarter about its use though.
             * - Commented out right now, as we don't load assembly dependencies yet.
             */

            ITypeSystem ts = (ITypeSystem)this;
            // FIXME: Include this when we're loading mscorlib
            //RuntimeType rtMia = ts.GetType(@"System.Runtime.CompilerServices.MethodImplAttribute");
            //MethodImplAttribute mia = (MethodImplAttribute)internalCall.GetAttributes(rtMia, true);
            //Debug.Assert(MethodImplOptions.InternalCall == (mia.Value & MethodImplOptions.InternalCall), @"Method is not InternalCall.");
            //if (MethodImplOptions.InternalCall != (mia.Value & MethodImplOptions.InternalCall))
            //    throw new ArgumentException(@"Method not marked as an InternalCall.", @"internalCall");

            RuntimeType callImplType = ts.GetType("Mosa.Runtime.Vm.InternalCallImplAttribute");

            object[] callDefAttrs = internalCall.GetCustomAttributes(callImplType);
            Debug.Assert(0 != callDefAttrs.Length, @"No runtime call definition for icall!");
            Debug.Assert(1 == callDefAttrs.Length, @"Only one call definition for icall supported! Additional ones ignored!");
            InternalCallImplAttribute callDef = (InternalCallImplAttribute)callDefAttrs[0];

            // Scan all known types for icalls
            foreach (RuntimeType rType in internalTypes)
            {
                foreach (RuntimeMethod rMethod in rType.Methods)
                {
                    object[] callImpls = rMethod.GetCustomAttributes(callImplType);
                    foreach (InternalCallImplAttribute callImpl in callImpls)
                    {
                        if (callDef.Match(callImpl) == true)
                        {
                            // We found the sought icall, save it and return it
                            this.internalCallTargets[internalCall] = rMethod;
                            return(rMethod);
                        }
                    }
                }
            }

            throw new NotImplementedException(@"Requested InternalCall not loaded or not implemented.");
        }
コード例 #33
0
ファイル: TypeLayout.cs プロジェクト: davidleon/MOSA-Project
        /// <summary>
        /// Initializes a new instance of the <see cref="TypeLayout"/> class.
        /// </summary>
        /// <param name="typeSystem">The type system.</param>
        /// <param name="nativePointerSize">Size of the native pointer.</param>
        /// <param name="nativePointerAlignment">The native pointer alignment.</param>
        public TypeLayout(ITypeSystem typeSystem, int nativePointerSize, int nativePointerAlignment)
        {
            this.nativePointerAlignment = nativePointerAlignment;
            this.nativePointerSize      = nativePointerSize;
            this.typeSystem             = typeSystem;

            ResolveLayouts();
        }
コード例 #34
0
        public SystemReferences([NotNull] ITypeSystem typeSystem)
        {
#pragma warning disable CS1720 // Expression will always cause a System.NullReferenceException because the type's default value is null
            GetFieldFromHandle = typeSystem.ImportMethod(() => FieldInfo.GetFieldFromHandle(default(RuntimeFieldHandle)));
            PropertyInfoType   = typeSystem.ImportType <PropertyInfo>();
            GetTypeFromHandle  = typeSystem.ImportMethod(() => Type.GetTypeFromHandle(default(RuntimeTypeHandle)));
            GetPropertyInfo    = typeSystem.TryImportMethod(() => default(Type).GetProperty(default(string), default(BindingFlags)));
        }
コード例 #35
0
        public SimpleJitMethodCompiler(AssemblyCompiler compiler, ICompilationSchedulerStage compilationScheduler, RuntimeType type, RuntimeMethod method, Stream codeStream, ITypeSystem typeSystem)
            : base(compiler.Pipeline.FindFirst<IAssemblyLinker>(), compiler.Architecture, compilationScheduler, type, method, typeSystem, compiler.Pipeline.FindFirst<ITypeLayout>())
        {
            if (codeStream == null)
                throw new ArgumentNullException(@"codeStream");

            this.codeStream = codeStream;
        }
コード例 #36
0
        /// <summary>
        /// Initializes a new compiler instance.
        /// </summary>
        /// <param name="architecture">The compiler target architecture.</param>
        /// <param name="typeSystem">The type system.</param>
        protected AssemblyCompiler(IArchitecture architecture, ITypeSystem typeSystem)
        {
            if (architecture == null)
                throw new ArgumentNullException(@"architecture");

            this.architecture = architecture;
            this.pipeline = new CompilerPipeline();
            this.typeSystem = typeSystem;
        }
コード例 #37
0
        /// <summary>
        /// Replaces the intrinsic call site
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="typeSystem">The type system.</param>
        void IIntrinsicInternalMethod.ReplaceIntrinsicCall(Context context, ITypeSystem typeSystem, IList<RuntimeParameter> parameters)
        {
            Operand callTargetOperand = this.GetInternalAllocateStringCallTarget(typeSystem);
            Operand methodTableOperand = Operand.CreateSymbol(BuiltInSigType.IntPtr, StringClassMethodTableSymbolName);
            Operand lengthOperand = context.Operand1;
            Operand result = context.Result;

            context.SetInstruction(IRInstruction.Call, result, callTargetOperand, methodTableOperand, lengthOperand);
        }
コード例 #38
0
        /// <summary>
        /// Replaces the intrinsic call site
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="typeSystem">The type system.</param>
        void IIntrinsicMethod.ReplaceIntrinsicCall(Context context, ITypeSystem typeSystem, IList<RuntimeParameter> parameters)
        {
            Operand result = context.Result;

            RegisterOperand imm = new RegisterOperand(BuiltInSigType.UInt32, GeneralPurposeRegister.EAX);

            context.SetInstruction(IR.Instruction.MoveInstruction, imm, new RegisterOperand(BuiltInSigType.UInt32, control));
            context.AppendInstruction(IR.Instruction.MoveInstruction, result, imm);
        }
コード例 #39
0
        /// <summary>
        /// Replaces the intrinsic call site
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="typeSystem">The type system.</param>
        public void ReplaceIntrinsicCall(Context context, ITypeSystem typeSystem)
        {
            SymbolOperand callTargetOperand  = this.GetInternalAllocateStringCallTarget(typeSystem);
            SymbolOperand methodTableOperand = new SymbolOperand(BuiltInSigType.IntPtr, StringClassMethodTableSymbolName);
            Operand       lengthOperand      = context.Operand1;
            Operand       result             = context.Result;

            context.SetInstruction(IR.Instruction.CallInstruction, result, callTargetOperand, methodTableOperand, lengthOperand);
        }
コード例 #40
0
        /// <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)
        {
            Operand result = context.Result;

            Operand imm = Operand.CreateCPURegister(BuiltInSigType.UInt32, GeneralPurposeRegister.EAX);

            context.SetInstruction(IR.IRInstruction.Move, imm, Operand.CreateCPURegister(BuiltInSigType.UInt32, control));
            context.AppendInstruction(IR.IRInstruction.Move, result, imm);
        }
コード例 #41
0
        /// <summary>
        /// Initializes static data members of the type loader.
        /// </summary>
        /// <param name="typeSystem">The type system.</param>
        public InternalTypeModule(ITypeSystem typeSystem)
        {
            Debug.Assert(typeSystem != null);

            this.typeSystem = typeSystem;
            this.types = new List<RuntimeType>();
            this.methods = new List<RuntimeMethod>();
            this.typeNames = new HashSet<string>();
        }
コード例 #42
0
 public MultipartFormDataObjectCodec(
     ICommunicationContext context,
     ICodecRepository codecs,
     IDependencyResolver container,
     ITypeSystem typeSystem,
     IObjectBinderLocator binderLocator)
     : base(context, codecs, container, typeSystem, binderLocator)
 {
 }
コード例 #43
0
        /// <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);
        }
コード例 #44
0
        /// <summary>
        /// Replaces the intrinsic call site
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="typeSystem">The type system.</param>
        public void ReplaceIntrinsicCall(Context context, ITypeSystem typeSystem)
        {
            SymbolOperand callTargetOperand = this.GetInternalAllocateStringCallTarget(typeSystem);
            SymbolOperand methodTableOperand = new SymbolOperand(BuiltInSigType.IntPtr, StringClassMethodTableSymbolName);
            Operand lengthOperand = context.Operand1;
            Operand result = context.Result;

            context.SetInstruction(IR.Instruction.CallInstruction, result, callTargetOperand, methodTableOperand, lengthOperand);
        }
コード例 #45
0
        public static TypeReference?TryImportType(this ITypeSystem typeSystem, Type type)
        {
            if (!typeSystem.TryFindType(GetFullName(type), out var typeDefinition))
            {
                return(null);
            }

            return(typeSystem.ModuleDefinition.ImportReference(typeDefinition));
        }
コード例 #46
0
        /// <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);
        }
コード例 #47
0
        /// <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 tmp     = new RegisterOperand(new Mosa.Runtime.Metadata.Signatures.SigType(Mosa.Runtime.Metadata.CilElementType.Ptr), GeneralPurposeRegister.EDX);
            MemoryOperand   operand = new MemoryOperand(context.Operand1.Type, GeneralPurposeRegister.EDX, new System.IntPtr(0));

            context.SetInstruction(CPUx86.Instruction.MovInstruction, tmp, context.Operand1);
            context.AppendInstruction(CPUx86.Instruction.MovInstruction, result, operand);
        }
コード例 #48
0
ファイル: Get.cs プロジェクト: toddhainsworth/MOSA-Project
        /// <summary>
        /// Replaces the intrinsic call site
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="typeSystem">The type system.</param>
        void IIntrinsicMethod.ReplaceIntrinsicCall(Context context, ITypeSystem typeSystem, IList<RuntimeParameter> parameters)
        {
            Operand result = context.Result;

            RegisterOperand tmp = new RegisterOperand(BuiltInSigType.Ptr, GeneralPurposeRegister.EDX);
            MemoryOperand operand = new MemoryOperand(context.Operand1.Type, GeneralPurposeRegister.EDX, new System.IntPtr(0));

            context.SetInstruction(X86.Mov, tmp, context.Operand1);
            context.AppendInstruction(X86.Mov, result, operand);
        }
コード例 #49
0
 public static IMethod From(this ITypeSystem typeSystem, MethodInfo method)
 {
     return(typeSystem
            .FromClr(method.DeclaringType)
            .GetMethods()
            .First(m => m.Name == method.Name &&
                   m.InputMembers.Select(i => i.StaticType)
                   .SequenceEqual(
                       method.GetParameters().Select(p => p.ParameterType))));
 }
コード例 #50
0
        /// <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)
        {
            Operand operand1 = context.Operand1;

            Operand eax = Operand.CreateCPURegister(BuiltInSigType.UInt32, GeneralPurposeRegister.EAX);
            Operand cr = Operand.CreateCPURegister(BuiltInSigType.UInt32, control);

            context.SetInstruction(IR.IRInstruction.Move, eax, operand1);
            context.AppendInstruction(IR.IRInstruction.Move, cr, eax);
        }
コード例 #51
0
        public static void Weave(ModuleDefinition moduleDefinition, ITypeSystem typeSystem, ILogger logger)
        {
            if (!moduleDefinition.TryGetTypeReference(MakeWeakAttributeName, out var makeWeakAttributeReference))
            {
                logger.LogWarning("No reference to WeakEventHandler.dll found. Weaving skipped.");
                return;
            }

            new WeakEventHandlerWeaver(moduleDefinition, typeSystem, logger, makeWeakAttributeReference).Weave();
        }
コード例 #52
0
        /// <summary>
        /// Replaces the intrinsic call site
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="typeSystem">The type system.</param>
        void IIntrinsicMethod.ReplaceIntrinsicCall(Context context, ITypeSystem typeSystem, IList<RuntimeParameter> parameters)
        {
            Operand operand1 = context.Operand1;

            RegisterOperand eax = new RegisterOperand(BuiltInSigType.UInt32, GeneralPurposeRegister.EAX);
            RegisterOperand cr = new RegisterOperand(BuiltInSigType.UInt32, control);

            context.SetInstruction(IR.Instruction.MoveInstruction, eax, operand1);
            context.AppendInstruction(IR.Instruction.MoveInstruction, cr, eax);
        }
コード例 #53
0
ファイル: SwitchTask.cs プロジェクト: jeffreye/MOSA-Project
        /// <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)
        {
            Operand esp = Operand.CreateCPURegister(BuiltInSigType.Int32, GeneralPurposeRegister.ESP);

            context.SetInstruction(X86.Mov, esp, context.Operand1);
            context.AppendInstruction(X86.Popad);
            context.AppendInstruction(X86.Add, esp, Operand.CreateConstant(BuiltInSigType.Int32, 0x08));
            context.AppendInstruction(X86.Sti);
            context.AppendInstruction(X86.IRetd);
        }
コード例 #54
0
ファイル: Get.cs プロジェクト: illuminus86/MOSA-Project
        /// <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 tmp = new RegisterOperand(new Mosa.Runtime.Metadata.Signatures.SigType(Mosa.Runtime.Metadata.CilElementType.Ptr), GeneralPurposeRegister.EDX);
            MemoryOperand operand = new MemoryOperand(context.Operand1.Type, GeneralPurposeRegister.EDX, new System.IntPtr(0));

            context.SetInstruction(CPUx86.Instruction.MovInstruction, tmp, context.Operand1);
            context.AppendInstruction(CPUx86.Instruction.MovInstruction, result, operand);
        }
コード例 #55
0
ファイル: Get.cs プロジェクト: pdelprat/MOSA-Project
        /// <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)
        {
            Operand result = context.Result;

            Operand tmp = Operand.CreateCPURegister(BuiltInSigType.Ptr, GeneralPurposeRegister.EDX);
            Operand operand = Operand.CreateMemoryAddress(context.Operand1.Type, GeneralPurposeRegister.EDX, new System.IntPtr(0));

            context.SetInstruction(X86.Mov, tmp, context.Operand1);
            context.AppendInstruction(X86.Mov, result, operand);
        }
コード例 #56
0
        /// <summary>
        /// Replaces the intrinsic call site
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="typeSystem">The type system.</param>
        void IIntrinsicMethod.ReplaceIntrinsicCall(Context context, ITypeSystem typeSystem, IList<RuntimeParameter> parameters)
        {
            SigType I4 = BuiltInSigType.Int32;
            RegisterOperand esp = new RegisterOperand(I4, GeneralPurposeRegister.ESP);

            context.SetInstruction(X86.Mov, esp, context.Operand1);
            context.AppendInstruction(X86.Popad);
            context.AppendInstruction(X86.Add, esp, new ConstantOperand(I4, 0x08));
            context.AppendInstruction(X86.Sti);
            context.AppendInstruction(X86.IRetd);
        }
コード例 #57
0
        /// <summary>
        /// Replaces the intrinsic call site
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="typeSystem">The type system.</param>
        void IIntrinsicMethod.ReplaceIntrinsicCall(Context context, ITypeSystem typeSystem, IList<RuntimeParameter> parameters)
        {
            //var result = context.Result;
            //var op1 = context.Operand1;
            //var op2 = context.Operand2;

            //var eax = new RegisterOperand(BuiltInSigType.IntPtr, GeneralPurposeRegister.EAX);
            //var edx = new RegisterOperand(BuiltInSigType.IntPtr, GeneralPurposeRegister.EDX);
            //var esp = new RegisterOperand(BuiltInSigType.IntPtr, GeneralPurposeRegister.ESP);
            //var ebp = new RegisterOperand(BuiltInSigType.IntPtr, GeneralPurposeRegister.EBP);
            //context.SetInstruction(Instruction.SubInstruction, esp, new ConstantOperand(BuiltInSigType.IntPtr, parameters.Count * 4 + 4));
            //context.AppendInstruction(Instruction.MovInstruction, edx, esp);

            //var size = parameters.Count * 4 + 4;
            //foreach (var parameter in parameters)
            //{
            //    context.AppendInstruction(Instruction.MovInstruction, new MemoryOperand(BuiltInSigType.IntPtr, edx.Register, new IntPtr(size - 4)), new MemoryOperand(BuiltInSigType.IntPtr, ebp.Register, new IntPtr(size + 4)));
            //    size -= 4;
            //}
            //context.AppendInstruction(Instruction.MovInstruction, new MemoryOperand(BuiltInSigType.IntPtr, edx.Register, new IntPtr(size - 4)), op1);

            //context.AppendInstruction(Instruction.MovInstruction, eax, op2);
            //context.AppendInstruction(Instruction.CallPointerInstruction, null, new RegisterOperand(BuiltInSigType.IntPtr, GeneralPurposeRegister.EAX));
            //context.AppendInstruction(Instruction.AddInstruction, esp, new ConstantOperand(BuiltInSigType.IntPtr, parameters.Count * 4 + 4));
            //context.AppendInstruction(Instruction.MovInstruction, result, new RegisterOperand(result.Type, GeneralPurposeRegister.EAX));

            var result = context.Result;
            var op1 = context.Operand1;
            var op2 = context.Operand2;

            var r8 = new RegisterOperand(BuiltInSigType.IntPtr, GeneralPurposeRegister.R8);
            var r9 = new RegisterOperand(BuiltInSigType.IntPtr, GeneralPurposeRegister.R9);
            var sp = new RegisterOperand(BuiltInSigType.IntPtr, GeneralPurposeRegister.SP);
            var r11 = new RegisterOperand(BuiltInSigType.IntPtr, GeneralPurposeRegister.R11);
            var r10 = new RegisterOperand(BuiltInSigType.UInt32, GeneralPurposeRegister.R10);
            context.SetInstruction(Instruction.SubInstruction, sp, new ConstantOperand(BuiltInSigType.IntPtr, parameters.Count * 4 + 4));
            context.AppendInstruction(Instruction.MovInstruction, r9, sp);

            var size = parameters.Count * 4 + 4;
            foreach (var parameter in parameters)
            {
                context.AppendInstruction(Instruction.LdInstruction, r10, new MemoryOperand(BuiltInSigType.IntPtr, r11.Register, new IntPtr(size + 4)));
                context.AppendInstruction(Instruction.StInstruction, new MemoryOperand(BuiltInSigType.IntPtr, r9.Register, new IntPtr(size - 4)), r10);
                size -= 4;
            }
            context.AppendInstruction(Instruction.LdInstruction, r10, op1);
            context.AppendInstruction(Instruction.StInstruction, new MemoryOperand(BuiltInSigType.IntPtr, r9.Register, new IntPtr(size - 4)), r10);

            context.AppendInstruction(Instruction.MovInstruction, r8, op2);
            context.AppendInstruction(Instruction.IcallInstruction, null, new RegisterOperand(BuiltInSigType.IntPtr, GeneralPurposeRegister.R8));
            context.AppendInstruction(Instruction.MovInstruction, r10, new ConstantOperand(BuiltInSigType.IntPtr, parameters.Count * 4));
            context.AppendInstruction(Instruction.AddInstruction, sp, r10);
            context.AppendInstruction(Instruction.StInstruction, result, new RegisterOperand(result.Type, GeneralPurposeRegister.R8));
        }
コード例 #58
0
        /// <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)
        {
            SigType         I4  = new SigType(CilElementType.I4);
            RegisterOperand esp = new RegisterOperand(I4, GeneralPurposeRegister.ESP);

            context.SetInstruction(CPUx86.Instruction.MovInstruction, esp, context.Operand1);
            context.AppendInstruction(CPUx86.Instruction.PopadInstruction);
            context.AppendInstruction(CPUx86.Instruction.AddInstruction, esp, new ConstantOperand(I4, 0x08));
            context.AppendInstruction(CPUx86.Instruction.StiInstruction);
            context.AppendInstruction(CPUx86.Instruction.IRetdInstruction);
        }
コード例 #59
0
ファイル: SwitchTask.cs プロジェクト: davidleon/MOSA-Project
        /// <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)
        {
            SigType I4 = new SigType(CilElementType.I4);
            RegisterOperand esp = new RegisterOperand(I4, GeneralPurposeRegister.ESP);

            context.SetInstruction(CPUx86.Instruction.MovInstruction, esp, context.Operand1);
            context.AppendInstruction(CPUx86.Instruction.PopadInstruction);
            context.AppendInstruction(CPUx86.Instruction.AddInstruction, esp, new ConstantOperand(I4, 0x08));
            context.AppendInstruction(CPUx86.Instruction.StiInstruction);
            context.AppendInstruction(CPUx86.Instruction.IRetdInstruction);
        }
コード例 #60
0
        public override IType Infer(ITypeSystem system, IEnvironment env, IList <IType> types)
        {
            var known = new List <IType>(types);
            var type  = system.NewGeneric();
            var var   = (Var)Spec;
            var scope = Body.IsAnnotation ? env.Local(system) : env;

            env[var.Id] = type;
            known.Add(type);
            system.Unify(type, system.Infer(scope, Body, known));
            return(env[var.Id] = !type.Value.IsConstructor ? type.Value.Bind(var.Id) : type.Value);
        }