public CompilerTrace(IInternalTrace internalTrace, MosaMethod method, string stage) : this(internalTrace) { this.Stage = stage; this.Method = method; this.Active = internalTrace.TraceFilter.IsMatch(this.Method, this.Stage); }
/// <summary> /// Compiles the specified type system. /// </summary> /// <param name="typeSystem">The type system.</param> /// <param name="typeLayout">The type layout.</param> /// <param name="internalTrace">The internal trace.</param> /// <param name="enabledSSA">if set to <c>true</c> [enabled ssa].</param> /// <param name="architecture">The architecture.</param> /// <param name="simAdapter">The sim adapter.</param> /// <param name="linker">The linker.</param> /// <returns></returns> public static SimCompiler Compile(TypeSystem typeSystem, MosaTypeLayout typeLayout, IInternalTrace internalTrace, bool enabledSSA, BaseArchitecture architecture, ISimAdapter simAdapter, ILinker linker) { CompilerOptions compilerOptions = new CompilerOptions(); compilerOptions.EnableSSA = enabledSSA; compilerOptions.EnableSSAOptimizations = enabledSSA; SimCompiler compiler = new SimCompiler(architecture, typeSystem, typeLayout, linker, compilerOptions, internalTrace, simAdapter); compiler.Compile(); return compiler; }
/// <summary> /// Prevents a default instance of the <see cref="ExplorerCompiler"/> class from being created. /// </summary> /// <param name="architecture">The compiler target architecture.</param> /// <param name="typeSystem">The type system.</param> /// <param name="typeLayout">The type layout.</param> /// <param name="internalTrace">The internal trace.</param> /// <param name="compilerOptions">The compiler options.</param> public ExplorerCompiler(IArchitecture architecture, ITypeSystem typeSystem, ITypeLayout typeLayout, IInternalTrace internalTrace, CompilerOptions compilerOptions) : base(architecture, typeSystem, typeLayout, new CompilationScheduler(typeSystem, true), internalTrace, compilerOptions) { // Build the assembly compiler pipeline Pipeline.AddRange(new ICompilerStage[] { new PlugStage(), new MethodCompilerSchedulerStage(), new TypeLayoutStage(), (ExplorerLinker)Linker }); architecture.ExtendCompilerPipeline(Pipeline); }
/// <summary> /// Initializes a new compiler instance. /// </summary> /// <param name="architecture">The compiler target architecture.</param> /// <param name="typeSystem">The type system.</param> protected AssemblyCompiler(IArchitecture architecture, ITypeSystem typeSystem, ITypeLayout typeLayout, IInternalTrace internalTrace, CompilerOptions compilerOptions) { if (architecture == null) throw new ArgumentNullException(@"architecture"); this.pipeline = new CompilerPipeline(); this.architecture = architecture; this.typeSystem = typeSystem; this.typeLayout = typeLayout; this.internalTrace = internalTrace; this.compilerOptions = compilerOptions; this.genericTypePatcher = new GenericTypePatcher(typeSystem); }
private ExplorerAssemblyCompiler(IArchitecture architecture, ITypeSystem typeSystem, ITypeLayout typeLayout, IInternalTrace internalTrace, CompilerOptions compilerOptions) : base(architecture, typeSystem, typeLayout, internalTrace, compilerOptions) { var linker = new ExplorerLinker(); // Build the assembly compiler pipeline Pipeline.AddRange(new IAssemblyCompilerStage[] { new AssemblyMemberCompilationSchedulerStage(), new MethodCompilerSchedulerStage(), new TypeLayoutStage(), linker }); architecture.ExtendAssemblyCompilerPipeline(Pipeline); }
public static void Run(IInternalTrace internalLog, IPipelineStage stage, RuntimeMethod method, InstructionSet instructionSet, BasicBlocks basicBlocks) { if (internalLog == null) return; if (internalLog.TraceListener == null) return; if (!internalLog.TraceFilter.IsMatch(method, stage.Name)) return; StringBuilder text = new StringBuilder(); // Line number int index = 1; text.AppendLine(String.Format("IR representation of method {0} after stage {1}:", method, stage.Name)); text.AppendLine(); if (basicBlocks.Count > 0) { foreach (BasicBlock block in basicBlocks) { text.AppendFormat("Block #{0} - Label L_{1:X4}", index, block.Label); if (basicBlocks.IsHeaderBlock(block)) text.Append(" [Header]"); text.AppendLine(); text.AppendFormat(" Prev: "); text.AppendLine(ListBlocks(block.PreviousBlocks)); LogInstructions(text, new Context(instructionSet, block)); text.AppendFormat(" Next: "); text.AppendLine(ListBlocks(block.NextBlocks)); text.AppendLine(); index++; } } else { LogInstructions(text, new Context(instructionSet, 0)); } internalLog.TraceListener.SubmitInstructionTraceInformation(method, stage.Name, text.ToString()); }
private TestCaseAssemblyCompiler(IArchitecture architecture, ITypeSystem typeSystem, ITypeLayout typeLayout, IInternalTrace internalTrace, CompilerOptions compilerOptions) : base(architecture, typeSystem, typeLayout, internalTrace, compilerOptions) { linker = new TestAssemblyLinker(); // Build the assembly compiler pipeline Pipeline.AddRange(new IAssemblyCompilerStage[] { new DelegateTypePatchStage(), new PlugStage(), new AssemblyMemberCompilationSchedulerStage(), new MethodCompilerSchedulerStage(), new TypeLayoutStage(), new MetadataStage(), linker }); architecture.ExtendAssemblyCompilerPipeline(Pipeline); }
/// <summary> /// Prevents a default instance of the <see cref="SimCompiler" /> class from being created. /// </summary> /// <param name="architecture">The compiler target architecture.</param> /// <param name="typeSystem">The type system.</param> /// <param name="typeLayout">The type layout.</param> /// <param name="linker">The linker.</param> /// <param name="compilerOptions">The compiler options.</param> /// <param name="internalTrace">The internal trace.</param> /// <param name="simAdapter">The sim adapter.</param> public SimCompiler(BaseArchitecture architecture, TypeSystem typeSystem, MosaTypeLayout typeLayout, ILinker linker, CompilerOptions compilerOptions, IInternalTrace internalTrace, ISimAdapter simAdapter) : base(architecture, typeSystem, typeLayout, new CompilationScheduler(typeSystem, true), internalTrace, linker, compilerOptions) { this.simAdapter = simAdapter; // Build the assembly compiler pipeline Pipeline.Add(new ICompilerStage[] { new PlugStage(), new MethodCompilerSchedulerStage(), new TypeInitializerSchedulerStage(), new SimPowerUpStage(), new TypeLayoutStage(), new MetadataStage(), new LinkerFinalizationStage(), }); architecture.ExtendCompilerPipeline(Pipeline); }
public static void Compile(ITypeSystem typeSystem, ITypeLayout typeLayout, IInternalTrace internalTrace, string platform, bool enabledSSA) { IArchitecture architecture; switch (platform.ToLower()) { case "x86": architecture = x86.Architecture.CreateArchitecture(x86.ArchitectureFeatureFlags.AutoDetect); break; case "avr32": architecture = AVR32.Architecture.CreateArchitecture(AVR32.ArchitectureFeatureFlags.AutoDetect); break; default: architecture = x86.Architecture.CreateArchitecture(x86.ArchitectureFeatureFlags.AutoDetect); break; } CompilerOptions compilerOptions = new CompilerOptions(); compilerOptions.EnableSSA = enabledSSA; ExplorerAssemblyCompiler compiler = new ExplorerAssemblyCompiler(architecture, typeSystem, typeLayout, internalTrace, compilerOptions); compiler.Compile(); }
/// <summary> /// Prevents a default instance of the <see cref="ExplorerCompiler" /> class from being created. /// </summary> /// <param name="architecture">The compiler target architecture.</param> /// <param name="typeSystem">The type system.</param> /// <param name="typeLayout">The type layout.</param> /// <param name="internalTrace">The internal trace.</param> /// <param name="compilerOptions">The compiler options.</param> public ExplorerCompiler(BaseArchitecture architecture, TypeSystem typeSystem, MosaTypeLayout typeLayout, IInternalTrace internalTrace, CompilerOptions compilerOptions, bool emitBinary) : base(architecture, typeSystem, typeLayout, new CompilationScheduler(typeSystem, true), internalTrace, new ExplorerLinker(), compilerOptions) { this.emitBinary = emitBinary; // Build the assembly compiler pipeline Pipeline.Add(new ICompilerStage[] { new PlugStage(), new MethodCompilerSchedulerStage(), new TypeInitializerSchedulerStage(), new TypeLayoutStage(), new MetadataStage(), }); if (emitBinary) Pipeline.Add(new ICompilerStage[] { new LinkerFinalizationStage(), }); architecture.ExtendCompilerPipeline(Pipeline); }
/// <summary> /// Compiles the specified type system. /// </summary> /// <param name="typeSystem">The type system.</param> /// <param name="typeLayout">The type layout.</param> /// <param name="internalTrace">The internal trace.</param> /// <param name="platform">The platform.</param> /// <param name="enabledSSA">if set to <c>true</c> [enabled ssa].</param> /// <param name="emitBinary">if set to <c>true</c> [emit binary].</param> public static void Compile(TypeSystem typeSystem, MosaTypeLayout typeLayout, IInternalTrace internalTrace, string platform, bool enabledSSA, bool emitBinary) { BaseArchitecture architecture; switch (platform.ToLower()) { case "x86": architecture = Mosa.Platform.x86.Architecture.CreateArchitecture(Mosa.Platform.x86.ArchitectureFeatureFlags.AutoDetect); break; case "armv6": architecture = Mosa.Platform.ARMv6.Architecture.CreateArchitecture(Mosa.Platform.ARMv6.ArchitectureFeatureFlags.AutoDetect); break; //case "avr32": architecture = Mosa.Platform.AVR32.Architecture.CreateArchitecture(Mosa.Platform.AVR32.ArchitectureFeatureFlags.AutoDetect); break; default: architecture = Mosa.Platform.x86.Architecture.CreateArchitecture(Mosa.Platform.x86.ArchitectureFeatureFlags.AutoDetect); break; } CompilerOptions compilerOptions = new CompilerOptions(); compilerOptions.EnableSSA = enabledSSA; compilerOptions.EnableSSAOptimizations = enabledSSA && enabledSSA; ExplorerCompiler compiler = new ExplorerCompiler(architecture, typeSystem, typeLayout, internalTrace, compilerOptions, emitBinary); compiler.Compile(); }
/// <summary> /// Initializes a new compiler instance. /// </summary> /// <param name="architecture">The compiler target architecture.</param> /// <param name="typeSystem">The type system.</param> /// <param name="typeLayout">The type layout.</param> /// <param name="compilationScheduler">The compilation scheduler.</param> /// <param name="internalTrace">The internal trace.</param> /// <param name="compilerOptions">The compiler options.</param> protected BaseCompiler(BaseArchitecture architecture, TypeSystem typeSystem, MosaTypeLayout typeLayout, ICompilationScheduler compilationScheduler, IInternalTrace internalTrace, ILinker linker, CompilerOptions compilerOptions) { if (architecture == null) throw new ArgumentNullException(@"Architecture"); Pipeline = new CompilerPipeline(); Architecture = architecture; TypeSystem = typeSystem; TypeLayout = typeLayout; InternalTrace = internalTrace; CompilerOptions = compilerOptions; Counters = new Counters(); CompilationScheduler = compilationScheduler; PlugSystem = new PlugSystem(); Linker = linker; if (Linker == null) { Linker = compilerOptions.LinkerFactory(); Linker.Initialize(compilerOptions.OutputFile, architecture.Endianness, architecture.ElfMachineType); } }
public AotAssemblyCompiler(IArchitecture architecture, IAssemblyLinker linker, ITypeSystem typeSystem, ITypeLayout typeLayout, IInternalTrace internalTrace, CompilerOptions compilerOptions) : base(architecture, typeSystem, typeLayout, internalTrace, compilerOptions) { }
/// <summary> /// Initializes a new instance of the <see cref="AotCompiler"/> class. /// </summary> /// <param name="architecture">The architecture.</param> /// <param name="linker">The linker.</param> /// <param name="typeSystem">The type system.</param> /// <param name="typeLayout">The type layout.</param> /// <param name="internalTrace">The internal trace.</param> /// <param name="compilerOptions">The compiler options.</param> public AotCompiler(IArchitecture architecture, ILinker linker, ITypeSystem typeSystem, ITypeLayout typeLayout, IInternalTrace internalTrace, CompilerOptions compilerOptions) : base(architecture, typeSystem, typeLayout, new CompilationScheduler(typeSystem, true), internalTrace, compilerOptions) { }
/// <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(); }
public CompilerTrace(IInternalTrace internalTrace) { this.internalTrace = internalTrace; this.Active = true; }
/// <summary> /// Initializes a new instance of the <see cref="AotCompiler" /> class. /// </summary> /// <param name="architecture">The architecture.</param> /// <param name="typeSystem">The type system.</param> /// <param name="typeLayout">The type layout.</param> /// <param name="internalTrace">The internal trace.</param> /// <param name="compilerOptions">The compiler options.</param> public AotCompiler(BaseArchitecture architecture, TypeSystem typeSystem, MosaTypeLayout typeLayout, IInternalTrace internalTrace, CompilerOptions compilerOptions) : base(architecture, typeSystem, typeLayout, new CompilationScheduler(typeSystem, true), internalTrace, null, compilerOptions) { }
/// <summary> /// Initializes a new instance of the <see cref="BaseMethodCompiler"/> class. /// </summary> /// <param name="compiler">The assembly compiler.</param> /// <param name="method">The method to compile by this instance.</param> /// <param name="instructionSet">The instruction set.</param> protected BaseMethodCompiler(BaseCompiler compiler, RuntimeMethod method, InstructionSet instructionSet) { this.compiler = compiler; this.method = method; this.type = method.DeclaringType; this.compilationScheduler = compiler.Scheduler; this.moduleTypeSystem = method.Module; this.architecture = compiler.Architecture; this.typeSystem = compiler.TypeSystem; this.typeLayout = Compiler.TypeLayout; this.internalTrace = Compiler.InternalTrace; this.linker = compiler.Linker; 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(); this.stopMethodCompiler = false; }
/// <summary> /// Initializes a new compiler instance. /// </summary> /// <param name="architecture">The compiler target architecture.</param> /// <param name="typeSystem">The type system.</param> /// <param name="typeLayout">The type layout.</param> /// <param name="compilationScheduler">The compilation scheduler.</param> /// <param name="internalTrace">The internal trace.</param> /// <param name="compilerOptions">The compiler options.</param> protected BaseCompiler(IArchitecture architecture, ITypeSystem typeSystem, ITypeLayout typeLayout, ICompilationScheduler compilationScheduler, IInternalTrace internalTrace, CompilerOptions compilerOptions) { if (architecture == null) throw new ArgumentNullException(@"architecture"); this.pipeline = new CompilerPipeline(); this.architecture = architecture; this.typeSystem = typeSystem; this.typeLayout = typeLayout; this.internalTrace = internalTrace; this.compilerOptions = compilerOptions; this.genericTypePatcher = new GenericTypePatcher(typeSystem); this.counters = new Counters(); this.compilationScheduler = compilationScheduler; this.linker = compilerOptions.Linker; this.plugSystem = new PlugSystem(); }
/// <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(); }