Beispiel #1
0
        public Compiler(MosaCompiler mosaCompiler)
        {
            TypeSystem      = mosaCompiler.TypeSystem;
            TypeLayout      = mosaCompiler.TypeLayout;
            CompilerOptions = mosaCompiler.CompilerOptions;
            Linker          = mosaCompiler.Linker;
            CompilerTrace   = mosaCompiler.CompilerTrace;
            Architecture    = CompilerOptions.Architecture;

            PostCompilerTraceEvent(CompilerEvent.CompilerStart);

            CompilerExtensions.AddRange(mosaCompiler.CompilerExtensions);

            MethodStagePipelines = new Pipeline <BaseMethodCompilerStage> [mosaCompiler.MaxThreads + 1];

            MethodScheduler = new MethodScheduler(this);
            MethodScanner   = new MethodScanner(this);

            foreach (var type in Assembly.GetExecutingAssembly().GetTypes())
            {
                if (!type.IsClass)
                {
                    continue;
                }

                foreach (var method in type.GetRuntimeMethods())
                {
                    // Now get all the IntrinsicMethodAttribute attributes
                    var attributes = (IntrinsicMethodAttribute[])method.GetCustomAttributes(typeof(IntrinsicMethodAttribute), true);

                    for (int i = 0; i < attributes.Length; i++)
                    {
                        var d = (InstrinsicMethodDelegate)Delegate.CreateDelegate(typeof(InstrinsicMethodDelegate), method);

                        // Finally add the dictionary entry mapping the target name and the delegate
                        InternalIntrinsicMethods.Add(attributes[i].Target, d);
                    }
                }
            }

            PlugSystem = new PlugSystem(TypeSystem);

            PlatformInternalRuntimeType = GetPlatformInternalRuntimeType();
            InternalRuntimeType         = GeInternalRuntimeType();

            // Build the default compiler pipeline
            CompilerPipeline.Add(GetDefaultCompilerPipeline(CompilerOptions));

            foreach (var extension in CompilerExtensions)
            {
                extension.ExtendCompilerPipeline(CompilerPipeline);
            }

            Architecture.ExtendCompilerPipeline(CompilerPipeline, CompilerOptions);

            IsStopped = false;
            WorkCount = 0;
        }
Beispiel #2
0
        public MosaCompiler(List <BaseCompilerExtension> compilerExtensions = null, int maxThreads = 0)
        {
            MaxThreads = (maxThreads == 0) ? Environment.ProcessorCount : maxThreads;

            if (compilerExtensions != null)
            {
                CompilerExtensions.AddRange(compilerExtensions);
            }
        }
Beispiel #3
0
        public MosaCompiler(CompilerOptions compilerOptions = null, List <BaseCompilerExtension> compilerExtensions = null, int maxThreads = 0)
        {
            MaxThreads = (maxThreads == 0) ? Environment.ProcessorCount * 2 : maxThreads;

            CompilerOptions = compilerOptions ?? new CompilerOptions();
            CompilerTrace   = new CompilerTrace(CompilerOptions);

            if (compilerExtensions != null)
            {
                CompilerExtensions.AddRange(compilerExtensions);
            }
        }
Beispiel #4
0
        public Compiler(MosaCompiler mosaCompiler)
        {
            Architecture = mosaCompiler.CompilerOptions.Architecture;

            TypeSystem           = mosaCompiler.TypeSystem;
            TypeLayout           = mosaCompiler.TypeLayout;
            CompilerTrace        = mosaCompiler.CompilerTrace;
            CompilerOptions      = mosaCompiler.CompilerOptions;
            CompilationScheduler = mosaCompiler.CompilationScheduler;
            Linker = mosaCompiler.Linker;

            CompilerExtensions.AddRange(mosaCompiler.CompilerExtensions);

            methodStagePipelines = new Pipeline <BaseMethodCompilerStage> [mosaCompiler.MaxThreads];

            // Create new dictionary
            IntrinsicTypes = new Dictionary <string, Type>();

            foreach (var type in Assembly.GetExecutingAssembly().GetTypes())
            {
                if (type.IsClass && typeof(IIntrinsicInternalMethod).IsAssignableFrom(type))
                {
                    // Now get all the ReplacementTarget attributes
                    var attributes = (ReplacementTargetAttribute[])type.GetCustomAttributes(typeof(ReplacementTargetAttribute), true);
                    for (int i = 0; i < attributes.Length; i++)
                    {
                        // Finally add the dictionary entry mapping the target string and the type
                        IntrinsicTypes.Add(attributes[i].Target, type);
                    }
                }
            }

            PlugSystem = new PlugSystem(TypeSystem);

            PlatformInternalRuntimeType = GetPlatformInternalRuntimeType();
            InternalRuntimeType         = GeInternalRuntimeType();

            // Build the default compiler pipeline
            CompilerPipeline.Add(GetDefaultCompilerPipeline(CompilerOptions));

            foreach (var extension in CompilerExtensions)
            {
                extension.ExtendCompilerPipeline(CompilerPipeline);
            }

            Architecture.ExtendCompilerPipeline(CompilerPipeline);

            IsStopped = false;
        }