private static void MeasureCompileTime(Stopwatch stopwatch, MosaCompiler compiler, MosaMethod method, int iterations) { Console.WriteLine($"Method: {method}"); double min = double.MaxValue; double max = double.MinValue; double total = 0; for (int i = 0; i < iterations; i++) { var start = stopwatch.Elapsed.TotalMilliseconds; compiler.CompileSingleMethod(method); var elapsed = stopwatch.Elapsed.TotalMilliseconds - start; min = Math.Min(min, elapsed); max = Math.Max(max, elapsed); total += elapsed; //Console.WriteLine($"Elapsed: {elapsed.ToString("F2")} ms"); } double avg = total / iterations; Console.WriteLine($"Elapsed: {max.ToString("F2")} ms (worst)"); Console.WriteLine($"Elapsed: {avg.ToString("F2")} ms (average)"); Console.WriteLine($"Elapsed: {min.ToString("F2")} ms (best)"); }
private void Compile() { var fileHunter = new FileHunter(Path.GetDirectoryName(LauncherSettings.SourceFiles[0])); if (LauncherSettings.HuntForCorLib) { var fileCorlib = fileHunter.HuntFile("mscorlib.dll"); if (fileCorlib != null) { Settings.AddPropertyListValue("Compiler.SourceFiles", fileCorlib.FullName); } } if (LauncherSettings.PlugKorlib) { var fileKorlib = fileHunter.HuntFile("Mosa.Plug.Korlib.dll"); if (fileKorlib != null) { Settings.AddPropertyListValue("Compiler.SourceFiles", fileKorlib.FullName); } var platform = LauncherSettings.Platform; if (platform == "armv8a32") { platform = "ARMv8A32"; } var fileKorlibPlatform = fileHunter.HuntFile($"Mosa.Plug.Korlib.{platform}.dll"); if (fileKorlibPlatform != null) { Settings.AddPropertyListValue("Compiler.SourceFiles", fileKorlibPlatform.FullName); } } var compiler = new MosaCompiler(Settings, CompilerHooks); compiler.Load(); compiler.Initialize(); compiler.Setup(); if (LauncherSettings.Multithreading) { compiler.ThreadedCompile(); } else { compiler.Compile(); } Linker = compiler.Linker; TypeSystem = compiler.TypeSystem; }
/// <summary> /// Runs the command line parser and the compilation process. /// </summary> /// <param name="args">The command line arguments.</param> public void Run(string[] args) { RegisterPlatforms(); // always print header with version information Console.WriteLine("MOSA Compiler, Version {0}.", CompilerVersion.VersionString); Console.WriteLine("Copyright 2020 by the MOSA Project. Licensed under the New BSD License."); Console.WriteLine(); Console.WriteLine("Parsing options..."); try { LoadArguments(args); var sourceFiles = Settings.GetValueList("Compiler.SourceFiles"); if (sourceFiles == null && sourceFiles.Count == 0) { throw new Exception("No input file(s) specified."); } compiler = new MosaCompiler(Settings, CreateCompilerHooks()); if (string.IsNullOrEmpty(compiler.CompilerSettings.OutputFile)) { throw new Exception("No output file specified."); } if (compiler.CompilerSettings.Platform == null) { throw new Exception("No Architecture specified."); } Trace.Listeners.Add(new TextWriterTraceListener(Console.Out)); Debug.AutoFlush = true; Console.WriteLine($" > Output file: {compiler.CompilerSettings.OutputFile}"); Console.WriteLine($" > Input file(s): {(string.Join(", ", new List<string>(compiler.CompilerSettings.SourceFiles.ToArray())))}"); Console.WriteLine($" > Platform: {compiler.CompilerSettings.Platform}"); Console.WriteLine(); Console.WriteLine("Compiling ..."); Console.WriteLine(); Compile(); } catch (CompilerException ce) { ShowError(ce.Message); Environment.Exit(1); return; } }
private void ClearAll() { Compiler = null; typeSystemTree = null; treeView.Nodes.Clear(); tbInstructions.Text = string.Empty; tbDebugResult.Text = string.Empty; methodStore.Clear(); ClearAllLogs(); }
public void LoadAssembly() { ClearAll(); UpdateSettings(); var compilerHooks = CreateCompilerHook(); Compiler = new MosaCompiler(Settings, compilerHooks); Compiler.Load(); CreateTree(); SetStatus("Assemblies Loaded!"); }
private static void MeasureCompileTime(Stopwatch stopwatch, MosaCompiler compiler, MosaMethod method) { Console.WriteLine($"Method: {method}"); double min = double.MaxValue; for (int i = 0; i < 6; i++) { var start = stopwatch.Elapsed.TotalMilliseconds; compiler.CompileSingleMethod(method); var elapsed = stopwatch.Elapsed.TotalMilliseconds - start; min = Math.Min(min, elapsed); //Console.WriteLine($"Elapsed: {elapsed.ToString("F2")} ms"); } Console.WriteLine($"Elapsed: {min.ToString("F2")} ms (best)"); }
public void Reset() { IsInitialized = false; simAdapter = platform.CreateSimAdaptor(); Compiler = new MosaCompiler(); Compiler.CompilerTrace.TraceFilter.Active = false; Compiler.CompilerTrace.TraceListener = this; Compiler.CompilerOptions.EnableOptimizations = true; Compiler.CompilerOptions.EnableSSA = true; Compiler.CompilerOptions.EnableVariablePromotion = true; Compiler.CompilerOptions.EnableSparseConditionalConstantPropagation = true; Compiler.CompilerOptions.EnableInlinedMethods = true; Compiler.CompilerOptions.EmitRelocations = false; Compiler.CompilerOptions.EmitSymbols = false; Compiler.CompilerOptions.Architecture = platform.CreateArchitecture(); Compiler.CompilerOptions.LinkerFormatType = LinkerFormatType.Elf32; Compiler.CompilerFactory = delegate { return(new SimCompiler(simAdapter)); }; }
private static void MeasureCompileTime(Stopwatch stopwatch, MosaCompiler compiler, string methodName) { var method = GetMethod(methodName, compiler.TypeSystem); MeasureCompileTime(stopwatch, compiler, method); }
private static void Main() { const string platform = "x86"; var compilerOptions = new CompilerOptions() { EnableSSA = true, EnableIROptimizations = true, EnableSparseConditionalConstantPropagation = true, EnableInlinedMethods = true, EnableLongExpansion = true, EnableValueNumbering = true, TwoPassOptimizations = true, EnableMethodScanner = true, EnableBitTracker = true, // FUTURE MultibootSpecification = MultibootSpecification.V1, LinkerFormatType = LinkerFormatType.Elf32, InlinedIRMaximum = 12, BaseAddress = 0x00500000, EmitStaticRelocations = false, EmitAllSymbols = false, EmitBinary = false, TraceLevel = 0, EnableStatistics = true, }; compilerOptions.Architecture = SelectArchitecture(platform); compilerOptions.AddSourceFile($"Mosa.TestWorld.{platform}.exe"); compilerOptions.AddSourceFile("Mosa.Plug.Korlib.dll"); compilerOptions.AddSourceFile($"Mosa.Plug.Korlib.{platform}.dll"); compilerOptions.TraceLevel = 5; var stopwatch = new Stopwatch(); var compiler = new MosaCompiler(compilerOptions); compiler.Load(); compiler.Initialize(); compiler.Setup(); stopwatch.Start(); //MeasureCompileTime(stopwatch, compiler, "Mosa.Kernel.x86.IDT::SetTableEntries"); //MeasureCompileTime(stopwatch, compiler, "System.Void Mosa.TestWorld.x86.Boot::Thread1"); //MeasureCompileTime(stopwatch, compiler, "System.String System.Int32::CreateString(System.UInt32, System.Boolean, System.Boolean)"); //compiler.ScheduleAll(); var start = stopwatch.Elapsed.TotalSeconds; Console.WriteLine("Threaded Execution Time:"); compiler.ThreadedCompile(); //compiler.Execute(); Console.WriteLine($"Elapsed: {(stopwatch.Elapsed.TotalSeconds - start).ToString("F2")} secs"); Console.ReadKey(); }
public void Compile() { Log.Clear(); Counters.Clear(); HasCompileError = true; var compiler = new MosaCompiler(GetCompilerExtensions()); try { CompileStartTime = DateTime.Now; CompiledFile = Path.Combine(LauncherOptions.DestinationDirectory, $"{Path.GetFileNameWithoutExtension(LauncherOptions.SourceFile)}.bin"); compiler.CompilerOptions.EnableSSA = LauncherOptions.EnableSSA; compiler.CompilerOptions.EnableIROptimizations = LauncherOptions.EnableIROptimizations; compiler.CompilerOptions.EnableSparseConditionalConstantPropagation = LauncherOptions.EnableSparseConditionalConstantPropagation; compiler.CompilerOptions.EnableInlinedMethods = LauncherOptions.EnableInlinedMethods; compiler.CompilerOptions.InlinedIRMaximum = LauncherOptions.InlinedIRMaximum; compiler.CompilerOptions.EnableLongExpansion = LauncherOptions.EnableLongExpansion; compiler.CompilerOptions.TwoPassOptimizations = LauncherOptions.TwoPassOptimizations; compiler.CompilerOptions.EnableValueNumbering = LauncherOptions.EnableValueNumbering; compiler.CompilerOptions.OutputFile = CompiledFile; compiler.CompilerOptions.Architecture = SelectArchitecture(LauncherOptions.PlatformType); compiler.CompilerOptions.LinkerFormatType = LauncherOptions.LinkerFormatType; compiler.CompilerOptions.MultibootSpecification = LauncherOptions.MultibootSpecification; compiler.CompilerOptions.SetCustomOption("multiboot.video", LauncherOptions.VBEVideo ? "true" : "false"); compiler.CompilerOptions.SetCustomOption("multiboot.width", LauncherOptions.Width.ToString()); compiler.CompilerOptions.SetCustomOption("multiboot.height", LauncherOptions.Height.ToString()); compiler.CompilerOptions.SetCustomOption("multiboot.depth", LauncherOptions.Depth.ToString()); compiler.CompilerOptions.BaseAddress = LauncherOptions.BaseAddress; compiler.CompilerOptions.EmitAllSymbols = LauncherOptions.EmitAllSymbols; compiler.CompilerOptions.EmitStaticRelocations = LauncherOptions.EmitStaticRelocations; compiler.CompilerOptions.EnableMethodScanner = LauncherOptions.EnableMethodScanner; compiler.CompilerOptions.EnableBitTracker = LauncherOptions.EnableBitTracker; compiler.CompilerOptions.CreateExtraSections = LauncherOptions.CreateExtraSections; compiler.CompilerOptions.CreateExtraProgramHeaders = LauncherOptions.CreateExtraProgramHeaders; if (LauncherOptions.GenerateMapFile) { compiler.CompilerOptions.MapFile = Path.Combine(LauncherOptions.DestinationDirectory, $"{Path.GetFileNameWithoutExtension(LauncherOptions.SourceFile)}.map"); } if (LauncherOptions.GenerateCompileTimeFile) { compiler.CompilerOptions.CompileTimeFile = Path.Combine(LauncherOptions.DestinationDirectory, $"{Path.GetFileNameWithoutExtension(LauncherOptions.SourceFile)}-time.txt"); } if (LauncherOptions.GenerateDebugFile) { var debugFile = LauncherOptions.DebugFile ?? Path.GetFileNameWithoutExtension(LauncherOptions.SourceFile) + ".debug"; compiler.CompilerOptions.DebugFile = Path.Combine(LauncherOptions.DestinationDirectory, debugFile); } if (!Directory.Exists(LauncherOptions.DestinationDirectory)) { Directory.CreateDirectory(LauncherOptions.DestinationDirectory); } compiler.CompilerTrace.SetTraceListener(traceListener); if (string.IsNullOrEmpty(LauncherOptions.SourceFile)) { AddOutput("Please select a source file"); return; } else if (!File.Exists(LauncherOptions.SourceFile)) { AddOutput($"File {LauncherOptions.SourceFile} does not exists"); return; } compiler.CompilerOptions.AddSourceFile(LauncherOptions.SourceFile); compiler.CompilerOptions.AddSearchPaths(LauncherOptions.Paths); var inputFiles = new List <FileInfo> { (LauncherOptions.HuntForCorLib) ? HuntFor("mscorlib.dll") : null, (LauncherOptions.PlugKorlib) ? HuntFor("Mosa.Plug.Korlib.dll") : null, (LauncherOptions.PlugKorlib) ? HuntFor("Mosa.Plug.Korlib." + LauncherOptions.PlatformType.ToString() + ".dll"): null, }; compiler.CompilerOptions.AddSourceFiles(inputFiles); compiler.CompilerOptions.AddSearchPaths(inputFiles); compiler.Load(); compiler.Initialize(); compiler.Setup(); // TODO Include Unit Tests if (LauncherOptions.EnableMultiThreading) { compiler.ThreadedCompile(); } else { compiler.Compile(); } Linker = compiler.Linker; TypeSystem = compiler.TypeSystem; if (LauncherOptions.ImageFormat == ImageFormat.ISO) { if (LauncherOptions.BootLoader == BootLoader.Grub_0_97 || LauncherOptions.BootLoader == BootLoader.Grub_2_00) { CreateISOImageWithGrub(CompiledFile); } else // assuming syslinux { CreateISOImageWithSyslinux(CompiledFile); } } else { CreateDiskImage(CompiledFile); if (LauncherOptions.ImageFormat == ImageFormat.VMDK) { CreateVMDK(); } } if (LauncherOptions.GenerateNASMFile) { LaunchNDISASM(); } if (LauncherOptions.GenerateASMFile) { GenerateASMFile(); } HasCompileError = false; } catch (Exception e) { HasCompileError = true; AddOutput(e.ToString()); } finally { compiler = null; } }
public void Compile() { HasCompileError = true; Log.Clear(); Counters.Clear(); var compiler = new MosaCompiler(); try { CompileStartTime = DateTime.Now; CompiledFile = Path.Combine(Options.DestinationDirectory, $"{Path.GetFileNameWithoutExtension(Options.SourceFile)}.bin"); compiler.CompilerFactory = delegate { return(new AotCompiler()); }; compiler.CompilerOptions.EnableSSA = Options.EnableSSA; compiler.CompilerOptions.EnableIROptimizations = Options.EnableIROptimizations; compiler.CompilerOptions.EnableSparseConditionalConstantPropagation = Options.EnableSparseConditionalConstantPropagation; compiler.CompilerOptions.EnableInlinedMethods = Options.EnableInlinedMethods; compiler.CompilerOptions.InlinedIRMaximum = Options.InlinedIRMaximum; compiler.CompilerOptions.OutputFile = CompiledFile; compiler.CompilerOptions.Architecture = SelectArchitecture(Options.PlatformType); compiler.CompilerOptions.LinkerFormatType = Options.LinkerFormatType; compiler.CompilerOptions.BootStageFactory = GetBootStageFactory(Options.BootFormat); compiler.CompilerOptions.SetCustomOption("multiboot.video", Options.VBEVideo ? "true" : "false"); compiler.CompilerOptions.SetCustomOption("multiboot.width", Options.Width.ToString()); compiler.CompilerOptions.SetCustomOption("multiboot.height", Options.Height.ToString()); compiler.CompilerOptions.SetCustomOption("multiboot.depth", Options.Depth.ToString()); compiler.CompilerOptions.BaseAddress = Options.BaseAddress; compiler.CompilerOptions.EmitSymbols = Options.EmitSymbols; compiler.CompilerOptions.EmitRelocations = Options.EmitRelocations; compiler.CompilerOptions.SetCustomOption("x86.irq-methods", Options.Emitx86IRQMethods ? "true" : "false"); if (Options.GenerateMapFile) { compiler.CompilerOptions.MapFile = Path.Combine(Options.DestinationDirectory, $"{Path.GetFileNameWithoutExtension(Options.SourceFile)}.map"); } if (!Directory.Exists(Options.DestinationDirectory)) { Directory.CreateDirectory(Options.DestinationDirectory); } compiler.CompilerTrace.TraceListener = traceListener; if (string.IsNullOrEmpty(Options.SourceFile)) { AddOutput("Please select a source file"); return; } else if (!File.Exists(Options.SourceFile)) { AddOutput($"File {Options.SourceFile} does not exists"); return; } var inputFiles = new List <FileInfo>(); inputFiles.Add(new FileInfo(Options.SourceFile)); compiler.Load(inputFiles); var threads = Options.UseMultipleThreadCompiler ? Environment.ProcessorCount : 1; compiler.Execute(threads); Linker = compiler.Linker; TypeSystem = compiler.TypeSystem; if (Options.ImageFormat == ImageFormat.ISO) { if (Options.BootLoader == BootLoader.Grub_0_97 || Options.BootLoader == BootLoader.Grub_2_00) { CreateISOImageWithGrub(CompiledFile); } else // assuming syslinux { CreateISOImageWithSyslinux(CompiledFile); } } else { CreateDiskImage(CompiledFile); if (Options.ImageFormat == ImageFormat.VMDK) { CreateVMDK(ImageFile); } } HasCompileError = false; if (Options.GenerateNASMFile) { LaunchNDISASM(); } if (Options.GenerateASMFile) { GenerateASMFile(); } } catch (Exception e) { Console.WriteLine(e.ToString()); } finally { compiler.Dispose(); compiler = null; } }
public void Compile() { HasCompileError = false; try { Compiler = new MosaCompiler(); CompileStartTime = DateTime.Now; compiledFile = Path.Combine(Options.DestinationDirectory, Path.GetFileNameWithoutExtension(Options.SourceFile) + ".bin"); Compiler.CompilerFactory = delegate { return(new AotCompiler()); }; Compiler.CompilerOptions.EnableSSA = Options.EnableSSA; Compiler.CompilerOptions.EnableOptimizations = Options.EnableIROptimizations; Compiler.CompilerOptions.EnableSparseConditionalConstantPropagation = Options.EnableSparseConditionalConstantPropagation; Compiler.CompilerOptions.EnableInlinedMethods = Options.EnableInlinedMethods; Compiler.CompilerOptions.InlinedIRMaximum = Options.InlinedIRMaximum; Compiler.CompilerOptions.OutputFile = compiledFile; Compiler.CompilerOptions.Architecture = SelectArchitecture(Options.PlatformType); Compiler.CompilerOptions.LinkerFactory = GetLinkerFactory(Options.LinkerFormat); Compiler.CompilerOptions.BootStageFactory = GetBootStageFactory(Options.BootFormat); if (Options.GenerateMapFile) { Compiler.CompilerOptions.MapFile = Path.Combine(Options.DestinationDirectory, Path.GetFileNameWithoutExtension(Options.SourceFile) + ".map"); } if (!Directory.Exists(Options.DestinationDirectory)) { Directory.CreateDirectory(Options.DestinationDirectory); } Compiler.CompilerTrace.TraceListener = traceListener; if (string.IsNullOrEmpty(Options.SourceFile)) { AddOutput("Please select a source file"); HasCompileError = true; return; } else if (!File.Exists(Options.SourceFile)) { AddOutput(string.Format("File {0} does not exists", Options.SourceFile)); HasCompileError = true; return; } var inputFiles = new List <FileInfo>(); inputFiles.Add(new FileInfo(Options.SourceFile)); Compiler.Load(inputFiles); var threads = Options.CompilerUsesMultipleThreads ? Environment.ProcessorCount : 1; Compiler.Execute(threads); if (Options.ImageFormat == ImageFormat.ISO) { CreateISOImage(compiledFile); } else { CreateDiskImage(compiledFile); if (Options.ImageFormat == ImageFormat.VMDK) { CreateVMDK(imageFile); } } if (Options.GenerateASMFile) { LaunchNDISASM(); } } finally { Compiler.Dispose(); Compiler = null; } }
private static void Compile() { RegisterPlatforms(); var settings = new Settings(); settings.SetValue("Compiler.MethodScanner", false); settings.SetValue("Compiler.Multithreading", true); settings.SetValue("Optimizations.SSA", false); settings.SetValue("Optimizations.Basic", false); settings.SetValue("Optimizations.ValueNumbering", false); settings.SetValue("Optimizations.SCCP", false); settings.SetValue("Optimizations.Devirtualization", false); settings.SetValue("Optimizations.BitTracker", false); settings.SetValue("Optimizations.LoopInvariantCodeMotion", false); settings.SetValue("Optimizations.LongExpansion", false); settings.SetValue("Optimizations.TwoPass", false); settings.SetValue("Optimizations.Platform", false); settings.SetValue("Optimizations.Inline", false); settings.SetValue("Optimizations.Inline.ExplicitOnly", false); settings.SetValue("Optimizations.Inline.Maximum", 12); settings.SetValue("Optimizations.Inline.AggressiveMaximum", 24); settings.SetValue("Multiboot.Version", "v1"); settings.SetValue("Compiler.Platform", "x86"); settings.SetValue("Compiler.BaseAddress", 0x00500000); settings.SetValue("Compiler.Binary", true); settings.SetValue("Compiler.TraceLevel", 0); settings.SetValue("Launcher.PlugKorlib", true); settings.SetValue("Multiboot.Version", "v1"); settings.SetValue("Emulator", "Qemu"); settings.SetValue("Emulator.Memory", 128); settings.SetValue("Emulator.Serial", "TCPServer"); settings.SetValue("Emulator.Serial.Host", "127.0.0.1"); settings.SetValue("Emulator.Serial.Port", new Random().Next(11111, 22222)); settings.SetValue("Emulator.Serial.Pipe", "MOSA"); settings.SetValue("Launcher.Start", false); settings.SetValue("Launcher.Launch", false); settings.SetValue("Launcher.Exit", true); settings.SetValue("Launcher.HuntForCorLib", true); settings.SetValue("Image.BootLoader", "syslinux3.72"); settings.SetValue("Image.Folder", Path.Combine(Path.GetTempPath(), "MOSA-UnitTest")); settings.SetValue("Image.Format", "IMG"); settings.SetValue("Image.FileSystem", "FAT16"); settings.AddPropertyListValue("SearchPaths", AppContext.BaseDirectory); settings.AddPropertyListValue("Compiler.SourceFiles", Path.Combine(AppContext.BaseDirectory, "Mosa.UnitTests.x86.exe")); settings.AddPropertyListValue("Compiler.SourceFiles", Path.Combine(AppContext.BaseDirectory, "Mosa.Plug.Korlib.dll")); settings.AddPropertyListValue("Compiler.SourceFiles", Path.Combine(AppContext.BaseDirectory, "Mosa.Plug.Korlib.x86.dll")); var stopwatch = new Stopwatch(); var compiler = new MosaCompiler(settings, new CompilerHooks()); compiler.Load(); compiler.Initialize(); compiler.Setup(); stopwatch.Start(); MeasureCompileTime(stopwatch, compiler, "Mosa.Kernel.x86.IDT::SetTableEntries"); compiler.ScheduleAll(); var start = stopwatch.Elapsed.TotalSeconds; Console.WriteLine("Threaded Execution Time:"); //compiler.ThreadedCompile(); //compiler.Execute(); Console.WriteLine($"Elapsed: {(stopwatch.Elapsed.TotalSeconds - start).ToString("F2")} secs"); Console.ReadKey(); }
/// <summary> /// Runs the command line parser and the compilation process. /// </summary> /// <param name="args">The command line arguments.</param> public void Run(string[] args) { // always print header with version information Console.WriteLine("MOSA AOT Compiler, Version {0}.{1} '{2}'", majorVersion, minorVersion, codeName); Console.WriteLine("Copyright 2019 by the MOSA Project. Licensed under the New BSD License."); Console.WriteLine(); Console.WriteLine("Parsing options..."); try { options = ParseOptions(args); if (options == null) { ShowShortHelp(); return; } if (options.InputFiles.Count == 0) { throw new Exception("No input file(s) specified."); } compiler = new MosaCompiler(options.CompilerOptions, GetCompilerExtensions()); Trace.Listeners.Add(new TextWriterTraceListener(Console.Out)); Debug.AutoFlush = true; // Process boot format: // Boot format only matters if it's an executable // Process this only now, because input files must be known if (!options.IsInputExecutable) { Console.WriteLine("Warning: Ignoring boot format, because target is not an executable."); Console.WriteLine(); } if (string.IsNullOrEmpty(compiler.CompilerOptions.OutputFile)) { throw new Exception("No output file specified."); } if (compiler.CompilerOptions.Architecture == null) { throw new Exception("No Architecture specified."); } } catch (Exception e) { ShowError(e.Message); Environment.Exit(1); return; } Console.WriteLine(ToString()); Console.WriteLine("Compiling ..."); DateTime start = DateTime.Now; try { Compile(); } catch (CompilerException ce) { ShowError(ce.Message); Environment.Exit(1); return; } DateTime end = DateTime.Now; TimeSpan time = end - start; Console.WriteLine(); Console.WriteLine("Compilation time: " + time); }