/// <summary>
        /// Initializes a new instance of the <see cref="BaseMethodCompiler" /> class.
        /// </summary>
        /// <param name="compiler">The assembly compiler.</param>
        /// <param name="method">The method to compile by this instance.</param>
        /// <param name="basicBlocks">The basic blocks.</param>
        /// <param name="threadID">The thread identifier.</param>
        protected BaseMethodCompiler(BaseCompiler compiler, MosaMethod method, BasicBlocks basicBlocks, int threadID)
        {
            Compiler = compiler;
            Method = method;
            Type = method.DeclaringType;
            Scheduler = compiler.CompilationScheduler;
            Architecture = compiler.Architecture;
            TypeSystem = compiler.TypeSystem;
            TypeLayout = compiler.TypeLayout;
            Trace = compiler.CompilerTrace;
            Linker = compiler.Linker;
            BasicBlocks = basicBlocks ?? new BasicBlocks();
            Pipeline = new CompilerPipeline();
            StackLayout = new StackLayout(Architecture, method.Signature.Parameters.Count + (method.HasThis || method.HasExplicitThis ? 1 : 0));
            VirtualRegisters = new VirtualRegisters(Architecture);
            LocalVariables = emptyOperandList;
            ThreadID = threadID;
            DominanceAnalysis = new Dominance(Compiler.CompilerOptions.DominanceAnalysisFactory, BasicBlocks);
            PluggedMethod = compiler.PlugSystem.GetPlugMethod(Method);
            stop = false;

            MethodData = compiler.CompilerData.GetCompilerMethodData(Method);
            MethodData.Counters.Clear();

            EvaluateParameterOperands();
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new compiler instance.
        /// </summary>
        /// <param name="architecture">The compiler target architecture.</param>
        /// <param name="assembly">The assembly of this compiler.</param>
        /// <exception cref="System.ArgumentNullException">Either <paramref name="architecture"/> or <paramref name="assembly"/> is null.</exception>
        protected AssemblyCompiler(IArchitecture architecture, IMetadataModule assembly)
        {
            if (architecture == null)
                throw new ArgumentNullException(@"architecture");

            _architecture = architecture;
            _assembly = assembly;
            _pipeline = new CompilerPipeline();
        }
        /// <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;
        }
Esempio n. 4
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, ITypeLayout typeLayout, IInternalTrace internalTrace, CompilerOptions compilerOptions)
        {
            if (architecture == null)
                throw new ArgumentNullException(@"architecture");

            this.pipeline = new CompilerPipeline();
            this.architecture = architecture;
            this.typeSystem = typeSystem;
            this.typeLayout = typeLayout;
            this.internalTrace = internalTrace;
            this.compilerOptions = compilerOptions;
            this.genericTypePatcher = new GenericTypePatcher(typeSystem);
        }
Esempio n. 5
0
        /// <summary>
        /// Initializes a new compiler instance.
        /// </summary>
        /// <param name="architecture">The compiler target architecture.</param>
        /// <param name="typeSystem">The type system.</param>
        /// <param name="typeLayout">The type layout.</param>
        /// <param name="compilationScheduler">The compilation scheduler.</param>
        /// <param name="compilerTrace">The compiler trace.</param>
        /// <param name="linker">The linker.</param>
        /// <param name="compilerOptions">The compiler options.</param>
        /// <exception cref="System.ArgumentNullException">@Architecture</exception>
        protected BaseCompiler(BaseArchitecture architecture, TypeSystem typeSystem, MosaTypeLayout typeLayout, ICompilationScheduler compilationScheduler, CompilerTrace compilerTrace, BaseLinker linker, CompilerOptions compilerOptions)
        {
            if (architecture == null)
                throw new ArgumentNullException(@"Architecture");

            Pipeline = new CompilerPipeline();
            Architecture = architecture;
            TypeSystem = typeSystem;
            TypeLayout = typeLayout;
            CompilerTrace = compilerTrace;
            CompilerOptions = compilerOptions;
            Counters = new Counters();
            CompilationScheduler = compilationScheduler;
            PlugSystem = new PlugSystem();
            Linker = linker;

            if (Linker == null)
            {
                Linker = compilerOptions.LinkerFactory();
                Linker.Initialize(compilerOptions.BaseAddress, architecture.Endianness, architecture.ElfMachineType);
            }

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

            // Get all the classes that implement the IIntrinsicInternalMethod interface
            IEnumerable<Type> types = AppDomain.CurrentDomain.GetAssemblies()
                .SelectMany(s => s.GetTypes())
                .Where(p => typeof(IIntrinsicInternalMethod).IsAssignableFrom(p) && p.IsClass);

            // Iterate through all the found types
            foreach (var t in types)
            {
                // Now get all the ReplacementTarget attributes
                var attributes = (ReplacementTargetAttribute[])t.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, t);
                }
            }

            PlatformInternalRuntimeType = GetPlatformInternalRuntimeType();
        }
Esempio n. 6
0
        /// <summary>
        /// Initializes a new compiler instance.
        /// </summary>
        /// <param name="architecture">The compiler target architecture.</param>
        /// <param name="typeSystem">The type system.</param>
        /// <param name="typeLayout">The type layout.</param>
        /// <param name="compilationScheduler">The compilation scheduler.</param>
        /// <param name="internalTrace">The internal trace.</param>
        /// <param name="compilerOptions">The compiler options.</param>
        protected BaseCompiler(BaseArchitecture architecture, TypeSystem typeSystem, MosaTypeLayout typeLayout, ICompilationScheduler compilationScheduler, IInternalTrace internalTrace, ILinker linker, CompilerOptions compilerOptions)
        {
            if (architecture == null)
                throw new ArgumentNullException(@"Architecture");

            Pipeline = new CompilerPipeline();
            Architecture = architecture;
            TypeSystem = typeSystem;
            TypeLayout = typeLayout;
            InternalTrace = internalTrace;
            CompilerOptions = compilerOptions;
            Counters = new Counters();
            CompilationScheduler = compilationScheduler;
            PlugSystem = new PlugSystem();
            Linker = linker;

            if (Linker == null)
            {
                Linker = compilerOptions.LinkerFactory();
                Linker.Initialize(compilerOptions.OutputFile, architecture.Endianness, architecture.ElfMachineType);
            }
        }
Esempio n. 7
0
        public CompileUnit SetUpTypeInferenceSource()
        {
            CompilerPipeline compilerPipeline = UnityScriptCompiler.Pipelines.AdjustBooPipeline(new ResolveExpressions());

            compilerPipeline.RemoveAt(compilerPipeline.Find(typeof(ApplySemantics)));
            compilerPipeline.BreakOnErrors = false;
            var unityScriptCompiler = new UnityScriptCompiler();

            CopyUnityScriptCompilerParametersTo(unityScriptCompiler);
            unityScriptCompiler.Parameters.Pipeline = compilerPipeline;

            unityScriptCompiler.Parameters.AddToEnvironment(
                typeof(TypeInferenceRuleProvider),
                GetCustomTypeInferenceRuleProvider);

            var compilerContext = unityScriptCompiler.Run(CompileUnit.CloneNode());

            if (((ICollection)compilerContext.Errors).Count != 0)
            {
                throw new CompilationErrorsException(compilerContext.Errors);
            }
            return(compilerContext.CompileUnit);
        }
Esempio n. 8
0
        /// <summary>
        /// Extends the method compiler pipeline with x86 specific stages.
        /// </summary>
        /// <param name="methodCompilerPipeline">The method compiler pipeline to extend.</param>
        public override void ExtendMethodCompilerPipeline(CompilerPipeline methodCompilerPipeline)
        {
            methodCompilerPipeline.InsertAfterLast <PlatformStubStage>(
                new IMethodCompilerStage[]
            {
                //new CheckOperandCountStage(),
                new PlatformIntrinsicStage(),
                new LongOperandTransformationStage(),
                new IRTransformationStage(),

                //new StopStage(),

                new TweakTransformationStage(),

                new FixedRegisterAssignmentStage(),
                new SimpleDeadCodeRemovalStage(),
                new AddressModeConversionStage(),
                new FloatingPointStage(),
            });

            methodCompilerPipeline.InsertAfterLast <StackLayoutStage>(
                new BuildStackStage()
                );

            methodCompilerPipeline.InsertBefore <CodeGenerationStage>(
                new FinalTweakTransformationStage()
                );

            methodCompilerPipeline.InsertBefore <CodeGenerationStage>(
                new JumpOptimizationStage()
                );

            methodCompilerPipeline.InsertBefore <CodeGenerationStage>(
                new ConversionPhaseStage()
                );
        }
Esempio n. 9
0
 /// <summary>
 /// Extends the post compiler pipeline with ARMv6 specific stages.
 /// </summary>
 /// <param name="compilerPipeline">The pipeline to extend.</param>
 public override void ExtendPostCompilerPipeline(CompilerPipeline compilerPipeline)
 {
 }
Esempio n. 10
0
 /// <summary>
 /// Extends the post-compiler pipeline with x86 compiler stages.
 /// </summary>
 /// <param name="compilerPipeline">The pipeline to extend.</param>
 public override void ExtendPostCompilerPipeline(CompilerPipeline compilerPipeline)
 {
 }
Esempio n. 11
0
        /// <summary>
        /// Extends the method compiler pipeline with x86 specific stages.
        /// </summary>
        /// <param name="methodCompilerPipeline">The method compiler pipeline to extend.</param>
        public override void ExtendMethodCompilerPipeline(CompilerPipeline methodCompilerPipeline)
        {
            // FIXME: Create a specific code generator instance using requested feature flags.
            // FIXME: Add some more optimization passes, which take advantage of advanced x86 instructions
            // and packed operations available with SSE extensions
            methodCompilerPipeline.InsertAfterLast<PlatformStubStage>(
                new IMethodCompilerStage[]
                {
                    //new CheckOperandCountStage(),
                    new PlatformIntrinsicTransformationStage(),
                    new LongOperandTransformationStage(),

                    //new StopStage(),
                    new IRTransformationStage(),
                    new TweakTransformationStage(),

                    new FixedRegisterAssignmentStage(),
                    new SimpleDeadCodeRemovalStage(),
                    new AddressModeConversionStage(),
                    new FloatingPointStage(),
                });

            methodCompilerPipeline.InsertAfterLast<StackLayoutStage>(
                new BuildStackStage()
            );

            methodCompilerPipeline.InsertBefore<CodeGenerationStage>(
                new FinalTweakTransformationStage()
            );

            methodCompilerPipeline.InsertBefore<CodeGenerationStage>(
                new JumpPeepholeOptimizationStage()
            );
        }
Esempio n. 12
0
        /// <summary>
        /// Extends the method compiler pipeline with x86 specific stages.
        /// </summary>
        /// <param name="methodCompilerPipeline">The method compiler pipeline to extend.</param>
        public override void ExtendMethodCompilerPipeline(CompilerPipeline methodCompilerPipeline)
        {
            // FIXME: Create a specific code generator instance using requested feature flags.
            // FIXME: Add some more optimization passes, which take advantage of advanced x86 instructions
            // and packed operations available with MMX/SSE extensions
            methodCompilerPipeline.InsertAfter<PlatformStubStage>(
                new IMethodCompilerStage[]
                {
                    //InstructionLogger.Instance,
                    new LongOperandTransformationStage(),
                    //InstructionLogger.Instance,
                    new AddressModeConversionStage(),
                    //InstructionLogger.Instance,
                    new IRTransformationStage(),
                    //InstructionLogger.Instance,
                    new TweakTransformationStage(),
                    //InstructionLogger.Instance,
                    new MemToMemConversionStage(),
                    //InstructionLogger.Instance,
                    new ExceptionHeaderPreprocessingStage(),
                });

            methodCompilerPipeline.InsertAfter<IBlockOrderStage>(
                new IMethodCompilerStage[]
                {
                    new SimplePeepholeOptimizationStage(),
                    //InstructionLogger.Instance,
                });

            //FlowGraphVisualizationStage.Instance,
        }
Esempio n. 13
0
 /// <summary>
 /// Extends the assembly compiler pipeline with x86 specific stages.
 /// </summary>
 /// <param name="assemblyCompilerPipeline">The assembly compiler pipeline to extend.</param>
 public override void ExtendAssemblyCompilerPipeline(CompilerPipeline assemblyCompilerPipeline)
 {
 }
Esempio n. 14
0
        public void Initialize(MosaCompiler compiler)
        {
            if (compiler == null)
                throw new ArgumentNullException(@"compiler");

            Compiler = compiler;

            Architecture = Compiler.CompilerOptions.Architecture;
            TypeSystem = Compiler.TypeSystem;
            TypeLayout = Compiler.TypeLayout;
            CompilerTrace = Compiler.CompilerTrace;
            CompilerOptions = Compiler.CompilerOptions;
            CompilationScheduler = Compiler.CompilationScheduler;
            Linker = compiler.Linker;

            PreCompilePipeline = new CompilerPipeline();
            PostCompilePipeline = new CompilerPipeline();
            Counters = new Counters();
            PlugSystem = new PlugSystem();
            CompilerData = new CompilerData(this);

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

            // Get all the classes that implement the IIntrinsicInternalMethod interface
            IEnumerable<Type> types = AppDomain.CurrentDomain.GetAssemblies()
                .SelectMany(s => s.GetTypes())
                .Where(p => typeof(IIntrinsicInternalMethod).IsAssignableFrom(p) && p.IsClass);

            // Iterate through all the found types
            foreach (var t in types)
            {
                // Now get all the ReplacementTarget attributes
                var attributes = (ReplacementTargetAttribute[])t.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, t);
                }
            }

            PlatformInternalRuntimeType = GetPlatformInternalRuntimeType();

            // Extended Setup
            ExtendCompilerSetup();

            // Build the default pre-compiler pipeline
            Architecture.ExtendPreCompilerPipeline(this.PreCompilePipeline);

            // Build the default post-compiler pipeline
            Architecture.ExtendPostCompilerPipeline(this.PostCompilePipeline);
        }
Esempio n. 15
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BaseMethodCompiler"/> class.
        /// </summary>
        /// <param name="linker">The _linker.</param>
        /// <param name="architecture">The target compilation Architecture.</param>
        /// <param name="type">The type, which owns the method to compile.</param>
        /// <param name="method">The method to compile by this instance.</param>
        protected BaseMethodCompiler(
			IAssemblyLinker linker,
			IArchitecture architecture,
			ICompilationSchedulerStage compilationScheduler,
			RuntimeType type,
			RuntimeMethod method,
			ITypeSystem typeSystem,
			ITypeLayout typeLayout)
        {
            if (architecture == null)
                throw new ArgumentNullException(@"architecture");

            if (linker == null)
                throw new ArgumentNullException(@"linker");

            if (compilationScheduler == null)
                throw new ArgumentNullException(@"compilationScheduler");

            this.linker = linker;
            this.architecture = architecture;
            this.method = method;
            this.type = type;

            parameters = new List<Operand>(new Operand[method.Parameters.Count]);
            nextStackSlot = 0;
            basicBlocks = new List<BasicBlock>();
            instructionSet = null; // this will be set later

            pipeline = new CompilerPipeline();

            this.compilationScheduler = compilationScheduler;
            this.moduleTypeSystem = method.Module;
            this.typeSystem = typeSystem;
            this.typeLayout = typeLayout;
        }
Esempio n. 16
0
 protected abstract void SetUpCompilerPipeline(CompilerPipeline pipeline);
Esempio n. 17
0
        void ParseOptions(string[] args, CompilerParameters _options)
        {
            bool      debugSteps = false;
            ArrayList arglist    = new ArrayList(args);

            ExpandResponseFiles(ref arglist);
            AddDefaultResponseFile(ref arglist);
            foreach (string arg in arglist)
            {
                if ("-" == arg)
                {
                    _options.Input.Add(new StringInput("<stdin>", Consume(Console.In)));
                }
                else
                {
                    if (IsFlag(arg))
                    {
                        if ("-utf8" == arg)
                        {
                            continue;
                        }
                        switch (arg[1])
                        {
                        case 'v':
                        {
                            _options.TraceSwitch.Level = TraceLevel.Warning;
                            Trace.Listeners.Add(new TextWriterTraceListener(Console.Error));
                            if (arg.Length > 2)
                            {
                                switch (arg.Substring(1))
                                {
                                case "vv":
                                {
                                    _options.TraceSwitch.Level = TraceLevel.Info;
                                    break;
                                }

                                case "vvv":
                                {
                                    _options.TraceSwitch.Level = TraceLevel.Verbose;
                                    break;
                                }
                                }
                            }
                            else
                            {
                                _options.TraceSwitch.Level = TraceLevel.Warning;
                            }
                            break;
                        }

                        case 'r':
                        {
                            if (arg.IndexOf(":") > 2)
                            {
                                switch (arg.Substring(1, 8))
                                {
                                case "resource":
                                {
                                    string resourceFile;
                                    int    start = arg.IndexOf(":") + 1;
                                    int    comma = arg.LastIndexOf(',');
                                    if (comma >= 0)
                                    {
                                        resourceFile = arg.Substring(start, comma - start);
                                        string resourceName = arg.Substring(comma + 1);
                                        _options.Resources.Add(new NamedFileResource(resourceFile, resourceName));
                                    }
                                    else
                                    {
                                        resourceFile = arg.Substring(start);
                                        _options.Resources.Add(new FileResource(resourceFile));
                                    }
                                    break;
                                }

                                default:
                                {
                                    InvalidOption(arg);
                                    break;
                                }
                                }
                            }
                            else
                            {
                                string assemblyName = arg.Substring(3);
                                _options.References.Add(LoadAssembly(assemblyName));
                            }
                            break;
                        }

                        case 'o':
                        {
                            _options.OutputAssembly = arg.Substring(arg.IndexOf(":") + 1);
                            break;
                        }

                        case 't':
                        {
                            string targetType = arg.Substring(arg.IndexOf(":") + 1);
                            switch (targetType)
                            {
                            case "library":
                            {
                                _options.OutputType = CompilerOutputType.Library;
                                break;
                            }

                            case "exe":
                            {
                                _options.OutputType = CompilerOutputType.ConsoleApplication;
                                break;
                            }

                            case "winexe":
                            {
                                _options.OutputType = CompilerOutputType.WindowsApplication;
                                break;
                            }

                            default:
                            {
                                InvalidOption(arg);
                                break;
                            }
                            }
                            break;
                        }

                        case 'p':
                        {
                            string pipelineName = arg.Substring(3);
                            _options.Pipeline = CompilerPipeline.GetPipeline(pipelineName);
                            break;
                        }

                        case 'c':
                        {
                            string culture = arg.Substring(3);
                            Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture(culture);
                            break;
                        }

                        case 's':
                        {
                            switch (arg.Substring(1, 6))
                            {
                            case "srcdir":
                            {
                                string path = arg.Substring(8);
                                AddFilesForPath(path, _options);
                                break;
                            }

                            default:
                            {
                                InvalidOption(arg);
                                break;
                            }
                            }
                            break;
                        }

                        case 'd':
                        {
                            switch (arg.Substring(1))
                            {
                            case "debug":
                            case "debug+":
                            {
                                _options.Debug = true;
                                break;
                            }

                            case "debug-":
                            {
                                _options.Debug = false;
                                break;
                            }

                            case "ducky":
                            {
                                _options.Ducky = true;
                                break;
                            }

                            case "debug-steps":
                            {
                                debugSteps = true;
                                break;
                            }

                            default:
                            {
                                InvalidOption(arg);
                                break;
                            }
                            }
                            break;
                        }

                        case 'e':
                        {
                            switch (arg.Substring(1, 8))
                            {
                            case "embedres":
                            {
                                // TODO: Add check for runtime support for "mono resources"
                                string resourceFile;
                                int    start = arg.IndexOf(":") + 1;
                                int    comma = arg.LastIndexOf(',');
                                if (comma >= 0)
                                {
                                    resourceFile = arg.Substring(start, comma - start);
                                    string resourceName = arg.Substring(comma + 1);
                                    _options.Resources.Add(new NamedEmbeddedFileResource(resourceFile, resourceName));
                                }
                                else
                                {
                                    resourceFile = arg.Substring(start);
                                    _options.Resources.Add(new EmbeddedFileResource(resourceFile));
                                }
                                break;
                            }

                            default:
                            {
                                InvalidOption(arg);
                                break;
                            }
                            }
                            break;
                        }

                        default:
                        {
                            InvalidOption(arg);
                            break;
                        }
                        }
                    }
                    else
                    {
                        _options.Input.Add(new FileInput(arg));
                    }
                }
            }

            if (null == _options.Pipeline)
            {
                _options.Pipeline = new CompileToFile();
            }
            if (debugSteps)
            {
                _options.Pipeline.AfterStep += new CompilerStepEventHandler(DebugModuleAfterStep);
            }
        }
Esempio n. 18
0
 protected override void CustomizeCompiler(BooCompiler compiler, CompilerPipeline pipeline, string[] urls)
 {
     pipeline.Insert(1, new ImplicitBaseClassCompilerStep(typeof(DemoDslBase), "Execute"));
 }
Esempio n. 19
0
 /// <summary>
 /// Extends the method compiler pipeline with x86 specific stages.
 /// </summary>
 /// <param name="methodCompilerPipeline">The method compiler pipeline to extend.</param>
 public override void ExtendMethodCompilerPipeline(CompilerPipeline methodCompilerPipeline)
 {
     // FIXME: Create a specific code generator instance using requested feature flags.
     // FIXME: Add some more optimization passes, which take advantage of advanced x86 instructions
     // and packed operations available with MMX/SSE extensions
     methodCompilerPipeline.AddRange (new IMethodCompilerStage[] {
         new LongOperandTransformationStage (),
         new InstructionLogger (typeof(LongOperandTransformationStage)),
         new AddressModeConversionStage (),
         new InstructionLogger (typeof(AddressModeConversionStage)),
         new CILTransformationStage (),
         new InstructionLogger (typeof(CILTransformationStage)),
         new IRTransformationStage (),
         new InstructionLogger (typeof(IRTransformationStage)),
         new TweakTransformationStage (),
         new InstructionLogger (typeof(TweakTransformationStage)),
         new MemToMemConversionStage (),
         new InstructionLogger (typeof(MemToMemConversionStage)),
         new SimplePeepholeOptimizationStage (),
         new InstructionLogger (typeof(SimplePeepholeOptimizationStage))
         //FlowGraphVisualizationStage.Instance,
     });
 }
Esempio n. 20
0
 /// <summary>
 /// Extends the method compiler pipeline with x64 specific stages.
 /// </summary>
 /// <param name="methodCompilerPipeline">The method compiler pipeline to extend.</param>
 public override void ExtendMethodCompilerPipeline(CompilerPipeline methodCompilerPipeline)
 {
     // TODO
 }
Esempio n. 21
0
        /// <summary>
        /// Extends the pre-compiler pipeline with x86 compiler stages.
        /// </summary>
        /// <param name="compilerPipeline">The pipeline to extend.</param>
        public override void ExtendCompilerPipeline(CompilerPipeline compilerPipeline)
        {
            compilerPipeline.Add(
                new StartUpStage()
            );

            compilerPipeline.Add(
                new InterruptVectorStage()
            );

            compilerPipeline.Add(
                new SSEInitStage()
            );
        }
Esempio n. 22
0
 /// <summary>
 /// Extends the pre-compiler pipeline with architecture specific compiler stages.
 /// </summary>
 /// <param name="compilerPipeline">The pipeline to extend.</param>
 public abstract void ExtendCompilerPipeline(CompilerPipeline compilerPipeline);
Esempio n. 23
0
        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        public void Dispose()
        {
            if (pipeline == null)
                throw new ObjectDisposedException(@"MethodCompilerBase");

            foreach (IMethodCompilerStage mcs in pipeline)
            {
                IDisposable d = mcs as IDisposable;
                if (null != d)
                    d.Dispose();
            }

            pipeline.Clear();
            pipeline = null;

            architecture = null;
            linker = null;
            method = null;
            type = null;
            instructionSet = null;
            basicBlocks = null;
        }
Esempio n. 24
0
 /// <summary>
 /// Initializes a new instance of.
 /// </summary>
 protected CompilerBase()
 {
     _pipeline = new CompilerPipeline();
 }
Esempio n. 25
0
 /// <summary>
 /// Extends the assembly compiler pipeline with ARMv6 specific stages.
 /// </summary>
 /// <param name="compilerPipeline">The pipeline to extend.</param>
 public override void ExtendCompilerPipeline(CompilerPipeline compilerPipeline)
 {
     // TODO
 }
Esempio n. 26
0
        /// <summary>
        /// Extends the compiler pipeline with x86 specific stages.
        /// </summary>
        /// <param name="compilerPipeline">The pipeline to extend.</param>
        public override void ExtendCompilerPipeline(CompilerPipeline compilerPipeline)
        {
            compilerPipeline.InsertAfterFirst<ICompilerStage>(
                new InterruptVectorStage()
            );

            compilerPipeline.InsertAfterFirst<InterruptVectorStage>(
                new ExceptionVectorStage()
            );

            compilerPipeline.InsertAfterLast<TypeLayoutStage>(
                new MethodTableBuilderStage()
            );
        }
Esempio n. 27
0
 /// <summary>
 /// Extends the assembly compiler pipeline with ARMv6 specific stages.
 /// </summary>
 /// <param name="compilerPipeline">The pipeline to extend.</param>
 public override void ExtendCompilerPipeline(CompilerPipeline compilerPipeline)
 {
     // TODO
 }
Esempio n. 28
0
        /// <summary>
        /// Initializes a new compiler instance.
        /// </summary>
        /// <param name="architecture">The compiler target architecture.</param>
        /// <param name="typeSystem">The type system.</param>
        /// <param name="typeLayout">The type layout.</param>
        /// <param name="compilationScheduler">The compilation scheduler.</param>
        /// <param name="internalTrace">The internal trace.</param>
        /// <param name="compilerOptions">The compiler options.</param>
        protected BaseCompiler(IArchitecture architecture, ITypeSystem typeSystem, ITypeLayout typeLayout, ICompilationScheduler compilationScheduler, IInternalTrace internalTrace, CompilerOptions compilerOptions)
        {
            if (architecture == null)
                throw new ArgumentNullException(@"architecture");

            this.pipeline = new CompilerPipeline();
            this.architecture = architecture;
            this.typeSystem = typeSystem;
            this.typeLayout = typeLayout;
            this.internalTrace = internalTrace;
            this.compilerOptions = compilerOptions;
            this.genericTypePatcher = new GenericTypePatcher(typeSystem);
            this.counters = new Counters();
            this.compilationScheduler = compilationScheduler;
            this.linker = compilerOptions.Linker;
            this.plugSystem = new PlugSystem();
        }
Esempio n. 29
0
        /// <summary>
        /// Extends the method compiler pipeline with ARMv6 specific stages.
        /// </summary>
        /// <param name="methodCompilerPipeline">The method compiler pipeline to extend.</param>
        public override void ExtendMethodCompilerPipeline(CompilerPipeline methodCompilerPipeline)
        {
            methodCompilerPipeline.InsertAfterLast<PlatformStubStage>(
                new IMethodCompilerStage[]
                {
                    //new LongOperandTransformationStage(),
                    new IRTransformationStage(),
                });

            //methodCompilerPipeline.InsertAfterLast<CodeGenerationStage>(
            //    new ExceptionLayoutStage()
            //);

            methodCompilerPipeline.InsertBefore<GreedyRegisterAllocatorStage>(
                new StopStage()
            );
        }
 protected override void AddCompilerSteps(BooCompiler compiler, string filename, CompilerPipeline pipeline)
 {
     compiler.Parameters.AddAssembly(typeof(Boo.Lang.Compiler.Ast.DepthFirstTransformer).Assembly);
     compiler.Parameters.Pipeline.Insert(1,
                                         new MethodSubstitutionBaseClassCompilerStep(typeof(MyMethodSubstitutionBaseClass),
                                                                                     "System",
                                                                                     "Boo.Lang.Compiler.Ast.DepthFirstTransformer"));
 }
Esempio n. 31
0
 protected override void AddCompilerSteps(BooCompiler compiler, string filename, CompilerPipeline pipeline)
 {
     compiler.Parameters.Pipeline.Insert(1,
                                         new ImplicitBaseClassCompilerStep(typeof(MyAnonymousBaseClass), "Run"));
 }
Esempio n. 32
0
 /// <summary>
 /// Extends the assembly compiler pipeline with x86 specific stages.
 /// </summary>
 /// <param name="assemblyCompilerPipeline">The assembly compiler pipeline to extend.</param>
 public override void ExtendAssemblyCompilerPipeline(CompilerPipeline assemblyCompilerPipeline)
 {
 }
Esempio n. 33
0
 /// <summary>
 /// Extends the assembly compiler pipeline with architecture specific assembly compiler stages.
 /// </summary>
 /// <param name="assemblyPipeline">The pipeline to extend.</param>
 public abstract void ExtendAssemblyCompilerPipeline(CompilerPipeline assemblyPipeline);
Esempio n. 34
0
 /// <summary>
 /// Extends the method compiler pipeline with ARM specific stages.
 /// </summary>
 /// <param name="methodCompilerPipeline">The method compiler pipeline to extend.</param>
 public override void ExtendMethodCompilerPipeline(CompilerPipeline methodCompilerPipeline)
 {
 }
Esempio n. 35
0
 protected override void AddCompilerSteps(BooCompiler compiler, string filename, CompilerPipeline pipeline)
 {
     pipeline.Insert(1, new AutoReferenceFilesCompilerStep(Path.GetDirectoryName(filename)));
 }
Esempio n. 36
0
        /// <summary>
        /// Extends the method compiler pipeline with x86 specific stages.
        /// </summary>
        /// <param name="methodCompilerPipeline">The method compiler pipeline to extend.</param>
        public override void ExtendMethodCompilerPipeline(CompilerPipeline methodCompilerPipeline)
        {
            methodCompilerPipeline.InsertAfterLast<PlatformStubStage>(
                new IMethodCompilerStage[]
                {
                    //new CheckOperandCountStage(),
                    new PlatformIntrinsicStage(),
                    new LongOperandTransformationStage(),

                    //new StopStage(),

                    new IRTransformationStage(),
                    new TweakTransformationStage(),

                    new FixedRegisterAssignmentStage(),
                    new SimpleDeadCodeRemovalStage(),
                    new AddressModeConversionStage(),
                    new FloatingPointStage(),
                });

            methodCompilerPipeline.InsertAfterLast<StackLayoutStage>(
                new BuildStackStage()
            );

            methodCompilerPipeline.InsertBefore<CodeGenerationStage>(
                new FinalTweakTransformationStage()
            );

            methodCompilerPipeline.InsertBefore<CodeGenerationStage>(
                new JumpOptimizationStage()
            );
        }
Esempio n. 37
0
 protected virtual void AddCompilerSteps(BooCompiler compiler, string filename, CompilerPipeline pipeline)
 {
 }
Esempio n. 38
0
        /// <summary>
        /// Extends the pre-compiler pipeline with x86 compiler stages.
        /// </summary>
        /// <param name="compilerPipeline">The pipeline to extend.</param>
        public override void ExtendPreCompilerPipeline(CompilerPipeline compilerPipeline)
        {
            compilerPipeline.InsertAfterFirst<ICompilerStage>(
                new InterruptVectorStage()
            );

            compilerPipeline.InsertAfterLast<ICompilerStage>(
                new SSESetupStage()
            );
        }
Esempio n. 39
0
 protected override void CustomizeCompiler(BooCompiler compiler, CompilerPipeline pipeline, string[] urls)
 {
     pipeline.Insert(1, new ImplicitBaseClassCompilerStep(typeof(BaseScheduler), "Prepare",
                                                          "Rhino.DSL.Tests.SchedulingDSL"));
 }
Esempio n. 40
0
        /// <summary>
        /// Extends the assembly compiler pipeline with ARM specific stages.
        /// </summary>
        /// <param name="assemblyCompilerPipeline">The assembly compiler pipeline to extend.</param>
        public override void ExtendAssemblyCompilerPipeline(CompilerPipeline assemblyCompilerPipeline)
        {
            //assemblyCompilerPipeline.InsertAfterFirst<IAssemblyCompilerStage>(
            //    new InterruptVectorStage()
            //);

            //assemblyCompilerPipeline.InsertAfterFirst<InterruptVectorStage>(
            //    new ExceptionVectorStage()
            //);

            //assemblyCompilerPipeline.InsertAfterLast<TypeLayoutStage>(
            //    new MethodTableBuilderStage()
            //);
        }
Esempio n. 41
0
 /// <summary>
 /// Customise the compiler to fit this DSL engine.
 /// This is the most commonly overriden method.
 /// </summary>
 protected virtual void CustomizeCompiler(BooCompiler compiler, CompilerPipeline pipeline, string[] urls)
 {
 }
Esempio n. 42
0
        public void Initialize(MosaCompiler compiler)
        {
            if (compiler == null)
                throw new ArgumentNullException(@"compiler");

            Compiler = compiler;

            Architecture = Compiler.CompilerOptions.Architecture;
            TypeSystem = Compiler.TypeSystem;
            TypeLayout = Compiler.TypeLayout;
            CompilerTrace = Compiler.CompilerTrace;
            CompilerOptions = Compiler.CompilerOptions;
            CompilationScheduler = Compiler.CompilationScheduler;
            Linker = compiler.Linker;

            PreCompilePipeline = new CompilerPipeline();
            PostCompilePipeline = new CompilerPipeline();
            GlobalCounters = new Counters();
            PlugSystem = new PlugSystem();
            CompilerData = new CompilerData();

            // 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);
                    }
                }
            }

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

            // Extended Setup
            ExtendCompilerSetup();

            // Build the default pre-compiler pipeline
            Architecture.ExtendPreCompilerPipeline(PreCompilePipeline);

            // Build the default post-compiler pipeline
            Architecture.ExtendPostCompilerPipeline(PostCompilePipeline);
        }
Esempio n. 43
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BaseMethodCompiler"/> class.
        /// </summary>
        /// <param name="compiler">The assembly compiler.</param>
        /// <param name="method">The method to compile by this instance.</param>
        /// <param name="instructionSet">The instruction set.</param>
        protected BaseMethodCompiler(BaseCompiler compiler, RuntimeMethod method, InstructionSet instructionSet)
        {
            this.compiler = compiler;
            this.method = method;
            this.type = method.DeclaringType;
            this.compilationScheduler = compiler.Scheduler;
            this.moduleTypeSystem = method.Module;
            this.architecture = compiler.Architecture;
            this.typeSystem = compiler.TypeSystem;
            this.typeLayout = Compiler.TypeLayout;
            this.internalTrace = Compiler.InternalTrace;
            this.linker = compiler.Linker;

            this.basicBlocks = new BasicBlocks();

            this.instructionSet = instructionSet ?? new InstructionSet(256);

            this.pipeline = new CompilerPipeline();

            this.stackLayout = new StackLayout(architecture, method.Parameters.Count + (method.Signature.HasThis || method.Signature.HasExplicitThis ? 1 : 0));

            this.virtualRegisterLayout = new VirtualRegisterLayout(architecture, stackLayout);

            EvaluateParameterOperands();

            this.stopMethodCompiler = false;
        }
Esempio n. 44
0
 /// <summary>
 /// Requests the architecture to add architecture specific compilation stages to the pipeline. These
 /// may depend upon the current state of the pipeline.
 /// </summary>
 /// <param name="methodPipeline">The pipeline of the method compiler to add architecture specific compilation stages to.</param>
 public abstract void ExtendMethodCompilerPipeline(CompilerPipeline methodPipeline);
Esempio n. 45
0
 public void SetUp()
 {
     _pipeline = new CompilerPipeline();
 }
Esempio n. 46
0
        /// <summary>
        /// Extends the method compiler pipeline with ARM specific stages.
        /// </summary>
        /// <param name="methodCompilerPipeline">The method compiler pipeline to extend.</param>
        public override void ExtendMethodCompilerPipeline(CompilerPipeline methodCompilerPipeline)
        {
            //methodCompilerPipeline.InsertAfterLast<PlatformStubStage>(
            //    new IMethodCompilerStage[]
            //    {
            //        new LongOperandTransformationStage(),
            //        new AddressModeConversionStage(),
            //        new IRTransformationStage(),
            //        new TweakTransformationStage(),
            //        new MemToMemConversionStage(),
            //    });

            //methodCompilerPipeline.InsertAfterLast<IBlockOrderStage>(
            //    new SimplePeepholeOptimizationStage()
            //);

            //methodCompilerPipeline.InsertAfterLast<CodeGenerationStage>(
            //    new ExceptionLayoutStage()
            //);
        }
Esempio n. 47
0
 protected override void AddCompilerSteps(BooCompiler compiler, string filename, CompilerPipeline pipeline)
 {
     compiler.Parameters.References.Add(typeof(XmlDocument).Assembly);
     pipeline.Insert(1, new AutoImportCompilerStep("System.Xml"));
 }