public Starter(Options options, AppLocations appLocations, string imagefile, IStarterEvent launcherEvent, BaseLinker linker) : base(options, appLocations) { ImageFile = imagefile; LauncherEvent = launcherEvent; Linker = linker; }
/// <summary> /// Compiles the specified type system. /// </summary> /// <param name="typeSystem">The type system.</param> /// <param name="typeLayout">The type layout.</param> /// <param name="compilerTrace">The compiler trace.</param> /// <param name="compilerOptions">The compiler options.</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, CompilerTrace compilerTrace, CompilerOptions compilerOptions, BaseArchitecture architecture, ISimAdapter simAdapter, BaseLinker linker) { var compiler = new SimCompiler(architecture, typeSystem, typeLayout, linker, compilerOptions, compilerTrace, simAdapter); compiler.Compile(); return compiler; }
/// <summary> /// Emits all the section created in the binary file. /// </summary> /// <param name="linker">The linker.</param> private void EmitSections(BaseLinker linker) { writer.WriteLine("Offset Virtual Length Name Class"); foreach (var section in linker.LinkerSections) { writer.WriteLine("{0:x16} {1:x16} {2:x16} {3} {4}", section.FileOffset, section.VirtualAddress, section.Size, section.Name.PadRight(32), section.SectionKind); } }
/// <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="compilerTrace">The compiler trace.</param> /// <param name="linker">The linker.</param> /// <param name="compilerOptions">The compiler options.</param> /// <exception cref="System.ArgumentNullException">@Architecture</exception> protected BaseCompiler(BaseArchitecture architecture, TypeSystem typeSystem, MosaTypeLayout typeLayout, ICompilationScheduler compilationScheduler, CompilerTrace compilerTrace, BaseLinker linker, CompilerOptions compilerOptions) { if (architecture == null) throw new ArgumentNullException(@"Architecture"); Pipeline = new CompilerPipeline(); Architecture = architecture; TypeSystem = typeSystem; TypeLayout = typeLayout; CompilerTrace = compilerTrace; CompilerOptions = compilerOptions; Counters = new Counters(); CompilationScheduler = compilationScheduler; PlugSystem = new PlugSystem(); Linker = linker; if (Linker == null) { Linker = compilerOptions.LinkerFactory(); Linker.Initialize(compilerOptions.BaseAddress, architecture.Endianness, architecture.ElfMachineType); } // 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(); }
/// <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="compilerTrace">The internal trace.</param> /// <param name="simAdapter">The sim adapter.</param> public SimCompiler(BaseArchitecture architecture, TypeSystem typeSystem, MosaTypeLayout typeLayout, BaseLinker linker, CompilerOptions compilerOptions, CompilerTrace compilerTrace, ISimAdapter simAdapter) : base(architecture, typeSystem, typeLayout, new CompilationScheduler(typeSystem, true), compilerTrace, linker, compilerOptions) { this.simAdapter = simAdapter; // Build the assembly compiler pipeline Pipeline.Add(new ICompilerStage[] { new PlugStage(), new MethodCompilerSchedulerStage(), new TypeInitializerSchedulerStage(), new SimPowerUpStage(), new MethodLookupTableStage(), new MethodExceptionLookupTableStage(), new MetadataStage(), new SimLinkerFinalizationStage(simAdapter.SimCPU), }); architecture.ExtendCompilerPipeline(Pipeline); }
/// <summary> /// Initializes a new instance of <see cref="BaseCodeEmitter" />. /// </summary> /// <param name="methodName">Name of the method.</param> /// <param name="linker">The linker.</param> /// <param name="codeStream">The stream the machine code is written to.</param> /// <param name="typeSystem">The type system.</param> public void Initialize(string methodName, BaseLinker linker, Stream codeStream, TypeSystem typeSystem) { Debug.Assert(codeStream != null); Debug.Assert(linker != null); this.MethodName = methodName; this.linker = linker; this.codeStream = codeStream; this.TypeSystem = typeSystem; }
public void StartSimulator(string platform) { if (TypeSystem == null) return; Status = "Compiling..."; Architecture = GetArchitecture(platform); var simAdapter = GetSimAdaptor(platform); Linker = new SimLinker(simAdapter); compileStartTime = DateTime.Now; var compilerOptions = new CompilerOptions(); compilerOptions.EnableSSA = true; compilerOptions.EnableOptimizations = true; compilerOptions.EnablePromoteTemporaryVariablesOptimization = true; compilerOptions.EnableSparseConditionalConstantPropagation = true; SimCompiler.Compile(TypeSystem, TypeLayout, InternalTrace, compilerOptions, Architecture, simAdapter, Linker); SimCPU = simAdapter.SimCPU; SimCPU.Monitor.BreakAtTick = 1; SimCPU.Monitor.BreakOnException = true; SimCPU.Monitor.OnStateUpdate = UpdateSimState; SimCPU.Reset(); Display32 = SimCPU.GetState().NativeRegisterSize == 32; SimCPU.Monitor.OnExecutionStepCompleted(true); Status = "Compiled."; symbolView.CreateEntries(); }
public void Initialize() { Linker = new BaseLinker(CompilerOptions.BaseAddress, CompilerOptions.Architecture.Endianness, CompilerOptions.Architecture.MachineType, CompilerOptions.EmitSymbols, CompilerOptions.LinkerFormatType); BaseCompiler = CompilerFactory(); BaseCompiler.Initialize(this); }
/// <summary> /// Initializes a new instance of <see cref="BaseCodeEmitter" />. /// </summary> /// <param name="methodName">Name of the method.</param> /// <param name="linker">The linker.</param> /// <param name="codeStream">The stream the machine code is written to.</param> public void Initialize(string methodName, BaseLinker linker, Stream codeStream) { Debug.Assert(codeStream != null); Debug.Assert(linker != null); MethodName = methodName; this.linker = linker; this.codeStream = codeStream; // only necessary if method is being recompiled (due to inline optimization, for example) var symbol = linker.GetSymbol(MethodName, SectionKind.Text); symbol.RemovePatches(); }
/// <summary> /// Emits all symbols emitted in the binary file. /// </summary> /// <param name="linker">The linker.</param> private void EmitSymbols(BaseLinker linker) { writer.WriteLine("Virtual Offset Length Symbol"); foreach (var section in linker.LinkerSections) { foreach (var symbol in section.Symbols) { writer.WriteLine("{0:x16} {1:x16} {2:x16} {3} {4}", symbol.VirtualAddress, symbol.SectionOffset, symbol.Size, symbol.SectionKind.ToString().PadRight(7), symbol.Name); } } var entryPoint = linker.EntryPoint; if (entryPoint != null) { writer.WriteLine(); writer.WriteLine("Entry point is {0}", entryPoint.Name); writer.WriteLine("\tat Offset {0:x16}", entryPoint.SectionOffset); // TODO! add section offset too? writer.WriteLine("\tat virtual address {0:x16}", entryPoint.VirtualAddress); } //writer.WriteLine(); //writer.WriteLine("Hash Table:"); //writer.WriteLine(); //writer.WriteLine("Virtual Size Pre-Hash Post-Hash Symbol"); //var symbols = linker.Symbols.OrderBy(symbol => symbol.Name); //foreach (var symbol in linker.Symbols) //{ // if (symbol.SectionKind == SectionKind.Text) // { // writer.WriteLine("{0:x16} {1:x8} {2} {3} {4}", symbol.VirtualAddress, symbol.Size, ExtractHash(symbol.PreHash), ExtractHash(symbol.PostHash), symbol.Name); // } //} //writer.WriteLine(); //writer.WriteLine("Pre-Hash Table:"); //writer.WriteLine(); //writer.WriteLine("Hash Size Symbol"); //var symbols2 = linker.Symbols.OrderBy(symbol => symbol.Name); //foreach (var symbol in symbols2) //{ // if (symbol.SectionKind == SectionKind.Text) // { // writer.WriteLine("{0} {1:x8} {2}", ExtractHash(symbol.PreHash), symbol.Size, symbol.Name); // } //} }
/// <summary> /// Emits all symbols emitted in the binary file. /// </summary> /// <param name="linker">The linker.</param> private void EmitSymbols(BaseLinker linker) { writer.WriteLine("Offset Virtual Length Section Symbols"); foreach (var section in linker.Sections) { //foreach (var symbol in section.Ordered) foreach (var symbol in section.Symbols) { writer.WriteLine("{0:x16} {1:x16} {2:x16} {3} {4}", symbol.SectionOffset, symbol.VirtualAddress, symbol.Size, symbol.SectionKind.ToString().PadRight(7), symbol.Name); } } var entryPoint = linker.EntryPoint; if (entryPoint != null) { writer.WriteLine(); writer.WriteLine("Entry point is {0}", entryPoint.Name); writer.WriteLine("\tat Offset {0:x16}", entryPoint.SectionOffset); // TODO! add section offset too? writer.WriteLine("\tat virtual address {0:x16}", entryPoint.VirtualAddress); } }
public void Resolve(TypeSystem typeSystem, BaseLinker linker) { // Find the test method to execute RuntimeMethod = FindMethod( typeSystem, MethodNamespaceName, MethodTypeName, MethodName, Parameters ); Debug.Assert(RuntimeMethod != null, MethodNamespaceName + "." + MethodTypeName + "." + MethodName); var symbol = linker.GetSymbol(RuntimeMethod.FullName, SectionKind.Text); Address = symbol.VirtualAddress; }
public void Resolve(TypeSystem typeSystem, BaseLinker linker) { // Find the test method to execute RuntimeMethod = UnitTestEngine.FindMethod( typeSystem, MethodNamespaceName, MethodTypeName, MethodName, Parameters ); Address = UnitTestEngine.GetMethodAddress(RuntimeMethod, linker); }