public void Setup(AssemblyCompiler compiler)
 {
     this.compiler = compiler;
     architecture = compiler.Architecture;
     typeSystem = compiler.TypeSystem;
     typeLayout = compiler.TypeLayout;
 }
Example #2
0
 public void Setup(AssemblyCompiler compiler)
 {
     this.OutputFile = compiler.CompilerOptions.OutputFile;
     //this.FileAlignment = compiler.CompilerOptions.Elf64.FileAlignment;
     this.IsLittleEndian = compiler.Architecture.IsLittleEndian;
     this.Machine = (MachineType)compiler.Architecture.ElfMachineType;
 }
        /// <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;
        }
        void IAssemblyCompilerStage.Setup(AssemblyCompiler compiler)
        {
            base.Setup(compiler);

            scheduler = compiler.Pipeline.FindFirst<ICompilationSchedulerStage>();

            if (scheduler == null)
                throw new InvalidOperationException(@"No compilation scheduler found in the assembly compiler pipeline.");
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="LinkerMethodCompiler"/> class.
        /// </summary>
        /// <param name="assemblyCompiler">The assembly compiler executing this method compiler.</param>
        /// <param name="method">The metadata of the method to compile.</param>
        /// <param name="instructionSet">The instruction set.</param>
        /// <exception cref="System.ArgumentNullException"><paramref name="assemblyCompiler"/>, <paramref name="method"/> or <paramref name="instructionSet"/> is null.</exception>
        public LinkerMethodCompiler(AssemblyCompiler assemblyCompiler, ICompilationSchedulerStage compilationScheduler, RuntimeMethod method, InstructionSet instructionSet)
            : base(assemblyCompiler, method.DeclaringType, method,  instructionSet, compilationScheduler)
        {
            this.CreateBlock(-1, 0);

            this.Pipeline.AddRange(new IMethodCompilerStage[] {
                new SimpleTraceBlockOrderStage(),
                new PlatformStubStage(),
                new CodeGenerationStage(),
            });

            assemblyCompiler.Architecture.ExtendMethodCompilerPipeline(this.Pipeline);
        }
        public void Setup(AssemblyCompiler compiler)
        {
            this.OutputFile = compiler.CompilerOptions.OutputFile;
            this.IsLittleEndian = compiler.Architecture.IsLittleEndian;

            if (compiler.CompilerOptions.PortableExecutable.FileAlignment.HasValue)
                this.FileAlignment = compiler.CompilerOptions.PortableExecutable.FileAlignment.Value;

            if (compiler.CompilerOptions.PortableExecutable.SectionAlignment.HasValue)
                this.SectionAlignment = compiler.CompilerOptions.PortableExecutable.SectionAlignment.Value;

            if (compiler.CompilerOptions.PortableExecutable.SetChecksum.HasValue)
                this.SetChecksum = compiler.CompilerOptions.PortableExecutable.SetChecksum.Value;
        }
Example #7
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(),
                });
        }
 private static List<RuntimeMethod> RecompileMethods(AssemblyCompiler compiler, List<Token> types, RuntimeMethod method)
 {
     throw new NotImplementedException();
 }
        void IAssemblyCompilerStage.Setup(AssemblyCompiler compiler)
        {
            base.Setup(compiler);
            linker = RetrieveAssemblyLinkerFromCompiler();

            if (compiler.CompilerOptions.Multiboot.VideoDepth.HasValue)
                this.VideoDepth = compiler.CompilerOptions.Multiboot.VideoDepth.Value;
            if (compiler.CompilerOptions.Multiboot.VideoHeight.HasValue)
                this.VideoHeight = compiler.CompilerOptions.Multiboot.VideoHeight.Value;
            if (compiler.CompilerOptions.Multiboot.VideoMode.HasValue)
                this.VideoMode = compiler.CompilerOptions.Multiboot.VideoMode.Value;
            if (compiler.CompilerOptions.Multiboot.VideoWidth.HasValue)
                this.VideoWidth = compiler.CompilerOptions.Multiboot.VideoWidth.Value;
        }
 void IAssemblyCompilerStage.Setup(AssemblyCompiler compiler)
 {
     base.Setup(compiler);
 }
        void IAssemblyCompilerStage.Setup(AssemblyCompiler compiler)
        {
            base.Setup(compiler);

            this.MethodPipelineExportDirectory = compiler.CompilerOptions.MethodPipelineExportDirectory;
        }
 /// <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>
 /// <returns></returns>
 /// <exception cref="System.ArgumentNullException"><paramref name="compiler"/> or <paramref name="methodName"/>  is null.</exception>
 /// <exception cref="System.ArgumentException"><paramref name="methodName"/> is invalid.</exception>
 public static LinkerGeneratedMethod Compile(AssemblyCompiler compiler, string methodName, ITypeSystem typeSystem)
 {
     return Compile(compiler, methodName, null, typeSystem);
 }
Example #13
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BaseMethodCompiler"/> class.
        /// </summary>
        /// <param name="assemblyCompiler">The assembly compiler.</param>
        /// <param name="type">The type, which owns the method to compile.</param>
        /// <param name="method">The method to compile by this instance.</param>
        /// <param name="instructionSet">The instruction set.</param>
        /// <param name="compilationScheduler">The compilation scheduler.</param>
        protected BaseMethodCompiler(AssemblyCompiler assemblyCompiler, RuntimeType type, RuntimeMethod method, InstructionSet instructionSet, ICompilationSchedulerStage compilationScheduler)
        {
            if (compilationScheduler == null)
                throw new ArgumentNullException(@"compilationScheduler");

            this.assemblyCompiler = assemblyCompiler;
            this.method = method;
            this.type = type;
            this.compilationScheduler = compilationScheduler;
            this.moduleTypeSystem = method.Module;

            this.architecture = assemblyCompiler.Architecture;
            this.typeSystem = assemblyCompiler.TypeSystem;
            this.typeLayout = AssemblyCompiler.TypeLayout;
            this.internalTrace = AssemblyCompiler.InternalTrace;

            this.linker = assemblyCompiler.Pipeline.FindFirst<IAssemblyLinker>();
            this.plugSystem = assemblyCompiler.Pipeline.FindFirst<IPlugSystem>();

            this.parameters = new List<Operand>(new Operand[method.Parameters.Count]);
            this.nextStackSlot = 0;
            this.basicBlocks = new List<BasicBlock>();

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

            this.pipeline = new CompilerPipeline();
        }
 /// <summary>
 /// Setups the specified compiler.
 /// </summary>
 /// <param name="compiler">The compiler.</param>
 void IAssemblyCompilerStage.Setup(AssemblyCompiler compiler)
 {
     base.Setup(compiler);
     linker = RetrieveAssemblyLinkerFromCompiler();
 }
 private static List<Token> GetTokenTypesForMethod(AssemblyCompiler compiler, RuntimeType type, RuntimeMethod method)
 {
     throw new NotImplementedException();
 }
Example #16
0
        void IAssemblyCompilerStage.Setup(AssemblyCompiler compiler)
        {
            base.Setup(compiler);
            this.linker = RetrieveAssemblyLinkerFromCompiler();

            plugTypeAttribute = typeSystem.GetType("Mosa.Internal.Plug", "Mosa.Internal.Plug", "PlugTypeAttribute");
            plugMethodAttribute = typeSystem.GetType("Mosa.Internal.Plug", "Mosa.Internal.Plug", "PlugMethodAttribute");
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="BaseMethodCompiler"/> class.
        /// </summary>
        /// <param name="assemblyCompiler">The assembly compiler.</param>
        /// <param name="type">The type, which owns the method to compile.</param>
        /// <param name="method">The method to compile by this instance.</param>
        /// <param name="instructionSet">The instruction set.</param>
        /// <param name="compilationScheduler">The compilation scheduler.</param>
        protected BaseMethodCompiler(AssemblyCompiler assemblyCompiler, RuntimeType type, RuntimeMethod method, InstructionSet instructionSet, ICompilationSchedulerStage compilationScheduler)
        {
            if (compilationScheduler == null)
                throw new ArgumentNullException(@"compilationScheduler");

            this.assemblyCompiler = assemblyCompiler;
            this.method = method;
            this.type = type;
            this.compilationScheduler = compilationScheduler;
            this.moduleTypeSystem = method.Module;

            this.architecture = assemblyCompiler.Architecture;
            this.typeSystem = assemblyCompiler.TypeSystem;
            this.typeLayout = AssemblyCompiler.TypeLayout;
            this.internalTrace = AssemblyCompiler.InternalTrace;

            this.linker = assemblyCompiler.Pipeline.FindFirst<IAssemblyLinker>();
            this.plugSystem = assemblyCompiler.Pipeline.FindFirst<IPlugSystem>();

            this.parameters = new List<Operand>(new Operand[method.Parameters.Count]);
            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();
        }