public Compiler(MosaCompiler mosaCompiler) { TypeSystem = mosaCompiler.TypeSystem; TypeLayout = mosaCompiler.TypeLayout; CompilerOptions = mosaCompiler.CompilerOptions; Linker = mosaCompiler.Linker; CompilerTrace = mosaCompiler.CompilerTrace; Architecture = CompilerOptions.Architecture; PostCompilerTraceEvent(CompilerEvent.CompilerStart); CompilerExtensions.AddRange(mosaCompiler.CompilerExtensions); MethodStagePipelines = new Pipeline <BaseMethodCompilerStage> [mosaCompiler.MaxThreads + 1]; MethodScheduler = new MethodScheduler(this); MethodScanner = new MethodScanner(this); foreach (var type in Assembly.GetExecutingAssembly().GetTypes()) { if (!type.IsClass) { continue; } foreach (var method in type.GetRuntimeMethods()) { // Now get all the IntrinsicMethodAttribute attributes var attributes = (IntrinsicMethodAttribute[])method.GetCustomAttributes(typeof(IntrinsicMethodAttribute), true); for (int i = 0; i < attributes.Length; i++) { var d = (InstrinsicMethodDelegate)Delegate.CreateDelegate(typeof(InstrinsicMethodDelegate), method); // Finally add the dictionary entry mapping the target name and the delegate InternalIntrinsicMethods.Add(attributes[i].Target, d); } } } PlugSystem = new PlugSystem(TypeSystem); PlatformInternalRuntimeType = GetPlatformInternalRuntimeType(); InternalRuntimeType = GeInternalRuntimeType(); // Build the default compiler pipeline CompilerPipeline.Add(GetDefaultCompilerPipeline(CompilerOptions)); foreach (var extension in CompilerExtensions) { extension.ExtendCompilerPipeline(CompilerPipeline); } Architecture.ExtendCompilerPipeline(CompilerPipeline, CompilerOptions); IsStopped = false; WorkCount = 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); }
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); }
public Compiler(MosaCompiler mosaCompiler) { Architecture = mosaCompiler.CompilerOptions.Architecture; TypeSystem = mosaCompiler.TypeSystem; TypeLayout = mosaCompiler.TypeLayout; CompilerTrace = mosaCompiler.CompilerTrace; CompilerOptions = mosaCompiler.CompilerOptions; CompilationScheduler = mosaCompiler.CompilationScheduler; Linker = mosaCompiler.Linker; CompilerExtensions.AddRange(mosaCompiler.CompilerExtensions); methodStagePipelines = new Pipeline <BaseMethodCompilerStage> [mosaCompiler.MaxThreads]; // 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); } } } PlugSystem = new PlugSystem(TypeSystem); PlatformInternalRuntimeType = GetPlatformInternalRuntimeType(); InternalRuntimeType = GeInternalRuntimeType(); // Build the default compiler pipeline CompilerPipeline.Add(GetDefaultCompilerPipeline(CompilerOptions)); foreach (var extension in CompilerExtensions) { extension.ExtendCompilerPipeline(CompilerPipeline); } Architecture.ExtendCompilerPipeline(CompilerPipeline); IsStopped = false; }
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); }
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.EnableOptimizations = Options.EnableIROptimizations; compiler.CompilerOptions.EnableSparseConditionalConstantPropagation = Options.EnableSparseConditionalConstantPropagation; compiler.CompilerOptions.EnableInlinedMethods = Options.EnableInlinedMethods; compiler.CompilerOptions.InlinedIRMaximum = Options.InlinedIRMaximum; compiler.CompilerOptions.EnableVariablePromotion = Options.EnableVariablePromotion; 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(string.Format("File {0} does not exists", Options.SourceFile)); 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.GenerateASMFile) { LaunchNDISASM(); } } catch (Exception e) { Console.WriteLine(e.ToString()); } finally { compiler.Dispose(); compiler = null; } }
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); }
public Compiler(MosaCompiler mosaCompiler) { TypeSystem = mosaCompiler.TypeSystem; TypeLayout = mosaCompiler.TypeLayout; CompilerSettings = mosaCompiler.CompilerSettings; Architecture = mosaCompiler.Platform; CompilerHooks = mosaCompiler.CompilerHooks; TraceLevel = CompilerSettings.TraceLevel; Statistics = CompilerSettings.Statistics; Linker = new MosaLinker(this); ObjectHeaderSize = Architecture.NativePointerSize + 4 + 4; // Hash Value (32-bit) + Lock & Status (32-bit) + Method Table StackFrame = Operand.CreateCPURegister(TypeSystem.BuiltIn.Pointer, Architecture.StackFrameRegister); StackPointer = Operand.CreateCPURegister(TypeSystem.BuiltIn.Pointer, Architecture.StackPointerRegister); LinkRegister = Architecture.LinkRegister == null ? null : Operand.CreateCPURegister(TypeSystem.BuiltIn.Object, Architecture.LinkRegister); ProgramCounter = Architecture.ProgramCounter == null ? null : Operand.CreateCPURegister(TypeSystem.BuiltIn.Object, Architecture.ProgramCounter); ExceptionRegister = Operand.CreateCPURegister(TypeSystem.BuiltIn.Object, Architecture.ExceptionRegister); LeaveTargetRegister = Operand.CreateCPURegister(TypeSystem.BuiltIn.Object, Architecture.LeaveTargetRegister); PostEvent(CompilerEvent.CompileStart); MethodStagePipelines = new Pipeline <BaseMethodCompilerStage> [MaxThreads]; MethodScheduler = new MethodScheduler(this); MethodScanner = new MethodScanner(this); foreach (var type in Assembly.GetExecutingAssembly().GetTypes()) { if (!type.IsClass) { continue; } foreach (var method in type.GetRuntimeMethods()) { // Now get all the IntrinsicMethodAttribute attributes var intrinsicMethodAttributes = (IntrinsicMethodAttribute[])method.GetCustomAttributes(typeof(IntrinsicMethodAttribute), true); for (int i = 0; i < intrinsicMethodAttributes.Length; i++) { var d = (IntrinsicMethodDelegate)System.Delegate.CreateDelegate(typeof(IntrinsicMethodDelegate), method); // Finally add the dictionary entry mapping the target name and the delegate InternalIntrinsicMethods.Add(intrinsicMethodAttributes[i].Target, d); } // Now get all the StubMethodAttribute attributes var stubMethodAttributes = (StubMethodAttribute[])method.GetCustomAttributes(typeof(StubMethodAttribute), true); for (int i = 0; i < stubMethodAttributes.Length; i++) { var d = (StubMethodDelegate)System.Delegate.CreateDelegate(typeof(StubMethodDelegate), method); // Finally add the dictionary entry mapping the target name and the delegate InternalStubMethods.Add(stubMethodAttributes[i].Target, d); } } } PlugSystem = new PlugSystem(TypeSystem); PlatformInternalRuntimeType = GetPlatformInternalRuntimeType(); InternalRuntimeType = GeInternalRuntimeType(); // Build the default compiler pipeline CompilerPipeline.Add(GetDefaultCompilerPipeline(CompilerSettings, Architecture.Is64BitPlatform)); // Call hook to allow for the extension of the pipeline CompilerHooks.ExtendCompilerPipeline?.Invoke(CompilerPipeline); Architecture.ExtendCompilerPipeline(CompilerPipeline, CompilerSettings); IsStopped = false; }
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.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; } }