Example #1
0
        private void Compile()
        {
            IAssemblyLoader assemblyLoader = new AssemblyLoader();

            assemblyLoader.InitializePrivatePaths(this.GetInputFileNames());

            foreach (string file in this.GetInputFileNames())
            {
                assemblyLoader.LoadModule(file);
            }

            ITypeSystem typeSystem = new TypeSystem();

            typeSystem.LoadModules(assemblyLoader.Modules);

            int nativePointerSize;
            int nativePointerAlignment;

            this.architectureSelector.Architecture.GetTypeRequirements(BuiltInSigType.IntPtr, out nativePointerSize, out nativePointerAlignment);

            TypeLayout typeLayout = new TypeLayout(typeSystem, nativePointerSize, nativePointerAlignment);

            // Create the compiler
            using (AotCompiler aot = new AotCompiler(this.architectureSelector.Architecture, typeSystem, typeLayout))
            {
                aot.Pipeline.AddRange(new IAssemblyCompilerStage[]
                {
                    this.bootFormatStage,
                    new InterruptBuilderStage(),
                    new AssemblyCompilationStage(),
                    //new FakeSystemObjectGenerationStage(),
                    new MethodCompilerSchedulerStage(),
                    new TypeInitializers.TypeInitializerSchedulerStage(),
                    this.bootFormatStage,
                    new CilHeaderBuilderStage(),
                    new ObjectFileLayoutStage(),
                    this.linkerStage,
                    this.mapFileWrapper
                });

                aot.Run();
            }
        }
Example #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AotMethodCompiler"/> class.
 /// </summary>
 /// <param name="compiler">The AOT assembly compiler.</param>
 /// <param name="type">The type.</param>
 /// <param name="method">The method.</param>
 public AotMethodCompiler(AotCompiler compiler, RuntimeType type, RuntimeMethod method)
     : base(compiler.Pipeline.Find <IAssemblyLinker>(), compiler.Architecture, compiler.Assembly, type, method)
 {
     aotCompiler = compiler;
     Pipeline.AddRange(new IMethodCompilerStage[] {
         new DecodingStage(),
         new InstructionLogger(typeof(DecodingStage)),
         new BasicBlockBuilderStage(),
         new InstructionLogger(typeof(BasicBlockBuilderStage)),
         new OperandDeterminationStage(),
         new InstructionLogger(typeof(OperandDeterminationStage)),
         new CILTransformationStage(),
         new InstructionLogger(typeof(CILTransformationStage)),
         //InstructionStatisticsStage.Instance,
         new DominanceCalculationStage(),
         new InstructionLogger(typeof(DominanceCalculationStage)),
         //new EnterSSA(),
         //new InstructionLogger(typeof(EnterSSA)),
         //new ConstantPropagationStage(),
         //InstructionLogger.Instance,
         //new ConstantFoldingStage(),
         //new StrengthReductionStage(),
         //InstructionLogger.Instance,
         //new LeaveSSA(),
         //InstructionLogger.Instance,
         //InstructionLogger.Instance,
         new StackLayoutStage(),
         new InstructionLogger(typeof(StackLayoutStage)),
         //InstructionLogger.Instance,
         //new BlockReductionStage(),
         new LoopAwareBlockOrderStage(),
         new InstructionLogger(typeof(LoopAwareBlockOrderStage)),
         //new SimpleTraceBlockOrderStage(),
         //new ReverseBlockOrderStage(),
         //		InstructionStatisticsStage.Instance,
         //new LocalCSE(),
         new CodeGenerationStage(),
     });
 }
Example #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AotMethodCompiler"/> class.
 /// </summary>
 /// <param name="compiler">The AOT assembly compiler.</param>
 /// <param name="type">The type.</param>
 /// <param name="method">The method.</param>
 public AotMethodCompiler(AotCompiler compiler, RuntimeType type, RuntimeMethod method)
     : base(compiler.Pipeline.Find<IAssemblyLinker>(), compiler.Architecture, compiler.Assembly, type, method)
 {
     aotCompiler = compiler;
     Pipeline.AddRange(new IMethodCompilerStage[] {
         new DecodingStage(),
         new InstructionLogger(typeof(DecodingStage)),
         new BasicBlockBuilderStage(),
         new InstructionLogger(typeof(BasicBlockBuilderStage)),
         new OperandDeterminationStage(),
         new InstructionLogger(typeof(OperandDeterminationStage)),
         new CILTransformationStage(),
         new InstructionLogger(typeof(CILTransformationStage)),
         //InstructionStatisticsStage.Instance,
         new DominanceCalculationStage(),
         new InstructionLogger(typeof(DominanceCalculationStage)),
         //new EnterSSA(),
         //new InstructionLogger(typeof(EnterSSA)),
         //new ConstantPropagationStage(),
         //InstructionLogger.Instance,
         //new ConstantFoldingStage(),
         //new StrengthReductionStage(),
         //InstructionLogger.Instance,
         //new LeaveSSA(),
         //InstructionLogger.Instance,
         //InstructionLogger.Instance,
         new StackLayoutStage(),
         new InstructionLogger(typeof(StackLayoutStage)),
         //InstructionLogger.Instance,
         //new BlockReductionStage(),
         new LoopAwareBlockOrderStage(),
         new InstructionLogger(typeof(LoopAwareBlockOrderStage)),
         //new SimpleTraceBlockOrderStage(),
         //new ReverseBlockOrderStage(),
     //		InstructionStatisticsStage.Instance,
         //new LocalCSE(),
         new CodeGenerationStage(),
     });
 }
Example #4
0
        private void Compile()
        {
            using (CompilationRuntime runtime = new CompilationRuntime()) {
                // Append the paths of the folder to the loader path
                List <string> paths = new List <string>();
                foreach (FileInfo assembly in this.inputFiles)
                {
                    string path = Path.GetDirectoryName(assembly.FullName);
                    if (!paths.Contains(path))
                    {
                        paths.Add(path);
                    }
                }

                // Append the search paths
                foreach (string path in paths)
                {
                    runtime.AssemblyLoader.AppendPrivatePath(path);
                }
                paths = null;

                /* FIXME: This only compiles the very first assembly, but we want to
                 * potentially merge multiple assemblies into our kernel. This will
                 * need an extension/modification of the assembly compiler method.
                 *
                 * // Load all input assemblies
                 * foreach (FileInfo assembly in this.inputFiles)
                 * {
                 *      IMetadataModule module = runtime.AssemblyLoader.Load(assembly.FullName);
                 * }
                 */

                IMetadataModule assemblyModule;
                FileInfo        file = null;

                try {
                    file           = this.inputFiles[0];
                    assemblyModule = runtime.AssemblyLoader.Load(file.FullName);

                    // Try to load debug information for the compilation
                    string dbgFile;
                    dbgFile = Path.Combine(Path.GetDirectoryName(file.FullName), Path.GetFileNameWithoutExtension(file.FullName) + ".pdb");
                    //dbgFile = Path.Combine(Path.GetDirectoryName(file.FullName), "mosacl.pdb");
                    if (File.Exists(dbgFile) == true)
                    {
                        using (FileStream fileStream = new FileStream(dbgFile, FileMode.Open, FileAccess.Read, FileShare.Read)) {
                            using (PdbReader reader = new PdbReader(fileStream)) {
                                Debug.WriteLine(@"Global symbols:");
                                foreach (CvSymbol symbol in reader.GlobalSymbols)
                                {
                                    Debug.WriteLine("\t" + symbol.ToString());
                                }

                                Debug.WriteLine(@"Types:");
                                foreach (PdbType type in reader.Types)
                                {
                                    Debug.WriteLine("\t" + type.Name);
                                    Debug.WriteLine("\t\tSymbols:");
                                    foreach (CvSymbol symbol in type.Symbols)
                                    {
                                        Debug.WriteLine("\t\t\t" + symbol.ToString());
                                    }

                                    Debug.WriteLine("\t\tLines:");
                                    foreach (CvLine line in type.LineNumbers)
                                    {
                                        Debug.WriteLine("\t\t\t" + line.ToString());
                                    }
                                }
                            }
                        }
                    }
                }
                catch (BadImageFormatException) {
                    ShowError(String.Format("Couldn't load input file {0} (invalid format).", file.FullName));
                    return;
                }

                // Create the compiler
                using (AotCompiler aot = new AotCompiler(this.architectureSelector.Architecture, assemblyModule)) {
                    aot.Pipeline.AddRange(new IAssemblyCompilerStage[] {
                        bootFormatStage,
                        new TypeLayoutStage(),
                        new MethodCompilerBuilderStage(),
                        new MethodCompilerRunnerStage(),
                        new TypeInitializers.TypeInitializerSchedulerStage(),
                        bootFormatStage,
                        new MetadataBuilderStage(),
                        new CilHeaderBuilderStage(),
                        new ObjectFileLayoutStage(),
                        linkerStage,
                        mapFileWrapper
                    });

                    aot.Run();
                }
            }
        }
Example #5
0
        private void Compile()
        {
            using (CompilationRuntime runtime = new CompilationRuntime())
            {
                runtime.InitializePrivatePaths(this.GetInputFileNames());

                // Create the compiler
                using (AotCompiler aot = new AotCompiler(this.architectureSelector.Architecture, this.GetMainAssembly()))
                {
                    aot.Pipeline.AddRange(
                        new IAssemblyCompilerStage[]
                    {
                        this.bootFormatStage,
                        new x86.InterruptBuilderStage(),
                        new AssemblyCompilationStage(this.GetInputFileNames()),
                        new FakeSystemObjectGenerationStage(),
                        new MethodCompilerSchedulerStage(),
                        new TypeInitializers.TypeInitializerSchedulerStage(),
                        this.bootFormatStage,
                        new Metadata.MetadataBuilderStage(),
                        new CilHeaderBuilderStage(),
                        new ObjectFileLayoutStage(),
                        this.linkerStage,
                        this.mapFileWrapper
                    });

                    aot.Run();
                }
            }
        }
Example #6
0
        private void Compile()
        {
            using (CompilationRuntime runtime = new CompilationRuntime()) {

                // Append the paths of the folder to the loader path
                List<string> paths = new List<string>();
                foreach (FileInfo assembly in this.inputFiles) {

                    string path = Path.GetDirectoryName(assembly.FullName);
                    if (!paths.Contains(path))
                        paths.Add(path);
                }

                // Append the search paths
                foreach (string path in paths)
                    runtime.AssemblyLoader.AppendPrivatePath(path);
                paths = null;

                /* FIXME: This only compiles the very first assembly, but we want to
                 * potentially merge multiple assemblies into our kernel. This will
                 * need an extension/modification of the assembly compiler method.
                 *
                // Load all input assemblies
                foreach (FileInfo assembly in this.inputFiles)
                {
                    IMetadataModule module = runtime.AssemblyLoader.Load(assembly.FullName);
                }
                 */

                IMetadataModule assemblyModule;
                FileInfo file = null;

                try {
                    file = this.inputFiles[0];
                    assemblyModule = runtime.AssemblyLoader.Load(file.FullName);

                    // Try to load debug information for the compilation
                    string dbgFile;
                    dbgFile = Path.Combine(Path.GetDirectoryName(file.FullName), Path.GetFileNameWithoutExtension(file.FullName) + ".pdb");
                    //dbgFile = Path.Combine(Path.GetDirectoryName(file.FullName), "mosacl.pdb");
                    if (File.Exists(dbgFile) == true) {
                        using (FileStream fileStream = new FileStream(dbgFile, FileMode.Open, FileAccess.Read, FileShare.Read)) {
                            using (PdbReader reader = new PdbReader(fileStream)) {
                                Debug.WriteLine(@"Global symbols:");
                                foreach (CvSymbol symbol in reader.GlobalSymbols) {
                                    Debug.WriteLine("\t" + symbol.ToString());
                                }

                                Debug.WriteLine(@"Types:");
                                foreach (PdbType type in reader.Types) {
                                    Debug.WriteLine("\t" + type.Name);
                                    Debug.WriteLine("\t\tSymbols:");
                                    foreach (CvSymbol symbol in type.Symbols) {
                                        Debug.WriteLine("\t\t\t" + symbol.ToString());
                                    }

                                    Debug.WriteLine("\t\tLines:");
                                    foreach (CvLine line in type.LineNumbers) {
                                        Debug.WriteLine("\t\t\t" + line.ToString());
                                    }
                                }
                            }
                        }
                    }
                }
                catch (BadImageFormatException) {
                    ShowError(String.Format("Couldn't load input file {0} (invalid format).", file.FullName));
                    return;
                }

                // Create the compiler
                using (AotCompiler aot = new AotCompiler(this.architectureSelector.Architecture, assemblyModule)) {
                    aot.Pipeline.AddRange(new IAssemblyCompilerStage[] {
                        bootFormatStage,
                        new TypeLayoutStage(),
                        new MethodCompilerBuilderStage(),
                        new MethodCompilerRunnerStage(),
                        new TypeInitializers.TypeInitializerSchedulerStage(),
                        new x86.InterruptStage(),
                        bootFormatStage,
                        new MetadataBuilderStage(),
                        new CilHeaderBuilderStage(),
                        new ObjectFileLayoutStage(),
                        linkerStage,
                        mapFileWrapper
                    });

                    aot.Run();
                }
            }
        }
Example #7
0
        private void Compile()
        {
            IAssemblyLoader assemblyLoader = new AssemblyLoader();
            assemblyLoader.InitializePrivatePaths(this.GetInputFileNames());

            ITypeSystem typeSystem = new DefaultTypeSystem(assemblyLoader);
            typeSystem.LoadModules(this.GetInputFileNames());

            // Create the compiler
            using (AotCompiler aot = new AotCompiler(this.architectureSelector.Architecture, typeSystem))
            {
                aot.Pipeline.AddRange(new IAssemblyCompilerStage[]
                    {
                        this.bootFormatStage,
                        new InterruptBuilderStage(),
                        new AssemblyCompilationStage(),
                        //new FakeSystemObjectGenerationStage(),
                        new MethodCompilerSchedulerStage(),
                        new TypeInitializers.TypeInitializerSchedulerStage(),
                        this.bootFormatStage,
                        new Metadata.MetadataBuilderStage(),
                        new CilHeaderBuilderStage(),
                        new ObjectFileLayoutStage(),
                        this.linkerStage,
                        this.mapFileWrapper
                    });

                aot.Run();
            }
        }
Example #8
0
        private void Compile()
        {
            IAssemblyLoader assemblyLoader = new AssemblyLoader();
            assemblyLoader.InitializePrivatePaths(this.GetInputFileNames());

            foreach (string file in this.GetInputFileNames())
            {
                assemblyLoader.LoadModule(file);
            }

            ITypeSystem typeSystem = new TypeSystem();
            typeSystem.LoadModules(assemblyLoader.Modules);

            int nativePointerSize;
            int nativePointerAlignment;

            this.architectureSelector.Architecture.GetTypeRequirements(BuiltInSigType.IntPtr, out nativePointerSize, out nativePointerAlignment);

            TypeLayout typeLayout = new TypeLayout(typeSystem, nativePointerSize, nativePointerAlignment);

            // Create the compiler
            using (AotCompiler aot = new AotCompiler(this.architectureSelector.Architecture, typeSystem, typeLayout))
            {
                aot.Pipeline.AddRange(new IAssemblyCompilerStage[]
                    {
                        this.bootFormatStage,
                        new InterruptBuilderStage(),
                        new AssemblyCompilationStage(),
                        //new FakeSystemObjectGenerationStage(),
                        new MethodCompilerSchedulerStage(),
                        new TypeInitializers.TypeInitializerSchedulerStage(),
                        this.bootFormatStage,
                        new CilHeaderBuilderStage(),
                        new ObjectFileLayoutStage(),
                        this.linkerStage,
                        this.mapFileWrapper
                    });

                aot.Run();
            }
        }