示例#1
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;
                }
            }
        }
        /// <summary>
        /// Creates the ISR methods.
        /// </summary>
        /// <param name="compiler">The compiler.</param>
        private void CreateISRMethods(AssemblyCompiler compiler)
        {
            // Get RuntimeMethod for the Mosa.Kernel.X86.IDT.InterruptHandler
            RuntimeType rt = RuntimeBase.Instance.TypeLoader.GetType(@"Mosa.Kernel.X86.IDT");
            RuntimeMethod InterruptMethod = FindMethod(rt, "InterruptHandler");

            SigType I1 = new SigType(CilElementType.I1);
            SigType I2 = new SigType(CilElementType.I4);

            RegisterOperand ecx1 = new RegisterOperand(I1, GeneralPurposeRegister.ECX);
            RegisterOperand ecx2 = new RegisterOperand(I2, GeneralPurposeRegister.ECX);

            for (int i = 0; i <= 256; i++) {
                InstructionSet set = new InstructionSet(100);
                Context ctx = new Context(set, -1);

                ctx.AppendInstruction(CPUx86.Instruction.CliInstruction);
                ctx.AppendInstruction(CPUx86.Instruction.PushadInstruction);
                if ((i != 8) && (i < 10 || i > 14)) // For IRQ 8, 10, 11, 12, 13, 14 the cpu automatically pushed the error code
                    ctx.AppendInstruction(CPUx86.Instruction.PushInstruction, null, new ConstantOperand(I1, 0x0));
                ctx.AppendInstruction(CPUx86.Instruction.PushInstruction, null, new ConstantOperand(I2, i));
                ctx.AppendInstruction(CPUx86.Instruction.CallInstruction, InterruptMethod);
                // TODO: Replace next two instructions with add esp, 5 ;Stack clearing
                ctx.AppendInstruction(CPUx86.Instruction.PopInstruction, ecx2);
                ctx.AppendInstruction(CPUx86.Instruction.PopInstruction, ecx1);
                ctx.AppendInstruction(CPUx86.Instruction.PopadInstruction);
                ctx.AppendInstruction(CPUx86.Instruction.StiInstruction);
                ctx.AppendInstruction(CPUx86.Instruction.IRetdInstruction);

                CompilerGeneratedMethod method = LinkTimeCodeGenerator.Compile(compiler, @"InterruptISR" + i.ToString(), set);
            }
        }
 /// <summary>
 /// Writes the Cil _header.
 /// </summary>
 /// <param name="compiler">The assembly compiler.</param>
 /// <param name="linker">The linker.</param>
 private void WriteCilHeader(AssemblyCompiler compiler, IAssemblyLinker linker)
 {
     using (Stream stream = linker.Allocate(CLI_HEADER.SymbolName, SectionKind.Text, CLI_HEADER.Length, 4))
     using (BinaryWriter bw = new BinaryWriter(stream, Encoding.ASCII)) {
         _cliHeader.Write(bw);
     }
 }
 public void Setup(AssemblyCompiler compiler)
 {
     this.compiler = compiler;
     architecture  = compiler.Architecture;
     typeSystem    = compiler.TypeSystem;
     typeLayout    = compiler.TypeLayout;
 }
        /// <summary>
        /// Creates the ISR methods.
        /// </summary>
        /// <param name="compiler">The compiler.</param>
        private void CreateISRMethods(AssemblyCompiler compiler)
        {
            // Create Interrupt Service Routines (ISR)
            RuntimeMethod InterruptMethod = compiler.Assembly.EntryPoint; // TODO: replace with another entry point

            SigType I1 = new SigType(CilElementType.I1);
            SigType I4 = new SigType(CilElementType.I4);
            RegisterOperand eax = new RegisterOperand(I4, GeneralPurposeRegister.EAX);

            for (int i = 0; i <= 256; i++) {
                InstructionSet set = new InstructionSet(100);
                Context ctx = new Context(set, -1);

                ctx.SetInstruction(CPUx86.Instruction.CliInstruction);
                if ((i != 8) && (i < 10 || i > 14)) // For IRQ 8, 10, 11, 12, 13, 14 the cpu automatically pushed the error code
                    ctx.AppendInstruction(CPUx86.Instruction.PushInstruction, null, new ConstantOperand(I4, 0x0));
                ctx.AppendInstruction(CPUx86.Instruction.PushadInstruction);
                ctx.AppendInstruction(CPUx86.Instruction.PushInstruction, null, new ConstantOperand(I4, i));
                // TODO: Set method parameters
                ctx.AppendInstruction(CPUx86.Instruction.CallInstruction, InterruptMethod);
                ctx.AppendInstruction(CPUx86.Instruction.PopInstruction, eax);
                ctx.AppendInstruction(CPUx86.Instruction.PopadInstruction);
                ctx.AppendInstruction(CPUx86.Instruction.PopInstruction, eax);
                ctx.AppendInstruction(CPUx86.Instruction.StiInstruction);
                //ctx.AppendInstruction(CPUx86.Instruction.IRetdInstruction);

                CompilerGeneratedMethod method = LinkTimeCodeGenerator.Compile(compiler, @"InterruptISR" + i.ToString(), set);
            }
        }
示例#6
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;
                }
            }
        }
        void IAssemblyCompilerStage.Run(AssemblyCompiler compiler)
        {
            // Retrieve the provider provider
            ReadOnlyRuntimeTypeListView types = RuntimeBase.Instance.TypeLoader.GetTypesFromModule(compiler.Assembly);
            foreach (RuntimeType type in types)
            {
                // Do not compile generic types
                if (type.IsGeneric)
                    continue;

                foreach (RuntimeMethod method in type.Methods)
                {
                    if (method.IsGeneric)
                        continue;

                    if (method.IsNative)
                    {
                        Debug.WriteLine("Skipping native method: " + type + "." + method.Name);
                        Debug.WriteLine("Method will not be available in compiled image.");
                        continue;
                    }

                    // FIXME: Create a method implementation for this method...
                    //MethodImplementation methodImpl = provider.GetRow<MethodImplementation>(method);
                    //methodImpl.OwnerType = type;
                    //Debug.WriteLine("\tMethod: " + method.ToString());

                    // Schedule the method for compilation...
                    // FIXME: Do we really want to do it this way? Shouldn't we use some compilation service for this?
                    // REFACTOR out of the AssemblyCompiler class
                    MethodCompilerBase mcb = compiler.CreateMethodCompiler(type, method);
                    ScheduleMethod(mcb);
                }
            }
        }
 public void Setup(AssemblyCompiler compiler)
 {
     this.compiler = compiler;
     architecture = compiler.Architecture;
     typeSystem = compiler.TypeSystem;
     typeLayout = compiler.TypeLayout;
 }
        /// <summary>
        /// Performs stage specific processing on the compiler context.
        /// </summary>
        /// <param name="compiler">The compiler context to perform processing in.</param>
        public void Run(AssemblyCompiler compiler)
        {
            _linker = compiler.Pipeline.FindFirst<IAssemblyLinker>();

            CreateISRMethods(compiler);
            CreateIVTMethod(compiler);
        }
        /// <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(new SigType(CilElementType.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;
        }
示例#11
0
        /// <summary>
        /// Performs stage specific processing on the compiler context.
        /// </summary>
        /// <param name="compiler">The compiler context to perform processing in.</param>
        public override void Run(Mosa.Runtime.CompilerFramework.AssemblyCompiler compiler)
        {
            // Resolve all symbols first
            base.Run(compiler);

            // Persist the Elf32 file now
            CreateElf64File(compiler);
        }
        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;
        }
        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>
        /// Performs stage specific processing on the compiler context.
        /// </summary>
        /// <param name="compiler">The compiler context to perform processing in.</param>
        public void Run(AssemblyCompiler compiler)
        {
            IAssemblyLinker linker = compiler.Pipeline.FindFirst<IAssemblyLinker>();
            if (linker == null)
                throw new InvalidOperationException(@"ObjectFileLayoutStage needs a linker.");

            LayoutSections(linker);
            LayoutSymbols(linker);
        }
        public void Setup(AssemblyCompiler compiler)
        {
            ICompilationSchedulerStage scheduler = compiler.Pipeline.FindFirst<ICompilationSchedulerStage>();
            if (scheduler == null)
                throw new InvalidOperationException(@"No compilation scheduler found in the assembly compiler pipeline.");

            this.compiler = compiler;
            this.scheduler = scheduler;
        }
示例#16
0
        /// <summary>
        /// Creates the elf32 file.
        /// </summary>
        /// <param name="compiler">The compiler.</param>
        private void CreateElf64File(Mosa.Runtime.CompilerFramework.AssemblyCompiler compiler)
        {
            using (System.IO.FileStream fs = new System.IO.FileStream(this.OutputFile, System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.None))
            {
                Elf64Header header = new Elf64Header();
                header.Type                = Elf64FileType.Executable;
                header.Machine             = Elf64MachineType.Intel386;
                header.SectionHeaderNumber = (ushort)(Sections.Count + 2);
                header.SectionHeaderOffset = header.ElfHeaderSize;

                header.CreateIdent(Elf64IdentClass.Class64, Elf64IdentData.Data2LSB, null);

                // Calculate the concatenated size of all section's data
                uint offset = 0;
                foreach (Mosa.Runtime.Linker.Elf64.Sections.Elf64Section section in Sections)
                {
                    offset += (uint)section.Length;
                }
                offset += (uint)nullSection.Length;
                offset += (uint)stringTableSection.Length;

                // Calculate offsets
                header.ProgramHeaderOffset      = (uint)header.ElfHeaderSize + (uint)header.SectionHeaderEntrySize * (uint)header.SectionHeaderNumber + offset;
                header.SectionHeaderStringIndex = (ushort)((ushort)header.ProgramHeaderOffset + (ushort)header.ProgramHeaderNumber * (ushort)header.ProgramHeaderEntrySize);

                System.IO.BinaryWriter writer = new System.IO.BinaryWriter(fs);

                // Write the ELF Header
                header.Write(writer);

                // Overjump the Section Header Table and write the section's data first
                long tmp = fs.Position;
                writer.Seek((int)(tmp + header.SectionHeaderNumber * header.SectionHeaderEntrySize), System.IO.SeekOrigin.Begin);

                nullSection.Write(writer);
                stringTableSection.Write(writer);

                // Write the sections
                foreach (Mosa.Runtime.Linker.Elf64.Sections.Elf64Section section in Sections)
                {
                    section.Write(writer);
                }

                // Jump back to the Section Header Table
                writer.Seek((int)tmp, System.IO.SeekOrigin.Begin);

                nullSection.WriteHeader(writer);
                stringTableSection.WriteHeader(writer);

                // Write the section headers
                foreach (Mosa.Runtime.Linker.Elf64.Sections.Elf64Section section in Sections)
                {
                    section.WriteHeader(writer);
                }
            }
        }
示例#17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LinkerMethodCompiler"/> class.
 /// </summary>
 /// <param name="compiler">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="compiler"/>, <paramref name="method"/> or <paramref name="instructionSet"/> is null.</exception>
 public LinkerMethodCompiler(AssemblyCompiler compiler, RuntimeMethod method, InstructionSet instructionSet)
     : base(compiler.Pipeline.Find<IAssemblyLinker>(), compiler.Architecture, compiler.Assembly, method.DeclaringType, method)
 {
     InstructionSet = instructionSet;
     this.Pipeline.AddRange(new IMethodCompilerStage[] {
         new BasicBlockBuilderStage(),
         new CodeGenerationStage(),
     });
     compiler.Architecture.ExtendMethodCompilerPipeline(this.Pipeline);
 }
        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.");
            }
        }
        void IAssemblyCompilerStage.Setup(AssemblyCompiler compiler)
        {
            base.Setup(compiler);

            typeInitializerSchedulerStage = compiler.Pipeline.FindFirst<ITypeInitializerSchedulerStage>();

            if (typeInitializerSchedulerStage == null)
                throw new InvalidOperationException(@"AssemblyCompilationStage needs a ITypeInitializerSchedulerStage.");

            linker = RetrieveAssemblyLinkerFromCompiler();
        }
示例#20
0
        /// <summary>
        /// Performs stage specific processing on the compiler context.
        /// </summary>
        /// <param name="compiler">The compiler context to perform processing in.</param>
        public void Run(AssemblyCompiler compiler)
        {
            IAssemblyLinker linker = compiler.Pipeline.Find<IAssemblyLinker>();
            if (linker == null)
                throw new InvalidOperationException(@"Can't run without a linker.");

            // FIXME: Retrieve the compilation target assembly
            // HACK: Using Metadata From source assembly, rather than re-create it From scratch From the target assembly
            IMetadataModule module = compiler.Assembly;

            ExportCilMetadata(module, linker);
        }
 /// <summary>
 /// Performs stage specific processing on the compiler context.
 /// </summary>
 /// <param name="compiler">The compiler context to perform processing in.</param>
 void IAssemblyCompilerStage.Run(AssemblyCompiler compiler)
 {
     IMethodCompilerBuilder mcb = compiler.Pipeline.FindFirst<IMethodCompilerBuilder>();
     Debug.Assert(null != mcb, @"Failed to find a method compiler builder stage.");
     foreach (MethodCompilerBase mc in mcb.Scheduled) {
         try {
             mc.Compile();
         }
         finally {
             mc.Dispose();
         }
     }
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="LinkerMethodCompiler"/> class.
        /// </summary>
        /// <param name="compiler">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="compiler"/>, <paramref name="method"/> or <paramref name="instructionSet"/> is null.</exception>
        public LinkerMethodCompiler(AssemblyCompiler compiler, ICompilationSchedulerStage compilationScheduler, RuntimeMethod method, InstructionSet instructionSet)
            : base(compiler.Pipeline.FindFirst<IAssemblyLinker>(), compiler.Architecture, compilationScheduler, method.DeclaringType, method, compiler.TypeSystem, compiler.TypeLayout)
        {
            this.InstructionSet = instructionSet;
            this.CreateBlock(-1, 0);

            this.Pipeline.AddRange(new IMethodCompilerStage[] {
                new SimpleTraceBlockOrderStage(),
                new PlatformStubStage(),
                new CodeGenerationStage(),
            });
            compiler.Architecture.ExtendMethodCompilerPipeline(this.Pipeline);
        }
示例#23
0
        /// <summary>
        /// Performs stage specific processing on the compiler context.
        /// </summary>
        /// <param name="compiler">The compiler context to perform processing in.</param>
        void IAssemblyCompilerStage.Run(AssemblyCompiler compiler)
        {
            IMethodCompilerBuilder mcb = compiler.Pipeline.Find <IMethodCompilerBuilder> ();

            Debug.Assert(null != mcb, "Failed to find a method compiler builder stage.");
            foreach (MethodCompilerBase mc in mcb.Scheduled)
            {
                try
                {
                    mc.Compile();
                } finally
                {
                    mc.Dispose();
                }
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="AotMethodCompiler"/> class.
 /// </summary>
 public AotMethodCompiler(AssemblyCompiler compiler, ICompilationSchedulerStage compilationScheduler, RuntimeType type, RuntimeMethod method)
     : base(compiler.Pipeline.FindFirst<IAssemblyLinker>(), compiler.Architecture, compilationScheduler, type, method, compiler.TypeSystem, compiler.Pipeline.FindFirst<ITypeLayout>())
 {
     this.assemblyCompiler = compiler;
     this.Pipeline.AddRange(
         new IMethodCompilerStage[]
         {
             new DecodingStage(),
             //InstructionLogger.Instance,
             new BasicBlockBuilderStage(),
             //InstructionLogger.Instance,
             new OperandDeterminationStage(),
             InstructionLogger.Instance,
             StaticAllocationResolutionStageWrapper.Instance,
             //InstructionLogger.Instance,
             new CILTransformationStage(),
             InstructionLogger.Instance,
             //InstructionStatisticsStage.Instance,
             //new DominanceCalculationStage(),
             //InstructionLogger.Instance,
             //new EnterSSA(),
             //InstructionLogger.Instance,
             //new ConstantPropagationStage(),
             //InstructionLogger.Instance,
             //new ConstantFoldingStage(),
             //new StrengthReductionStage(),
             //InstructionLogger.Instance,
             //new LeaveSSA(),
             //InstructionLogger.Instance,
             new StackLayoutStage(),
             //InstructionLogger.Instance,
             new PlatformStubStage(),
             InstructionLogger.Instance,
             //new BlockReductionStage(),
             new LoopAwareBlockOrderStage(),
             //InstructionLogger.Instance,
             //new SimpleTraceBlockOrderStage(),
             //new ReverseBlockOrderStage(),
             //new LocalCSE(),
             new CodeGenerationStage(),
         });
 }
        /// <summary>
        /// Performs stage specific processing on the compiler context.
        /// </summary>
        /// <param name="compiler">The compiler context to perform processing in.</param>
        public void Run(AssemblyCompiler compiler)
        {
            if (compiler == null)
                throw new ArgumentNullException(@"compiler");

            IAssemblyLinker linker = compiler.Pipeline.FindFirst<IAssemblyLinker>();
            Debug.Assert(linker != null, @"No linker??");

            _cliHeader.Cb = 0x48;
            _cliHeader.MajorRuntimeVersion = 2;
            _cliHeader.MinorRuntimeVersion = 0;
            _cliHeader.Flags = RuntimeImageFlags.ILOnly;
            _cliHeader.EntryPointToken = 0x06000001; // FIXME: ??

            LinkerSymbol metadata = linker.GetSymbol(Mosa.Runtime.Metadata.Symbol.Name);
            _cliHeader.Metadata.VirtualAddress = (uint)(linker.GetSection(SectionKind.Text).VirtualAddress.ToInt64() + metadata.SectionAddress);
            _cliHeader.Metadata.Size = (int)metadata.Length;

            WriteCilHeader(compiler, linker);
        }
示例#26
0
        /// <summary>
        /// Performs stage specific processing on the compiler context.
        /// </summary>
        /// <param name="compiler">The compiler context to perform processing in.</param>
        public void Run(AssemblyCompiler compiler)
        {
            // Retrieve the linker
            IAssemblyLinker linker = compiler.Pipeline.Find<IAssemblyLinker> ();

            // Emit map file _header
            this.writer.WriteLine (linker.OutputFile);
            this.writer.WriteLine ();
            this.writer.WriteLine ("Timestamp is {0}", linker.TimeStamp);
            this.writer.WriteLine ();
            this.writer.WriteLine ("Preferred load address is {0:x16}", linker.BaseAddress);
            this.writer.WriteLine ();

            // Emit the sections
            EmitSections (linker);
            this.writer.WriteLine ();

            // Emit all symbols
            EmitSymbols (linker);
        }
 /// <summary>
 /// Performs stage specific processing on the compiler context.
 /// </summary>
 /// <param name="compiler">The compiler context to perform processing in.</param>
 public void Run(AssemblyCompiler compiler)
 {
     if (this.mapFile != null)
     {
         try
         {
             using (FileStream fs = new FileStream(this.mapFile, FileMode.Create, FileAccess.Write, FileShare.Read))
             using (StreamWriter writer = new StreamWriter(fs, Encoding.UTF8))
             {
                 MapFileGenerationStage mapGenerator = new MapFileGenerationStage(writer);
                 mapGenerator.Run(compiler);
             }
         }
         catch (Exception x)
         {
             Console.WriteLine(@"Failed to generate map file.");
             Console.WriteLine(x);
         }
     }
 }
示例#28
0
        void IAssemblyCompilerStage.Run(AssemblyCompiler compiler)
        {
            // Retrieve the provider provider
            ReadOnlyRuntimeTypeListView types = RuntimeBase.Instance.TypeLoader.GetTypesFromModule(compiler.Assembly);

            foreach (RuntimeType type in types)
            {
                // Do not compile generic types
                if (type.IsGeneric)
                {
                    continue;
                }

                foreach (RuntimeMethod method in type.Methods)
                {
                    if (method.IsGeneric)
                    {
                        continue;
                    }

                    if (method.IsNative)
                    {
                        Debug.WriteLine("Skipping native method: " + type + "." + method.Name);
                        Debug.WriteLine("Method will not be available in compiled image.");
                        continue;
                    }

                    // FIXME: Create a method implementation for this method...
                    //MethodImplementation methodImpl = provider.GetRow<MethodImplementation>(method);
                    //methodImpl.OwnerType = type;
                    //Debug.WriteLine("\tMethod: " + method.ToString());

                    // Schedule the method for compilation...
                    // FIXME: Do we really want to do it this way? Shouldn't we use some compilation service for this?
                    // REFACTOR out of the AssemblyCompiler class
                    MethodCompilerBase mcb = compiler.CreateMethodCompiler(type, method);
                    ScheduleMethod(mcb);
                }
            }
        }
        /// <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 CompilerGeneratedMethod Compile(AssemblyCompiler compiler, string methodName, InstructionSet instructionSet)
        {
            if (compiler == null)
                throw new ArgumentNullException(@"compiler");
            if (methodName == null)
                throw new ArgumentNullException(@"methodName");
            if (methodName.Length == 0)
                throw new ArgumentException(@"Invalid method name.");

            // Create the type if we need to.
            if (compilerGeneratedType == null)
                compilerGeneratedType = new CompilerGeneratedType(compiler.Assembly, @"Mosa.Tools.Compiler", @"LinkerGenerated");

            // Create the method
            // HACK: <$> prevents the method from being called from CIL
            CompilerGeneratedMethod method = new CompilerGeneratedMethod(compiler.Assembly, "<$>" + methodName, compilerGeneratedType);
            compilerGeneratedType.AddMethod(method);

            LinkerMethodCompiler methodCompiler = new LinkerMethodCompiler(compiler, compiler.Pipeline.FindFirst<ICompilationSchedulerStage>(), method, instructionSet);
            methodCompiler.Compile();
            return method;
        }
示例#30
0
 /// <summary>
 /// Called when an assembly's compilation ends
 /// </summary>
 /// <param name="compiler">The compiler</param>
 public virtual void OnAssemblyCompileEnd(AssemblyCompiler compiler)
 {
 }
示例#31
0
 /// <summary>
 /// Called when an assembly's compilation ends
 /// </summary>
 /// <param name="compiler">The compiler</param>
 public virtual void OnAssemblyCompileEnd(AssemblyCompiler compiler)
 {
 }
示例#32
0
 /// <summary>
 /// Called when an assembly's compilation begins
 /// </summary>
 /// <param name="compiler">The compiler</param>
 public virtual void OnAssemblyCompileBegin(AssemblyCompiler compiler)
 {
 }
        void IAssemblyCompilerStage.Setup(AssemblyCompiler compiler)
        {
            base.Setup(compiler);

            CheckImplementation();
            ((IAssemblyCompilerStage)this.implementation).Setup(compiler);
        }
        void IAssemblyCompilerStage.Setup(AssemblyCompiler compiler)
        {
            base.Setup(compiler);

            linker = RetrieveAssemblyLinkerFromCompiler();
        }
 /// <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 CompilerGeneratedMethod Compile(AssemblyCompiler compiler, string methodName)
 {
     return Compile(compiler, methodName, null);
 }
示例#36
0
 public void Setup(AssemblyCompiler compiler)
 {
     CheckImplementation();
     this.compiler = compiler;
     ((IAssemblyCompilerStage)this.implementation).Setup(compiler);
 }
 public void Setup(AssemblyCompiler compiler)
 {
     this.compiler = compiler;
 }
        void IAssemblyCompilerStage.Setup(AssemblyCompiler compiler)
        {
            base.Setup(compiler);

            this.compiler = compiler;
        }
示例#39
0
        void IAssemblyCompilerStage.Setup(AssemblyCompiler compiler)
        {
            base.Setup(compiler);

            linker = RetrieveAssemblyLinkerFromCompiler();
        }
 private static List <RuntimeMethod> RecompileMethods(AssemblyCompiler compiler, List <Token> types, RuntimeMethod method)
 {
     throw new NotImplementedException();
 }
示例#41
0
 /// <summary>
 /// Called when an assembly's compilation begins
 /// </summary>
 /// <param name="compiler">The compiler</param>
 public virtual void OnAssemblyCompileBegin(AssemblyCompiler compiler)
 {
 }
 private static List <Token> GetTokenTypesForMethod(AssemblyCompiler compiler, RuntimeType type, RuntimeMethod method)
 {
     throw new NotImplementedException();
 }