コード例 #1
0
        /// <summary>
        /// Patches the type.
        /// </summary>
        /// <param name="type">The type.</param>
        public void PatchType(RuntimeType type)
        {
            if (alreadyPatched.Contains(type))
                return;

            if (delegateStub == null)
                LoadDelegateStub();

            GenerateAndInsertFields(type);
            GenerateAndReplaceMethods(type);

            alreadyPatched.Add(type);
        }
コード例 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AotMethodCompiler"/> class.
        /// </summary>
        public AotMethodCompiler(AssemblyCompiler assemblyCompiler, ICompilationSchedulerStage compilationScheduler, RuntimeType type, RuntimeMethod method, CompilerOptions compilerOptions)
            : base(assemblyCompiler, type, method, null, compilationScheduler)
        {
            this.Pipeline.AddRange(
                new IMethodCompilerStage[]
                {
                    new DecodingStage(),
                    new BasicBlockBuilderStage(),
                    new ExceptionPrologueStage(),
                    new OperandDeterminationStage(),
                    new StaticAllocationResolutionStage(),
                    new CILTransformationStage(),

                    (compilerOptions.EnableSSA) ? new EdgeSplitStage() : null,
                    (compilerOptions.EnableSSA) ? new DominanceCalculationStage() : null,
                    (compilerOptions.EnableSSA) ? new PhiPlacementStage() : null,
                    (compilerOptions.EnableSSA) ? new EnterSSAStage() : null,

                    (compilerOptions.EnableSSA) ? new SSAOptimizations() : null,
                    //(compilerOptions.EnableSSA) ? new ConstantPropagationStage(ConstantPropagationStage.PropagationStage.PreFolding) : null,
                    //(compilerOptions.EnableSSA) ? new ConstantFoldingStage() : null,
                    //(compilerOptions.EnableSSA) ? new ConstantPropagationStage(ConstantPropagationStage.PropagationStage.PostFolding) : null,

                    (compilerOptions.EnableSSA) ? new LeaveSSA() : null,

                    new StrengthReductionStage(),
                    new StackLayoutStage(),
                    new PlatformStubStage(),
                    //new LoopAwareBlockOrderStage(),
                    new SimpleTraceBlockOrderStage(),
                    //new ReverseBlockOrderStage(),
                    //new LocalCSE(),
                    //new SimpleRegisterAllocatorStage(),
                    new CodeGenerationStage(),
                    //new RegisterUsageAnalyzerStage(),
                });
        }
コード例 #3
0
 /// <summary>
 /// Creates the method compiler.
 /// </summary>
 /// <param name="compilationScheduler">The compilation scheduler.</param>
 /// <param name="type">The type.</param>
 /// <param name="method">The method.</param>
 /// <returns></returns>
 public override IMethodCompiler CreateMethodCompiler(ICompilationSchedulerStage compilationScheduler, RuntimeType type, RuntimeMethod method)
 {
     IMethodCompiler mc = new AotMethodCompiler(this, compilationScheduler, type, method, CompilerOptions);
     this.Architecture.ExtendMethodCompilerPipeline(mc.Pipeline);
     return mc;
 }
コード例 #4
0
 /// <summary>
 /// Searches and replaces the method.
 /// </summary>
 /// <param name="type">The type.</param>
 /// <param name="methodName">Name of the method.</param>
 /// <param name="methodToReplace">The method to replace.</param>
 private void SearchAndReplaceMethod(RuntimeType type, string methodName, RuntimeMethod methodToReplace)
 {
     for (int i = 0; i < type.Methods.Count; ++i)
         if (type.Methods[i].Name == methodName)
             type.Methods[i] = methodToReplace;
 }
コード例 #5
0
        /// <summary>
        /// Loads the delegate stub.
        /// </summary>
        private void LoadDelegateStub()
        {
            foreach (var t in typeSystem.GetAllTypes())
            {
                if (t.FullName == "Mosa.Platform." + platform + ".Intrinsic.DelegateStub")
                {
                    delegateStub = t;
                    return;
                }

                // FIXME: Remove this!
                if (t.FullName == "Mosa.Platform." + platform.Trim('i') + ".Intrinsic.DelegateStub")
                {
                    delegateStub = t;
                    return;
                }
            }
        }
コード例 #6
0
        /// <summary>
        /// Generates and replace methods.
        /// </summary>
        /// <param name="type">The type.</param>
        private void GenerateAndReplaceMethods(RuntimeType type)
        {
            GenerateAndReplaceConstructor(type);

            if (type.Methods[1].Signature.ReturnType.Type == CilElementType.Void)
                GenerateAndReplaceInvokeMethod(type);
            else
                GenerateAndReplaceInvokeWithReturnMethod(type);

            GenerateAndReplaceBeginInvokeMethod(type);
            GenerateAndReplaceEndInvokeMethod(type);
        }
コード例 #7
0
        private void CompileType(RuntimeType type)
        {
            if (type.IsModule)
                return;

            if (type.IsInterface)
                return;

            // Can not compile an open generic type
            if (type.ContainsOpenGenericParameters)
                return;

            if (typeScheduled.Contains(type))
                return;

            //
            typeScheduled.Add(type);
            foreach (var method in type.Methods)
                CompileMethod(method);
        }
コード例 #8
0
 /// <summary>
 /// Gets the open generic.
 /// </summary>
 /// <param name="baseGenericType">Type of the base generic.</param>
 /// <returns></returns>
 CilGenericType ITypeModule.GetOpenGeneric(RuntimeType baseGenericType)
 {
     return null;
 }
コード例 #9
0
 /// <summary>
 /// Adds the type.
 /// </summary>
 /// <param name="type">The type.</param>
 public void AddType(RuntimeType type)
 {
     if (!types.Contains(type) && !typeNames.Contains(type.FullName)) // FIXME: Remove this line when generic patch is fixed! It duplicates generic types
     {
         types.Add(type);
         typeNames.Add(type.FullName);
     }
 }
コード例 #10
0
 /// <summary>
 /// Generates and inserts the method pointer field.
 /// </summary>
 /// <param name="type">The type.</param>
 private void GenerateAndInsertMethodPtrField(RuntimeType type)
 {
     var stubObjectField = delegateStub.Fields[1];
     var objectField = new CilRuntimeField(type.Module, MethodPtrFieldName,
         stubObjectField.Signature, stubObjectField.Token, 0, 0, type, stubObjectField.Attributes);
     type.Fields.Add(objectField);
 }
コード例 #11
0
 /// <summary>
 /// Generates and inserts fields.
 /// </summary>
 /// <param name="type">The type.</param>
 private void GenerateAndInsertFields(RuntimeType type)
 {
     GenerateAndInsertInstanceField(type);
     GenerateAndInsertMethodPtrField(type);
 }
コード例 #12
0
 /// <summary>
 /// Loads the delegate stub.
 /// </summary>
 private void LoadDelegateStub()
 {
     foreach (var t in typeSystem.GetAllTypes())
     {
         // FIXME: This is not platform independent
         if (t.FullName == "Mosa.Platform.x86.Intrinsic.DelegateStub")
         {
             delegateStub = t;
             return;
         }
     }
 }
コード例 #13
0
        private static RuntimeField GetField(RuntimeType type, string name)
        {
            foreach (var field in type.Fields)
            {
                if (field.Name == name)
                    return field;
            }

            return GetField(type.BaseType, name);
        }
コード例 #14
0
        void ICompilationScheduler.TrackTypeAllocated(RuntimeType type)
        {
            if (type.IsModule)
                return;

            typesAllocated.AddIfNew(type);

            if (compileAllMethods)
                CompileType(type);
        }
コード例 #15
0
        private SigType CreateSignatureTypeFor(IMetadataModule module, Token ctorToken, RuntimeType declaringType)
        {
            Token typeToken = declaringType.Token;
            if (IsMemberRef(ctorToken) == true)
            {
                typeToken = GetLocalTypeRefToken(module, ctorToken);
            }

            //if (declaringType.IsValueType)
            //{
            //    // TODO
            //    var typeSpecRow = module.Metadata.ReadTypeSpecRow(typeToken);
            //    var typeSpecSignature = new TypeSpecSignature(module.Metadata, typeSpecRow.SignatureBlobIdx);
            //    return typeSpecSignature.Type;
            //    //return new ValueTypeSigType(typeToken);
            //}

            return new ClassSigType(typeToken);
        }
コード例 #16
0
 public override IMethodCompiler CreateMethodCompiler(ICompilationSchedulerStage schedulerStage, RuntimeType type, RuntimeMethod method)
 {
     IMethodCompiler mc = new TestCaseMethodCompiler(this, schedulerStage, type, method);
     Architecture.ExtendMethodCompilerPipeline(mc.Pipeline);
     return mc;
 }
コード例 #17
0
        /// <summary>
        /// Generates and replace constructor.
        /// </summary>
        /// <param name="type">The type.</param>
        private void GenerateAndReplaceConstructor(RuntimeType type)
        {
            RuntimeParameter[] parameters = new RuntimeParameter[type.Methods[0].Parameters.Count];
            type.Methods[0].Parameters.CopyTo(parameters, 0);
            var stubConstructor = delegateStub.Methods[0];

            var constructor = new CilRuntimeMethod(delegateStub.Module, ConstructorName,
                type.Methods[0].Signature, stubConstructor.Token, type, stubConstructor.Attributes, stubConstructor.ImplAttributes, stubConstructor.Rva);

            foreach (var parameter in parameters)
                constructor.Parameters.Add(parameter);

            SearchAndReplaceMethod(type, ConstructorName, constructor);
        }
コード例 #18
0
 /// <summary>
 /// Gets the method.
 /// </summary>
 /// <param name="token">The token.</param>
 /// <param name="callingType">Type of the calling.</param>
 /// <returns></returns>
 RuntimeMethod ITypeModule.GetMethod(Token token, RuntimeType callingType)
 {
     return null;
 }
コード例 #19
0
        /// <summary>
        /// Generates the and replace end invoke method.
        /// </summary>
        /// <param name="type">The type.</param>
        private void GenerateAndReplaceEndInvokeMethod(RuntimeType type)
        {
            RuntimeParameter[] parameters = new RuntimeParameter[type.Methods[3].Parameters.Count];
            type.Methods[3].Parameters.CopyTo(parameters, 0);
            var stubMethod = delegateStub.Methods[3];

            var method = new CilRuntimeMethod(delegateStub.Module, EndInvokeMethodName,
                type.Methods[3].Signature, stubMethod.Token, type, stubMethod.Attributes, stubMethod.ImplAttributes, stubMethod.Rva);

            foreach (var parameter in parameters)
                method.Parameters.Add(parameter);

            SearchAndReplaceMethod(type, EndInvokeMethodName, method);
        }
コード例 #20
0
ファイル: RuntimeMethod.cs プロジェクト: GeroL/MOSA-Project
 /// <summary>
 /// Initializes a new instance of the <see cref="RuntimeMethod"/> class.
 /// </summary>
 /// <param name="token">The token.</param>
 /// <param name="declaringType">The type, which declared this method.</param>
 public RuntimeMethod(ITypeModule module, Token token, RuntimeType declaringType)
     : base(module, token, declaringType)
 {
     this.genericParameters = new List<GenericParameter>();
 }
コード例 #21
0
        /// <summary>
        /// Generates the and replace invoke with return method.
        /// </summary>
        /// <param name="type">The type.</param>
        private void GenerateAndReplaceInvokeWithReturnMethod(RuntimeType type)
        {
            RuntimeParameter[] parameters = new RuntimeParameter[type.Methods[1].Parameters.Count];
            type.Methods[1].Parameters.CopyTo(parameters, 0);
            var stubInvoke = delegateStub.Methods[2];

            var invokeMethod = new CilRuntimeMethod(delegateStub.Module, InvokeMethodName,
                type.Methods[1].Signature, stubInvoke.Token, type, stubInvoke.Attributes, stubInvoke.ImplAttributes, stubInvoke.Rva);
            foreach (var parameter in parameters)
                invokeMethod.Parameters.Add(parameter);

            SearchAndReplaceMethod(type, InvokeMethodName, invokeMethod);
        }